^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) * AS3711 PMIC regulator driver, using DCDC Step Down and LDO supplies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2012 Renesas Electronics Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Guennadi Liakhovetski, <g.liakhovetski@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mfd/as3711.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * The regulator API supports 4 modes of operataion: FAST, NORMAL, IDLE and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * STANDBY. We map them in the following way to AS3711 SD1-4 DCDC modes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * FAST: sdX_fast=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * NORMAL: low_noise=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * IDLE: low_noise=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int as3711_set_mode_sd(struct regulator_dev *rdev, unsigned int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned int fast_bit = rdev->desc->enable_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) low_noise_bit = fast_bit << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u8 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) case REGULATOR_MODE_FAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) val = fast_bit | low_noise_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) case REGULATOR_MODE_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) val = low_noise_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case REGULATOR_MODE_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) default:
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return regmap_update_bits(rdev->regmap, AS3711_SD_CONTROL_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) low_noise_bit | fast_bit, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static unsigned int as3711_get_mode_sd(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned int fast_bit = rdev->desc->enable_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) low_noise_bit = fast_bit << 4, mask = fast_bit | low_noise_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int ret = regmap_read(rdev->regmap, AS3711_SD_CONTROL_1, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if ((val & mask) == mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return REGULATOR_MODE_FAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if ((val & mask) == low_noise_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return REGULATOR_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!(val & mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return REGULATOR_MODE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static const struct regulator_ops as3711_sd_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .map_voltage = regulator_map_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .get_mode = as3711_get_mode_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .set_mode = as3711_set_mode_sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static const struct regulator_ops as3711_aldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .map_voltage = regulator_map_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static const struct regulator_ops as3711_dldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .map_voltage = regulator_map_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static const struct linear_range as3711_sd_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) REGULATOR_LINEAR_RANGE(612500, 0x1, 0x40, 12500),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7f, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct linear_range as3711_aldo_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) REGULATOR_LINEAR_RANGE(1200000, 0, 0xf, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) REGULATOR_LINEAR_RANGE(1800000, 0x10, 0x1f, 100000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static const struct linear_range as3711_dldo_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) REGULATOR_LINEAR_RANGE(900000, 0, 0x10, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) REGULATOR_LINEAR_RANGE(1750000, 0x20, 0x3f, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _sfx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) [AS3711_REGULATOR_ ## _id] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .name = "as3711-regulator-" # _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .id = AS3711_REGULATOR_ ## _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .n_voltages = (_vmask + 1), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .ops = &as3711_ ## _sfx ## _ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .vsel_reg = AS3711_ ## _id ## _VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .vsel_mask = _vmask, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .enable_reg = AS3711_ ## _en_reg, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .enable_mask = BIT(_en_bit), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .linear_ranges = as3711_ ## _sfx ## _ranges, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .n_linear_ranges = ARRAY_SIZE(as3711_ ## _sfx ## _ranges), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static const struct regulator_desc as3711_reg_desc[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) AS3711_REG(SD_1, SD_CONTROL, 0, 0x7f, sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) AS3711_REG(SD_2, SD_CONTROL, 1, 0x7f, sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) AS3711_REG(SD_3, SD_CONTROL, 2, 0x7f, sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) AS3711_REG(SD_4, SD_CONTROL, 3, 0x7f, sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) AS3711_REG(LDO_1, LDO_1_VOLTAGE, 7, 0x1f, aldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) AS3711_REG(LDO_2, LDO_2_VOLTAGE, 7, 0x1f, aldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) AS3711_REG(LDO_3, LDO_3_VOLTAGE, 7, 0x3f, dldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) AS3711_REG(LDO_4, LDO_4_VOLTAGE, 7, 0x3f, dldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) AS3711_REG(LDO_5, LDO_5_VOLTAGE, 7, 0x3f, dldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) AS3711_REG(LDO_6, LDO_6_VOLTAGE, 7, 0x3f, dldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) AS3711_REG(LDO_7, LDO_7_VOLTAGE, 7, 0x3f, dldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) AS3711_REG(LDO_8, LDO_8_VOLTAGE, 7, 0x3f, dldo),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* StepUp output voltage depends on supplying regulator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct of_regulator_match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) as3711_regulator_matches[AS3711_REGULATOR_NUM] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) [AS3711_REGULATOR_SD_1] = { .name = "sd1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) [AS3711_REGULATOR_SD_2] = { .name = "sd2" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) [AS3711_REGULATOR_SD_3] = { .name = "sd3" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) [AS3711_REGULATOR_SD_4] = { .name = "sd4" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) [AS3711_REGULATOR_LDO_1] = { .name = "ldo1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) [AS3711_REGULATOR_LDO_2] = { .name = "ldo2" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) [AS3711_REGULATOR_LDO_3] = { .name = "ldo3" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) [AS3711_REGULATOR_LDO_4] = { .name = "ldo4" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) [AS3711_REGULATOR_LDO_5] = { .name = "ldo5" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) [AS3711_REGULATOR_LDO_6] = { .name = "ldo6" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) [AS3711_REGULATOR_LDO_7] = { .name = "ldo7" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) [AS3711_REGULATOR_LDO_8] = { .name = "ldo8" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int as3711_regulator_parse_dt(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct device_node **of_node, const int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct as3711_regulator_pdata *pdata = dev_get_platdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct device_node *regulators =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) of_get_child_by_name(dev->parent->of_node, "regulators");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct of_regulator_match *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!regulators) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dev_err(dev, "regulator node not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ret = of_regulator_match(dev->parent, regulators,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) as3711_regulator_matches, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) of_node_put(regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) dev_err(dev, "Error parsing regulator init data: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) for (i = 0, match = as3711_regulator_matches; i < count; i++, match++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (match->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pdata->init_data[i] = match->init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) of_node[i] = match->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int as3711_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct as3711_regulator_pdata *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct as3711 *as3711 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct regulator_config config = {.dev = &pdev->dev,};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct device_node *of_node[AS3711_REGULATOR_NUM] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) dev_err(&pdev->dev, "No platform data...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (pdev->dev.parent->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ret = as3711_regulator_parse_dt(&pdev->dev, of_node, AS3711_REGULATOR_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) dev_err(&pdev->dev, "DT parsing failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) for (id = 0; id < AS3711_REGULATOR_NUM; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) config.init_data = pdata->init_data[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) config.regmap = as3711->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) config.of_node = of_node[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) rdev = devm_regulator_register(&pdev->dev, &as3711_reg_desc[id],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) dev_err(&pdev->dev, "Failed to register regulator %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) as3711_reg_desc[id].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return PTR_ERR(rdev);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static struct platform_driver as3711_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .name = "as3711-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .probe = as3711_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int __init as3711_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return platform_driver_register(&as3711_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) subsys_initcall(as3711_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void __exit as3711_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) platform_driver_unregister(&as3711_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) module_exit(as3711_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) MODULE_DESCRIPTION("AS3711 regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_ALIAS("platform:as3711-regulator");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) MODULE_LICENSE("GPL v2");