12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121 |
- /*
- * Regulator device driver for DA9061 and DA9062.
- * Copyright (C) 2015-2017 Dialog Semiconductor
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/err.h>
- #include <linux/slab.h>
- #include <linux/of.h>
- #include <linux/platform_device.h>
- #include <linux/regmap.h>
- #include <linux/regulator/driver.h>
- #include <linux/regulator/machine.h>
- #include <linux/regulator/of_regulator.h>
- #include <linux/mfd/da9062/core.h>
- #include <linux/mfd/da9062/registers.h>
- /* Regulator IDs */
- enum {
- DA9061_ID_BUCK1,
- DA9061_ID_BUCK2,
- DA9061_ID_BUCK3,
- DA9061_ID_LDO1,
- DA9061_ID_LDO2,
- DA9061_ID_LDO3,
- DA9061_ID_LDO4,
- DA9061_MAX_REGULATORS,
- };
- enum {
- DA9062_ID_BUCK1,
- DA9062_ID_BUCK2,
- DA9062_ID_BUCK3,
- DA9062_ID_BUCK4,
- DA9062_ID_LDO1,
- DA9062_ID_LDO2,
- DA9062_ID_LDO3,
- DA9062_ID_LDO4,
- DA9062_MAX_REGULATORS,
- };
- /* Regulator capabilities and registers description */
- struct da9062_regulator_info {
- struct regulator_desc desc;
- /* Current limiting */
- unsigned int n_current_limits;
- const int *current_limits;
- /* Main register fields */
- struct reg_field mode;
- struct reg_field suspend;
- struct reg_field sleep;
- struct reg_field suspend_sleep;
- unsigned int suspend_vsel_reg;
- struct reg_field ilimit;
- /* Event detection bit */
- struct reg_field oc_event;
- };
- /* Single regulator settings */
- struct da9062_regulator {
- struct regulator_desc desc;
- struct regulator_dev *rdev;
- struct da9062 *hw;
- const struct da9062_regulator_info *info;
- struct regmap_field *mode;
- struct regmap_field *suspend;
- struct regmap_field *sleep;
- struct regmap_field *suspend_sleep;
- struct regmap_field *ilimit;
- };
- /* Encapsulates all information for the regulators driver */
- struct da9062_regulators {
- int irq_ldo_lim;
- unsigned n_regulators;
- /* Array size to be defined during init. Keep at end. */
- struct da9062_regulator regulator[0];
- };
- /* BUCK modes */
- enum {
- BUCK_MODE_MANUAL, /* 0 */
- BUCK_MODE_SLEEP, /* 1 */
- BUCK_MODE_SYNC, /* 2 */
- BUCK_MODE_AUTO /* 3 */
- };
- /* Regulator operations */
- /* Current limits array (in uA)
- * - DA9061_ID_[BUCK1|BUCK3]
- * - DA9062_ID_[BUCK1|BUCK2|BUCK4]
- * Entry indexes corresponds to register values.
- */
- static const int da9062_buck_a_limits[] = {
- 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
- 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
- };
- /* Current limits array (in uA)
- * - DA9061_ID_BUCK2
- * - DA9062_ID_BUCK3
- * Entry indexes corresponds to register values.
- */
- static const int da9062_buck_b_limits[] = {
- 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
- 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
- };
- static int da9062_set_current_limit(struct regulator_dev *rdev,
- int min_ua, int max_ua)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- const struct da9062_regulator_info *rinfo = regl->info;
- int n, tval;
- for (n = 0; n < rinfo->n_current_limits; n++) {
- tval = rinfo->current_limits[n];
- if (tval >= min_ua && tval <= max_ua)
- return regmap_field_write(regl->ilimit, n);
- }
- return -EINVAL;
- }
- static int da9062_get_current_limit(struct regulator_dev *rdev)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- const struct da9062_regulator_info *rinfo = regl->info;
- unsigned int sel;
- int ret;
- ret = regmap_field_read(regl->ilimit, &sel);
- if (ret < 0)
- return ret;
- if (sel >= rinfo->n_current_limits)
- sel = rinfo->n_current_limits - 1;
- return rinfo->current_limits[sel];
- }
- static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- unsigned val;
- switch (mode) {
- case REGULATOR_MODE_FAST:
- val = BUCK_MODE_SYNC;
- break;
- case REGULATOR_MODE_NORMAL:
- val = BUCK_MODE_AUTO;
- break;
- case REGULATOR_MODE_STANDBY:
- val = BUCK_MODE_SLEEP;
- break;
- default:
- return -EINVAL;
- }
- return regmap_field_write(regl->mode, val);
- }
- /*
- * Bucks use single mode register field for normal operation
- * and suspend state.
- * There are 3 modes to map to: FAST, NORMAL, and STANDBY.
- */
- static unsigned da9062_buck_get_mode(struct regulator_dev *rdev)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- struct regmap_field *field;
- unsigned int val, mode = 0;
- int ret;
- ret = regmap_field_read(regl->mode, &val);
- if (ret < 0)
- return ret;
- switch (val) {
- default:
- case BUCK_MODE_MANUAL:
- mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
- /* Sleep flag bit decides the mode */
- break;
- case BUCK_MODE_SLEEP:
- return REGULATOR_MODE_STANDBY;
- case BUCK_MODE_SYNC:
- return REGULATOR_MODE_FAST;
- case BUCK_MODE_AUTO:
- return REGULATOR_MODE_NORMAL;
- }
- /* Detect current regulator state */
- ret = regmap_field_read(regl->suspend, &val);
- if (ret < 0)
- return 0;
- /* Read regulator mode from proper register, depending on state */
- if (val)
- field = regl->suspend_sleep;
- else
- field = regl->sleep;
- ret = regmap_field_read(field, &val);
- if (ret < 0)
- return 0;
- if (val)
- mode &= REGULATOR_MODE_STANDBY;
- else
- mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
- return mode;
- }
- /*
- * LDOs use sleep flags - one for normal and one for suspend state.
- * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.
- */
- static int da9062_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- unsigned val;
- switch (mode) {
- case REGULATOR_MODE_NORMAL:
- val = 0;
- break;
- case REGULATOR_MODE_STANDBY:
- val = 1;
- break;
- default:
- return -EINVAL;
- }
- return regmap_field_write(regl->sleep, val);
- }
- static unsigned da9062_ldo_get_mode(struct regulator_dev *rdev)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- struct regmap_field *field;
- int ret, val;
- /* Detect current regulator state */
- ret = regmap_field_read(regl->suspend, &val);
- if (ret < 0)
- return 0;
- /* Read regulator mode from proper register, depending on state */
- if (val)
- field = regl->suspend_sleep;
- else
- field = regl->sleep;
- ret = regmap_field_read(field, &val);
- if (ret < 0)
- return 0;
- if (val)
- return REGULATOR_MODE_STANDBY;
- else
- return REGULATOR_MODE_NORMAL;
- }
- static int da9062_buck_get_status(struct regulator_dev *rdev)
- {
- int ret = regulator_is_enabled_regmap(rdev);
- if (ret == 0) {
- ret = REGULATOR_STATUS_OFF;
- } else if (ret > 0) {
- ret = da9062_buck_get_mode(rdev);
- if (ret > 0)
- ret = regulator_mode_to_status(ret);
- else if (ret == 0)
- ret = -EIO;
- }
- return ret;
- }
- static int da9062_ldo_get_status(struct regulator_dev *rdev)
- {
- int ret = regulator_is_enabled_regmap(rdev);
- if (ret == 0) {
- ret = REGULATOR_STATUS_OFF;
- } else if (ret > 0) {
- ret = da9062_ldo_get_mode(rdev);
- if (ret > 0)
- ret = regulator_mode_to_status(ret);
- else if (ret == 0)
- ret = -EIO;
- }
- return ret;
- }
- static int da9062_set_suspend_voltage(struct regulator_dev *rdev, int uv)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- const struct da9062_regulator_info *rinfo = regl->info;
- int ret, sel;
- sel = regulator_map_voltage_linear(rdev, uv, uv);
- if (sel < 0)
- return sel;
- sel <<= ffs(rdev->desc->vsel_mask) - 1;
- ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg,
- rdev->desc->vsel_mask, sel);
- return ret;
- }
- static int da9062_suspend_enable(struct regulator_dev *rdev)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- return regmap_field_write(regl->suspend, 1);
- }
- static int da9062_suspend_disable(struct regulator_dev *rdev)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- return regmap_field_write(regl->suspend, 0);
- }
- static int da9062_buck_set_suspend_mode(struct regulator_dev *rdev,
- unsigned mode)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- int val;
- switch (mode) {
- case REGULATOR_MODE_FAST:
- val = BUCK_MODE_SYNC;
- break;
- case REGULATOR_MODE_NORMAL:
- val = BUCK_MODE_AUTO;
- break;
- case REGULATOR_MODE_STANDBY:
- val = BUCK_MODE_SLEEP;
- break;
- default:
- return -EINVAL;
- }
- return regmap_field_write(regl->mode, val);
- }
- static int da9062_ldo_set_suspend_mode(struct regulator_dev *rdev,
- unsigned mode)
- {
- struct da9062_regulator *regl = rdev_get_drvdata(rdev);
- unsigned val;
- switch (mode) {
- case REGULATOR_MODE_NORMAL:
- val = 0;
- break;
- case REGULATOR_MODE_STANDBY:
- val = 1;
- break;
- default:
- return -EINVAL;
- }
- return regmap_field_write(regl->suspend_sleep, val);
- }
- static const struct regulator_ops da9062_buck_ops = {
- .enable = regulator_enable_regmap,
- .disable = regulator_disable_regmap,
- .is_enabled = regulator_is_enabled_regmap,
- .get_voltage_sel = regulator_get_voltage_sel_regmap,
- .set_voltage_sel = regulator_set_voltage_sel_regmap,
- .list_voltage = regulator_list_voltage_linear,
- .set_current_limit = da9062_set_current_limit,
- .get_current_limit = da9062_get_current_limit,
- .set_mode = da9062_buck_set_mode,
- .get_mode = da9062_buck_get_mode,
- .get_status = da9062_buck_get_status,
- .set_suspend_voltage = da9062_set_suspend_voltage,
- .set_suspend_enable = da9062_suspend_enable,
- .set_suspend_disable = da9062_suspend_disable,
- .set_suspend_mode = da9062_buck_set_suspend_mode,
- };
- static const struct regulator_ops da9062_ldo_ops = {
- .enable = regulator_enable_regmap,
- .disable = regulator_disable_regmap,
- .is_enabled = regulator_is_enabled_regmap,
- .get_voltage_sel = regulator_get_voltage_sel_regmap,
- .set_voltage_sel = regulator_set_voltage_sel_regmap,
- .list_voltage = regulator_list_voltage_linear,
- .set_mode = da9062_ldo_set_mode,
- .get_mode = da9062_ldo_get_mode,
- .get_status = da9062_ldo_get_status,
- .set_suspend_voltage = da9062_set_suspend_voltage,
- .set_suspend_enable = da9062_suspend_enable,
- .set_suspend_disable = da9062_suspend_disable,
- .set_suspend_mode = da9062_ldo_set_suspend_mode,
- };
- /* DA9061 Regulator information */
- static const struct da9062_regulator_info local_da9061_regulator_info[] = {
- {
- .desc.id = DA9061_ID_BUCK1,
- .desc.name = "DA9061 BUCK1",
- .desc.of_match = of_match_ptr("buck1"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (300) * 1000,
- .desc.uV_step = (10) * 1000,
- .desc.n_voltages = ((1570) - (300))/(10) + 1,
- .current_limits = da9062_buck_a_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
- .desc.enable_reg = DA9062AA_BUCK1_CONT,
- .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK1_A,
- .desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK1_A,
- __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK1_B,
- __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK1_B,
- .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
- __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
- __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9061_ID_BUCK2,
- .desc.name = "DA9061 BUCK2",
- .desc.of_match = of_match_ptr("buck2"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (800) * 1000,
- .desc.uV_step = (20) * 1000,
- .desc.n_voltages = ((3340) - (800))/(20) + 1,
- .current_limits = da9062_buck_b_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
- .desc.enable_reg = DA9062AA_BUCK3_CONT,
- .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK3_A,
- .desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK3_A,
- __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK3_B,
- __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK3_B,
- .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
- __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
- __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9061_ID_BUCK3,
- .desc.name = "DA9061 BUCK3",
- .desc.of_match = of_match_ptr("buck3"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (530) * 1000,
- .desc.uV_step = (10) * 1000,
- .desc.n_voltages = ((1800) - (530))/(10) + 1,
- .current_limits = da9062_buck_a_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
- .desc.enable_reg = DA9062AA_BUCK4_CONT,
- .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK4_A,
- .desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK4_A,
- __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK4_B,
- __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK4_B,
- .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
- __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
- __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9061_ID_LDO1,
- .desc.name = "DA9061 LDO1",
- .desc.of_match = of_match_ptr("ldo1"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (900))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO1_CONT,
- .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO1_A,
- .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO1_A,
- __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO1_B,
- __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO1_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO1_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO1_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9061_ID_LDO2,
- .desc.name = "DA9061 LDO2",
- .desc.of_match = of_match_ptr("ldo2"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (600))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO2_CONT,
- .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO2_A,
- .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO2_A,
- __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO2_B,
- __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO2_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO2_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO2_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9061_ID_LDO3,
- .desc.name = "DA9061 LDO3",
- .desc.of_match = of_match_ptr("ldo3"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (900))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO3_CONT,
- .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO3_A,
- .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO3_A,
- __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO3_B,
- __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO3_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO3_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO3_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9061_ID_LDO4,
- .desc.name = "DA9061 LDO4",
- .desc.of_match = of_match_ptr("ldo4"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (900))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO4_CONT,
- .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO4_A,
- .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO4_A,
- __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO4_B,
- __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO4_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO4_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO4_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
- },
- };
- /* DA9062 Regulator information */
- static const struct da9062_regulator_info local_da9062_regulator_info[] = {
- {
- .desc.id = DA9062_ID_BUCK1,
- .desc.name = "DA9062 BUCK1",
- .desc.of_match = of_match_ptr("buck1"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (300) * 1000,
- .desc.uV_step = (10) * 1000,
- .desc.n_voltages = ((1570) - (300))/(10) + 1,
- .current_limits = da9062_buck_a_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
- .desc.enable_reg = DA9062AA_BUCK1_CONT,
- .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK1_A,
- .desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK1_A,
- __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK1_B,
- __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK1_B,
- .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
- __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
- __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_BUCK2,
- .desc.name = "DA9062 BUCK2",
- .desc.of_match = of_match_ptr("buck2"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (300) * 1000,
- .desc.uV_step = (10) * 1000,
- .desc.n_voltages = ((1570) - (300))/(10) + 1,
- .current_limits = da9062_buck_a_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
- .desc.enable_reg = DA9062AA_BUCK2_CONT,
- .desc.enable_mask = DA9062AA_BUCK2_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK2_A,
- .desc.vsel_mask = DA9062AA_VBUCK2_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK2_A,
- __builtin_ffs((int)DA9062AA_BUCK2_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK2_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK2_B,
- __builtin_ffs((int)DA9062AA_BUCK2_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK2_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK2_B,
- .mode = REG_FIELD(DA9062AA_BUCK2_CFG,
- __builtin_ffs((int)DA9062AA_BUCK2_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK2_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK2_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK2_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
- __builtin_ffs((int)DA9062AA_BUCK2_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK2_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_BUCK3,
- .desc.name = "DA9062 BUCK3",
- .desc.of_match = of_match_ptr("buck3"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (800) * 1000,
- .desc.uV_step = (20) * 1000,
- .desc.n_voltages = ((3340) - (800))/(20) + 1,
- .current_limits = da9062_buck_b_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
- .desc.enable_reg = DA9062AA_BUCK3_CONT,
- .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK3_A,
- .desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK3_A,
- __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK3_B,
- __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK3_B,
- .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
- __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
- __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_BUCK4,
- .desc.name = "DA9062 BUCK4",
- .desc.of_match = of_match_ptr("buck4"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_buck_ops,
- .desc.min_uV = (530) * 1000,
- .desc.uV_step = (10) * 1000,
- .desc.n_voltages = ((1800) - (530))/(10) + 1,
- .current_limits = da9062_buck_a_limits,
- .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
- .desc.enable_reg = DA9062AA_BUCK4_CONT,
- .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
- .desc.vsel_reg = DA9062AA_VBUCK4_A,
- .desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VBUCK4_A,
- __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VBUCK4_B,
- __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VBUCK4_B,
- .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
- __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
- .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
- __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_LDO1,
- .desc.name = "DA9062 LDO1",
- .desc.of_match = of_match_ptr("ldo1"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (900))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO1_CONT,
- .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO1_A,
- .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO1_A,
- __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO1_B,
- __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO1_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO1_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO1_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_LDO2,
- .desc.name = "DA9062 LDO2",
- .desc.of_match = of_match_ptr("ldo2"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (600))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO2_CONT,
- .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO2_A,
- .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO2_A,
- __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO2_B,
- __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO2_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO2_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO2_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_LDO3,
- .desc.name = "DA9062 LDO3",
- .desc.of_match = of_match_ptr("ldo3"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (900))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO3_CONT,
- .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO3_A,
- .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO3_A,
- __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO3_B,
- __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO3_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO3_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO3_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
- },
- {
- .desc.id = DA9062_ID_LDO4,
- .desc.name = "DA9062 LDO4",
- .desc.of_match = of_match_ptr("ldo4"),
- .desc.regulators_node = of_match_ptr("regulators"),
- .desc.ops = &da9062_ldo_ops,
- .desc.min_uV = (900) * 1000,
- .desc.uV_step = (50) * 1000,
- .desc.n_voltages = ((3600) - (900))/(50) + 1,
- .desc.enable_reg = DA9062AA_LDO4_CONT,
- .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
- .desc.vsel_reg = DA9062AA_VLDO4_A,
- .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
- .desc.linear_min_sel = 0,
- .sleep = REG_FIELD(DA9062AA_VLDO4_A,
- __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
- .suspend_sleep = REG_FIELD(DA9062AA_VLDO4_B,
- __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
- .suspend_vsel_reg = DA9062AA_VLDO4_B,
- .suspend = REG_FIELD(DA9062AA_DVC_1,
- __builtin_ffs((int)DA9062AA_VLDO4_SEL_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_VLDO4_SEL_MASK)) - 1),
- .oc_event = REG_FIELD(DA9062AA_STATUS_D,
- __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
- sizeof(unsigned int) * 8 -
- __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
- },
- };
- /* Regulator interrupt handlers */
- static irqreturn_t da9062_ldo_lim_event(int irq, void *data)
- {
- struct da9062_regulators *regulators = data;
- struct da9062 *hw = regulators->regulator[0].hw;
- struct da9062_regulator *regl;
- int handled = IRQ_NONE;
- int bits, i, ret;
- ret = regmap_read(hw->regmap, DA9062AA_STATUS_D, &bits);
- if (ret < 0) {
- dev_err(hw->dev,
- "Failed to read LDO overcurrent indicator\n");
- goto ldo_lim_error;
- }
- for (i = regulators->n_regulators - 1; i >= 0; i--) {
- regl = ®ulators->regulator[i];
- if (regl->info->oc_event.reg != DA9062AA_STATUS_D)
- continue;
- if (BIT(regl->info->oc_event.lsb) & bits) {
- regulator_notifier_call_chain(regl->rdev,
- REGULATOR_EVENT_OVER_CURRENT, NULL);
- handled = IRQ_HANDLED;
- }
- }
- ldo_lim_error:
- return handled;
- }
- static int da9062_regulator_probe(struct platform_device *pdev)
- {
- struct da9062 *chip = dev_get_drvdata(pdev->dev.parent);
- struct da9062_regulators *regulators;
- struct da9062_regulator *regl;
- struct regulator_config config = { };
- const struct da9062_regulator_info *rinfo;
- int irq, n, ret;
- size_t size;
- int max_regulators;
- switch (chip->chip_type) {
- case COMPAT_TYPE_DA9061:
- max_regulators = DA9061_MAX_REGULATORS;
- rinfo = local_da9061_regulator_info;
- break;
- case COMPAT_TYPE_DA9062:
- max_regulators = DA9062_MAX_REGULATORS;
- rinfo = local_da9062_regulator_info;
- break;
- default:
- dev_err(chip->dev, "Unrecognised chip type\n");
- return -ENODEV;
- }
- /* Allocate memory required by usable regulators */
- size = sizeof(struct da9062_regulators) +
- max_regulators * sizeof(struct da9062_regulator);
- regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
- if (!regulators)
- return -ENOMEM;
- regulators->n_regulators = max_regulators;
- platform_set_drvdata(pdev, regulators);
- n = 0;
- while (n < regulators->n_regulators) {
- /* Initialise regulator structure */
- regl = ®ulators->regulator[n];
- regl->hw = chip;
- regl->info = &rinfo[n];
- regl->desc = regl->info->desc;
- regl->desc.type = REGULATOR_VOLTAGE;
- regl->desc.owner = THIS_MODULE;
- if (regl->info->mode.reg)
- regl->mode = devm_regmap_field_alloc(
- &pdev->dev,
- chip->regmap,
- regl->info->mode);
- if (regl->info->suspend.reg)
- regl->suspend = devm_regmap_field_alloc(
- &pdev->dev,
- chip->regmap,
- regl->info->suspend);
- if (regl->info->sleep.reg)
- regl->sleep = devm_regmap_field_alloc(
- &pdev->dev,
- chip->regmap,
- regl->info->sleep);
- if (regl->info->suspend_sleep.reg)
- regl->suspend_sleep = devm_regmap_field_alloc(
- &pdev->dev,
- chip->regmap,
- regl->info->suspend_sleep);
- if (regl->info->ilimit.reg)
- regl->ilimit = devm_regmap_field_alloc(
- &pdev->dev,
- chip->regmap,
- regl->info->ilimit);
- /* Register regulator */
- memset(&config, 0, sizeof(config));
- config.dev = chip->dev;
- config.driver_data = regl;
- config.regmap = chip->regmap;
- regl->rdev = devm_regulator_register(&pdev->dev, ®l->desc,
- &config);
- if (IS_ERR(regl->rdev)) {
- dev_err(&pdev->dev,
- "Failed to register %s regulator\n",
- regl->desc.name);
- return PTR_ERR(regl->rdev);
- }
- n++;
- }
- /* LDOs overcurrent event support */
- irq = platform_get_irq_byname(pdev, "LDO_LIM");
- if (irq < 0) {
- dev_err(&pdev->dev, "Failed to get IRQ.\n");
- return irq;
- }
- regulators->irq_ldo_lim = irq;
- ret = devm_request_threaded_irq(&pdev->dev, irq,
- NULL, da9062_ldo_lim_event,
- IRQF_TRIGGER_LOW | IRQF_ONESHOT,
- "LDO_LIM", regulators);
- if (ret) {
- dev_warn(&pdev->dev,
- "Failed to request LDO_LIM IRQ.\n");
- regulators->irq_ldo_lim = -ENXIO;
- }
- return 0;
- }
- static struct platform_driver da9062_regulator_driver = {
- .driver = {
- .name = "da9062-regulators",
- },
- .probe = da9062_regulator_probe,
- };
- static int __init da9062_regulator_init(void)
- {
- return platform_driver_register(&da9062_regulator_driver);
- }
- subsys_initcall(da9062_regulator_init);
- static void __exit da9062_regulator_cleanup(void)
- {
- platform_driver_unregister(&da9062_regulator_driver);
- }
- module_exit(da9062_regulator_cleanup);
- /* Module information */
- MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>");
- MODULE_DESCRIPTION("REGULATOR device driver for Dialog DA9062 and DA9061");
- MODULE_LICENSE("GPL");
- MODULE_ALIAS("platform:da9062-regulators");
|