Linux Audio

Check our new training course

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