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