blob: 2b65c697ec9431a87497b29011638464fcef628e [file] [log] [blame]
Mateusz Kulikowski0be548f2016-03-31 23:12:30 +02001/*
2 * Qualcomm pm8916 pmic driver
3 *
4 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8#include <common.h>
9#include <dm.h>
Mateusz Kulikowski0be548f2016-03-31 23:12:30 +020010#include <power/pmic.h>
11#include <spmi/spmi.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15#define PID_SHIFT 8
16#define PID_MASK (0xFF << PID_SHIFT)
17#define REG_MASK 0xFF
18
19struct pm8916_priv {
Tom Rini96504b62016-04-12 15:11:24 -040020 uint32_t usid; /* Slave ID on SPMI bus */
Mateusz Kulikowski0be548f2016-03-31 23:12:30 +020021};
22
23static int pm8916_reg_count(struct udevice *dev)
24{
25 return 0xFFFF;
26}
27
28static int pm8916_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 int len)
30{
31 struct pm8916_priv *priv = dev_get_priv(dev);
32
33 if (len != 1)
34 return -EINVAL;
35
36 return spmi_reg_write(dev->parent, priv->usid,
37 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK,
38 *buff);
39}
40
41static int pm8916_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
42{
43 struct pm8916_priv *priv = dev_get_priv(dev);
44 int val;
45
46 if (len != 1)
47 return -EINVAL;
48
49 val = spmi_reg_read(dev->parent, priv->usid,
50 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK);
51
52 if (val < 0)
53 return val;
54 *buff = val;
55 return 0;
56}
57
58static struct dm_pmic_ops pm8916_ops = {
59 .reg_count = pm8916_reg_count,
60 .read = pm8916_read,
61 .write = pm8916_write,
62};
63
64static const struct udevice_id pm8916_ids[] = {
65 { .compatible = "qcom,spmi-pmic" },
66 { }
67};
68
69static int pm8916_probe(struct udevice *dev)
70{
71 struct pm8916_priv *priv = dev_get_priv(dev);
72
73 priv->usid = dev_get_addr(dev);
74
75 if (priv->usid == FDT_ADDR_T_NONE)
76 return -EINVAL;
77
78 return 0;
79}
80
Mateusz Kulikowski0be548f2016-03-31 23:12:30 +020081U_BOOT_DRIVER(pmic_pm8916) = {
82 .name = "pmic_pm8916",
83 .id = UCLASS_PMIC,
84 .of_match = pm8916_ids,
Simon Glass18230342016-07-05 17:10:10 -060085 .bind = dm_scan_fdt_dev,
Mateusz Kulikowski0be548f2016-03-31 23:12:30 +020086 .probe = pm8916_probe,
87 .ops = &pm8916_ops,
88 .priv_auto_alloc_size = sizeof(struct pm8916_priv),
89};