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