18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * internal.h  --  Voltage/Current Regulator framework internal code
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2007, 2008 Wolfson Microelectronics PLC.
68c2ecf20Sopenharmony_ci * Copyright 2008 SlimLogic Ltd.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Author: Liam Girdwood <lrg@slimlogic.co.uk>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __REGULATOR_INTERNAL_H
128c2ecf20Sopenharmony_ci#define __REGULATOR_INTERNAL_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/suspend.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define REGULATOR_STATES_NUM	(PM_SUSPEND_MAX + 1)
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct regulator_voltage {
198c2ecf20Sopenharmony_ci	int min_uV;
208c2ecf20Sopenharmony_ci	int max_uV;
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * struct regulator
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * One for each consumer device.
278c2ecf20Sopenharmony_ci * @voltage - a voltage array for each state of runtime, i.e.:
288c2ecf20Sopenharmony_ci *            PM_SUSPEND_ON
298c2ecf20Sopenharmony_ci *            PM_SUSPEND_TO_IDLE
308c2ecf20Sopenharmony_ci *            PM_SUSPEND_STANDBY
318c2ecf20Sopenharmony_ci *            PM_SUSPEND_MEM
328c2ecf20Sopenharmony_ci *            PM_SUSPEND_MAX
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_cistruct regulator {
358c2ecf20Sopenharmony_ci	struct device *dev;
368c2ecf20Sopenharmony_ci	struct list_head list;
378c2ecf20Sopenharmony_ci	unsigned int always_on:1;
388c2ecf20Sopenharmony_ci	unsigned int bypass:1;
398c2ecf20Sopenharmony_ci	unsigned int device_link:1;
408c2ecf20Sopenharmony_ci	int uA_load;
418c2ecf20Sopenharmony_ci	unsigned int enable_count;
428c2ecf20Sopenharmony_ci	unsigned int deferred_disables;
438c2ecf20Sopenharmony_ci	struct regulator_voltage voltage[REGULATOR_STATES_NUM];
448c2ecf20Sopenharmony_ci	const char *supply_name;
458c2ecf20Sopenharmony_ci	struct device_attribute dev_attr;
468c2ecf20Sopenharmony_ci	struct regulator_dev *rdev;
478c2ecf20Sopenharmony_ci	struct dentry *debugfs;
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciextern struct class regulator_class;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic inline struct regulator_dev *dev_to_rdev(struct device *dev)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	return container_of(dev, struct regulator_dev, dev);
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#ifdef CONFIG_OF
588c2ecf20Sopenharmony_cistruct regulator_dev *of_find_regulator_by_node(struct device_node *np);
598c2ecf20Sopenharmony_cistruct regulator_init_data *regulator_of_get_init_data(struct device *dev,
608c2ecf20Sopenharmony_ci			         const struct regulator_desc *desc,
618c2ecf20Sopenharmony_ci				 struct regulator_config *config,
628c2ecf20Sopenharmony_ci				 struct device_node **node);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
658c2ecf20Sopenharmony_ci						 int index);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciint of_get_n_coupled(struct regulator_dev *rdev);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cibool of_check_coupling_data(struct regulator_dev *rdev);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#else
728c2ecf20Sopenharmony_cistatic inline struct regulator_dev *
738c2ecf20Sopenharmony_ciof_find_regulator_by_node(struct device_node *np)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	return NULL;
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cistatic inline struct regulator_init_data *
798c2ecf20Sopenharmony_ciregulator_of_get_init_data(struct device *dev,
808c2ecf20Sopenharmony_ci			   const struct regulator_desc *desc,
818c2ecf20Sopenharmony_ci			   struct regulator_config *config,
828c2ecf20Sopenharmony_ci			   struct device_node **node)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	return NULL;
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic inline struct regulator_dev *
888c2ecf20Sopenharmony_ciof_parse_coupled_regulator(struct regulator_dev *rdev,
898c2ecf20Sopenharmony_ci			   int index)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	return NULL;
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic inline int of_get_n_coupled(struct regulator_dev *rdev)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	return 0;
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic inline bool of_check_coupling_data(struct regulator_dev *rdev)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	return false;
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#endif
1058c2ecf20Sopenharmony_cienum regulator_get_type {
1068c2ecf20Sopenharmony_ci	NORMAL_GET,
1078c2ecf20Sopenharmony_ci	EXCLUSIVE_GET,
1088c2ecf20Sopenharmony_ci	OPTIONAL_GET,
1098c2ecf20Sopenharmony_ci	MAX_GET_TYPE
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistruct regulator *_regulator_get(struct device *dev, const char *id,
1138c2ecf20Sopenharmony_ci				 enum regulator_get_type get_type);
1148c2ecf20Sopenharmony_ci#endif
115