Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | 3753f28 | 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 | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 12 | #include <power/pmic.h> |
| 13 | #include <power/regulator.h> |
| 14 | |
Simon Glass | 1c1ddf6 | 2020-07-19 10:15:44 -0600 | [diff] [blame] | 15 | #include "regulator_common.h" |
| 16 | |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 17 | static int fixed_regulator_ofdata_to_platdata(struct udevice *dev) |
| 18 | { |
| 19 | struct dm_regulator_uclass_platdata *uc_pdata; |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 20 | struct regulator_common_platdata *dev_pdata; |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 21 | |
| 22 | dev_pdata = dev_get_platdata(dev); |
| 23 | uc_pdata = dev_get_uclass_platdata(dev); |
| 24 | if (!uc_pdata) |
| 25 | return -ENXIO; |
| 26 | |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 27 | uc_pdata->type = REGULATOR_TYPE_FIXED; |
| 28 | |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 29 | return regulator_common_ofdata_to_platdata(dev, dev_pdata, "gpio"); |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static int fixed_regulator_get_value(struct udevice *dev) |
| 33 | { |
| 34 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 35 | |
| 36 | uc_pdata = dev_get_uclass_platdata(dev); |
| 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 | { |
| 50 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 51 | |
| 52 | uc_pdata = dev_get_uclass_platdata(dev); |
| 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 | 8690d6a | 2017-06-13 09:53:46 +0530 | [diff] [blame] | 64 | static int fixed_regulator_get_enable(struct udevice *dev) |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 65 | { |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 66 | return regulator_common_get_enable(dev, dev_get_platdata(dev)); |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static int fixed_regulator_set_enable(struct udevice *dev, bool enable) |
| 70 | { |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 71 | return regulator_common_set_enable(dev, dev_get_platdata(dev), enable); |
Przemyslaw Marczak | 3753f28 | 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 | 2901ac6 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 86 | U_BOOT_DRIVER(regulator_fixed) = { |
| 87 | .name = "regulator_fixed", |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 88 | .id = UCLASS_REGULATOR, |
| 89 | .ops = &fixed_regulator_ops, |
| 90 | .of_match = fixed_regulator_ids, |
| 91 | .ofdata_to_platdata = fixed_regulator_ofdata_to_platdata, |
Sven Schwermer | 2595752 | 2019-06-24 13:03:33 +0200 | [diff] [blame] | 92 | .platdata_auto_alloc_size = sizeof(struct regulator_common_platdata), |
Przemyslaw Marczak | 3753f28 | 2015-04-20 20:07:48 +0200 | [diff] [blame] | 93 | }; |