^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) // Regulator driver for DA9055 PMIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright(c) 2012 Dialog Semiconductor Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Author: David Dajun Chen <dchen@diasemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^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/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/gpio/consumer.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/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regulator/machine.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) #include <linux/mfd/da9055/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mfd/da9055/reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mfd/da9055/pdata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DA9055_MIN_UA 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define DA9055_MAX_UA 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DA9055_LDO_MODE_SYNC 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DA9055_LDO_MODE_SLEEP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DA9055_BUCK_MODE_SLEEP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define DA9055_BUCK_MODE_SYNC 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define DA9055_BUCK_MODE_AUTO 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* DA9055 REGULATOR IDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define DA9055_ID_BUCK1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define DA9055_ID_BUCK2 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define DA9055_ID_LDO1 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DA9055_ID_LDO2 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DA9055_ID_LDO3 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DA9055_ID_LDO4 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DA9055_ID_LDO5 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define DA9055_ID_LDO6 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* DA9055 BUCK current limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const unsigned int da9055_current_limits[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 500000, 600000, 700000, 800000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct da9055_conf_reg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int sel_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int en_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct da9055_volt_reg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int reg_a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int reg_b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int sl_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int v_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct da9055_mode_reg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct da9055_regulator_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct regulator_desc reg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct da9055_conf_reg conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct da9055_volt_reg volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct da9055_mode_reg mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct da9055_regulator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct da9055 *da9055;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct da9055_regulator_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) enum gpio_select reg_rselect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static unsigned int da9055_buck_get_mode(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int ret, mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ret = da9055_reg_read(regulator->da9055, info->mode.reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) switch ((ret & info->mode.mask) >> info->mode.shift) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) case DA9055_BUCK_MODE_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) mode = REGULATOR_MODE_FAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) case DA9055_BUCK_MODE_AUTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) mode = REGULATOR_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) case DA9055_BUCK_MODE_SLEEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) mode = REGULATOR_MODE_STANDBY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int da9055_buck_set_mode(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case REGULATOR_MODE_FAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) val = DA9055_BUCK_MODE_SYNC << info->mode.shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) case REGULATOR_MODE_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) val = DA9055_BUCK_MODE_AUTO << info->mode.shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case REGULATOR_MODE_STANDBY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) val = DA9055_BUCK_MODE_SLEEP << info->mode.shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return da9055_reg_update(regulator->da9055, info->mode.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) info->mode.mask, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static unsigned int da9055_ldo_get_mode(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ret = da9055_reg_read(regulator->da9055, info->volt.reg_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (ret >> info->volt.sl_shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return REGULATOR_MODE_STANDBY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return REGULATOR_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct da9055_volt_reg volt = info->volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case REGULATOR_MODE_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) case REGULATOR_MODE_FAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) val = DA9055_LDO_MODE_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) case REGULATOR_MODE_STANDBY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) val = DA9055_LDO_MODE_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return da9055_reg_update(regulator->da9055, volt.reg_b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 1 << volt.sl_shift,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) val << volt.sl_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct da9055_volt_reg volt = info->volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int ret, sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * There are two voltage register set A & B for voltage ramping but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * either one of then can be active therefore we first determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * the active register set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ret = da9055_reg_read(regulator->da9055, info->conf.reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ret &= info->conf.sel_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* Get the voltage for the active register set A/B */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (ret == DA9055_REGUALTOR_SET_A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ret = da9055_reg_read(regulator->da9055, volt.reg_a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ret = da9055_reg_read(regulator->da9055, volt.reg_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) sel = (ret & volt.v_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) unsigned int selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * Regulator register set A/B is not selected through GPIO therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * we use default register set A for voltage ramping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (regulator->reg_rselect == NO_GPIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* Select register set A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ret = da9055_reg_update(regulator->da9055, info->conf.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) info->conf.sel_mask, DA9055_SEL_REG_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* Set the voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return da9055_reg_update(regulator->da9055, info->volt.reg_a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) info->volt.v_mask, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Here regulator register set A/B is selected through GPIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Therefore we first determine the selected register set A/B and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * then set the desired voltage for that register set A/B.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ret = da9055_reg_read(regulator->da9055, info->conf.reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ret &= info->conf.sel_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Set the voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (ret == DA9055_REGUALTOR_SET_A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return da9055_reg_update(regulator->da9055, info->volt.reg_a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) info->volt.v_mask, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return da9055_reg_update(regulator->da9055, info->volt.reg_b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) info->volt.v_mask, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int uV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* Select register set B for suspend voltage ramping. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (regulator->reg_rselect == NO_GPIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ret = da9055_reg_update(regulator->da9055, info->conf.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) info->conf.sel_mask, DA9055_SEL_REG_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ret = regulator_map_voltage_linear(rdev, uV, uV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return da9055_reg_update(regulator->da9055, info->volt.reg_b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) info->volt.v_mask, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static int da9055_suspend_enable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* Select register set B for voltage ramping. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (regulator->reg_rselect == NO_GPIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return da9055_reg_update(regulator->da9055, info->conf.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) info->conf.sel_mask, DA9055_SEL_REG_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int da9055_suspend_disable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /* Diselect register set B. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (regulator->reg_rselect == NO_GPIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return da9055_reg_update(regulator->da9055, info->conf.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) info->conf.sel_mask, DA9055_SEL_REG_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static const struct regulator_ops da9055_buck_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .get_mode = da9055_buck_get_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .set_mode = da9055_buck_set_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .get_current_limit = regulator_get_current_limit_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .set_current_limit = regulator_set_current_limit_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .get_voltage_sel = da9055_regulator_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .set_voltage_sel = da9055_regulator_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .set_suspend_enable = da9055_suspend_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .set_suspend_disable = da9055_suspend_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .set_suspend_mode = da9055_buck_set_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static const struct regulator_ops da9055_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .get_mode = da9055_ldo_get_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .set_mode = da9055_ldo_set_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .get_voltage_sel = da9055_regulator_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) .set_voltage_sel = da9055_regulator_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .set_suspend_enable = da9055_suspend_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .set_suspend_disable = da9055_suspend_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .set_suspend_mode = da9055_ldo_set_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #define DA9055_LDO(_id, step, min, max, vbits, voffset) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .reg_desc = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .name = #_id,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) .of_match = of_match_ptr(#_id),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .regulators_node = of_match_ptr("regulators"),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .ops = &da9055_ldo_ops,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .type = REGULATOR_VOLTAGE,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .id = DA9055_ID_##_id,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .n_voltages = (max - min) / step + 1 + (voffset), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .enable_mask = 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .min_uV = (min) * 1000,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .uV_step = (step) * 1000,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .linear_min_sel = (voffset),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .owner = THIS_MODULE,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .conf = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .sel_mask = (1 << 4),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .en_mask = 1,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .volt = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) .sl_shift = 7,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) .v_mask = (1 << (vbits)) - 1,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) #define DA9055_BUCK(_id, step, min, max, vbits, voffset, mbits, sbits) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) .reg_desc = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) .name = #_id,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) .of_match = of_match_ptr(#_id),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) .regulators_node = of_match_ptr("regulators"),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .ops = &da9055_buck_ops,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .type = REGULATOR_VOLTAGE,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .id = DA9055_ID_##_id,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .n_voltages = (max - min) / step + 1 + (voffset), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) .enable_mask = 1,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) .min_uV = (min) * 1000,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .uV_step = (step) * 1000,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) .linear_min_sel = (voffset),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .owner = THIS_MODULE,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) .curr_table = da9055_current_limits,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) .n_current_limits = ARRAY_SIZE(da9055_current_limits),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) .csel_reg = DA9055_REG_BUCK_LIM,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .csel_mask = (mbits),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .conf = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .sel_mask = (1 << 4),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .en_mask = 1,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .volt = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .sl_shift = 7,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .v_mask = (1 << (vbits)) - 1,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .mode = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .reg = DA9055_REG_BCORE_MODE,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .mask = (mbits),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .shift = (sbits),\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) },\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static struct da9055_regulator_info da9055_regulator_info[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) DA9055_BUCK(BUCK1, 25, 725, 2075, 6, 9, 0xc, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) DA9055_BUCK(BUCK2, 25, 925, 2500, 6, 0, 3, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) DA9055_LDO(LDO1, 50, 900, 3300, 6, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) DA9055_LDO(LDO2, 50, 900, 3300, 6, 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) DA9055_LDO(LDO3, 50, 900, 3300, 6, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) DA9055_LDO(LDO4, 50, 900, 3300, 6, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) DA9055_LDO(LDO5, 50, 900, 2750, 6, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) DA9055_LDO(LDO6, 20, 900, 3300, 7, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * Configures regulator to be controlled either through GPIO 1 or 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * GPIO can control regulator state and/or select the regulator register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * set A/B for voltage ramping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static int da9055_gpio_init(struct da9055_regulator *regulator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct regulator_config *config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct da9055_pdata *pdata, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct da9055_regulator_info *info = regulator->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (pdata->gpio_ren && pdata->gpio_ren[id]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) char name[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) int gpio_mux = pdata->gpio_ren[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) config->ena_gpiod = pdata->ena_gpiods[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * GPI pin is muxed with regulator to control the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * regulator state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) sprintf(name, "DA9055 GPI %d", gpio_mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * Let the regulator know that its state is controlled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * through GPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ret = da9055_reg_update(regulator->da9055, info->conf.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) DA9055_E_GPI_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) pdata->reg_ren[id]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) << DA9055_E_GPI_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (pdata->gpio_rsel && pdata->gpio_rsel[id]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) char name[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) int gpio_mux = pdata->gpio_rsel[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) regulator->reg_rselect = pdata->reg_rsel[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * GPI pin is muxed with regulator to select the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * regulator register set A/B for voltage ramping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) sprintf(name, "DA9055 GPI %d", gpio_mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Let the regulator know that its register set A/B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * will be selected through GPI for voltage ramping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ret = da9055_reg_update(regulator->da9055, info->conf.reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) DA9055_V_GPI_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) pdata->reg_rsel[id]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) << DA9055_V_GPI_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct da9055_regulator *regulator = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) regulator_notifier_call_chain(regulator->rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) REGULATOR_EVENT_OVER_CURRENT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static inline struct da9055_regulator_info *find_regulator_info(int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct da9055_regulator_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) for (i = 0; i < ARRAY_SIZE(da9055_regulator_info); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) info = &da9055_regulator_info[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (info->reg_desc.id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static int da9055_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct da9055_regulator *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct da9055_pdata *pdata = dev_get_platdata(da9055->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int ret, irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (!regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) regulator->info = find_regulator_info(pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (regulator->info == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) dev_err(&pdev->dev, "invalid regulator ID specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) regulator->da9055 = da9055;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) config.dev = da9055->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) config.driver_data = regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) config.regmap = da9055->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) config.init_data = pdata->regulators[pdev->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) regulator->rdev = devm_regulator_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ®ulator->info->reg_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (IS_ERR(regulator->rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) dev_err(&pdev->dev, "Failed to register regulator %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) regulator->info->reg_desc.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return PTR_ERR(regulator->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* Only LDO 5 and 6 has got the over current interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) irq = platform_get_irq_byname(pdev, "REGULATOR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) da9055_ldo5_6_oc_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) IRQF_TRIGGER_HIGH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) IRQF_ONESHOT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) IRQF_PROBE_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pdev->name, regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (ret != -EBUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) "Failed to request Regulator IRQ %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) irq, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) platform_set_drvdata(pdev, regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static struct platform_driver da9055_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .probe = da9055_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) .name = "da9055-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static int __init da9055_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return platform_driver_register(&da9055_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) subsys_initcall(da9055_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static void __exit da9055_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) platform_driver_unregister(&da9055_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) module_exit(da9055_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9055 PMIC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) MODULE_ALIAS("platform:da9055-regulator");