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