Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 2 | /* |
| 3 | * internal.h -- Voltage/Current Regulator framework internal code |
| 4 | * |
| 5 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
| 6 | * Copyright 2008 SlimLogic Ltd. |
| 7 | * |
| 8 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef __REGULATOR_INTERNAL_H |
| 12 | #define __REGULATOR_INTERNAL_H |
| 13 | |
Chunyan Zhang | c360a6d | 2018-01-26 21:08:44 +0800 | [diff] [blame] | 14 | #include <linux/suspend.h> |
| 15 | |
| 16 | #define REGULATOR_STATES_NUM (PM_SUSPEND_MAX + 1) |
| 17 | |
| 18 | struct regulator_voltage { |
| 19 | int min_uV; |
| 20 | int max_uV; |
| 21 | }; |
| 22 | |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 23 | /* |
| 24 | * struct regulator |
| 25 | * |
| 26 | * One for each consumer device. |
Chunyan Zhang | c360a6d | 2018-01-26 21:08:44 +0800 | [diff] [blame] | 27 | * @voltage - a voltage array for each state of runtime, i.e.: |
| 28 | * PM_SUSPEND_ON |
| 29 | * PM_SUSPEND_TO_IDLE |
| 30 | * PM_SUSPEND_STANDBY |
| 31 | * PM_SUSPEND_MEM |
| 32 | * PM_SUSPEND_MAX |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 33 | */ |
| 34 | struct regulator { |
| 35 | struct device *dev; |
| 36 | struct list_head list; |
| 37 | unsigned int always_on:1; |
| 38 | unsigned int bypass:1; |
Saravana Kannan | b59b654 | 2019-11-14 16:04:38 -0800 | [diff] [blame^] | 39 | unsigned int device_link:1; |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 40 | int uA_load; |
Douglas Anderson | 5451781 | 2018-11-20 09:52:53 -0800 | [diff] [blame] | 41 | unsigned int enable_count; |
| 42 | unsigned int deferred_disables; |
Chunyan Zhang | c360a6d | 2018-01-26 21:08:44 +0800 | [diff] [blame] | 43 | struct regulator_voltage voltage[REGULATOR_STATES_NUM]; |
Stephen Boyd | 0630b61 | 2017-03-16 18:07:14 -0700 | [diff] [blame] | 44 | const char *supply_name; |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 45 | struct device_attribute dev_attr; |
| 46 | struct regulator_dev *rdev; |
| 47 | struct dentry *debugfs; |
| 48 | }; |
| 49 | |
Maciej Purski | 148096a | 2018-01-22 15:30:06 +0100 | [diff] [blame] | 50 | extern struct class regulator_class; |
| 51 | |
| 52 | static inline struct regulator_dev *dev_to_rdev(struct device *dev) |
| 53 | { |
| 54 | return container_of(dev, struct regulator_dev, dev); |
| 55 | } |
| 56 | |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 57 | #ifdef CONFIG_OF |
Changbin Du | 08813e0 | 2018-05-02 21:44:57 +0800 | [diff] [blame] | 58 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np); |
Mark Brown | a0c7b16 | 2014-09-09 23:13:57 +0100 | [diff] [blame] | 59 | struct regulator_init_data *regulator_of_get_init_data(struct device *dev, |
| 60 | const struct regulator_desc *desc, |
Krzysztof Kozlowski | bfa21a0 | 2015-01-05 12:48:42 +0100 | [diff] [blame] | 61 | struct regulator_config *config, |
Mark Brown | a0c7b16 | 2014-09-09 23:13:57 +0100 | [diff] [blame] | 62 | struct device_node **node); |
Maciej Purski | a085a31 | 2018-04-23 16:33:39 +0200 | [diff] [blame] | 63 | |
| 64 | struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev, |
| 65 | int index); |
| 66 | |
| 67 | int of_get_n_coupled(struct regulator_dev *rdev); |
| 68 | |
| 69 | bool of_check_coupling_data(struct regulator_dev *rdev); |
| 70 | |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 71 | #else |
Changbin Du | 08813e0 | 2018-05-02 21:44:57 +0800 | [diff] [blame] | 72 | static inline struct regulator_dev * |
| 73 | of_find_regulator_by_node(struct device_node *np) |
| 74 | { |
| 75 | return NULL; |
| 76 | } |
| 77 | |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 78 | static inline struct regulator_init_data * |
| 79 | regulator_of_get_init_data(struct device *dev, |
| 80 | const struct regulator_desc *desc, |
Krzysztof Kozlowski | bfa21a0 | 2015-01-05 12:48:42 +0100 | [diff] [blame] | 81 | struct regulator_config *config, |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 82 | struct device_node **node) |
| 83 | { |
| 84 | return NULL; |
| 85 | } |
Mark Brown | a0c7b16 | 2014-09-09 23:13:57 +0100 | [diff] [blame] | 86 | |
Maciej Purski | a085a31 | 2018-04-23 16:33:39 +0200 | [diff] [blame] | 87 | static inline struct regulator_dev * |
| 88 | of_parse_coupled_regulator(struct regulator_dev *rdev, |
| 89 | int index) |
| 90 | { |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | static inline int of_get_n_coupled(struct regulator_dev *rdev) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static inline bool of_check_coupling_data(struct regulator_dev *rdev) |
| 100 | { |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | #endif |
Dmitry Torokhov | a8bd42a | 2017-02-03 13:56:02 -0800 | [diff] [blame] | 105 | enum regulator_get_type { |
| 106 | NORMAL_GET, |
| 107 | EXCLUSIVE_GET, |
| 108 | OPTIONAL_GET, |
| 109 | MAX_GET_TYPE |
| 110 | }; |
| 111 | |
| 112 | struct regulator *_regulator_get(struct device *dev, const char *id, |
| 113 | enum regulator_get_type get_type); |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 114 | #endif |