ramips: fix the number of uarts for MT7688
[openwrt/staging/yousong.git] / target / linux / mediatek / patches-4.4 / 0044-mfd-mt6397-add-support-for-different-Slave-types.patch
1 From c6c447480e51301faa2254c7316ab075e20c4b0c Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Fri, 8 Jan 2016 08:41:52 +0100
4 Subject: [PATCH 044/102] mfd: mt6397: add support for different Slave types
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8 drivers/mfd/mt6397-core.c | 58 ++++++++++++++++++++++++++++++++-------------
9 1 file changed, 41 insertions(+), 17 deletions(-)
10
11 --- a/drivers/mfd/mt6397-core.c
12 +++ b/drivers/mfd/mt6397-core.c
13 @@ -24,6 +24,9 @@
14 #define MT6397_RTC_BASE 0xe000
15 #define MT6397_RTC_SIZE 0x3e
16
17 +#define MT6391_CID_CODE 0x91
18 +#define MT6397_CID_CODE 0x97
19 +
20 static const struct resource mt6397_rtc_resources[] = {
21 {
22 .start = MT6397_RTC_BASE,
23 @@ -232,39 +235,60 @@ static SIMPLE_DEV_PM_OPS(mt6397_pm_ops,
24 static int mt6397_probe(struct platform_device *pdev)
25 {
26 int ret;
27 - struct mt6397_chip *mt6397;
28 + unsigned int id;
29 + struct mt6397_chip *pmic;
30
31 - mt6397 = devm_kzalloc(&pdev->dev, sizeof(*mt6397), GFP_KERNEL);
32 - if (!mt6397)
33 + pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
34 + if (!pmic)
35 return -ENOMEM;
36
37 - mt6397->dev = &pdev->dev;
38 - mt6397->int_con[0] = MT6397_INT_CON0;
39 - mt6397->int_con[1] = MT6397_INT_CON1;
40 - mt6397->int_status[0] = MT6397_INT_STATUS0;
41 - mt6397->int_status[1] = MT6397_INT_STATUS1;
42 + pmic->dev = &pdev->dev;
43
44 /*
45 * mt6397 MFD is child device of soc pmic wrapper.
46 * Regmap is set from its parent.
47 */
48 - mt6397->regmap = dev_get_regmap(pdev->dev.parent, NULL);
49 - if (!mt6397->regmap)
50 + pmic->regmap = dev_get_regmap(pdev->dev.parent, NULL);
51 + if (!pmic->regmap)
52 return -ENODEV;
53
54 - platform_set_drvdata(pdev, mt6397);
55 + platform_set_drvdata(pdev, pmic);
56 +
57 + ret = regmap_read(pmic->regmap, MT6397_CID, &id);
58 + if (ret) {
59 + dev_err(pmic->dev, "Failed to read chip id: %d\n", ret);
60 + goto fail_irq;
61 + }
62 +
63 + switch (id & 0xff) {
64 + case MT6397_CID_CODE:
65 + case MT6391_CID_CODE:
66 + pmic->int_con[0] = MT6397_INT_CON0;
67 + pmic->int_con[1] = MT6397_INT_CON1;
68 + pmic->int_status[0] = MT6397_INT_STATUS0;
69 + pmic->int_status[1] = MT6397_INT_STATUS1;
70 + ret = mfd_add_devices(&pdev->dev, -1, mt6397_devs,
71 + ARRAY_SIZE(mt6397_devs), NULL, 0, NULL);
72 + break;
73 +
74 + default:
75 + dev_err(&pdev->dev, "unsupported chip: %d\n", id);
76 + ret = -ENODEV;
77 + break;
78 + }
79
80 - mt6397->irq = platform_get_irq(pdev, 0);
81 - if (mt6397->irq > 0) {
82 - ret = mt6397_irq_init(mt6397);
83 + pmic->irq = platform_get_irq(pdev, 0);
84 + if (pmic->irq > 0) {
85 + ret = mt6397_irq_init(pmic);
86 if (ret)
87 return ret;
88 }
89
90 - ret = mfd_add_devices(&pdev->dev, -1, mt6397_devs,
91 - ARRAY_SIZE(mt6397_devs), NULL, 0, NULL);
92 - if (ret)
93 +fail_irq:
94 + if (ret) {
95 + irq_domain_remove(pmic->irq_domain);
96 dev_err(&pdev->dev, "failed to add child devices: %d\n", ret);
97 + }
98
99 return ret;
100 }