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