Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ivan Grimaldi and committed by
Alexandre Belloni
fa395fb8 2ec68825

+83 -2
+18
Documentation/devicetree/bindings/rtc/dallas,ds1390.txt
··· 1 + * Dallas DS1390 SPI Serial Real-Time Clock 2 + 3 + Required properties: 4 + - compatible: Should contain "dallas,ds1390". 5 + - reg: SPI address for chip 6 + 7 + Optional properties: 8 + - trickle-resistor-ohms : Selected resistor for trickle charger 9 + Values usable for ds1390 are 250, 2000, 4000 10 + Should be given if trickle charger should be enabled 11 + - trickle-diode-disable : Do not use internal trickle charger diode 12 + Should be given if internal trickle charger diode should be disabled 13 + Example: 14 + ds1390: rtc@68 { 15 + compatible = "dallas,ds1390"; 16 + trickle-resistor-ohms = <250>; 17 + reg = <0>; 18 + };
+2 -2
drivers/rtc/Kconfig
··· 666 666 If you say yes here you get support for the 667 667 Dallas/Maxim DS1390/93/94 chips. 668 668 669 - This driver only supports the RTC feature, and not other chip 670 - features such as alarms and trickle charging. 669 + This driver supports the RTC feature and trickle charging but not 670 + other chip features such as alarms. 671 671 672 672 This driver can also be built as a module. If so, the module 673 673 will be called rtc-ds1390.
+63
drivers/rtc/rtc-ds1390.c
··· 20 20 #include <linux/spi/spi.h> 21 21 #include <linux/bcd.h> 22 22 #include <linux/slab.h> 23 + #include <linux/of.h> 23 24 24 25 #define DS1390_REG_100THS 0x00 25 26 #define DS1390_REG_SECONDS 0x01 ··· 41 40 #define DS1390_REG_STATUS 0x0E 42 41 #define DS1390_REG_TRICKLE 0x0F 43 42 43 + #define DS1390_TRICKLE_CHARGER_ENABLE 0xA0 44 + #define DS1390_TRICKLE_CHARGER_250_OHM 0x01 45 + #define DS1390_TRICKLE_CHARGER_2K_OHM 0x02 46 + #define DS1390_TRICKLE_CHARGER_4K_OHM 0x03 47 + #define DS1390_TRICKLE_CHARGER_NO_DIODE 0x04 48 + #define DS1390_TRICKLE_CHARGER_DIODE 0x08 49 + 44 50 struct ds1390 { 45 51 struct rtc_device *rtc; 46 52 u8 txrx_buf[9]; /* cmd + 8 registers */ 47 53 }; 54 + 55 + static void ds1390_set_reg(struct device *dev, unsigned char address, 56 + unsigned char data) 57 + { 58 + struct spi_device *spi = to_spi_device(dev); 59 + unsigned char buf[2]; 60 + 61 + /* MSB must be '1' to write */ 62 + buf[0] = address | 0x80; 63 + buf[1] = data; 64 + 65 + spi_write(spi, buf, 2); 66 + } 48 67 49 68 static int ds1390_get_reg(struct device *dev, unsigned char address, 50 69 unsigned char *data) ··· 86 65 *data = chip->txrx_buf[0]; 87 66 88 67 return 0; 68 + } 69 + 70 + static void ds1390_trickle_of_init(struct spi_device *spi) 71 + { 72 + u32 ohms = 0; 73 + u8 value; 74 + 75 + if (of_property_read_u32(spi->dev.of_node, "trickle-resistor-ohms", 76 + &ohms)) 77 + goto out; 78 + 79 + /* Enable charger */ 80 + value = DS1390_TRICKLE_CHARGER_ENABLE; 81 + if (of_property_read_bool(spi->dev.of_node, "trickle-diode-disable")) 82 + value |= DS1390_TRICKLE_CHARGER_NO_DIODE; 83 + else 84 + value |= DS1390_TRICKLE_CHARGER_DIODE; 85 + 86 + /* Resistor select */ 87 + switch (ohms) { 88 + case 250: 89 + value |= DS1390_TRICKLE_CHARGER_250_OHM; 90 + break; 91 + case 2000: 92 + value |= DS1390_TRICKLE_CHARGER_2K_OHM; 93 + break; 94 + case 4000: 95 + value |= DS1390_TRICKLE_CHARGER_4K_OHM; 96 + break; 97 + default: 98 + dev_warn(&spi->dev, 99 + "Unsupported ohm value %02ux in dt\n", ohms); 100 + return; 101 + } 102 + 103 + ds1390_set_reg(&spi->dev, DS1390_REG_TRICKLE, value); 104 + 105 + out: 106 + return; 89 107 } 90 108 91 109 static int ds1390_read_time(struct device *dev, struct rtc_time *dt) ··· 202 142 dev_err(&spi->dev, "unable to read device\n"); 203 143 return res; 204 144 } 145 + 146 + if (spi->dev.of_node) 147 + ds1390_trickle_of_init(spi); 205 148 206 149 chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390", 207 150 &ds1390_rtc_ops, THIS_MODULE);