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; |
| 24 | int hi_bit; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | struct mc13xxx_regulator_priv { |
| 28 | struct mc13xxx *mc13xxx; |
| 29 | u32 powermisc_pwgt_state; |
| 30 | struct mc13xxx_regulator *mc13xxx_regulators; |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 31 | int num_regulators; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 32 | struct regulator_dev *regulators[]; |
| 33 | }; |
| 34 | |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 35 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, |
| 36 | int min_uV, int max_uV, unsigned *selector); |
| 37 | extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev); |
| 38 | |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 39 | #ifdef CONFIG_OF |
| 40 | extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); |
| 41 | extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
| 42 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
| 43 | int num_regulators); |
| 44 | #else |
| 45 | static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) |
| 46 | { |
| 47 | return -ENODEV; |
| 48 | } |
| 49 | |
| 50 | static 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 Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 58 | extern struct regulator_ops mc13xxx_regulator_ops; |
| 59 | extern 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 Guo | 3a5d031 | 2011-12-21 23:00:45 +0800 | [diff] [blame] | 64 | .name = #_name, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 65 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 66 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 67 | .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 Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \ |
| 80 | [prefix ## _name] = { \ |
| 81 | .desc = { \ |
Shawn Guo | 3a5d031 | 2011-12-21 23:00:45 +0800 | [diff] [blame] | 82 | .name = #_name, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 83 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 84 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 85 | .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 Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | #define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \ |
| 95 | [prefix ## _name] = { \ |
| 96 | .desc = { \ |
Shawn Guo | 3a5d031 | 2011-12-21 23:00:45 +0800 | [diff] [blame] | 97 | .name = #_name, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 98 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 99 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 100 | .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 Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 107 | } |
| 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 |