^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // max14577.c - Regulator driver for the Maxim 14577/77836
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright (C) 2013,2014 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Krzysztof Kozlowski <krzk@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mfd/max14577.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mfd/max14577-private.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static int max14577_reg_is_enabled(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) int rid = rdev_get_id(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct regmap *rmap = rdev->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) u8 reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) switch (rid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) case MAX14577_CHARGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if ((reg_data & STATUS3_CGMBC_MASK) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* MBCHOSTEN and CGMBC are on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u8 reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct regmap *rmap = rdev->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct max14577 *max14577 = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) const struct maxim_charger_current *limits =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) &maxim_charger_currents[max14577->dev_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (rdev_get_id(rdev) != MAX14577_CHARGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, ®_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if ((reg_data & CHGCTRL4_MBCICHWRCL_MASK) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return limits->min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) reg_data = ((reg_data & CHGCTRL4_MBCICHWRCH_MASK) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) CHGCTRL4_MBCICHWRCH_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return limits->high_start + reg_data * limits->high_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int min_uA, int max_uA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u8 reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct max14577 *max14577 = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) const struct maxim_charger_current *limits =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) &maxim_charger_currents[max14577->dev_type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (rdev_get_id(rdev) != MAX14577_CHARGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ret = maxim_charger_calc_reg_current(limits, min_uA, max_uA, ®_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) reg_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static const struct regulator_ops max14577_safeout_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static const struct regulator_ops max14577_charger_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .is_enabled = max14577_reg_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .get_current_limit = max14577_reg_get_current_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .set_current_limit = max14577_reg_set_current_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define MAX14577_SAFEOUT_REG { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .name = "SAFEOUT", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .of_match = of_match_ptr("SAFEOUT"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .id = MAX14577_SAFEOUT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .ops = &max14577_safeout_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .n_voltages = 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .enable_reg = MAX14577_REG_CONTROL2, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .enable_mask = CTRL2_SFOUTORD_MASK, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define MAX14577_CHARGER_REG { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .name = "CHARGER", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .of_match = of_match_ptr("CHARGER"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .id = MAX14577_CHARGER, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .ops = &max14577_charger_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .type = REGULATOR_CURRENT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .enable_reg = MAX14577_CHG_REG_CHG_CTRL2, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .enable_mask = CHGCTRL2_MBCHOSTEN_MASK, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct regulator_desc max14577_supported_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) [MAX14577_SAFEOUT] = MAX14577_SAFEOUT_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) [MAX14577_CHARGER] = MAX14577_CHARGER_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const struct regulator_ops max77836_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* TODO: add .set_suspend_mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define MAX77836_LDO_REG(num) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .name = "LDO" # num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .of_match = of_match_ptr("LDO" # num), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .id = MAX77836_LDO ## num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .ops = &max77836_ldo_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .enable_reg = MAX77836_LDO_REG_CNFG1_LDO ## num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO ## num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static const struct regulator_desc max77836_supported_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) [MAX14577_SAFEOUT] = MAX14577_SAFEOUT_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) [MAX14577_CHARGER] = MAX14577_CHARGER_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) [MAX77836_LDO1] = MAX77836_LDO_REG(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) [MAX77836_LDO2] = MAX77836_LDO_REG(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Registers for regulators of max77836 use different I2C slave addresses so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * different regmaps must be used for them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * Returns proper regmap for accessing regulator passed by id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static struct regmap *max14577_get_regmap(struct max14577 *max14577,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int reg_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) switch (max14577->dev_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) case MAXIM_DEVICE_TYPE_MAX77836:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) switch (reg_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) case MAX77836_SAFEOUT ... MAX77836_CHARGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return max14577->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* MAX77836_LDO1 ... MAX77836_LDO2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return max14577->regmap_pmic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) case MAXIM_DEVICE_TYPE_MAX14577:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return max14577->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static int max14577_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct max14577_platform_data *pdata = dev_get_platdata(max14577->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct regulator_config config = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) const struct regulator_desc *supported_regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) unsigned int supported_regulators_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) enum maxim_device_type dev_type = max14577->dev_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) switch (dev_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) case MAXIM_DEVICE_TYPE_MAX77836:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) supported_regulators = max77836_supported_regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) supported_regulators_size = ARRAY_SIZE(max77836_supported_regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) case MAXIM_DEVICE_TYPE_MAX14577:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) supported_regulators = max14577_supported_regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) supported_regulators_size = ARRAY_SIZE(max14577_supported_regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) config.dev = max14577->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) config.driver_data = max14577;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) for (i = 0; i < supported_regulators_size; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct regulator_dev *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Index of supported_regulators[] is also the id and must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * match index of pdata->regulators[].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (pdata && pdata->regulators) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) config.init_data = pdata->regulators[i].initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) config.of_node = pdata->regulators[i].of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) config.regmap = max14577_get_regmap(max14577,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) supported_regulators[i].id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) regulator = devm_regulator_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) &supported_regulators[i], &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (IS_ERR(regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ret = PTR_ERR(regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) "Regulator init failed for %d/%s with error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) i, supported_regulators[i].name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static const struct platform_device_id max14577_regulator_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) { "max14577-regulator", MAXIM_DEVICE_TYPE_MAX14577, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) { "max77836-regulator", MAXIM_DEVICE_TYPE_MAX77836, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) MODULE_DEVICE_TABLE(platform, max14577_regulator_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static struct platform_driver max14577_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .name = "max14577-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .probe = max14577_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .id_table = max14577_regulator_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int __init max14577_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REGULATOR_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REGULATOR_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) BUILD_BUG_ON(MAX77836_REGULATOR_LDO_VOLTAGE_MIN +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) (MAX77836_REGULATOR_LDO_VOLTAGE_STEP *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) (MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM - 1)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) MAX77836_REGULATOR_LDO_VOLTAGE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return platform_driver_register(&max14577_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) subsys_initcall(max14577_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static void __exit max14577_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) platform_driver_unregister(&max14577_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) module_exit(max14577_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) MODULE_DESCRIPTION("Maxim 14577/77836 regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_LICENSE("GPL");