^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Regulator driver for TI TPS65912x PMICs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Andrew F. Davis <afd@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * modify it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * This program is distributed "as is" WITHOUT ANY WARRANTY of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * kind, whether expressed or implied; without even the implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * GNU General Public License version 2 for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Based on the TPS65218 driver and the previous TPS65912 driver by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mfd/tps65912.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) enum tps65912_regulators { DCDC1, DCDC2, DCDC3, DCDC4, LDO1, LDO2, LDO3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) LDO4, LDO5, LDO6, LDO7, LDO8, LDO9, LDO10 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define TPS65912_REGULATOR(_name, _id, _of_match, _ops, _vr, _er, _lr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) [_id] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .name = _name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .of_match = _of_match, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .regulators_node = "regulators", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .id = _id, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .ops = &_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .n_voltages = 64, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .vsel_reg = _vr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .vsel_mask = 0x3f, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .enable_reg = _er, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .enable_mask = BIT(7), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .volt_table = NULL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .linear_ranges = _lr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .n_linear_ranges = ARRAY_SIZE(_lr), \
^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) static const struct linear_range tps65912_dcdc_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) REGULATOR_LINEAR_RANGE(500000, 0x0, 0x3f, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static const struct linear_range tps65912_ldo_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) REGULATOR_LINEAR_RANGE(800000, 0x0, 0x20, 25000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) REGULATOR_LINEAR_RANGE(1650000, 0x21, 0x3c, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) REGULATOR_LINEAR_RANGE(3100000, 0x3d, 0x3f, 100000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* Operations permitted on DCDCx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static const struct regulator_ops tps65912_ops_dcdc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Operations permitted on LDOx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static const struct regulator_ops tps65912_ops_ldo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .map_voltage = regulator_map_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static const struct regulator_desc regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) TPS65912_REGULATOR("DCDC1", DCDC1, "dcdc1", tps65912_ops_dcdc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) TPS65912_DCDC1_OP, TPS65912_DCDC1_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) tps65912_dcdc_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) TPS65912_REGULATOR("DCDC2", DCDC2, "dcdc2", tps65912_ops_dcdc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) TPS65912_DCDC2_OP, TPS65912_DCDC2_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) tps65912_dcdc_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) TPS65912_REGULATOR("DCDC3", DCDC3, "dcdc3", tps65912_ops_dcdc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) TPS65912_DCDC3_OP, TPS65912_DCDC3_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) tps65912_dcdc_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) TPS65912_REGULATOR("DCDC4", DCDC4, "dcdc4", tps65912_ops_dcdc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) TPS65912_DCDC4_OP, TPS65912_DCDC4_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) tps65912_dcdc_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) TPS65912_REGULATOR("LDO1", LDO1, "ldo1", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) TPS65912_LDO1_OP, TPS65912_LDO1_AVS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) TPS65912_REGULATOR("LDO2", LDO2, "ldo2", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) TPS65912_LDO2_OP, TPS65912_LDO2_AVS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) TPS65912_REGULATOR("LDO3", LDO3, "ldo3", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) TPS65912_LDO3_OP, TPS65912_LDO3_AVS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) TPS65912_REGULATOR("LDO4", LDO4, "ldo4", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) TPS65912_LDO4_OP, TPS65912_LDO4_AVS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) TPS65912_REGULATOR("LDO5", LDO5, "ldo5", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) TPS65912_LDO5, TPS65912_LDO5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) TPS65912_REGULATOR("LDO6", LDO6, "ldo6", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) TPS65912_LDO6, TPS65912_LDO6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) TPS65912_REGULATOR("LDO7", LDO7, "ldo7", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) TPS65912_LDO7, TPS65912_LDO7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) TPS65912_REGULATOR("LDO8", LDO8, "ldo8", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) TPS65912_LDO8, TPS65912_LDO8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) TPS65912_REGULATOR("LDO9", LDO9, "ldo9", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) TPS65912_LDO9, TPS65912_LDO9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) tps65912_ldo_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) TPS65912_REGULATOR("LDO10", LDO10, "ldo10", tps65912_ops_ldo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) TPS65912_LDO10, TPS65912_LDO10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) tps65912_ldo_ranges),
^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 tps65912_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct tps65912 *tps = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) platform_set_drvdata(pdev, tps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) config.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) config.driver_data = tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) config.dev->of_node = tps->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) config.regmap = tps->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) for (i = 0; i < ARRAY_SIZE(regulators); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) dev_err(tps->dev, "failed to register %s regulator\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) pdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return PTR_ERR(rdev);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static const struct platform_device_id tps65912_regulator_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) { "tps65912-regulator", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) MODULE_DEVICE_TABLE(platform, tps65912_regulator_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static struct platform_driver tps65912_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .name = "tps65912-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .probe = tps65912_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .id_table = tps65912_regulator_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) module_platform_driver(tps65912_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) MODULE_DESCRIPTION("TPS65912 voltage regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) MODULE_LICENSE("GPL v2");