blob: e03279dc43f4efe818cd56f1026633d46034ad2e [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Yong Shen167e3d82010-12-14 14:00:54 +08002/*
3 * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
4 *
5 * Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
Yong Shen167e3d82010-12-14 14:00:54 +08006 */
7
8#ifndef __LINUX_REGULATOR_MC13XXX_H
9#define __LINUX_REGULATOR_MC13XXX_H
10
11#include <linux/regulator/driver.h>
12
13struct 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;
Yong Shen167e3d82010-12-14 14:00:54 +080020};
21
22struct mc13xxx_regulator_priv {
23 struct mc13xxx *mc13xxx;
24 u32 powermisc_pwgt_state;
25 struct mc13xxx_regulator *mc13xxx_regulators;
Shawn Guo93bcb232011-12-21 23:00:46 +080026 int num_regulators;
Yong Shen167e3d82010-12-14 14:00:54 +080027 struct regulator_dev *regulators[];
28};
29
Yong Shen167e3d82010-12-14 14:00:54 +080030extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
31 int min_uV, int max_uV, unsigned *selector);
Yong Shen167e3d82010-12-14 14:00:54 +080032
Shawn Guo93bcb232011-12-21 23:00:46 +080033#ifdef CONFIG_OF
34extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
35extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
36 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
Alexander Shiyaneb0d8e72013-04-27 10:29:24 +040037 int num_regulators);
Shawn Guo93bcb232011-12-21 23:00:46 +080038#else
39static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
40{
41 return -ENODEV;
42}
43
44static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
45 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
Alexander Shiyaneb0d8e72013-04-27 10:29:24 +040046 int num_regulators)
Shawn Guo93bcb232011-12-21 23:00:46 +080047{
48 return NULL;
49}
50#endif
51
Axel Line5680c42019-03-01 22:20:53 +080052extern const struct regulator_ops mc13xxx_regulator_ops;
53extern const struct regulator_ops mc13xxx_fixed_regulator_ops;
Yong Shen167e3d82010-12-14 14:00:54 +080054
Rob Herringec520912019-01-25 09:37:04 -060055#define MC13xxx_DEFINE(prefix, _name, _node, _reg, _vsel_reg, _voltages, _ops) \
Yong Shen167e3d82010-12-14 14:00:54 +080056 [prefix ## _name] = { \
57 .desc = { \
Rob Herringec520912019-01-25 09:37:04 -060058 .name = #_node, \
Yong Shen167e3d82010-12-14 14:00:54 +080059 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080060 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080061 .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,\
Yong Shen167e3d82010-12-14 14:00:54 +080071 }
72
Rob Herringec520912019-01-25 09:37:04 -060073#define MC13xxx_FIXED_DEFINE(prefix, _name, _node, _reg, _voltages, _ops) \
Yong Shen167e3d82010-12-14 14:00:54 +080074 [prefix ## _name] = { \
75 .desc = { \
Rob Herringec520912019-01-25 09:37:04 -060076 .name = #_node, \
Yong Shen167e3d82010-12-14 14:00:54 +080077 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080078 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080079 .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, \
Yong Shen167e3d82010-12-14 14:00:54 +080086 }
87
Rob Herringec520912019-01-25 09:37:04 -060088#define MC13xxx_GPO_DEFINE(prefix, _name, _node, _reg, _voltages, _ops) \
Yong Shen167e3d82010-12-14 14:00:54 +080089 [prefix ## _name] = { \
90 .desc = { \
Rob Herringec520912019-01-25 09:37:04 -060091 .name = #_node, \
Yong Shen167e3d82010-12-14 14:00:54 +080092 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080093 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080094 .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, \
Yong Shen167e3d82010-12-14 14:00:54 +0800101 }
102
Rob Herringec520912019-01-25 09:37:04 -0600103#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)
Yong Shen167e3d82010-12-14 14:00:54 +0800107
108#endif