Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Samsung Electronics |
| 4 | * Przemyslaw Marczak <p.marczak@samsung.com> |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Patrick Delaunay | 8131335 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 7 | #define LOG_CATEGORY UCLASS_ADC |
| 8 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 9 | #include <common.h> |
| 10 | #include <errno.h> |
Fabrice Gasnier | b341a43 | 2018-11-12 14:03:58 +0100 | [diff] [blame] | 11 | #include <div64.h> |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include <dm/lists.h> |
| 14 | #include <dm/device-internal.h> |
| 15 | #include <dm/uclass-internal.h> |
| 16 | #include <adc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 18 | #include <power/regulator.h> |
| 19 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 20 | #define ADC_UCLASS_PLATDATA_SIZE sizeof(struct adc_uclass_plat) |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 21 | #define CHECK_NUMBER true |
| 22 | #define CHECK_MASK (!CHECK_NUMBER) |
| 23 | |
| 24 | /* TODO: add support for timer uclass (for early calls) */ |
Tom Rini | 8f0dfd4 | 2022-12-02 16:42:43 -0500 | [diff] [blame] | 25 | #ifdef CONFIG_SANDBOX |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 26 | #define sdelay(x) udelay(x) |
| 27 | #else |
| 28 | extern void sdelay(unsigned long loops); |
| 29 | #endif |
| 30 | |
| 31 | static int check_channel(struct udevice *dev, int value, bool number_or_mask, |
| 32 | const char *caller_function) |
| 33 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 34 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 35 | unsigned mask = number_or_mask ? (1 << value) : value; |
| 36 | |
| 37 | /* For the real ADC hardware, some ADC channels can be inactive. |
| 38 | * For example if device has 4 analog channels, and only channels |
| 39 | * 1-st and 3-rd are valid, then channel mask is: 0b1010, so request |
| 40 | * with mask 0b1110 should return an error. |
| 41 | */ |
| 42 | if ((uc_pdata->channel_mask >= mask) && (uc_pdata->channel_mask & mask)) |
| 43 | return 0; |
| 44 | |
| 45 | printf("Error in %s/%s().\nWrong channel selection for device: %s\n", |
| 46 | __FILE__, caller_function, dev->name); |
| 47 | |
| 48 | return -EINVAL; |
| 49 | } |
| 50 | |
| 51 | static int adc_supply_enable(struct udevice *dev) |
| 52 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 53 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 54 | const char *supply_type; |
| 55 | int ret = 0; |
| 56 | |
| 57 | if (uc_pdata->vdd_supply) { |
| 58 | supply_type = "vdd"; |
| 59 | ret = regulator_set_enable(uc_pdata->vdd_supply, true); |
| 60 | } |
| 61 | |
| 62 | if (!ret && uc_pdata->vss_supply) { |
| 63 | supply_type = "vss"; |
| 64 | ret = regulator_set_enable(uc_pdata->vss_supply, true); |
| 65 | } |
| 66 | |
| 67 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 68 | pr_err("%s: can't enable %s-supply!", dev->name, supply_type); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 69 | |
| 70 | return ret; |
| 71 | } |
| 72 | |
| 73 | int adc_data_mask(struct udevice *dev, unsigned int *data_mask) |
| 74 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 75 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 76 | |
| 77 | if (!uc_pdata) |
| 78 | return -ENOSYS; |
| 79 | |
| 80 | *data_mask = uc_pdata->data_mask; |
| 81 | return 0; |
| 82 | } |
| 83 | |
Fabrice Gasnier | b341a43 | 2018-11-12 14:03:58 +0100 | [diff] [blame] | 84 | int adc_channel_mask(struct udevice *dev, unsigned int *channel_mask) |
| 85 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 86 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Fabrice Gasnier | b341a43 | 2018-11-12 14:03:58 +0100 | [diff] [blame] | 87 | |
| 88 | if (!uc_pdata) |
| 89 | return -ENOSYS; |
| 90 | |
| 91 | *channel_mask = uc_pdata->channel_mask; |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 96 | int adc_stop(struct udevice *dev) |
| 97 | { |
| 98 | const struct adc_ops *ops = dev_get_driver_ops(dev); |
| 99 | |
| 100 | if (!ops->stop) |
| 101 | return -ENOSYS; |
| 102 | |
| 103 | return ops->stop(dev); |
| 104 | } |
| 105 | |
| 106 | int adc_start_channel(struct udevice *dev, int channel) |
| 107 | { |
| 108 | const struct adc_ops *ops = dev_get_driver_ops(dev); |
| 109 | int ret; |
| 110 | |
| 111 | if (!ops->start_channel) |
| 112 | return -ENOSYS; |
| 113 | |
| 114 | ret = check_channel(dev, channel, CHECK_NUMBER, __func__); |
| 115 | if (ret) |
| 116 | return ret; |
| 117 | |
| 118 | ret = adc_supply_enable(dev); |
| 119 | if (ret) |
| 120 | return ret; |
| 121 | |
| 122 | return ops->start_channel(dev, channel); |
| 123 | } |
| 124 | |
| 125 | int adc_start_channels(struct udevice *dev, unsigned int channel_mask) |
| 126 | { |
| 127 | const struct adc_ops *ops = dev_get_driver_ops(dev); |
| 128 | int ret; |
| 129 | |
| 130 | if (!ops->start_channels) |
| 131 | return -ENOSYS; |
| 132 | |
| 133 | ret = check_channel(dev, channel_mask, CHECK_MASK, __func__); |
| 134 | if (ret) |
| 135 | return ret; |
| 136 | |
| 137 | ret = adc_supply_enable(dev); |
| 138 | if (ret) |
| 139 | return ret; |
| 140 | |
| 141 | return ops->start_channels(dev, channel_mask); |
| 142 | } |
| 143 | |
| 144 | int adc_channel_data(struct udevice *dev, int channel, unsigned int *data) |
| 145 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 146 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 147 | const struct adc_ops *ops = dev_get_driver_ops(dev); |
| 148 | unsigned int timeout_us = uc_pdata->data_timeout_us; |
| 149 | int ret; |
| 150 | |
| 151 | if (!ops->channel_data) |
| 152 | return -ENOSYS; |
| 153 | |
| 154 | ret = check_channel(dev, channel, CHECK_NUMBER, __func__); |
| 155 | if (ret) |
| 156 | return ret; |
| 157 | |
| 158 | do { |
| 159 | ret = ops->channel_data(dev, channel, data); |
| 160 | if (!ret || ret != -EBUSY) |
| 161 | break; |
| 162 | |
| 163 | /* TODO: use timer uclass (for early calls). */ |
| 164 | sdelay(5); |
| 165 | } while (timeout_us--); |
| 166 | |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | int adc_channels_data(struct udevice *dev, unsigned int channel_mask, |
| 171 | struct adc_channel *channels) |
| 172 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 173 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 174 | unsigned int timeout_us = uc_pdata->multidata_timeout_us; |
| 175 | const struct adc_ops *ops = dev_get_driver_ops(dev); |
| 176 | int ret; |
| 177 | |
| 178 | if (!ops->channels_data) |
| 179 | return -ENOSYS; |
| 180 | |
| 181 | ret = check_channel(dev, channel_mask, CHECK_MASK, __func__); |
| 182 | if (ret) |
| 183 | return ret; |
| 184 | |
| 185 | do { |
| 186 | ret = ops->channels_data(dev, channel_mask, channels); |
| 187 | if (!ret || ret != -EBUSY) |
| 188 | break; |
| 189 | |
| 190 | /* TODO: use timer uclass (for early calls). */ |
| 191 | sdelay(5); |
| 192 | } while (timeout_us--); |
| 193 | |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | int adc_channel_single_shot(const char *name, int channel, unsigned int *data) |
| 198 | { |
| 199 | struct udevice *dev; |
| 200 | int ret; |
| 201 | |
| 202 | ret = uclass_get_device_by_name(UCLASS_ADC, name, &dev); |
| 203 | if (ret) |
| 204 | return ret; |
| 205 | |
| 206 | ret = adc_start_channel(dev, channel); |
| 207 | if (ret) |
| 208 | return ret; |
| 209 | |
| 210 | ret = adc_channel_data(dev, channel, data); |
| 211 | if (ret) |
| 212 | return ret; |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static int _adc_channels_single_shot(struct udevice *dev, |
| 218 | unsigned int channel_mask, |
| 219 | struct adc_channel *channels) |
| 220 | { |
| 221 | unsigned int data; |
| 222 | int channel, ret; |
| 223 | |
| 224 | for (channel = 0; channel <= ADC_MAX_CHANNEL; channel++) { |
| 225 | /* Check channel bit. */ |
| 226 | if (!((channel_mask >> channel) & 0x1)) |
| 227 | continue; |
| 228 | |
| 229 | ret = adc_start_channel(dev, channel); |
| 230 | if (ret) |
| 231 | return ret; |
| 232 | |
| 233 | ret = adc_channel_data(dev, channel, &data); |
| 234 | if (ret) |
| 235 | return ret; |
| 236 | |
| 237 | channels->id = channel; |
| 238 | channels->data = data; |
| 239 | channels++; |
| 240 | } |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | int adc_channels_single_shot(const char *name, unsigned int channel_mask, |
| 246 | struct adc_channel *channels) |
| 247 | { |
| 248 | struct udevice *dev; |
| 249 | int ret; |
| 250 | |
| 251 | ret = uclass_get_device_by_name(UCLASS_ADC, name, &dev); |
| 252 | if (ret) |
| 253 | return ret; |
| 254 | |
| 255 | ret = adc_start_channels(dev, channel_mask); |
| 256 | if (ret) |
| 257 | goto try_manual; |
| 258 | |
| 259 | ret = adc_channels_data(dev, channel_mask, channels); |
| 260 | if (ret) |
| 261 | return ret; |
| 262 | |
| 263 | return 0; |
| 264 | |
| 265 | try_manual: |
| 266 | if (ret != -ENOSYS) |
| 267 | return ret; |
| 268 | |
| 269 | return _adc_channels_single_shot(dev, channel_mask, channels); |
| 270 | } |
| 271 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 272 | static int adc_vdd_plat_update(struct udevice *dev) |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 273 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 274 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 275 | int ret; |
| 276 | |
| 277 | /* Warning! |
| 278 | * This function can't return supply device before its bind. |
| 279 | * Please pay attention to proper fdt scan sequence. If ADC device |
| 280 | * will bind before its supply regulator device, then the below 'get' |
| 281 | * will return an error. |
| 282 | */ |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 283 | if (!uc_pdata->vdd_supply) |
| 284 | return 0; |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 285 | |
| 286 | ret = regulator_get_value(uc_pdata->vdd_supply); |
| 287 | if (ret < 0) |
| 288 | return ret; |
| 289 | |
| 290 | uc_pdata->vdd_microvolts = ret; |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 295 | static int adc_vss_plat_update(struct udevice *dev) |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 296 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 297 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 298 | int ret; |
| 299 | |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 300 | if (!uc_pdata->vss_supply) |
| 301 | return 0; |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 302 | |
| 303 | ret = regulator_get_value(uc_pdata->vss_supply); |
| 304 | if (ret < 0) |
| 305 | return ret; |
| 306 | |
| 307 | uc_pdata->vss_microvolts = ret; |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | int adc_vdd_value(struct udevice *dev, int *uV) |
| 313 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 314 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 315 | int ret, value_sign = uc_pdata->vdd_polarity_negative ? -1 : 1; |
| 316 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 317 | /* Update the regulator Value. */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 318 | ret = adc_vdd_plat_update(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 319 | if (ret) |
| 320 | return ret; |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 321 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 322 | if (uc_pdata->vdd_microvolts == -ENODATA) |
| 323 | return -ENODATA; |
| 324 | |
| 325 | *uV = uc_pdata->vdd_microvolts * value_sign; |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | int adc_vss_value(struct udevice *dev, int *uV) |
| 331 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 332 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 333 | int ret, value_sign = uc_pdata->vss_polarity_negative ? -1 : 1; |
| 334 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 335 | /* Update the regulator Value. */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 336 | ret = adc_vss_plat_update(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 337 | if (ret) |
| 338 | return ret; |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 339 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 340 | if (uc_pdata->vss_microvolts == -ENODATA) |
| 341 | return -ENODATA; |
| 342 | |
| 343 | *uV = uc_pdata->vss_microvolts * value_sign; |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
Fabrice Gasnier | b341a43 | 2018-11-12 14:03:58 +0100 | [diff] [blame] | 348 | int adc_raw_to_uV(struct udevice *dev, unsigned int raw, int *uV) |
| 349 | { |
| 350 | unsigned int data_mask; |
| 351 | int ret, val, vref; |
| 352 | u64 raw64 = raw; |
| 353 | |
| 354 | ret = adc_vdd_value(dev, &vref); |
| 355 | if (ret) |
| 356 | return ret; |
| 357 | |
| 358 | if (!adc_vss_value(dev, &val)) |
| 359 | vref -= val; |
| 360 | |
| 361 | ret = adc_data_mask(dev, &data_mask); |
| 362 | if (ret) |
| 363 | return ret; |
| 364 | |
| 365 | raw64 *= vref; |
| 366 | do_div(raw64, data_mask); |
| 367 | *uV = raw64; |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 372 | static int adc_vdd_plat_set(struct udevice *dev) |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 373 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 374 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Simon Glass | d22709c | 2017-05-18 20:09:37 -0600 | [diff] [blame] | 375 | int ret; |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 376 | char *prop; |
| 377 | |
| 378 | prop = "vdd-polarity-negative"; |
Simon Glass | d22709c | 2017-05-18 20:09:37 -0600 | [diff] [blame] | 379 | uc_pdata->vdd_polarity_negative = dev_read_bool(dev, prop); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 380 | |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 381 | /* Optionally get regulators */ |
| 382 | ret = device_get_supply_regulator(dev, "vdd-supply", |
| 383 | &uc_pdata->vdd_supply); |
| 384 | if (!ret) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 385 | return adc_vdd_plat_update(dev); |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 386 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 387 | if (ret != -ENOENT) |
| 388 | return ret; |
| 389 | |
| 390 | /* No vdd-supply phandle. */ |
| 391 | prop = "vdd-microvolts"; |
Simon Glass | d22709c | 2017-05-18 20:09:37 -0600 | [diff] [blame] | 392 | uc_pdata->vdd_microvolts = dev_read_u32_default(dev, prop, -ENODATA); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 397 | static int adc_vss_plat_set(struct udevice *dev) |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 398 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 399 | struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); |
Simon Glass | d22709c | 2017-05-18 20:09:37 -0600 | [diff] [blame] | 400 | int ret; |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 401 | char *prop; |
| 402 | |
| 403 | prop = "vss-polarity-negative"; |
Simon Glass | d22709c | 2017-05-18 20:09:37 -0600 | [diff] [blame] | 404 | uc_pdata->vss_polarity_negative = dev_read_bool(dev, prop); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 405 | |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 406 | ret = device_get_supply_regulator(dev, "vss-supply", |
| 407 | &uc_pdata->vss_supply); |
| 408 | if (!ret) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 409 | return adc_vss_plat_update(dev); |
Fabrice Gasnier | 91d954b | 2018-07-24 16:31:29 +0200 | [diff] [blame] | 410 | |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 411 | if (ret != -ENOENT) |
| 412 | return ret; |
| 413 | |
| 414 | /* No vss-supply phandle. */ |
| 415 | prop = "vss-microvolts"; |
Simon Glass | d22709c | 2017-05-18 20:09:37 -0600 | [diff] [blame] | 416 | uc_pdata->vss_microvolts = dev_read_u32_default(dev, prop, -ENODATA); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int adc_pre_probe(struct udevice *dev) |
| 422 | { |
| 423 | int ret; |
| 424 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 425 | /* Set ADC VDD plat: polarity, uV, regulator (phandle). */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 426 | ret = adc_vdd_plat_set(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 427 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 428 | pr_err("%s: Can't update Vdd. Error: %d", dev->name, ret); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 429 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 430 | /* Set ADC VSS plat: polarity, uV, regulator (phandle). */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 431 | ret = adc_vss_plat_set(dev); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 432 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 433 | pr_err("%s: Can't update Vss. Error: %d", dev->name, ret); |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | UCLASS_DRIVER(adc) = { |
| 439 | .id = UCLASS_ADC, |
| 440 | .name = "adc", |
| 441 | .pre_probe = adc_pre_probe, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 442 | .per_device_plat_auto = ADC_UCLASS_PLATDATA_SIZE, |
Przemyslaw Marczak | e0cb85b | 2015-10-27 13:08:00 +0100 | [diff] [blame] | 443 | }; |