blob: ddc30604cff86d6d95e5051fa46fb289c4f0bbe1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +02002/*
3 * Qualcomm pm8916 pmic driver
4 *
5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +02006 */
7#include <common.h>
8#include <dm.h>
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +02009#include <power/pmic.h>
10#include <spmi/spmi.h>
11
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +020012#define PID_SHIFT 8
13#define PID_MASK (0xFF << PID_SHIFT)
14#define REG_MASK 0xFF
15
16struct pm8916_priv {
Tom Rini3bfc8152016-04-12 15:11:24 -040017 uint32_t usid; /* Slave ID on SPMI bus */
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +020018};
19
20static int pm8916_reg_count(struct udevice *dev)
21{
22 return 0xFFFF;
23}
24
25static int pm8916_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 int len)
27{
28 struct pm8916_priv *priv = dev_get_priv(dev);
29
30 if (len != 1)
31 return -EINVAL;
32
33 return spmi_reg_write(dev->parent, priv->usid,
34 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK,
35 *buff);
36}
37
38static int pm8916_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
39{
40 struct pm8916_priv *priv = dev_get_priv(dev);
41 int val;
42
43 if (len != 1)
44 return -EINVAL;
45
46 val = spmi_reg_read(dev->parent, priv->usid,
47 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK);
48
49 if (val < 0)
50 return val;
51 *buff = val;
52 return 0;
53}
54
55static struct dm_pmic_ops pm8916_ops = {
56 .reg_count = pm8916_reg_count,
57 .read = pm8916_read,
58 .write = pm8916_write,
59};
60
61static const struct udevice_id pm8916_ids[] = {
62 { .compatible = "qcom,spmi-pmic" },
63 { }
64};
65
66static int pm8916_probe(struct udevice *dev)
67{
68 struct pm8916_priv *priv = dev_get_priv(dev);
69
Simon Glass04048d52017-05-18 20:10:01 -060070 priv->usid = dev_read_addr(dev);
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +020071
72 if (priv->usid == FDT_ADDR_T_NONE)
73 return -EINVAL;
74
75 return 0;
76}
77
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +020078U_BOOT_DRIVER(pmic_pm8916) = {
79 .name = "pmic_pm8916",
80 .id = UCLASS_PMIC,
81 .of_match = pm8916_ids,
Simon Glass91195482016-07-05 17:10:10 -060082 .bind = dm_scan_fdt_dev,
Mateusz Kulikowskic2f74c82016-03-31 23:12:30 +020083 .probe = pm8916_probe,
84 .ops = &pm8916_ops,
85 .priv_auto_alloc_size = sizeof(struct pm8916_priv),
86};