File Index
Files and directories
Sign in
FILE

tps65219-regulator.c

File preview with syntax highlighting.

linux-6.19.14/drivers/regulator/tps65219-regulator.c C
  1// SPDX-License-Identifier: GPL-2.0
  2//
  3// TPS65214/TPS65215/TPS65219 PMIC Regulator Driver
  4//
  5// Copyright (C) 2022 BayLibre Incorporated - https://www.baylibre.com/
  6// Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
  7//
  8// This implementation derived from tps65218 authored by
  9// "J Keerthy <j-keerthy@ti.com>"
 10//
 11
 12#include <linux/kernel.h>
 13#include <linux/module.h>
 14#include <linux/device.h>
 15#include <linux/init.h>
 16#include <linux/err.h>
 17#include <linux/of.h>
 18#include <linux/platform_device.h>
 19#include <linux/regmap.h>
 20#include <linux/regulator/of_regulator.h>
 21#include <linux/regulator/driver.h>
 22#include <linux/regulator/machine.h>
 23#include <linux/mfd/tps65219.h>
 24
 25struct tps65219_regulator_irq_type {
 26	const char *irq_name;
 27	const char *regulator_name;
 28	const char *event_name;
 29	unsigned long event;
 30};
 31
 32static struct tps65219_regulator_irq_type tps65215_regulator_irq_types[] = {
 33	{ "SENSOR_3_WARM", "SENSOR3", "warm temperature", REGULATOR_EVENT_OVER_TEMP_WARN},
 34	{ "SENSOR_3_HOT", "SENSOR3", "hot temperature", REGULATOR_EVENT_OVER_TEMP},
 35};
 36
 37static struct tps65219_regulator_irq_type tps65219_regulator_irq_types[] = {
 38	{ "LDO3_SCG", "LDO3", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 39	{ "LDO3_OC", "LDO3", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 40	{ "LDO3_UV", "LDO3", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 41	{ "LDO4_SCG", "LDO4", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 42	{ "LDO4_OC", "LDO4", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 43	{ "LDO4_UV", "LDO4", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 44	{ "LDO3_RV", "LDO3", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 45	{ "LDO4_RV", "LDO4", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 46	{ "LDO3_RV_SD", "LDO3", "residual voltage on shutdown", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 47	{ "LDO4_RV_SD", "LDO4", "residual voltage on shutdown", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 48	{ "SENSOR_3_WARM", "SENSOR3", "warm temperature", REGULATOR_EVENT_OVER_TEMP_WARN},
 49	{ "SENSOR_3_HOT", "SENSOR3", "hot temperature", REGULATOR_EVENT_OVER_TEMP},
 50};
 51
 52/*  All of TPS65214's irq types are the same as common_regulator_irq_types */
 53static struct tps65219_regulator_irq_type common_regulator_irq_types[] = {
 54	{ "LDO1_SCG", "LDO1", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 55	{ "LDO1_OC", "LDO1", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 56	{ "LDO1_UV", "LDO1", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 57	{ "LDO2_SCG", "LDO2", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 58	{ "LDO2_OC", "LDO2", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 59	{ "LDO2_UV", "LDO2", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 60	{ "BUCK3_SCG", "BUCK3", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 61	{ "BUCK3_OC", "BUCK3", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 62	{ "BUCK3_NEG_OC", "BUCK3", "negative overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 63	{ "BUCK3_UV", "BUCK3", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 64	{ "BUCK1_SCG", "BUCK1", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 65	{ "BUCK1_OC", "BUCK1", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 66	{ "BUCK1_NEG_OC", "BUCK1", "negative overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 67	{ "BUCK1_UV", "BUCK1", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 68	{ "BUCK2_SCG", "BUCK2", "short circuit to ground", REGULATOR_EVENT_REGULATION_OUT },
 69	{ "BUCK2_OC", "BUCK2", "overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 70	{ "BUCK2_NEG_OC", "BUCK2", "negative overcurrent", REGULATOR_EVENT_OVER_CURRENT },
 71	{ "BUCK2_UV", "BUCK2", "undervoltage", REGULATOR_EVENT_UNDER_VOLTAGE },
 72	{ "BUCK1_RV", "BUCK1", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 73	{ "BUCK2_RV", "BUCK2", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 74	{ "BUCK3_RV", "BUCK3", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 75	{ "LDO1_RV", "LDO1", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 76	{ "LDO2_RV", "LDO2", "residual voltage", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 77	{ "BUCK1_RV_SD", "BUCK1", "residual voltage on shutdown",
 78	 REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 79	{ "BUCK2_RV_SD", "BUCK2", "residual voltage on shutdown",
 80	 REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 81	{ "BUCK3_RV_SD", "BUCK3", "residual voltage on shutdown",
 82	 REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 83	{ "LDO1_RV_SD", "LDO1", "residual voltage on shutdown", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 84	{ "LDO2_RV_SD", "LDO2", "residual voltage on shutdown", REGULATOR_EVENT_OVER_VOLTAGE_WARN },
 85	{ "SENSOR_2_WARM", "SENSOR2", "warm temperature", REGULATOR_EVENT_OVER_TEMP_WARN },
 86	{ "SENSOR_1_WARM", "SENSOR1", "warm temperature", REGULATOR_EVENT_OVER_TEMP_WARN },
 87	{ "SENSOR_0_WARM", "SENSOR0", "warm temperature", REGULATOR_EVENT_OVER_TEMP_WARN },
 88	{ "SENSOR_2_HOT", "SENSOR2", "hot temperature", REGULATOR_EVENT_OVER_TEMP },
 89	{ "SENSOR_1_HOT", "SENSOR1", "hot temperature", REGULATOR_EVENT_OVER_TEMP },
 90	{ "SENSOR_0_HOT", "SENSOR0", "hot temperature", REGULATOR_EVENT_OVER_TEMP },
 91	{ "TIMEOUT", "", "", REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE },
 92};
 93
 94struct tps65219_regulator_irq_data {
 95	struct device *dev;
 96	struct tps65219_regulator_irq_type *type;
 97	struct regulator_dev *rdev;
 98};
 99
100#define TPS65219_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \
101			   _em, _cr, _cm, _lr, _nlr, _delay, _fuv, \
102			   _ct, _ncl, _bpm) \
103	{								\
104		.name			= _name,			\
105		.of_match		= _of,				\
106		.regulators_node	= of_match_ptr("regulators"),	\
107		.supply_name		= _of,				\
108		.id			= _id,				\
109		.ops			= &(_ops),			\
110		.n_voltages		= _n,				\
111		.type			= _type,			\
112		.owner			= THIS_MODULE,			\
113		.vsel_reg		= _vr,				\
114		.vsel_mask		= _vm,				\
115		.csel_reg		= _cr,				\
116		.csel_mask		= _cm,				\
117		.curr_table		= _ct,				\
118		.n_current_limits	= _ncl,				\
119		.enable_reg		= _er,				\
120		.enable_mask		= _em,				\
121		.volt_table		= NULL,				\
122		.linear_ranges		= _lr,				\
123		.n_linear_ranges	= _nlr,				\
124		.ramp_delay		= _delay,			\
125		.fixed_uV		= _fuv,				\
126		.bypass_reg		= _vr,				\
127		.bypass_mask		= _bpm,				\
128	}								\
129
130static const struct linear_range bucks_ranges[] = {
131	REGULATOR_LINEAR_RANGE(600000, 0x0, 0x1f, 25000),
132	REGULATOR_LINEAR_RANGE(1400000, 0x20, 0x33, 100000),
133	REGULATOR_LINEAR_RANGE(3400000, 0x34, 0x3f, 0),
134};
135
136static const struct linear_range ldo_1_range[] = {
137	REGULATOR_LINEAR_RANGE(600000, 0x0, 0x37, 50000),
138	REGULATOR_LINEAR_RANGE(3400000, 0x38, 0x3f, 0),
139};
140
141static const struct linear_range tps65214_ldo_1_2_range[] = {
142	REGULATOR_LINEAR_RANGE(600000, 0x0, 0x2, 0),
143	REGULATOR_LINEAR_RANGE(650000, 0x3, 0x37, 50000),
144	REGULATOR_LINEAR_RANGE(3300000, 0x38, 0x3F, 0),
145};
146
147static const struct linear_range tps65215_ldo_2_range[] = {
148	REGULATOR_LINEAR_RANGE(1200000, 0x0, 0xC, 50000),
149	REGULATOR_LINEAR_RANGE(3300000, 0x36, 0x3F, 0),
150};
151
152static const struct linear_range tps65219_ldo_2_range[] = {
153	REGULATOR_LINEAR_RANGE(600000, 0x0, 0x37, 50000),
154	REGULATOR_LINEAR_RANGE(3400000, 0x38, 0x3f, 0),
155};
156
157static const struct linear_range tps65219_ldos_3_4_range[] = {
158	REGULATOR_LINEAR_RANGE(1200000, 0x0, 0xC, 0),
159	REGULATOR_LINEAR_RANGE(1250000, 0xD, 0x35, 50000),
160	REGULATOR_LINEAR_RANGE(3300000, 0x36, 0x3F, 0),
161};
162
163static int tps65219_set_mode(struct regulator_dev *dev, unsigned int mode)
164{
165	struct tps65219 *tps = rdev_get_drvdata(dev);
166
167	switch (mode) {
168	case REGULATOR_MODE_NORMAL:
169		return regmap_set_bits(tps->regmap, TPS65219_REG_STBY_1_CONFIG,
170				       dev->desc->enable_mask);
171
172	case REGULATOR_MODE_STANDBY:
173		return regmap_clear_bits(tps->regmap,
174					 TPS65219_REG_STBY_1_CONFIG,
175					 dev->desc->enable_mask);
176	default:
177		return -EINVAL;
178	}
179}
180
181static unsigned int tps65219_get_mode(struct regulator_dev *dev)
182{
183	struct tps65219 *tps = rdev_get_drvdata(dev);
184	unsigned int rid = rdev_get_id(dev);
185	int ret, value = 0;
186
187	ret = regmap_read(tps->regmap, TPS65219_REG_STBY_1_CONFIG, &value);
188	if (ret) {
189		dev_dbg(tps->dev, "%s failed for regulator %s: %d ",
190			__func__, dev->desc->name, ret);
191		return ret;
192	}
193	value = (value & BIT(rid)) >> rid;
194	if (value)
195		return REGULATOR_MODE_STANDBY;
196	else
197		return REGULATOR_MODE_NORMAL;
198}
199
200/* Operations permitted on BUCK1/2/3 */
201static const struct regulator_ops bucks_ops = {
202	.is_enabled		= regulator_is_enabled_regmap,
203	.enable			= regulator_enable_regmap,
204	.disable		= regulator_disable_regmap,
205	.set_mode		= tps65219_set_mode,
206	.get_mode		= tps65219_get_mode,
207	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
208	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
209	.list_voltage		= regulator_list_voltage_linear_range,
210	.map_voltage		= regulator_map_voltage_linear_range,
211	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
212
213};
214
215/* Operations permitted on LDO1/2 */
216static const struct regulator_ops ldos_1_2_ops = {
217	.is_enabled		= regulator_is_enabled_regmap,
218	.enable			= regulator_enable_regmap,
219	.disable		= regulator_disable_regmap,
220	.set_mode		= tps65219_set_mode,
221	.get_mode		= tps65219_get_mode,
222	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
223	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
224	.list_voltage		= regulator_list_voltage_linear_range,
225	.map_voltage		= regulator_map_voltage_linear_range,
226	.set_bypass		= regulator_set_bypass_regmap,
227	.get_bypass		= regulator_get_bypass_regmap,
228};
229
230/* Operations permitted on LDO3/4 */
231static const struct regulator_ops ldos_3_4_ops = {
232	.is_enabled		= regulator_is_enabled_regmap,
233	.enable			= regulator_enable_regmap,
234	.disable		= regulator_disable_regmap,
235	.set_mode		= tps65219_set_mode,
236	.get_mode		= tps65219_get_mode,
237	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
238	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
239	.list_voltage		= regulator_list_voltage_linear_range,
240	.map_voltage		= regulator_map_voltage_linear_range,
241};
242
243static const struct regulator_desc common_regs[] = {
244	TPS65219_REGULATOR("BUCK1", "buck1", TPS65219_BUCK_1,
245			   REGULATOR_VOLTAGE, bucks_ops, 64,
246			   TPS65219_REG_BUCK1_VOUT,
247			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
248			   TPS65219_REG_ENABLE_CTRL,
249			   TPS65219_ENABLE_BUCK1_EN_MASK, 0, 0, bucks_ranges,
250			   3, 4000, 0, NULL, 0, 0),
251	TPS65219_REGULATOR("BUCK2", "buck2", TPS65219_BUCK_2,
252			   REGULATOR_VOLTAGE, bucks_ops, 64,
253			   TPS65219_REG_BUCK2_VOUT,
254			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
255			   TPS65219_REG_ENABLE_CTRL,
256			   TPS65219_ENABLE_BUCK2_EN_MASK, 0, 0, bucks_ranges,
257			   3, 4000, 0, NULL, 0, 0),
258	TPS65219_REGULATOR("BUCK3", "buck3", TPS65219_BUCK_3,
259			   REGULATOR_VOLTAGE, bucks_ops, 64,
260			   TPS65219_REG_BUCK3_VOUT,
261			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
262			   TPS65219_REG_ENABLE_CTRL,
263			   TPS65219_ENABLE_BUCK3_EN_MASK, 0, 0, bucks_ranges,
264			   3, 0, 0, NULL, 0, 0),
265};
266
267static const struct regulator_desc tps65214_regs[] = {
268	// TPS65214's LDO3 pin maps to TPS65219's LDO3 pin
269	TPS65219_REGULATOR("LDO1", "ldo1", TPS65214_LDO_1,
270			   REGULATOR_VOLTAGE, ldos_3_4_ops, 64,
271			   TPS65214_REG_LDO1_VOUT,
272			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
273			   TPS65219_REG_ENABLE_CTRL,
274			   TPS65219_ENABLE_LDO3_EN_MASK, 0, 0, tps65214_ldo_1_2_range,
275			   3, 0, 0, NULL, 0, 0),
276	TPS65219_REGULATOR("LDO2", "ldo2", TPS65214_LDO_2,
277			   REGULATOR_VOLTAGE, ldos_3_4_ops, 64,
278			   TPS65214_REG_LDO2_VOUT,
279			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
280			   TPS65219_REG_ENABLE_CTRL,
281			   TPS65219_ENABLE_LDO2_EN_MASK, 0, 0, tps65214_ldo_1_2_range,
282			   3, 0, 0, NULL, 0, 0),
283};
284
285static const struct regulator_desc tps65215_regs[] = {
286	/*
287	 *  TPS65215's LDO1 is the same as TPS65219's LDO1. LDO1 is
288	 *  configurable as load switch and bypass-mode.
289	 *  TPS65215's LDO2 is the same as TPS65219's LDO3
290	 */
291	TPS65219_REGULATOR("LDO1", "ldo1", TPS65219_LDO_1,
292			   REGULATOR_VOLTAGE, ldos_1_2_ops, 64,
293			   TPS65219_REG_LDO1_VOUT,
294			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
295			   TPS65219_REG_ENABLE_CTRL,
296			   TPS65219_ENABLE_LDO1_EN_MASK, 0, 0, ldo_1_range,
297			   2, 0, 0, NULL, 0, TPS65219_LDOS_BYP_CONFIG_MASK),
298	TPS65219_REGULATOR("LDO2", "ldo2", TPS65215_LDO_2,
299			   REGULATOR_VOLTAGE, ldos_3_4_ops, 64,
300			   TPS65215_REG_LDO2_VOUT,
301			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
302			   TPS65219_REG_ENABLE_CTRL,
303			   TPS65215_ENABLE_LDO2_EN_MASK, 0, 0, tps65215_ldo_2_range,
304			   2, 0, 0, NULL, 0, 0),
305};
306
307static const struct regulator_desc tps65219_regs[] = {
308	TPS65219_REGULATOR("LDO1", "ldo1", TPS65219_LDO_1,
309			   REGULATOR_VOLTAGE, ldos_1_2_ops, 64,
310			   TPS65219_REG_LDO1_VOUT,
311			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
312			   TPS65219_REG_ENABLE_CTRL,
313			   TPS65219_ENABLE_LDO1_EN_MASK, 0, 0, ldo_1_range,
314			   2, 0, 0, NULL, 0, TPS65219_LDOS_BYP_CONFIG_MASK),
315	TPS65219_REGULATOR("LDO2", "ldo2", TPS65219_LDO_2,
316			   REGULATOR_VOLTAGE, ldos_1_2_ops, 64,
317			   TPS65219_REG_LDO2_VOUT,
318			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
319			   TPS65219_REG_ENABLE_CTRL,
320			   TPS65219_ENABLE_LDO2_EN_MASK, 0, 0, tps65219_ldo_2_range,
321			   2, 0, 0, NULL, 0, TPS65219_LDOS_BYP_CONFIG_MASK),
322	TPS65219_REGULATOR("LDO3", "ldo3", TPS65219_LDO_3,
323			   REGULATOR_VOLTAGE, ldos_3_4_ops, 64,
324			   TPS65219_REG_LDO3_VOUT,
325			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
326			   TPS65219_REG_ENABLE_CTRL,
327			   TPS65219_ENABLE_LDO3_EN_MASK, 0, 0, tps65219_ldos_3_4_range,
328			   3, 0, 0, NULL, 0, 0),
329	TPS65219_REGULATOR("LDO4", "ldo4", TPS65219_LDO_4,
330			   REGULATOR_VOLTAGE, ldos_3_4_ops, 64,
331			   TPS65219_REG_LDO4_VOUT,
332			   TPS65219_BUCKS_LDOS_VOUT_VSET_MASK,
333			   TPS65219_REG_ENABLE_CTRL,
334			   TPS65219_ENABLE_LDO4_EN_MASK, 0, 0, tps65219_ldos_3_4_range,
335			   3, 0, 0, NULL, 0, 0),
336};
337
338static irqreturn_t tps65219_regulator_irq_handler(int irq, void *data)
339{
340	struct tps65219_regulator_irq_data *irq_data = data;
341
342	if (irq_data->type->event_name[0] == '\0') {
343		/* This is the timeout interrupt no specific regulator */
344		dev_err(irq_data->dev,
345			"System was put in shutdown due to timeout during an active or standby transition.\n");
346		return IRQ_HANDLED;
347	}
348
349	regulator_notifier_call_chain(irq_data->rdev,
350				      irq_data->type->event, NULL);
351
352	dev_err(irq_data->dev, "Error IRQ trap %s for %s\n",
353		irq_data->type->event_name, irq_data->type->regulator_name);
354	return IRQ_HANDLED;
355}
356
357struct tps65219_chip_data {
358	size_t rdesc_size;
359	size_t common_rdesc_size;
360	size_t dev_irq_size;
361	size_t common_irq_size;
362	const struct regulator_desc *rdesc;
363	const struct regulator_desc *common_rdesc;
364	struct tps65219_regulator_irq_type *irq_types;
365	struct tps65219_regulator_irq_type *common_irq_types;
366};
367
368static struct tps65219_chip_data chip_info_table[] = {
369	[TPS65214] = {
370		.rdesc = tps65214_regs,
371		.rdesc_size = ARRAY_SIZE(tps65214_regs),
372		.common_rdesc = common_regs,
373		.common_rdesc_size = ARRAY_SIZE(common_regs),
374		.irq_types = NULL,
375		.dev_irq_size = 0,
376		.common_irq_types = common_regulator_irq_types,
377		.common_irq_size = ARRAY_SIZE(common_regulator_irq_types),
378	},
379	[TPS65215] = {
380		.rdesc = tps65215_regs,
381		.rdesc_size = ARRAY_SIZE(tps65215_regs),
382		.common_rdesc = common_regs,
383		.common_rdesc_size = ARRAY_SIZE(common_regs),
384		.irq_types = tps65215_regulator_irq_types,
385		.dev_irq_size = ARRAY_SIZE(tps65215_regulator_irq_types),
386		.common_irq_types = common_regulator_irq_types,
387		.common_irq_size = ARRAY_SIZE(common_regulator_irq_types),
388	},
389	[TPS65219] = {
390		.rdesc = tps65219_regs,
391		.rdesc_size = ARRAY_SIZE(tps65219_regs),
392		.common_rdesc = common_regs,
393		.common_rdesc_size = ARRAY_SIZE(common_regs),
394		.irq_types = tps65219_regulator_irq_types,
395		.dev_irq_size = ARRAY_SIZE(tps65219_regulator_irq_types),
396		.common_irq_types = common_regulator_irq_types,
397		.common_irq_size = ARRAY_SIZE(common_regulator_irq_types),
398	},
399};
400
401static int tps65219_regulator_probe(struct platform_device *pdev)
402{
403	struct tps65219_regulator_irq_data *irq_data;
404	struct tps65219_regulator_irq_type *irq_type;
405	struct tps65219_chip_data *pmic;
406	struct regulator_dev *rdev;
407	int error;
408	int irq;
409	int i;
410
411	struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
412	struct regulator_config config = { };
413	enum pmic_id chip = platform_get_device_id(pdev)->driver_data;
414
415	pmic = &chip_info_table[chip];
416
417	config.dev = tps->dev;
418	config.driver_data = tps;
419	config.regmap = tps->regmap;
420
421	for (i = 0; i <  pmic->common_rdesc_size; i++) {
422		rdev = devm_regulator_register(&pdev->dev, &pmic->common_rdesc[i],
423					       &config);
424		if (IS_ERR(rdev))
425			return dev_err_probe(tps->dev, PTR_ERR(rdev),
426					      "Failed to register %s regulator\n",
427					      pmic->common_rdesc[i].name);
428	}
429
430	for (i = 0; i <  pmic->rdesc_size; i++) {
431		rdev = devm_regulator_register(&pdev->dev, &pmic->rdesc[i],
432					       &config);
433		if (IS_ERR(rdev))
434			return dev_err_probe(tps->dev, PTR_ERR(rdev),
435					     "Failed to register %s regulator\n",
436					     pmic->rdesc[i].name);
437	}
438
439	for (i = 0; i < pmic->common_irq_size; ++i) {
440		irq_type = &pmic->common_irq_types[i];
441		irq = platform_get_irq_byname(pdev, irq_type->irq_name);
442		if (irq < 0)
443			return -EINVAL;
444
445		irq_data = devm_kmalloc(tps->dev, sizeof(*irq_data), GFP_KERNEL);
446		if (!irq_data)
447			return -ENOMEM;
448
449		irq_data->dev = tps->dev;
450		irq_data->type = irq_type;
451		error = devm_request_threaded_irq(tps->dev, irq, NULL,
452						  tps65219_regulator_irq_handler,
453						  IRQF_ONESHOT,
454						  irq_type->irq_name,
455						  irq_data);
456		if (error)
457			return dev_err_probe(tps->dev, error,
458					     "Failed to request %s IRQ %d\n",
459					     irq_type->irq_name, irq);
460	}
461
462	for (i = 0; i < pmic->dev_irq_size; ++i) {
463		irq_type = &pmic->irq_types[i];
464		irq = platform_get_irq_byname(pdev, irq_type->irq_name);
465		if (irq < 0)
466			return -EINVAL;
467
468		irq_data = devm_kmalloc(tps->dev, sizeof(*irq_data), GFP_KERNEL);
469		if (!irq_data)
470			return -ENOMEM;
471
472		irq_data->dev = tps->dev;
473		irq_data->type = irq_type;
474		error = devm_request_threaded_irq(tps->dev, irq, NULL,
475						  tps65219_regulator_irq_handler,
476						  IRQF_ONESHOT,
477						  irq_type->irq_name,
478						  irq_data);
479		if (error)
480			return dev_err_probe(tps->dev, error,
481					     "Failed to request %s IRQ %d\n",
482					     irq_type->irq_name, irq);
483	}
484
485	return 0;
486}
487
488static const struct platform_device_id tps65219_regulator_id_table[] = {
489	{ "tps65214-regulator", TPS65214 },
490	{ "tps65215-regulator", TPS65215 },
491	{ "tps65219-regulator", TPS65219 },
492	{ /* sentinel */ }
493};
494MODULE_DEVICE_TABLE(platform, tps65219_regulator_id_table);
495
496static struct platform_driver tps65219_regulator_driver = {
497	.driver = {
498		.name = "tps65219-regulator",
499		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
500	},
501	.probe = tps65219_regulator_probe,
502	.id_table = tps65219_regulator_id_table,
503};
504
505module_platform_driver(tps65219_regulator_driver);
506
507MODULE_AUTHOR("Jerome Neanne <j-neanne@baylibre.com>");
508MODULE_DESCRIPTION("TPS65214/TPS65215/TPS65219 Regulator driver");
509MODULE_LICENSE("GPL");
~/ Read-only file preview.