blob: eaff5510b6df62cc6096c1e6683a4601cdb50240 [file] [log] [blame]
Yong Shen167e3d82010-12-14 14:00:54 +08001/*
2 * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
3 *
4 * Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __LINUX_REGULATOR_MC13XXX_H
13#define __LINUX_REGULATOR_MC13XXX_H
14
15#include <linux/regulator/driver.h>
16
17struct mc13xxx_regulator {
18 struct regulator_desc desc;
19 int reg;
20 int enable_bit;
21 int vsel_reg;
22 int vsel_shift;
23 int vsel_mask;
24 int hi_bit;
Yong Shen167e3d82010-12-14 14:00:54 +080025};
26
27struct mc13xxx_regulator_priv {
28 struct mc13xxx *mc13xxx;
29 u32 powermisc_pwgt_state;
30 struct mc13xxx_regulator *mc13xxx_regulators;
Shawn Guo93bcb232011-12-21 23:00:46 +080031 int num_regulators;
Yong Shen167e3d82010-12-14 14:00:54 +080032 struct regulator_dev *regulators[];
33};
34
Yong Shen167e3d82010-12-14 14:00:54 +080035extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
36 int min_uV, int max_uV, unsigned *selector);
37extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
38
Shawn Guo93bcb232011-12-21 23:00:46 +080039#ifdef CONFIG_OF
40extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
41extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
42 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
43 int num_regulators);
44#else
45static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
46{
47 return -ENODEV;
48}
49
50static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
51 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
52 int num_regulators)
53{
54 return NULL;
55}
56#endif
57
Yong Shen167e3d82010-12-14 14:00:54 +080058extern struct regulator_ops mc13xxx_regulator_ops;
59extern struct regulator_ops mc13xxx_fixed_regulator_ops;
60
61#define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops) \
62 [prefix ## _name] = { \
63 .desc = { \
Shawn Guo3a5d0312011-12-21 23:00:45 +080064 .name = #_name, \
Yong Shen167e3d82010-12-14 14:00:54 +080065 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080066 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080067 .ops = &_ops, \
68 .type = REGULATOR_VOLTAGE, \
69 .id = prefix ## _name, \
70 .owner = THIS_MODULE, \
71 }, \
72 .reg = prefix ## _reg, \
73 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
74 .vsel_reg = prefix ## _vsel_reg, \
75 .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
76 .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
Yong Shen167e3d82010-12-14 14:00:54 +080077 }
78
79#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \
80 [prefix ## _name] = { \
81 .desc = { \
Shawn Guo3a5d0312011-12-21 23:00:45 +080082 .name = #_name, \
Yong Shen167e3d82010-12-14 14:00:54 +080083 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080084 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080085 .ops = &_ops, \
86 .type = REGULATOR_VOLTAGE, \
87 .id = prefix ## _name, \
88 .owner = THIS_MODULE, \
89 }, \
90 .reg = prefix ## _reg, \
91 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
Yong Shen167e3d82010-12-14 14:00:54 +080092 }
93
94#define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \
95 [prefix ## _name] = { \
96 .desc = { \
Shawn Guo3a5d0312011-12-21 23:00:45 +080097 .name = #_name, \
Yong Shen167e3d82010-12-14 14:00:54 +080098 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080099 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +0800100 .ops = &_ops, \
101 .type = REGULATOR_VOLTAGE, \
102 .id = prefix ## _name, \
103 .owner = THIS_MODULE, \
104 }, \
105 .reg = prefix ## _reg, \
106 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
Yong Shen167e3d82010-12-14 14:00:54 +0800107 }
108
109#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \
110 MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops)
111#define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops) \
112 MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops)
113
114#endif