blob: 1cacc00aa6c95e7d03b6e2ecd6b61207edad62fc [file] [log] [blame]
Thomas Gleixner97fb5e82019-05-29 07:17:58 -07001// SPDX-License-Identifier: GPL-2.0-only
Josh Cartwrightc3a973a2014-08-01 17:30:48 +03002/*
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
Josh Cartwrightc3a973a2014-08-01 17:30:48 +03004 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/spmi.h>
9#include <linux/regmap.h>
10#include <linux/of_platform.h>
11
Ivan T. Ivanovdc716bb2015-03-17 12:47:24 +020012#define PMIC_REV2 0x101
13#define PMIC_REV3 0x102
14#define PMIC_REV4 0x103
15#define PMIC_TYPE 0x104
16#define PMIC_SUBTYPE 0x105
17
18#define PMIC_TYPE_VALUE 0x51
19
20#define COMMON_SUBTYPE 0x00
21#define PM8941_SUBTYPE 0x01
22#define PM8841_SUBTYPE 0x02
23#define PM8019_SUBTYPE 0x03
24#define PM8226_SUBTYPE 0x04
25#define PM8110_SUBTYPE 0x05
26#define PMA8084_SUBTYPE 0x06
27#define PMI8962_SUBTYPE 0x07
28#define PMD9635_SUBTYPE 0x08
29#define PM8994_SUBTYPE 0x09
30#define PMI8994_SUBTYPE 0x0a
31#define PM8916_SUBTYPE 0x0b
32#define PM8004_SUBTYPE 0x0c
33#define PM8909_SUBTYPE 0x0d
Bjorn Anderssone7488f32021-10-17 09:12:18 -070034#define PM8028_SUBTYPE 0x0e
35#define PM8901_SUBTYPE 0x0f
Angelo G. Del Regnof5b4c8b2019-09-21 11:50:42 +020036#define PM8950_SUBTYPE 0x10
37#define PMI8950_SUBTYPE 0x11
Stephen Boydc04da892018-05-02 09:35:35 -070038#define PM8998_SUBTYPE 0x14
39#define PMI8998_SUBTYPE 0x15
40#define PM8005_SUBTYPE 0x18
AngeloGioacchino Del Regnoa4b9be22020-09-26 14:55:48 +020041#define PM660L_SUBTYPE 0x1A
42#define PM660_SUBTYPE 0x1B
Bjorn Anderssone7488f32021-10-17 09:12:18 -070043#define PM8150_SUBTYPE 0x1E
44#define PM8150L_SUBTYPE 0x1f
45#define PM8150B_SUBTYPE 0x20
46#define PMK8002_SUBTYPE 0x21
47#define PM8009_SUBTYPE 0x24
48#define PM8150C_SUBTYPE 0x26
49#define SMB2351_SUBTYPE 0x29
Ivan T. Ivanovdc716bb2015-03-17 12:47:24 +020050
51static const struct of_device_id pmic_spmi_id_table[] = {
AngeloGioacchino Del Regnoa4b9be22020-09-26 14:55:48 +020052 { .compatible = "qcom,pm660", .data = (void *)PM660_SUBTYPE },
Bjorn Andersson0e2a35a2021-10-17 09:12:16 -070053 { .compatible = "qcom,pm660l", .data = (void *)PM660L_SUBTYPE },
54 { .compatible = "qcom,pm8004", .data = (void *)PM8004_SUBTYPE },
55 { .compatible = "qcom,pm8005", .data = (void *)PM8005_SUBTYPE },
56 { .compatible = "qcom,pm8019", .data = (void *)PM8019_SUBTYPE },
Bjorn Anderssone7488f32021-10-17 09:12:18 -070057 { .compatible = "qcom,pm8028", .data = (void *)PM8028_SUBTYPE },
Bjorn Andersson0e2a35a2021-10-17 09:12:16 -070058 { .compatible = "qcom,pm8110", .data = (void *)PM8110_SUBTYPE },
Bjorn Anderssone7488f32021-10-17 09:12:18 -070059 { .compatible = "qcom,pm8150", .data = (void *)PM8150_SUBTYPE },
60 { .compatible = "qcom,pm8150b", .data = (void *)PM8150B_SUBTYPE },
61 { .compatible = "qcom,pm8150c", .data = (void *)PM8150C_SUBTYPE },
62 { .compatible = "qcom,pm8150l", .data = (void *)PM8150L_SUBTYPE },
Bjorn Andersson0e2a35a2021-10-17 09:12:16 -070063 { .compatible = "qcom,pm8226", .data = (void *)PM8226_SUBTYPE },
64 { .compatible = "qcom,pm8841", .data = (void *)PM8841_SUBTYPE },
Bjorn Anderssone7488f32021-10-17 09:12:18 -070065 { .compatible = "qcom,pm8901", .data = (void *)PM8901_SUBTYPE },
Bjorn Andersson0e2a35a2021-10-17 09:12:16 -070066 { .compatible = "qcom,pm8909", .data = (void *)PM8909_SUBTYPE },
67 { .compatible = "qcom,pm8916", .data = (void *)PM8916_SUBTYPE },
68 { .compatible = "qcom,pm8941", .data = (void *)PM8941_SUBTYPE },
69 { .compatible = "qcom,pm8950", .data = (void *)PM8950_SUBTYPE },
70 { .compatible = "qcom,pm8994", .data = (void *)PM8994_SUBTYPE },
71 { .compatible = "qcom,pm8998", .data = (void *)PM8998_SUBTYPE },
72 { .compatible = "qcom,pma8084", .data = (void *)PMA8084_SUBTYPE },
73 { .compatible = "qcom,pmd9635", .data = (void *)PMD9635_SUBTYPE },
74 { .compatible = "qcom,pmi8950", .data = (void *)PMI8950_SUBTYPE },
75 { .compatible = "qcom,pmi8962", .data = (void *)PMI8962_SUBTYPE },
76 { .compatible = "qcom,pmi8994", .data = (void *)PMI8994_SUBTYPE },
77 { .compatible = "qcom,pmi8998", .data = (void *)PMI8998_SUBTYPE },
Bjorn Anderssone7488f32021-10-17 09:12:18 -070078 { .compatible = "qcom,pmk8002", .data = (void *)PMK8002_SUBTYPE },
79 { .compatible = "qcom,smb2351", .data = (void *)SMB2351_SUBTYPE },
Bjorn Andersson0e2a35a2021-10-17 09:12:16 -070080 { .compatible = "qcom,spmi-pmic", .data = (void *)COMMON_SUBTYPE },
Ivan T. Ivanovdc716bb2015-03-17 12:47:24 +020081 { }
82};
83
84static void pmic_spmi_show_revid(struct regmap *map, struct device *dev)
85{
86 unsigned int rev2, minor, major, type, subtype;
87 const char *name = "unknown";
88 int ret, i;
89
90 ret = regmap_read(map, PMIC_TYPE, &type);
91 if (ret < 0)
92 return;
93
94 if (type != PMIC_TYPE_VALUE)
95 return;
96
97 ret = regmap_read(map, PMIC_SUBTYPE, &subtype);
98 if (ret < 0)
99 return;
100
101 for (i = 0; i < ARRAY_SIZE(pmic_spmi_id_table); i++) {
102 if (subtype == (unsigned long)pmic_spmi_id_table[i].data)
103 break;
104 }
105
106 if (i != ARRAY_SIZE(pmic_spmi_id_table))
107 name = pmic_spmi_id_table[i].compatible;
108
109 ret = regmap_read(map, PMIC_REV2, &rev2);
110 if (ret < 0)
111 return;
112
113 ret = regmap_read(map, PMIC_REV3, &minor);
114 if (ret < 0)
115 return;
116
117 ret = regmap_read(map, PMIC_REV4, &major);
118 if (ret < 0)
119 return;
120
121 /*
122 * In early versions of PM8941 and PM8226, the major revision number
123 * started incrementing from 0 (eg 0 = v1.0, 1 = v2.0).
124 * Increment the major revision number here if the chip is an early
125 * version of PM8941 or PM8226.
126 */
127 if ((subtype == PM8941_SUBTYPE || subtype == PM8226_SUBTYPE) &&
128 major < 0x02)
129 major++;
130
131 if (subtype == PM8110_SUBTYPE)
132 minor = rev2;
133
134 dev_dbg(dev, "%x: %s v%d.%d\n", subtype, name, major, minor);
135}
136
Josh Cartwrightc3a973a2014-08-01 17:30:48 +0300137static const struct regmap_config spmi_regmap_config = {
138 .reg_bits = 16,
139 .val_bits = 8,
140 .max_register = 0xffff,
141 .fast_io = true,
142};
143
144static int pmic_spmi_probe(struct spmi_device *sdev)
145{
Josh Cartwrightc3a973a2014-08-01 17:30:48 +0300146 struct regmap *regmap;
147
148 regmap = devm_regmap_init_spmi_ext(sdev, &spmi_regmap_config);
149 if (IS_ERR(regmap))
150 return PTR_ERR(regmap);
151
Ivan T. Ivanov742dcd12015-11-17 16:06:44 -0800152 /* Only the first slave id for a PMIC contains this information */
153 if (sdev->usid % 2 == 0)
154 pmic_spmi_show_revid(regmap, &sdev->dev);
Ivan T. Ivanovdc716bb2015-03-17 12:47:24 +0200155
Benjamin Gaignard6f00f8c2017-05-29 17:46:00 +0200156 return devm_of_platform_populate(&sdev->dev);
Josh Cartwrightc3a973a2014-08-01 17:30:48 +0300157}
158
Josh Cartwrightc3a973a2014-08-01 17:30:48 +0300159MODULE_DEVICE_TABLE(of, pmic_spmi_id_table);
160
161static struct spmi_driver pmic_spmi_driver = {
162 .probe = pmic_spmi_probe,
Josh Cartwrightc3a973a2014-08-01 17:30:48 +0300163 .driver = {
164 .name = "pmic-spmi",
165 .of_match_table = pmic_spmi_id_table,
166 },
167};
168module_spmi_driver(pmic_spmi_driver);
169
170MODULE_DESCRIPTION("Qualcomm SPMI PMIC driver");
171MODULE_ALIAS("spmi:spmi-pmic");
172MODULE_LICENSE("GPL v2");
173MODULE_AUTHOR("Josh Cartwright <joshc@codeaurora.org>");
174MODULE_AUTHOR("Stanimir Varbanov <svarbanov@mm-sol.com>");