Merge tag 'Smack-for-5.11-io_uring-fix' of git://github.com/cschaufler/smack-next
[linux-2.6-microblaze.git] / drivers / rtc / rtc-pcf8563.c
index 3c322f3..de3e6c3 100644 (file)
@@ -22,8 +22,8 @@
 
 #define PCF8563_REG_ST1                0x00 /* status */
 #define PCF8563_REG_ST2                0x01
-#define PCF8563_BIT_AIE                (1 << 1)
-#define PCF8563_BIT_AF         (1 << 3)
+#define PCF8563_BIT_AIE                BIT(1)
+#define PCF8563_BIT_AF         BIT(3)
 #define PCF8563_BITS_ST2_N     (7 << 5)
 
 #define PCF8563_REG_SC         0x02 /* datetime */
@@ -76,7 +76,6 @@ struct pcf8563 {
         * 1970...2069.
         */
        int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
-       int voltage_low; /* incicates if a low_voltage was detected */
 
        struct i2c_client *client;
 #ifdef CONFIG_COMMON_CLK
@@ -208,7 +207,6 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
                return err;
 
        if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {
-               pcf8563->voltage_low = 1;
                dev_err(&client->dev,
                        "low voltage detected, date/time is not reliable.\n");
                return -EINVAL;
@@ -276,43 +274,23 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
                                9 - PCF8563_REG_SC, buf + PCF8563_REG_SC);
 }
 
-#ifdef CONFIG_RTC_INTF_DEV
 static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
 {
-       struct pcf8563 *pcf8563 = i2c_get_clientdata(to_i2c_client(dev));
-       struct rtc_time tm;
+       struct i2c_client *client = to_i2c_client(dev);
+       int ret;
 
        switch (cmd) {
        case RTC_VL_READ:
-               if (pcf8563->voltage_low)
-                       dev_info(dev, "low voltage detected, date/time is not reliable.\n");
-
-               if (copy_to_user((void __user *)arg, &pcf8563->voltage_low,
-                                       sizeof(int)))
-                       return -EFAULT;
-               return 0;
-       case RTC_VL_CLR:
-               /*
-                * Clear the VL bit in the seconds register in case
-                * the time has not been set already (which would
-                * have cleared it). This does not really matter
-                * because of the cached voltage_low value but do it
-                * anyway for consistency.
-                */
-               if (pcf8563_rtc_read_time(dev, &tm))
-                       pcf8563_rtc_set_time(dev, &tm);
-
-               /* Clear the cached value. */
-               pcf8563->voltage_low = 0;
+               ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC);
+               if (ret < 0)
+                       return ret;
 
-               return 0;
+               return put_user(ret & PCF8563_SC_LV ? RTC_VL_DATA_INVALID : 0,
+                               (unsigned int __user *)arg);
        default:
                return -ENOIOCTLCMD;
        }
 }
-#else
-#define pcf8563_rtc_ioctl NULL
-#endif
 
 static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
 {
@@ -604,7 +582,7 @@ static int pcf8563_probe(struct i2c_client *client,
                }
        }
 
-       err = rtc_register_device(pcf8563->rtc);
+       err = devm_rtc_register_device(pcf8563->rtc);
        if (err)
                return err;