1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <linux/device.h>
31#include <linux/i2c.h>
32#include <linux/init.h>
33#include <linux/io.h>
34#include <linux/notifier.h>
35#include <linux/of.h>
36#include <linux/mfd/da9063/registers.h>
37
38
39#define IRQC_BASE 0xe61c0000
40#define IRQC_MONITOR 0x104
41
42#define REGULATOR_IRQ_MASK BIT(2)
43
44
45#define DA9210_REG_MASK_A 0x54
46
47static void __iomem *irqc;
48
49
50static u8 da9063_irq_clr[] = { DA9063_REG_IRQ_MASK_A, 0xff, 0xff, 0xff, 0xff };
51static u8 da9210_irq_clr[] = { DA9210_REG_MASK_A, 0xff, 0xff };
52
53static struct i2c_msg da9xxx_msgs[2] = {
54 {
55 .addr = 0x58,
56 .len = ARRAY_SIZE(da9063_irq_clr),
57 .buf = da9063_irq_clr,
58 }, {
59 .addr = 0x68,
60 .len = ARRAY_SIZE(da9210_irq_clr),
61 .buf = da9210_irq_clr,
62 },
63};
64
65static int regulator_quirk_notify(struct notifier_block *nb,
66 unsigned long action, void *data)
67{
68 struct device *dev = data;
69 struct i2c_client *client;
70 static bool done;
71 u32 mon;
72
73 if (done)
74 return 0;
75
76 mon = ioread32(irqc + IRQC_MONITOR);
77 dev_dbg(dev, "%s: %ld, IRQC_MONITOR = 0x%x\n", __func__, action, mon);
78 if (mon & REGULATOR_IRQ_MASK)
79 goto remove;
80
81 if (action != BUS_NOTIFY_ADD_DEVICE || dev->type == &i2c_adapter_type)
82 return 0;
83
84 client = to_i2c_client(dev);
85 dev_dbg(dev, "Detected %s\n", client->name);
86
87 if ((client->addr == 0x58 && !strcmp(client->name, "da9063")) ||
88 (client->addr == 0x68 && !strcmp(client->name, "da9210"))) {
89 int ret;
90
91 dev_info(&client->dev, "clearing da9063/da9210 interrupts\n");
92 ret = i2c_transfer(client->adapter, da9xxx_msgs, ARRAY_SIZE(da9xxx_msgs));
93 if (ret != ARRAY_SIZE(da9xxx_msgs))
94 dev_err(&client->dev, "i2c error %d\n", ret);
95 }
96
97 mon = ioread32(irqc + IRQC_MONITOR);
98 if (mon & REGULATOR_IRQ_MASK)
99 goto remove;
100
101 return 0;
102
103remove:
104 dev_info(dev, "IRQ2 is not asserted, removing quirk\n");
105
106 done = true;
107 iounmap(irqc);
108 return 0;
109}
110
111static struct notifier_block regulator_quirk_nb = {
112 .notifier_call = regulator_quirk_notify
113};
114
115static int __init rcar_gen2_regulator_quirk(void)
116{
117 u32 mon;
118
119 if (!of_machine_is_compatible("renesas,koelsch") &&
120 !of_machine_is_compatible("renesas,lager") &&
121 !of_machine_is_compatible("renesas,gose"))
122 return -ENODEV;
123
124 irqc = ioremap(IRQC_BASE, PAGE_SIZE);
125 if (!irqc)
126 return -ENOMEM;
127
128 mon = ioread32(irqc + IRQC_MONITOR);
129 if (mon & REGULATOR_IRQ_MASK) {
130 pr_debug("%s: IRQ2 is not asserted, not installing quirk\n",
131 __func__);
132 iounmap(irqc);
133 return 0;
134 }
135
136 pr_info("IRQ2 is asserted, installing da9063/da9210 regulator quirk\n");
137
138 bus_register_notifier(&i2c_bus_type, ®ulator_quirk_nb);
139 return 0;
140}
141
142arch_initcall(rcar_gen2_regulator_quirk);
143