Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | struct 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; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | struct mc13xxx_regulator_priv { |
| 27 | struct mc13xxx *mc13xxx; |
| 28 | u32 powermisc_pwgt_state; |
| 29 | struct mc13xxx_regulator *mc13xxx_regulators; |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 30 | int num_regulators; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 31 | struct regulator_dev *regulators[]; |
| 32 | }; |
| 33 | |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 34 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, |
| 35 | int min_uV, int max_uV, unsigned *selector); |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 36 | |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 37 | #ifdef CONFIG_OF |
| 38 | extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); |
| 39 | extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
| 40 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
Alexander Shiyan | eb0d8e7 | 2013-04-27 10:29:24 +0400 | [diff] [blame] | 41 | int num_regulators); |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 42 | #else |
| 43 | static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) |
| 44 | { |
| 45 | return -ENODEV; |
| 46 | } |
| 47 | |
| 48 | static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
| 49 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
Alexander Shiyan | eb0d8e7 | 2013-04-27 10:29:24 +0400 | [diff] [blame] | 50 | int num_regulators) |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 51 | { |
| 52 | return NULL; |
| 53 | } |
| 54 | #endif |
| 55 | |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 56 | extern struct regulator_ops mc13xxx_regulator_ops; |
| 57 | extern struct regulator_ops mc13xxx_fixed_regulator_ops; |
| 58 | |
| 59 | #define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops) \ |
| 60 | [prefix ## _name] = { \ |
| 61 | .desc = { \ |
Shawn Guo | 3a5d031 | 2011-12-21 23:00:45 +0800 | [diff] [blame] | 62 | .name = #_name, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 63 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 64 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 65 | .ops = &_ops, \ |
| 66 | .type = REGULATOR_VOLTAGE, \ |
| 67 | .id = prefix ## _name, \ |
| 68 | .owner = THIS_MODULE, \ |
| 69 | }, \ |
| 70 | .reg = prefix ## _reg, \ |
| 71 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
| 72 | .vsel_reg = prefix ## _vsel_reg, \ |
| 73 | .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\ |
| 74 | .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \ |
| 78 | [prefix ## _name] = { \ |
| 79 | .desc = { \ |
Shawn Guo | 3a5d031 | 2011-12-21 23:00:45 +0800 | [diff] [blame] | 80 | .name = #_name, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 81 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 82 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 83 | .ops = &_ops, \ |
| 84 | .type = REGULATOR_VOLTAGE, \ |
| 85 | .id = prefix ## _name, \ |
| 86 | .owner = THIS_MODULE, \ |
| 87 | }, \ |
| 88 | .reg = prefix ## _reg, \ |
| 89 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | #define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \ |
| 93 | [prefix ## _name] = { \ |
| 94 | .desc = { \ |
Shawn Guo | 3a5d031 | 2011-12-21 23:00:45 +0800 | [diff] [blame] | 95 | .name = #_name, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 96 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 97 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 98 | .ops = &_ops, \ |
| 99 | .type = REGULATOR_VOLTAGE, \ |
| 100 | .id = prefix ## _name, \ |
| 101 | .owner = THIS_MODULE, \ |
| 102 | }, \ |
| 103 | .reg = prefix ## _reg, \ |
| 104 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | #define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \ |
| 108 | MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops) |
| 109 | #define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops) \ |
| 110 | MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops) |
| 111 | |
| 112 | #endif |