blob: 8343a25888d2f95c9df278dc5ab37c67415ef05b [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
35extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
Yong Shen167e3d82010-12-14 14:00:54 +080036extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
37 int min_uV, int max_uV, unsigned *selector);
38extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
39
Shawn Guo93bcb232011-12-21 23:00:46 +080040#ifdef CONFIG_OF
41extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
42extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
43 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
44 int num_regulators);
45#else
46static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
47{
48 return -ENODEV;
49}
50
51static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
52 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
53 int num_regulators)
54{
55 return NULL;
56}
57#endif
58
Yong Shen167e3d82010-12-14 14:00:54 +080059extern struct regulator_ops mc13xxx_regulator_ops;
60extern struct regulator_ops mc13xxx_fixed_regulator_ops;
61
62#define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops) \
63 [prefix ## _name] = { \
64 .desc = { \
Shawn Guo3a5d0312011-12-21 23:00:45 +080065 .name = #_name, \
Yong Shen167e3d82010-12-14 14:00:54 +080066 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080067 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080068 .ops = &_ops, \
69 .type = REGULATOR_VOLTAGE, \
70 .id = prefix ## _name, \
71 .owner = THIS_MODULE, \
72 }, \
73 .reg = prefix ## _reg, \
74 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
75 .vsel_reg = prefix ## _vsel_reg, \
76 .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
77 .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
Yong Shen167e3d82010-12-14 14:00:54 +080078 }
79
80#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \
81 [prefix ## _name] = { \
82 .desc = { \
Shawn Guo3a5d0312011-12-21 23:00:45 +080083 .name = #_name, \
Yong Shen167e3d82010-12-14 14:00:54 +080084 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +080085 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +080086 .ops = &_ops, \
87 .type = REGULATOR_VOLTAGE, \
88 .id = prefix ## _name, \
89 .owner = THIS_MODULE, \
90 }, \
91 .reg = prefix ## _reg, \
92 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
Yong Shen167e3d82010-12-14 14:00:54 +080093 }
94
95#define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \
96 [prefix ## _name] = { \
97 .desc = { \
Shawn Guo3a5d0312011-12-21 23:00:45 +080098 .name = #_name, \
Yong Shen167e3d82010-12-14 14:00:54 +080099 .n_voltages = ARRAY_SIZE(_voltages), \
Axel Lin34e74f32012-06-08 15:41:48 +0800100 .volt_table = _voltages, \
Yong Shen167e3d82010-12-14 14:00:54 +0800101 .ops = &_ops, \
102 .type = REGULATOR_VOLTAGE, \
103 .id = prefix ## _name, \
104 .owner = THIS_MODULE, \
105 }, \
106 .reg = prefix ## _reg, \
107 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
Yong Shen167e3d82010-12-14 14:00:54 +0800108 }
109
110#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \
111 MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops)
112#define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops) \
113 MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops)
114
115#endif