1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014 MediaTek Inc.
4 * Author: Flora Fu, MediaTek
7 #include <linux/interrupt.h>
8 #include <linux/ioport.h>
9 #include <linux/module.h>
10 #include <linux/of_device.h>
11 #include <linux/of_irq.h>
12 #include <linux/regmap.h>
13 #include <linux/mfd/core.h>
14 #include <linux/mfd/mt6323/core.h>
15 #include <linux/mfd/mt6358/core.h>
16 #include <linux/mfd/mt6359/core.h>
17 #include <linux/mfd/mt6397/core.h>
18 #include <linux/mfd/mt6323/registers.h>
19 #include <linux/mfd/mt6358/registers.h>
20 #include <linux/mfd/mt6359/registers.h>
21 #include <linux/mfd/mt6397/registers.h>
23 #define MT6323_RTC_BASE 0x8000
24 #define MT6323_RTC_SIZE 0x40
26 #define MT6358_RTC_BASE 0x0588
27 #define MT6358_RTC_SIZE 0x3c
29 #define MT6397_RTC_BASE 0xe000
30 #define MT6397_RTC_SIZE 0x3e
32 #define MT6323_PWRC_BASE 0x8000
33 #define MT6323_PWRC_SIZE 0x40
35 static const struct resource mt6323_rtc_resources[] = {
36 DEFINE_RES_MEM(MT6323_RTC_BASE, MT6323_RTC_SIZE),
37 DEFINE_RES_IRQ(MT6323_IRQ_STATUS_RTC),
40 static const struct resource mt6358_rtc_resources[] = {
41 DEFINE_RES_MEM(MT6358_RTC_BASE, MT6358_RTC_SIZE),
42 DEFINE_RES_IRQ(MT6358_IRQ_RTC),
45 static const struct resource mt6397_rtc_resources[] = {
46 DEFINE_RES_MEM(MT6397_RTC_BASE, MT6397_RTC_SIZE),
47 DEFINE_RES_IRQ(MT6397_IRQ_RTC),
50 static const struct resource mt6323_keys_resources[] = {
51 DEFINE_RES_IRQ(MT6323_IRQ_STATUS_PWRKEY),
52 DEFINE_RES_IRQ(MT6323_IRQ_STATUS_FCHRKEY),
55 static const struct resource mt6397_keys_resources[] = {
56 DEFINE_RES_IRQ(MT6397_IRQ_PWRKEY),
57 DEFINE_RES_IRQ(MT6397_IRQ_HOMEKEY),
60 static const struct resource mt6323_pwrc_resources[] = {
61 DEFINE_RES_MEM(MT6323_PWRC_BASE, MT6323_PWRC_SIZE),
64 static const struct mfd_cell mt6323_devs[] = {
67 .num_resources = ARRAY_SIZE(mt6323_rtc_resources),
68 .resources = mt6323_rtc_resources,
69 .of_compatible = "mediatek,mt6323-rtc",
71 .name = "mt6323-regulator",
72 .of_compatible = "mediatek,mt6323-regulator"
75 .of_compatible = "mediatek,mt6323-led"
77 .name = "mtk-pmic-keys",
78 .num_resources = ARRAY_SIZE(mt6323_keys_resources),
79 .resources = mt6323_keys_resources,
80 .of_compatible = "mediatek,mt6323-keys"
82 .name = "mt6323-pwrc",
83 .num_resources = ARRAY_SIZE(mt6323_pwrc_resources),
84 .resources = mt6323_pwrc_resources,
85 .of_compatible = "mediatek,mt6323-pwrc"
89 static const struct mfd_cell mt6358_devs[] = {
91 .name = "mt6358-regulator",
92 .of_compatible = "mediatek,mt6358-regulator"
95 .num_resources = ARRAY_SIZE(mt6358_rtc_resources),
96 .resources = mt6358_rtc_resources,
97 .of_compatible = "mediatek,mt6358-rtc",
99 .name = "mt6358-sound",
100 .of_compatible = "mediatek,mt6358-sound"
104 static const struct mfd_cell mt6359_devs[] = {
105 { .name = "mt6359-regulator", },
107 .name = "mt6359-rtc",
108 .num_resources = ARRAY_SIZE(mt6358_rtc_resources),
109 .resources = mt6358_rtc_resources,
110 .of_compatible = "mediatek,mt6358-rtc",
112 { .name = "mt6359-sound", },
115 static const struct mfd_cell mt6397_devs[] = {
117 .name = "mt6397-rtc",
118 .num_resources = ARRAY_SIZE(mt6397_rtc_resources),
119 .resources = mt6397_rtc_resources,
120 .of_compatible = "mediatek,mt6397-rtc",
122 .name = "mt6397-regulator",
123 .of_compatible = "mediatek,mt6397-regulator",
125 .name = "mt6397-codec",
126 .of_compatible = "mediatek,mt6397-codec",
128 .name = "mt6397-clk",
129 .of_compatible = "mediatek,mt6397-clk",
131 .name = "mt6397-pinctrl",
132 .of_compatible = "mediatek,mt6397-pinctrl",
134 .name = "mtk-pmic-keys",
135 .num_resources = ARRAY_SIZE(mt6397_keys_resources),
136 .resources = mt6397_keys_resources,
137 .of_compatible = "mediatek,mt6397-keys"
144 const struct mfd_cell *cells;
146 int (*irq_init)(struct mt6397_chip *chip);
149 static const struct chip_data mt6323_core = {
150 .cid_addr = MT6323_CID,
152 .cells = mt6323_devs,
153 .cell_size = ARRAY_SIZE(mt6323_devs),
154 .irq_init = mt6397_irq_init,
157 static const struct chip_data mt6358_core = {
158 .cid_addr = MT6358_SWCID,
160 .cells = mt6358_devs,
161 .cell_size = ARRAY_SIZE(mt6358_devs),
162 .irq_init = mt6358_irq_init,
165 static const struct chip_data mt6359_core = {
166 .cid_addr = MT6359_SWCID,
168 .cells = mt6359_devs,
169 .cell_size = ARRAY_SIZE(mt6359_devs),
170 .irq_init = mt6358_irq_init,
173 static const struct chip_data mt6397_core = {
174 .cid_addr = MT6397_CID,
176 .cells = mt6397_devs,
177 .cell_size = ARRAY_SIZE(mt6397_devs),
178 .irq_init = mt6397_irq_init,
181 static int mt6397_probe(struct platform_device *pdev)
185 struct mt6397_chip *pmic;
186 const struct chip_data *pmic_core;
188 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
192 pmic->dev = &pdev->dev;
195 * mt6397 MFD is child device of soc pmic wrapper.
196 * Regmap is set from its parent.
198 pmic->regmap = dev_get_regmap(pdev->dev.parent, NULL);
202 pmic_core = of_device_get_match_data(&pdev->dev);
206 ret = regmap_read(pmic->regmap, pmic_core->cid_addr, &id);
208 dev_err(&pdev->dev, "Failed to read chip id: %d\n", ret);
212 pmic->chip_id = (id >> pmic_core->cid_shift) & 0xff;
214 platform_set_drvdata(pdev, pmic);
216 pmic->irq = platform_get_irq(pdev, 0);
220 ret = pmic_core->irq_init(pmic);
224 ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
225 pmic_core->cells, pmic_core->cell_size,
226 NULL, 0, pmic->irq_domain);
228 irq_domain_remove(pmic->irq_domain);
229 dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
235 static const struct of_device_id mt6397_of_match[] = {
237 .compatible = "mediatek,mt6323",
238 .data = &mt6323_core,
240 .compatible = "mediatek,mt6358",
241 .data = &mt6358_core,
243 .compatible = "mediatek,mt6359",
244 .data = &mt6359_core,
246 .compatible = "mediatek,mt6397",
247 .data = &mt6397_core,
252 MODULE_DEVICE_TABLE(of, mt6397_of_match);
254 static const struct platform_device_id mt6397_id[] = {
258 MODULE_DEVICE_TABLE(platform, mt6397_id);
260 static struct platform_driver mt6397_driver = {
261 .probe = mt6397_probe,
264 .of_match_table = mt6397_of_match,
266 .id_table = mt6397_id,
269 module_platform_driver(mt6397_driver);
271 MODULE_AUTHOR("Flora Fu, MediaTek");
272 MODULE_DESCRIPTION("Driver for MediaTek MT6397 PMIC");
273 MODULE_LICENSE("GPL");