blob: c803d2d5dfb7c14f155dee45c00a8d5e33412f91 [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", },
Joseph Chen8d249b62017-08-21 03:28:41 +0200100 { .name = "rk805-pinctrl", },
Elaine Zhang990f05f2017-08-21 03:28:38 +0200101 {
102 .name = "rk808-rtc",
103 .num_resources = ARRAY_SIZE(rtc_resources),
104 .resources = &rtc_resources[0],
105 },
106};
107
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800108static const struct mfd_cell rk808s[] = {
109 { .name = "rk808-clkout", },
110 { .name = "rk808-regulator", },
111 {
112 .name = "rk808-rtc",
113 .num_resources = ARRAY_SIZE(rtc_resources),
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200114 .resources = rtc_resources,
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800115 },
116};
117
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200118static const struct mfd_cell rk818s[] = {
119 { .name = "rk808-clkout", },
120 { .name = "rk808-regulator", },
121 {
122 .name = "rk808-rtc",
123 .num_resources = ARRAY_SIZE(rtc_resources),
124 .resources = rtc_resources,
125 },
126};
127
Elaine Zhang990f05f2017-08-21 03:28:38 +0200128static const struct rk808_reg_data rk805_pre_init_reg[] = {
129 {RK805_BUCK1_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
130 RK805_BUCK1_2_ILMAX_4000MA},
131 {RK805_BUCK2_CONFIG_REG, RK805_BUCK1_2_ILMAX_MASK,
132 RK805_BUCK1_2_ILMAX_4000MA},
133 {RK805_BUCK3_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
134 RK805_BUCK3_ILMAX_3000MA},
135 {RK805_BUCK4_CONFIG_REG, RK805_BUCK3_4_ILMAX_MASK,
136 RK805_BUCK4_ILMAX_3500MA},
137 {RK805_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_400MA},
138 {RK805_GPIO_IO_POL_REG, SLP_SD_MSK, SLEEP_FUN},
139 {RK805_THERMAL_REG, TEMP_HOTDIE_MSK, TEMP115C},
140};
141
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200142static const struct rk808_reg_data rk808_pre_init_reg[] = {
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800143 { RK808_BUCK3_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_150MA },
144 { RK808_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_200MA },
145 { RK808_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
146 { RK808_BUCK1_CONFIG_REG, BUCK1_RATE_MASK, BUCK_ILMIN_200MA },
147 { RK808_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_200MA },
Chris Zhonge19f7422015-02-28 18:09:06 +0800148 { RK808_DCDC_UV_ACT_REG, BUCK_UV_ACT_MASK, BUCK_UV_ACT_DISABLE},
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800149 { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT |
150 VB_LO_SEL_3500MV },
151};
152
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200153static const struct rk808_reg_data rk818_pre_init_reg[] = {
154 /* improve efficiency */
155 { RK818_BUCK2_CONFIG_REG, BUCK2_RATE_MASK, BUCK_ILMIN_250MA },
156 { RK818_BUCK4_CONFIG_REG, BUCK_ILMIN_MASK, BUCK_ILMIN_250MA },
157 { RK818_BOOST_CONFIG_REG, BOOST_ILMIN_MASK, BOOST_ILMIN_100MA },
158 { RK818_USB_CTRL_REG, RK818_USB_ILIM_SEL_MASK,
159 RK818_USB_ILMIN_2000MA },
160 /* close charger when usb lower then 3.4V */
161 { RK818_USB_CTRL_REG, RK818_USB_CHG_SD_VSEL_MASK,
162 (0x7 << 4) },
163 /* no action when vref */
164 { RK818_H5V_EN_REG, BIT(1), RK818_REF_RDY_CTRL },
165 /* enable HDMI 5V */
166 { RK818_H5V_EN_REG, BIT(0), RK818_H5V_EN },
167 { RK808_VB_MON_REG, MASK_ALL, VB_LO_ACT |
168 VB_LO_SEL_3500MV },
169};
170
Elaine Zhang990f05f2017-08-21 03:28:38 +0200171static const struct regmap_irq rk805_irqs[] = {
172 [RK805_IRQ_PWRON_RISE] = {
173 .mask = RK805_IRQ_PWRON_RISE_MSK,
174 .reg_offset = 0,
175 },
176 [RK805_IRQ_VB_LOW] = {
177 .mask = RK805_IRQ_VB_LOW_MSK,
178 .reg_offset = 0,
179 },
180 [RK805_IRQ_PWRON] = {
181 .mask = RK805_IRQ_PWRON_MSK,
182 .reg_offset = 0,
183 },
184 [RK805_IRQ_PWRON_LP] = {
185 .mask = RK805_IRQ_PWRON_LP_MSK,
186 .reg_offset = 0,
187 },
188 [RK805_IRQ_HOTDIE] = {
189 .mask = RK805_IRQ_HOTDIE_MSK,
190 .reg_offset = 0,
191 },
192 [RK805_IRQ_RTC_ALARM] = {
193 .mask = RK805_IRQ_RTC_ALARM_MSK,
194 .reg_offset = 0,
195 },
196 [RK805_IRQ_RTC_PERIOD] = {
197 .mask = RK805_IRQ_RTC_PERIOD_MSK,
198 .reg_offset = 0,
199 },
200 [RK805_IRQ_PWRON_FALL] = {
201 .mask = RK805_IRQ_PWRON_FALL_MSK,
202 .reg_offset = 0,
203 },
204};
205
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800206static const struct regmap_irq rk808_irqs[] = {
207 /* INT_STS */
208 [RK808_IRQ_VOUT_LO] = {
209 .mask = RK808_IRQ_VOUT_LO_MSK,
210 .reg_offset = 0,
211 },
212 [RK808_IRQ_VB_LO] = {
213 .mask = RK808_IRQ_VB_LO_MSK,
214 .reg_offset = 0,
215 },
216 [RK808_IRQ_PWRON] = {
217 .mask = RK808_IRQ_PWRON_MSK,
218 .reg_offset = 0,
219 },
220 [RK808_IRQ_PWRON_LP] = {
221 .mask = RK808_IRQ_PWRON_LP_MSK,
222 .reg_offset = 0,
223 },
224 [RK808_IRQ_HOTDIE] = {
225 .mask = RK808_IRQ_HOTDIE_MSK,
226 .reg_offset = 0,
227 },
228 [RK808_IRQ_RTC_ALARM] = {
229 .mask = RK808_IRQ_RTC_ALARM_MSK,
230 .reg_offset = 0,
231 },
232 [RK808_IRQ_RTC_PERIOD] = {
233 .mask = RK808_IRQ_RTC_PERIOD_MSK,
234 .reg_offset = 0,
235 },
236
237 /* INT_STS2 */
238 [RK808_IRQ_PLUG_IN_INT] = {
239 .mask = RK808_IRQ_PLUG_IN_INT_MSK,
240 .reg_offset = 1,
241 },
242 [RK808_IRQ_PLUG_OUT_INT] = {
243 .mask = RK808_IRQ_PLUG_OUT_INT_MSK,
244 .reg_offset = 1,
245 },
246};
247
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200248static const struct regmap_irq rk818_irqs[] = {
249 /* INT_STS */
250 [RK818_IRQ_VOUT_LO] = {
251 .mask = RK818_IRQ_VOUT_LO_MSK,
252 .reg_offset = 0,
253 },
254 [RK818_IRQ_VB_LO] = {
255 .mask = RK818_IRQ_VB_LO_MSK,
256 .reg_offset = 0,
257 },
258 [RK818_IRQ_PWRON] = {
259 .mask = RK818_IRQ_PWRON_MSK,
260 .reg_offset = 0,
261 },
262 [RK818_IRQ_PWRON_LP] = {
263 .mask = RK818_IRQ_PWRON_LP_MSK,
264 .reg_offset = 0,
265 },
266 [RK818_IRQ_HOTDIE] = {
267 .mask = RK818_IRQ_HOTDIE_MSK,
268 .reg_offset = 0,
269 },
270 [RK818_IRQ_RTC_ALARM] = {
271 .mask = RK818_IRQ_RTC_ALARM_MSK,
272 .reg_offset = 0,
273 },
274 [RK818_IRQ_RTC_PERIOD] = {
275 .mask = RK818_IRQ_RTC_PERIOD_MSK,
276 .reg_offset = 0,
277 },
278 [RK818_IRQ_USB_OV] = {
279 .mask = RK818_IRQ_USB_OV_MSK,
280 .reg_offset = 0,
281 },
282
283 /* INT_STS2 */
284 [RK818_IRQ_PLUG_IN] = {
285 .mask = RK818_IRQ_PLUG_IN_MSK,
286 .reg_offset = 1,
287 },
288 [RK818_IRQ_PLUG_OUT] = {
289 .mask = RK818_IRQ_PLUG_OUT_MSK,
290 .reg_offset = 1,
291 },
292 [RK818_IRQ_CHG_OK] = {
293 .mask = RK818_IRQ_CHG_OK_MSK,
294 .reg_offset = 1,
295 },
296 [RK818_IRQ_CHG_TE] = {
297 .mask = RK818_IRQ_CHG_TE_MSK,
298 .reg_offset = 1,
299 },
300 [RK818_IRQ_CHG_TS1] = {
301 .mask = RK818_IRQ_CHG_TS1_MSK,
302 .reg_offset = 1,
303 },
304 [RK818_IRQ_TS2] = {
305 .mask = RK818_IRQ_TS2_MSK,
306 .reg_offset = 1,
307 },
308 [RK818_IRQ_CHG_CVTLIM] = {
309 .mask = RK818_IRQ_CHG_CVTLIM_MSK,
310 .reg_offset = 1,
311 },
312 [RK818_IRQ_DISCHG_ILIM] = {
313 .mask = RK818_IRQ_DISCHG_ILIM_MSK,
314 .reg_offset = 1,
315 },
316};
317
Elaine Zhang990f05f2017-08-21 03:28:38 +0200318static struct regmap_irq_chip rk805_irq_chip = {
319 .name = "rk805",
320 .irqs = rk805_irqs,
321 .num_irqs = ARRAY_SIZE(rk805_irqs),
322 .num_regs = 1,
323 .status_base = RK805_INT_STS_REG,
324 .mask_base = RK805_INT_STS_MSK_REG,
325 .ack_base = RK805_INT_STS_REG,
326 .init_ack_masked = true,
327};
328
Bhumika Goyal24e34b92017-01-25 00:55:24 +0530329static const struct regmap_irq_chip rk808_irq_chip = {
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800330 .name = "rk808",
331 .irqs = rk808_irqs,
332 .num_irqs = ARRAY_SIZE(rk808_irqs),
333 .num_regs = 2,
334 .irq_reg_stride = 2,
335 .status_base = RK808_INT_STS_REG1,
336 .mask_base = RK808_INT_STS_MSK_REG1,
337 .ack_base = RK808_INT_STS_REG1,
338 .init_ack_masked = true,
339};
340
Bhumika Goyal24e34b92017-01-25 00:55:24 +0530341static const struct regmap_irq_chip rk818_irq_chip = {
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200342 .name = "rk818",
343 .irqs = rk818_irqs,
344 .num_irqs = ARRAY_SIZE(rk818_irqs),
345 .num_regs = 2,
346 .irq_reg_stride = 2,
347 .status_base = RK818_INT_STS_REG1,
348 .mask_base = RK818_INT_STS_MSK_REG1,
349 .ack_base = RK818_INT_STS_REG1,
350 .init_ack_masked = true,
351};
352
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800353static struct i2c_client *rk808_i2c_client;
Elaine Zhang990f05f2017-08-21 03:28:38 +0200354
355static void rk805_device_shutdown(void)
356{
357 int ret;
358 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
359
360 if (!rk808) {
361 dev_warn(&rk808_i2c_client->dev,
362 "have no rk805, so do nothing here\n");
363 return;
364 }
365
366 ret = regmap_update_bits(rk808->regmap,
367 RK805_DEV_CTRL_REG,
368 DEV_OFF, DEV_OFF);
369 if (ret)
370 dev_err(&rk808_i2c_client->dev, "power off error!\n");
371}
372
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800373static void rk808_device_shutdown(void)
374{
375 int ret;
376 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
377
378 if (!rk808) {
379 dev_warn(&rk808_i2c_client->dev,
380 "have no rk808, so do nothing here\n");
381 return;
382 }
383
384 ret = regmap_update_bits(rk808->regmap,
385 RK808_DEVCTRL_REG,
386 DEV_OFF_RST, DEV_OFF_RST);
387 if (ret)
388 dev_err(&rk808_i2c_client->dev, "power off error!\n");
389}
390
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800391static void rk818_device_shutdown(void)
392{
393 int ret;
394 struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
395
396 if (!rk808) {
397 dev_warn(&rk808_i2c_client->dev,
398 "have no rk818, so do nothing here\n");
399 return;
400 }
401
402 ret = regmap_update_bits(rk808->regmap,
403 RK818_DEVCTRL_REG,
404 DEV_OFF, DEV_OFF);
405 if (ret)
406 dev_err(&rk808_i2c_client->dev, "power off error!\n");
407}
408
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200409static const struct of_device_id rk808_of_match[] = {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200410 { .compatible = "rockchip,rk805" },
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200411 { .compatible = "rockchip,rk808" },
412 { .compatible = "rockchip,rk818" },
413 { },
414};
415MODULE_DEVICE_TABLE(of, rk808_of_match);
416
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800417static int rk808_probe(struct i2c_client *client,
418 const struct i2c_device_id *id)
419{
420 struct device_node *np = client->dev.of_node;
421 struct rk808 *rk808;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200422 const struct rk808_reg_data *pre_init_reg;
423 const struct mfd_cell *cells;
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800424 void (*pm_pwroff_fn)(void);
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200425 int nr_pre_init_regs;
426 int nr_cells;
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200427 int pm_off = 0, msb, lsb;
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800428 int ret;
429 int i;
430
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200431 rk808 = devm_kzalloc(&client->dev, sizeof(*rk808), GFP_KERNEL);
432 if (!rk808)
433 return -ENOMEM;
434
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200435 /* Read chip variant */
436 msb = i2c_smbus_read_byte_data(client, RK808_ID_MSB);
437 if (msb < 0) {
438 dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200439 RK808_ID_MSB);
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200440 return msb;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200441 }
442
Elaine Zhang9d6105e2017-08-21 03:28:34 +0200443 lsb = i2c_smbus_read_byte_data(client, RK808_ID_LSB);
444 if (lsb < 0) {
445 dev_err(&client->dev, "failed to read the chip id at 0x%x\n",
446 RK808_ID_LSB);
447 return lsb;
448 }
449
450 rk808->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
451 dev_info(&client->dev, "chip id: 0x%x\n", (unsigned int)rk808->variant);
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200452
453 switch (rk808->variant) {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200454 case RK805_ID:
455 rk808->regmap_cfg = &rk805_regmap_config;
456 rk808->regmap_irq_chip = &rk805_irq_chip;
457 pre_init_reg = rk805_pre_init_reg;
458 nr_pre_init_regs = ARRAY_SIZE(rk805_pre_init_reg);
459 cells = rk805s;
460 nr_cells = ARRAY_SIZE(rk805s);
461 pm_pwroff_fn = rk805_device_shutdown;
462 break;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200463 case RK808_ID:
464 rk808->regmap_cfg = &rk808_regmap_config;
465 rk808->regmap_irq_chip = &rk808_irq_chip;
466 pre_init_reg = rk808_pre_init_reg;
467 nr_pre_init_regs = ARRAY_SIZE(rk808_pre_init_reg);
468 cells = rk808s;
469 nr_cells = ARRAY_SIZE(rk808s);
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800470 pm_pwroff_fn = rk808_device_shutdown;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200471 break;
472 case RK818_ID:
473 rk808->regmap_cfg = &rk818_regmap_config;
474 rk808->regmap_irq_chip = &rk818_irq_chip;
475 pre_init_reg = rk818_pre_init_reg;
476 nr_pre_init_regs = ARRAY_SIZE(rk818_pre_init_reg);
477 cells = rk818s;
478 nr_cells = ARRAY_SIZE(rk818s);
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800479 pm_pwroff_fn = rk818_device_shutdown;
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200480 break;
481 default:
482 dev_err(&client->dev, "Unsupported RK8XX ID %lu\n",
483 rk808->variant);
484 return -EINVAL;
485 }
486
487 rk808->i2c = client;
488 i2c_set_clientdata(client, rk808);
489
490 rk808->regmap = devm_regmap_init_i2c(client, rk808->regmap_cfg);
491 if (IS_ERR(rk808->regmap)) {
492 dev_err(&client->dev, "regmap initialization failed\n");
493 return PTR_ERR(rk808->regmap);
494 }
495
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800496 if (!client->irq) {
497 dev_err(&client->dev, "No interrupt support, no core IRQ\n");
498 return -EINVAL;
499 }
500
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800501 ret = regmap_add_irq_chip(rk808->regmap, client->irq,
502 IRQF_ONESHOT, -1,
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200503 rk808->regmap_irq_chip, &rk808->irq_data);
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800504 if (ret) {
505 dev_err(&client->dev, "Failed to add irq_chip %d\n", ret);
506 return ret;
507 }
508
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200509 for (i = 0; i < nr_pre_init_regs; i++) {
510 ret = regmap_update_bits(rk808->regmap,
511 pre_init_reg[i].addr,
512 pre_init_reg[i].mask,
513 pre_init_reg[i].value);
514 if (ret) {
515 dev_err(&client->dev,
516 "0x%x write err\n",
517 pre_init_reg[i].addr);
518 return ret;
519 }
520 }
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800521
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200522 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
523 cells, nr_cells, NULL, 0,
524 regmap_irq_get_domain(rk808->irq_data));
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800525 if (ret) {
526 dev_err(&client->dev, "failed to add MFD devices %d\n", ret);
527 goto err_irq;
528 }
529
530 pm_off = of_property_read_bool(np,
531 "rockchip,system-power-controller");
532 if (pm_off && !pm_power_off) {
533 rk808_i2c_client = client;
Jianhong Chenb2e2c852016-10-17 17:03:10 +0800534 pm_power_off = pm_pwroff_fn;
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800535 }
536
537 return 0;
538
539err_irq:
540 regmap_del_irq_chip(client->irq, rk808->irq_data);
541 return ret;
542}
543
544static int rk808_remove(struct i2c_client *client)
545{
546 struct rk808 *rk808 = i2c_get_clientdata(client);
547
548 regmap_del_irq_chip(client->irq, rk808->irq_data);
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800549 pm_power_off = NULL;
550
551 return 0;
552}
553
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800554static const struct i2c_device_id rk808_ids[] = {
Elaine Zhang990f05f2017-08-21 03:28:38 +0200555 { "rk805" },
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800556 { "rk808" },
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200557 { "rk818" },
Chris Zhongf69a7cf2014-09-03 21:51:44 +0800558 { },
559};
560MODULE_DEVICE_TABLE(i2c, rk808_ids);
561
562static struct i2c_driver rk808_i2c_driver = {
563 .driver = {
564 .name = "rk808",
565 .of_match_table = rk808_of_match,
566 },
567 .probe = rk808_probe,
568 .remove = rk808_remove,
569 .id_table = rk808_ids,
570};
571
572module_i2c_driver(rk808_i2c_driver);
573
574MODULE_LICENSE("GPL");
575MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
576MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
Wadim Egorov2eedcbf2016-08-29 13:07:58 +0200577MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
578MODULE_DESCRIPTION("RK808/RK818 PMIC driver");