u-boot/drivers/power/pmic/pm8916.c
Simon Glass a821c4af79 dm: Rename dev_addr..() functions
These support the flat device tree. We want to use the dev_read_..()
prefix for functions that support both flat tree and live tree. So rename
the existing functions to avoid confusion.

In the end we will have:

   1. dev_read_addr...()    - works on devices, supports flat/live tree
   2. devfdt_get_addr...()  - current functions, flat tree only
   3. of_get_address() etc. - new functions, live tree only

All drivers will be written to use 1. That function will in turn call
either 2 or 3 depending on whether the flat or live tree is in use.

Note this involves changing some dead code - the imx_lpi2c.c file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01 07:03:01 -06:00

89 lines
1.7 KiB
C

/*
* Qualcomm pm8916 pmic driver
*
* (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <dm.h>
#include <power/pmic.h>
#include <spmi/spmi.h>
DECLARE_GLOBAL_DATA_PTR;
#define PID_SHIFT 8
#define PID_MASK (0xFF << PID_SHIFT)
#define REG_MASK 0xFF
struct pm8916_priv {
uint32_t usid; /* Slave ID on SPMI bus */
};
static int pm8916_reg_count(struct udevice *dev)
{
return 0xFFFF;
}
static int pm8916_write(struct udevice *dev, uint reg, const uint8_t *buff,
int len)
{
struct pm8916_priv *priv = dev_get_priv(dev);
if (len != 1)
return -EINVAL;
return spmi_reg_write(dev->parent, priv->usid,
(reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK,
*buff);
}
static int pm8916_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
{
struct pm8916_priv *priv = dev_get_priv(dev);
int val;
if (len != 1)
return -EINVAL;
val = spmi_reg_read(dev->parent, priv->usid,
(reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK);
if (val < 0)
return val;
*buff = val;
return 0;
}
static struct dm_pmic_ops pm8916_ops = {
.reg_count = pm8916_reg_count,
.read = pm8916_read,
.write = pm8916_write,
};
static const struct udevice_id pm8916_ids[] = {
{ .compatible = "qcom,spmi-pmic" },
{ }
};
static int pm8916_probe(struct udevice *dev)
{
struct pm8916_priv *priv = dev_get_priv(dev);
priv->usid = devfdt_get_addr(dev);
if (priv->usid == FDT_ADDR_T_NONE)
return -EINVAL;
return 0;
}
U_BOOT_DRIVER(pmic_pm8916) = {
.name = "pmic_pm8916",
.id = UCLASS_PMIC,
.of_match = pm8916_ids,
.bind = dm_scan_fdt_dev,
.probe = pm8916_probe,
.ops = &pm8916_ops,
.priv_auto_alloc_size = sizeof(struct pm8916_priv),
};