^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) // Copyright (C) 2018 ROHM Semiconductors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // bd70528-regulator.c ROHM BD70528MWV regulator driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/mfd/rohm-bd70528.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define BUCK_RAMPRATE_250MV 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define BUCK_RAMPRATE_125MV 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define BUCK_RAMP_MAX 250
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static const struct linear_range bd70528_buck1_volts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x1, 600000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) REGULATOR_LINEAR_RANGE(2750000, 0x2, 0xf, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static const struct linear_range bd70528_buck2_volts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x1, 300000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) REGULATOR_LINEAR_RANGE(1550000, 0x2, 0xd, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) REGULATOR_LINEAR_RANGE(3000000, 0xe, 0xf, 300000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static const struct linear_range bd70528_buck3_volts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) REGULATOR_LINEAR_RANGE(800000, 0x00, 0xd, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) REGULATOR_LINEAR_RANGE(1800000, 0xe, 0xf, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* All LDOs have same voltage ranges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static const struct linear_range bd70528_ldo_volts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) REGULATOR_LINEAR_RANGE(1650000, 0x0, 0x07, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) REGULATOR_LINEAR_RANGE(2100000, 0x8, 0x0f, 100000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) REGULATOR_LINEAR_RANGE(2850000, 0x10, 0x19, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) REGULATOR_LINEAR_RANGE(3300000, 0x19, 0x1f, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Also both LEDs support same voltages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static const unsigned int led_volts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 20000, 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int bd70528_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (ramp_delay > 0 && ramp_delay <= BUCK_RAMP_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned int ramp_value = BUCK_RAMPRATE_250MV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (ramp_delay <= 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ramp_value = BUCK_RAMPRATE_125MV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) BD70528_MASK_BUCK_RAMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ramp_value << BD70528_SIFT_BUCK_RAMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) dev_err(&rdev->dev, "%s: ramp_delay: %d not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) rdev->desc->name, ramp_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int bd70528_led_set_voltage_sel(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned int sel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ret = regulator_is_enabled_regmap(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return regulator_set_voltage_sel_regmap(rdev, sel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dev_err(&rdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) "LED voltage change not allowed when led is enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return -EBUSY;
^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 bd70528_buck_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .set_voltage_time_sel = regulator_set_voltage_time_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .set_ramp_delay = bd70528_set_ramp_delay,
^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 bd70528_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .list_voltage = regulator_list_voltage_linear_range,
^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) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .set_voltage_time_sel = regulator_set_voltage_time_sel,
^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 regulator_ops bd70528_led_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .set_voltage_sel = bd70528_led_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static const struct regulator_desc bd70528_desc[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .name = "buck1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .of_match = of_match_ptr("BUCK1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .id = BD70528_BUCK1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .ops = &bd70528_buck_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .linear_ranges = bd70528_buck1_volts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .n_linear_ranges = ARRAY_SIZE(bd70528_buck1_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .n_voltages = BD70528_BUCK_VOLTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .enable_reg = BD70528_REG_BUCK1_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .enable_mask = BD70528_MASK_RUN_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .vsel_reg = BD70528_REG_BUCK1_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .vsel_mask = BD70528_MASK_BUCK_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .name = "buck2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .of_match = of_match_ptr("BUCK2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .id = BD70528_BUCK2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .ops = &bd70528_buck_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .linear_ranges = bd70528_buck2_volts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .n_linear_ranges = ARRAY_SIZE(bd70528_buck2_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .n_voltages = BD70528_BUCK_VOLTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .enable_reg = BD70528_REG_BUCK2_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .enable_mask = BD70528_MASK_RUN_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .vsel_reg = BD70528_REG_BUCK2_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .vsel_mask = BD70528_MASK_BUCK_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .name = "buck3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .of_match = of_match_ptr("BUCK3"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .id = BD70528_BUCK3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .ops = &bd70528_buck_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .linear_ranges = bd70528_buck3_volts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .n_linear_ranges = ARRAY_SIZE(bd70528_buck3_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .n_voltages = BD70528_BUCK_VOLTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .enable_reg = BD70528_REG_BUCK3_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .enable_mask = BD70528_MASK_RUN_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .vsel_reg = BD70528_REG_BUCK3_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .vsel_mask = BD70528_MASK_BUCK_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .name = "ldo1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .of_match = of_match_ptr("LDO1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .id = BD70528_LDO1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .ops = &bd70528_ldo_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .linear_ranges = bd70528_ldo_volts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .n_voltages = BD70528_LDO_VOLTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .enable_reg = BD70528_REG_LDO1_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .enable_mask = BD70528_MASK_RUN_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .vsel_reg = BD70528_REG_LDO1_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .vsel_mask = BD70528_MASK_LDO_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .name = "ldo2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .of_match = of_match_ptr("LDO2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .id = BD70528_LDO2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .ops = &bd70528_ldo_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .linear_ranges = bd70528_ldo_volts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .n_voltages = BD70528_LDO_VOLTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .enable_reg = BD70528_REG_LDO2_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .enable_mask = BD70528_MASK_RUN_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .vsel_reg = BD70528_REG_LDO2_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .vsel_mask = BD70528_MASK_LDO_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .name = "ldo3",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .of_match = of_match_ptr("LDO3"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .id = BD70528_LDO3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .ops = &bd70528_ldo_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .linear_ranges = bd70528_ldo_volts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .n_voltages = BD70528_LDO_VOLTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .enable_reg = BD70528_REG_LDO3_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .enable_mask = BD70528_MASK_RUN_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .vsel_reg = BD70528_REG_LDO3_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .vsel_mask = BD70528_MASK_LDO_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .name = "ldo_led1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .of_match = of_match_ptr("LDO_LED1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .id = BD70528_LED1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .ops = &bd70528_led_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .volt_table = &led_volts[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .n_voltages = ARRAY_SIZE(led_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .enable_reg = BD70528_REG_LED_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .enable_mask = BD70528_MASK_LED1_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .vsel_reg = BD70528_REG_LED_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .vsel_mask = BD70528_MASK_LED1_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .name = "ldo_led2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .of_match = of_match_ptr("LDO_LED2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .id = BD70528_LED2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .ops = &bd70528_led_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .volt_table = &led_volts[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .n_voltages = ARRAY_SIZE(led_volts),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .enable_reg = BD70528_REG_LED_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .enable_mask = BD70528_MASK_LED2_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .vsel_reg = BD70528_REG_LED_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .vsel_mask = BD70528_MASK_LED2_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .owner = THIS_MODULE,
^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) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int bd70528_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct rohm_regmap_dev *bd70528;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct regulator_config config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .dev = pdev->dev.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) bd70528 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!bd70528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) dev_err(&pdev->dev, "No MFD driver data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) config.regmap = bd70528->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) for (i = 0; i < ARRAY_SIZE(bd70528_desc); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) rdev = devm_regulator_register(&pdev->dev, &bd70528_desc[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) "failed to register %s regulator\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) bd70528_desc[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static struct platform_driver bd70528_regulator = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .name = "bd70528-pmic"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .probe = bd70528_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) module_platform_driver(bd70528_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_DESCRIPTION("BD70528 voltage regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) MODULE_ALIAS("platform:bd70528-pmic");