0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/kernel.h>
0011 #include <linux/init.h>
0012 #include <linux/export.h>
0013 #include <linux/bcd.h>
0014 #include <linux/delay.h>
0015 #include <linux/mfd/core.h>
0016 #include <linux/slab.h>
0017 #include <linux/err.h>
0018 #include <linux/of.h>
0019 #include <linux/of_device.h>
0020
0021 #include <linux/mfd/wm831x/core.h>
0022 #include <linux/mfd/wm831x/pdata.h>
0023 #include <linux/mfd/wm831x/irq.h>
0024 #include <linux/mfd/wm831x/auxadc.h>
0025 #include <linux/mfd/wm831x/otp.h>
0026 #include <linux/mfd/wm831x/pmu.h>
0027 #include <linux/mfd/wm831x/regulator.h>
0028
0029
0030
0031
0032 const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
0033 2,
0034 2,
0035 3,
0036 3,
0037 4,
0038 5,
0039 6,
0040 7,
0041 8,
0042 10,
0043 11,
0044 13,
0045 16,
0046 19,
0047 23,
0048 27,
0049 32,
0050 38,
0051 45,
0052 54,
0053 64,
0054 76,
0055 91,
0056 108,
0057 128,
0058 152,
0059 181,
0060 215,
0061 256,
0062 304,
0063 362,
0064 431,
0065 512,
0066 609,
0067 724,
0068 861,
0069 1024,
0070 1218,
0071 1448,
0072 1722,
0073 2048,
0074 2435,
0075 2896,
0076 3444,
0077 4096,
0078 4871,
0079 5793,
0080 6889,
0081 8192,
0082 9742,
0083 11585,
0084 13777,
0085 16384,
0086 19484,
0087 23170,
0088 27554,
0089 };
0090 EXPORT_SYMBOL_GPL(wm831x_isinkv_values);
0091
0092 static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
0093 {
0094 if (!wm831x->locked)
0095 return 0;
0096
0097 switch (reg) {
0098 case WM831X_WATCHDOG:
0099 case WM831X_DC4_CONTROL:
0100 case WM831X_ON_PIN_CONTROL:
0101 case WM831X_BACKUP_CHARGER_CONTROL:
0102 case WM831X_CHARGER_CONTROL_1:
0103 case WM831X_CHARGER_CONTROL_2:
0104 return 1;
0105
0106 default:
0107 return 0;
0108 }
0109 }
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 void wm831x_reg_lock(struct wm831x *wm831x)
0121 {
0122 int ret;
0123
0124 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
0125 if (ret == 0) {
0126 dev_vdbg(wm831x->dev, "Registers locked\n");
0127
0128 mutex_lock(&wm831x->io_lock);
0129 WARN_ON(wm831x->locked);
0130 wm831x->locked = 1;
0131 mutex_unlock(&wm831x->io_lock);
0132 } else {
0133 dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
0134 }
0135
0136 }
0137 EXPORT_SYMBOL_GPL(wm831x_reg_lock);
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 int wm831x_reg_unlock(struct wm831x *wm831x)
0149 {
0150 int ret;
0151
0152
0153 ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
0154 if (ret == 0) {
0155 dev_vdbg(wm831x->dev, "Registers unlocked\n");
0156
0157 mutex_lock(&wm831x->io_lock);
0158 WARN_ON(!wm831x->locked);
0159 wm831x->locked = 0;
0160 mutex_unlock(&wm831x->io_lock);
0161 }
0162
0163 return ret;
0164 }
0165 EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
0166
0167 static bool wm831x_reg_readable(struct device *dev, unsigned int reg)
0168 {
0169 switch (reg) {
0170 case WM831X_RESET_ID:
0171 case WM831X_REVISION:
0172 case WM831X_PARENT_ID:
0173 case WM831X_SYSVDD_CONTROL:
0174 case WM831X_THERMAL_MONITORING:
0175 case WM831X_POWER_STATE:
0176 case WM831X_WATCHDOG:
0177 case WM831X_ON_PIN_CONTROL:
0178 case WM831X_RESET_CONTROL:
0179 case WM831X_CONTROL_INTERFACE:
0180 case WM831X_SECURITY_KEY:
0181 case WM831X_SOFTWARE_SCRATCH:
0182 case WM831X_OTP_CONTROL:
0183 case WM831X_GPIO_LEVEL:
0184 case WM831X_SYSTEM_STATUS:
0185 case WM831X_ON_SOURCE:
0186 case WM831X_OFF_SOURCE:
0187 case WM831X_SYSTEM_INTERRUPTS:
0188 case WM831X_INTERRUPT_STATUS_1:
0189 case WM831X_INTERRUPT_STATUS_2:
0190 case WM831X_INTERRUPT_STATUS_3:
0191 case WM831X_INTERRUPT_STATUS_4:
0192 case WM831X_INTERRUPT_STATUS_5:
0193 case WM831X_IRQ_CONFIG:
0194 case WM831X_SYSTEM_INTERRUPTS_MASK:
0195 case WM831X_INTERRUPT_STATUS_1_MASK:
0196 case WM831X_INTERRUPT_STATUS_2_MASK:
0197 case WM831X_INTERRUPT_STATUS_3_MASK:
0198 case WM831X_INTERRUPT_STATUS_4_MASK:
0199 case WM831X_INTERRUPT_STATUS_5_MASK:
0200 case WM831X_RTC_WRITE_COUNTER:
0201 case WM831X_RTC_TIME_1:
0202 case WM831X_RTC_TIME_2:
0203 case WM831X_RTC_ALARM_1:
0204 case WM831X_RTC_ALARM_2:
0205 case WM831X_RTC_CONTROL:
0206 case WM831X_RTC_TRIM:
0207 case WM831X_TOUCH_CONTROL_1:
0208 case WM831X_TOUCH_CONTROL_2:
0209 case WM831X_TOUCH_DATA_X:
0210 case WM831X_TOUCH_DATA_Y:
0211 case WM831X_TOUCH_DATA_Z:
0212 case WM831X_AUXADC_DATA:
0213 case WM831X_AUXADC_CONTROL:
0214 case WM831X_AUXADC_SOURCE:
0215 case WM831X_COMPARATOR_CONTROL:
0216 case WM831X_COMPARATOR_1:
0217 case WM831X_COMPARATOR_2:
0218 case WM831X_COMPARATOR_3:
0219 case WM831X_COMPARATOR_4:
0220 case WM831X_GPIO1_CONTROL:
0221 case WM831X_GPIO2_CONTROL:
0222 case WM831X_GPIO3_CONTROL:
0223 case WM831X_GPIO4_CONTROL:
0224 case WM831X_GPIO5_CONTROL:
0225 case WM831X_GPIO6_CONTROL:
0226 case WM831X_GPIO7_CONTROL:
0227 case WM831X_GPIO8_CONTROL:
0228 case WM831X_GPIO9_CONTROL:
0229 case WM831X_GPIO10_CONTROL:
0230 case WM831X_GPIO11_CONTROL:
0231 case WM831X_GPIO12_CONTROL:
0232 case WM831X_GPIO13_CONTROL:
0233 case WM831X_GPIO14_CONTROL:
0234 case WM831X_GPIO15_CONTROL:
0235 case WM831X_GPIO16_CONTROL:
0236 case WM831X_CHARGER_CONTROL_1:
0237 case WM831X_CHARGER_CONTROL_2:
0238 case WM831X_CHARGER_STATUS:
0239 case WM831X_BACKUP_CHARGER_CONTROL:
0240 case WM831X_STATUS_LED_1:
0241 case WM831X_STATUS_LED_2:
0242 case WM831X_CURRENT_SINK_1:
0243 case WM831X_CURRENT_SINK_2:
0244 case WM831X_DCDC_ENABLE:
0245 case WM831X_LDO_ENABLE:
0246 case WM831X_DCDC_STATUS:
0247 case WM831X_LDO_STATUS:
0248 case WM831X_DCDC_UV_STATUS:
0249 case WM831X_LDO_UV_STATUS:
0250 case WM831X_DC1_CONTROL_1:
0251 case WM831X_DC1_CONTROL_2:
0252 case WM831X_DC1_ON_CONFIG:
0253 case WM831X_DC1_SLEEP_CONTROL:
0254 case WM831X_DC1_DVS_CONTROL:
0255 case WM831X_DC2_CONTROL_1:
0256 case WM831X_DC2_CONTROL_2:
0257 case WM831X_DC2_ON_CONFIG:
0258 case WM831X_DC2_SLEEP_CONTROL:
0259 case WM831X_DC2_DVS_CONTROL:
0260 case WM831X_DC3_CONTROL_1:
0261 case WM831X_DC3_CONTROL_2:
0262 case WM831X_DC3_ON_CONFIG:
0263 case WM831X_DC3_SLEEP_CONTROL:
0264 case WM831X_DC4_CONTROL:
0265 case WM831X_DC4_SLEEP_CONTROL:
0266 case WM831X_EPE1_CONTROL:
0267 case WM831X_EPE2_CONTROL:
0268 case WM831X_LDO1_CONTROL:
0269 case WM831X_LDO1_ON_CONTROL:
0270 case WM831X_LDO1_SLEEP_CONTROL:
0271 case WM831X_LDO2_CONTROL:
0272 case WM831X_LDO2_ON_CONTROL:
0273 case WM831X_LDO2_SLEEP_CONTROL:
0274 case WM831X_LDO3_CONTROL:
0275 case WM831X_LDO3_ON_CONTROL:
0276 case WM831X_LDO3_SLEEP_CONTROL:
0277 case WM831X_LDO4_CONTROL:
0278 case WM831X_LDO4_ON_CONTROL:
0279 case WM831X_LDO4_SLEEP_CONTROL:
0280 case WM831X_LDO5_CONTROL:
0281 case WM831X_LDO5_ON_CONTROL:
0282 case WM831X_LDO5_SLEEP_CONTROL:
0283 case WM831X_LDO6_CONTROL:
0284 case WM831X_LDO6_ON_CONTROL:
0285 case WM831X_LDO6_SLEEP_CONTROL:
0286 case WM831X_LDO7_CONTROL:
0287 case WM831X_LDO7_ON_CONTROL:
0288 case WM831X_LDO7_SLEEP_CONTROL:
0289 case WM831X_LDO8_CONTROL:
0290 case WM831X_LDO8_ON_CONTROL:
0291 case WM831X_LDO8_SLEEP_CONTROL:
0292 case WM831X_LDO9_CONTROL:
0293 case WM831X_LDO9_ON_CONTROL:
0294 case WM831X_LDO9_SLEEP_CONTROL:
0295 case WM831X_LDO10_CONTROL:
0296 case WM831X_LDO10_ON_CONTROL:
0297 case WM831X_LDO10_SLEEP_CONTROL:
0298 case WM831X_LDO11_ON_CONTROL:
0299 case WM831X_LDO11_SLEEP_CONTROL:
0300 case WM831X_POWER_GOOD_SOURCE_1:
0301 case WM831X_POWER_GOOD_SOURCE_2:
0302 case WM831X_CLOCK_CONTROL_1:
0303 case WM831X_CLOCK_CONTROL_2:
0304 case WM831X_FLL_CONTROL_1:
0305 case WM831X_FLL_CONTROL_2:
0306 case WM831X_FLL_CONTROL_3:
0307 case WM831X_FLL_CONTROL_4:
0308 case WM831X_FLL_CONTROL_5:
0309 case WM831X_UNIQUE_ID_1:
0310 case WM831X_UNIQUE_ID_2:
0311 case WM831X_UNIQUE_ID_3:
0312 case WM831X_UNIQUE_ID_4:
0313 case WM831X_UNIQUE_ID_5:
0314 case WM831X_UNIQUE_ID_6:
0315 case WM831X_UNIQUE_ID_7:
0316 case WM831X_UNIQUE_ID_8:
0317 case WM831X_FACTORY_OTP_ID:
0318 case WM831X_FACTORY_OTP_1:
0319 case WM831X_FACTORY_OTP_2:
0320 case WM831X_FACTORY_OTP_3:
0321 case WM831X_FACTORY_OTP_4:
0322 case WM831X_FACTORY_OTP_5:
0323 case WM831X_CUSTOMER_OTP_ID:
0324 case WM831X_DC1_OTP_CONTROL:
0325 case WM831X_DC2_OTP_CONTROL:
0326 case WM831X_DC3_OTP_CONTROL:
0327 case WM831X_LDO1_2_OTP_CONTROL:
0328 case WM831X_LDO3_4_OTP_CONTROL:
0329 case WM831X_LDO5_6_OTP_CONTROL:
0330 case WM831X_LDO7_8_OTP_CONTROL:
0331 case WM831X_LDO9_10_OTP_CONTROL:
0332 case WM831X_LDO11_EPE_CONTROL:
0333 case WM831X_GPIO1_OTP_CONTROL:
0334 case WM831X_GPIO2_OTP_CONTROL:
0335 case WM831X_GPIO3_OTP_CONTROL:
0336 case WM831X_GPIO4_OTP_CONTROL:
0337 case WM831X_GPIO5_OTP_CONTROL:
0338 case WM831X_GPIO6_OTP_CONTROL:
0339 case WM831X_DBE_CHECK_DATA:
0340 return true;
0341 default:
0342 return false;
0343 }
0344 }
0345
0346 static bool wm831x_reg_writeable(struct device *dev, unsigned int reg)
0347 {
0348 struct wm831x *wm831x = dev_get_drvdata(dev);
0349
0350 if (wm831x_reg_locked(wm831x, reg))
0351 return false;
0352
0353 switch (reg) {
0354 case WM831X_SYSVDD_CONTROL:
0355 case WM831X_THERMAL_MONITORING:
0356 case WM831X_POWER_STATE:
0357 case WM831X_WATCHDOG:
0358 case WM831X_ON_PIN_CONTROL:
0359 case WM831X_RESET_CONTROL:
0360 case WM831X_CONTROL_INTERFACE:
0361 case WM831X_SECURITY_KEY:
0362 case WM831X_SOFTWARE_SCRATCH:
0363 case WM831X_OTP_CONTROL:
0364 case WM831X_GPIO_LEVEL:
0365 case WM831X_INTERRUPT_STATUS_1:
0366 case WM831X_INTERRUPT_STATUS_2:
0367 case WM831X_INTERRUPT_STATUS_3:
0368 case WM831X_INTERRUPT_STATUS_4:
0369 case WM831X_INTERRUPT_STATUS_5:
0370 case WM831X_IRQ_CONFIG:
0371 case WM831X_SYSTEM_INTERRUPTS_MASK:
0372 case WM831X_INTERRUPT_STATUS_1_MASK:
0373 case WM831X_INTERRUPT_STATUS_2_MASK:
0374 case WM831X_INTERRUPT_STATUS_3_MASK:
0375 case WM831X_INTERRUPT_STATUS_4_MASK:
0376 case WM831X_INTERRUPT_STATUS_5_MASK:
0377 case WM831X_RTC_TIME_1:
0378 case WM831X_RTC_TIME_2:
0379 case WM831X_RTC_ALARM_1:
0380 case WM831X_RTC_ALARM_2:
0381 case WM831X_RTC_CONTROL:
0382 case WM831X_RTC_TRIM:
0383 case WM831X_TOUCH_CONTROL_1:
0384 case WM831X_TOUCH_CONTROL_2:
0385 case WM831X_AUXADC_CONTROL:
0386 case WM831X_AUXADC_SOURCE:
0387 case WM831X_COMPARATOR_CONTROL:
0388 case WM831X_COMPARATOR_1:
0389 case WM831X_COMPARATOR_2:
0390 case WM831X_COMPARATOR_3:
0391 case WM831X_COMPARATOR_4:
0392 case WM831X_GPIO1_CONTROL:
0393 case WM831X_GPIO2_CONTROL:
0394 case WM831X_GPIO3_CONTROL:
0395 case WM831X_GPIO4_CONTROL:
0396 case WM831X_GPIO5_CONTROL:
0397 case WM831X_GPIO6_CONTROL:
0398 case WM831X_GPIO7_CONTROL:
0399 case WM831X_GPIO8_CONTROL:
0400 case WM831X_GPIO9_CONTROL:
0401 case WM831X_GPIO10_CONTROL:
0402 case WM831X_GPIO11_CONTROL:
0403 case WM831X_GPIO12_CONTROL:
0404 case WM831X_GPIO13_CONTROL:
0405 case WM831X_GPIO14_CONTROL:
0406 case WM831X_GPIO15_CONTROL:
0407 case WM831X_GPIO16_CONTROL:
0408 case WM831X_CHARGER_CONTROL_1:
0409 case WM831X_CHARGER_CONTROL_2:
0410 case WM831X_CHARGER_STATUS:
0411 case WM831X_BACKUP_CHARGER_CONTROL:
0412 case WM831X_STATUS_LED_1:
0413 case WM831X_STATUS_LED_2:
0414 case WM831X_CURRENT_SINK_1:
0415 case WM831X_CURRENT_SINK_2:
0416 case WM831X_DCDC_ENABLE:
0417 case WM831X_LDO_ENABLE:
0418 case WM831X_DC1_CONTROL_1:
0419 case WM831X_DC1_CONTROL_2:
0420 case WM831X_DC1_ON_CONFIG:
0421 case WM831X_DC1_SLEEP_CONTROL:
0422 case WM831X_DC1_DVS_CONTROL:
0423 case WM831X_DC2_CONTROL_1:
0424 case WM831X_DC2_CONTROL_2:
0425 case WM831X_DC2_ON_CONFIG:
0426 case WM831X_DC2_SLEEP_CONTROL:
0427 case WM831X_DC2_DVS_CONTROL:
0428 case WM831X_DC3_CONTROL_1:
0429 case WM831X_DC3_CONTROL_2:
0430 case WM831X_DC3_ON_CONFIG:
0431 case WM831X_DC3_SLEEP_CONTROL:
0432 case WM831X_DC4_CONTROL:
0433 case WM831X_DC4_SLEEP_CONTROL:
0434 case WM831X_EPE1_CONTROL:
0435 case WM831X_EPE2_CONTROL:
0436 case WM831X_LDO1_CONTROL:
0437 case WM831X_LDO1_ON_CONTROL:
0438 case WM831X_LDO1_SLEEP_CONTROL:
0439 case WM831X_LDO2_CONTROL:
0440 case WM831X_LDO2_ON_CONTROL:
0441 case WM831X_LDO2_SLEEP_CONTROL:
0442 case WM831X_LDO3_CONTROL:
0443 case WM831X_LDO3_ON_CONTROL:
0444 case WM831X_LDO3_SLEEP_CONTROL:
0445 case WM831X_LDO4_CONTROL:
0446 case WM831X_LDO4_ON_CONTROL:
0447 case WM831X_LDO4_SLEEP_CONTROL:
0448 case WM831X_LDO5_CONTROL:
0449 case WM831X_LDO5_ON_CONTROL:
0450 case WM831X_LDO5_SLEEP_CONTROL:
0451 case WM831X_LDO6_CONTROL:
0452 case WM831X_LDO6_ON_CONTROL:
0453 case WM831X_LDO6_SLEEP_CONTROL:
0454 case WM831X_LDO7_CONTROL:
0455 case WM831X_LDO7_ON_CONTROL:
0456 case WM831X_LDO7_SLEEP_CONTROL:
0457 case WM831X_LDO8_CONTROL:
0458 case WM831X_LDO8_ON_CONTROL:
0459 case WM831X_LDO8_SLEEP_CONTROL:
0460 case WM831X_LDO9_CONTROL:
0461 case WM831X_LDO9_ON_CONTROL:
0462 case WM831X_LDO9_SLEEP_CONTROL:
0463 case WM831X_LDO10_CONTROL:
0464 case WM831X_LDO10_ON_CONTROL:
0465 case WM831X_LDO10_SLEEP_CONTROL:
0466 case WM831X_LDO11_ON_CONTROL:
0467 case WM831X_LDO11_SLEEP_CONTROL:
0468 case WM831X_POWER_GOOD_SOURCE_1:
0469 case WM831X_POWER_GOOD_SOURCE_2:
0470 case WM831X_CLOCK_CONTROL_1:
0471 case WM831X_CLOCK_CONTROL_2:
0472 case WM831X_FLL_CONTROL_1:
0473 case WM831X_FLL_CONTROL_2:
0474 case WM831X_FLL_CONTROL_3:
0475 case WM831X_FLL_CONTROL_4:
0476 case WM831X_FLL_CONTROL_5:
0477 return true;
0478 default:
0479 return false;
0480 }
0481 }
0482
0483 static bool wm831x_reg_volatile(struct device *dev, unsigned int reg)
0484 {
0485 switch (reg) {
0486 case WM831X_SYSTEM_STATUS:
0487 case WM831X_ON_SOURCE:
0488 case WM831X_OFF_SOURCE:
0489 case WM831X_GPIO_LEVEL:
0490 case WM831X_SYSTEM_INTERRUPTS:
0491 case WM831X_INTERRUPT_STATUS_1:
0492 case WM831X_INTERRUPT_STATUS_2:
0493 case WM831X_INTERRUPT_STATUS_3:
0494 case WM831X_INTERRUPT_STATUS_4:
0495 case WM831X_INTERRUPT_STATUS_5:
0496 case WM831X_RTC_TIME_1:
0497 case WM831X_RTC_TIME_2:
0498 case WM831X_TOUCH_DATA_X:
0499 case WM831X_TOUCH_DATA_Y:
0500 case WM831X_TOUCH_DATA_Z:
0501 case WM831X_AUXADC_DATA:
0502 case WM831X_CHARGER_STATUS:
0503 case WM831X_DCDC_STATUS:
0504 case WM831X_LDO_STATUS:
0505 case WM831X_DCDC_UV_STATUS:
0506 case WM831X_LDO_UV_STATUS:
0507 return true;
0508 default:
0509 return false;
0510 }
0511 }
0512
0513
0514
0515
0516
0517
0518
0519 int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
0520 {
0521 unsigned int val;
0522 int ret;
0523
0524 ret = regmap_read(wm831x->regmap, reg, &val);
0525
0526 if (ret < 0)
0527 return ret;
0528 else
0529 return val;
0530 }
0531 EXPORT_SYMBOL_GPL(wm831x_reg_read);
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541 int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
0542 int count, u16 *buf)
0543 {
0544 return regmap_bulk_read(wm831x->regmap, reg, buf, count);
0545 }
0546 EXPORT_SYMBOL_GPL(wm831x_bulk_read);
0547
0548 static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
0549 int bytes, void *src)
0550 {
0551 u16 *buf = src;
0552 int i, ret;
0553
0554 BUG_ON(bytes % 2);
0555 BUG_ON(bytes <= 0);
0556
0557 for (i = 0; i < bytes / 2; i++) {
0558 if (wm831x_reg_locked(wm831x, reg))
0559 return -EPERM;
0560
0561 dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
0562 buf[i], reg + i, reg + i);
0563 ret = regmap_write(wm831x->regmap, reg + i, buf[i]);
0564 if (ret != 0)
0565 return ret;
0566 }
0567
0568 return 0;
0569 }
0570
0571
0572
0573
0574
0575
0576
0577
0578 int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
0579 unsigned short val)
0580 {
0581 int ret;
0582
0583 mutex_lock(&wm831x->io_lock);
0584
0585 ret = wm831x_write(wm831x, reg, 2, &val);
0586
0587 mutex_unlock(&wm831x->io_lock);
0588
0589 return ret;
0590 }
0591 EXPORT_SYMBOL_GPL(wm831x_reg_write);
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601 int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
0602 unsigned short mask, unsigned short val)
0603 {
0604 int ret;
0605
0606 mutex_lock(&wm831x->io_lock);
0607
0608 if (!wm831x_reg_locked(wm831x, reg))
0609 ret = regmap_update_bits(wm831x->regmap, reg, mask, val);
0610 else
0611 ret = -EPERM;
0612
0613 mutex_unlock(&wm831x->io_lock);
0614
0615 return ret;
0616 }
0617 EXPORT_SYMBOL_GPL(wm831x_set_bits);
0618
0619 static const struct resource wm831x_dcdc1_resources[] = {
0620 {
0621 .start = WM831X_DC1_CONTROL_1,
0622 .end = WM831X_DC1_DVS_CONTROL,
0623 .flags = IORESOURCE_REG,
0624 },
0625 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC1, "UV"),
0626 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_HC_DC1, "HC"),
0627 };
0628
0629
0630 static const struct resource wm831x_dcdc2_resources[] = {
0631 {
0632 .start = WM831X_DC2_CONTROL_1,
0633 .end = WM831X_DC2_DVS_CONTROL,
0634 .flags = IORESOURCE_REG,
0635 },
0636 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC2, "UV"),
0637 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_HC_DC2, "HC"),
0638 };
0639
0640 static const struct resource wm831x_dcdc3_resources[] = {
0641 {
0642 .start = WM831X_DC3_CONTROL_1,
0643 .end = WM831X_DC3_SLEEP_CONTROL,
0644 .flags = IORESOURCE_REG,
0645 },
0646 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC3, "UV"),
0647 };
0648
0649 static const struct resource wm831x_dcdc4_resources[] = {
0650 {
0651 .start = WM831X_DC4_CONTROL,
0652 .end = WM831X_DC4_SLEEP_CONTROL,
0653 .flags = IORESOURCE_REG,
0654 },
0655 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC4, "UV"),
0656 };
0657
0658 static const struct resource wm8320_dcdc4_buck_resources[] = {
0659 {
0660 .start = WM831X_DC4_CONTROL,
0661 .end = WM832X_DC4_SLEEP_CONTROL,
0662 .flags = IORESOURCE_REG,
0663 },
0664 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_DC4, "UV"),
0665 };
0666
0667 static const struct resource wm831x_gpio_resources[] = {
0668 {
0669 .start = WM831X_IRQ_GPIO_1,
0670 .end = WM831X_IRQ_GPIO_16,
0671 .flags = IORESOURCE_IRQ,
0672 },
0673 };
0674
0675 static const struct resource wm831x_isink1_resources[] = {
0676 {
0677 .start = WM831X_CURRENT_SINK_1,
0678 .end = WM831X_CURRENT_SINK_1,
0679 .flags = IORESOURCE_REG,
0680 },
0681 DEFINE_RES_IRQ(WM831X_IRQ_CS1),
0682 };
0683
0684 static const struct resource wm831x_isink2_resources[] = {
0685 {
0686 .start = WM831X_CURRENT_SINK_2,
0687 .end = WM831X_CURRENT_SINK_2,
0688 .flags = IORESOURCE_REG,
0689 },
0690 DEFINE_RES_IRQ(WM831X_IRQ_CS2),
0691 };
0692
0693 static const struct resource wm831x_ldo1_resources[] = {
0694 {
0695 .start = WM831X_LDO1_CONTROL,
0696 .end = WM831X_LDO1_SLEEP_CONTROL,
0697 .flags = IORESOURCE_REG,
0698 },
0699 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO1, "UV"),
0700 };
0701
0702 static const struct resource wm831x_ldo2_resources[] = {
0703 {
0704 .start = WM831X_LDO2_CONTROL,
0705 .end = WM831X_LDO2_SLEEP_CONTROL,
0706 .flags = IORESOURCE_REG,
0707 },
0708 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO2, "UV"),
0709 };
0710
0711 static const struct resource wm831x_ldo3_resources[] = {
0712 {
0713 .start = WM831X_LDO3_CONTROL,
0714 .end = WM831X_LDO3_SLEEP_CONTROL,
0715 .flags = IORESOURCE_REG,
0716 },
0717 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO3, "UV"),
0718 };
0719
0720 static const struct resource wm831x_ldo4_resources[] = {
0721 {
0722 .start = WM831X_LDO4_CONTROL,
0723 .end = WM831X_LDO4_SLEEP_CONTROL,
0724 .flags = IORESOURCE_REG,
0725 },
0726 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO4, "UV"),
0727 };
0728
0729 static const struct resource wm831x_ldo5_resources[] = {
0730 {
0731 .start = WM831X_LDO5_CONTROL,
0732 .end = WM831X_LDO5_SLEEP_CONTROL,
0733 .flags = IORESOURCE_REG,
0734 },
0735 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO5, "UV"),
0736 };
0737
0738 static const struct resource wm831x_ldo6_resources[] = {
0739 {
0740 .start = WM831X_LDO6_CONTROL,
0741 .end = WM831X_LDO6_SLEEP_CONTROL,
0742 .flags = IORESOURCE_REG,
0743 },
0744 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO6, "UV"),
0745 };
0746
0747 static const struct resource wm831x_ldo7_resources[] = {
0748 {
0749 .start = WM831X_LDO7_CONTROL,
0750 .end = WM831X_LDO7_SLEEP_CONTROL,
0751 .flags = IORESOURCE_REG,
0752 },
0753 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO7, "UV"),
0754 };
0755
0756 static const struct resource wm831x_ldo8_resources[] = {
0757 {
0758 .start = WM831X_LDO8_CONTROL,
0759 .end = WM831X_LDO8_SLEEP_CONTROL,
0760 .flags = IORESOURCE_REG,
0761 },
0762 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO8, "UV"),
0763 };
0764
0765 static const struct resource wm831x_ldo9_resources[] = {
0766 {
0767 .start = WM831X_LDO9_CONTROL,
0768 .end = WM831X_LDO9_SLEEP_CONTROL,
0769 .flags = IORESOURCE_REG,
0770 },
0771 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO9, "UV"),
0772 };
0773
0774 static const struct resource wm831x_ldo10_resources[] = {
0775 {
0776 .start = WM831X_LDO10_CONTROL,
0777 .end = WM831X_LDO10_SLEEP_CONTROL,
0778 .flags = IORESOURCE_REG,
0779 },
0780 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_UV_LDO10, "UV"),
0781 };
0782
0783 static const struct resource wm831x_ldo11_resources[] = {
0784 {
0785 .start = WM831X_LDO11_ON_CONTROL,
0786 .end = WM831X_LDO11_SLEEP_CONTROL,
0787 .flags = IORESOURCE_REG,
0788 },
0789 };
0790
0791 static const struct resource wm831x_on_resources[] = {
0792 DEFINE_RES_IRQ(WM831X_IRQ_ON),
0793 };
0794
0795
0796 static const struct resource wm831x_power_resources[] = {
0797 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_PPM_SYSLO, "SYSLO"),
0798 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_PPM_PWR_SRC, "PWR SRC"),
0799 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_PPM_USB_CURR, "USB CURR"),
0800 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_BATT_HOT, "BATT HOT"),
0801 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_BATT_COLD, "BATT COLD"),
0802 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_BATT_FAIL, "BATT FAIL"),
0803 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_OV, "OV"),
0804 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_END, "END"),
0805 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_TO, "TO"),
0806 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_MODE, "MODE"),
0807 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_CHG_START, "START"),
0808 };
0809
0810 static const struct resource wm831x_rtc_resources[] = {
0811 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_RTC_PER, "PER"),
0812 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_RTC_ALM, "ALM"),
0813 };
0814
0815 static const struct resource wm831x_status1_resources[] = {
0816 {
0817 .start = WM831X_STATUS_LED_1,
0818 .end = WM831X_STATUS_LED_1,
0819 .flags = IORESOURCE_REG,
0820 },
0821 };
0822
0823 static const struct resource wm831x_status2_resources[] = {
0824 {
0825 .start = WM831X_STATUS_LED_2,
0826 .end = WM831X_STATUS_LED_2,
0827 .flags = IORESOURCE_REG,
0828 },
0829 };
0830
0831 static const struct resource wm831x_touch_resources[] = {
0832 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_TCHPD, "TCHPD"),
0833 DEFINE_RES_IRQ_NAMED(WM831X_IRQ_TCHDATA, "TCHDATA"),
0834 };
0835
0836 static const struct resource wm831x_wdt_resources[] = {
0837 DEFINE_RES_IRQ(WM831X_IRQ_WDOG_TO),
0838 };
0839
0840 static const struct mfd_cell wm8310_devs[] = {
0841 {
0842 .name = "wm831x-backup",
0843 },
0844 {
0845 .name = "wm831x-buckv",
0846 .id = 1,
0847 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
0848 .resources = wm831x_dcdc1_resources,
0849 },
0850 {
0851 .name = "wm831x-buckv",
0852 .id = 2,
0853 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
0854 .resources = wm831x_dcdc2_resources,
0855 },
0856 {
0857 .name = "wm831x-buckp",
0858 .id = 3,
0859 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
0860 .resources = wm831x_dcdc3_resources,
0861 },
0862 {
0863 .name = "wm831x-boostp",
0864 .id = 4,
0865 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
0866 .resources = wm831x_dcdc4_resources,
0867 },
0868 {
0869 .name = "wm831x-clk",
0870 },
0871 {
0872 .name = "wm831x-epe",
0873 .id = 1,
0874 },
0875 {
0876 .name = "wm831x-epe",
0877 .id = 2,
0878 },
0879 {
0880 .name = "wm831x-gpio",
0881 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
0882 .resources = wm831x_gpio_resources,
0883 },
0884 {
0885 .name = "wm831x-hwmon",
0886 },
0887 {
0888 .name = "wm831x-isink",
0889 .id = 1,
0890 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
0891 .resources = wm831x_isink1_resources,
0892 },
0893 {
0894 .name = "wm831x-isink",
0895 .id = 2,
0896 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
0897 .resources = wm831x_isink2_resources,
0898 },
0899 {
0900 .name = "wm831x-ldo",
0901 .id = 1,
0902 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
0903 .resources = wm831x_ldo1_resources,
0904 },
0905 {
0906 .name = "wm831x-ldo",
0907 .id = 2,
0908 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
0909 .resources = wm831x_ldo2_resources,
0910 },
0911 {
0912 .name = "wm831x-ldo",
0913 .id = 3,
0914 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
0915 .resources = wm831x_ldo3_resources,
0916 },
0917 {
0918 .name = "wm831x-ldo",
0919 .id = 4,
0920 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
0921 .resources = wm831x_ldo4_resources,
0922 },
0923 {
0924 .name = "wm831x-ldo",
0925 .id = 5,
0926 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
0927 .resources = wm831x_ldo5_resources,
0928 },
0929 {
0930 .name = "wm831x-ldo",
0931 .id = 6,
0932 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
0933 .resources = wm831x_ldo6_resources,
0934 },
0935 {
0936 .name = "wm831x-aldo",
0937 .id = 7,
0938 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
0939 .resources = wm831x_ldo7_resources,
0940 },
0941 {
0942 .name = "wm831x-aldo",
0943 .id = 8,
0944 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
0945 .resources = wm831x_ldo8_resources,
0946 },
0947 {
0948 .name = "wm831x-aldo",
0949 .id = 9,
0950 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
0951 .resources = wm831x_ldo9_resources,
0952 },
0953 {
0954 .name = "wm831x-aldo",
0955 .id = 10,
0956 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
0957 .resources = wm831x_ldo10_resources,
0958 },
0959 {
0960 .name = "wm831x-alive-ldo",
0961 .id = 11,
0962 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
0963 .resources = wm831x_ldo11_resources,
0964 },
0965 {
0966 .name = "wm831x-on",
0967 .num_resources = ARRAY_SIZE(wm831x_on_resources),
0968 .resources = wm831x_on_resources,
0969 },
0970 {
0971 .name = "wm831x-power",
0972 .num_resources = ARRAY_SIZE(wm831x_power_resources),
0973 .resources = wm831x_power_resources,
0974 },
0975 {
0976 .name = "wm831x-status",
0977 .id = 1,
0978 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
0979 .resources = wm831x_status1_resources,
0980 },
0981 {
0982 .name = "wm831x-status",
0983 .id = 2,
0984 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
0985 .resources = wm831x_status2_resources,
0986 },
0987 {
0988 .name = "wm831x-watchdog",
0989 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
0990 .resources = wm831x_wdt_resources,
0991 },
0992 };
0993
0994 static const struct mfd_cell wm8311_devs[] = {
0995 {
0996 .name = "wm831x-backup",
0997 },
0998 {
0999 .name = "wm831x-buckv",
1000 .id = 1,
1001 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1002 .resources = wm831x_dcdc1_resources,
1003 },
1004 {
1005 .name = "wm831x-buckv",
1006 .id = 2,
1007 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1008 .resources = wm831x_dcdc2_resources,
1009 },
1010 {
1011 .name = "wm831x-buckp",
1012 .id = 3,
1013 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1014 .resources = wm831x_dcdc3_resources,
1015 },
1016 {
1017 .name = "wm831x-boostp",
1018 .id = 4,
1019 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
1020 .resources = wm831x_dcdc4_resources,
1021 },
1022 {
1023 .name = "wm831x-clk",
1024 },
1025 {
1026 .name = "wm831x-epe",
1027 .id = 1,
1028 },
1029 {
1030 .name = "wm831x-epe",
1031 .id = 2,
1032 },
1033 {
1034 .name = "wm831x-gpio",
1035 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1036 .resources = wm831x_gpio_resources,
1037 },
1038 {
1039 .name = "wm831x-hwmon",
1040 },
1041 {
1042 .name = "wm831x-isink",
1043 .id = 1,
1044 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
1045 .resources = wm831x_isink1_resources,
1046 },
1047 {
1048 .name = "wm831x-isink",
1049 .id = 2,
1050 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
1051 .resources = wm831x_isink2_resources,
1052 },
1053 {
1054 .name = "wm831x-ldo",
1055 .id = 1,
1056 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1057 .resources = wm831x_ldo1_resources,
1058 },
1059 {
1060 .name = "wm831x-ldo",
1061 .id = 2,
1062 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1063 .resources = wm831x_ldo2_resources,
1064 },
1065 {
1066 .name = "wm831x-ldo",
1067 .id = 3,
1068 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1069 .resources = wm831x_ldo3_resources,
1070 },
1071 {
1072 .name = "wm831x-ldo",
1073 .id = 4,
1074 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1075 .resources = wm831x_ldo4_resources,
1076 },
1077 {
1078 .name = "wm831x-ldo",
1079 .id = 5,
1080 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1081 .resources = wm831x_ldo5_resources,
1082 },
1083 {
1084 .name = "wm831x-aldo",
1085 .id = 7,
1086 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1087 .resources = wm831x_ldo7_resources,
1088 },
1089 {
1090 .name = "wm831x-alive-ldo",
1091 .id = 11,
1092 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1093 .resources = wm831x_ldo11_resources,
1094 },
1095 {
1096 .name = "wm831x-on",
1097 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1098 .resources = wm831x_on_resources,
1099 },
1100 {
1101 .name = "wm831x-power",
1102 .num_resources = ARRAY_SIZE(wm831x_power_resources),
1103 .resources = wm831x_power_resources,
1104 },
1105 {
1106 .name = "wm831x-status",
1107 .id = 1,
1108 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1109 .resources = wm831x_status1_resources,
1110 },
1111 {
1112 .name = "wm831x-status",
1113 .id = 2,
1114 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1115 .resources = wm831x_status2_resources,
1116 },
1117 {
1118 .name = "wm831x-watchdog",
1119 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1120 .resources = wm831x_wdt_resources,
1121 },
1122 };
1123
1124 static const struct mfd_cell wm8312_devs[] = {
1125 {
1126 .name = "wm831x-backup",
1127 },
1128 {
1129 .name = "wm831x-buckv",
1130 .id = 1,
1131 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1132 .resources = wm831x_dcdc1_resources,
1133 },
1134 {
1135 .name = "wm831x-buckv",
1136 .id = 2,
1137 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1138 .resources = wm831x_dcdc2_resources,
1139 },
1140 {
1141 .name = "wm831x-buckp",
1142 .id = 3,
1143 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1144 .resources = wm831x_dcdc3_resources,
1145 },
1146 {
1147 .name = "wm831x-boostp",
1148 .id = 4,
1149 .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
1150 .resources = wm831x_dcdc4_resources,
1151 },
1152 {
1153 .name = "wm831x-clk",
1154 },
1155 {
1156 .name = "wm831x-epe",
1157 .id = 1,
1158 },
1159 {
1160 .name = "wm831x-epe",
1161 .id = 2,
1162 },
1163 {
1164 .name = "wm831x-gpio",
1165 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1166 .resources = wm831x_gpio_resources,
1167 },
1168 {
1169 .name = "wm831x-hwmon",
1170 },
1171 {
1172 .name = "wm831x-isink",
1173 .id = 1,
1174 .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
1175 .resources = wm831x_isink1_resources,
1176 },
1177 {
1178 .name = "wm831x-isink",
1179 .id = 2,
1180 .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
1181 .resources = wm831x_isink2_resources,
1182 },
1183 {
1184 .name = "wm831x-ldo",
1185 .id = 1,
1186 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1187 .resources = wm831x_ldo1_resources,
1188 },
1189 {
1190 .name = "wm831x-ldo",
1191 .id = 2,
1192 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1193 .resources = wm831x_ldo2_resources,
1194 },
1195 {
1196 .name = "wm831x-ldo",
1197 .id = 3,
1198 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1199 .resources = wm831x_ldo3_resources,
1200 },
1201 {
1202 .name = "wm831x-ldo",
1203 .id = 4,
1204 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1205 .resources = wm831x_ldo4_resources,
1206 },
1207 {
1208 .name = "wm831x-ldo",
1209 .id = 5,
1210 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1211 .resources = wm831x_ldo5_resources,
1212 },
1213 {
1214 .name = "wm831x-ldo",
1215 .id = 6,
1216 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
1217 .resources = wm831x_ldo6_resources,
1218 },
1219 {
1220 .name = "wm831x-aldo",
1221 .id = 7,
1222 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1223 .resources = wm831x_ldo7_resources,
1224 },
1225 {
1226 .name = "wm831x-aldo",
1227 .id = 8,
1228 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
1229 .resources = wm831x_ldo8_resources,
1230 },
1231 {
1232 .name = "wm831x-aldo",
1233 .id = 9,
1234 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
1235 .resources = wm831x_ldo9_resources,
1236 },
1237 {
1238 .name = "wm831x-aldo",
1239 .id = 10,
1240 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
1241 .resources = wm831x_ldo10_resources,
1242 },
1243 {
1244 .name = "wm831x-alive-ldo",
1245 .id = 11,
1246 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1247 .resources = wm831x_ldo11_resources,
1248 },
1249 {
1250 .name = "wm831x-on",
1251 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1252 .resources = wm831x_on_resources,
1253 },
1254 {
1255 .name = "wm831x-power",
1256 .num_resources = ARRAY_SIZE(wm831x_power_resources),
1257 .resources = wm831x_power_resources,
1258 },
1259 {
1260 .name = "wm831x-status",
1261 .id = 1,
1262 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1263 .resources = wm831x_status1_resources,
1264 },
1265 {
1266 .name = "wm831x-status",
1267 .id = 2,
1268 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1269 .resources = wm831x_status2_resources,
1270 },
1271 {
1272 .name = "wm831x-watchdog",
1273 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1274 .resources = wm831x_wdt_resources,
1275 },
1276 };
1277
1278 static const struct mfd_cell wm8320_devs[] = {
1279 {
1280 .name = "wm831x-backup",
1281 },
1282 {
1283 .name = "wm831x-buckv",
1284 .id = 1,
1285 .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
1286 .resources = wm831x_dcdc1_resources,
1287 },
1288 {
1289 .name = "wm831x-buckv",
1290 .id = 2,
1291 .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
1292 .resources = wm831x_dcdc2_resources,
1293 },
1294 {
1295 .name = "wm831x-buckp",
1296 .id = 3,
1297 .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
1298 .resources = wm831x_dcdc3_resources,
1299 },
1300 {
1301 .name = "wm831x-buckp",
1302 .id = 4,
1303 .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
1304 .resources = wm8320_dcdc4_buck_resources,
1305 },
1306 {
1307 .name = "wm831x-clk",
1308 },
1309 {
1310 .name = "wm831x-gpio",
1311 .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
1312 .resources = wm831x_gpio_resources,
1313 },
1314 {
1315 .name = "wm831x-hwmon",
1316 },
1317 {
1318 .name = "wm831x-ldo",
1319 .id = 1,
1320 .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
1321 .resources = wm831x_ldo1_resources,
1322 },
1323 {
1324 .name = "wm831x-ldo",
1325 .id = 2,
1326 .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
1327 .resources = wm831x_ldo2_resources,
1328 },
1329 {
1330 .name = "wm831x-ldo",
1331 .id = 3,
1332 .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
1333 .resources = wm831x_ldo3_resources,
1334 },
1335 {
1336 .name = "wm831x-ldo",
1337 .id = 4,
1338 .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
1339 .resources = wm831x_ldo4_resources,
1340 },
1341 {
1342 .name = "wm831x-ldo",
1343 .id = 5,
1344 .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
1345 .resources = wm831x_ldo5_resources,
1346 },
1347 {
1348 .name = "wm831x-ldo",
1349 .id = 6,
1350 .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
1351 .resources = wm831x_ldo6_resources,
1352 },
1353 {
1354 .name = "wm831x-aldo",
1355 .id = 7,
1356 .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
1357 .resources = wm831x_ldo7_resources,
1358 },
1359 {
1360 .name = "wm831x-aldo",
1361 .id = 8,
1362 .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
1363 .resources = wm831x_ldo8_resources,
1364 },
1365 {
1366 .name = "wm831x-aldo",
1367 .id = 9,
1368 .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
1369 .resources = wm831x_ldo9_resources,
1370 },
1371 {
1372 .name = "wm831x-aldo",
1373 .id = 10,
1374 .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
1375 .resources = wm831x_ldo10_resources,
1376 },
1377 {
1378 .name = "wm831x-alive-ldo",
1379 .id = 11,
1380 .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
1381 .resources = wm831x_ldo11_resources,
1382 },
1383 {
1384 .name = "wm831x-on",
1385 .num_resources = ARRAY_SIZE(wm831x_on_resources),
1386 .resources = wm831x_on_resources,
1387 },
1388 {
1389 .name = "wm831x-status",
1390 .id = 1,
1391 .num_resources = ARRAY_SIZE(wm831x_status1_resources),
1392 .resources = wm831x_status1_resources,
1393 },
1394 {
1395 .name = "wm831x-status",
1396 .id = 2,
1397 .num_resources = ARRAY_SIZE(wm831x_status2_resources),
1398 .resources = wm831x_status2_resources,
1399 },
1400 {
1401 .name = "wm831x-watchdog",
1402 .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
1403 .resources = wm831x_wdt_resources,
1404 },
1405 };
1406
1407 static const struct mfd_cell touch_devs[] = {
1408 {
1409 .name = "wm831x-touch",
1410 .num_resources = ARRAY_SIZE(wm831x_touch_resources),
1411 .resources = wm831x_touch_resources,
1412 },
1413 };
1414
1415 static const struct mfd_cell rtc_devs[] = {
1416 {
1417 .name = "wm831x-rtc",
1418 .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
1419 .resources = wm831x_rtc_resources,
1420 },
1421 };
1422
1423 static const struct mfd_cell backlight_devs[] = {
1424 {
1425 .name = "wm831x-backlight",
1426 },
1427 };
1428
1429 struct regmap_config wm831x_regmap_config = {
1430 .reg_bits = 16,
1431 .val_bits = 16,
1432
1433 .cache_type = REGCACHE_RBTREE,
1434
1435 .max_register = WM831X_DBE_CHECK_DATA,
1436 .readable_reg = wm831x_reg_readable,
1437 .writeable_reg = wm831x_reg_writeable,
1438 .volatile_reg = wm831x_reg_volatile,
1439 };
1440 EXPORT_SYMBOL_GPL(wm831x_regmap_config);
1441
1442 const struct of_device_id wm831x_of_match[] = {
1443 { .compatible = "wlf,wm8310", .data = (void *)WM8310 },
1444 { .compatible = "wlf,wm8311", .data = (void *)WM8311 },
1445 { .compatible = "wlf,wm8312", .data = (void *)WM8312 },
1446 { .compatible = "wlf,wm8320", .data = (void *)WM8320 },
1447 { .compatible = "wlf,wm8321", .data = (void *)WM8321 },
1448 { .compatible = "wlf,wm8325", .data = (void *)WM8325 },
1449 { .compatible = "wlf,wm8326", .data = (void *)WM8326 },
1450 { },
1451 };
1452 EXPORT_SYMBOL_GPL(wm831x_of_match);
1453
1454
1455
1456
1457 int wm831x_device_init(struct wm831x *wm831x, int irq)
1458 {
1459 struct wm831x_pdata *pdata = &wm831x->pdata;
1460 int rev, wm831x_num;
1461 enum wm831x_parent parent;
1462 int ret, i;
1463
1464 mutex_init(&wm831x->io_lock);
1465 mutex_init(&wm831x->key_lock);
1466 dev_set_drvdata(wm831x->dev, wm831x);
1467
1468 wm831x->soft_shutdown = pdata->soft_shutdown;
1469
1470 ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
1471 if (ret < 0) {
1472 dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
1473 goto err;
1474 }
1475 switch (ret) {
1476 case 0x6204:
1477 case 0x6246:
1478 break;
1479 default:
1480 dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
1481 ret = -EINVAL;
1482 goto err;
1483 }
1484
1485 ret = wm831x_reg_read(wm831x, WM831X_REVISION);
1486 if (ret < 0) {
1487 dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
1488 goto err;
1489 }
1490 rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
1491
1492 ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
1493 if (ret < 0) {
1494 dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
1495 goto err;
1496 }
1497
1498
1499
1500
1501 if (ret == 0) {
1502 dev_info(wm831x->dev, "Device is an engineering sample\n");
1503 ret = wm831x->type;
1504 }
1505
1506 switch (ret) {
1507 case WM8310:
1508 parent = WM8310;
1509 wm831x->num_gpio = 16;
1510 wm831x->charger_irq_wake = 1;
1511 if (rev > 0) {
1512 wm831x->has_gpio_ena = 1;
1513 wm831x->has_cs_sts = 1;
1514 }
1515
1516 dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
1517 break;
1518
1519 case WM8311:
1520 parent = WM8311;
1521 wm831x->num_gpio = 16;
1522 wm831x->charger_irq_wake = 1;
1523 if (rev > 0) {
1524 wm831x->has_gpio_ena = 1;
1525 wm831x->has_cs_sts = 1;
1526 }
1527
1528 dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
1529 break;
1530
1531 case WM8312:
1532 parent = WM8312;
1533 wm831x->num_gpio = 16;
1534 wm831x->charger_irq_wake = 1;
1535 if (rev > 0) {
1536 wm831x->has_gpio_ena = 1;
1537 wm831x->has_cs_sts = 1;
1538 }
1539
1540 dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
1541 break;
1542
1543 case WM8320:
1544 parent = WM8320;
1545 wm831x->num_gpio = 12;
1546 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
1547 break;
1548
1549 case WM8321:
1550 parent = WM8321;
1551 wm831x->num_gpio = 12;
1552 dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
1553 break;
1554
1555 case WM8325:
1556 parent = WM8325;
1557 wm831x->num_gpio = 12;
1558 dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
1559 break;
1560
1561 case WM8326:
1562 parent = WM8326;
1563 wm831x->num_gpio = 12;
1564 dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
1565 break;
1566
1567 default:
1568 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1569 ret = -EINVAL;
1570 goto err;
1571 }
1572
1573
1574
1575
1576 if (parent != wm831x->type)
1577 dev_warn(wm831x->dev, "Device was registered as a WM%x\n",
1578 wm831x->type);
1579
1580
1581 ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
1582 if (ret < 0) {
1583 dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
1584 goto err;
1585 }
1586 if (ret != 0) {
1587 dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
1588 ret);
1589 wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
1590 }
1591 wm831x->locked = 1;
1592
1593 if (pdata->pre_init) {
1594 ret = pdata->pre_init(wm831x);
1595 if (ret != 0) {
1596 dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
1597 goto err;
1598 }
1599 }
1600
1601 for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
1602 if (!pdata->gpio_defaults[i])
1603 continue;
1604
1605 wm831x_reg_write(wm831x,
1606 WM831X_GPIO1_CONTROL + i,
1607 pdata->gpio_defaults[i] & 0xffff);
1608 }
1609
1610
1611 if (pdata->wm831x_num)
1612 wm831x_num = pdata->wm831x_num * 10;
1613 else
1614 wm831x_num = -1;
1615
1616 ret = wm831x_irq_init(wm831x, irq);
1617 if (ret != 0)
1618 goto err;
1619
1620 wm831x_auxadc_init(wm831x);
1621
1622
1623 switch (parent) {
1624 case WM8310:
1625 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1626 wm8310_devs, ARRAY_SIZE(wm8310_devs),
1627 NULL, 0, NULL);
1628 break;
1629
1630 case WM8311:
1631 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1632 wm8311_devs, ARRAY_SIZE(wm8311_devs),
1633 NULL, 0, NULL);
1634 if (!pdata->disable_touch)
1635 mfd_add_devices(wm831x->dev, wm831x_num,
1636 touch_devs, ARRAY_SIZE(touch_devs),
1637 NULL, 0, NULL);
1638 break;
1639
1640 case WM8312:
1641 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1642 wm8312_devs, ARRAY_SIZE(wm8312_devs),
1643 NULL, 0, NULL);
1644 if (!pdata->disable_touch)
1645 mfd_add_devices(wm831x->dev, wm831x_num,
1646 touch_devs, ARRAY_SIZE(touch_devs),
1647 NULL, 0, NULL);
1648 break;
1649
1650 case WM8320:
1651 case WM8321:
1652 case WM8325:
1653 case WM8326:
1654 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1655 wm8320_devs, ARRAY_SIZE(wm8320_devs),
1656 NULL, 0, NULL);
1657 break;
1658
1659 default:
1660
1661 BUG();
1662 }
1663
1664 if (ret != 0) {
1665 dev_err(wm831x->dev, "Failed to add children\n");
1666 goto err_irq;
1667 }
1668
1669
1670
1671
1672 ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
1673 if (ret < 0) {
1674 dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret);
1675 goto err_irq;
1676 }
1677
1678 if (ret & WM831X_XTAL_ENA) {
1679 ret = mfd_add_devices(wm831x->dev, wm831x_num,
1680 rtc_devs, ARRAY_SIZE(rtc_devs),
1681 NULL, 0, NULL);
1682 if (ret != 0) {
1683 dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
1684 goto err_irq;
1685 }
1686 } else {
1687 dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n");
1688 }
1689
1690 if (pdata->backlight) {
1691
1692 ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
1693 ARRAY_SIZE(backlight_devs), NULL,
1694 0, NULL);
1695 if (ret < 0)
1696 dev_err(wm831x->dev, "Failed to add backlight: %d\n",
1697 ret);
1698 }
1699
1700 wm831x_otp_init(wm831x);
1701
1702 if (pdata->post_init) {
1703 ret = pdata->post_init(wm831x);
1704 if (ret != 0) {
1705 dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
1706 goto err_irq;
1707 }
1708 }
1709
1710 return 0;
1711
1712 err_irq:
1713 wm831x_irq_exit(wm831x);
1714 err:
1715 mfd_remove_devices(wm831x->dev);
1716 return ret;
1717 }
1718
1719 int wm831x_device_suspend(struct wm831x *wm831x)
1720 {
1721 int reg, mask;
1722
1723
1724
1725
1726
1727
1728 if (wm831x->charger_irq_wake) {
1729 reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
1730
1731 mask = WM831X_CHG_BATT_HOT_EINT |
1732 WM831X_CHG_BATT_COLD_EINT |
1733 WM831X_CHG_BATT_FAIL_EINT |
1734 WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
1735 WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
1736 WM831X_CHG_START_EINT;
1737
1738
1739 if (reg & mask)
1740 reg = wm831x_reg_read(wm831x,
1741 WM831X_INTERRUPT_STATUS_2);
1742
1743 if (reg & mask) {
1744 dev_info(wm831x->dev,
1745 "Acknowledging masked charger IRQs: %x\n",
1746 reg & mask);
1747 wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
1748 reg & mask);
1749 }
1750 }
1751
1752 return 0;
1753 }
1754
1755 void wm831x_device_shutdown(struct wm831x *wm831x)
1756 {
1757 if (wm831x->soft_shutdown) {
1758 dev_info(wm831x->dev, "Initiating shutdown...\n");
1759 wm831x_set_bits(wm831x, WM831X_POWER_STATE, WM831X_CHIP_ON, 0);
1760 }
1761 }
1762 EXPORT_SYMBOL_GPL(wm831x_device_shutdown);