Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 Disruptive Technologies Research AS |
| 4 | * Sven Schwermer <sven.svenschwermer@disruptive-technologies.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _REGULATOR_COMMON_H |
| 8 | #define _REGULATOR_COMMON_H |
| 9 | |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 10 | #include <asm/gpio.h> |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 11 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 12 | struct regulator_common_plat { |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 13 | struct gpio_desc gpio; /* GPIO for regulator enable control */ |
| 14 | unsigned int startup_delay_us; |
| 15 | unsigned int off_on_delay_us; |
Eugen Hristev | 405512e | 2023-04-19 16:45:24 +0300 | [diff] [blame] | 16 | unsigned int enable_count; |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 17 | }; |
| 18 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 19 | int regulator_common_of_to_plat(struct udevice *dev, |
Eugen Hristev | 81aa192 | 2023-04-19 16:45:25 +0300 | [diff] [blame] | 20 | struct regulator_common_plat *plat, const |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 21 | char *enable_gpio_name); |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 22 | int regulator_common_get_enable(const struct udevice *dev, |
Eugen Hristev | 81aa192 | 2023-04-19 16:45:25 +0300 | [diff] [blame] | 23 | struct regulator_common_plat *plat); |
Eugen Hristev | 405512e | 2023-04-19 16:45:24 +0300 | [diff] [blame] | 24 | /* |
| 25 | * Enable or Disable a regulator |
| 26 | * |
| 27 | * This is a reentrant function and subsequent calls that enable will |
| 28 | * increase an internal counter, and disable calls will decrease the counter. |
| 29 | * The actual resource will be enabled when the counter gets to 1 coming from 0, |
| 30 | * and disabled when it reaches 0 coming from 1. |
| 31 | * |
| 32 | * @dev: regulator device |
Eugen Hristev | 81aa192 | 2023-04-19 16:45:25 +0300 | [diff] [blame] | 33 | * @plat: Platform data |
Eugen Hristev | 405512e | 2023-04-19 16:45:24 +0300 | [diff] [blame] | 34 | * @enable: bool indicating whether to enable or disable the regulator |
| 35 | * @return: |
| 36 | * 0 on Success |
| 37 | * -EBUSY if the regulator cannot be disabled because it's requested by |
| 38 | * another device |
| 39 | * -EALREADY if the regulator has already been enabled or has already been |
| 40 | * disabled |
| 41 | * -EACCES if there is no possibility to enable/disable the regulator |
| 42 | * -ve on different error situation |
| 43 | */ |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 44 | int regulator_common_set_enable(const struct udevice *dev, |
Eugen Hristev | 81aa192 | 2023-04-19 16:45:25 +0300 | [diff] [blame] | 45 | struct regulator_common_plat *plat, bool enable); |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 46 | |
| 47 | #endif /* _REGULATOR_COMMON_H */ |