diff options
author | Ivan Grimaldi <grimaldi.ivan@gmail.com> | 2015-09-18 11:27:57 -0400 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2015-11-08 08:12:23 -0500 |
commit | fa395fb8fc3206cdd70b046e0b98168576cc71ef (patch) | |
tree | d82868266fb4b87719ad11ea98d4db97dbc35378 /drivers/rtc | |
parent | 2ec68825fc55d1ddeb04ab861f3bfdbaa8e9f3c4 (diff) |
rtc: ds1390: Add trickle charger device tree binding
Introduce a device tree binding for specifying the trickle charger
configuration for ds1390.
Signed-off-by: Ivan Grimaldi <grimaldi.ivan@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/Kconfig | 4 | ||||
-rw-r--r-- | drivers/rtc/rtc-ds1390.c | 63 |
2 files changed, 65 insertions, 2 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 9d4290617cee..57c2dbc4f438 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -666,8 +666,8 @@ config RTC_DRV_DS1390 | |||
666 | If you say yes here you get support for the | 666 | If you say yes here you get support for the |
667 | Dallas/Maxim DS1390/93/94 chips. | 667 | Dallas/Maxim DS1390/93/94 chips. |
668 | 668 | ||
669 | This driver only supports the RTC feature, and not other chip | 669 | This driver supports the RTC feature and trickle charging but not |
670 | features such as alarms and trickle charging. | 670 | other chip features such as alarms. |
671 | 671 | ||
672 | This driver can also be built as a module. If so, the module | 672 | This driver can also be built as a module. If so, the module |
673 | will be called rtc-ds1390. | 673 | will be called rtc-ds1390. |
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c index a4303b43a36a..b2b9454aa7a2 100644 --- a/drivers/rtc/rtc-ds1390.c +++ b/drivers/rtc/rtc-ds1390.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/spi/spi.h> | 20 | #include <linux/spi/spi.h> |
21 | #include <linux/bcd.h> | 21 | #include <linux/bcd.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | #include <linux/of.h> | ||
23 | 24 | ||
24 | #define DS1390_REG_100THS 0x00 | 25 | #define DS1390_REG_100THS 0x00 |
25 | #define DS1390_REG_SECONDS 0x01 | 26 | #define DS1390_REG_SECONDS 0x01 |
@@ -40,11 +41,31 @@ | |||
40 | #define DS1390_REG_STATUS 0x0E | 41 | #define DS1390_REG_STATUS 0x0E |
41 | #define DS1390_REG_TRICKLE 0x0F | 42 | #define DS1390_REG_TRICKLE 0x0F |
42 | 43 | ||
44 | #define DS1390_TRICKLE_CHARGER_ENABLE 0xA0 | ||
45 | #define DS1390_TRICKLE_CHARGER_250_OHM 0x01 | ||
46 | #define DS1390_TRICKLE_CHARGER_2K_OHM 0x02 | ||
47 | #define DS1390_TRICKLE_CHARGER_4K_OHM 0x03 | ||
48 | #define DS1390_TRICKLE_CHARGER_NO_DIODE 0x04 | ||
49 | #define DS1390_TRICKLE_CHARGER_DIODE 0x08 | ||
50 | |||
43 | struct ds1390 { | 51 | struct ds1390 { |
44 | struct rtc_device *rtc; | 52 | struct rtc_device *rtc; |
45 | u8 txrx_buf[9]; /* cmd + 8 registers */ | 53 | u8 txrx_buf[9]; /* cmd + 8 registers */ |
46 | }; | 54 | }; |
47 | 55 | ||
56 | static void ds1390_set_reg(struct device *dev, unsigned char address, | ||
57 | unsigned char data) | ||
58 | { | ||
59 | struct spi_device *spi = to_spi_device(dev); | ||
60 | unsigned char buf[2]; | ||
61 | |||
62 | /* MSB must be '1' to write */ | ||
63 | buf[0] = address | 0x80; | ||
64 | buf[1] = data; | ||
65 | |||
66 | spi_write(spi, buf, 2); | ||
67 | } | ||
68 | |||
48 | static int ds1390_get_reg(struct device *dev, unsigned char address, | 69 | static int ds1390_get_reg(struct device *dev, unsigned char address, |
49 | unsigned char *data) | 70 | unsigned char *data) |
50 | { | 71 | { |
@@ -67,6 +88,45 @@ static int ds1390_get_reg(struct device *dev, unsigned char address, | |||
67 | return 0; | 88 | return 0; |
68 | } | 89 | } |
69 | 90 | ||
91 | static void ds1390_trickle_of_init(struct spi_device *spi) | ||
92 | { | ||
93 | u32 ohms = 0; | ||
94 | u8 value; | ||
95 | |||
96 | if (of_property_read_u32(spi->dev.of_node, "trickle-resistor-ohms", | ||
97 | &ohms)) | ||
98 | goto out; | ||
99 | |||
100 | /* Enable charger */ | ||
101 | value = DS1390_TRICKLE_CHARGER_ENABLE; | ||
102 | if (of_property_read_bool(spi->dev.of_node, "trickle-diode-disable")) | ||
103 | value |= DS1390_TRICKLE_CHARGER_NO_DIODE; | ||
104 | else | ||
105 | value |= DS1390_TRICKLE_CHARGER_DIODE; | ||
106 | |||
107 | /* Resistor select */ | ||
108 | switch (ohms) { | ||
109 | case 250: | ||
110 | value |= DS1390_TRICKLE_CHARGER_250_OHM; | ||
111 | break; | ||
112 | case 2000: | ||
113 | value |= DS1390_TRICKLE_CHARGER_2K_OHM; | ||
114 | break; | ||
115 | case 4000: | ||
116 | value |= DS1390_TRICKLE_CHARGER_4K_OHM; | ||
117 | break; | ||
118 | default: | ||
119 | dev_warn(&spi->dev, | ||
120 | "Unsupported ohm value %02ux in dt\n", ohms); | ||
121 | return; | ||
122 | } | ||
123 | |||
124 | ds1390_set_reg(&spi->dev, DS1390_REG_TRICKLE, value); | ||
125 | |||
126 | out: | ||
127 | return; | ||
128 | } | ||
129 | |||
70 | static int ds1390_read_time(struct device *dev, struct rtc_time *dt) | 130 | static int ds1390_read_time(struct device *dev, struct rtc_time *dt) |
71 | { | 131 | { |
72 | struct spi_device *spi = to_spi_device(dev); | 132 | struct spi_device *spi = to_spi_device(dev); |
@@ -143,6 +203,9 @@ static int ds1390_probe(struct spi_device *spi) | |||
143 | return res; | 203 | return res; |
144 | } | 204 | } |
145 | 205 | ||
206 | if (spi->dev.of_node) | ||
207 | ds1390_trickle_of_init(spi); | ||
208 | |||
146 | chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390", | 209 | chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390", |
147 | &ds1390_rtc_ops, THIS_MODULE); | 210 | &ds1390_rtc_ops, THIS_MODULE); |
148 | if (IS_ERR(chip->rtc)) { | 211 | if (IS_ERR(chip->rtc)) { |