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