Commit deea211aec45e95cdc4fed006526591fe70abe22

Authored by Simon Glass
1 parent 68f0081139

power: Add a regulator driver for the as3722 PMIC

This pmic includes regulators which should have their own driver. Add
a driver to support these.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-on: Beaver, Jetson-TK1
Tested-by: Stephen Warren <swarren@nvidia.com>

Showing 4 changed files with 167 additions and 0 deletions Side-by-side Diff

drivers/power/regulator/Kconfig
... ... @@ -34,6 +34,15 @@
34 34 by the PMIC device. This driver is controlled by a device tree node
35 35 which includes voltage limits.
36 36  
  37 +config REGULATOR_AS3722
  38 + bool "Enable driver for AS7322 regulator"
  39 + depends on DM_REGULATOR && PMIC_AS3722
  40 + help
  41 + Enable support for the regulator functions of the AS3722. The
  42 + driver implements enable/disable for step-down bucks and LDOs,
  43 + but does not yet support change voltages. Currently this must be
  44 + done using direct register writes to the PMIC.
  45 +
37 46 config DM_REGULATOR_PFUZE100
38 47 bool "Enable Driver Model for REGULATOR PFUZE100"
39 48 depends on DM_REGULATOR && DM_PMIC_PFUZE100
drivers/power/regulator/Makefile
... ... @@ -7,6 +7,7 @@
7 7  
8 8 obj-$(CONFIG_$(SPL_)DM_REGULATOR) += regulator-uclass.o
9 9 obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
  10 +obj-$(CONFIG_REGULATOR_AS3722) += as3722_regulator.o
10 11 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
11 12 obj-$(CONFIG_DM_REGULATOR_PFUZE100) += pfuze100.o
12 13 obj-$(CONFIG_REGULATOR_PWM) += pwm_regulator.o
drivers/power/regulator/as3722_regulator.c
  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 +};
include/power/as3722.h
... ... @@ -12,6 +12,14 @@
12 12 #define AS3722_GPIO_OUTPUT_VDDH (1 << 0)
13 13 #define AS3722_GPIO_INVERT (1 << 1)
14 14  
  15 +#define AS3722_DEVICE_ID 0x0c
  16 +#define AS3722_SD_VOLTAGE(n) (0x00 + (n))
  17 +#define AS3722_LDO_VOLTAGE(n) (0x10 + (n))
  18 +#define AS3722_SD_CONTROL 0x4d
  19 +#define AS3722_LDO_CONTROL 0x4e
  20 +#define AS3722_ASIC_ID1 0x90
  21 +#define AS3722_ASIC_ID2 0x91
  22 +
15 23 struct udevice;
16 24  
17 25 int as3722_init(struct udevice **devp);