Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 2 | /* |
| 3 | * mc13xxx.h - regulators for the Freescale mc13xxx PMIC |
| 4 | * |
| 5 | * Copyright (C) 2010 Yong Shen <yong.shen@linaro.org> |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __LINUX_REGULATOR_MC13XXX_H |
| 9 | #define __LINUX_REGULATOR_MC13XXX_H |
| 10 | |
| 11 | #include <linux/regulator/driver.h> |
| 12 | |
| 13 | struct mc13xxx_regulator { |
| 14 | struct regulator_desc desc; |
| 15 | int reg; |
| 16 | int enable_bit; |
| 17 | int vsel_reg; |
| 18 | int vsel_shift; |
| 19 | int vsel_mask; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | struct mc13xxx_regulator_priv { |
| 23 | struct mc13xxx *mc13xxx; |
| 24 | u32 powermisc_pwgt_state; |
| 25 | struct mc13xxx_regulator *mc13xxx_regulators; |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 26 | int num_regulators; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 27 | struct regulator_dev *regulators[]; |
| 28 | }; |
| 29 | |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 30 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, |
| 31 | int min_uV, int max_uV, unsigned *selector); |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 32 | |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 33 | #ifdef CONFIG_OF |
| 34 | extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); |
| 35 | extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
| 36 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
Alexander Shiyan | eb0d8e7 | 2013-04-27 10:29:24 +0400 | [diff] [blame] | 37 | int num_regulators); |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 38 | #else |
| 39 | static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) |
| 40 | { |
| 41 | return -ENODEV; |
| 42 | } |
| 43 | |
| 44 | static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
| 45 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
Alexander Shiyan | eb0d8e7 | 2013-04-27 10:29:24 +0400 | [diff] [blame] | 46 | int num_regulators) |
Shawn Guo | 93bcb23 | 2011-12-21 23:00:46 +0800 | [diff] [blame] | 47 | { |
| 48 | return NULL; |
| 49 | } |
| 50 | #endif |
| 51 | |
Axel Lin | e5680c4 | 2019-03-01 22:20:53 +0800 | [diff] [blame] | 52 | extern const struct regulator_ops mc13xxx_regulator_ops; |
| 53 | extern const struct regulator_ops mc13xxx_fixed_regulator_ops; |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 54 | |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 55 | #define MC13xxx_DEFINE(prefix, _name, _node, _reg, _vsel_reg, _voltages, _ops) \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 56 | [prefix ## _name] = { \ |
| 57 | .desc = { \ |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 58 | .name = #_node, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 59 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 60 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 61 | .ops = &_ops, \ |
| 62 | .type = REGULATOR_VOLTAGE, \ |
| 63 | .id = prefix ## _name, \ |
| 64 | .owner = THIS_MODULE, \ |
| 65 | }, \ |
| 66 | .reg = prefix ## _reg, \ |
| 67 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
| 68 | .vsel_reg = prefix ## _vsel_reg, \ |
| 69 | .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\ |
| 70 | .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 71 | } |
| 72 | |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 73 | #define MC13xxx_FIXED_DEFINE(prefix, _name, _node, _reg, _voltages, _ops) \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 74 | [prefix ## _name] = { \ |
| 75 | .desc = { \ |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 76 | .name = #_node, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 77 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 78 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 79 | .ops = &_ops, \ |
| 80 | .type = REGULATOR_VOLTAGE, \ |
| 81 | .id = prefix ## _name, \ |
| 82 | .owner = THIS_MODULE, \ |
| 83 | }, \ |
| 84 | .reg = prefix ## _reg, \ |
| 85 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 86 | } |
| 87 | |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 88 | #define MC13xxx_GPO_DEFINE(prefix, _name, _node, _reg, _voltages, _ops) \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 89 | [prefix ## _name] = { \ |
| 90 | .desc = { \ |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 91 | .name = #_node, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 92 | .n_voltages = ARRAY_SIZE(_voltages), \ |
Axel Lin | 34e74f3 | 2012-06-08 15:41:48 +0800 | [diff] [blame] | 93 | .volt_table = _voltages, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 94 | .ops = &_ops, \ |
| 95 | .type = REGULATOR_VOLTAGE, \ |
| 96 | .id = prefix ## _name, \ |
| 97 | .owner = THIS_MODULE, \ |
| 98 | }, \ |
| 99 | .reg = prefix ## _reg, \ |
| 100 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 101 | } |
| 102 | |
Rob Herring | ec52091 | 2019-01-25 09:37:04 -0600 | [diff] [blame] | 103 | #define MC13xxx_DEFINE_SW(_name, _node, _reg, _vsel_reg, _voltages, ops) \ |
| 104 | MC13xxx_DEFINE(SW, _name, _node, _reg, _vsel_reg, _voltages, ops) |
| 105 | #define MC13xxx_DEFINE_REGU(_name, _node, _reg, _vsel_reg, _voltages, ops) \ |
| 106 | MC13xxx_DEFINE(REGU, _name, _node, _reg, _vsel_reg, _voltages, ops) |
Yong Shen | 167e3d8 | 2010-12-14 14:00:54 +0800 | [diff] [blame] | 107 | |
| 108 | #endif |