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 | |
Matti Vaittinen | 157d223 | 2021-06-03 08:41:37 +0300 | [diff] [blame] | 18 | #define rdev_crit(rdev, fmt, ...) \ |
| 19 | pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 20 | #define rdev_err(rdev, fmt, ...) \ |
| 21 | pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 22 | #define rdev_warn(rdev, fmt, ...) \ |
| 23 | pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 24 | #define rdev_info(rdev, fmt, ...) \ |
| 25 | pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 26 | #define rdev_dbg(rdev, fmt, ...) \ |
| 27 | pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) |
| 28 | |
Chunyan Zhang | c360a6d | 2018-01-26 21:08:44 +0800 | [diff] [blame] | 29 | struct regulator_voltage { |
| 30 | int min_uV; |
| 31 | int max_uV; |
| 32 | }; |
| 33 | |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 34 | /* |
| 35 | * struct regulator |
| 36 | * |
| 37 | * One for each consumer device. |
Chunyan Zhang | c360a6d | 2018-01-26 21:08:44 +0800 | [diff] [blame] | 38 | * @voltage - a voltage array for each state of runtime, i.e.: |
| 39 | * PM_SUSPEND_ON |
| 40 | * PM_SUSPEND_TO_IDLE |
| 41 | * PM_SUSPEND_STANDBY |
| 42 | * PM_SUSPEND_MEM |
| 43 | * PM_SUSPEND_MAX |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 44 | */ |
| 45 | struct regulator { |
| 46 | struct device *dev; |
| 47 | struct list_head list; |
| 48 | unsigned int always_on:1; |
| 49 | unsigned int bypass:1; |
Saravana Kannan | b59b654 | 2019-11-14 16:04:38 -0800 | [diff] [blame] | 50 | unsigned int device_link:1; |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 51 | int uA_load; |
Douglas Anderson | 5451781 | 2018-11-20 09:52:53 -0800 | [diff] [blame] | 52 | unsigned int enable_count; |
| 53 | unsigned int deferred_disables; |
Chunyan Zhang | c360a6d | 2018-01-26 21:08:44 +0800 | [diff] [blame] | 54 | struct regulator_voltage voltage[REGULATOR_STATES_NUM]; |
Stephen Boyd | 0630b61 | 2017-03-16 18:07:14 -0700 | [diff] [blame] | 55 | const char *supply_name; |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 56 | struct device_attribute dev_attr; |
| 57 | struct regulator_dev *rdev; |
| 58 | struct dentry *debugfs; |
| 59 | }; |
| 60 | |
Maciej Purski | 148096a | 2018-01-22 15:30:06 +0100 | [diff] [blame] | 61 | extern struct class regulator_class; |
| 62 | |
| 63 | static inline struct regulator_dev *dev_to_rdev(struct device *dev) |
| 64 | { |
| 65 | return container_of(dev, struct regulator_dev, dev); |
| 66 | } |
| 67 | |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 68 | #ifdef CONFIG_OF |
Changbin Du | 08813e0 | 2018-05-02 21:44:57 +0800 | [diff] [blame] | 69 | struct regulator_dev *of_find_regulator_by_node(struct device_node *np); |
Mark Brown | a0c7b16 | 2014-09-09 23:13:57 +0100 | [diff] [blame] | 70 | struct regulator_init_data *regulator_of_get_init_data(struct device *dev, |
| 71 | const struct regulator_desc *desc, |
Krzysztof Kozlowski | bfa21a0 | 2015-01-05 12:48:42 +0100 | [diff] [blame] | 72 | struct regulator_config *config, |
Mark Brown | a0c7b16 | 2014-09-09 23:13:57 +0100 | [diff] [blame] | 73 | struct device_node **node); |
Maciej Purski | a085a31 | 2018-04-23 16:33:39 +0200 | [diff] [blame] | 74 | |
| 75 | struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev, |
| 76 | int index); |
| 77 | |
| 78 | int of_get_n_coupled(struct regulator_dev *rdev); |
| 79 | |
| 80 | bool of_check_coupling_data(struct regulator_dev *rdev); |
| 81 | |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 82 | #else |
Changbin Du | 08813e0 | 2018-05-02 21:44:57 +0800 | [diff] [blame] | 83 | static inline struct regulator_dev * |
| 84 | of_find_regulator_by_node(struct device_node *np) |
| 85 | { |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 89 | static inline struct regulator_init_data * |
| 90 | regulator_of_get_init_data(struct device *dev, |
| 91 | const struct regulator_desc *desc, |
Krzysztof Kozlowski | bfa21a0 | 2015-01-05 12:48:42 +0100 | [diff] [blame] | 92 | struct regulator_config *config, |
Mark Brown | ef126a4 | 2014-09-10 15:17:01 +0100 | [diff] [blame] | 93 | struct device_node **node) |
| 94 | { |
| 95 | return NULL; |
| 96 | } |
Mark Brown | a0c7b16 | 2014-09-09 23:13:57 +0100 | [diff] [blame] | 97 | |
Maciej Purski | a085a31 | 2018-04-23 16:33:39 +0200 | [diff] [blame] | 98 | static inline struct regulator_dev * |
| 99 | of_parse_coupled_regulator(struct regulator_dev *rdev, |
| 100 | int index) |
| 101 | { |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | static inline int of_get_n_coupled(struct regulator_dev *rdev) |
| 106 | { |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static inline bool of_check_coupling_data(struct regulator_dev *rdev) |
| 111 | { |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | #endif |
Dmitry Torokhov | a8bd42a | 2017-02-03 13:56:02 -0800 | [diff] [blame] | 116 | enum regulator_get_type { |
| 117 | NORMAL_GET, |
| 118 | EXCLUSIVE_GET, |
| 119 | OPTIONAL_GET, |
| 120 | MAX_GET_TYPE |
| 121 | }; |
| 122 | |
| 123 | struct regulator *_regulator_get(struct device *dev, const char *id, |
| 124 | enum regulator_get_type get_type); |
Mark Brown | 0cdfcc0 | 2013-09-11 13:15:40 +0100 | [diff] [blame] | 125 | #endif |