blob: 9acf5f55f7362eb34a54252363e8c85939c9f0f6 [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>
10#include <dm/root.h>
11#include <power/pmic.h>
12#include <spmi/spmi.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16#define PID_SHIFT 8
17#define PID_MASK (0xFF << PID_SHIFT)
18#define REG_MASK 0xFF
19
20struct pm8916_priv {
21 uint16_t usid; /* Slave ID on SPMI bus */
22};
23
24static int pm8916_reg_count(struct udevice *dev)
25{
26 return 0xFFFF;
27}
28
29static int pm8916_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 int len)
31{
32 struct pm8916_priv *priv = dev_get_priv(dev);
33
34 if (len != 1)
35 return -EINVAL;
36
37 return spmi_reg_write(dev->parent, priv->usid,
38 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK,
39 *buff);
40}
41
42static int pm8916_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
43{
44 struct pm8916_priv *priv = dev_get_priv(dev);
45 int val;
46
47 if (len != 1)
48 return -EINVAL;
49
50 val = spmi_reg_read(dev->parent, priv->usid,
51 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK);
52
53 if (val < 0)
54 return val;
55 *buff = val;
56 return 0;
57}
58
59static struct dm_pmic_ops pm8916_ops = {
60 .reg_count = pm8916_reg_count,
61 .read = pm8916_read,
62 .write = pm8916_write,
63};
64
65static const struct udevice_id pm8916_ids[] = {
66 { .compatible = "qcom,spmi-pmic" },
67 { }
68};
69
70static int pm8916_probe(struct udevice *dev)
71{
72 struct pm8916_priv *priv = dev_get_priv(dev);
73
74 priv->usid = dev_get_addr(dev);
75
76 if (priv->usid == FDT_ADDR_T_NONE)
77 return -EINVAL;
78
79 return 0;
80}
81
82
83static int pm8916_bind(struct udevice *dev)
84{
85 return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
86}
87
88U_BOOT_DRIVER(pmic_pm8916) = {
89 .name = "pmic_pm8916",
90 .id = UCLASS_PMIC,
91 .of_match = pm8916_ids,
92 .bind = pm8916_bind,
93 .probe = pm8916_probe,
94 .ops = &pm8916_ops,
95 .priv_auto_alloc_size = sizeof(struct pm8916_priv),
96};