blob: 18329c8b4fe728d3b33a4523dd268dc1573e53fd [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
Elaine Zhang990f05f2017-08-21 03:28:38 +020097static const struct mfd_cell rk805s[] = {
98 { .name = "rk808-clkout", },
99 { .name = "rk808-regulator", },
100 {
101 .name = "rk808-rtc",
102 .num_resources = ARRAY_SIZE(rtc_resources),
103 .resources = &rtc_resources[0],
104 },
105};
106
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800107static const struct mfd_cell rk808s[] = {
108 { .name = "rk808-clkout", },
109 { .name = "rk808-regulator", },
110 {
111 .name = "rk808-rtc",
112 .num_resources = ARRAY_SIZE(rtc_resources),
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200113 .resources = rtc_resources,
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800114 },
115};
116
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200117static const struct mfd_cell rk818s[] = {
118 { .name = "rk808-clkout", },
119 { .name = "rk808-regulator", },
120 {
121 .name = "rk808-rtc",
122 .num_resources = ARRAY_SIZE(rtc_resources),
123 .resources = rtc_resources,
124 },
125};
126
Elaine Zhang990f05f2017-08-21 03:28:38 +0200127static const struct rk808_reg_data rk805_pre_init_reg[] = {
128 {RK805_BUCK1_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
129 RK805_BUCK1_2_ILMAX_4000MA},
130 {RK805_BUCK2_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
131 RK805_BUCK1_2_ILMAX_4000MA},
132 {RK805_BUCK3_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
133 RK805_BUCK3_ILMAX_3000MA},
134 {RK805_BUCK4_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
135 RK805_BUCK4_ILMAX_3500MA},
136 {RK805_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_400MA},
137 {RK805_GPIO_IO_POL_REG, SLP_SD_MSK, SLEEP_FUN},
138 {RK805_THERMAL_REG, TEMP_HOTDIE_MSK, TEMP115C},
139};
140
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200141static const struct rk808_reg_data rk808_pre_init_reg[] = {
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800142 { RK808_BUCK3_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_150MA },
143 { RK808_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_200MA },
144 { RK808_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
145 { RK808_BUCK1_CONFIG_REG, BUCK1_RATE_MASK, BUCK_ILMIN_200MA },
146 { RK808_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_200MA },
Chris Zhonge19f7422015-02-28 18:09:06 +0800147 { RK808_DCDC_UV_ACT_REG, BUCK_UV_ACT_MASK, BUCK_UV_ACT_DISABLE},
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800148 { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT |
149 VB_LO_SEL_3500MV },
150};
151
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200152static const struct rk808_reg_data rk818_pre_init_reg[] = {
153 /* improve efficiency */
154 { RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_250MA },
155 { RK818_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_250MA },
156 { RK818_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
157 { RK818_USB_CTRL_REG, RK818_USB_ILIM_SEL_MASK,
158 RK818_USB_ILMIN_2000MA },
159 /* close charger when usb lower then 3.4V */
160 { RK818_USB_CTRL_REG, RK818_USB_CHG_SD_VSEL_MASK,
161 (0x7 << 4) },
162 /* no action when vref */
163 { RK818_H5V_EN_REG, BIT(1), RK818_REF_RDY_CTRL },
164 /* enable HDMI 5V */
165 { RK818_H5V_EN_REG, BIT(0), RK818_H5V_EN },
166 { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT |
167 VB_LO_SEL_3500MV },
168};
169
Elaine Zhang990f05f2017-08-21 03:28:38 +0200170static const struct regmap_irq rk805_irqs[] = {
171 [RK805_IRQ_PWRON_RISE] = {
172 .mask = RK805_IRQ_PWRON_RISE_MSK,
173 .reg_offset = 0,
174 },
175 [RK805_IRQ_VB_LOW] = {
176 .mask = RK805_IRQ_VB_LOW_MSK,
177 .reg_offset = 0,
178 },
179 [RK805_IRQ_PWRON] = {
180 .mask = RK805_IRQ_PWRON_MSK,
181 .reg_offset = 0,
182 },
183 [RK805_IRQ_PWRON_LP] = {
184 .mask = RK805_IRQ_PWRON_LP_MSK,
185 .reg_offset = 0,
186 },
187 [RK805_IRQ_HOTDIE] = {
188 .mask = RK805_IRQ_HOTDIE_MSK,
189 .reg_offset = 0,
190 },
191 [RK805_IRQ_RTC_ALARM] = {
192 .mask = RK805_IRQ_RTC_ALARM_MSK,
193 .reg_offset = 0,
194 },
195 [RK805_IRQ_RTC_PERIOD] = {
196 .mask = RK805_IRQ_RTC_PERIOD_MSK,
197 .reg_offset = 0,
198 },
199 [RK805_IRQ_PWRON_FALL] = {
200 .mask = RK805_IRQ_PWRON_FALL_MSK,
201 .reg_offset = 0,
202 },
203};
204
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800205static const struct regmap_irq rk808_irqs[] = {
206 /* INT_STS */
207 [RK808_IRQ_VOUT_LO] = {
208 .mask = RK808_IRQ_VOUT_LO_MSK,
209 .reg_offset = 0,
210 },
211 [RK808_IRQ_VB_LO] = {
212 .mask = RK808_IRQ_VB_LO_MSK,
213 .reg_offset = 0,
214 },
215 [RK808_IRQ_PWRON] = {
216 .mask = RK808_IRQ_PWRON_MSK,
217 .reg_offset = 0,
218 },
219 [RK808_IRQ_PWRON_LP] = {
220 .mask = RK808_IRQ_PWRON_LP_MSK,
221 .reg_offset = 0,
222 },
223 [RK808_IRQ_HOTDIE] = {
224 .mask = RK808_IRQ_HOTDIE_MSK,
225 .reg_offset = 0,
226 },
227 [RK808_IRQ_RTC_ALARM] = {
228 .mask = RK808_IRQ_RTC_ALARM_MSK,
229 .reg_offset = 0,
230 },
231 [RK808_IRQ_RTC_PERIOD] = {
232 .mask = RK808_IRQ_RTC_PERIOD_MSK,
233 .reg_offset = 0,
234 },
235
236 /* INT_STS2 */
237 [RK808_IRQ_PLUG_IN_INT] = {
238 .mask = RK808_IRQ_PLUG_IN_INT_MSK,
239 .reg_offset = 1,
240 },
241 [RK808_IRQ_PLUG_OUT_INT] = {
242 .mask = RK808_IRQ_PLUG_OUT_INT_MSK,
243 .reg_offset = 1,
244 },
245};
246
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200247static const struct regmap_irq rk818_irqs[] = {
248 /* INT_STS */
249 [RK818_IRQ_VOUT_LO] = {
250 .mask = RK818_IRQ_VOUT_LO_MSK,
251 .reg_offset = 0,
252 },
253 [RK818_IRQ_VB_LO] = {
254 .mask = RK818_IRQ_VB_LO_MSK,
255 .reg_offset = 0,
256 },
257 [RK818_IRQ_PWRON] = {
258 .mask = RK818_IRQ_PWRON_MSK,
259 .reg_offset = 0,
260 },
261 [RK818_IRQ_PWRON_LP] = {
262 .mask = RK818_IRQ_PWRON_LP_MSK,
263 .reg_offset = 0,
264 },
265 [RK818_IRQ_HOTDIE] = {
266 .mask = RK818_IRQ_HOTDIE_MSK,
267 .reg_offset = 0,
268 },
269 [RK818_IRQ_RTC_ALARM] = {
270 .mask = RK818_IRQ_RTC_ALARM_MSK,
271 .reg_offset = 0,
272 },
273 [RK818_IRQ_RTC_PERIOD] = {
274 .mask = RK818_IRQ_RTC_PERIOD_MSK,
275 .reg_offset = 0,
276 },
277 [RK818_IRQ_USB_OV] = {
278 .mask = RK818_IRQ_USB_OV_MSK,
279 .reg_offset = 0,
280 },
281
282 /* INT_STS2 */
283 [RK818_IRQ_PLUG_IN] = {
284 .mask = RK818_IRQ_PLUG_IN_MSK,
285 .reg_offset = 1,
286 },
287 [RK818_IRQ_PLUG_OUT] = {
288 .mask = RK818_IRQ_PLUG_OUT_MSK,
289 .reg_offset = 1,
290 },
291 [RK818_IRQ_CHG_OK] = {
292 .mask = RK818_IRQ_CHG_OK_MSK,
293 .reg_offset = 1,
294 },
295 [RK818_IRQ_CHG_TE] = {
296 .mask = RK818_IRQ_CHG_TE_MSK,
297 .reg_offset = 1,
298 },
299 [RK818_IRQ_CHG_TS1] = {
300 .mask = RK818_IRQ_CHG_TS1_MSK,
301 .reg_offset = 1,
302 },
303 [RK818_IRQ_TS2] = {
304 .mask = RK818_IRQ_TS2_MSK,
305 .reg_offset = 1,
306 },
307 [RK818_IRQ_CHG_CVTLIM] = {
308 .mask = RK818_IRQ_CHG_CVTLIM_MSK,
309 .reg_offset = 1,
310 },
311 [RK818_IRQ_DISCHG_ILIM] = {
312 .mask = RK818_IRQ_DISCHG_ILIM_MSK,
313 .reg_offset = 1,
314 },
315};
316
Elaine Zhang990f05f2017-08-21 03:28:38 +0200317static struct regmap_irq_chip rk805_irq_chip = {
318 .name = "rk805",
319 .irqs = rk805_irqs,
320 .num_irqs = ARRAY_SIZE(rk805_irqs),
321 .num_regs = 1,
322 .status_base = RK805_INT_STS_REG,
323 .mask_base = RK805_INT_STS_MSK_REG,
324 .ack_base = RK805_INT_STS_REG,
325 .init_ack_masked = true,
326};
327
Bhumika Goyal24e34b92017-01-25 00:55:24 +0530328static const struct regmap_irq_chip rk808_irq_chip = {
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800329 .name = "rk808",
330 .irqs = rk808_irqs,
331 .num_irqs = ARRAY_SIZE(rk808_irqs),
332 .num_regs = 2,
333 .irq_reg_stride = 2,
334 .status_base = RK808_INT_STS_REG1,
335 .mask_base = RK808_INT_STS_MSK_REG1,
336 .ack_base = RK808_INT_STS_REG1,
337 .init_ack_masked = true,
338};
339
Bhumika Goyal24e34b92017-01-25 00:55:24 +0530340static const struct regmap_irq_chip rk818_irq_chip = {
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200341 .name = "rk818",
342 .irqs = rk818_irqs,
343 .num_irqs = ARRAY_SIZE(rk818_irqs),
344 .num_regs = 2,
345 .irq_reg_stride = 2,
346 .status_base = RK818_INT_STS_REG1,
347 .mask_base = RK818_INT_STS_MSK_REG1,
348 .ack_base = RK818_INT_STS_REG1,
349 .init_ack_masked = true,
350};
351
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800352static struct i2c_client *rk808_i2c_client;
Elaine Zhang990f05f2017-08-21 03:28:38 +0200353
354static void rk805_device_shutdown(void)
355{
356 int ret;
357 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
358
359 if (!rk808) {
360 dev_warn(&rk808_i2c_client->dev,
361 "have no rk805, so do nothing here\n");
362 return;
363 }
364
365 ret = regmap_update_bits(rk808->regmap,
366 RK805_DEV_CTRL_REG,
367 DEV_OFF, DEV_OFF);
368 if (ret)
369 dev_err(&rk808_i2c_client->dev, "power off error!\n");
370}
371
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800372static void rk808_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 rk808, so do nothing here\n");
380 return;
381 }
382
383 ret = regmap_update_bits(rk808->regmap,
384 RK808_DEVCTRL_REG,
385 DEV_OFF_RST, DEV_OFF_RST);
386 if (ret)
387 dev_err(&rk808_i2c_client->dev, "power off error!\n");
388}
389
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800390static void rk818_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 rk818, so do nothing here\n");
398 return;
399 }
400
401 ret = regmap_update_bits(rk808->regmap,
402 RK818_DEVCTRL_REG,
403 DEV_OFF, DEV_OFF);
404 if (ret)
405 dev_err(&rk808_i2c_client->dev, "power off error!\n");
406}
407
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200408static const struct of_device_id rk808_of_match[] = {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200409 { .compatible = "rockchip,rk805" },
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200410 { .compatible = "rockchip,rk808" },
411 { .compatible = "rockchip,rk818" },
412 { },
413};
414MODULE_DEVICE_TABLE(of, rk808_of_match);
415
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800416static int rk808_probe(struct i2c_client *client,
417 const struct i2c_device_id *id)
418{
419 struct device_node *np = client->dev.of_node;
420 struct rk808 *rk808;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200421 const struct rk808_reg_data *pre_init_reg;
422 const struct mfd_cell *cells;
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800423 void (*pm_pwroff_fn)(void);
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200424 int nr_pre_init_regs;
425 int nr_cells;
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200426 int pm_off = 0, msb, lsb;
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800427 int ret;
428 int i;
429
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200430 rk808 = devm_kzalloc(&client->dev, sizeof(*rk808), GFP_KERNEL);
431 if (!rk808)
432 return -ENOMEM;
433
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200434 /* Read chip variant */
435 msb = i2c_smbus_read_byte_data(client, RK808_ID_MSB);
436 if (msb < 0) {
437 dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200438 RK808_ID_MSB);
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200439 return msb;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200440 }
441
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200442 lsb = i2c_smbus_read_byte_data(client, RK808_ID_LSB);
443 if (lsb < 0) {
444 dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
445 RK808_ID_LSB);
446 return lsb;
447 }
448
449 rk808->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
450 dev_info(&client->dev, "chip id: 0x%x\n", (unsigned int)rk808->variant);
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200451
452 switch (rk808->variant) {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200453 case RK805_ID:
454 rk808->regmap_cfg = &rk805_regmap_config;
455 rk808->regmap_irq_chip = &rk805_irq_chip;
456 pre_init_reg = rk805_pre_init_reg;
457 nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
458 cells = rk805s;
459 nr_cells = ARRAY_SIZE(rk805s);
460 pm_pwroff_fn = rk805_device_shutdown;
461 break;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200462 case RK808_ID:
463 rk808->regmap_cfg = &rk808_regmap_config;
464 rk808->regmap_irq_chip = &rk808_irq_chip;
465 pre_init_reg = rk808_pre_init_reg;
466 nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
467 cells = rk808s;
468 nr_cells = ARRAY_SIZE(rk808s);
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800469 pm_pwroff_fn = rk808_device_shutdown;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200470 break;
471 case RK818_ID:
472 rk808->regmap_cfg = &rk818_regmap_config;
473 rk808->regmap_irq_chip = &rk818_irq_chip;
474 pre_init_reg = rk818_pre_init_reg;
475 nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
476 cells = rk818s;
477 nr_cells = ARRAY_SIZE(rk818s);
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800478 pm_pwroff_fn = rk818_device_shutdown;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200479 break;
480 default:
481 dev_err(&client->dev, "Unsupported RK8XX ID %lu\n",
482 rk808->variant);
483 return -EINVAL;
484 }
485
486 rk808->i2c = client;
487 i2c_set_clientdata(client, rk808);
488
489 rk808->regmap = devm_regmap_init_i2c(client, rk808->regmap_cfg);
490 if (IS_ERR(rk808->regmap)) {
491 dev_err(&client->dev, "regmap initialization failed\n");
492 return PTR_ERR(rk808->regmap);
493 }
494
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800495 if (!client->irq) {
496 dev_err(&client->dev, "No interrupt support, no core IRQ\n");
497 return -EINVAL;
498 }
499
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800500 ret = regmap_add_irq_chip(rk808->regmap, client->irq,
501 IRQF_ONESHOT, -1,
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200502 rk808->regmap_irq_chip, &rk808->irq_data);
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800503 if (ret) {
504 dev_err(&client->dev, "Failed to add irq_chip %d\n", ret);
505 return ret;
506 }
507
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200508 for (i = 0; i < nr_pre_init_regs; i++) {
509 ret = regmap_update_bits(rk808->regmap,
510 pre_init_reg[i].addr,
511 pre_init_reg[i].mask,
512 pre_init_reg[i].value);
513 if (ret) {
514 dev_err(&client->dev,
515 "0x%x write err\n",
516 pre_init_reg[i].addr);
517 return ret;
518 }
519 }
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800520
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200521 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
522 cells, nr_cells, NULL, 0,
523 regmap_irq_get_domain(rk808->irq_data));
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800524 if (ret) {
525 dev_err(&client->dev, "failed to add MFD devices %d\n", ret);
526 goto err_irq;
527 }
528
529 pm_off = of_property_read_bool(np,
530 "rockchip,system-power-controller");
531 if (pm_off && !pm_power_off) {
532 rk808_i2c_client = client;
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800533 pm_power_off = pm_pwroff_fn;
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800534 }
535
536 return 0;
537
538err_irq:
539 regmap_del_irq_chip(client->irq, rk808->irq_data);
540 return ret;
541}
542
543static int rk808_remove(struct i2c_client *client)
544{
545 struct rk808 *rk808 = i2c_get_clientdata(client);
546
547 regmap_del_irq_chip(client->irq, rk808->irq_data);
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800548 pm_power_off = NULL;
549
550 return 0;
551}
552
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800553static const struct i2c_device_id rk808_ids[] = {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200554 { "rk805" },
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800555 { "rk808" },
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200556 { "rk818" },
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800557 { },
558};
559MODULE_DEVICE_TABLE(i2c, rk808_ids);
560
561static struct i2c_driver rk808_i2c_driver = {
562 .driver = {
563 .name = "rk808",
564 .of_match_table = rk808_of_match,
565 },
566 .probe = rk808_probe,
567 .remove = rk808_remove,
568 .id_table = rk808_ids,
569};
570
571module_i2c_driver(rk808_i2c_driver);
572
573MODULE_LICENSE("GPL");
574MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
575MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200576MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
577MODULE_DESCRIPTION("RK808/RK818 PMIC driver");