blob: 92d0a95859b0fed240363b04053e04efbb4a1f40 [file] [log] [blame]
Sumit Garg60900b42022-08-04 19:57:17 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Qualcomm generic pmic driver
4 *
5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
6 */
Sumit Garg60900b42022-08-04 19:57:17 +05307#include <dm.h>
8#include <power/pmic.h>
9#include <spmi/spmi.h>
10
11#define PID_SHIFT 8
12#define PID_MASK (0xFF << PID_SHIFT)
13#define REG_MASK 0xFF
14
15struct pmic_qcom_priv {
16 uint32_t usid; /* Slave ID on SPMI bus */
17};
18
19static int pmic_qcom_reg_count(struct udevice *dev)
20{
21 return 0xFFFF;
22}
23
24static int pmic_qcom_write(struct udevice *dev, uint reg, const uint8_t *buff,
25 int len)
26{
27 struct pmic_qcom_priv *priv = dev_get_priv(dev);
28
29 if (len != 1)
30 return -EINVAL;
31
32 return spmi_reg_write(dev->parent, priv->usid,
33 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK,
34 *buff);
35}
36
37static int pmic_qcom_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
38{
39 struct pmic_qcom_priv *priv = dev_get_priv(dev);
40 int val;
41
42 if (len != 1)
43 return -EINVAL;
44
45 val = spmi_reg_read(dev->parent, priv->usid,
46 (reg & PID_MASK) >> PID_SHIFT, reg & REG_MASK);
47
48 if (val < 0)
49 return val;
50 *buff = val;
51 return 0;
52}
53
54static struct dm_pmic_ops pmic_qcom_ops = {
55 .reg_count = pmic_qcom_reg_count,
56 .read = pmic_qcom_read,
57 .write = pmic_qcom_write,
58};
59
60static const struct udevice_id pmic_qcom_ids[] = {
61 { .compatible = "qcom,spmi-pmic" },
62 { }
63};
64
65static int pmic_qcom_probe(struct udevice *dev)
66{
67 struct pmic_qcom_priv *priv = dev_get_priv(dev);
Caleb Connolly783cb3f2023-12-05 13:46:54 +000068 int ret;
Sumit Garg60900b42022-08-04 19:57:17 +053069
Caleb Connolly783cb3f2023-12-05 13:46:54 +000070 /*
71 * dev_read_addr() can't be used here because the reg property actually
72 * contains two discrete values, not a single 64-bit address.
73 * The address is the first value.
74 */
75 ret = ofnode_read_u32_index(dev_ofnode(dev), "reg", 0, &priv->usid);
76 if (ret < 0)
Sumit Garg60900b42022-08-04 19:57:17 +053077 return -EINVAL;
78
Caleb Connolly783cb3f2023-12-05 13:46:54 +000079 debug("usid: %d\n", priv->usid);
80
Sumit Garg60900b42022-08-04 19:57:17 +053081 return 0;
82}
83
84U_BOOT_DRIVER(pmic_qcom) = {
85 .name = "pmic_qcom",
86 .id = UCLASS_PMIC,
87 .of_match = pmic_qcom_ids,
88 .bind = dm_scan_fdt_dev,
89 .probe = pmic_qcom_probe,
90 .ops = &pmic_qcom_ops,
91 .priv_auto = sizeof(struct pmic_qcom_priv),
92};