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; 25 }; 26 27 struct mc13xxx_regulator_priv { 28 struct mc13xxx *mc13xxx; 29 u32 powermisc_pwgt_state; 30 struct mc13xxx_regulator *mc13xxx_regulators; 31 int num_regulators; 32 struct regulator_dev *regulators[]; 33 }; 34 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 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 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 = { \ 64 .name = #_name, \ 65 .n_voltages = ARRAY_SIZE(_voltages), \ 66 .volt_table = _voltages, \ 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,\ 77 } 78 79 #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \ 80 [prefix ## _name] = { \ 81 .desc = { \ 82 .name = #_name, \ 83 .n_voltages = ARRAY_SIZE(_voltages), \ 84 .volt_table = _voltages, \ 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, \ 92 } 93 94 #define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \ 95 [prefix ## _name] = { \ 96 .desc = { \ 97 .name = #_name, \ 98 .n_voltages = ARRAY_SIZE(_voltages), \ 99 .volt_table = _voltages, \ 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, \ 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 115