blob: 216fbf6adec9906e9c49991929aaa07f4ec0f1e5 [file] [log] [blame]
Chris Zhongf69a7cf2014-09-03 21:51:44 +08001/*
Wadim Egorov2eedcbf2016-08-29 13:07:58 +02002 * MFD core driver for Rockchip RK808/RK818
Chris Zhongf69a7cf2014-09-03 21:51:44 +08003 *
4 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
5 *
6 * Author: Chris Zhong <zyw@rock-chips.com>
7 * Author: Zhang Qing <zhangqing@rock-chips.com>
8 *
Wadim Egorov2eedcbf2016-08-29 13:07:58 +02009 * Copyright (C) 2016 PHYTEC Messtechnik GmbH
10 *
11 * Author: Wadim Egorov <w.egorov@phytec.de>
12 *
Chris Zhongf69a7cf2014-09-03 21:51:44 +080013 * This program is free software; you can redistribute it and/or modify it
14 * under the terms and conditions of the GNU General Public License,
15 * version 2, as published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * more details.
21 */
22
23#include <linux/i2c.h>
24#include <linux/interrupt.h>
25#include <linux/mfd/rk808.h>
26#include <linux/mfd/core.h>
27#include <linux/module.h>
Wadim Egorov2eedcbf2016-08-29 13:07:58 +020028#include <linux/of_device.h>
Chris Zhongf69a7cf2014-09-03 21:51:44 +080029#include <linux/regmap.h>
30
31struct rk808_reg_data {
32 int addr;
33 int mask;
34 int value;
35};
36
Doug Anderson2adb3b82014-09-09 16:06:04 -070037static bool rk808_is_volatile_reg(struct device *dev, unsigned int reg)
38{
39 /*
40 * Notes:
41 * - Technically the ROUND_30s bit makes RTC_CTRL_REG volatile, but
42 * we don't use that feature. It's better to cache.
43 * - It's unlikely we care that RK808_DEVCTRL_REG is volatile since
44 * bits are cleared in case when we shutoff anyway, but better safe.
45 */
46
47 switch (reg) {
48 case RK808_SECONDS_REG ... RK808_WEEKS_REG:
49 case RK808_RTC_STATUS_REG:
50 case RK808_VB_MON_REG:
51 case RK808_THERMAL_REG:
52 case RK808_DCDC_UV_STS_REG:
53 case RK808_LDO_UV_STS_REG:
54 case RK808_DCDC_PG_REG:
55 case RK808_LDO_PG_REG:
56 case RK808_DEVCTRL_REG:
57 case RK808_INT_STS_REG1:
58 case RK808_INT_STS_REG2:
59 return true;
60 }
61
62 return false;
63}
64
Wadim Egorov2eedcbf2016-08-29 13:07:58 +020065static const struct regmap_config rk818_regmap_config = {
66 .reg_bits = 8,
67 .val_bits = 8,
68 .max_register = RK818_USB_CTRL_REG,
69 .cache_type = REGCACHE_RBTREE,
70 .volatile_reg = rk808_is_volatile_reg,
71};
72
Elaine Zhang990f05f2017-08-21 03:28:38 +020073static const struct regmap_config rk805_regmap_config = {
74 .reg_bits = 8,
75 .val_bits = 8,
76 .max_register = RK805_OFF_SOURCE_REG,
77 .cache_type = REGCACHE_RBTREE,
78 .volatile_reg = rk808_is_volatile_reg,
79};
80
Chris Zhongf69a7cf2014-09-03 21:51:44 +080081static const struct regmap_config rk808_regmap_config = {
82 .reg_bits = 8,
83 .val_bits = 8,
84 .max_register = RK808_IO_POL_REG,
Doug Anderson2adb3b82014-09-09 16:06:04 -070085 .cache_type = REGCACHE_RBTREE,
86 .volatile_reg = rk808_is_volatile_reg,
Chris Zhongf69a7cf2014-09-03 21:51:44 +080087};
88
89static struct resource rtc_resources[] = {
90 {
91 .start = RK808_IRQ_RTC_ALARM,
92 .end = RK808_IRQ_RTC_ALARM,
93 .flags = IORESOURCE_IRQ,
94 }
95};
96
Joseph Chenf7c22392017-08-21 03:28:42 +020097static struct resource rk805_key_resources[] = {
98 {
99 .start = RK805_IRQ_PWRON_FALL,
100 .end = RK805_IRQ_PWRON_FALL,
101 .flags = IORESOURCE_IRQ,
102 },
103 {
104 .start = RK805_IRQ_PWRON_RISE,
105 .end = RK805_IRQ_PWRON_RISE,
106 .flags = IORESOURCE_IRQ,
107 }
108};
109
Elaine Zhang990f05f2017-08-21 03:28:38 +0200110static const struct mfd_cell rk805s[] = {
111 { .name = "rk808-clkout", },
112 { .name = "rk808-regulator", },
Joseph Chen8d249b62017-08-21 03:28:41 +0200113 { .name = "rk805-pinctrl", },
Elaine Zhang990f05f2017-08-21 03:28:38 +0200114 {
115 .name = "rk808-rtc",
116 .num_resources = ARRAY_SIZE(rtc_resources),
117 .resources = &rtc_resources[0],
118 },
Joseph Chenf7c22392017-08-21 03:28:42 +0200119 { .name = "rk805-pwrkey",
120 .num_resources = ARRAY_SIZE(rk805_key_resources),
121 .resources = &rk805_key_resources[0],
122 },
Elaine Zhang990f05f2017-08-21 03:28:38 +0200123};
124
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800125static const struct mfd_cell rk808s[] = {
126 { .name = "rk808-clkout", },
127 { .name = "rk808-regulator", },
128 {
129 .name = "rk808-rtc",
130 .num_resources = ARRAY_SIZE(rtc_resources),
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200131 .resources = rtc_resources,
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800132 },
133};
134
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200135static const struct mfd_cell rk818s[] = {
136 { .name = "rk808-clkout", },
137 { .name = "rk808-regulator", },
138 {
139 .name = "rk808-rtc",
140 .num_resources = ARRAY_SIZE(rtc_resources),
141 .resources = rtc_resources,
142 },
143};
144
Elaine Zhang990f05f2017-08-21 03:28:38 +0200145static const struct rk808_reg_data rk805_pre_init_reg[] = {
146 {RK805_BUCK1_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
147 RK805_BUCK1_2_ILMAX_4000MA},
148 {RK805_BUCK2_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
149 RK805_BUCK1_2_ILMAX_4000MA},
150 {RK805_BUCK3_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
151 RK805_BUCK3_ILMAX_3000MA},
152 {RK805_BUCK4_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
153 RK805_BUCK4_ILMAX_3500MA},
154 {RK805_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_400MA},
155 {RK805_GPIO_IO_POL_REG, SLP_SD_MSK, SLEEP_FUN},
156 {RK805_THERMAL_REG, TEMP_HOTDIE_MSK, TEMP115C},
157};
158
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200159static const struct rk808_reg_data rk808_pre_init_reg[] = {
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800160 { RK808_BUCK3_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_150MA },
161 { RK808_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_200MA },
162 { RK808_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
163 { RK808_BUCK1_CONFIG_REG, BUCK1_RATE_MASK, BUCK_ILMIN_200MA },
164 { RK808_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_200MA },
Chris Zhonge19f7422015-02-28 18:09:06 +0800165 { RK808_DCDC_UV_ACT_REG, BUCK_UV_ACT_MASK, BUCK_UV_ACT_DISABLE},
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800166 { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT |
167 VB_LO_SEL_3500MV },
168};
169
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200170static const struct rk808_reg_data rk818_pre_init_reg[] = {
171 /* improve efficiency */
172 { RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_250MA },
173 { RK818_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_250MA },
174 { RK818_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
175 { RK818_USB_CTRL_REG, RK818_USB_ILIM_SEL_MASK,
176 RK818_USB_ILMIN_2000MA },
177 /* close charger when usb lower then 3.4V */
178 { RK818_USB_CTRL_REG, RK818_USB_CHG_SD_VSEL_MASK,
179 (0x7 << 4) },
180 /* no action when vref */
181 { RK818_H5V_EN_REG, BIT(1), RK818_REF_RDY_CTRL },
182 /* enable HDMI 5V */
183 { RK818_H5V_EN_REG, BIT(0), RK818_H5V_EN },
184 { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT |
185 VB_LO_SEL_3500MV },
186};
187
Elaine Zhang990f05f2017-08-21 03:28:38 +0200188static const struct regmap_irq rk805_irqs[] = {
189 [RK805_IRQ_PWRON_RISE] = {
190 .mask = RK805_IRQ_PWRON_RISE_MSK,
191 .reg_offset = 0,
192 },
193 [RK805_IRQ_VB_LOW] = {
194 .mask = RK805_IRQ_VB_LOW_MSK,
195 .reg_offset = 0,
196 },
197 [RK805_IRQ_PWRON] = {
198 .mask = RK805_IRQ_PWRON_MSK,
199 .reg_offset = 0,
200 },
201 [RK805_IRQ_PWRON_LP] = {
202 .mask = RK805_IRQ_PWRON_LP_MSK,
203 .reg_offset = 0,
204 },
205 [RK805_IRQ_HOTDIE] = {
206 .mask = RK805_IRQ_HOTDIE_MSK,
207 .reg_offset = 0,
208 },
209 [RK805_IRQ_RTC_ALARM] = {
210 .mask = RK805_IRQ_RTC_ALARM_MSK,
211 .reg_offset = 0,
212 },
213 [RK805_IRQ_RTC_PERIOD] = {
214 .mask = RK805_IRQ_RTC_PERIOD_MSK,
215 .reg_offset = 0,
216 },
217 [RK805_IRQ_PWRON_FALL] = {
218 .mask = RK805_IRQ_PWRON_FALL_MSK,
219 .reg_offset = 0,
220 },
221};
222
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800223static const struct regmap_irq rk808_irqs[] = {
224 /* INT_STS */
225 [RK808_IRQ_VOUT_LO] = {
226 .mask = RK808_IRQ_VOUT_LO_MSK,
227 .reg_offset = 0,
228 },
229 [RK808_IRQ_VB_LO] = {
230 .mask = RK808_IRQ_VB_LO_MSK,
231 .reg_offset = 0,
232 },
233 [RK808_IRQ_PWRON] = {
234 .mask = RK808_IRQ_PWRON_MSK,
235 .reg_offset = 0,
236 },
237 [RK808_IRQ_PWRON_LP] = {
238 .mask = RK808_IRQ_PWRON_LP_MSK,
239 .reg_offset = 0,
240 },
241 [RK808_IRQ_HOTDIE] = {
242 .mask = RK808_IRQ_HOTDIE_MSK,
243 .reg_offset = 0,
244 },
245 [RK808_IRQ_RTC_ALARM] = {
246 .mask = RK808_IRQ_RTC_ALARM_MSK,
247 .reg_offset = 0,
248 },
249 [RK808_IRQ_RTC_PERIOD] = {
250 .mask = RK808_IRQ_RTC_PERIOD_MSK,
251 .reg_offset = 0,
252 },
253
254 /* INT_STS2 */
255 [RK808_IRQ_PLUG_IN_INT] = {
256 .mask = RK808_IRQ_PLUG_IN_INT_MSK,
257 .reg_offset = 1,
258 },
259 [RK808_IRQ_PLUG_OUT_INT] = {
260 .mask = RK808_IRQ_PLUG_OUT_INT_MSK,
261 .reg_offset = 1,
262 },
263};
264
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200265static const struct regmap_irq rk818_irqs[] = {
266 /* INT_STS */
267 [RK818_IRQ_VOUT_LO] = {
268 .mask = RK818_IRQ_VOUT_LO_MSK,
269 .reg_offset = 0,
270 },
271 [RK818_IRQ_VB_LO] = {
272 .mask = RK818_IRQ_VB_LO_MSK,
273 .reg_offset = 0,
274 },
275 [RK818_IRQ_PWRON] = {
276 .mask = RK818_IRQ_PWRON_MSK,
277 .reg_offset = 0,
278 },
279 [RK818_IRQ_PWRON_LP] = {
280 .mask = RK818_IRQ_PWRON_LP_MSK,
281 .reg_offset = 0,
282 },
283 [RK818_IRQ_HOTDIE] = {
284 .mask = RK818_IRQ_HOTDIE_MSK,
285 .reg_offset = 0,
286 },
287 [RK818_IRQ_RTC_ALARM] = {
288 .mask = RK818_IRQ_RTC_ALARM_MSK,
289 .reg_offset = 0,
290 },
291 [RK818_IRQ_RTC_PERIOD] = {
292 .mask = RK818_IRQ_RTC_PERIOD_MSK,
293 .reg_offset = 0,
294 },
295 [RK818_IRQ_USB_OV] = {
296 .mask = RK818_IRQ_USB_OV_MSK,
297 .reg_offset = 0,
298 },
299
300 /* INT_STS2 */
301 [RK818_IRQ_PLUG_IN] = {
302 .mask = RK818_IRQ_PLUG_IN_MSK,
303 .reg_offset = 1,
304 },
305 [RK818_IRQ_PLUG_OUT] = {
306 .mask = RK818_IRQ_PLUG_OUT_MSK,
307 .reg_offset = 1,
308 },
309 [RK818_IRQ_CHG_OK] = {
310 .mask = RK818_IRQ_CHG_OK_MSK,
311 .reg_offset = 1,
312 },
313 [RK818_IRQ_CHG_TE] = {
314 .mask = RK818_IRQ_CHG_TE_MSK,
315 .reg_offset = 1,
316 },
317 [RK818_IRQ_CHG_TS1] = {
318 .mask = RK818_IRQ_CHG_TS1_MSK,
319 .reg_offset = 1,
320 },
321 [RK818_IRQ_TS2] = {
322 .mask = RK818_IRQ_TS2_MSK,
323 .reg_offset = 1,
324 },
325 [RK818_IRQ_CHG_CVTLIM] = {
326 .mask = RK818_IRQ_CHG_CVTLIM_MSK,
327 .reg_offset = 1,
328 },
329 [RK818_IRQ_DISCHG_ILIM] = {
330 .mask = RK818_IRQ_DISCHG_ILIM_MSK,
331 .reg_offset = 1,
332 },
333};
334
Elaine Zhang990f05f2017-08-21 03:28:38 +0200335static struct regmap_irq_chip rk805_irq_chip = {
336 .name = "rk805",
337 .irqs = rk805_irqs,
338 .num_irqs = ARRAY_SIZE(rk805_irqs),
339 .num_regs = 1,
340 .status_base = RK805_INT_STS_REG,
341 .mask_base = RK805_INT_STS_MSK_REG,
342 .ack_base = RK805_INT_STS_REG,
343 .init_ack_masked = true,
344};
345
Bhumika Goyal24e34b92017-01-25 00:55:24 +0530346static const struct regmap_irq_chip rk808_irq_chip = {
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800347 .name = "rk808",
348 .irqs = rk808_irqs,
349 .num_irqs = ARRAY_SIZE(rk808_irqs),
350 .num_regs = 2,
351 .irq_reg_stride = 2,
352 .status_base = RK808_INT_STS_REG1,
353 .mask_base = RK808_INT_STS_MSK_REG1,
354 .ack_base = RK808_INT_STS_REG1,
355 .init_ack_masked = true,
356};
357
Bhumika Goyal24e34b92017-01-25 00:55:24 +0530358static const struct regmap_irq_chip rk818_irq_chip = {
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200359 .name = "rk818",
360 .irqs = rk818_irqs,
361 .num_irqs = ARRAY_SIZE(rk818_irqs),
362 .num_regs = 2,
363 .irq_reg_stride = 2,
364 .status_base = RK818_INT_STS_REG1,
365 .mask_base = RK818_INT_STS_MSK_REG1,
366 .ack_base = RK818_INT_STS_REG1,
367 .init_ack_masked = true,
368};
369
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800370static struct i2c_client *rk808_i2c_client;
Elaine Zhang990f05f2017-08-21 03:28:38 +0200371
372static void rk805_device_shutdown(void)
373{
374 int ret;
375 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
376
377 if (!rk808) {
378 dev_warn(&rk808_i2c_client->dev,
379 "have no rk805, so do nothing here\n");
380 return;
381 }
382
383 ret = regmap_update_bits(rk808->regmap,
384 RK805_DEV_CTRL_REG,
385 DEV_OFF, DEV_OFF);
386 if (ret)
387 dev_err(&rk808_i2c_client->dev, "power off error!\n");
388}
389
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800390static void rk808_device_shutdown(void)
391{
392 int ret;
393 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
394
395 if (!rk808) {
396 dev_warn(&rk808_i2c_client->dev,
397 "have no rk808, so do nothing here\n");
398 return;
399 }
400
401 ret = regmap_update_bits(rk808->regmap,
402 RK808_DEVCTRL_REG,
403 DEV_OFF_RST, DEV_OFF_RST);
404 if (ret)
405 dev_err(&rk808_i2c_client->dev, "power off error!\n");
406}
407
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800408static void rk818_device_shutdown(void)
409{
410 int ret;
411 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
412
413 if (!rk808) {
414 dev_warn(&rk808_i2c_client->dev,
415 "have no rk818, so do nothing here\n");
416 return;
417 }
418
419 ret = regmap_update_bits(rk808->regmap,
420 RK818_DEVCTRL_REG,
421 DEV_OFF, DEV_OFF);
422 if (ret)
423 dev_err(&rk808_i2c_client->dev, "power off error!\n");
424}
425
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200426static const struct of_device_id rk808_of_match[] = {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200427 { .compatible = "rockchip,rk805" },
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200428 { .compatible = "rockchip,rk808" },
429 { .compatible = "rockchip,rk818" },
430 { },
431};
432MODULE_DEVICE_TABLE(of, rk808_of_match);
433
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800434static int rk808_probe(struct i2c_client *client,
435 const struct i2c_device_id *id)
436{
437 struct device_node *np = client->dev.of_node;
438 struct rk808 *rk808;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200439 const struct rk808_reg_data *pre_init_reg;
440 const struct mfd_cell *cells;
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800441 void (*pm_pwroff_fn)(void);
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200442 int nr_pre_init_regs;
443 int nr_cells;
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200444 int pm_off = 0, msb, lsb;
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800445 int ret;
446 int i;
447
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200448 rk808 = devm_kzalloc(&client->dev, sizeof(*rk808), GFP_KERNEL);
449 if (!rk808)
450 return -ENOMEM;
451
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200452 /* Read chip variant */
453 msb = i2c_smbus_read_byte_data(client, RK808_ID_MSB);
454 if (msb < 0) {
455 dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200456 RK808_ID_MSB);
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200457 return msb;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200458 }
459
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200460 lsb = i2c_smbus_read_byte_data(client, RK808_ID_LSB);
461 if (lsb < 0) {
462 dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
463 RK808_ID_LSB);
464 return lsb;
465 }
466
467 rk808->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
468 dev_info(&client->dev, "chip id: 0x%x\n", (unsigned int)rk808->variant);
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200469
470 switch (rk808->variant) {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200471 case RK805_ID:
472 rk808->regmap_cfg = &rk805_regmap_config;
473 rk808->regmap_irq_chip = &rk805_irq_chip;
474 pre_init_reg = rk805_pre_init_reg;
475 nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
476 cells = rk805s;
477 nr_cells = ARRAY_SIZE(rk805s);
478 pm_pwroff_fn = rk805_device_shutdown;
479 break;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200480 case RK808_ID:
481 rk808->regmap_cfg = &rk808_regmap_config;
482 rk808->regmap_irq_chip = &rk808_irq_chip;
483 pre_init_reg = rk808_pre_init_reg;
484 nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
485 cells = rk808s;
486 nr_cells = ARRAY_SIZE(rk808s);
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800487 pm_pwroff_fn = rk808_device_shutdown;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200488 break;
489 case RK818_ID:
490 rk808->regmap_cfg = &rk818_regmap_config;
491 rk808->regmap_irq_chip = &rk818_irq_chip;
492 pre_init_reg = rk818_pre_init_reg;
493 nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
494 cells = rk818s;
495 nr_cells = ARRAY_SIZE(rk818s);
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800496 pm_pwroff_fn = rk818_device_shutdown;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200497 break;
498 default:
499 dev_err(&client->dev, "Unsupported RK8XX ID %lu\n",
500 rk808->variant);
501 return -EINVAL;
502 }
503
504 rk808->i2c = client;
505 i2c_set_clientdata(client, rk808);
506
507 rk808->regmap = devm_regmap_init_i2c(client, rk808->regmap_cfg);
508 if (IS_ERR(rk808->regmap)) {
509 dev_err(&client->dev, "regmap initialization failed\n");
510 return PTR_ERR(rk808->regmap);
511 }
512
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800513 if (!client->irq) {
514 dev_err(&client->dev, "No interrupt support, no core IRQ\n");
515 return -EINVAL;
516 }
517
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800518 ret = regmap_add_irq_chip(rk808->regmap, client->irq,
519 IRQF_ONESHOT, -1,
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200520 rk808->regmap_irq_chip, &rk808->irq_data);
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800521 if (ret) {
522 dev_err(&client->dev, "Failed to add irq_chip %d\n", ret);
523 return ret;
524 }
525
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200526 for (i = 0; i < nr_pre_init_regs; i++) {
527 ret = regmap_update_bits(rk808->regmap,
528 pre_init_reg[i].addr,
529 pre_init_reg[i].mask,
530 pre_init_reg[i].value);
531 if (ret) {
532 dev_err(&client->dev,
533 "0x%x write err\n",
534 pre_init_reg[i].addr);
535 return ret;
536 }
537 }
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800538
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200539 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
540 cells, nr_cells, NULL, 0,
541 regmap_irq_get_domain(rk808->irq_data));
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800542 if (ret) {
543 dev_err(&client->dev, "failed to add MFD devices %d\n", ret);
544 goto err_irq;
545 }
546
547 pm_off = of_property_read_bool(np,
548 "rockchip,system-power-controller");
549 if (pm_off && !pm_power_off) {
550 rk808_i2c_client = client;
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800551 pm_power_off = pm_pwroff_fn;
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800552 }
553
554 return 0;
555
556err_irq:
557 regmap_del_irq_chip(client->irq, rk808->irq_data);
558 return ret;
559}
560
561static int rk808_remove(struct i2c_client *client)
562{
563 struct rk808 *rk808 = i2c_get_clientdata(client);
564
565 regmap_del_irq_chip(client->irq, rk808->irq_data);
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800566 pm_power_off = NULL;
567
568 return 0;
569}
570
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800571static const struct i2c_device_id rk808_ids[] = {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200572 { "rk805" },
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800573 { "rk808" },
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200574 { "rk818" },
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800575 { },
576};
577MODULE_DEVICE_TABLE(i2c, rk808_ids);
578
579static struct i2c_driver rk808_i2c_driver = {
580 .driver = {
581 .name = "rk808",
582 .of_match_table = rk808_of_match,
583 },
584 .probe = rk808_probe,
585 .remove = rk808_remove,
586 .id_table = rk808_ids,
587};
588
589module_i2c_driver(rk808_i2c_driver);
590
591MODULE_LICENSE("GPL");
592MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
593MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200594MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
595MODULE_DESCRIPTION("RK808/RK818 PMIC driver");