^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Regulators driver for Maxim max8925
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2009 Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Haojian Zhuang <haojian.zhuang@marvell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^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/module.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/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.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/mfd/max8925.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define SD1_DVM_VMIN 850000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define SD1_DVM_VMAX 1000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define SD1_DVM_STEP 50000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define SD1_DVM_SHIFT 5 /* SDCTL1 bit5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define SD1_DVM_EN 6 /* SDV1 bit 6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* bit definitions in LDO control registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define LDO_SEQ_I2C 0x7 /* Power U/D by i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define LDO_SEQ_MASK 0x7 /* Power U/D sequence mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define LDO_SEQ_SHIFT 2 /* Power U/D sequence offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define LDO_I2C_EN 0x1 /* Enable by i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define LDO_I2C_EN_MASK 0x1 /* Enable mask by i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define LDO_I2C_EN_SHIFT 0 /* Enable offset by i2c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct max8925_regulator_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct regulator_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct i2c_client *i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int vol_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int enable_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int max8925_set_voltage_sel(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned int selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned char mask = rdev->desc->n_voltages - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return max8925_set_bits(info->i2c, info->vol_reg, mask, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int max8925_get_voltage_sel(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned char data, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ret = max8925_reg_read(info->i2c, info->vol_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) mask = rdev->desc->n_voltages - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) data = ret & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int max8925_enable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return max8925_set_bits(info->i2c, info->enable_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) LDO_SEQ_MASK << LDO_SEQ_SHIFT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) LDO_SEQ_I2C << LDO_SEQ_SHIFT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) LDO_I2C_EN << LDO_I2C_EN_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int max8925_disable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return max8925_set_bits(info->i2c, info->enable_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) LDO_SEQ_MASK << LDO_SEQ_SHIFT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) LDO_SEQ_I2C << LDO_SEQ_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int max8925_is_enabled(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int ldo_seq, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ret = max8925_reg_read(info->i2c, info->enable_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ldo_seq = (ret >> LDO_SEQ_SHIFT) & LDO_SEQ_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (ldo_seq != LDO_SEQ_I2C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return ret & (LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int max8925_set_dvm_voltage(struct regulator_dev *rdev, int uV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned char data, mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (uV < SD1_DVM_VMIN || uV > SD1_DVM_VMAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) data = DIV_ROUND_UP(uV - SD1_DVM_VMIN, SD1_DVM_STEP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) data <<= SD1_DVM_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mask = 3 << SD1_DVM_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return max8925_set_bits(info->i2c, info->enable_reg, mask, data);
^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 int max8925_set_dvm_enable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return max8925_set_bits(info->i2c, info->vol_reg, 1 << SD1_DVM_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 1 << SD1_DVM_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int max8925_set_dvm_disable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return max8925_set_bits(info->i2c, info->vol_reg, 1 << SD1_DVM_EN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static const struct regulator_ops max8925_regulator_sdv_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .set_voltage_sel = max8925_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .get_voltage_sel = max8925_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .enable = max8925_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .disable = max8925_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .is_enabled = max8925_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .set_suspend_voltage = max8925_set_dvm_voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .set_suspend_enable = max8925_set_dvm_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .set_suspend_disable = max8925_set_dvm_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static const struct regulator_ops max8925_regulator_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .set_voltage_sel = max8925_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .get_voltage_sel = max8925_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .enable = max8925_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .disable = max8925_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .is_enabled = max8925_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define MAX8925_SDV(_id, min, max, step) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .desc = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .name = "SDV" #_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .of_match = of_match_ptr("SDV" #_id), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .ops = &max8925_regulator_sdv_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .id = MAX8925_ID_SD##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .n_voltages = 64, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .min_uV = min * 1000, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .uV_step = step * 1000, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .vol_reg = MAX8925_SDV##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .enable_reg = MAX8925_SDCTL##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define MAX8925_LDO(_id, min, max, step) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .desc = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .name = "LDO" #_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .of_match = of_match_ptr("LDO" #_id), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .ops = &max8925_regulator_ldo_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .id = MAX8925_ID_LDO##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .n_voltages = 64, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .min_uV = min * 1000, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .uV_step = step * 1000, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .vol_reg = MAX8925_LDOVOUT##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .enable_reg = MAX8925_LDOCTL##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static struct max8925_regulator_info max8925_regulator_info[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) MAX8925_SDV(1, 637.5, 1425, 12.5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) MAX8925_SDV(2, 650, 2225, 25),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) MAX8925_SDV(3, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) MAX8925_LDO(1, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) MAX8925_LDO(2, 650, 2250, 25),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) MAX8925_LDO(3, 650, 2250, 25),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MAX8925_LDO(4, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) MAX8925_LDO(5, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) MAX8925_LDO(6, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) MAX8925_LDO(7, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) MAX8925_LDO(8, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) MAX8925_LDO(9, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) MAX8925_LDO(10, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) MAX8925_LDO(11, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) MAX8925_LDO(12, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) MAX8925_LDO(13, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) MAX8925_LDO(14, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) MAX8925_LDO(15, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) MAX8925_LDO(16, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) MAX8925_LDO(17, 650, 2250, 25),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) MAX8925_LDO(18, 650, 2250, 25),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) MAX8925_LDO(19, 750, 3900, 50),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) MAX8925_LDO(20, 750, 3900, 50),
^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) static int max8925_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct max8925_regulator_info *ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) res = platform_get_resource(pdev, IORESOURCE_REG, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) dev_err(&pdev->dev, "No REG resource!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ri = &max8925_regulator_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (ri->vol_reg == res->start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^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) if (i == ARRAY_SIZE(max8925_regulator_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) dev_err(&pdev->dev, "Failed to find regulator %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) (unsigned long long)res->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ri->i2c = chip->i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) config.dev = chip->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) config.driver_data = ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) config.init_data = pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) dev_err(&pdev->dev, "failed to register regulator %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ri->desc.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return PTR_ERR(rdev);
^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) platform_set_drvdata(pdev, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static struct platform_driver max8925_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .name = "max8925-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .probe = max8925_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int __init max8925_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return platform_driver_register(&max8925_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) subsys_initcall(max8925_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static void __exit max8925_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) platform_driver_unregister(&max8925_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) module_exit(max8925_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_DESCRIPTION("Regulator Driver for Maxim 8925 PMIC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_ALIAS("platform:max8925-regulator");