uboot/drivers/power/pmic/lp873x.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com>
   4 * Keerthy <j-keerthy@ti.com>
   5 */
   6
   7#include <common.h>
   8#include <fdtdec.h>
   9#include <errno.h>
  10#include <dm.h>
  11#include <i2c.h>
  12#include <log.h>
  13#include <power/pmic.h>
  14#include <power/regulator.h>
  15#include <power/lp873x.h>
  16#include <dm/device.h>
  17
  18static const struct pmic_child_info pmic_children_info[] = {
  19        { .prefix = "ldo", .driver = LP873X_LDO_DRIVER },
  20        { .prefix = "buck", .driver = LP873X_BUCK_DRIVER },
  21        { },
  22};
  23
  24static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff,
  25                          int len)
  26{
  27        if (dm_i2c_write(dev, reg, buff, len)) {
  28                pr_err("write error to device: %p register: %#x!\n", dev, reg);
  29                return -EIO;
  30        }
  31
  32        return 0;
  33}
  34
  35static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  36{
  37        if (dm_i2c_read(dev, reg, buff, len)) {
  38                pr_err("read error from device: %p register: %#x!\n", dev, reg);
  39                return -EIO;
  40        }
  41
  42        return 0;
  43}
  44
  45static int lp873x_bind(struct udevice *dev)
  46{
  47        ofnode regulators_node;
  48        int children;
  49
  50        regulators_node = dev_read_subnode(dev, "regulators");
  51        if (!ofnode_valid(regulators_node)) {
  52                debug("%s: %s regulators subnode not found!\n", __func__,
  53                      dev->name);
  54                return -ENXIO;
  55        }
  56
  57        children = pmic_bind_children(dev, regulators_node, pmic_children_info);
  58        if (!children)
  59                printf("%s: %s - no child found\n", __func__, dev->name);
  60
  61        /* Always return success for this device */
  62        return 0;
  63}
  64
  65static struct dm_pmic_ops lp873x_ops = {
  66        .read = lp873x_read,
  67        .write = lp873x_write,
  68};
  69
  70static const struct udevice_id lp873x_ids[] = {
  71        { .compatible = "ti,lp8732", .data = LP8732 },
  72        { .compatible = "ti,lp8733" , .data = LP8733 },
  73        { }
  74};
  75
  76U_BOOT_DRIVER(pmic_lp873x) = {
  77        .name = "lp873x_pmic",
  78        .id = UCLASS_PMIC,
  79        .of_match = lp873x_ids,
  80        .bind = lp873x_bind,
  81        .ops = &lp873x_ops,
  82};
  83