diff options
author | Jesper Nilsson <jesper.nilsson@axis.com> | 2013-02-21 19:44:27 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-21 20:22:27 -0500 |
commit | f32bc70d5f938cfef3e534c9db6d38a3759eac6d (patch) | |
tree | 2b3772a6c6923871136d6285bb28e3898c6fea42 /drivers/rtc | |
parent | fca1dd031a28da74db3df4921dc36fa78941c99f (diff) |
rtc-pcf8523: add low battery voltage support
Implement reading of the battery voltage low signal for rtc-pcf8523.
The bit is read-only and cannot be cleared by software, so no
clear function is implemented.
[akpm@linux-foundation.org: omit pcf8563_rtc_ioctl() if CONFIG_RTC_INTF_DEV=n]
Signed-off-by: Jesper Nilsson <jesper.nilsson@axis.com>
Reviewed-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-pcf8523.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c index be05a645f99e..889e3160e701 100644 --- a/drivers/rtc/rtc-pcf8523.c +++ b/drivers/rtc/rtc-pcf8523.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #define REG_CONTROL3_PM_VDD (1 << 6) /* switch-over disabled */ | 23 | #define REG_CONTROL3_PM_VDD (1 << 6) /* switch-over disabled */ |
24 | #define REG_CONTROL3_PM_DSM (1 << 5) /* direct switching mode */ | 24 | #define REG_CONTROL3_PM_DSM (1 << 5) /* direct switching mode */ |
25 | #define REG_CONTROL3_PM_MASK 0xe0 | 25 | #define REG_CONTROL3_PM_MASK 0xe0 |
26 | #define REG_CONTROL3_BLF (1 << 2) /* battery low bit, read-only */ | ||
26 | 27 | ||
27 | #define REG_SECONDS 0x03 | 28 | #define REG_SECONDS 0x03 |
28 | #define REG_SECONDS_OS (1 << 7) | 29 | #define REG_SECONDS_OS (1 << 7) |
@@ -250,9 +251,39 @@ static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm) | |||
250 | return pcf8523_start_rtc(client); | 251 | return pcf8523_start_rtc(client); |
251 | } | 252 | } |
252 | 253 | ||
254 | #ifdef CONFIG_RTC_INTF_DEV | ||
255 | static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd, | ||
256 | unsigned long arg) | ||
257 | { | ||
258 | struct i2c_client *client = to_i2c_client(dev); | ||
259 | u8 value; | ||
260 | int ret = 0, err; | ||
261 | |||
262 | switch (cmd) { | ||
263 | case RTC_VL_READ: | ||
264 | err = pcf8523_read(client, REG_CONTROL3, &value); | ||
265 | if (err < 0) | ||
266 | return err; | ||
267 | |||
268 | if (value & REG_CONTROL3_BLF) | ||
269 | ret = 1; | ||
270 | |||
271 | if (copy_to_user((void __user *)arg, &ret, sizeof(int))) | ||
272 | return -EFAULT; | ||
273 | |||
274 | return 0; | ||
275 | default: | ||
276 | return -ENOIOCTLCMD; | ||
277 | } | ||
278 | } | ||
279 | #else | ||
280 | #define pcf8523_rtc_ioctl NULL | ||
281 | #endif | ||
282 | |||
253 | static const struct rtc_class_ops pcf8523_rtc_ops = { | 283 | static const struct rtc_class_ops pcf8523_rtc_ops = { |
254 | .read_time = pcf8523_rtc_read_time, | 284 | .read_time = pcf8523_rtc_read_time, |
255 | .set_time = pcf8523_rtc_set_time, | 285 | .set_time = pcf8523_rtc_set_time, |
286 | .ioctl = pcf8523_rtc_ioctl, | ||
256 | }; | 287 | }; |
257 | 288 | ||
258 | static int pcf8523_probe(struct i2c_client *client, | 289 | static int pcf8523_probe(struct i2c_client *client, |