David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * rtc-ds1307.c - RTC driver for some mostly-compatible I2C chips. |
| 3 | * |
| 4 | * Copyright (C) 2005 James Chapman (ds1337 core) |
| 5 | * Copyright (C) 2006 David Brownell |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 6 | * Copyright (C) 2009 Matthias Fuchs (rx8025 support) |
Bertrand Achard | bc48b90 | 2013-04-29 16:19:26 -0700 | [diff] [blame] | 7 | * Copyright (C) 2012 Bertrand Achard (nvram access fixes) |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 14 | #include <linux/acpi.h> |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 15 | #include <linux/bcd.h> |
Nishanth Menon | eac7237 | 2015-06-23 11:15:12 -0500 | [diff] [blame] | 16 | #include <linux/i2c.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/module.h> |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 19 | #include <linux/of_device.h> |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 20 | #include <linux/rtc/ds1307.h> |
Nishanth Menon | eac7237 | 2015-06-23 11:15:12 -0500 | [diff] [blame] | 21 | #include <linux/rtc.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/string.h> |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 24 | #include <linux/hwmon.h> |
| 25 | #include <linux/hwmon-sysfs.h> |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 26 | #include <linux/clk-provider.h> |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 27 | #include <linux/regmap.h> |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 28 | |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 29 | /* |
| 30 | * We can't determine type by probing, but if we expect pre-Linux code |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 31 | * to have set the chip up as a clock (turning on the oscillator and |
| 32 | * setting the date and time), Linux can ignore the non-clock features. |
| 33 | * That's a natural job for a factory or repair bench. |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 34 | */ |
| 35 | enum ds_type { |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 36 | ds_1307, |
Sean Nyekjaer | 300a773 | 2017-06-08 12:36:54 +0200 | [diff] [blame] | 37 | ds_1308, |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 38 | ds_1337, |
| 39 | ds_1338, |
| 40 | ds_1339, |
| 41 | ds_1340, |
Nikita Yushchenko | 0759c88 | 2017-08-24 09:32:11 +0300 | [diff] [blame] | 42 | ds_1341, |
Joakim Tjernlund | 33df2ee | 2009-06-17 16:26:08 -0700 | [diff] [blame] | 43 | ds_1388, |
Wolfram Sang | 97f902b | 2009-06-17 16:26:10 -0700 | [diff] [blame] | 44 | ds_3231, |
Stefan Agner | 8566f70 | 2017-03-23 16:54:57 -0700 | [diff] [blame] | 45 | m41t0, |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 46 | m41t00, |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 47 | m41t11, |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 48 | mcp794xx, |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 49 | rx_8025, |
Marek Vasut | ee0981b | 2017-06-18 22:55:28 +0200 | [diff] [blame] | 50 | rx_8130, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 51 | last_ds_type /* always last */ |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 52 | /* rs5c372 too? different address... */ |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 55 | /* RTC registers don't differ much, except for the century flag */ |
| 56 | #define DS1307_REG_SECS 0x00 /* 00-59 */ |
| 57 | # define DS1307_BIT_CH 0x80 |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 58 | # define DS1340_BIT_nEOSC 0x80 |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 59 | # define MCP794XX_BIT_ST 0x80 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 60 | #define DS1307_REG_MIN 0x01 /* 00-59 */ |
Stefan Agner | 8566f70 | 2017-03-23 16:54:57 -0700 | [diff] [blame] | 61 | # define M41T0_BIT_OF 0x80 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 62 | #define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */ |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 63 | # define DS1307_BIT_12HR 0x40 /* in REG_HOUR */ |
| 64 | # define DS1307_BIT_PM 0x20 /* in REG_HOUR */ |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 65 | # define DS1340_BIT_CENTURY_EN 0x80 /* in REG_HOUR */ |
| 66 | # define DS1340_BIT_CENTURY 0x40 /* in REG_HOUR */ |
| 67 | #define DS1307_REG_WDAY 0x03 /* 01-07 */ |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 68 | # define MCP794XX_BIT_VBATEN 0x08 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 69 | #define DS1307_REG_MDAY 0x04 /* 01-31 */ |
| 70 | #define DS1307_REG_MONTH 0x05 /* 01-12 */ |
| 71 | # define DS1337_BIT_CENTURY 0x80 /* in REG_MONTH */ |
| 72 | #define DS1307_REG_YEAR 0x06 /* 00-99 */ |
| 73 | |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 74 | /* |
| 75 | * Other registers (control, status, alarms, trickle charge, NVRAM, etc) |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 76 | * start at 7, and they differ a LOT. Only control and status matter for |
| 77 | * basic RTC date and time functionality; be careful using them. |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 78 | */ |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 79 | #define DS1307_REG_CONTROL 0x07 /* or ds1338 */ |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 80 | # define DS1307_BIT_OUT 0x80 |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 81 | # define DS1338_BIT_OSF 0x20 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 82 | # define DS1307_BIT_SQWE 0x10 |
| 83 | # define DS1307_BIT_RS1 0x02 |
| 84 | # define DS1307_BIT_RS0 0x01 |
| 85 | #define DS1337_REG_CONTROL 0x0e |
| 86 | # define DS1337_BIT_nEOSC 0x80 |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 87 | # define DS1339_BIT_BBSQI 0x20 |
Wolfram Sang | 97f902b | 2009-06-17 16:26:10 -0700 | [diff] [blame] | 88 | # define DS3231_BIT_BBSQW 0x40 /* same as BBSQI */ |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 89 | # define DS1337_BIT_RS2 0x10 |
| 90 | # define DS1337_BIT_RS1 0x08 |
| 91 | # define DS1337_BIT_INTCN 0x04 |
| 92 | # define DS1337_BIT_A2IE 0x02 |
| 93 | # define DS1337_BIT_A1IE 0x01 |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 94 | #define DS1340_REG_CONTROL 0x07 |
| 95 | # define DS1340_BIT_OUT 0x80 |
| 96 | # define DS1340_BIT_FT 0x40 |
| 97 | # define DS1340_BIT_CALIB_SIGN 0x20 |
| 98 | # define DS1340_M_CALIBRATION 0x1f |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 99 | #define DS1340_REG_FLAG 0x09 |
| 100 | # define DS1340_BIT_OSF 0x80 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 101 | #define DS1337_REG_STATUS 0x0f |
| 102 | # define DS1337_BIT_OSF 0x80 |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 103 | # define DS3231_BIT_EN32KHZ 0x08 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 104 | # define DS1337_BIT_A2I 0x02 |
| 105 | # define DS1337_BIT_A1I 0x01 |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 106 | #define DS1339_REG_ALARM1_SECS 0x07 |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 107 | |
| 108 | #define DS13XX_TRICKLE_CHARGER_MAGIC 0xa0 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 109 | |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 110 | #define RX8025_REG_CTRL1 0x0e |
| 111 | # define RX8025_BIT_2412 0x20 |
| 112 | #define RX8025_REG_CTRL2 0x0f |
| 113 | # define RX8025_BIT_PON 0x10 |
| 114 | # define RX8025_BIT_VDET 0x40 |
| 115 | # define RX8025_BIT_XST 0x20 |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 116 | |
Uwe Kleine-König | 92cbf12 | 2019-01-25 15:35:54 +0100 | [diff] [blame] | 117 | #define RX8130_REG_ALARM_MIN 0x07 |
| 118 | #define RX8130_REG_ALARM_HOUR 0x08 |
| 119 | #define RX8130_REG_ALARM_WEEK_OR_DAY 0x09 |
| 120 | #define RX8130_REG_EXTENSION 0x0c |
| 121 | #define RX8130_REG_EXTENSION_WADA BIT(3) |
| 122 | #define RX8130_REG_FLAG 0x0d |
| 123 | #define RX8130_REG_FLAG_AF BIT(3) |
| 124 | #define RX8130_REG_CONTROL0 0x0e |
| 125 | #define RX8130_REG_CONTROL0_AIE BIT(3) |
| 126 | |
| 127 | #define MCP794XX_REG_CONTROL 0x07 |
| 128 | # define MCP794XX_BIT_ALM0_EN 0x10 |
| 129 | # define MCP794XX_BIT_ALM1_EN 0x20 |
| 130 | #define MCP794XX_REG_ALARM0_BASE 0x0a |
| 131 | #define MCP794XX_REG_ALARM0_CTRL 0x0d |
| 132 | #define MCP794XX_REG_ALARM1_BASE 0x11 |
| 133 | #define MCP794XX_REG_ALARM1_CTRL 0x14 |
| 134 | # define MCP794XX_BIT_ALMX_IF BIT(3) |
| 135 | # define MCP794XX_BIT_ALMX_C0 BIT(4) |
| 136 | # define MCP794XX_BIT_ALMX_C1 BIT(5) |
| 137 | # define MCP794XX_BIT_ALMX_C2 BIT(6) |
| 138 | # define MCP794XX_BIT_ALMX_POL BIT(7) |
| 139 | # define MCP794XX_MSK_ALMX_MATCH (MCP794XX_BIT_ALMX_C0 | \ |
| 140 | MCP794XX_BIT_ALMX_C1 | \ |
| 141 | MCP794XX_BIT_ALMX_C2) |
| 142 | |
Giulio Benetti | 79230ff | 2018-07-25 19:26:04 +0200 | [diff] [blame] | 143 | #define M41TXX_REG_CONTROL 0x07 |
| 144 | # define M41TXX_BIT_OUT BIT(7) |
| 145 | # define M41TXX_BIT_FT BIT(6) |
| 146 | # define M41TXX_BIT_CALIB_SIGN BIT(5) |
| 147 | # define M41TXX_M_CALIBRATION GENMASK(4, 0) |
| 148 | |
| 149 | /* negative offset step is -2.034ppm */ |
| 150 | #define M41TXX_NEG_OFFSET_STEP_PPB 2034 |
| 151 | /* positive offset step is +4.068ppm */ |
| 152 | #define M41TXX_POS_OFFSET_STEP_PPB 4068 |
| 153 | /* Min and max values supported with 'offset' interface by M41TXX */ |
| 154 | #define M41TXX_MIN_OFFSET ((-31) * M41TXX_NEG_OFFSET_STEP_PPB) |
| 155 | #define M41TXX_MAX_OFFSET ((31) * M41TXX_POS_OFFSET_STEP_PPB) |
| 156 | |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 157 | struct ds1307 { |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 158 | enum ds_type type; |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 159 | unsigned long flags; |
| 160 | #define HAS_NVRAM 0 /* bit 0 == sysfs file active */ |
| 161 | #define HAS_ALARM 1 /* bit 1 == irq claimed */ |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 162 | struct device *dev; |
| 163 | struct regmap *regmap; |
| 164 | const char *name; |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 165 | struct rtc_device *rtc; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 166 | #ifdef CONFIG_COMMON_CLK |
| 167 | struct clk_hw clks[2]; |
| 168 | #endif |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 171 | struct chip_desc { |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 172 | unsigned alarm:1; |
Austin Boyle | 9eab0a7 | 2012-03-23 15:02:38 -0700 | [diff] [blame] | 173 | u16 nvram_offset; |
| 174 | u16 nvram_size; |
Heiner Kallweit | e553170 | 2017-07-12 07:49:47 +0200 | [diff] [blame] | 175 | u8 offset; /* register's offset */ |
Heiner Kallweit | e48585d | 2017-06-05 17:57:33 +0200 | [diff] [blame] | 176 | u8 century_reg; |
| 177 | u8 century_enable_bit; |
| 178 | u8 century_bit; |
Heiner Kallweit | 0b6ee80 | 2017-07-12 07:49:22 +0200 | [diff] [blame] | 179 | u8 bbsqi_bit; |
Heiner Kallweit | 4594712 | 2017-07-12 07:49:41 +0200 | [diff] [blame] | 180 | irq_handler_t irq_handler; |
Heiner Kallweit | 1efb98b | 2017-07-12 07:49:44 +0200 | [diff] [blame] | 181 | const struct rtc_class_ops *rtc_ops; |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 182 | u16 trickle_charger_reg; |
Alexandre Belloni | 57ec2d9 | 2017-09-04 22:46:04 +0200 | [diff] [blame] | 183 | u8 (*do_trickle_setup)(struct ds1307 *, u32, |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 184 | bool); |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Uwe Kleine-König | d0e3f61 | 2019-01-25 15:35:55 +0100 | [diff] [blame^] | 187 | static const struct chip_desc chips[last_ds_type]; |
| 188 | |
| 189 | static int ds1307_get_time(struct device *dev, struct rtc_time *t) |
| 190 | { |
| 191 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 192 | int tmp, ret; |
| 193 | const struct chip_desc *chip = &chips[ds1307->type]; |
| 194 | u8 regs[7]; |
| 195 | |
| 196 | /* read the RTC date and time registers all at once */ |
| 197 | ret = regmap_bulk_read(ds1307->regmap, chip->offset, regs, |
| 198 | sizeof(regs)); |
| 199 | if (ret) { |
| 200 | dev_err(dev, "%s error %d\n", "read", ret); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | dev_dbg(dev, "%s: %7ph\n", "read", regs); |
| 205 | |
| 206 | /* if oscillator fail bit is set, no data can be trusted */ |
| 207 | if (ds1307->type == m41t0 && |
| 208 | regs[DS1307_REG_MIN] & M41T0_BIT_OF) { |
| 209 | dev_warn_once(dev, "oscillator failed, set time!\n"); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | |
| 213 | t->tm_sec = bcd2bin(regs[DS1307_REG_SECS] & 0x7f); |
| 214 | t->tm_min = bcd2bin(regs[DS1307_REG_MIN] & 0x7f); |
| 215 | tmp = regs[DS1307_REG_HOUR] & 0x3f; |
| 216 | t->tm_hour = bcd2bin(tmp); |
| 217 | t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1; |
| 218 | t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f); |
| 219 | tmp = regs[DS1307_REG_MONTH] & 0x1f; |
| 220 | t->tm_mon = bcd2bin(tmp) - 1; |
| 221 | t->tm_year = bcd2bin(regs[DS1307_REG_YEAR]) + 100; |
| 222 | |
| 223 | if (regs[chip->century_reg] & chip->century_bit && |
| 224 | IS_ENABLED(CONFIG_RTC_DRV_DS1307_CENTURY)) |
| 225 | t->tm_year += 100; |
| 226 | |
| 227 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
| 228 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", |
| 229 | "read", t->tm_sec, t->tm_min, |
| 230 | t->tm_hour, t->tm_mday, |
| 231 | t->tm_mon, t->tm_year, t->tm_wday); |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | static int ds1307_set_time(struct device *dev, struct rtc_time *t) |
| 237 | { |
| 238 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 239 | const struct chip_desc *chip = &chips[ds1307->type]; |
| 240 | int result; |
| 241 | int tmp; |
| 242 | u8 regs[7]; |
| 243 | |
| 244 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
| 245 | "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", |
| 246 | "write", t->tm_sec, t->tm_min, |
| 247 | t->tm_hour, t->tm_mday, |
| 248 | t->tm_mon, t->tm_year, t->tm_wday); |
| 249 | |
| 250 | if (t->tm_year < 100) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | #ifdef CONFIG_RTC_DRV_DS1307_CENTURY |
| 254 | if (t->tm_year > (chip->century_bit ? 299 : 199)) |
| 255 | return -EINVAL; |
| 256 | #else |
| 257 | if (t->tm_year > 199) |
| 258 | return -EINVAL; |
| 259 | #endif |
| 260 | |
| 261 | regs[DS1307_REG_SECS] = bin2bcd(t->tm_sec); |
| 262 | regs[DS1307_REG_MIN] = bin2bcd(t->tm_min); |
| 263 | regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour); |
| 264 | regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1); |
| 265 | regs[DS1307_REG_MDAY] = bin2bcd(t->tm_mday); |
| 266 | regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1); |
| 267 | |
| 268 | /* assume 20YY not 19YY */ |
| 269 | tmp = t->tm_year - 100; |
| 270 | regs[DS1307_REG_YEAR] = bin2bcd(tmp); |
| 271 | |
| 272 | if (chip->century_enable_bit) |
| 273 | regs[chip->century_reg] |= chip->century_enable_bit; |
| 274 | if (t->tm_year > 199 && chip->century_bit) |
| 275 | regs[chip->century_reg] |= chip->century_bit; |
| 276 | |
| 277 | if (ds1307->type == mcp794xx) { |
| 278 | /* |
| 279 | * these bits were cleared when preparing the date/time |
| 280 | * values and need to be set again before writing the |
| 281 | * regsfer out to the device. |
| 282 | */ |
| 283 | regs[DS1307_REG_SECS] |= MCP794XX_BIT_ST; |
| 284 | regs[DS1307_REG_WDAY] |= MCP794XX_BIT_VBATEN; |
| 285 | } |
| 286 | |
| 287 | dev_dbg(dev, "%s: %7ph\n", "write", regs); |
| 288 | |
| 289 | result = regmap_bulk_write(ds1307->regmap, chip->offset, regs, |
| 290 | sizeof(regs)); |
| 291 | if (result) { |
| 292 | dev_err(dev, "%s error %d\n", "write", result); |
| 293 | return result; |
| 294 | } |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 299 | { |
| 300 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 301 | int ret; |
| 302 | u8 regs[9]; |
| 303 | |
| 304 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 305 | return -EINVAL; |
| 306 | |
| 307 | /* read all ALARM1, ALARM2, and status registers at once */ |
| 308 | ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, |
| 309 | regs, sizeof(regs)); |
| 310 | if (ret) { |
| 311 | dev_err(dev, "%s error %d\n", "alarm read", ret); |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | dev_dbg(dev, "%s: %4ph, %3ph, %2ph\n", "alarm read", |
| 316 | ®s[0], ®s[4], ®s[7]); |
| 317 | |
| 318 | /* |
| 319 | * report alarm time (ALARM1); assume 24 hour and day-of-month modes, |
| 320 | * and that all four fields are checked matches |
| 321 | */ |
| 322 | t->time.tm_sec = bcd2bin(regs[0] & 0x7f); |
| 323 | t->time.tm_min = bcd2bin(regs[1] & 0x7f); |
| 324 | t->time.tm_hour = bcd2bin(regs[2] & 0x3f); |
| 325 | t->time.tm_mday = bcd2bin(regs[3] & 0x3f); |
| 326 | |
| 327 | /* ... and status */ |
| 328 | t->enabled = !!(regs[7] & DS1337_BIT_A1IE); |
| 329 | t->pending = !!(regs[8] & DS1337_BIT_A1I); |
| 330 | |
| 331 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
| 332 | "hours=%d, mday=%d, enabled=%d, pending=%d\n", |
| 333 | "alarm read", t->time.tm_sec, t->time.tm_min, |
| 334 | t->time.tm_hour, t->time.tm_mday, |
| 335 | t->enabled, t->pending); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 341 | { |
| 342 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 343 | unsigned char regs[9]; |
| 344 | u8 control, status; |
| 345 | int ret; |
| 346 | |
| 347 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 348 | return -EINVAL; |
| 349 | |
| 350 | dev_dbg(dev, "%s secs=%d, mins=%d, " |
| 351 | "hours=%d, mday=%d, enabled=%d, pending=%d\n", |
| 352 | "alarm set", t->time.tm_sec, t->time.tm_min, |
| 353 | t->time.tm_hour, t->time.tm_mday, |
| 354 | t->enabled, t->pending); |
| 355 | |
| 356 | /* read current status of both alarms and the chip */ |
| 357 | ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, |
| 358 | sizeof(regs)); |
| 359 | if (ret) { |
| 360 | dev_err(dev, "%s error %d\n", "alarm write", ret); |
| 361 | return ret; |
| 362 | } |
| 363 | control = regs[7]; |
| 364 | status = regs[8]; |
| 365 | |
| 366 | dev_dbg(dev, "%s: %4ph, %3ph, %02x %02x\n", "alarm set (old status)", |
| 367 | ®s[0], ®s[4], control, status); |
| 368 | |
| 369 | /* set ALARM1, using 24 hour and day-of-month modes */ |
| 370 | regs[0] = bin2bcd(t->time.tm_sec); |
| 371 | regs[1] = bin2bcd(t->time.tm_min); |
| 372 | regs[2] = bin2bcd(t->time.tm_hour); |
| 373 | regs[3] = bin2bcd(t->time.tm_mday); |
| 374 | |
| 375 | /* set ALARM2 to non-garbage */ |
| 376 | regs[4] = 0; |
| 377 | regs[5] = 0; |
| 378 | regs[6] = 0; |
| 379 | |
| 380 | /* disable alarms */ |
| 381 | regs[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE); |
| 382 | regs[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I); |
| 383 | |
| 384 | ret = regmap_bulk_write(ds1307->regmap, DS1339_REG_ALARM1_SECS, regs, |
| 385 | sizeof(regs)); |
| 386 | if (ret) { |
| 387 | dev_err(dev, "can't set alarm time\n"); |
| 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | /* optionally enable ALARM1 */ |
| 392 | if (t->enabled) { |
| 393 | dev_dbg(dev, "alarm IRQ armed\n"); |
| 394 | regs[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */ |
| 395 | regmap_write(ds1307->regmap, DS1337_REG_CONTROL, regs[7]); |
| 396 | } |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static int ds1307_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 402 | { |
| 403 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 404 | |
| 405 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 406 | return -ENOTTY; |
| 407 | |
| 408 | return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, |
| 409 | DS1337_BIT_A1IE, |
| 410 | enabled ? DS1337_BIT_A1IE : 0); |
| 411 | } |
| 412 | |
| 413 | static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, u32 ohms, bool diode) |
| 414 | { |
| 415 | u8 setup = (diode) ? DS1307_TRICKLE_CHARGER_DIODE : |
| 416 | DS1307_TRICKLE_CHARGER_NO_DIODE; |
| 417 | |
| 418 | switch (ohms) { |
| 419 | case 250: |
| 420 | setup |= DS1307_TRICKLE_CHARGER_250_OHM; |
| 421 | break; |
| 422 | case 2000: |
| 423 | setup |= DS1307_TRICKLE_CHARGER_2K_OHM; |
| 424 | break; |
| 425 | case 4000: |
| 426 | setup |= DS1307_TRICKLE_CHARGER_4K_OHM; |
| 427 | break; |
| 428 | default: |
| 429 | dev_warn(ds1307->dev, |
| 430 | "Unsupported ohm value %u in dt\n", ohms); |
| 431 | return 0; |
| 432 | } |
| 433 | return setup; |
| 434 | } |
| 435 | |
| 436 | static irqreturn_t rx8130_irq(int irq, void *dev_id) |
| 437 | { |
| 438 | struct ds1307 *ds1307 = dev_id; |
| 439 | struct mutex *lock = &ds1307->rtc->ops_lock; |
| 440 | u8 ctl[3]; |
| 441 | int ret; |
| 442 | |
| 443 | mutex_lock(lock); |
| 444 | |
| 445 | /* Read control registers. */ |
| 446 | ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, |
| 447 | sizeof(ctl)); |
| 448 | if (ret < 0) |
| 449 | goto out; |
| 450 | if (!(ctl[1] & RX8130_REG_FLAG_AF)) |
| 451 | goto out; |
| 452 | ctl[1] &= ~RX8130_REG_FLAG_AF; |
| 453 | ctl[2] &= ~RX8130_REG_CONTROL0_AIE; |
| 454 | |
| 455 | ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, |
| 456 | sizeof(ctl)); |
| 457 | if (ret < 0) |
| 458 | goto out; |
| 459 | |
| 460 | rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); |
| 461 | |
| 462 | out: |
| 463 | mutex_unlock(lock); |
| 464 | |
| 465 | return IRQ_HANDLED; |
| 466 | } |
| 467 | |
| 468 | static int rx8130_read_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 469 | { |
| 470 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 471 | u8 ald[3], ctl[3]; |
| 472 | int ret; |
| 473 | |
| 474 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 475 | return -EINVAL; |
| 476 | |
| 477 | /* Read alarm registers. */ |
| 478 | ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, |
| 479 | sizeof(ald)); |
| 480 | if (ret < 0) |
| 481 | return ret; |
| 482 | |
| 483 | /* Read control registers. */ |
| 484 | ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, |
| 485 | sizeof(ctl)); |
| 486 | if (ret < 0) |
| 487 | return ret; |
| 488 | |
| 489 | t->enabled = !!(ctl[2] & RX8130_REG_CONTROL0_AIE); |
| 490 | t->pending = !!(ctl[1] & RX8130_REG_FLAG_AF); |
| 491 | |
| 492 | /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ |
| 493 | t->time.tm_sec = -1; |
| 494 | t->time.tm_min = bcd2bin(ald[0] & 0x7f); |
| 495 | t->time.tm_hour = bcd2bin(ald[1] & 0x7f); |
| 496 | t->time.tm_wday = -1; |
| 497 | t->time.tm_mday = bcd2bin(ald[2] & 0x7f); |
| 498 | t->time.tm_mon = -1; |
| 499 | t->time.tm_year = -1; |
| 500 | t->time.tm_yday = -1; |
| 501 | t->time.tm_isdst = -1; |
| 502 | |
| 503 | dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d enabled=%d\n", |
| 504 | __func__, t->time.tm_sec, t->time.tm_min, t->time.tm_hour, |
| 505 | t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled); |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static int rx8130_set_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 511 | { |
| 512 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 513 | u8 ald[3], ctl[3]; |
| 514 | int ret; |
| 515 | |
| 516 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 517 | return -EINVAL; |
| 518 | |
| 519 | dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d " |
| 520 | "enabled=%d pending=%d\n", __func__, |
| 521 | t->time.tm_sec, t->time.tm_min, t->time.tm_hour, |
| 522 | t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, |
| 523 | t->enabled, t->pending); |
| 524 | |
| 525 | /* Read control registers. */ |
| 526 | ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, |
| 527 | sizeof(ctl)); |
| 528 | if (ret < 0) |
| 529 | return ret; |
| 530 | |
| 531 | ctl[0] &= ~RX8130_REG_EXTENSION_WADA; |
| 532 | ctl[1] |= RX8130_REG_FLAG_AF; |
| 533 | ctl[2] &= ~RX8130_REG_CONTROL0_AIE; |
| 534 | |
| 535 | ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, |
| 536 | sizeof(ctl)); |
| 537 | if (ret < 0) |
| 538 | return ret; |
| 539 | |
| 540 | /* Hardware alarm precision is 1 minute! */ |
| 541 | ald[0] = bin2bcd(t->time.tm_min); |
| 542 | ald[1] = bin2bcd(t->time.tm_hour); |
| 543 | ald[2] = bin2bcd(t->time.tm_mday); |
| 544 | |
| 545 | ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, |
| 546 | sizeof(ald)); |
| 547 | if (ret < 0) |
| 548 | return ret; |
| 549 | |
| 550 | if (!t->enabled) |
| 551 | return 0; |
| 552 | |
| 553 | ctl[2] |= RX8130_REG_CONTROL0_AIE; |
| 554 | |
| 555 | return regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, |
| 556 | sizeof(ctl)); |
| 557 | } |
| 558 | |
| 559 | static int rx8130_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 560 | { |
| 561 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 562 | int ret, reg; |
| 563 | |
| 564 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 565 | return -EINVAL; |
| 566 | |
| 567 | ret = regmap_read(ds1307->regmap, RX8130_REG_CONTROL0, ®); |
| 568 | if (ret < 0) |
| 569 | return ret; |
| 570 | |
| 571 | if (enabled) |
| 572 | reg |= RX8130_REG_CONTROL0_AIE; |
| 573 | else |
| 574 | reg &= ~RX8130_REG_CONTROL0_AIE; |
| 575 | |
| 576 | return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg); |
| 577 | } |
| 578 | |
| 579 | static irqreturn_t mcp794xx_irq(int irq, void *dev_id) |
| 580 | { |
| 581 | struct ds1307 *ds1307 = dev_id; |
| 582 | struct mutex *lock = &ds1307->rtc->ops_lock; |
| 583 | int reg, ret; |
| 584 | |
| 585 | mutex_lock(lock); |
| 586 | |
| 587 | /* Check and clear alarm 0 interrupt flag. */ |
| 588 | ret = regmap_read(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, ®); |
| 589 | if (ret) |
| 590 | goto out; |
| 591 | if (!(reg & MCP794XX_BIT_ALMX_IF)) |
| 592 | goto out; |
| 593 | reg &= ~MCP794XX_BIT_ALMX_IF; |
| 594 | ret = regmap_write(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, reg); |
| 595 | if (ret) |
| 596 | goto out; |
| 597 | |
| 598 | /* Disable alarm 0. */ |
| 599 | ret = regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, |
| 600 | MCP794XX_BIT_ALM0_EN, 0); |
| 601 | if (ret) |
| 602 | goto out; |
| 603 | |
| 604 | rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); |
| 605 | |
| 606 | out: |
| 607 | mutex_unlock(lock); |
| 608 | |
| 609 | return IRQ_HANDLED; |
| 610 | } |
| 611 | |
| 612 | static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 613 | { |
| 614 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 615 | u8 regs[10]; |
| 616 | int ret; |
| 617 | |
| 618 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 619 | return -EINVAL; |
| 620 | |
| 621 | /* Read control and alarm 0 registers. */ |
| 622 | ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, |
| 623 | sizeof(regs)); |
| 624 | if (ret) |
| 625 | return ret; |
| 626 | |
| 627 | t->enabled = !!(regs[0] & MCP794XX_BIT_ALM0_EN); |
| 628 | |
| 629 | /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ |
| 630 | t->time.tm_sec = bcd2bin(regs[3] & 0x7f); |
| 631 | t->time.tm_min = bcd2bin(regs[4] & 0x7f); |
| 632 | t->time.tm_hour = bcd2bin(regs[5] & 0x3f); |
| 633 | t->time.tm_wday = bcd2bin(regs[6] & 0x7) - 1; |
| 634 | t->time.tm_mday = bcd2bin(regs[7] & 0x3f); |
| 635 | t->time.tm_mon = bcd2bin(regs[8] & 0x1f) - 1; |
| 636 | t->time.tm_year = -1; |
| 637 | t->time.tm_yday = -1; |
| 638 | t->time.tm_isdst = -1; |
| 639 | |
| 640 | dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d " |
| 641 | "enabled=%d polarity=%d irq=%d match=%lu\n", __func__, |
| 642 | t->time.tm_sec, t->time.tm_min, t->time.tm_hour, |
| 643 | t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled, |
| 644 | !!(regs[6] & MCP794XX_BIT_ALMX_POL), |
| 645 | !!(regs[6] & MCP794XX_BIT_ALMX_IF), |
| 646 | (regs[6] & MCP794XX_MSK_ALMX_MATCH) >> 4); |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | * We may have a random RTC weekday, therefore calculate alarm weekday based |
| 653 | * on current weekday we read from the RTC timekeeping regs |
| 654 | */ |
| 655 | static int mcp794xx_alm_weekday(struct device *dev, struct rtc_time *tm_alarm) |
| 656 | { |
| 657 | struct rtc_time tm_now; |
| 658 | int days_now, days_alarm, ret; |
| 659 | |
| 660 | ret = ds1307_get_time(dev, &tm_now); |
| 661 | if (ret) |
| 662 | return ret; |
| 663 | |
| 664 | days_now = div_s64(rtc_tm_to_time64(&tm_now), 24 * 60 * 60); |
| 665 | days_alarm = div_s64(rtc_tm_to_time64(tm_alarm), 24 * 60 * 60); |
| 666 | |
| 667 | return (tm_now.tm_wday + days_alarm - days_now) % 7 + 1; |
| 668 | } |
| 669 | |
| 670 | static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 671 | { |
| 672 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 673 | unsigned char regs[10]; |
| 674 | int wday, ret; |
| 675 | |
| 676 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 677 | return -EINVAL; |
| 678 | |
| 679 | wday = mcp794xx_alm_weekday(dev, &t->time); |
| 680 | if (wday < 0) |
| 681 | return wday; |
| 682 | |
| 683 | dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d " |
| 684 | "enabled=%d pending=%d\n", __func__, |
| 685 | t->time.tm_sec, t->time.tm_min, t->time.tm_hour, |
| 686 | t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, |
| 687 | t->enabled, t->pending); |
| 688 | |
| 689 | /* Read control and alarm 0 registers. */ |
| 690 | ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, |
| 691 | sizeof(regs)); |
| 692 | if (ret) |
| 693 | return ret; |
| 694 | |
| 695 | /* Set alarm 0, using 24-hour and day-of-month modes. */ |
| 696 | regs[3] = bin2bcd(t->time.tm_sec); |
| 697 | regs[4] = bin2bcd(t->time.tm_min); |
| 698 | regs[5] = bin2bcd(t->time.tm_hour); |
| 699 | regs[6] = wday; |
| 700 | regs[7] = bin2bcd(t->time.tm_mday); |
| 701 | regs[8] = bin2bcd(t->time.tm_mon + 1); |
| 702 | |
| 703 | /* Clear the alarm 0 interrupt flag. */ |
| 704 | regs[6] &= ~MCP794XX_BIT_ALMX_IF; |
| 705 | /* Set alarm match: second, minute, hour, day, date, month. */ |
| 706 | regs[6] |= MCP794XX_MSK_ALMX_MATCH; |
| 707 | /* Disable interrupt. We will not enable until completely programmed */ |
| 708 | regs[0] &= ~MCP794XX_BIT_ALM0_EN; |
| 709 | |
| 710 | ret = regmap_bulk_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs, |
| 711 | sizeof(regs)); |
| 712 | if (ret) |
| 713 | return ret; |
| 714 | |
| 715 | if (!t->enabled) |
| 716 | return 0; |
| 717 | regs[0] |= MCP794XX_BIT_ALM0_EN; |
| 718 | return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs[0]); |
| 719 | } |
| 720 | |
| 721 | static int mcp794xx_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 722 | { |
| 723 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 724 | |
| 725 | if (!test_bit(HAS_ALARM, &ds1307->flags)) |
| 726 | return -EINVAL; |
| 727 | |
| 728 | return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, |
| 729 | MCP794XX_BIT_ALM0_EN, |
| 730 | enabled ? MCP794XX_BIT_ALM0_EN : 0); |
| 731 | } |
| 732 | |
| 733 | static int m41txx_rtc_read_offset(struct device *dev, long *offset) |
| 734 | { |
| 735 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 736 | unsigned int ctrl_reg; |
| 737 | u8 val; |
| 738 | |
| 739 | regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); |
| 740 | |
| 741 | val = ctrl_reg & M41TXX_M_CALIBRATION; |
| 742 | |
| 743 | /* check if positive */ |
| 744 | if (ctrl_reg & M41TXX_BIT_CALIB_SIGN) |
| 745 | *offset = (val * M41TXX_POS_OFFSET_STEP_PPB); |
| 746 | else |
| 747 | *offset = -(val * M41TXX_NEG_OFFSET_STEP_PPB); |
| 748 | |
| 749 | return 0; |
| 750 | } |
| 751 | |
| 752 | static int m41txx_rtc_set_offset(struct device *dev, long offset) |
| 753 | { |
| 754 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 755 | unsigned int ctrl_reg; |
| 756 | |
| 757 | if ((offset < M41TXX_MIN_OFFSET) || (offset > M41TXX_MAX_OFFSET)) |
| 758 | return -ERANGE; |
| 759 | |
| 760 | if (offset >= 0) { |
| 761 | ctrl_reg = DIV_ROUND_CLOSEST(offset, |
| 762 | M41TXX_POS_OFFSET_STEP_PPB); |
| 763 | ctrl_reg |= M41TXX_BIT_CALIB_SIGN; |
| 764 | } else { |
| 765 | ctrl_reg = DIV_ROUND_CLOSEST(abs(offset), |
| 766 | M41TXX_NEG_OFFSET_STEP_PPB); |
| 767 | } |
| 768 | |
| 769 | return regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, |
| 770 | M41TXX_M_CALIBRATION | M41TXX_BIT_CALIB_SIGN, |
| 771 | ctrl_reg); |
| 772 | } |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 773 | |
Heiner Kallweit | 1efb98b | 2017-07-12 07:49:44 +0200 | [diff] [blame] | 774 | static const struct rtc_class_ops rx8130_rtc_ops = { |
| 775 | .read_time = ds1307_get_time, |
| 776 | .set_time = ds1307_set_time, |
| 777 | .read_alarm = rx8130_read_alarm, |
| 778 | .set_alarm = rx8130_set_alarm, |
| 779 | .alarm_irq_enable = rx8130_alarm_irq_enable, |
| 780 | }; |
| 781 | |
| 782 | static const struct rtc_class_ops mcp794xx_rtc_ops = { |
| 783 | .read_time = ds1307_get_time, |
| 784 | .set_time = ds1307_set_time, |
| 785 | .read_alarm = mcp794xx_read_alarm, |
| 786 | .set_alarm = mcp794xx_set_alarm, |
| 787 | .alarm_irq_enable = mcp794xx_alarm_irq_enable, |
| 788 | }; |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 789 | |
Giulio Benetti | 79230ff | 2018-07-25 19:26:04 +0200 | [diff] [blame] | 790 | static const struct rtc_class_ops m41txx_rtc_ops = { |
| 791 | .read_time = ds1307_get_time, |
| 792 | .set_time = ds1307_set_time, |
| 793 | .read_alarm = ds1337_read_alarm, |
| 794 | .set_alarm = ds1337_set_alarm, |
| 795 | .alarm_irq_enable = ds1307_alarm_irq_enable, |
| 796 | .read_offset = m41txx_rtc_read_offset, |
| 797 | .set_offset = m41txx_rtc_set_offset, |
| 798 | }; |
| 799 | |
Heiner Kallweit | 7624df4 | 2017-07-12 07:49:33 +0200 | [diff] [blame] | 800 | static const struct chip_desc chips[last_ds_type] = { |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 801 | [ds_1307] = { |
Austin Boyle | 9eab0a7 | 2012-03-23 15:02:38 -0700 | [diff] [blame] | 802 | .nvram_offset = 8, |
| 803 | .nvram_size = 56, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 804 | }, |
Sean Nyekjaer | 300a773 | 2017-06-08 12:36:54 +0200 | [diff] [blame] | 805 | [ds_1308] = { |
| 806 | .nvram_offset = 8, |
| 807 | .nvram_size = 56, |
| 808 | }, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 809 | [ds_1337] = { |
| 810 | .alarm = 1, |
Heiner Kallweit | e48585d | 2017-06-05 17:57:33 +0200 | [diff] [blame] | 811 | .century_reg = DS1307_REG_MONTH, |
| 812 | .century_bit = DS1337_BIT_CENTURY, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 813 | }, |
| 814 | [ds_1338] = { |
Austin Boyle | 9eab0a7 | 2012-03-23 15:02:38 -0700 | [diff] [blame] | 815 | .nvram_offset = 8, |
| 816 | .nvram_size = 56, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 817 | }, |
| 818 | [ds_1339] = { |
| 819 | .alarm = 1, |
Heiner Kallweit | e48585d | 2017-06-05 17:57:33 +0200 | [diff] [blame] | 820 | .century_reg = DS1307_REG_MONTH, |
| 821 | .century_bit = DS1337_BIT_CENTURY, |
Heiner Kallweit | 0b6ee80 | 2017-07-12 07:49:22 +0200 | [diff] [blame] | 822 | .bbsqi_bit = DS1339_BIT_BBSQI, |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 823 | .trickle_charger_reg = 0x10, |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 824 | .do_trickle_setup = &do_trickle_setup_ds1339, |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 825 | }, |
| 826 | [ds_1340] = { |
Heiner Kallweit | e48585d | 2017-06-05 17:57:33 +0200 | [diff] [blame] | 827 | .century_reg = DS1307_REG_HOUR, |
| 828 | .century_enable_bit = DS1340_BIT_CENTURY_EN, |
| 829 | .century_bit = DS1340_BIT_CENTURY, |
Andrea Greco | 51ed73eb | 2018-04-20 11:34:02 +0200 | [diff] [blame] | 830 | .do_trickle_setup = &do_trickle_setup_ds1339, |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 831 | .trickle_charger_reg = 0x08, |
| 832 | }, |
Nikita Yushchenko | 0759c88 | 2017-08-24 09:32:11 +0300 | [diff] [blame] | 833 | [ds_1341] = { |
| 834 | .century_reg = DS1307_REG_MONTH, |
| 835 | .century_bit = DS1337_BIT_CENTURY, |
| 836 | }, |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 837 | [ds_1388] = { |
Heiner Kallweit | e553170 | 2017-07-12 07:49:47 +0200 | [diff] [blame] | 838 | .offset = 1, |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 839 | .trickle_charger_reg = 0x0a, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 840 | }, |
| 841 | [ds_3231] = { |
| 842 | .alarm = 1, |
Heiner Kallweit | e48585d | 2017-06-05 17:57:33 +0200 | [diff] [blame] | 843 | .century_reg = DS1307_REG_MONTH, |
| 844 | .century_bit = DS1337_BIT_CENTURY, |
Heiner Kallweit | 0b6ee80 | 2017-07-12 07:49:22 +0200 | [diff] [blame] | 845 | .bbsqi_bit = DS3231_BIT_BBSQW, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 846 | }, |
Marek Vasut | ee0981b | 2017-06-18 22:55:28 +0200 | [diff] [blame] | 847 | [rx_8130] = { |
| 848 | .alarm = 1, |
| 849 | /* this is battery backed SRAM */ |
| 850 | .nvram_offset = 0x20, |
| 851 | .nvram_size = 4, /* 32bit (4 word x 8 bit) */ |
Heiner Kallweit | e553170 | 2017-07-12 07:49:47 +0200 | [diff] [blame] | 852 | .offset = 0x10, |
Heiner Kallweit | 4594712 | 2017-07-12 07:49:41 +0200 | [diff] [blame] | 853 | .irq_handler = rx8130_irq, |
Heiner Kallweit | 1efb98b | 2017-07-12 07:49:44 +0200 | [diff] [blame] | 854 | .rtc_ops = &rx8130_rtc_ops, |
Marek Vasut | ee0981b | 2017-06-18 22:55:28 +0200 | [diff] [blame] | 855 | }, |
Giulio Benetti | 79230ff | 2018-07-25 19:26:04 +0200 | [diff] [blame] | 856 | [m41t0] = { |
| 857 | .rtc_ops = &m41txx_rtc_ops, |
| 858 | }, |
| 859 | [m41t00] = { |
| 860 | .rtc_ops = &m41txx_rtc_ops, |
| 861 | }, |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 862 | [m41t11] = { |
| 863 | /* this is battery backed SRAM */ |
| 864 | .nvram_offset = 8, |
| 865 | .nvram_size = 56, |
Giulio Benetti | 79230ff | 2018-07-25 19:26:04 +0200 | [diff] [blame] | 866 | .rtc_ops = &m41txx_rtc_ops, |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 867 | }, |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 868 | [mcp794xx] = { |
Simon Guinot | 1d1945d | 2014-04-03 14:49:55 -0700 | [diff] [blame] | 869 | .alarm = 1, |
Austin Boyle | 9eab0a7 | 2012-03-23 15:02:38 -0700 | [diff] [blame] | 870 | /* this is battery backed SRAM */ |
| 871 | .nvram_offset = 0x20, |
| 872 | .nvram_size = 0x40, |
Heiner Kallweit | 4594712 | 2017-07-12 07:49:41 +0200 | [diff] [blame] | 873 | .irq_handler = mcp794xx_irq, |
Heiner Kallweit | 1efb98b | 2017-07-12 07:49:44 +0200 | [diff] [blame] | 874 | .rtc_ops = &mcp794xx_rtc_ops, |
Austin Boyle | 9eab0a7 | 2012-03-23 15:02:38 -0700 | [diff] [blame] | 875 | }, |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 876 | }; |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 877 | |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 878 | static const struct i2c_device_id ds1307_id[] = { |
| 879 | { "ds1307", ds_1307 }, |
Sean Nyekjaer | 300a773 | 2017-06-08 12:36:54 +0200 | [diff] [blame] | 880 | { "ds1308", ds_1308 }, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 881 | { "ds1337", ds_1337 }, |
| 882 | { "ds1338", ds_1338 }, |
| 883 | { "ds1339", ds_1339 }, |
Joakim Tjernlund | 33df2ee | 2009-06-17 16:26:08 -0700 | [diff] [blame] | 884 | { "ds1388", ds_1388 }, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 885 | { "ds1340", ds_1340 }, |
Nikita Yushchenko | 0759c88 | 2017-08-24 09:32:11 +0300 | [diff] [blame] | 886 | { "ds1341", ds_1341 }, |
Wolfram Sang | 97f902b | 2009-06-17 16:26:10 -0700 | [diff] [blame] | 887 | { "ds3231", ds_3231 }, |
Stefan Agner | 8566f70 | 2017-03-23 16:54:57 -0700 | [diff] [blame] | 888 | { "m41t0", m41t0 }, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 889 | { "m41t00", m41t00 }, |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 890 | { "m41t11", m41t11 }, |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 891 | { "mcp7940x", mcp794xx }, |
| 892 | { "mcp7941x", mcp794xx }, |
Priyanka Jain | 31c1771 | 2011-06-27 16:18:04 -0700 | [diff] [blame] | 893 | { "pt7c4338", ds_1307 }, |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 894 | { "rx8025", rx_8025 }, |
Alexandre Belloni | 78aaa06 | 2016-07-13 02:36:41 +0200 | [diff] [blame] | 895 | { "isl12057", ds_1337 }, |
Marek Vasut | ee0981b | 2017-06-18 22:55:28 +0200 | [diff] [blame] | 896 | { "rx8130", rx_8130 }, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 897 | { } |
| 898 | }; |
| 899 | MODULE_DEVICE_TABLE(i2c, ds1307_id); |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 900 | |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 901 | #ifdef CONFIG_OF |
| 902 | static const struct of_device_id ds1307_of_match[] = { |
| 903 | { |
| 904 | .compatible = "dallas,ds1307", |
| 905 | .data = (void *)ds_1307 |
| 906 | }, |
| 907 | { |
Sean Nyekjaer | 300a773 | 2017-06-08 12:36:54 +0200 | [diff] [blame] | 908 | .compatible = "dallas,ds1308", |
| 909 | .data = (void *)ds_1308 |
| 910 | }, |
| 911 | { |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 912 | .compatible = "dallas,ds1337", |
| 913 | .data = (void *)ds_1337 |
| 914 | }, |
| 915 | { |
| 916 | .compatible = "dallas,ds1338", |
| 917 | .data = (void *)ds_1338 |
| 918 | }, |
| 919 | { |
| 920 | .compatible = "dallas,ds1339", |
| 921 | .data = (void *)ds_1339 |
| 922 | }, |
| 923 | { |
| 924 | .compatible = "dallas,ds1388", |
| 925 | .data = (void *)ds_1388 |
| 926 | }, |
| 927 | { |
| 928 | .compatible = "dallas,ds1340", |
| 929 | .data = (void *)ds_1340 |
| 930 | }, |
| 931 | { |
Nikita Yushchenko | 0759c88 | 2017-08-24 09:32:11 +0300 | [diff] [blame] | 932 | .compatible = "dallas,ds1341", |
| 933 | .data = (void *)ds_1341 |
| 934 | }, |
| 935 | { |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 936 | .compatible = "maxim,ds3231", |
| 937 | .data = (void *)ds_3231 |
| 938 | }, |
| 939 | { |
Alexandre Belloni | db2f814 | 2017-04-08 17:22:02 +0200 | [diff] [blame] | 940 | .compatible = "st,m41t0", |
Giulio Benetti | 146a552 | 2018-05-16 23:08:39 +0200 | [diff] [blame] | 941 | .data = (void *)m41t0 |
Alexandre Belloni | db2f814 | 2017-04-08 17:22:02 +0200 | [diff] [blame] | 942 | }, |
| 943 | { |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 944 | .compatible = "st,m41t00", |
| 945 | .data = (void *)m41t00 |
| 946 | }, |
| 947 | { |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 948 | .compatible = "st,m41t11", |
| 949 | .data = (void *)m41t11 |
| 950 | }, |
| 951 | { |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 952 | .compatible = "microchip,mcp7940x", |
| 953 | .data = (void *)mcp794xx |
| 954 | }, |
| 955 | { |
| 956 | .compatible = "microchip,mcp7941x", |
| 957 | .data = (void *)mcp794xx |
| 958 | }, |
| 959 | { |
| 960 | .compatible = "pericom,pt7c4338", |
| 961 | .data = (void *)ds_1307 |
| 962 | }, |
| 963 | { |
| 964 | .compatible = "epson,rx8025", |
| 965 | .data = (void *)rx_8025 |
| 966 | }, |
| 967 | { |
| 968 | .compatible = "isil,isl12057", |
| 969 | .data = (void *)ds_1337 |
| 970 | }, |
Bastian Stender | 47dd472 | 2017-10-17 14:46:07 +0200 | [diff] [blame] | 971 | { |
| 972 | .compatible = "epson,rx8130", |
| 973 | .data = (void *)rx_8130 |
| 974 | }, |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 975 | { } |
| 976 | }; |
| 977 | MODULE_DEVICE_TABLE(of, ds1307_of_match); |
| 978 | #endif |
| 979 | |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 980 | #ifdef CONFIG_ACPI |
| 981 | static const struct acpi_device_id ds1307_acpi_ids[] = { |
| 982 | { .id = "DS1307", .driver_data = ds_1307 }, |
Sean Nyekjaer | 300a773 | 2017-06-08 12:36:54 +0200 | [diff] [blame] | 983 | { .id = "DS1308", .driver_data = ds_1308 }, |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 984 | { .id = "DS1337", .driver_data = ds_1337 }, |
| 985 | { .id = "DS1338", .driver_data = ds_1338 }, |
| 986 | { .id = "DS1339", .driver_data = ds_1339 }, |
| 987 | { .id = "DS1388", .driver_data = ds_1388 }, |
| 988 | { .id = "DS1340", .driver_data = ds_1340 }, |
Nikita Yushchenko | 0759c88 | 2017-08-24 09:32:11 +0300 | [diff] [blame] | 989 | { .id = "DS1341", .driver_data = ds_1341 }, |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 990 | { .id = "DS3231", .driver_data = ds_3231 }, |
Stefan Agner | 8566f70 | 2017-03-23 16:54:57 -0700 | [diff] [blame] | 991 | { .id = "M41T0", .driver_data = m41t0 }, |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 992 | { .id = "M41T00", .driver_data = m41t00 }, |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 993 | { .id = "M41T11", .driver_data = m41t11 }, |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 994 | { .id = "MCP7940X", .driver_data = mcp794xx }, |
| 995 | { .id = "MCP7941X", .driver_data = mcp794xx }, |
| 996 | { .id = "PT7C4338", .driver_data = ds_1307 }, |
| 997 | { .id = "RX8025", .driver_data = rx_8025 }, |
| 998 | { .id = "ISL12057", .driver_data = ds_1337 }, |
Bastian Stender | 47dd472 | 2017-10-17 14:46:07 +0200 | [diff] [blame] | 999 | { .id = "RX8130", .driver_data = rx_8130 }, |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 1000 | { } |
| 1001 | }; |
| 1002 | MODULE_DEVICE_TABLE(acpi, ds1307_acpi_ids); |
| 1003 | #endif |
| 1004 | |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1005 | /* |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1006 | * The ds1337 and ds1339 both have two alarms, but we only use the first |
| 1007 | * one (with a "seconds" field). For ds1337 we expect nINTA is our alarm |
| 1008 | * signal; ds1339 chips have only one alarm signal. |
| 1009 | */ |
Felipe Balbi | 2fb07a1 | 2015-06-23 11:15:10 -0500 | [diff] [blame] | 1010 | static irqreturn_t ds1307_irq(int irq, void *dev_id) |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1011 | { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1012 | struct ds1307 *ds1307 = dev_id; |
Felipe Balbi | 2fb07a1 | 2015-06-23 11:15:10 -0500 | [diff] [blame] | 1013 | struct mutex *lock = &ds1307->rtc->ops_lock; |
Heiner Kallweit | 078f3f6 | 2017-06-05 17:57:29 +0200 | [diff] [blame] | 1014 | int stat, ret; |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1015 | |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1016 | mutex_lock(lock); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1017 | ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat); |
| 1018 | if (ret) |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1019 | goto out; |
| 1020 | |
| 1021 | if (stat & DS1337_BIT_A1I) { |
| 1022 | stat &= ~DS1337_BIT_A1I; |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1023 | regmap_write(ds1307->regmap, DS1337_REG_STATUS, stat); |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1024 | |
Heiner Kallweit | 078f3f6 | 2017-06-05 17:57:29 +0200 | [diff] [blame] | 1025 | ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, |
| 1026 | DS1337_BIT_A1IE, 0); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1027 | if (ret) |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1028 | goto out; |
| 1029 | |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1030 | rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | out: |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1034 | mutex_unlock(lock); |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1035 | |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1036 | return IRQ_HANDLED; |
| 1037 | } |
| 1038 | |
| 1039 | /*----------------------------------------------------------------------*/ |
| 1040 | |
David Brownell | ff8371a | 2006-09-30 23:28:17 -0700 | [diff] [blame] | 1041 | static const struct rtc_class_ops ds13xx_rtc_ops = { |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1042 | .read_time = ds1307_get_time, |
| 1043 | .set_time = ds1307_set_time, |
Jüri Reitel | 74d88eb | 2009-01-07 18:07:16 -0800 | [diff] [blame] | 1044 | .read_alarm = ds1337_read_alarm, |
| 1045 | .set_alarm = ds1337_set_alarm, |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 1046 | .alarm_irq_enable = ds1307_alarm_irq_enable, |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1047 | }; |
| 1048 | |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1049 | static ssize_t frequency_test_store(struct device *dev, |
| 1050 | struct device_attribute *attr, |
| 1051 | const char *buf, size_t count) |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1052 | { |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1053 | struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1054 | bool freq_test_en; |
| 1055 | int ret; |
| 1056 | |
| 1057 | ret = kstrtobool(buf, &freq_test_en); |
| 1058 | if (ret) { |
| 1059 | dev_err(dev, "Failed to store RTC Frequency Test attribute\n"); |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
| 1063 | regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT, |
| 1064 | freq_test_en ? M41TXX_BIT_FT : 0); |
| 1065 | |
| 1066 | return count; |
| 1067 | } |
| 1068 | |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1069 | static ssize_t frequency_test_show(struct device *dev, |
| 1070 | struct device_attribute *attr, |
| 1071 | char *buf) |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1072 | { |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1073 | struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1074 | unsigned int ctrl_reg; |
| 1075 | |
| 1076 | regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); |
| 1077 | |
| 1078 | return scnprintf(buf, PAGE_SIZE, (ctrl_reg & M41TXX_BIT_FT) ? "on\n" : |
| 1079 | "off\n"); |
| 1080 | } |
| 1081 | |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1082 | static DEVICE_ATTR_RW(frequency_test); |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1083 | |
| 1084 | static struct attribute *rtc_freq_test_attrs[] = { |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1085 | &dev_attr_frequency_test.attr, |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1086 | NULL, |
| 1087 | }; |
| 1088 | |
| 1089 | static const struct attribute_group rtc_freq_test_attr_group = { |
| 1090 | .attrs = rtc_freq_test_attrs, |
| 1091 | }; |
| 1092 | |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1093 | static int ds1307_add_frequency_test(struct ds1307 *ds1307) |
| 1094 | { |
| 1095 | int err; |
| 1096 | |
| 1097 | switch (ds1307->type) { |
| 1098 | case m41t0: |
| 1099 | case m41t00: |
| 1100 | case m41t11: |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1101 | err = rtc_add_group(ds1307->rtc, &rtc_freq_test_attr_group); |
| 1102 | if (err) |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1103 | return err; |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1104 | break; |
| 1105 | default: |
| 1106 | break; |
| 1107 | } |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Simon Guinot | 1d1945d | 2014-04-03 14:49:55 -0700 | [diff] [blame] | 1112 | /*----------------------------------------------------------------------*/ |
| 1113 | |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1114 | static int ds1307_nvram_read(void *priv, unsigned int offset, void *val, |
| 1115 | size_t bytes) |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1116 | { |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1117 | struct ds1307 *ds1307 = priv; |
Heiner Kallweit | 969fa07 | 2017-07-12 07:49:54 +0200 | [diff] [blame] | 1118 | const struct chip_desc *chip = &chips[ds1307->type]; |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1119 | |
Heiner Kallweit | 969fa07 | 2017-07-12 07:49:54 +0200 | [diff] [blame] | 1120 | return regmap_bulk_read(ds1307->regmap, chip->nvram_offset + offset, |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1121 | val, bytes); |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1124 | static int ds1307_nvram_write(void *priv, unsigned int offset, void *val, |
| 1125 | size_t bytes) |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1126 | { |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1127 | struct ds1307 *ds1307 = priv; |
Heiner Kallweit | 969fa07 | 2017-07-12 07:49:54 +0200 | [diff] [blame] | 1128 | const struct chip_desc *chip = &chips[ds1307->type]; |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1129 | |
Heiner Kallweit | 969fa07 | 2017-07-12 07:49:54 +0200 | [diff] [blame] | 1130 | return regmap_bulk_write(ds1307->regmap, chip->nvram_offset + offset, |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1131 | val, bytes); |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1134 | /*----------------------------------------------------------------------*/ |
| 1135 | |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1136 | static u8 ds1307_trickle_init(struct ds1307 *ds1307, |
Heiner Kallweit | 7624df4 | 2017-07-12 07:49:33 +0200 | [diff] [blame] | 1137 | const struct chip_desc *chip) |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1138 | { |
Alexandre Belloni | 57ec2d9 | 2017-09-04 22:46:04 +0200 | [diff] [blame] | 1139 | u32 ohms; |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1140 | bool diode = true; |
| 1141 | |
| 1142 | if (!chip->do_trickle_setup) |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1143 | return 0; |
| 1144 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1145 | if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", |
| 1146 | &ohms)) |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1147 | return 0; |
| 1148 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1149 | if (device_property_read_bool(ds1307->dev, "trickle-diode-disable")) |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1150 | diode = false; |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1151 | |
| 1152 | return chip->do_trickle_setup(ds1307, ohms, diode); |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1155 | /*----------------------------------------------------------------------*/ |
| 1156 | |
Heiner Kallweit | 6b583a6 | 2017-09-27 22:41:26 +0200 | [diff] [blame] | 1157 | #if IS_REACHABLE(CONFIG_HWMON) |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1158 | |
| 1159 | /* |
| 1160 | * Temperature sensor support for ds3231 devices. |
| 1161 | */ |
| 1162 | |
| 1163 | #define DS3231_REG_TEMPERATURE 0x11 |
| 1164 | |
| 1165 | /* |
| 1166 | * A user-initiated temperature conversion is not started by this function, |
| 1167 | * so the temperature is updated once every 64 seconds. |
| 1168 | */ |
Zhuang Yuyao | 9a3dce6 | 2016-04-18 09:21:42 +0900 | [diff] [blame] | 1169 | static int ds3231_hwmon_read_temp(struct device *dev, s32 *mC) |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1170 | { |
| 1171 | struct ds1307 *ds1307 = dev_get_drvdata(dev); |
| 1172 | u8 temp_buf[2]; |
| 1173 | s16 temp; |
| 1174 | int ret; |
| 1175 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1176 | ret = regmap_bulk_read(ds1307->regmap, DS3231_REG_TEMPERATURE, |
| 1177 | temp_buf, sizeof(temp_buf)); |
| 1178 | if (ret) |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1179 | return ret; |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1180 | /* |
| 1181 | * Temperature is represented as a 10-bit code with a resolution of |
| 1182 | * 0.25 degree celsius and encoded in two's complement format. |
| 1183 | */ |
| 1184 | temp = (temp_buf[0] << 8) | temp_buf[1]; |
| 1185 | temp >>= 6; |
| 1186 | *mC = temp * 250; |
| 1187 | |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | static ssize_t ds3231_hwmon_show_temp(struct device *dev, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1192 | struct device_attribute *attr, char *buf) |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1193 | { |
| 1194 | int ret; |
Zhuang Yuyao | 9a3dce6 | 2016-04-18 09:21:42 +0900 | [diff] [blame] | 1195 | s32 temp; |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1196 | |
| 1197 | ret = ds3231_hwmon_read_temp(dev, &temp); |
| 1198 | if (ret) |
| 1199 | return ret; |
| 1200 | |
| 1201 | return sprintf(buf, "%d\n", temp); |
| 1202 | } |
Alexandre Belloni | b4be271 | 2017-09-04 22:46:08 +0200 | [diff] [blame] | 1203 | static SENSOR_DEVICE_ATTR(temp1_input, 0444, ds3231_hwmon_show_temp, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1204 | NULL, 0); |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1205 | |
| 1206 | static struct attribute *ds3231_hwmon_attrs[] = { |
| 1207 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1208 | NULL, |
| 1209 | }; |
| 1210 | ATTRIBUTE_GROUPS(ds3231_hwmon); |
| 1211 | |
| 1212 | static void ds1307_hwmon_register(struct ds1307 *ds1307) |
| 1213 | { |
| 1214 | struct device *dev; |
| 1215 | |
| 1216 | if (ds1307->type != ds_3231) |
| 1217 | return; |
| 1218 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1219 | dev = devm_hwmon_device_register_with_groups(ds1307->dev, ds1307->name, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1220 | ds1307, |
| 1221 | ds3231_hwmon_groups); |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1222 | if (IS_ERR(dev)) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1223 | dev_warn(ds1307->dev, "unable to register hwmon device %ld\n", |
| 1224 | PTR_ERR(dev)); |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | #else |
| 1229 | |
| 1230 | static void ds1307_hwmon_register(struct ds1307 *ds1307) |
| 1231 | { |
| 1232 | } |
| 1233 | |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1234 | #endif /* CONFIG_RTC_DRV_DS1307_HWMON */ |
| 1235 | |
| 1236 | /*----------------------------------------------------------------------*/ |
| 1237 | |
| 1238 | /* |
| 1239 | * Square-wave output support for DS3231 |
| 1240 | * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3231.pdf |
| 1241 | */ |
| 1242 | #ifdef CONFIG_COMMON_CLK |
| 1243 | |
| 1244 | enum { |
| 1245 | DS3231_CLK_SQW = 0, |
| 1246 | DS3231_CLK_32KHZ, |
| 1247 | }; |
| 1248 | |
| 1249 | #define clk_sqw_to_ds1307(clk) \ |
| 1250 | container_of(clk, struct ds1307, clks[DS3231_CLK_SQW]) |
| 1251 | #define clk_32khz_to_ds1307(clk) \ |
| 1252 | container_of(clk, struct ds1307, clks[DS3231_CLK_32KHZ]) |
| 1253 | |
| 1254 | static int ds3231_clk_sqw_rates[] = { |
| 1255 | 1, |
| 1256 | 1024, |
| 1257 | 4096, |
| 1258 | 8192, |
| 1259 | }; |
| 1260 | |
| 1261 | static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value) |
| 1262 | { |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1263 | struct mutex *lock = &ds1307->rtc->ops_lock; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1264 | int ret; |
| 1265 | |
| 1266 | mutex_lock(lock); |
Heiner Kallweit | 078f3f6 | 2017-06-05 17:57:29 +0200 | [diff] [blame] | 1267 | ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, |
| 1268 | mask, value); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1269 | mutex_unlock(lock); |
| 1270 | |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
| 1274 | static unsigned long ds3231_clk_sqw_recalc_rate(struct clk_hw *hw, |
| 1275 | unsigned long parent_rate) |
| 1276 | { |
| 1277 | struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1278 | int control, ret; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1279 | int rate_sel = 0; |
| 1280 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1281 | ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); |
| 1282 | if (ret) |
| 1283 | return ret; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1284 | if (control & DS1337_BIT_RS1) |
| 1285 | rate_sel += 1; |
| 1286 | if (control & DS1337_BIT_RS2) |
| 1287 | rate_sel += 2; |
| 1288 | |
| 1289 | return ds3231_clk_sqw_rates[rate_sel]; |
| 1290 | } |
| 1291 | |
| 1292 | static long ds3231_clk_sqw_round_rate(struct clk_hw *hw, unsigned long rate, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1293 | unsigned long *prate) |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1294 | { |
| 1295 | int i; |
| 1296 | |
| 1297 | for (i = ARRAY_SIZE(ds3231_clk_sqw_rates) - 1; i >= 0; i--) { |
| 1298 | if (ds3231_clk_sqw_rates[i] <= rate) |
| 1299 | return ds3231_clk_sqw_rates[i]; |
| 1300 | } |
| 1301 | |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | static int ds3231_clk_sqw_set_rate(struct clk_hw *hw, unsigned long rate, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1306 | unsigned long parent_rate) |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1307 | { |
| 1308 | struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); |
| 1309 | int control = 0; |
| 1310 | int rate_sel; |
| 1311 | |
| 1312 | for (rate_sel = 0; rate_sel < ARRAY_SIZE(ds3231_clk_sqw_rates); |
| 1313 | rate_sel++) { |
| 1314 | if (ds3231_clk_sqw_rates[rate_sel] == rate) |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | if (rate_sel == ARRAY_SIZE(ds3231_clk_sqw_rates)) |
| 1319 | return -EINVAL; |
| 1320 | |
| 1321 | if (rate_sel & 1) |
| 1322 | control |= DS1337_BIT_RS1; |
| 1323 | if (rate_sel & 2) |
| 1324 | control |= DS1337_BIT_RS2; |
| 1325 | |
| 1326 | return ds1337_write_control(ds1307, DS1337_BIT_RS1 | DS1337_BIT_RS2, |
| 1327 | control); |
| 1328 | } |
| 1329 | |
| 1330 | static int ds3231_clk_sqw_prepare(struct clk_hw *hw) |
| 1331 | { |
| 1332 | struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); |
| 1333 | |
| 1334 | return ds1337_write_control(ds1307, DS1337_BIT_INTCN, 0); |
| 1335 | } |
| 1336 | |
| 1337 | static void ds3231_clk_sqw_unprepare(struct clk_hw *hw) |
| 1338 | { |
| 1339 | struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); |
| 1340 | |
| 1341 | ds1337_write_control(ds1307, DS1337_BIT_INTCN, DS1337_BIT_INTCN); |
| 1342 | } |
| 1343 | |
| 1344 | static int ds3231_clk_sqw_is_prepared(struct clk_hw *hw) |
| 1345 | { |
| 1346 | struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1347 | int control, ret; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1348 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1349 | ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); |
| 1350 | if (ret) |
| 1351 | return ret; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1352 | |
| 1353 | return !(control & DS1337_BIT_INTCN); |
| 1354 | } |
| 1355 | |
| 1356 | static const struct clk_ops ds3231_clk_sqw_ops = { |
| 1357 | .prepare = ds3231_clk_sqw_prepare, |
| 1358 | .unprepare = ds3231_clk_sqw_unprepare, |
| 1359 | .is_prepared = ds3231_clk_sqw_is_prepared, |
| 1360 | .recalc_rate = ds3231_clk_sqw_recalc_rate, |
| 1361 | .round_rate = ds3231_clk_sqw_round_rate, |
| 1362 | .set_rate = ds3231_clk_sqw_set_rate, |
| 1363 | }; |
| 1364 | |
| 1365 | static unsigned long ds3231_clk_32khz_recalc_rate(struct clk_hw *hw, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1366 | unsigned long parent_rate) |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1367 | { |
| 1368 | return 32768; |
| 1369 | } |
| 1370 | |
| 1371 | static int ds3231_clk_32khz_control(struct ds1307 *ds1307, bool enable) |
| 1372 | { |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1373 | struct mutex *lock = &ds1307->rtc->ops_lock; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1374 | int ret; |
| 1375 | |
| 1376 | mutex_lock(lock); |
Heiner Kallweit | 078f3f6 | 2017-06-05 17:57:29 +0200 | [diff] [blame] | 1377 | ret = regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS, |
| 1378 | DS3231_BIT_EN32KHZ, |
| 1379 | enable ? DS3231_BIT_EN32KHZ : 0); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1380 | mutex_unlock(lock); |
| 1381 | |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
| 1385 | static int ds3231_clk_32khz_prepare(struct clk_hw *hw) |
| 1386 | { |
| 1387 | struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); |
| 1388 | |
| 1389 | return ds3231_clk_32khz_control(ds1307, true); |
| 1390 | } |
| 1391 | |
| 1392 | static void ds3231_clk_32khz_unprepare(struct clk_hw *hw) |
| 1393 | { |
| 1394 | struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); |
| 1395 | |
| 1396 | ds3231_clk_32khz_control(ds1307, false); |
| 1397 | } |
| 1398 | |
| 1399 | static int ds3231_clk_32khz_is_prepared(struct clk_hw *hw) |
| 1400 | { |
| 1401 | struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1402 | int status, ret; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1403 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1404 | ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status); |
| 1405 | if (ret) |
| 1406 | return ret; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1407 | |
| 1408 | return !!(status & DS3231_BIT_EN32KHZ); |
| 1409 | } |
| 1410 | |
| 1411 | static const struct clk_ops ds3231_clk_32khz_ops = { |
| 1412 | .prepare = ds3231_clk_32khz_prepare, |
| 1413 | .unprepare = ds3231_clk_32khz_unprepare, |
| 1414 | .is_prepared = ds3231_clk_32khz_is_prepared, |
| 1415 | .recalc_rate = ds3231_clk_32khz_recalc_rate, |
| 1416 | }; |
| 1417 | |
| 1418 | static struct clk_init_data ds3231_clks_init[] = { |
| 1419 | [DS3231_CLK_SQW] = { |
| 1420 | .name = "ds3231_clk_sqw", |
| 1421 | .ops = &ds3231_clk_sqw_ops, |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1422 | }, |
| 1423 | [DS3231_CLK_32KHZ] = { |
| 1424 | .name = "ds3231_clk_32khz", |
| 1425 | .ops = &ds3231_clk_32khz_ops, |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1426 | }, |
| 1427 | }; |
| 1428 | |
| 1429 | static int ds3231_clks_register(struct ds1307 *ds1307) |
| 1430 | { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1431 | struct device_node *node = ds1307->dev->of_node; |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1432 | struct clk_onecell_data *onecell; |
| 1433 | int i; |
| 1434 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1435 | onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1436 | if (!onecell) |
| 1437 | return -ENOMEM; |
| 1438 | |
| 1439 | onecell->clk_num = ARRAY_SIZE(ds3231_clks_init); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1440 | onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num, |
| 1441 | sizeof(onecell->clks[0]), GFP_KERNEL); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1442 | if (!onecell->clks) |
| 1443 | return -ENOMEM; |
| 1444 | |
| 1445 | for (i = 0; i < ARRAY_SIZE(ds3231_clks_init); i++) { |
| 1446 | struct clk_init_data init = ds3231_clks_init[i]; |
| 1447 | |
| 1448 | /* |
| 1449 | * Interrupt signal due to alarm conditions and square-wave |
| 1450 | * output share same pin, so don't initialize both. |
| 1451 | */ |
| 1452 | if (i == DS3231_CLK_SQW && test_bit(HAS_ALARM, &ds1307->flags)) |
| 1453 | continue; |
| 1454 | |
| 1455 | /* optional override of the clockname */ |
| 1456 | of_property_read_string_index(node, "clock-output-names", i, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1457 | &init.name); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1458 | ds1307->clks[i].init = &init; |
| 1459 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1460 | onecell->clks[i] = devm_clk_register(ds1307->dev, |
| 1461 | &ds1307->clks[i]); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1462 | if (IS_ERR(onecell->clks[i])) |
| 1463 | return PTR_ERR(onecell->clks[i]); |
| 1464 | } |
| 1465 | |
| 1466 | if (!node) |
| 1467 | return 0; |
| 1468 | |
| 1469 | of_clk_add_provider(node, of_clk_src_onecell_get, onecell); |
| 1470 | |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | static void ds1307_clks_register(struct ds1307 *ds1307) |
| 1475 | { |
| 1476 | int ret; |
| 1477 | |
| 1478 | if (ds1307->type != ds_3231) |
| 1479 | return; |
| 1480 | |
| 1481 | ret = ds3231_clks_register(ds1307); |
| 1482 | if (ret) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1483 | dev_warn(ds1307->dev, "unable to register clock device %d\n", |
| 1484 | ret); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | #else |
| 1489 | |
| 1490 | static void ds1307_clks_register(struct ds1307 *ds1307) |
| 1491 | { |
| 1492 | } |
| 1493 | |
| 1494 | #endif /* CONFIG_COMMON_CLK */ |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1495 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1496 | static const struct regmap_config regmap_config = { |
| 1497 | .reg_bits = 8, |
| 1498 | .val_bits = 8, |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1499 | }; |
| 1500 | |
Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 1501 | static int ds1307_probe(struct i2c_client *client, |
| 1502 | const struct i2c_device_id *id) |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1503 | { |
| 1504 | struct ds1307 *ds1307; |
| 1505 | int err = -ENODEV; |
Heiner Kallweit | 584ce30 | 2017-08-29 21:52:56 +0200 | [diff] [blame] | 1506 | int tmp; |
Heiner Kallweit | 7624df4 | 2017-07-12 07:49:33 +0200 | [diff] [blame] | 1507 | const struct chip_desc *chip; |
Heiner Kallweit | 82e2d43 | 2017-07-12 07:49:37 +0200 | [diff] [blame] | 1508 | bool want_irq; |
Michael Lange | 8bc2a40 | 2016-01-21 18:10:16 +0100 | [diff] [blame] | 1509 | bool ds1307_can_wakeup_device = false; |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1510 | unsigned char regs[8]; |
Jingoo Han | 01ce893 | 2013-11-12 15:10:41 -0800 | [diff] [blame] | 1511 | struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1512 | u8 trickle_charger_setup = 0; |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1513 | |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1514 | ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 1515 | if (!ds1307) |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1516 | return -ENOMEM; |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1517 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1518 | dev_set_drvdata(&client->dev, ds1307); |
| 1519 | ds1307->dev = &client->dev; |
| 1520 | ds1307->name = client->name; |
Joakim Tjernlund | 33df2ee | 2009-06-17 16:26:08 -0700 | [diff] [blame] | 1521 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1522 | ds1307->regmap = devm_regmap_init_i2c(client, ®map_config); |
| 1523 | if (IS_ERR(ds1307->regmap)) { |
| 1524 | dev_err(ds1307->dev, "regmap allocation failed\n"); |
| 1525 | return PTR_ERR(ds1307->regmap); |
| 1526 | } |
| 1527 | |
| 1528 | i2c_set_clientdata(client, ds1307); |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 1529 | |
| 1530 | if (client->dev.of_node) { |
| 1531 | ds1307->type = (enum ds_type) |
| 1532 | of_device_get_match_data(&client->dev); |
| 1533 | chip = &chips[ds1307->type]; |
| 1534 | } else if (id) { |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 1535 | chip = &chips[id->driver_data]; |
| 1536 | ds1307->type = id->driver_data; |
| 1537 | } else { |
| 1538 | const struct acpi_device_id *acpi_id; |
Joakim Tjernlund | 33df2ee | 2009-06-17 16:26:08 -0700 | [diff] [blame] | 1539 | |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 1540 | acpi_id = acpi_match_device(ACPI_PTR(ds1307_acpi_ids), |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1541 | ds1307->dev); |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 1542 | if (!acpi_id) |
| 1543 | return -ENODEV; |
| 1544 | chip = &chips[acpi_id->driver_data]; |
| 1545 | ds1307->type = acpi_id->driver_data; |
| 1546 | } |
| 1547 | |
Heiner Kallweit | 82e2d43 | 2017-07-12 07:49:37 +0200 | [diff] [blame] | 1548 | want_irq = client->irq > 0 && chip->alarm; |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1549 | |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1550 | if (!pdata) |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1551 | trickle_charger_setup = ds1307_trickle_init(ds1307, chip); |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1552 | else if (pdata->trickle_charger_setup) |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1553 | trickle_charger_setup = pdata->trickle_charger_setup; |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1554 | |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1555 | if (trickle_charger_setup && chip->trickle_charger_reg) { |
| 1556 | trickle_charger_setup |= DS13XX_TRICKLE_CHARGER_MAGIC; |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1557 | dev_dbg(ds1307->dev, |
| 1558 | "writing trickle charger info 0x%x to 0x%x\n", |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1559 | trickle_charger_setup, chip->trickle_charger_reg); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1560 | regmap_write(ds1307->regmap, chip->trickle_charger_reg, |
Heiner Kallweit | d8490fd | 2017-07-12 07:49:28 +0200 | [diff] [blame] | 1561 | trickle_charger_setup); |
Matti Vaittinen | 33b04b7 | 2014-10-13 15:52:48 -0700 | [diff] [blame] | 1562 | } |
Wolfram Sang | eb86c30 | 2012-05-29 15:07:38 -0700 | [diff] [blame] | 1563 | |
Michael Lange | 8bc2a40 | 2016-01-21 18:10:16 +0100 | [diff] [blame] | 1564 | #ifdef CONFIG_OF |
| 1565 | /* |
| 1566 | * For devices with no IRQ directly connected to the SoC, the RTC chip |
| 1567 | * can be forced as a wakeup source by stating that explicitly in |
| 1568 | * the device's .dts file using the "wakeup-source" boolean property. |
| 1569 | * If the "wakeup-source" property is set, don't request an IRQ. |
| 1570 | * This will guarantee the 'wakealarm' sysfs entry is available on the device, |
| 1571 | * if supported by the RTC. |
| 1572 | */ |
Heiner Kallweit | 82e2d43 | 2017-07-12 07:49:37 +0200 | [diff] [blame] | 1573 | if (chip->alarm && of_property_read_bool(client->dev.of_node, |
| 1574 | "wakeup-source")) |
Michael Lange | 8bc2a40 | 2016-01-21 18:10:16 +0100 | [diff] [blame] | 1575 | ds1307_can_wakeup_device = true; |
Michael Lange | 8bc2a40 | 2016-01-21 18:10:16 +0100 | [diff] [blame] | 1576 | #endif |
| 1577 | |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1578 | switch (ds1307->type) { |
| 1579 | case ds_1337: |
| 1580 | case ds_1339: |
Nikita Yushchenko | 0759c88 | 2017-08-24 09:32:11 +0300 | [diff] [blame] | 1581 | case ds_1341: |
Wolfram Sang | 97f902b | 2009-06-17 16:26:10 -0700 | [diff] [blame] | 1582 | case ds_3231: |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1583 | /* get registers that the "rtc" read below won't read... */ |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1584 | err = regmap_bulk_read(ds1307->regmap, DS1337_REG_CONTROL, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1585 | regs, 2); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1586 | if (err) { |
| 1587 | dev_dbg(ds1307->dev, "read error %d\n", err); |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1588 | goto exit; |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1591 | /* oscillator off? turn it on, so clock can tick. */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1592 | if (regs[0] & DS1337_BIT_nEOSC) |
| 1593 | regs[0] &= ~DS1337_BIT_nEOSC; |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1594 | |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 1595 | /* |
Michael Lange | 8bc2a40 | 2016-01-21 18:10:16 +0100 | [diff] [blame] | 1596 | * Using IRQ or defined as wakeup-source? |
| 1597 | * Disable the square wave and both alarms. |
Wolfram Sang | 97f902b | 2009-06-17 16:26:10 -0700 | [diff] [blame] | 1598 | * For some variants, be sure alarms can trigger when we're |
| 1599 | * running on Vbackup (BBSQI/BBSQW) |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1600 | */ |
Heiner Kallweit | 82e2d43 | 2017-07-12 07:49:37 +0200 | [diff] [blame] | 1601 | if (want_irq || ds1307_can_wakeup_device) { |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1602 | regs[0] |= DS1337_BIT_INTCN | chip->bbsqi_bit; |
| 1603 | regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1606 | regmap_write(ds1307->regmap, DS1337_REG_CONTROL, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1607 | regs[0]); |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1608 | |
| 1609 | /* oscillator fault? clear flag, and warn */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1610 | if (regs[1] & DS1337_BIT_OSF) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1611 | regmap_write(ds1307->regmap, DS1337_REG_STATUS, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1612 | regs[1] & ~DS1337_BIT_OSF); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1613 | dev_warn(ds1307->dev, "SET TIME!\n"); |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1614 | } |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1615 | break; |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1616 | |
| 1617 | case rx_8025: |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1618 | err = regmap_bulk_read(ds1307->regmap, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1619 | RX8025_REG_CTRL1 << 4 | 0x08, regs, 2); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1620 | if (err) { |
| 1621 | dev_dbg(ds1307->dev, "read error %d\n", err); |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1622 | goto exit; |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | /* oscillator off? turn it on, so clock can tick. */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1626 | if (!(regs[1] & RX8025_BIT_XST)) { |
| 1627 | regs[1] |= RX8025_BIT_XST; |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1628 | regmap_write(ds1307->regmap, |
| 1629 | RX8025_REG_CTRL2 << 4 | 0x08, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1630 | regs[1]); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1631 | dev_warn(ds1307->dev, |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1632 | "oscillator stop detected - SET TIME!\n"); |
| 1633 | } |
| 1634 | |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1635 | if (regs[1] & RX8025_BIT_PON) { |
| 1636 | regs[1] &= ~RX8025_BIT_PON; |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1637 | regmap_write(ds1307->regmap, |
| 1638 | RX8025_REG_CTRL2 << 4 | 0x08, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1639 | regs[1]); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1640 | dev_warn(ds1307->dev, "power-on detected\n"); |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1641 | } |
| 1642 | |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1643 | if (regs[1] & RX8025_BIT_VDET) { |
| 1644 | regs[1] &= ~RX8025_BIT_VDET; |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1645 | regmap_write(ds1307->regmap, |
| 1646 | RX8025_REG_CTRL2 << 4 | 0x08, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1647 | regs[1]); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1648 | dev_warn(ds1307->dev, "voltage drop detected\n"); |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /* make sure we are running in 24hour mode */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1652 | if (!(regs[0] & RX8025_BIT_2412)) { |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1653 | u8 hour; |
| 1654 | |
| 1655 | /* switch to 24 hour mode */ |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1656 | regmap_write(ds1307->regmap, |
| 1657 | RX8025_REG_CTRL1 << 4 | 0x08, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1658 | regs[0] | RX8025_BIT_2412); |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1659 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1660 | err = regmap_bulk_read(ds1307->regmap, |
| 1661 | RX8025_REG_CTRL1 << 4 | 0x08, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1662 | regs, 2); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1663 | if (err) { |
| 1664 | dev_dbg(ds1307->dev, "read error %d\n", err); |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1665 | goto exit; |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /* correct hour */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1669 | hour = bcd2bin(regs[DS1307_REG_HOUR]); |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1670 | if (hour == 12) |
| 1671 | hour = 0; |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1672 | if (regs[DS1307_REG_HOUR] & DS1307_BIT_PM) |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1673 | hour += 12; |
| 1674 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1675 | regmap_write(ds1307->regmap, |
| 1676 | DS1307_REG_HOUR << 4 | 0x08, hour); |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1677 | } |
| 1678 | break; |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1679 | default: |
| 1680 | break; |
| 1681 | } |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1682 | |
| 1683 | read_rtc: |
| 1684 | /* read RTC registers */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1685 | err = regmap_bulk_read(ds1307->regmap, chip->offset, regs, |
| 1686 | sizeof(regs)); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1687 | if (err) { |
| 1688 | dev_dbg(ds1307->dev, "read error %d\n", err); |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1689 | goto exit; |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 1692 | /* |
| 1693 | * minimal sanity checking; some chips (like DS1340) don't |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1694 | * specify the extra bits as must-be-zero, but there are |
| 1695 | * still a few values that are clearly out-of-range. |
| 1696 | */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1697 | tmp = regs[DS1307_REG_SECS]; |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1698 | switch (ds1307->type) { |
| 1699 | case ds_1307: |
Stefan Agner | 8566f70 | 2017-03-23 16:54:57 -0700 | [diff] [blame] | 1700 | case m41t0: |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1701 | case m41t00: |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 1702 | case m41t11: |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1703 | /* clock halted? turn it on, so clock can tick. */ |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1704 | if (tmp & DS1307_BIT_CH) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1705 | regmap_write(ds1307->regmap, DS1307_REG_SECS, 0); |
| 1706 | dev_warn(ds1307->dev, "SET TIME!\n"); |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1707 | goto read_rtc; |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1708 | } |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1709 | break; |
Sean Nyekjaer | 300a773 | 2017-06-08 12:36:54 +0200 | [diff] [blame] | 1710 | case ds_1308: |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1711 | case ds_1338: |
| 1712 | /* clock halted? turn it on, so clock can tick. */ |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1713 | if (tmp & DS1307_BIT_CH) |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1714 | regmap_write(ds1307->regmap, DS1307_REG_SECS, 0); |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1715 | |
| 1716 | /* oscillator fault? clear flag, and warn */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1717 | if (regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1718 | regmap_write(ds1307->regmap, DS1307_REG_CONTROL, |
Alexandre Belloni | 4057a66 | 2017-09-04 22:46:06 +0200 | [diff] [blame] | 1719 | regs[DS1307_REG_CONTROL] & |
| 1720 | ~DS1338_BIT_OSF); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1721 | dev_warn(ds1307->dev, "SET TIME!\n"); |
Rodolfo Giometti | be5f59f | 2007-07-17 04:05:06 -0700 | [diff] [blame] | 1722 | goto read_rtc; |
| 1723 | } |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1724 | break; |
frederic Rodo | fcd8db0 | 2008-02-06 01:38:55 -0800 | [diff] [blame] | 1725 | case ds_1340: |
| 1726 | /* clock halted? turn it on, so clock can tick. */ |
| 1727 | if (tmp & DS1340_BIT_nEOSC) |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1728 | regmap_write(ds1307->regmap, DS1307_REG_SECS, 0); |
frederic Rodo | fcd8db0 | 2008-02-06 01:38:55 -0800 | [diff] [blame] | 1729 | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1730 | err = regmap_read(ds1307->regmap, DS1340_REG_FLAG, &tmp); |
| 1731 | if (err) { |
| 1732 | dev_dbg(ds1307->dev, "read error %d\n", err); |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1733 | goto exit; |
frederic Rodo | fcd8db0 | 2008-02-06 01:38:55 -0800 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | /* oscillator fault? clear flag, and warn */ |
| 1737 | if (tmp & DS1340_BIT_OSF) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1738 | regmap_write(ds1307->regmap, DS1340_REG_FLAG, 0); |
| 1739 | dev_warn(ds1307->dev, "SET TIME!\n"); |
frederic Rodo | fcd8db0 | 2008-02-06 01:38:55 -0800 | [diff] [blame] | 1740 | } |
| 1741 | break; |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 1742 | case mcp794xx: |
David Anders | 43fcb81 | 2011-11-02 13:37:53 -0700 | [diff] [blame] | 1743 | /* make sure that the backup battery is enabled */ |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1744 | if (!(regs[DS1307_REG_WDAY] & MCP794XX_BIT_VBATEN)) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1745 | regmap_write(ds1307->regmap, DS1307_REG_WDAY, |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1746 | regs[DS1307_REG_WDAY] | |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1747 | MCP794XX_BIT_VBATEN); |
David Anders | 43fcb81 | 2011-11-02 13:37:53 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | /* clock halted? turn it on, so clock can tick. */ |
Tomas Novotny | f4199f8 | 2014-12-10 15:53:57 -0800 | [diff] [blame] | 1751 | if (!(tmp & MCP794XX_BIT_ST)) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1752 | regmap_write(ds1307->regmap, DS1307_REG_SECS, |
| 1753 | MCP794XX_BIT_ST); |
| 1754 | dev_warn(ds1307->dev, "SET TIME!\n"); |
David Anders | 43fcb81 | 2011-11-02 13:37:53 -0700 | [diff] [blame] | 1755 | goto read_rtc; |
| 1756 | } |
| 1757 | |
| 1758 | break; |
Wolfram Sang | 32d322b | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 1759 | default: |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1760 | break; |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1761 | } |
David Brownell | 045e0e8 | 2007-07-17 04:04:55 -0700 | [diff] [blame] | 1762 | |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1763 | tmp = regs[DS1307_REG_HOUR]; |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1764 | switch (ds1307->type) { |
| 1765 | case ds_1340: |
Stefan Agner | 8566f70 | 2017-03-23 16:54:57 -0700 | [diff] [blame] | 1766 | case m41t0: |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1767 | case m41t00: |
Giulio Benetti | 7e58076 | 2018-05-16 23:08:40 +0200 | [diff] [blame] | 1768 | case m41t11: |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 1769 | /* |
| 1770 | * NOTE: ignores century bits; fix before deploying |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1771 | * systems that will run through year 2100. |
| 1772 | */ |
| 1773 | break; |
Matthias Fuchs | a216685 | 2009-03-31 15:24:58 -0700 | [diff] [blame] | 1774 | case rx_8025: |
| 1775 | break; |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1776 | default: |
| 1777 | if (!(tmp & DS1307_BIT_12HR)) |
| 1778 | break; |
| 1779 | |
David Anders | 40ce972 | 2012-03-23 15:02:37 -0700 | [diff] [blame] | 1780 | /* |
| 1781 | * Be sure we're in 24 hour mode. Multi-master systems |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1782 | * take note... |
| 1783 | */ |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 1784 | tmp = bcd2bin(tmp & 0x1f); |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1785 | if (tmp == 12) |
| 1786 | tmp = 0; |
Alexandre Belloni | 042fa8c | 2017-09-04 22:46:02 +0200 | [diff] [blame] | 1787 | if (regs[DS1307_REG_HOUR] & DS1307_BIT_PM) |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1788 | tmp += 12; |
Heiner Kallweit | e553170 | 2017-07-12 07:49:47 +0200 | [diff] [blame] | 1789 | regmap_write(ds1307->regmap, chip->offset + DS1307_REG_HOUR, |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1790 | bin2bcd(tmp)); |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Heiner Kallweit | 82e2d43 | 2017-07-12 07:49:37 +0200 | [diff] [blame] | 1793 | if (want_irq || ds1307_can_wakeup_device) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1794 | device_set_wakeup_capable(ds1307->dev, true); |
Simon Guinot | 3abb1ad | 2015-11-26 15:37:13 +0100 | [diff] [blame] | 1795 | set_bit(HAS_ALARM, &ds1307->flags); |
| 1796 | } |
Alexandre Belloni | 69b119a | 2017-07-06 11:42:06 +0200 | [diff] [blame] | 1797 | |
| 1798 | ds1307->rtc = devm_rtc_allocate_device(ds1307->dev); |
Alexandre Belloni | e69c056 | 2017-09-04 22:46:07 +0200 | [diff] [blame] | 1799 | if (IS_ERR(ds1307->rtc)) |
Alessandro Zummo | 4071ea2 | 2014-04-03 14:49:36 -0700 | [diff] [blame] | 1800 | return PTR_ERR(ds1307->rtc); |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1801 | |
Heiner Kallweit | 82e2d43 | 2017-07-12 07:49:37 +0200 | [diff] [blame] | 1802 | if (ds1307_can_wakeup_device && !want_irq) { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1803 | dev_info(ds1307->dev, |
| 1804 | "'wakeup-source' is set, request for an IRQ is disabled!\n"); |
Michael Lange | 8bc2a40 | 2016-01-21 18:10:16 +0100 | [diff] [blame] | 1805 | /* We cannot support UIE mode if we do not have an IRQ line */ |
| 1806 | ds1307->rtc->uie_unsupported = 1; |
| 1807 | } |
| 1808 | |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1809 | if (want_irq) { |
Heiner Kallweit | 4594712 | 2017-07-12 07:49:41 +0200 | [diff] [blame] | 1810 | err = devm_request_threaded_irq(ds1307->dev, client->irq, NULL, |
| 1811 | chip->irq_handler ?: ds1307_irq, |
Nishanth Menon | c598319 | 2015-06-23 11:15:11 -0500 | [diff] [blame] | 1812 | IRQF_SHARED | IRQF_ONESHOT, |
Alexandre Belloni | 4b9e2a0 | 2017-06-02 14:13:21 +0200 | [diff] [blame] | 1813 | ds1307->name, ds1307); |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1814 | if (err) { |
Alessandro Zummo | 4071ea2 | 2014-04-03 14:49:36 -0700 | [diff] [blame] | 1815 | client->irq = 0; |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1816 | device_set_wakeup_capable(ds1307->dev, false); |
Simon Guinot | 3abb1ad | 2015-11-26 15:37:13 +0100 | [diff] [blame] | 1817 | clear_bit(HAS_ALARM, &ds1307->flags); |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1818 | dev_err(ds1307->dev, "unable to request IRQ!\n"); |
Alexandre Belloni | e69c056 | 2017-09-04 22:46:07 +0200 | [diff] [blame] | 1819 | } else { |
Heiner Kallweit | 11e5890 | 2017-03-10 18:52:34 +0100 | [diff] [blame] | 1820 | dev_dbg(ds1307->dev, "got IRQ %d\n", client->irq); |
Alexandre Belloni | e69c056 | 2017-09-04 22:46:07 +0200 | [diff] [blame] | 1821 | } |
Rodolfo Giometti | cb49a5e | 2008-10-15 22:02:58 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Alexandre Belloni | e9fb768 | 2018-02-12 23:47:22 +0100 | [diff] [blame] | 1824 | ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1825 | err = ds1307_add_frequency_test(ds1307); |
Alexandre Belloni | e9fb768 | 2018-02-12 23:47:22 +0100 | [diff] [blame] | 1826 | if (err) |
| 1827 | return err; |
| 1828 | |
Alexandre Belloni | 6a5f2a1f | 2018-09-20 16:35:26 +0200 | [diff] [blame] | 1829 | err = rtc_register_device(ds1307->rtc); |
Giulio Benetti | b41c23e | 2018-07-25 19:26:05 +0200 | [diff] [blame] | 1830 | if (err) |
| 1831 | return err; |
| 1832 | |
Austin Boyle | 9eab0a7 | 2012-03-23 15:02:38 -0700 | [diff] [blame] | 1833 | if (chip->nvram_size) { |
Alexandre Belloni | 409baf1 | 2018-02-12 23:47:23 +0100 | [diff] [blame] | 1834 | struct nvmem_config nvmem_cfg = { |
| 1835 | .name = "ds1307_nvram", |
| 1836 | .word_size = 1, |
| 1837 | .stride = 1, |
| 1838 | .size = chip->nvram_size, |
| 1839 | .reg_read = ds1307_nvram_read, |
| 1840 | .reg_write = ds1307_nvram_write, |
| 1841 | .priv = ds1307, |
| 1842 | }; |
Alessandro Zummo | 4071ea2 | 2014-04-03 14:49:36 -0700 | [diff] [blame] | 1843 | |
Alexandre Belloni | abc925f | 2017-07-06 11:42:07 +0200 | [diff] [blame] | 1844 | ds1307->rtc->nvram_old_abi = true; |
Alexandre Belloni | 409baf1 | 2018-02-12 23:47:23 +0100 | [diff] [blame] | 1845 | rtc_nvmem_register(ds1307->rtc, &nvmem_cfg); |
David Brownell | 682d73f | 2007-11-14 16:58:32 -0800 | [diff] [blame] | 1846 | } |
| 1847 | |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1848 | ds1307_hwmon_register(ds1307); |
Akinobu Mita | 6c6ff14 | 2016-01-31 23:10:10 +0900 | [diff] [blame] | 1849 | ds1307_clks_register(ds1307); |
Akinobu Mita | 445c020 | 2016-01-25 00:22:16 +0900 | [diff] [blame] | 1850 | |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1851 | return 0; |
| 1852 | |
Jingoo Han | edca66d | 2013-07-03 15:07:05 -0700 | [diff] [blame] | 1853 | exit: |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1854 | return err; |
| 1855 | } |
| 1856 | |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1857 | static struct i2c_driver ds1307_driver = { |
| 1858 | .driver = { |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1859 | .name = "rtc-ds1307", |
Javier Martinez Canillas | 7ef6d2c | 2017-03-03 11:29:15 -0300 | [diff] [blame] | 1860 | .of_match_table = of_match_ptr(ds1307_of_match), |
Tin Huynh | 9c19b89 | 2016-11-30 09:57:31 +0700 | [diff] [blame] | 1861 | .acpi_match_table = ACPI_PTR(ds1307_acpi_ids), |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1862 | }, |
David Brownell | c065f35 | 2007-07-17 04:05:10 -0700 | [diff] [blame] | 1863 | .probe = ds1307_probe, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 1864 | .id_table = ds1307_id, |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1865 | }; |
| 1866 | |
Axel Lin | 0abc920 | 2012-03-23 15:02:31 -0700 | [diff] [blame] | 1867 | module_i2c_driver(ds1307_driver); |
David Brownell | 1abb0dc | 2006-06-25 05:48:17 -0700 | [diff] [blame] | 1868 | |
| 1869 | MODULE_DESCRIPTION("RTC driver for DS1307 and similar chips"); |
| 1870 | MODULE_LICENSE("GPL"); |