Simon Glass | 8f18951 | 2017-07-25 08:30:10 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 Google, Inc |
| 3 | * Written by Simon Glass <sjg@chromium.org> |
| 4 | * |
| 5 | * Placeholder regulator driver for as3722. |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <errno.h> |
| 13 | #include <power/as3722.h> |
| 14 | #include <power/pmic.h> |
| 15 | #include <power/regulator.h> |
| 16 | |
| 17 | static int stepdown_get_value(struct udevice *dev) |
| 18 | { |
| 19 | return -ENOSYS; |
| 20 | } |
| 21 | |
| 22 | static int stepdown_set_value(struct udevice *dev, int uvolt) |
| 23 | { |
| 24 | return -ENOSYS; |
| 25 | } |
| 26 | |
| 27 | static int stepdown_set_enable(struct udevice *dev, bool enable) |
| 28 | { |
| 29 | struct udevice *pmic = dev_get_parent(dev); |
| 30 | int sd = dev->driver_data; |
| 31 | int ret; |
| 32 | |
| 33 | ret = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd); |
| 34 | if (ret < 0) { |
| 35 | debug("%s: failed to write SD control register: %d", __func__, |
| 36 | ret); |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int stepdown_get_enable(struct udevice *dev) |
| 44 | { |
| 45 | struct udevice *pmic = dev_get_parent(dev); |
| 46 | int sd = dev->driver_data; |
| 47 | int ret; |
| 48 | |
| 49 | ret = pmic_reg_read(pmic, AS3722_SD_CONTROL); |
| 50 | if (ret < 0) { |
| 51 | debug("%s: failed to read SD control register: %d", __func__, |
| 52 | ret); |
| 53 | return ret; |
| 54 | } |
| 55 | |
| 56 | return ret & (1 << sd) ? true : false; |
| 57 | } |
| 58 | |
| 59 | static int ldo_get_value(struct udevice *dev) |
| 60 | { |
| 61 | return -ENOSYS; |
| 62 | } |
| 63 | |
| 64 | static int ldo_set_value(struct udevice *dev, int uvolt) |
| 65 | { |
| 66 | return -ENOSYS; |
| 67 | } |
| 68 | |
| 69 | static int ldo_set_enable(struct udevice *dev, bool enable) |
| 70 | { |
| 71 | struct udevice *pmic = dev_get_parent(dev); |
| 72 | int ldo = dev->driver_data; |
| 73 | int ret; |
| 74 | |
| 75 | ret = pmic_clrsetbits(pmic, AS3722_LDO_CONTROL, 0, 1 << ldo); |
| 76 | if (ret < 0) { |
| 77 | debug("%s: failed to write LDO control register: %d", __func__, |
| 78 | ret); |
| 79 | return ret; |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static int ldo_get_enable(struct udevice *dev) |
| 86 | { |
| 87 | struct udevice *pmic = dev_get_parent(dev); |
| 88 | int ldo = dev->driver_data; |
| 89 | int ret; |
| 90 | |
| 91 | ret = pmic_reg_read(pmic, AS3722_LDO_CONTROL); |
| 92 | if (ret < 0) { |
| 93 | debug("%s: failed to read SD control register: %d", __func__, |
| 94 | ret); |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | return ret & (1 << ldo) ? true : false; |
| 99 | } |
| 100 | |
| 101 | static int as3722_stepdown_probe(struct udevice *dev) |
| 102 | { |
| 103 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 104 | |
| 105 | uc_pdata = dev_get_uclass_platdata(dev); |
| 106 | |
| 107 | uc_pdata->type = REGULATOR_TYPE_BUCK; |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static int as3722_ldo_probe(struct udevice *dev) |
| 113 | { |
| 114 | struct dm_regulator_uclass_platdata *uc_pdata; |
| 115 | |
| 116 | uc_pdata = dev_get_uclass_platdata(dev); |
| 117 | |
| 118 | uc_pdata->type = REGULATOR_TYPE_LDO; |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static const struct dm_regulator_ops as3722_stepdown_ops = { |
| 124 | .get_value = stepdown_get_value, |
| 125 | .set_value = stepdown_set_value, |
| 126 | .get_enable = stepdown_get_enable, |
| 127 | .set_enable = stepdown_set_enable, |
| 128 | }; |
| 129 | |
| 130 | static const struct dm_regulator_ops as3722_ldo_ops = { |
| 131 | .get_value = ldo_get_value, |
| 132 | .set_value = ldo_set_value, |
| 133 | .get_enable = ldo_get_enable, |
| 134 | .set_enable = ldo_set_enable, |
| 135 | }; |
| 136 | |
| 137 | U_BOOT_DRIVER(as3722_stepdown) = { |
| 138 | .name = "as3722_stepdown", |
| 139 | .id = UCLASS_REGULATOR, |
| 140 | .ops = &as3722_stepdown_ops, |
| 141 | .probe = as3722_stepdown_probe, |
| 142 | }; |
| 143 | |
| 144 | U_BOOT_DRIVER(as3722_ldo) = { |
| 145 | .name = "as3722_ldo", |
| 146 | .id = UCLASS_REGULATOR, |
| 147 | .ops = &as3722_ldo_ops, |
| 148 | .probe = as3722_ldo_probe, |
| 149 | }; |