Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 2 | /* |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 3 | * Micro Crystal RV-3029 / RV-3049 rtc class driver |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 4 | * |
| 5 | * Author: Gregory Hermant <gregory.hermant@calao-systems.com> |
Michael Büsch | 2dca3d9 | 2016-03-04 22:40:30 +0100 | [diff] [blame] | 6 | * Michael Buesch <m@bues.ch> |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 7 | * |
| 8 | * based on previously existing rtc class drivers |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/i2c.h> |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 13 | #include <linux/spi/spi.h> |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 14 | #include <linux/bcd.h> |
| 15 | #include <linux/rtc.h> |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/of.h> |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 18 | #include <linux/hwmon.h> |
| 19 | #include <linux/hwmon-sysfs.h> |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 20 | #include <linux/regmap.h> |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 21 | |
| 22 | /* Register map */ |
| 23 | /* control section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 24 | #define RV3029_ONOFF_CTRL 0x00 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 25 | #define RV3029_ONOFF_CTRL_WE BIT(0) |
| 26 | #define RV3029_ONOFF_CTRL_TE BIT(1) |
| 27 | #define RV3029_ONOFF_CTRL_TAR BIT(2) |
| 28 | #define RV3029_ONOFF_CTRL_EERE BIT(3) |
| 29 | #define RV3029_ONOFF_CTRL_SRON BIT(4) |
| 30 | #define RV3029_ONOFF_CTRL_TD0 BIT(5) |
| 31 | #define RV3029_ONOFF_CTRL_TD1 BIT(6) |
| 32 | #define RV3029_ONOFF_CTRL_CLKINT BIT(7) |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 33 | #define RV3029_IRQ_CTRL 0x01 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 34 | #define RV3029_IRQ_CTRL_AIE BIT(0) |
| 35 | #define RV3029_IRQ_CTRL_TIE BIT(1) |
| 36 | #define RV3029_IRQ_CTRL_V1IE BIT(2) |
| 37 | #define RV3029_IRQ_CTRL_V2IE BIT(3) |
| 38 | #define RV3029_IRQ_CTRL_SRIE BIT(4) |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 39 | #define RV3029_IRQ_FLAGS 0x02 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 40 | #define RV3029_IRQ_FLAGS_AF BIT(0) |
| 41 | #define RV3029_IRQ_FLAGS_TF BIT(1) |
| 42 | #define RV3029_IRQ_FLAGS_V1IF BIT(2) |
| 43 | #define RV3029_IRQ_FLAGS_V2IF BIT(3) |
| 44 | #define RV3029_IRQ_FLAGS_SRF BIT(4) |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 45 | #define RV3029_STATUS 0x03 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 46 | #define RV3029_STATUS_VLOW1 BIT(2) |
| 47 | #define RV3029_STATUS_VLOW2 BIT(3) |
| 48 | #define RV3029_STATUS_SR BIT(4) |
| 49 | #define RV3029_STATUS_PON BIT(5) |
| 50 | #define RV3029_STATUS_EEBUSY BIT(7) |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 51 | #define RV3029_RST_CTRL 0x04 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 52 | #define RV3029_RST_CTRL_SYSR BIT(4) |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 53 | #define RV3029_CONTROL_SECTION_LEN 0x05 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 54 | |
| 55 | /* watch section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 56 | #define RV3029_W_SEC 0x08 |
| 57 | #define RV3029_W_MINUTES 0x09 |
| 58 | #define RV3029_W_HOURS 0x0A |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 59 | #define RV3029_REG_HR_12_24 BIT(6) /* 24h/12h mode */ |
| 60 | #define RV3029_REG_HR_PM BIT(5) /* PM/AM bit in 12h mode */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 61 | #define RV3029_W_DATE 0x0B |
| 62 | #define RV3029_W_DAYS 0x0C |
| 63 | #define RV3029_W_MONTHS 0x0D |
| 64 | #define RV3029_W_YEARS 0x0E |
| 65 | #define RV3029_WATCH_SECTION_LEN 0x07 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 66 | |
| 67 | /* alarm section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 68 | #define RV3029_A_SC 0x10 |
| 69 | #define RV3029_A_MN 0x11 |
| 70 | #define RV3029_A_HR 0x12 |
| 71 | #define RV3029_A_DT 0x13 |
| 72 | #define RV3029_A_DW 0x14 |
| 73 | #define RV3029_A_MO 0x15 |
| 74 | #define RV3029_A_YR 0x16 |
Mylène Josserand | dc492e8 | 2016-05-03 11:54:36 +0200 | [diff] [blame] | 75 | #define RV3029_A_AE_X BIT(7) |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 76 | #define RV3029_ALARM_SECTION_LEN 0x07 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 77 | |
| 78 | /* timer section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 79 | #define RV3029_TIMER_LOW 0x18 |
| 80 | #define RV3029_TIMER_HIGH 0x19 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 81 | |
| 82 | /* temperature section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 83 | #define RV3029_TEMP_PAGE 0x20 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 84 | |
| 85 | /* eeprom data section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 86 | #define RV3029_E2P_EEDATA1 0x28 |
| 87 | #define RV3029_E2P_EEDATA2 0x29 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 88 | #define RV3029_E2PDATA_SECTION_LEN 0x02 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 89 | |
| 90 | /* eeprom control section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 91 | #define RV3029_CONTROL_E2P_EECTRL 0x30 |
Michael Büsch | 7697de3 | 2016-03-04 22:39:49 +0100 | [diff] [blame] | 92 | #define RV3029_EECTRL_THP BIT(0) /* temp scan interval */ |
| 93 | #define RV3029_EECTRL_THE BIT(1) /* thermometer enable */ |
| 94 | #define RV3029_EECTRL_FD0 BIT(2) /* CLKOUT */ |
| 95 | #define RV3029_EECTRL_FD1 BIT(3) /* CLKOUT */ |
| 96 | #define RV3029_TRICKLE_1K BIT(4) /* 1.5K resistance */ |
| 97 | #define RV3029_TRICKLE_5K BIT(5) /* 5K resistance */ |
| 98 | #define RV3029_TRICKLE_20K BIT(6) /* 20K resistance */ |
| 99 | #define RV3029_TRICKLE_80K BIT(7) /* 80K resistance */ |
| 100 | #define RV3029_TRICKLE_MASK (RV3029_TRICKLE_1K |\ |
| 101 | RV3029_TRICKLE_5K |\ |
| 102 | RV3029_TRICKLE_20K |\ |
| 103 | RV3029_TRICKLE_80K) |
| 104 | #define RV3029_TRICKLE_SHIFT 4 |
| 105 | #define RV3029_CONTROL_E2P_XOFFS 0x31 /* XTAL offset */ |
| 106 | #define RV3029_CONTROL_E2P_XOFFS_SIGN BIT(7) /* Sign: 1->pos, 0->neg */ |
| 107 | #define RV3029_CONTROL_E2P_QCOEF 0x32 /* XTAL temp drift coef */ |
| 108 | #define RV3029_CONTROL_E2P_TURNOVER 0x33 /* XTAL turnover temp (in *C) */ |
| 109 | #define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */ |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 110 | |
| 111 | /* user ram section */ |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 112 | #define RV3029_USR1_RAM_PAGE 0x38 |
| 113 | #define RV3029_USR1_SECTION_LEN 0x04 |
| 114 | #define RV3029_USR2_RAM_PAGE 0x3C |
| 115 | #define RV3029_USR2_SECTION_LEN 0x04 |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 116 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 117 | struct rv3029_data { |
| 118 | struct device *dev; |
| 119 | struct rtc_device *rtc; |
| 120 | struct regmap *regmap; |
| 121 | int irq; |
| 122 | }; |
| 123 | |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 124 | static int rv3029_eeprom_busywait(struct rv3029_data *rv3029) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 125 | { |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 126 | unsigned int sr; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 127 | int i, ret; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 128 | |
| 129 | for (i = 100; i > 0; i--) { |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 130 | ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 131 | if (ret < 0) |
| 132 | break; |
| 133 | if (!(sr & RV3029_STATUS_EEBUSY)) |
| 134 | break; |
| 135 | usleep_range(1000, 10000); |
| 136 | } |
| 137 | if (i <= 0) { |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 138 | dev_err(rv3029->dev, "EEPROM busy wait timeout.\n"); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 139 | return -ETIMEDOUT; |
| 140 | } |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 145 | static int rv3029_eeprom_exit(struct rv3029_data *rv3029) |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 146 | { |
| 147 | /* Re-enable eeprom refresh */ |
Alexandre Belloni | 609e97f | 2019-12-14 23:10:09 +0100 | [diff] [blame] | 148 | return regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL, |
Mylène Josserand | 4e7f1a6 | 2016-05-03 11:54:32 +0200 | [diff] [blame] | 149 | RV3029_ONOFF_CTRL_EERE, |
| 150 | RV3029_ONOFF_CTRL_EERE); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 153 | static int rv3029_eeprom_enter(struct rv3029_data *rv3029) |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 154 | { |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 155 | unsigned int sr; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 156 | int ret; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 157 | |
| 158 | /* Check whether we are in the allowed voltage range. */ |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 159 | ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 160 | if (ret < 0) |
| 161 | return ret; |
| 162 | if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { |
| 163 | /* We clear the bits and retry once just in case |
| 164 | * we had a brown out in early startup. |
| 165 | */ |
Alexandre Belloni | 54c5970 | 2019-12-14 23:10:10 +0100 | [diff] [blame] | 166 | ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS, |
| 167 | RV3029_STATUS_VLOW1 | |
| 168 | RV3029_STATUS_VLOW2, 0); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 169 | if (ret < 0) |
| 170 | return ret; |
| 171 | usleep_range(1000, 10000); |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 172 | ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 173 | if (ret < 0) |
| 174 | return ret; |
| 175 | if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 176 | dev_err(rv3029->dev, |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 177 | "Supply voltage is too low to safely access the EEPROM.\n"); |
| 178 | return -ENODEV; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /* Disable eeprom refresh. */ |
Alexandre Belloni | 609e97f | 2019-12-14 23:10:09 +0100 | [diff] [blame] | 183 | ret = regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL, |
| 184 | RV3029_ONOFF_CTRL_EERE, 0); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 185 | if (ret < 0) |
| 186 | return ret; |
| 187 | |
| 188 | /* Wait for any previous eeprom accesses to finish. */ |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 189 | ret = rv3029_eeprom_busywait(rv3029); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 190 | if (ret < 0) |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 191 | rv3029_eeprom_exit(rv3029); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 192 | |
| 193 | return ret; |
| 194 | } |
| 195 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 196 | static int rv3029_eeprom_read(struct rv3029_data *rv3029, u8 reg, |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 197 | u8 buf[], size_t len) |
| 198 | { |
| 199 | int ret, err; |
| 200 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 201 | err = rv3029_eeprom_enter(rv3029); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 202 | if (err < 0) |
| 203 | return err; |
| 204 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 205 | ret = regmap_bulk_read(rv3029->regmap, reg, buf, len); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 206 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 207 | err = rv3029_eeprom_exit(rv3029); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 208 | if (err < 0) |
| 209 | return err; |
| 210 | |
| 211 | return ret; |
| 212 | } |
| 213 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 214 | static int rv3029_eeprom_write(struct rv3029_data *rv3029, u8 reg, |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 215 | u8 const buf[], size_t len) |
| 216 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 217 | unsigned int tmp; |
Dan Carpenter | a6f2660 | 2019-08-17 09:56:04 +0300 | [diff] [blame] | 218 | int ret, err; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 219 | size_t i; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 220 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 221 | err = rv3029_eeprom_enter(rv3029); |
Dan Carpenter | a6f2660 | 2019-08-17 09:56:04 +0300 | [diff] [blame] | 222 | if (err < 0) |
| 223 | return err; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 224 | |
| 225 | for (i = 0; i < len; i++, reg++) { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 226 | ret = regmap_read(rv3029->regmap, reg, &tmp); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 227 | if (ret < 0) |
| 228 | break; |
| 229 | if (tmp != buf[i]) { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 230 | tmp = buf[i]; |
| 231 | ret = regmap_write(rv3029->regmap, reg, tmp); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 232 | if (ret < 0) |
| 233 | break; |
| 234 | } |
Alexandre Belloni | bb72dbb | 2019-12-14 23:10:12 +0100 | [diff] [blame] | 235 | ret = rv3029_eeprom_busywait(rv3029); |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 236 | if (ret < 0) |
| 237 | break; |
| 238 | } |
| 239 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 240 | err = rv3029_eeprom_exit(rv3029); |
Dan Carpenter | a6f2660 | 2019-08-17 09:56:04 +0300 | [diff] [blame] | 241 | if (err < 0) |
| 242 | return err; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 243 | |
Dan Carpenter | a6f2660 | 2019-08-17 09:56:04 +0300 | [diff] [blame] | 244 | return ret; |
Michael Büsch | a7f6e28 | 2016-03-04 22:40:55 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 247 | static int rv3029_eeprom_update_bits(struct rv3029_data *rv3029, |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 248 | u8 reg, u8 mask, u8 set) |
| 249 | { |
| 250 | u8 buf; |
| 251 | int ret; |
| 252 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 253 | ret = rv3029_eeprom_read(rv3029, reg, &buf, 1); |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 254 | if (ret < 0) |
| 255 | return ret; |
| 256 | buf &= ~mask; |
| 257 | buf |= set & mask; |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 258 | ret = rv3029_eeprom_write(rv3029, reg, &buf, 1); |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 259 | if (ret < 0) |
| 260 | return ret; |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 265 | static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) |
| 266 | { |
| 267 | struct device *dev = dev_id; |
| 268 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
| 269 | struct mutex *lock = &rv3029->rtc->ops_lock; |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 270 | unsigned int flags, controls; |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 271 | unsigned long events = 0; |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 272 | int ret; |
| 273 | |
| 274 | mutex_lock(lock); |
| 275 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 276 | ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 277 | if (ret) { |
| 278 | dev_warn(dev, "Read IRQ Control Register error %d\n", ret); |
| 279 | mutex_unlock(lock); |
| 280 | return IRQ_NONE; |
| 281 | } |
| 282 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 283 | ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 284 | if (ret) { |
| 285 | dev_warn(dev, "Read IRQ Flags Register error %d\n", ret); |
| 286 | mutex_unlock(lock); |
| 287 | return IRQ_NONE; |
| 288 | } |
| 289 | |
| 290 | if (flags & RV3029_IRQ_FLAGS_AF) { |
| 291 | flags &= ~RV3029_IRQ_FLAGS_AF; |
| 292 | controls &= ~RV3029_IRQ_CTRL_AIE; |
| 293 | events |= RTC_AF; |
| 294 | } |
| 295 | |
| 296 | if (events) { |
| 297 | rtc_update_irq(rv3029->rtc, 1, events); |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 298 | regmap_write(rv3029->regmap, RV3029_IRQ_FLAGS, flags); |
| 299 | regmap_write(rv3029->regmap, RV3029_IRQ_CTRL, controls); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 300 | } |
| 301 | mutex_unlock(lock); |
| 302 | |
| 303 | return IRQ_HANDLED; |
| 304 | } |
| 305 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 306 | static int rv3029_read_time(struct device *dev, struct rtc_time *tm) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 307 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 308 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 309 | int ret; |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 310 | u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 311 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 312 | ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs, |
Mylène Josserand | 4e7f1a6 | 2016-05-03 11:54:32 +0200 | [diff] [blame] | 313 | RV3029_WATCH_SECTION_LEN); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 314 | if (ret < 0) { |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 315 | dev_err(dev, "%s: reading RTC section failed\n", __func__); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 316 | return ret; |
| 317 | } |
| 318 | |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 319 | tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]); |
| 320 | tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES - RV3029_W_SEC]); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 321 | |
| 322 | /* HR field has a more complex interpretation */ |
| 323 | { |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 324 | const u8 _hr = regs[RV3029_W_HOURS - RV3029_W_SEC]; |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 325 | |
| 326 | if (_hr & RV3029_REG_HR_12_24) { |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 327 | /* 12h format */ |
| 328 | tm->tm_hour = bcd2bin(_hr & 0x1f); |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 329 | if (_hr & RV3029_REG_HR_PM) /* PM flag set */ |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 330 | tm->tm_hour += 12; |
| 331 | } else /* 24h format */ |
| 332 | tm->tm_hour = bcd2bin(_hr & 0x3f); |
| 333 | } |
| 334 | |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 335 | tm->tm_mday = bcd2bin(regs[RV3029_W_DATE - RV3029_W_SEC]); |
| 336 | tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1; |
| 337 | tm->tm_year = bcd2bin(regs[RV3029_W_YEARS - RV3029_W_SEC]) + 100; |
| 338 | tm->tm_wday = bcd2bin(regs[RV3029_W_DAYS - RV3029_W_SEC]) - 1; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 343 | static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 344 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 345 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 346 | struct rtc_time *const tm = &alarm->time; |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 347 | unsigned int controls, flags; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 348 | int ret; |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 349 | u8 regs[8]; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 350 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 351 | ret = regmap_bulk_read(rv3029->regmap, RV3029_A_SC, regs, |
Mylène Josserand | 4e7f1a6 | 2016-05-03 11:54:32 +0200 | [diff] [blame] | 352 | RV3029_ALARM_SECTION_LEN); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 353 | if (ret < 0) { |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 354 | dev_err(dev, "%s: reading alarm section failed\n", __func__); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 355 | return ret; |
| 356 | } |
| 357 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 358 | ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 359 | if (ret) { |
| 360 | dev_err(dev, "Read IRQ Control Register error %d\n", ret); |
| 361 | return ret; |
| 362 | } |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 363 | ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 364 | if (ret < 0) { |
| 365 | dev_err(dev, "Read IRQ Flags Register error %d\n", ret); |
| 366 | return ret; |
| 367 | } |
| 368 | |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 369 | tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f); |
| 370 | tm->tm_min = bcd2bin(regs[RV3029_A_MN - RV3029_A_SC] & 0x7f); |
| 371 | tm->tm_hour = bcd2bin(regs[RV3029_A_HR - RV3029_A_SC] & 0x3f); |
| 372 | tm->tm_mday = bcd2bin(regs[RV3029_A_DT - RV3029_A_SC] & 0x3f); |
| 373 | tm->tm_mon = bcd2bin(regs[RV3029_A_MO - RV3029_A_SC] & 0x1f) - 1; |
| 374 | tm->tm_year = bcd2bin(regs[RV3029_A_YR - RV3029_A_SC] & 0x7f) + 100; |
| 375 | tm->tm_wday = bcd2bin(regs[RV3029_A_DW - RV3029_A_SC] & 0x07) - 1; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 376 | |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 377 | alarm->enabled = !!(controls & RV3029_IRQ_CTRL_AIE); |
| 378 | alarm->pending = (flags & RV3029_IRQ_FLAGS_AF) && alarm->enabled; |
| 379 | |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 380 | return 0; |
| 381 | } |
| 382 | |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 383 | static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 384 | { |
Alexandre Belloni | 38ce8e3 | 2019-12-14 23:10:13 +0100 | [diff] [blame] | 385 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 386 | |
Alexandre Belloni | 38ce8e3 | 2019-12-14 23:10:13 +0100 | [diff] [blame] | 387 | return regmap_update_bits(rv3029->regmap, RV3029_IRQ_CTRL, |
| 388 | RV3029_IRQ_CTRL_AIE, |
| 389 | enable ? RV3029_IRQ_CTRL_AIE : 0); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 392 | static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 393 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 394 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 395 | struct rtc_time *const tm = &alarm->time; |
| 396 | int ret; |
| 397 | u8 regs[8]; |
| 398 | |
| 399 | /* |
| 400 | * The clock has an 8 bit wide bcd-coded register (they never learn) |
| 401 | * for the year. tm_year is an offset from 1900 and we are interested |
| 402 | * in the 2000-2099 range, so any value less than 100 is invalid. |
| 403 | */ |
| 404 | if (tm->tm_year < 100) |
| 405 | return -EINVAL; |
| 406 | |
Mylène Josserand | dc492e8 | 2016-05-03 11:54:36 +0200 | [diff] [blame] | 407 | /* Activate all the alarms with AE_x bit */ |
| 408 | regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X; |
| 409 | regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min) | RV3029_A_AE_X; |
| 410 | regs[RV3029_A_HR - RV3029_A_SC] = (bin2bcd(tm->tm_hour) & 0x3f) |
| 411 | | RV3029_A_AE_X; |
| 412 | regs[RV3029_A_DT - RV3029_A_SC] = (bin2bcd(tm->tm_mday) & 0x3f) |
| 413 | | RV3029_A_AE_X; |
| 414 | regs[RV3029_A_MO - RV3029_A_SC] = (bin2bcd(tm->tm_mon + 1) & 0x1f) |
| 415 | | RV3029_A_AE_X; |
| 416 | regs[RV3029_A_DW - RV3029_A_SC] = (bin2bcd(tm->tm_wday + 1) & 0x7) |
| 417 | | RV3029_A_AE_X; |
| 418 | regs[RV3029_A_YR - RV3029_A_SC] = (bin2bcd(tm->tm_year - 100)) |
| 419 | | RV3029_A_AE_X; |
| 420 | |
| 421 | /* Write the alarm */ |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 422 | ret = regmap_bulk_write(rv3029->regmap, RV3029_A_SC, regs, |
Mylène Josserand | 4e7f1a6 | 2016-05-03 11:54:32 +0200 | [diff] [blame] | 423 | RV3029_ALARM_SECTION_LEN); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 424 | if (ret < 0) |
| 425 | return ret; |
| 426 | |
Alexandre Belloni | 8fd3d60 | 2019-12-14 23:10:14 +0100 | [diff] [blame] | 427 | return rv3029_alarm_irq_enable(dev, alarm->enabled); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 430 | static int rv3029_set_time(struct device *dev, struct rtc_time *tm) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 431 | { |
Alexandre Belloni | 54c5970 | 2019-12-14 23:10:10 +0100 | [diff] [blame] | 432 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 433 | u8 regs[8]; |
| 434 | int ret; |
| 435 | |
| 436 | /* |
| 437 | * The clock has an 8 bit wide bcd-coded register (they never learn) |
| 438 | * for the year. tm_year is an offset from 1900 and we are interested |
| 439 | * in the 2000-2099 range, so any value less than 100 is invalid. |
| 440 | */ |
| 441 | if (tm->tm_year < 100) |
| 442 | return -EINVAL; |
| 443 | |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 444 | regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec); |
| 445 | regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min); |
| 446 | regs[RV3029_W_HOURS - RV3029_W_SEC] = bin2bcd(tm->tm_hour); |
| 447 | regs[RV3029_W_DATE - RV3029_W_SEC] = bin2bcd(tm->tm_mday); |
| 448 | regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1); |
Mylène Josserand | 38201ca | 2016-05-03 11:54:37 +0200 | [diff] [blame] | 449 | regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7; |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 450 | regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 100); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 451 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 452 | ret = regmap_bulk_write(rv3029->regmap, RV3029_W_SEC, regs, |
Mylène Josserand | 4e7f1a6 | 2016-05-03 11:54:32 +0200 | [diff] [blame] | 453 | RV3029_WATCH_SECTION_LEN); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 454 | if (ret < 0) |
| 455 | return ret; |
| 456 | |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 457 | /* clear PON bit */ |
Alexandre Belloni | 54c5970 | 2019-12-14 23:10:10 +0100 | [diff] [blame] | 458 | return regmap_update_bits(rv3029->regmap, RV3029_STATUS, |
| 459 | RV3029_STATUS_PON, 0); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 460 | } |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 461 | |
Alexandre Belloni | f630f72 | 2019-12-14 23:10:16 +0100 | [diff] [blame^] | 462 | static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) |
| 463 | { |
| 464 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
| 465 | unsigned long vl = 0; |
| 466 | int sr, ret = 0; |
| 467 | |
| 468 | switch (cmd) { |
| 469 | case RTC_VL_READ: |
| 470 | ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); |
| 471 | if (ret < 0) |
| 472 | return ret; |
| 473 | |
| 474 | if (sr & RV3029_STATUS_VLOW1) |
| 475 | vl = RTC_VL_ACCURACY_LOW; |
| 476 | |
| 477 | if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON)) |
| 478 | vl |= RTC_VL_DATA_INVALID; |
| 479 | |
| 480 | return put_user(vl, (unsigned int __user *)arg); |
| 481 | |
| 482 | case RTC_VL_CLR: |
| 483 | return regmap_update_bits(rv3029->regmap, RV3029_STATUS, |
| 484 | RV3029_STATUS_VLOW1, 0); |
| 485 | |
| 486 | default: |
| 487 | return -ENOIOCTLCMD; |
| 488 | } |
| 489 | } |
| 490 | |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 491 | static const struct rv3029_trickle_tab_elem { |
| 492 | u32 r; /* resistance in ohms */ |
| 493 | u8 conf; /* trickle config bits */ |
| 494 | } rv3029_trickle_tab[] = { |
| 495 | { |
| 496 | .r = 1076, |
| 497 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K | |
| 498 | RV3029_TRICKLE_20K | RV3029_TRICKLE_80K, |
| 499 | }, { |
| 500 | .r = 1091, |
| 501 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K | |
| 502 | RV3029_TRICKLE_20K, |
| 503 | }, { |
| 504 | .r = 1137, |
| 505 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K | |
| 506 | RV3029_TRICKLE_80K, |
| 507 | }, { |
| 508 | .r = 1154, |
| 509 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K, |
| 510 | }, { |
| 511 | .r = 1371, |
| 512 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_20K | |
| 513 | RV3029_TRICKLE_80K, |
| 514 | }, { |
| 515 | .r = 1395, |
| 516 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_20K, |
| 517 | }, { |
| 518 | .r = 1472, |
| 519 | .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_80K, |
| 520 | }, { |
| 521 | .r = 1500, |
| 522 | .conf = RV3029_TRICKLE_1K, |
| 523 | }, { |
| 524 | .r = 3810, |
| 525 | .conf = RV3029_TRICKLE_5K | RV3029_TRICKLE_20K | |
| 526 | RV3029_TRICKLE_80K, |
| 527 | }, { |
| 528 | .r = 4000, |
| 529 | .conf = RV3029_TRICKLE_5K | RV3029_TRICKLE_20K, |
| 530 | }, { |
| 531 | .r = 4706, |
| 532 | .conf = RV3029_TRICKLE_5K | RV3029_TRICKLE_80K, |
| 533 | }, { |
| 534 | .r = 5000, |
| 535 | .conf = RV3029_TRICKLE_5K, |
| 536 | }, { |
| 537 | .r = 16000, |
| 538 | .conf = RV3029_TRICKLE_20K | RV3029_TRICKLE_80K, |
| 539 | }, { |
| 540 | .r = 20000, |
| 541 | .conf = RV3029_TRICKLE_20K, |
| 542 | }, { |
| 543 | .r = 80000, |
| 544 | .conf = RV3029_TRICKLE_80K, |
| 545 | }, |
| 546 | }; |
| 547 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 548 | static void rv3029_trickle_config(struct device *dev) |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 549 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 550 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 551 | struct device_node *of_node = dev->of_node; |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 552 | const struct rv3029_trickle_tab_elem *elem; |
| 553 | int i, err; |
| 554 | u32 ohms; |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 555 | u8 trickle_set_bits; |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 556 | |
| 557 | if (!of_node) |
| 558 | return; |
| 559 | |
| 560 | /* Configure the trickle charger. */ |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 561 | err = of_property_read_u32(of_node, "trickle-resistor-ohms", &ohms); |
| 562 | if (err) { |
| 563 | /* Disable trickle charger. */ |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 564 | trickle_set_bits = 0; |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 565 | } else { |
| 566 | /* Enable trickle charger. */ |
| 567 | for (i = 0; i < ARRAY_SIZE(rv3029_trickle_tab); i++) { |
| 568 | elem = &rv3029_trickle_tab[i]; |
| 569 | if (elem->r >= ohms) |
| 570 | break; |
| 571 | } |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 572 | trickle_set_bits = elem->conf; |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 573 | dev_info(dev, |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 574 | "Trickle charger enabled at %d ohms resistance.\n", |
| 575 | elem->r); |
| 576 | } |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 577 | err = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL, |
Michael Büsch | 39387dc2 | 2016-03-10 18:34:23 +0100 | [diff] [blame] | 578 | RV3029_TRICKLE_MASK, |
| 579 | trickle_set_bits); |
Mylène Josserand | abe2f55 | 2016-05-03 11:54:35 +0200 | [diff] [blame] | 580 | if (err < 0) |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 581 | dev_err(dev, "Failed to update trickle charger config\n"); |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 582 | } |
| 583 | |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 584 | #ifdef CONFIG_RTC_DRV_RV3029_HWMON |
| 585 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 586 | static int rv3029_read_temp(struct rv3029_data *rv3029, int *temp_mC) |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 587 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 588 | unsigned int temp; |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 589 | int ret; |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 590 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 591 | ret = regmap_read(rv3029->regmap, RV3029_TEMP_PAGE, &temp); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 592 | if (ret < 0) |
| 593 | return ret; |
| 594 | |
| 595 | *temp_mC = ((int)temp - 60) * 1000; |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static ssize_t rv3029_hwmon_show_temp(struct device *dev, |
| 601 | struct device_attribute *attr, |
| 602 | char *buf) |
| 603 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 604 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 605 | int ret, temp_mC; |
| 606 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 607 | ret = rv3029_read_temp(rv3029, &temp_mC); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 608 | if (ret < 0) |
| 609 | return ret; |
| 610 | |
| 611 | return sprintf(buf, "%d\n", temp_mC); |
| 612 | } |
| 613 | |
| 614 | static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, |
| 615 | struct device_attribute *attr, |
| 616 | const char *buf, |
| 617 | size_t count) |
| 618 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 619 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
| 620 | unsigned int th_set_bits = 0; |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 621 | unsigned long interval_ms; |
| 622 | int ret; |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 623 | |
| 624 | ret = kstrtoul(buf, 10, &interval_ms); |
| 625 | if (ret < 0) |
| 626 | return ret; |
| 627 | |
| 628 | if (interval_ms != 0) { |
| 629 | th_set_bits |= RV3029_EECTRL_THE; |
| 630 | if (interval_ms >= 16000) |
| 631 | th_set_bits |= RV3029_EECTRL_THP; |
| 632 | } |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 633 | ret = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL, |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 634 | RV3029_EECTRL_THE | RV3029_EECTRL_THP, |
| 635 | th_set_bits); |
| 636 | if (ret < 0) |
| 637 | return ret; |
| 638 | |
| 639 | return count; |
| 640 | } |
| 641 | |
| 642 | static ssize_t rv3029_hwmon_show_update_interval(struct device *dev, |
| 643 | struct device_attribute *attr, |
| 644 | char *buf) |
| 645 | { |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 646 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 647 | int ret, interval_ms; |
| 648 | u8 eectrl; |
| 649 | |
Alexandre Belloni | 7518dd9 | 2019-12-14 23:10:15 +0100 | [diff] [blame] | 650 | ret = rv3029_eeprom_read(rv3029, RV3029_CONTROL_E2P_EECTRL, |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 651 | &eectrl, 1); |
| 652 | if (ret < 0) |
| 653 | return ret; |
| 654 | |
| 655 | if (eectrl & RV3029_EECTRL_THE) { |
| 656 | if (eectrl & RV3029_EECTRL_THP) |
| 657 | interval_ms = 16000; |
| 658 | else |
| 659 | interval_ms = 1000; |
| 660 | } else { |
| 661 | interval_ms = 0; |
| 662 | } |
| 663 | |
| 664 | return sprintf(buf, "%d\n", interval_ms); |
| 665 | } |
| 666 | |
| 667 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, rv3029_hwmon_show_temp, |
| 668 | NULL, 0); |
| 669 | static SENSOR_DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, |
| 670 | rv3029_hwmon_show_update_interval, |
| 671 | rv3029_hwmon_set_update_interval, 0); |
| 672 | |
| 673 | static struct attribute *rv3029_hwmon_attrs[] = { |
| 674 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 675 | &sensor_dev_attr_update_interval.dev_attr.attr, |
| 676 | NULL, |
| 677 | }; |
| 678 | ATTRIBUTE_GROUPS(rv3029_hwmon); |
| 679 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 680 | static void rv3029_hwmon_register(struct device *dev, const char *name) |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 681 | { |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 682 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 683 | struct device *hwmon_dev; |
| 684 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 685 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, name, rv3029, |
| 686 | rv3029_hwmon_groups); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 687 | if (IS_ERR(hwmon_dev)) { |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 688 | dev_warn(dev, "unable to register hwmon device %ld\n", |
Mylène Josserand | 4e7f1a6 | 2016-05-03 11:54:32 +0200 | [diff] [blame] | 689 | PTR_ERR(hwmon_dev)); |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | #else /* CONFIG_RTC_DRV_RV3029_HWMON */ |
| 694 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 695 | static void rv3029_hwmon_register(struct device *dev, const char *name) |
Michael Büsch | a696b31 | 2016-03-10 18:34:46 +0100 | [diff] [blame] | 696 | { |
| 697 | } |
| 698 | |
| 699 | #endif /* CONFIG_RTC_DRV_RV3029_HWMON */ |
| 700 | |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 701 | static struct rtc_class_ops rv3029_rtc_ops = { |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 702 | .read_time = rv3029_read_time, |
| 703 | .set_time = rv3029_set_time, |
Alexandre Belloni | f630f72 | 2019-12-14 23:10:16 +0100 | [diff] [blame^] | 704 | .ioctl = rv3029_ioctl, |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 705 | }; |
| 706 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 707 | static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, |
| 708 | const char *name) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 709 | { |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 710 | struct rv3029_data *rv3029; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 711 | int rc = 0; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 712 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 713 | rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL); |
| 714 | if (!rv3029) |
| 715 | return -ENOMEM; |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 716 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 717 | rv3029->regmap = regmap; |
| 718 | rv3029->irq = irq; |
| 719 | rv3029->dev = dev; |
| 720 | dev_set_drvdata(dev, rv3029); |
| 721 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 722 | rv3029_trickle_config(dev); |
| 723 | rv3029_hwmon_register(dev, name); |
Michael Büsch | e27e216 | 2016-03-04 22:41:19 +0100 | [diff] [blame] | 724 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 725 | rv3029->rtc = devm_rtc_device_register(dev, name, &rv3029_rtc_ops, |
| 726 | THIS_MODULE); |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 727 | if (IS_ERR(rv3029->rtc)) { |
| 728 | dev_err(dev, "unable to register the class device\n"); |
| 729 | return PTR_ERR(rv3029->rtc); |
| 730 | } |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 731 | |
Mylène Josserand | 0ddc5b8 | 2016-05-03 11:54:38 +0200 | [diff] [blame] | 732 | if (rv3029->irq > 0) { |
| 733 | rc = devm_request_threaded_irq(dev, rv3029->irq, |
| 734 | NULL, rv3029_handle_irq, |
| 735 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
| 736 | "rv3029", dev); |
| 737 | if (rc) { |
| 738 | dev_warn(dev, "unable to request IRQ, alarms disabled\n"); |
| 739 | rv3029->irq = 0; |
| 740 | } else { |
| 741 | rv3029_rtc_ops.read_alarm = rv3029_read_alarm; |
| 742 | rv3029_rtc_ops.set_alarm = rv3029_set_alarm; |
| 743 | rv3029_rtc_ops.alarm_irq_enable = rv3029_alarm_irq_enable; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | return 0; |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 748 | } |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 749 | |
Alexandre Belloni | c509e43 | 2019-12-14 23:10:08 +0100 | [diff] [blame] | 750 | static const struct regmap_range rv3029_holes_range[] = { |
| 751 | regmap_reg_range(0x05, 0x07), |
| 752 | regmap_reg_range(0x0f, 0x0f), |
| 753 | regmap_reg_range(0x17, 0x17), |
| 754 | regmap_reg_range(0x1a, 0x1f), |
| 755 | regmap_reg_range(0x21, 0x27), |
| 756 | regmap_reg_range(0x34, 0x37), |
| 757 | }; |
| 758 | |
| 759 | static const struct regmap_access_table rv3029_regs = { |
| 760 | .no_ranges = rv3029_holes_range, |
| 761 | .n_no_ranges = ARRAY_SIZE(rv3029_holes_range), |
| 762 | }; |
| 763 | |
| 764 | static const struct regmap_config config = { |
| 765 | .reg_bits = 8, |
| 766 | .val_bits = 8, |
| 767 | .rd_table = &rv3029_regs, |
| 768 | .wr_table = &rv3029_regs, |
| 769 | .max_register = 0x3f, |
| 770 | }; |
| 771 | |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 772 | #if IS_ENABLED(CONFIG_I2C) |
| 773 | |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 774 | static int rv3029_i2c_probe(struct i2c_client *client, |
| 775 | const struct i2c_device_id *id) |
| 776 | { |
| 777 | struct regmap *regmap; |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 778 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK | |
| 779 | I2C_FUNC_SMBUS_BYTE)) { |
| 780 | dev_err(&client->dev, "Adapter does not support SMBUS_I2C_BLOCK or SMBUS_I2C_BYTE\n"); |
| 781 | return -ENODEV; |
| 782 | } |
| 783 | |
| 784 | regmap = devm_regmap_init_i2c(client, &config); |
| 785 | if (IS_ERR(regmap)) { |
| 786 | dev_err(&client->dev, "%s: regmap allocation failed: %ld\n", |
| 787 | __func__, PTR_ERR(regmap)); |
| 788 | return PTR_ERR(regmap); |
| 789 | } |
| 790 | |
| 791 | return rv3029_probe(&client->dev, regmap, client->irq, client->name); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Arvind Yadav | 45a6351 | 2017-08-20 00:37:55 +0530 | [diff] [blame] | 794 | static const struct i2c_device_id rv3029_id[] = { |
Arnd Bergmann | 814db2b | 2016-05-04 11:50:02 +0200 | [diff] [blame] | 795 | { "rv3029", 0 }, |
| 796 | { "rv3029c2", 0 }, |
| 797 | { } |
| 798 | }; |
| 799 | MODULE_DEVICE_TABLE(i2c, rv3029_id); |
| 800 | |
Javier Martinez Canillas | e696a1d | 2017-03-03 11:29:13 -0300 | [diff] [blame] | 801 | static const struct of_device_id rv3029_of_match[] = { |
Alexandre Belloni | 45b611c | 2017-09-15 04:00:02 +0200 | [diff] [blame] | 802 | { .compatible = "microcrystal,rv3029" }, |
| 803 | /* Backward compatibility only, do not use compatibles below: */ |
Javier Martinez Canillas | e696a1d | 2017-03-03 11:29:13 -0300 | [diff] [blame] | 804 | { .compatible = "rv3029" }, |
| 805 | { .compatible = "rv3029c2" }, |
| 806 | { .compatible = "mc,rv3029c2" }, |
| 807 | { } |
| 808 | }; |
| 809 | MODULE_DEVICE_TABLE(of, rv3029_of_match); |
| 810 | |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 811 | static struct i2c_driver rv3029_driver = { |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 812 | .driver = { |
Alexandre Belloni | 9b45ef9 | 2019-12-14 23:10:07 +0100 | [diff] [blame] | 813 | .name = "rv3029", |
Javier Martinez Canillas | e696a1d | 2017-03-03 11:29:13 -0300 | [diff] [blame] | 814 | .of_match_table = of_match_ptr(rv3029_of_match), |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 815 | }, |
Mylène Josserand | e6e3808 | 2016-05-03 11:54:33 +0200 | [diff] [blame] | 816 | .probe = rv3029_i2c_probe, |
Michael Büsch | aba39d2 | 2016-03-04 22:38:45 +0100 | [diff] [blame] | 817 | .id_table = rv3029_id, |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 818 | }; |
| 819 | |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 820 | static int rv3029_register_driver(void) |
| 821 | { |
| 822 | return i2c_add_driver(&rv3029_driver); |
| 823 | } |
| 824 | |
| 825 | static void rv3029_unregister_driver(void) |
| 826 | { |
| 827 | i2c_del_driver(&rv3029_driver); |
| 828 | } |
| 829 | |
| 830 | #else |
| 831 | |
| 832 | static int rv3029_register_driver(void) |
| 833 | { |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | static void rv3029_unregister_driver(void) |
| 838 | { |
| 839 | } |
| 840 | |
| 841 | #endif |
| 842 | |
| 843 | #if IS_ENABLED(CONFIG_SPI_MASTER) |
| 844 | |
| 845 | static int rv3049_probe(struct spi_device *spi) |
| 846 | { |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 847 | struct regmap *regmap; |
| 848 | |
| 849 | regmap = devm_regmap_init_spi(spi, &config); |
| 850 | if (IS_ERR(regmap)) { |
| 851 | dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", |
| 852 | __func__, PTR_ERR(regmap)); |
| 853 | return PTR_ERR(regmap); |
| 854 | } |
| 855 | |
| 856 | return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049"); |
| 857 | } |
| 858 | |
| 859 | static struct spi_driver rv3049_driver = { |
| 860 | .driver = { |
| 861 | .name = "rv3049", |
| 862 | }, |
| 863 | .probe = rv3049_probe, |
| 864 | }; |
| 865 | |
| 866 | static int rv3049_register_driver(void) |
| 867 | { |
| 868 | return spi_register_driver(&rv3049_driver); |
| 869 | } |
| 870 | |
| 871 | static void rv3049_unregister_driver(void) |
| 872 | { |
| 873 | spi_unregister_driver(&rv3049_driver); |
| 874 | } |
| 875 | |
| 876 | #else |
| 877 | |
| 878 | static int rv3049_register_driver(void) |
| 879 | { |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | static void rv3049_unregister_driver(void) |
| 884 | { |
| 885 | } |
| 886 | |
| 887 | #endif |
| 888 | |
| 889 | static int __init rv30x9_init(void) |
| 890 | { |
| 891 | int ret; |
| 892 | |
| 893 | ret = rv3029_register_driver(); |
| 894 | if (ret) { |
| 895 | pr_err("Failed to register rv3029 driver: %d\n", ret); |
| 896 | return ret; |
| 897 | } |
| 898 | |
| 899 | ret = rv3049_register_driver(); |
| 900 | if (ret) { |
| 901 | pr_err("Failed to register rv3049 driver: %d\n", ret); |
| 902 | rv3029_unregister_driver(); |
| 903 | } |
| 904 | |
| 905 | return ret; |
| 906 | } |
| 907 | module_init(rv30x9_init) |
| 908 | |
| 909 | static void __exit rv30x9_exit(void) |
| 910 | { |
| 911 | rv3049_unregister_driver(); |
| 912 | rv3029_unregister_driver(); |
| 913 | } |
| 914 | module_exit(rv30x9_exit) |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 915 | |
| 916 | MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>"); |
Michael Büsch | 2dca3d9 | 2016-03-04 22:40:30 +0100 | [diff] [blame] | 917 | MODULE_AUTHOR("Michael Buesch <m@bues.ch>"); |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 918 | MODULE_DESCRIPTION("Micro Crystal RV3029/RV3049 RTC driver"); |
Heiko Schocher | 5236523 | 2011-05-26 16:25:05 -0700 | [diff] [blame] | 919 | MODULE_LICENSE("GPL"); |
Mylène Josserand | c2a1c14 | 2016-05-03 11:54:34 +0200 | [diff] [blame] | 920 | MODULE_ALIAS("spi:rv3049"); |