aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPhilippe De Muyter <phdm@macqel.be>2015-05-05 19:23:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-05-05 20:10:10 -0400
commit4d61ff6b9960cb00cf2c12abd5769aa2dd475415 (patch)
tree7679022d518bf735e2a2270255824411f1ea74b5 /drivers
parentc71f1e05e62f3eb843b6458eeb7298f269b34b1e (diff)
rtc: add rtc-abx80x, a driver for the Abracon AB x80x i2c rtc
This is a basic driver for the ultra-low-power Abracon AB x80x series of RTC chips. It supports in particular, the supersets AB0805 and AB1805. It allows reading and writing the time, and enables the supercapacitor/ battery charger. [arnd@arndb.de: abx805 depends on i2c] [alexandre.belloni@free-electrons.com: renam buffer from date to buf in abx80x_rtc_read_time()] Signed-off-by: Philippe De Muyter <phdm@macqel.be> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: Paul Bolle <pebolle@tiscali.nl> Cc: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-abx80x.c307
3 files changed, 318 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 6149ae01e11f..0fe4ad8826b2 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -164,6 +164,16 @@ config RTC_DRV_ABB5ZES3
164 This driver can also be built as a module. If so, the module 164 This driver can also be built as a module. If so, the module
165 will be called rtc-ab-b5ze-s3. 165 will be called rtc-ab-b5ze-s3.
166 166
167config RTC_DRV_ABX80X
168 tristate "Abracon ABx80x"
169 help
170 If you say yes here you get support for Abracon AB080X and AB180X
171 families of ultra-low-power battery- and capacitor-backed real-time
172 clock chips.
173
174 This driver can also be built as a module. If so, the module
175 will be called rtc-abx80x.
176
167config RTC_DRV_AS3722 177config RTC_DRV_AS3722
168 tristate "ams AS3722 RTC driver" 178 tristate "ams AS3722 RTC driver"
169 depends on MFD_AS3722 179 depends on MFD_AS3722
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c31731c29762..2b82e2b0311b 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_RTC_DRV_88PM80X) += rtc-88pm80x.o
25obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o 25obj-$(CONFIG_RTC_DRV_AB3100) += rtc-ab3100.o
26obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o 26obj-$(CONFIG_RTC_DRV_AB8500) += rtc-ab8500.o
27obj-$(CONFIG_RTC_DRV_ABB5ZES3) += rtc-ab-b5ze-s3.o 27obj-$(CONFIG_RTC_DRV_ABB5ZES3) += rtc-ab-b5ze-s3.o
28obj-$(CONFIG_RTC_DRV_ABX80X) += rtc-abx80x.o
28obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o 29obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o
29obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o 30obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
30obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o 31obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
new file mode 100644
index 000000000000..4337c3bc6ace
--- /dev/null
+++ b/drivers/rtc/rtc-abx80x.c
@@ -0,0 +1,307 @@
1/*
2 * A driver for the I2C members of the Abracon AB x8xx RTC family,
3 * and compatible: AB 1805 and AB 0805
4 *
5 * Copyright 2014-2015 Macq S.A.
6 *
7 * Author: Philippe De Muyter <phdm@macqel.be>
8 * Author: Alexandre Belloni <alexandre.belloni@free-electrons.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/bcd.h>
17#include <linux/i2c.h>
18#include <linux/module.h>
19#include <linux/rtc.h>
20
21#define ABX8XX_REG_HTH 0x00
22#define ABX8XX_REG_SC 0x01
23#define ABX8XX_REG_MN 0x02
24#define ABX8XX_REG_HR 0x03
25#define ABX8XX_REG_DA 0x04
26#define ABX8XX_REG_MO 0x05
27#define ABX8XX_REG_YR 0x06
28#define ABX8XX_REG_WD 0x07
29
30#define ABX8XX_REG_CTRL1 0x10
31#define ABX8XX_CTRL_WRITE BIT(1)
32#define ABX8XX_CTRL_12_24 BIT(6)
33
34#define ABX8XX_REG_CFG_KEY 0x1f
35#define ABX8XX_CFG_KEY_MISC 0x9d
36
37#define ABX8XX_REG_ID0 0x28
38
39#define ABX8XX_REG_TRICKLE 0x20
40#define ABX8XX_TRICKLE_CHARGE_ENABLE 0xa0
41#define ABX8XX_TRICKLE_STANDARD_DIODE 0x8
42#define ABX8XX_TRICKLE_SCHOTTKY_DIODE 0x4
43
44static u8 trickle_resistors[] = {0, 3, 6, 11};
45
46enum abx80x_chip {AB0801, AB0803, AB0804, AB0805,
47 AB1801, AB1803, AB1804, AB1805, ABX80X};
48
49struct abx80x_cap {
50 u16 pn;
51 bool has_tc;
52};
53
54static struct abx80x_cap abx80x_caps[] = {
55 [AB0801] = {.pn = 0x0801},
56 [AB0803] = {.pn = 0x0803},
57 [AB0804] = {.pn = 0x0804, .has_tc = true},
58 [AB0805] = {.pn = 0x0805, .has_tc = true},
59 [AB1801] = {.pn = 0x1801},
60 [AB1803] = {.pn = 0x1803},
61 [AB1804] = {.pn = 0x1804, .has_tc = true},
62 [AB1805] = {.pn = 0x1805, .has_tc = true},
63 [ABX80X] = {.pn = 0}
64};
65
66static struct i2c_driver abx80x_driver;
67
68static int abx80x_enable_trickle_charger(struct i2c_client *client,
69 u8 trickle_cfg)
70{
71 int err;
72
73 /*
74 * Write the configuration key register to enable access to the Trickle
75 * register
76 */
77 err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY,
78 ABX8XX_CFG_KEY_MISC);
79 if (err < 0) {
80 dev_err(&client->dev, "Unable to write configuration key\n");
81 return -EIO;
82 }
83
84 err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE,
85 ABX8XX_TRICKLE_CHARGE_ENABLE |
86 trickle_cfg);
87 if (err < 0) {
88 dev_err(&client->dev, "Unable to write trickle register\n");
89 return -EIO;
90 }
91
92 return 0;
93}
94
95static int abx80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
96{
97 struct i2c_client *client = to_i2c_client(dev);
98 unsigned char buf[8];
99 int err;
100
101 err = i2c_smbus_read_i2c_block_data(client, ABX8XX_REG_HTH,
102 sizeof(buf), buf);
103 if (err < 0) {
104 dev_err(&client->dev, "Unable to read date\n");
105 return -EIO;
106 }
107
108 tm->tm_sec = bcd2bin(buf[ABX8XX_REG_SC] & 0x7F);
109 tm->tm_min = bcd2bin(buf[ABX8XX_REG_MN] & 0x7F);
110 tm->tm_hour = bcd2bin(buf[ABX8XX_REG_HR] & 0x3F);
111 tm->tm_wday = buf[ABX8XX_REG_WD] & 0x7;
112 tm->tm_mday = bcd2bin(buf[ABX8XX_REG_DA] & 0x3F);
113 tm->tm_mon = bcd2bin(buf[ABX8XX_REG_MO] & 0x1F) - 1;
114 tm->tm_year = bcd2bin(buf[ABX8XX_REG_YR]) + 100;
115
116 err = rtc_valid_tm(tm);
117 if (err < 0)
118 dev_err(&client->dev, "retrieved date/time is not valid.\n");
119
120 return err;
121}
122
123static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
124{
125 struct i2c_client *client = to_i2c_client(dev);
126 unsigned char buf[8];
127 int err;
128
129 if (tm->tm_year < 100)
130 return -EINVAL;
131
132 buf[ABX8XX_REG_HTH] = 0;
133 buf[ABX8XX_REG_SC] = bin2bcd(tm->tm_sec);
134 buf[ABX8XX_REG_MN] = bin2bcd(tm->tm_min);
135 buf[ABX8XX_REG_HR] = bin2bcd(tm->tm_hour);
136 buf[ABX8XX_REG_DA] = bin2bcd(tm->tm_mday);
137 buf[ABX8XX_REG_MO] = bin2bcd(tm->tm_mon + 1);
138 buf[ABX8XX_REG_YR] = bin2bcd(tm->tm_year - 100);
139 buf[ABX8XX_REG_WD] = tm->tm_wday;
140
141 err = i2c_smbus_write_i2c_block_data(client, ABX8XX_REG_HTH,
142 sizeof(buf), buf);
143 if (err < 0) {
144 dev_err(&client->dev, "Unable to write to date registers\n");
145 return -EIO;
146 }
147
148 return 0;
149}
150
151static const struct rtc_class_ops abx80x_rtc_ops = {
152 .read_time = abx80x_rtc_read_time,
153 .set_time = abx80x_rtc_set_time,
154};
155
156static int abx80x_dt_trickle_cfg(struct device_node *np)
157{
158 const char *diode;
159 int