.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for the Epson RTC module RX-8010 SJ |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright(C) Timesys Corporation 2015 |
---|
5 | 6 | * Copyright(C) General Electric Company 2015 |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | | - * |
---|
11 | 7 | */ |
---|
12 | 8 | |
---|
13 | 9 | #include <linux/bcd.h> |
---|
.. | .. |
---|
15 | 11 | #include <linux/i2c.h> |
---|
16 | 12 | #include <linux/kernel.h> |
---|
17 | 13 | #include <linux/module.h> |
---|
| 14 | +#include <linux/regmap.h> |
---|
18 | 15 | #include <linux/rtc.h> |
---|
19 | 16 | |
---|
20 | | -#define RX8010_SEC 0x10 |
---|
21 | | -#define RX8010_MIN 0x11 |
---|
22 | | -#define RX8010_HOUR 0x12 |
---|
23 | | -#define RX8010_WDAY 0x13 |
---|
24 | | -#define RX8010_MDAY 0x14 |
---|
25 | | -#define RX8010_MONTH 0x15 |
---|
26 | | -#define RX8010_YEAR 0x16 |
---|
27 | | -#define RX8010_RESV17 0x17 |
---|
28 | | -#define RX8010_ALMIN 0x18 |
---|
29 | | -#define RX8010_ALHOUR 0x19 |
---|
30 | | -#define RX8010_ALWDAY 0x1A |
---|
31 | | -#define RX8010_TCOUNT0 0x1B |
---|
32 | | -#define RX8010_TCOUNT1 0x1C |
---|
33 | | -#define RX8010_EXT 0x1D |
---|
34 | | -#define RX8010_FLAG 0x1E |
---|
35 | | -#define RX8010_CTRL 0x1F |
---|
| 17 | +#define RX8010_SEC 0x10 |
---|
| 18 | +#define RX8010_MIN 0x11 |
---|
| 19 | +#define RX8010_HOUR 0x12 |
---|
| 20 | +#define RX8010_WDAY 0x13 |
---|
| 21 | +#define RX8010_MDAY 0x14 |
---|
| 22 | +#define RX8010_MONTH 0x15 |
---|
| 23 | +#define RX8010_YEAR 0x16 |
---|
| 24 | +#define RX8010_RESV17 0x17 |
---|
| 25 | +#define RX8010_ALMIN 0x18 |
---|
| 26 | +#define RX8010_ALHOUR 0x19 |
---|
| 27 | +#define RX8010_ALWDAY 0x1A |
---|
| 28 | +#define RX8010_TCOUNT0 0x1B |
---|
| 29 | +#define RX8010_TCOUNT1 0x1C |
---|
| 30 | +#define RX8010_EXT 0x1D |
---|
| 31 | +#define RX8010_FLAG 0x1E |
---|
| 32 | +#define RX8010_CTRL 0x1F |
---|
36 | 33 | /* 0x20 to 0x2F are user registers */ |
---|
37 | | -#define RX8010_RESV30 0x30 |
---|
38 | | -#define RX8010_RESV31 0x31 |
---|
39 | | -#define RX8010_IRQ 0x32 |
---|
| 34 | +#define RX8010_RESV30 0x30 |
---|
| 35 | +#define RX8010_RESV31 0x31 |
---|
| 36 | +#define RX8010_IRQ 0x32 |
---|
40 | 37 | |
---|
41 | | -#define RX8010_EXT_WADA BIT(3) |
---|
| 38 | +#define RX8010_EXT_WADA BIT(3) |
---|
42 | 39 | |
---|
43 | | -#define RX8010_FLAG_VLF BIT(1) |
---|
44 | | -#define RX8010_FLAG_AF BIT(3) |
---|
45 | | -#define RX8010_FLAG_TF BIT(4) |
---|
46 | | -#define RX8010_FLAG_UF BIT(5) |
---|
| 40 | +#define RX8010_FLAG_VLF BIT(1) |
---|
| 41 | +#define RX8010_FLAG_AF BIT(3) |
---|
| 42 | +#define RX8010_FLAG_TF BIT(4) |
---|
| 43 | +#define RX8010_FLAG_UF BIT(5) |
---|
47 | 44 | |
---|
48 | | -#define RX8010_CTRL_AIE BIT(3) |
---|
49 | | -#define RX8010_CTRL_UIE BIT(5) |
---|
50 | | -#define RX8010_CTRL_STOP BIT(6) |
---|
51 | | -#define RX8010_CTRL_TEST BIT(7) |
---|
| 45 | +#define RX8010_CTRL_AIE BIT(3) |
---|
| 46 | +#define RX8010_CTRL_UIE BIT(5) |
---|
| 47 | +#define RX8010_CTRL_STOP BIT(6) |
---|
| 48 | +#define RX8010_CTRL_TEST BIT(7) |
---|
52 | 49 | |
---|
53 | | -#define RX8010_ALARM_AE BIT(7) |
---|
| 50 | +#define RX8010_ALARM_AE BIT(7) |
---|
54 | 51 | |
---|
55 | 52 | static const struct i2c_device_id rx8010_id[] = { |
---|
56 | 53 | { "rx8010", 0 }, |
---|
.. | .. |
---|
65 | 62 | MODULE_DEVICE_TABLE(of, rx8010_of_match); |
---|
66 | 63 | |
---|
67 | 64 | struct rx8010_data { |
---|
68 | | - struct i2c_client *client; |
---|
| 65 | + struct regmap *regs; |
---|
69 | 66 | struct rtc_device *rtc; |
---|
70 | 67 | u8 ctrlreg; |
---|
71 | 68 | }; |
---|
.. | .. |
---|
74 | 71 | { |
---|
75 | 72 | struct i2c_client *client = dev_id; |
---|
76 | 73 | struct rx8010_data *rx8010 = i2c_get_clientdata(client); |
---|
77 | | - int flagreg; |
---|
| 74 | + int flagreg, err; |
---|
78 | 75 | |
---|
79 | 76 | mutex_lock(&rx8010->rtc->ops_lock); |
---|
80 | 77 | |
---|
81 | | - flagreg = i2c_smbus_read_byte_data(client, RX8010_FLAG); |
---|
82 | | - |
---|
83 | | - if (flagreg <= 0) { |
---|
| 78 | + err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg); |
---|
| 79 | + if (err) { |
---|
84 | 80 | mutex_unlock(&rx8010->rtc->ops_lock); |
---|
85 | 81 | return IRQ_NONE; |
---|
86 | 82 | } |
---|
.. | .. |
---|
103 | 99 | rtc_update_irq(rx8010->rtc, 1, RTC_UF | RTC_IRQF); |
---|
104 | 100 | } |
---|
105 | 101 | |
---|
106 | | - i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg); |
---|
107 | | - |
---|
| 102 | + err = regmap_write(rx8010->regs, RX8010_FLAG, flagreg); |
---|
108 | 103 | mutex_unlock(&rx8010->rtc->ops_lock); |
---|
109 | | - return IRQ_HANDLED; |
---|
| 104 | + return err ? IRQ_NONE : IRQ_HANDLED; |
---|
110 | 105 | } |
---|
111 | 106 | |
---|
112 | 107 | static int rx8010_get_time(struct device *dev, struct rtc_time *dt) |
---|
113 | 108 | { |
---|
114 | 109 | struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
115 | | - u8 date[7]; |
---|
116 | | - int flagreg; |
---|
117 | | - int err; |
---|
| 110 | + u8 date[RX8010_YEAR - RX8010_SEC + 1]; |
---|
| 111 | + int flagreg, err; |
---|
118 | 112 | |
---|
119 | | - flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG); |
---|
120 | | - if (flagreg < 0) |
---|
121 | | - return flagreg; |
---|
| 113 | + err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg); |
---|
| 114 | + if (err) |
---|
| 115 | + return err; |
---|
122 | 116 | |
---|
123 | 117 | if (flagreg & RX8010_FLAG_VLF) { |
---|
124 | 118 | dev_warn(dev, "Frequency stop detected\n"); |
---|
125 | 119 | return -EINVAL; |
---|
126 | 120 | } |
---|
127 | 121 | |
---|
128 | | - err = i2c_smbus_read_i2c_block_data(rx8010->client, RX8010_SEC, |
---|
129 | | - 7, date); |
---|
130 | | - if (err != 7) |
---|
131 | | - return err < 0 ? err : -EIO; |
---|
| 122 | + err = regmap_bulk_read(rx8010->regs, RX8010_SEC, date, sizeof(date)); |
---|
| 123 | + if (err) |
---|
| 124 | + return err; |
---|
132 | 125 | |
---|
133 | 126 | dt->tm_sec = bcd2bin(date[RX8010_SEC - RX8010_SEC] & 0x7f); |
---|
134 | 127 | dt->tm_min = bcd2bin(date[RX8010_MIN - RX8010_SEC] & 0x7f); |
---|
.. | .. |
---|
144 | 137 | static int rx8010_set_time(struct device *dev, struct rtc_time *dt) |
---|
145 | 138 | { |
---|
146 | 139 | struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
147 | | - u8 date[7]; |
---|
148 | | - int ctrl, flagreg; |
---|
149 | | - int ret; |
---|
150 | | - |
---|
151 | | - if ((dt->tm_year < 100) || (dt->tm_year > 199)) |
---|
152 | | - return -EINVAL; |
---|
| 140 | + u8 date[RX8010_YEAR - RX8010_SEC + 1]; |
---|
| 141 | + int err; |
---|
153 | 142 | |
---|
154 | 143 | /* set STOP bit before changing clock/calendar */ |
---|
155 | | - ctrl = i2c_smbus_read_byte_data(rx8010->client, RX8010_CTRL); |
---|
156 | | - if (ctrl < 0) |
---|
157 | | - return ctrl; |
---|
158 | | - rx8010->ctrlreg = ctrl | RX8010_CTRL_STOP; |
---|
159 | | - ret = i2c_smbus_write_byte_data(rx8010->client, RX8010_CTRL, |
---|
160 | | - rx8010->ctrlreg); |
---|
161 | | - if (ret < 0) |
---|
162 | | - return ret; |
---|
| 144 | + err = regmap_set_bits(rx8010->regs, RX8010_CTRL, RX8010_CTRL_STOP); |
---|
| 145 | + if (err) |
---|
| 146 | + return err; |
---|
163 | 147 | |
---|
164 | 148 | date[RX8010_SEC - RX8010_SEC] = bin2bcd(dt->tm_sec); |
---|
165 | 149 | date[RX8010_MIN - RX8010_SEC] = bin2bcd(dt->tm_min); |
---|
.. | .. |
---|
169 | 153 | date[RX8010_YEAR - RX8010_SEC] = bin2bcd(dt->tm_year - 100); |
---|
170 | 154 | date[RX8010_WDAY - RX8010_SEC] = bin2bcd(1 << dt->tm_wday); |
---|
171 | 155 | |
---|
172 | | - ret = i2c_smbus_write_i2c_block_data(rx8010->client, |
---|
173 | | - RX8010_SEC, 7, date); |
---|
174 | | - if (ret < 0) |
---|
175 | | - return ret; |
---|
| 156 | + err = regmap_bulk_write(rx8010->regs, RX8010_SEC, date, sizeof(date)); |
---|
| 157 | + if (err) |
---|
| 158 | + return err; |
---|
176 | 159 | |
---|
177 | 160 | /* clear STOP bit after changing clock/calendar */ |
---|
178 | | - ctrl = i2c_smbus_read_byte_data(rx8010->client, RX8010_CTRL); |
---|
179 | | - if (ctrl < 0) |
---|
180 | | - return ctrl; |
---|
181 | | - rx8010->ctrlreg = ctrl & ~RX8010_CTRL_STOP; |
---|
182 | | - ret = i2c_smbus_write_byte_data(rx8010->client, RX8010_CTRL, |
---|
183 | | - rx8010->ctrlreg); |
---|
184 | | - if (ret < 0) |
---|
185 | | - return ret; |
---|
| 161 | + err = regmap_clear_bits(rx8010->regs, RX8010_CTRL, RX8010_CTRL_STOP); |
---|
| 162 | + if (err) |
---|
| 163 | + return err; |
---|
186 | 164 | |
---|
187 | | - flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG); |
---|
188 | | - if (flagreg < 0) { |
---|
189 | | - return flagreg; |
---|
190 | | - } |
---|
191 | | - |
---|
192 | | - if (flagreg & RX8010_FLAG_VLF) |
---|
193 | | - ret = i2c_smbus_write_byte_data(rx8010->client, RX8010_FLAG, |
---|
194 | | - flagreg & ~RX8010_FLAG_VLF); |
---|
| 165 | + err = regmap_clear_bits(rx8010->regs, RX8010_FLAG, RX8010_FLAG_VLF); |
---|
| 166 | + if (err) |
---|
| 167 | + return err; |
---|
195 | 168 | |
---|
196 | 169 | return 0; |
---|
197 | 170 | } |
---|
198 | 171 | |
---|
199 | | -static int rx8010_init_client(struct i2c_client *client) |
---|
| 172 | +static int rx8010_init(struct device *dev) |
---|
200 | 173 | { |
---|
201 | | - struct rx8010_data *rx8010 = i2c_get_clientdata(client); |
---|
| 174 | + struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
202 | 175 | u8 ctrl[2]; |
---|
203 | | - int need_clear = 0, err = 0; |
---|
| 176 | + int need_clear = 0, err; |
---|
204 | 177 | |
---|
205 | 178 | /* Initialize reserved registers as specified in datasheet */ |
---|
206 | | - err = i2c_smbus_write_byte_data(client, RX8010_RESV17, 0xD8); |
---|
207 | | - if (err < 0) |
---|
| 179 | + err = regmap_write(rx8010->regs, RX8010_RESV17, 0xD8); |
---|
| 180 | + if (err) |
---|
208 | 181 | return err; |
---|
209 | 182 | |
---|
210 | | - err = i2c_smbus_write_byte_data(client, RX8010_RESV30, 0x00); |
---|
211 | | - if (err < 0) |
---|
| 183 | + err = regmap_write(rx8010->regs, RX8010_RESV30, 0x00); |
---|
| 184 | + if (err) |
---|
212 | 185 | return err; |
---|
213 | 186 | |
---|
214 | | - err = i2c_smbus_write_byte_data(client, RX8010_RESV31, 0x08); |
---|
215 | | - if (err < 0) |
---|
| 187 | + err = regmap_write(rx8010->regs, RX8010_RESV31, 0x08); |
---|
| 188 | + if (err) |
---|
216 | 189 | return err; |
---|
217 | 190 | |
---|
218 | | - err = i2c_smbus_write_byte_data(client, RX8010_IRQ, 0x00); |
---|
219 | | - if (err < 0) |
---|
| 191 | + err = regmap_write(rx8010->regs, RX8010_IRQ, 0x00); |
---|
| 192 | + if (err) |
---|
220 | 193 | return err; |
---|
221 | 194 | |
---|
222 | | - err = i2c_smbus_read_i2c_block_data(rx8010->client, RX8010_FLAG, |
---|
223 | | - 2, ctrl); |
---|
224 | | - if (err != 2) |
---|
225 | | - return err < 0 ? err : -EIO; |
---|
| 195 | + err = regmap_bulk_read(rx8010->regs, RX8010_FLAG, ctrl, 2); |
---|
| 196 | + if (err) |
---|
| 197 | + return err; |
---|
226 | 198 | |
---|
227 | 199 | if (ctrl[0] & RX8010_FLAG_VLF) |
---|
228 | | - dev_warn(&client->dev, "Frequency stop was detected\n"); |
---|
| 200 | + dev_warn(dev, "Frequency stop was detected\n"); |
---|
229 | 201 | |
---|
230 | 202 | if (ctrl[0] & RX8010_FLAG_AF) { |
---|
231 | | - dev_warn(&client->dev, "Alarm was detected\n"); |
---|
| 203 | + dev_warn(dev, "Alarm was detected\n"); |
---|
232 | 204 | need_clear = 1; |
---|
233 | 205 | } |
---|
234 | 206 | |
---|
.. | .. |
---|
240 | 212 | |
---|
241 | 213 | if (need_clear) { |
---|
242 | 214 | ctrl[0] &= ~(RX8010_FLAG_AF | RX8010_FLAG_TF | RX8010_FLAG_UF); |
---|
243 | | - err = i2c_smbus_write_byte_data(client, RX8010_FLAG, ctrl[0]); |
---|
244 | | - if (err < 0) |
---|
| 215 | + err = regmap_write(rx8010->regs, RX8010_FLAG, ctrl[0]); |
---|
| 216 | + if (err) |
---|
245 | 217 | return err; |
---|
246 | 218 | } |
---|
247 | 219 | |
---|
.. | .. |
---|
253 | 225 | static int rx8010_read_alarm(struct device *dev, struct rtc_wkalrm *t) |
---|
254 | 226 | { |
---|
255 | 227 | struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
256 | | - struct i2c_client *client = rx8010->client; |
---|
257 | 228 | u8 alarmvals[3]; |
---|
258 | | - int flagreg; |
---|
259 | | - int err; |
---|
| 229 | + int flagreg, err; |
---|
260 | 230 | |
---|
261 | | - err = i2c_smbus_read_i2c_block_data(client, RX8010_ALMIN, 3, alarmvals); |
---|
262 | | - if (err != 3) |
---|
263 | | - return err < 0 ? err : -EIO; |
---|
| 231 | + err = regmap_bulk_read(rx8010->regs, RX8010_ALMIN, alarmvals, 3); |
---|
| 232 | + if (err) |
---|
| 233 | + return err; |
---|
264 | 234 | |
---|
265 | | - flagreg = i2c_smbus_read_byte_data(client, RX8010_FLAG); |
---|
266 | | - if (flagreg < 0) |
---|
267 | | - return flagreg; |
---|
| 235 | + err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg); |
---|
| 236 | + if (err) |
---|
| 237 | + return err; |
---|
268 | 238 | |
---|
269 | 239 | t->time.tm_sec = 0; |
---|
270 | 240 | t->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); |
---|
.. | .. |
---|
281 | 251 | |
---|
282 | 252 | static int rx8010_set_alarm(struct device *dev, struct rtc_wkalrm *t) |
---|
283 | 253 | { |
---|
284 | | - struct i2c_client *client = to_i2c_client(dev); |
---|
285 | 254 | struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
286 | 255 | u8 alarmvals[3]; |
---|
287 | | - int extreg, flagreg; |
---|
288 | 256 | int err; |
---|
289 | | - |
---|
290 | | - flagreg = i2c_smbus_read_byte_data(client, RX8010_FLAG); |
---|
291 | | - if (flagreg < 0) { |
---|
292 | | - return flagreg; |
---|
293 | | - } |
---|
294 | 257 | |
---|
295 | 258 | if (rx8010->ctrlreg & (RX8010_CTRL_AIE | RX8010_CTRL_UIE)) { |
---|
296 | 259 | rx8010->ctrlreg &= ~(RX8010_CTRL_AIE | RX8010_CTRL_UIE); |
---|
297 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_CTRL, |
---|
298 | | - rx8010->ctrlreg); |
---|
299 | | - if (err < 0) { |
---|
| 260 | + err = regmap_write(rx8010->regs, RX8010_CTRL, rx8010->ctrlreg); |
---|
| 261 | + if (err) |
---|
300 | 262 | return err; |
---|
301 | | - } |
---|
302 | 263 | } |
---|
303 | 264 | |
---|
304 | | - flagreg &= ~RX8010_FLAG_AF; |
---|
305 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_FLAG, flagreg); |
---|
306 | | - if (err < 0) |
---|
| 265 | + err = regmap_clear_bits(rx8010->regs, RX8010_FLAG, RX8010_FLAG_AF); |
---|
| 266 | + if (err) |
---|
307 | 267 | return err; |
---|
308 | 268 | |
---|
309 | 269 | alarmvals[0] = bin2bcd(t->time.tm_min); |
---|
310 | 270 | alarmvals[1] = bin2bcd(t->time.tm_hour); |
---|
311 | 271 | alarmvals[2] = bin2bcd(t->time.tm_mday); |
---|
312 | 272 | |
---|
313 | | - err = i2c_smbus_write_i2c_block_data(rx8010->client, RX8010_ALMIN, |
---|
314 | | - 2, alarmvals); |
---|
315 | | - if (err < 0) |
---|
| 273 | + err = regmap_bulk_write(rx8010->regs, RX8010_ALMIN, alarmvals, 2); |
---|
| 274 | + if (err) |
---|
316 | 275 | return err; |
---|
317 | 276 | |
---|
318 | | - extreg = i2c_smbus_read_byte_data(client, RX8010_EXT); |
---|
319 | | - if (extreg < 0) |
---|
320 | | - return extreg; |
---|
321 | | - |
---|
322 | | - extreg |= RX8010_EXT_WADA; |
---|
323 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_EXT, extreg); |
---|
324 | | - if (err < 0) |
---|
| 277 | + err = regmap_clear_bits(rx8010->regs, RX8010_EXT, RX8010_EXT_WADA); |
---|
| 278 | + if (err) |
---|
325 | 279 | return err; |
---|
326 | 280 | |
---|
327 | 281 | if (alarmvals[2] == 0) |
---|
328 | 282 | alarmvals[2] |= RX8010_ALARM_AE; |
---|
329 | 283 | |
---|
330 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_ALWDAY, |
---|
331 | | - alarmvals[2]); |
---|
332 | | - if (err < 0) |
---|
| 284 | + err = regmap_write(rx8010->regs, RX8010_ALWDAY, alarmvals[2]); |
---|
| 285 | + if (err) |
---|
333 | 286 | return err; |
---|
334 | 287 | |
---|
335 | 288 | if (t->enabled) { |
---|
.. | .. |
---|
339 | 292 | rx8010->ctrlreg |= |
---|
340 | 293 | (RX8010_CTRL_AIE | RX8010_CTRL_UIE); |
---|
341 | 294 | |
---|
342 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_CTRL, |
---|
343 | | - rx8010->ctrlreg); |
---|
344 | | - if (err < 0) |
---|
| 295 | + err = regmap_write(rx8010->regs, RX8010_CTRL, rx8010->ctrlreg); |
---|
| 296 | + if (err) |
---|
345 | 297 | return err; |
---|
346 | 298 | } |
---|
347 | 299 | |
---|
.. | .. |
---|
351 | 303 | static int rx8010_alarm_irq_enable(struct device *dev, |
---|
352 | 304 | unsigned int enabled) |
---|
353 | 305 | { |
---|
354 | | - struct i2c_client *client = to_i2c_client(dev); |
---|
355 | 306 | struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
356 | | - int flagreg; |
---|
357 | | - u8 ctrl; |
---|
358 | 307 | int err; |
---|
| 308 | + u8 ctrl; |
---|
359 | 309 | |
---|
360 | 310 | ctrl = rx8010->ctrlreg; |
---|
361 | 311 | |
---|
.. | .. |
---|
371 | 321 | ctrl &= ~RX8010_CTRL_AIE; |
---|
372 | 322 | } |
---|
373 | 323 | |
---|
374 | | - flagreg = i2c_smbus_read_byte_data(client, RX8010_FLAG); |
---|
375 | | - if (flagreg < 0) |
---|
376 | | - return flagreg; |
---|
377 | | - |
---|
378 | | - flagreg &= ~RX8010_FLAG_AF; |
---|
379 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_FLAG, flagreg); |
---|
380 | | - if (err < 0) |
---|
| 324 | + err = regmap_clear_bits(rx8010->regs, RX8010_FLAG, RX8010_FLAG_AF); |
---|
| 325 | + if (err) |
---|
381 | 326 | return err; |
---|
382 | 327 | |
---|
383 | 328 | if (ctrl != rx8010->ctrlreg) { |
---|
384 | 329 | rx8010->ctrlreg = ctrl; |
---|
385 | | - err = i2c_smbus_write_byte_data(rx8010->client, RX8010_CTRL, |
---|
386 | | - rx8010->ctrlreg); |
---|
387 | | - if (err < 0) |
---|
| 330 | + err = regmap_write(rx8010->regs, RX8010_CTRL, rx8010->ctrlreg); |
---|
| 331 | + if (err) |
---|
388 | 332 | return err; |
---|
389 | 333 | } |
---|
390 | 334 | |
---|
.. | .. |
---|
393 | 337 | |
---|
394 | 338 | static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) |
---|
395 | 339 | { |
---|
396 | | - struct i2c_client *client = to_i2c_client(dev); |
---|
397 | 340 | struct rx8010_data *rx8010 = dev_get_drvdata(dev); |
---|
398 | | - int ret, tmp; |
---|
399 | | - int flagreg; |
---|
| 341 | + int tmp, flagreg, err; |
---|
400 | 342 | |
---|
401 | 343 | switch (cmd) { |
---|
402 | 344 | case RTC_VL_READ: |
---|
403 | | - flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG); |
---|
404 | | - if (flagreg < 0) |
---|
405 | | - return flagreg; |
---|
| 345 | + err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg); |
---|
| 346 | + if (err) |
---|
| 347 | + return err; |
---|
406 | 348 | |
---|
407 | | - tmp = !!(flagreg & RX8010_FLAG_VLF); |
---|
408 | | - if (copy_to_user((void __user *)arg, &tmp, sizeof(int))) |
---|
409 | | - return -EFAULT; |
---|
410 | | - |
---|
411 | | - return 0; |
---|
412 | | - |
---|
413 | | - case RTC_VL_CLR: |
---|
414 | | - flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG); |
---|
415 | | - if (flagreg < 0) { |
---|
416 | | - return flagreg; |
---|
417 | | - } |
---|
418 | | - |
---|
419 | | - flagreg &= ~RX8010_FLAG_VLF; |
---|
420 | | - ret = i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg); |
---|
421 | | - if (ret < 0) |
---|
422 | | - return ret; |
---|
423 | | - |
---|
424 | | - return 0; |
---|
| 349 | + tmp = flagreg & RX8010_FLAG_VLF ? RTC_VL_DATA_INVALID : 0; |
---|
| 350 | + return put_user(tmp, (unsigned int __user *)arg); |
---|
425 | 351 | |
---|
426 | 352 | default: |
---|
427 | 353 | return -ENOIOCTLCMD; |
---|
.. | .. |
---|
443 | 369 | .alarm_irq_enable = rx8010_alarm_irq_enable, |
---|
444 | 370 | }; |
---|
445 | 371 | |
---|
446 | | -static int rx8010_probe(struct i2c_client *client, |
---|
447 | | - const struct i2c_device_id *id) |
---|
| 372 | +static const struct regmap_config rx8010_regmap_config = { |
---|
| 373 | + .name = "rx8010-rtc", |
---|
| 374 | + .reg_bits = 8, |
---|
| 375 | + .val_bits = 8, |
---|
| 376 | +}; |
---|
| 377 | + |
---|
| 378 | +static int rx8010_probe(struct i2c_client *client) |
---|
448 | 379 | { |
---|
449 | | - struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
---|
450 | | - const struct rtc_class_ops *rtc_ops; |
---|
| 380 | + struct device *dev = &client->dev; |
---|
451 | 381 | struct rx8010_data *rx8010; |
---|
452 | 382 | int err = 0; |
---|
453 | 383 | |
---|
454 | | - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
---|
455 | | - | I2C_FUNC_SMBUS_I2C_BLOCK)) { |
---|
456 | | - dev_err(&adapter->dev, "doesn't support required functionality\n"); |
---|
457 | | - return -EIO; |
---|
458 | | - } |
---|
459 | | - |
---|
460 | | - rx8010 = devm_kzalloc(&client->dev, sizeof(struct rx8010_data), |
---|
461 | | - GFP_KERNEL); |
---|
| 384 | + rx8010 = devm_kzalloc(dev, sizeof(*rx8010), GFP_KERNEL); |
---|
462 | 385 | if (!rx8010) |
---|
463 | 386 | return -ENOMEM; |
---|
464 | 387 | |
---|
465 | | - rx8010->client = client; |
---|
466 | 388 | i2c_set_clientdata(client, rx8010); |
---|
467 | 389 | |
---|
468 | | - err = rx8010_init_client(client); |
---|
| 390 | + rx8010->regs = devm_regmap_init_i2c(client, &rx8010_regmap_config); |
---|
| 391 | + if (IS_ERR(rx8010->regs)) |
---|
| 392 | + return PTR_ERR(rx8010->regs); |
---|
| 393 | + |
---|
| 394 | + err = rx8010_init(dev); |
---|
469 | 395 | if (err) |
---|
470 | 396 | return err; |
---|
471 | 397 | |
---|
| 398 | + rx8010->rtc = devm_rtc_allocate_device(dev); |
---|
| 399 | + if (IS_ERR(rx8010->rtc)) |
---|
| 400 | + return PTR_ERR(rx8010->rtc); |
---|
| 401 | + |
---|
472 | 402 | if (client->irq > 0) { |
---|
473 | | - dev_info(&client->dev, "IRQ %d supplied\n", client->irq); |
---|
474 | | - err = devm_request_threaded_irq(&client->dev, client->irq, NULL, |
---|
| 403 | + dev_info(dev, "IRQ %d supplied\n", client->irq); |
---|
| 404 | + err = devm_request_threaded_irq(dev, client->irq, NULL, |
---|
475 | 405 | rx8010_irq_1_handler, |
---|
476 | 406 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
---|
477 | 407 | "rx8010", client); |
---|
478 | | - |
---|
479 | 408 | if (err) { |
---|
480 | | - dev_err(&client->dev, "unable to request IRQ\n"); |
---|
| 409 | + dev_err(dev, "unable to request IRQ\n"); |
---|
481 | 410 | return err; |
---|
482 | 411 | } |
---|
483 | 412 | |
---|
484 | | - rtc_ops = &rx8010_rtc_ops_alarm; |
---|
| 413 | + rx8010->rtc->ops = &rx8010_rtc_ops_alarm; |
---|
485 | 414 | } else { |
---|
486 | | - rtc_ops = &rx8010_rtc_ops_default; |
---|
487 | | - } |
---|
488 | | - |
---|
489 | | - rx8010->rtc = devm_rtc_device_register(&client->dev, client->name, |
---|
490 | | - rtc_ops, THIS_MODULE); |
---|
491 | | - |
---|
492 | | - if (IS_ERR(rx8010->rtc)) { |
---|
493 | | - dev_err(&client->dev, "unable to register the class device\n"); |
---|
494 | | - return PTR_ERR(rx8010->rtc); |
---|
| 415 | + rx8010->rtc->ops = &rx8010_rtc_ops_default; |
---|
495 | 416 | } |
---|
496 | 417 | |
---|
497 | 418 | rx8010->rtc->max_user_freq = 1; |
---|
| 419 | + rx8010->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
---|
| 420 | + rx8010->rtc->range_max = RTC_TIMESTAMP_END_2099; |
---|
498 | 421 | |
---|
499 | | - return err; |
---|
| 422 | + return rtc_register_device(rx8010->rtc); |
---|
500 | 423 | } |
---|
501 | 424 | |
---|
502 | 425 | static struct i2c_driver rx8010_driver = { |
---|
.. | .. |
---|
504 | 427 | .name = "rtc-rx8010", |
---|
505 | 428 | .of_match_table = of_match_ptr(rx8010_of_match), |
---|
506 | 429 | }, |
---|
507 | | - .probe = rx8010_probe, |
---|
| 430 | + .probe_new = rx8010_probe, |
---|
508 | 431 | .id_table = rx8010_id, |
---|
509 | 432 | }; |
---|
510 | 433 | |
---|