Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Samsung Electronics |
| 4 | * |
| 5 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 12 | #include <power/pmic.h> |
| 13 | #include <power/regulator.h> |
| 14 | |
Simon Glass | ad2f4ac | 2020-07-19 10:15:44 -0600 | [diff] [blame] | 15 | #include "regulator_common.h" |
| 16 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 17 | static int fixed_regulator_of_to_plat(struct udevice *dev) |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 18 | { |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 19 | struct dm_regulator_uclass_plat *uc_pdata; |
Sven Schwermer | 2f7a5f2 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 20 | struct regulator_common_platdata *dev_pdata; |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 21 | |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 22 | dev_pdata = dev_get_plat(dev); |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 23 | uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 24 | if (!uc_pdata) |
| 25 | return -ENXIO; |
| 26 | |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 27 | uc_pdata->type = REGULATOR_TYPE_FIXED; |
| 28 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 29 | return regulator_common_of_to_plat(dev, dev_pdata, "gpio"); |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static int fixed_regulator_get_value(struct udevice *dev) |
| 33 | { |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 34 | struct dm_regulator_uclass_plat *uc_pdata; |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 35 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 36 | uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 37 | if (!uc_pdata) |
| 38 | return -ENXIO; |
| 39 | |
| 40 | if (uc_pdata->min_uV != uc_pdata->max_uV) { |
| 41 | debug("Invalid constraints for: %s\n", uc_pdata->name); |
| 42 | return -EINVAL; |
| 43 | } |
| 44 | |
| 45 | return uc_pdata->min_uV; |
| 46 | } |
| 47 | |
| 48 | static int fixed_regulator_get_current(struct udevice *dev) |
| 49 | { |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 50 | struct dm_regulator_uclass_plat *uc_pdata; |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 51 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 52 | uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 53 | if (!uc_pdata) |
| 54 | return -ENXIO; |
| 55 | |
| 56 | if (uc_pdata->min_uA != uc_pdata->max_uA) { |
| 57 | debug("Invalid constraints for: %s\n", uc_pdata->name); |
| 58 | return -EINVAL; |
| 59 | } |
| 60 | |
| 61 | return uc_pdata->min_uA; |
| 62 | } |
| 63 | |
Keerthy | 0f2194d | 2017-06-13 09:53:46 +0530 | [diff] [blame] | 64 | static int fixed_regulator_get_enable(struct udevice *dev) |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 65 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 66 | return regulator_common_get_enable(dev, dev_get_plat(dev)); |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static int fixed_regulator_set_enable(struct udevice *dev, bool enable) |
| 70 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 71 | return regulator_common_set_enable(dev, dev_get_plat(dev), enable); |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static const struct dm_regulator_ops fixed_regulator_ops = { |
| 75 | .get_value = fixed_regulator_get_value, |
| 76 | .get_current = fixed_regulator_get_current, |
| 77 | .get_enable = fixed_regulator_get_enable, |
| 78 | .set_enable = fixed_regulator_set_enable, |
| 79 | }; |
| 80 | |
| 81 | static const struct udevice_id fixed_regulator_ids[] = { |
| 82 | { .compatible = "regulator-fixed" }, |
| 83 | { }, |
| 84 | }; |
| 85 | |
Walter Lozano | e3e2470 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 86 | U_BOOT_DRIVER(regulator_fixed) = { |
| 87 | .name = "regulator_fixed", |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 88 | .id = UCLASS_REGULATOR, |
| 89 | .ops = &fixed_regulator_ops, |
| 90 | .of_match = fixed_regulator_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 91 | .of_to_plat = fixed_regulator_of_to_plat, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 92 | .plat_auto = sizeof(struct regulator_common_platdata), |
Przemyslaw Marczak | 9923a8b | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 93 | }; |