xref: /openbmc/linux/drivers/regulator/mc13xxx.h (revision bc33f5e5)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
4  *
5  *  Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
6  */
7 
8 #ifndef __LINUX_REGULATOR_MC13XXX_H
9 #define __LINUX_REGULATOR_MC13XXX_H
10 
11 #include <linux/regulator/driver.h>
12 
13 struct mc13xxx_regulator {
14 	struct regulator_desc desc;
15 	int reg;
16 	int enable_bit;
17 	int vsel_reg;
18 	int vsel_shift;
19 	int vsel_mask;
20 };
21 
22 struct mc13xxx_regulator_priv {
23 	struct mc13xxx *mc13xxx;
24 	u32 powermisc_pwgt_state;
25 	struct mc13xxx_regulator *mc13xxx_regulators;
26 	int num_regulators;
27 	struct regulator_dev *regulators[];
28 };
29 
30 extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
31 		int min_uV, int max_uV, unsigned *selector);
32 
33 #ifdef CONFIG_OF
34 extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
35 extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
36 	struct platform_device *pdev, struct mc13xxx_regulator *regulators,
37 	int num_regulators);
38 #else
39 static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
40 {
41 	return -ENODEV;
42 }
43 
44 static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
45 	struct platform_device *pdev, struct mc13xxx_regulator *regulators,
46 	int num_regulators)
47 {
48 	return NULL;
49 }
50 #endif
51 
52 extern const struct regulator_ops mc13xxx_regulator_ops;
53 extern const struct regulator_ops mc13xxx_fixed_regulator_ops;
54 
55 #define MC13xxx_DEFINE(prefix, _name, _node, _reg, _vsel_reg, _voltages, _ops)	\
56 	[prefix ## _name] = {				\
57 		.desc = {						\
58 			.name = #_node,					\
59 			.n_voltages = ARRAY_SIZE(_voltages),		\
60 			.volt_table =  _voltages,			\
61 			.ops = &_ops,			\
62 			.type = REGULATOR_VOLTAGE,			\
63 			.id = prefix ## _name,		\
64 			.owner = THIS_MODULE,				\
65 		},							\
66 		.reg = prefix ## _reg,				\
67 		.enable_bit = prefix ## _reg ## _ ## _name ## EN,	\
68 		.vsel_reg = prefix ## _vsel_reg,			\
69 		.vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
70 		.vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
71 	}
72 
73 #define MC13xxx_FIXED_DEFINE(prefix, _name, _node, _reg, _voltages, _ops)	\
74 	[prefix ## _name] = {				\
75 		.desc = {						\
76 			.name = #_node,					\
77 			.n_voltages = ARRAY_SIZE(_voltages),		\
78 			.volt_table =  _voltages,			\
79 			.ops = &_ops,		\
80 			.type = REGULATOR_VOLTAGE,			\
81 			.id = prefix ## _name,		\
82 			.owner = THIS_MODULE,				\
83 		},							\
84 		.reg = prefix ## _reg,				\
85 		.enable_bit = prefix ## _reg ## _ ## _name ## EN,	\
86 	}
87 
88 #define MC13xxx_GPO_DEFINE(prefix, _name, _node, _reg,  _voltages, _ops)	\
89 	[prefix ## _name] = {				\
90 		.desc = {						\
91 			.name = #_node,					\
92 			.n_voltages = ARRAY_SIZE(_voltages),		\
93 			.volt_table =  _voltages,			\
94 			.ops = &_ops,		\
95 			.type = REGULATOR_VOLTAGE,			\
96 			.id = prefix ## _name,		\
97 			.owner = THIS_MODULE,				\
98 		},							\
99 		.reg = prefix ## _reg,				\
100 		.enable_bit = prefix ## _reg ## _ ## _name ## EN,	\
101 	}
102 
103 #define MC13xxx_DEFINE_SW(_name, _node, _reg, _vsel_reg, _voltages, ops) \
104 	MC13xxx_DEFINE(SW, _name, _node, _reg, _vsel_reg, _voltages, ops)
105 #define MC13xxx_DEFINE_REGU(_name, _node, _reg, _vsel_reg, _voltages, ops) \
106 	MC13xxx_DEFINE(REGU, _name, _node, _reg, _vsel_reg, _voltages, ops)
107 
108 #endif
109