^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) * max8907-regulator.c -- support regulators in max8907
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2010 Gyungoh Yoo <jack.yoo@maxim-ic.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2010-2012, NVIDIA CORPORATION. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Portions based on drivers/regulator/tps65910-regulator.c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright 2010 Texas Instruments Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Author: Graeme Gregory <gg@slimlogic.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mfd/max8907.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define MAX8907_II2RR_VERSION_MASK 0xF0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define MAX8907_II2RR_VERSION_REV_A 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define MAX8907_II2RR_VERSION_REV_B 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define MAX8907_II2RR_VERSION_REV_C 0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct max8907_regulator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct regulator_desc desc[MAX8907_NUM_REGULATORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define REG_MBATT() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) [MAX8907_MBATT] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .name = "MBATT", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .supply_name = "mbatt", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .id = MAX8907_MBATT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .ops = &max8907_mbatt_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define REG_LDO(ids, supply, base, min, max, step) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) [MAX8907_##ids] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .name = #ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .supply_name = supply, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .id = MAX8907_##ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .n_voltages = ((max) - (min)) / (step) + 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .ops = &max8907_ldo_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .min_uV = (min), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .uV_step = (step), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .vsel_reg = (base) + MAX8907_VOUT, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .vsel_mask = 0x3f, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .enable_reg = (base) + MAX8907_CTL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .enable_mask = MAX8907_MASK_LDO_EN, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define REG_FIXED(ids, supply, voltage) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) [MAX8907_##ids] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .name = #ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .supply_name = supply, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .id = MAX8907_##ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .n_voltages = 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .ops = &max8907_fixed_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .min_uV = (voltage), \
^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) #define REG_OUT5V(ids, supply, base, voltage) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) [MAX8907_##ids] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .name = #ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .supply_name = supply, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .id = MAX8907_##ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .n_voltages = 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .ops = &max8907_out5v_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .min_uV = (voltage), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .enable_reg = (base), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .enable_mask = MAX8907_MASK_OUT5V_EN, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define REG_BBAT(ids, supply, base, min, max, step) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) [MAX8907_##ids] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .name = #ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .supply_name = supply, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .id = MAX8907_##ids, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .n_voltages = ((max) - (min)) / (step) + 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .ops = &max8907_bbat_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .min_uV = (min), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .uV_step = (step), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .vsel_reg = (base), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .vsel_mask = MAX8907_MASK_VBBATTCV, \
^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) #define LDO_750_50(id, supply, base) REG_LDO(id, supply, (base), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 750000, 3900000, 50000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define LDO_650_25(id, supply, base) REG_LDO(id, supply, (base), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 650000, 2225000, 25000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static const struct regulator_ops max8907_mbatt_ops = {
^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 regulator_ops max8907_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const struct regulator_ops max8907_ldo_hwctl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static const struct regulator_ops max8907_fixed_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static const struct regulator_ops max8907_out5v_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .is_enabled = regulator_is_enabled_regmap,
^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_ops max8907_out5v_hwctl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static const struct regulator_ops max8907_bbat_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static const struct regulator_desc max8907_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) REG_MBATT(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) REG_LDO(SD1, "in-v1", MAX8907_REG_SDCTL1, 650000, 2225000, 25000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) REG_LDO(SD2, "in-v2", MAX8907_REG_SDCTL2, 637500, 1425000, 12500),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) REG_LDO(SD3, "in-v3", MAX8907_REG_SDCTL3, 750000, 3900000, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) LDO_750_50(LDO1, "in1", MAX8907_REG_LDOCTL1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) LDO_650_25(LDO2, "in2", MAX8907_REG_LDOCTL2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) LDO_650_25(LDO3, "in3", MAX8907_REG_LDOCTL3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) LDO_750_50(LDO4, "in4", MAX8907_REG_LDOCTL4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) LDO_750_50(LDO5, "in5", MAX8907_REG_LDOCTL5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) LDO_750_50(LDO6, "in6", MAX8907_REG_LDOCTL6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) LDO_750_50(LDO7, "in7", MAX8907_REG_LDOCTL7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) LDO_750_50(LDO8, "in8", MAX8907_REG_LDOCTL8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) LDO_750_50(LDO9, "in9", MAX8907_REG_LDOCTL9),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) LDO_750_50(LDO10, "in10", MAX8907_REG_LDOCTL10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) LDO_750_50(LDO11, "in11", MAX8907_REG_LDOCTL11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) LDO_750_50(LDO12, "in12", MAX8907_REG_LDOCTL12),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) LDO_750_50(LDO13, "in13", MAX8907_REG_LDOCTL13),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) LDO_750_50(LDO14, "in14", MAX8907_REG_LDOCTL14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) LDO_750_50(LDO15, "in15", MAX8907_REG_LDOCTL15),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) LDO_750_50(LDO16, "in16", MAX8907_REG_LDOCTL16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) LDO_650_25(LDO17, "in17", MAX8907_REG_LDOCTL17),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) LDO_650_25(LDO18, "in18", MAX8907_REG_LDOCTL18),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) LDO_750_50(LDO19, "in19", MAX8907_REG_LDOCTL19),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) LDO_750_50(LDO20, "in20", MAX8907_REG_LDOCTL20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) REG_OUT5V(OUT5V, "mbatt", MAX8907_REG_OUT5VEN, 5000000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) REG_OUT5V(OUT33V, "mbatt", MAX8907_REG_OUT33VEN, 3300000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) REG_BBAT(BBAT, "MBATT", MAX8907_REG_BBAT_CNFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 2400000, 3000000, 200000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) REG_FIXED(SDBY, "MBATT", 1200000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) REG_FIXED(VRTC, "MBATT", 3300000),
^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) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define MATCH(_name, _id) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) [MAX8907_##_id] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .name = #_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .driver_data = (void *)&max8907_regulators[MAX8907_##_id], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static struct of_regulator_match max8907_matches[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) MATCH(mbatt, MBATT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) MATCH(sd1, SD1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) MATCH(sd2, SD2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) MATCH(sd3, SD3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) MATCH(ldo1, LDO1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) MATCH(ldo2, LDO2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) MATCH(ldo3, LDO3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) MATCH(ldo4, LDO4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) MATCH(ldo5, LDO5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) MATCH(ldo6, LDO6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) MATCH(ldo7, LDO7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) MATCH(ldo8, LDO8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) MATCH(ldo9, LDO9),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) MATCH(ldo10, LDO10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) MATCH(ldo11, LDO11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) MATCH(ldo12, LDO12),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) MATCH(ldo13, LDO13),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) MATCH(ldo14, LDO14),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) MATCH(ldo15, LDO15),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) MATCH(ldo16, LDO16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) MATCH(ldo17, LDO17),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) MATCH(ldo18, LDO18),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) MATCH(ldo19, LDO19),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) MATCH(ldo20, LDO20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) MATCH(out5v, OUT5V),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) MATCH(out33v, OUT33V),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) MATCH(bbat, BBAT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) MATCH(sdby, SDBY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) MATCH(vrtc, VRTC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int max8907_regulator_parse_dt(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct device_node *np, *regulators;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) np = pdev->dev.parent->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) regulators = of_get_child_by_name(np, "regulators");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!regulators) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) dev_err(&pdev->dev, "regulators node not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ret = of_regulator_match(&pdev->dev, regulators, max8907_matches,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ARRAY_SIZE(max8907_matches));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) of_node_put(regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return ret;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static inline struct regulator_init_data *match_init_data(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return max8907_matches[index].init_data;
^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) static inline struct device_node *match_of_node(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return max8907_matches[index].of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static int max8907_regulator_parse_dt(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^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 inline struct regulator_init_data *match_init_data(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static inline struct device_node *match_of_node(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int max8907_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct max8907 *max8907 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct max8907_platform_data *pdata = dev_get_platdata(max8907->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct max8907_regulator *pmic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct regulator_config config = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) struct regulator_init_data *idata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) const char *mbatt_rail_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret = max8907_regulator_parse_dt(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!pmic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) platform_set_drvdata(pdev, pmic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* Backwards compatibility with MAX8907B; SD1 uses different voltages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ret = regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if ((val & MAX8907_II2RR_VERSION_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) MAX8907_II2RR_VERSION_REV_B) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) pmic->desc[MAX8907_SD1].min_uV = 637500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) pmic->desc[MAX8907_SD1].uV_step = 12500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) pmic->desc[MAX8907_SD1].n_voltages =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) (1425000 - 637500) / 12500 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) for (i = 0; i < MAX8907_NUM_REGULATORS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) config.dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) idata = pdata->init_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) idata = match_init_data(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) config.init_data = idata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) config.driver_data = pmic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) config.regmap = max8907->regmap_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) config.of_node = match_of_node(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) switch (pmic->desc[i].id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) case MAX8907_MBATT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (idata && idata->constraints.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) mbatt_rail_name = idata->constraints.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) mbatt_rail_name = pmic->desc[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) case MAX8907_BBAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) case MAX8907_SDBY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) case MAX8907_VRTC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) idata->supply_regulator = mbatt_rail_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (pmic->desc[i].ops == &max8907_ldo_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ret = regmap_read(config.regmap, pmic->desc[i].enable_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if ((val & MAX8907_MASK_LDO_SEQ) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) MAX8907_MASK_LDO_SEQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) pmic->desc[i].ops = &max8907_ldo_hwctl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) } else if (pmic->desc[i].ops == &max8907_out5v_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ret = regmap_read(config.regmap, pmic->desc[i].enable_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if ((val & (MAX8907_MASK_OUT5V_VINEN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) MAX8907_MASK_OUT5V_ENSRC)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) MAX8907_MASK_OUT5V_ENSRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) pmic->desc[i].ops = &max8907_out5v_hwctl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) rdev = devm_regulator_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) &pmic->desc[i], &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) "failed to register %s regulator\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) pmic->desc[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static struct platform_driver max8907_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .name = "max8907-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .probe = max8907_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int __init max8907_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return platform_driver_register(&max8907_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) subsys_initcall(max8907_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static void __exit max8907_reg_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) platform_driver_unregister(&max8907_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) module_exit(max8907_reg_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) MODULE_DESCRIPTION("MAX8907 regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@maxim-ic.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) MODULE_ALIAS("platform:max8907-regulator");