fs/adfs: move append_filetype_suffix() into adfs_object_fixup()
[linux-2.6/linux-2.6-arm.git] / arch / arm / mach-shmobile / regulator-quirk-rcar-gen2.c
blobdc526ef2e9b313b28afaf531497c6a3201deebe4
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * R-Car Generation 2 da9063/da9210 regulator quirk
5 * Certain Gen2 development boards have an da9063 and one or more da9210
6 * regulators. All of these regulators have their interrupt request lines
7 * tied to the same interrupt pin (IRQ2) on the SoC.
9 * After cold boot or da9063-induced restart, both the da9063 and da9210 seem
10 * to assert their interrupt request lines. Hence as soon as one driver
11 * requests this irq, it gets stuck in an interrupt storm, as it only manages
12 * to deassert its own interrupt request line, and the other driver hasn't
13 * installed an interrupt handler yet.
15 * To handle this, install a quirk that masks the interrupts in both the
16 * da9063 and da9210. This quirk has to run after the i2c master driver has
17 * been initialized, but before the i2c slave drivers are initialized.
19 * Copyright (C) 2015 Glider bvba
22 #include <linux/device.h>
23 #include <linux/i2c.h>
24 #include <linux/init.h>
25 #include <linux/io.h>
26 #include <linux/list.h>
27 #include <linux/notifier.h>
28 #include <linux/of.h>
29 #include <linux/of_irq.h>
30 #include <linux/mfd/da9063/registers.h>
32 #define IRQC_BASE 0xe61c0000
33 #define IRQC_MONITOR 0x104 /* IRQn Signal Level Monitor Register */
35 #define REGULATOR_IRQ_MASK BIT(2) /* IRQ2, active low */
37 /* start of DA9210 System Control and Event Registers */
38 #define DA9210_REG_MASK_A 0x54
40 struct regulator_quirk {
41 struct list_head list;
42 const struct of_device_id *id;
43 struct device_node *np;
44 struct of_phandle_args irq_args;
45 struct i2c_msg i2c_msg;
46 bool shared; /* IRQ line is shared */
49 static LIST_HEAD(quirk_list);
50 static void __iomem *irqc;
52 /* first byte sets the memory pointer, following are consecutive reg values */
53 static u8 da9063_irq_clr[] = { DA9063_REG_IRQ_MASK_A, 0xff, 0xff, 0xff, 0xff };
54 static u8 da9210_irq_clr[] = { DA9210_REG_MASK_A, 0xff, 0xff };
56 static struct i2c_msg da9063_msg = {
57 .len = ARRAY_SIZE(da9063_irq_clr),
58 .buf = da9063_irq_clr,
61 static struct i2c_msg da9210_msg = {
62 .len = ARRAY_SIZE(da9210_irq_clr),
63 .buf = da9210_irq_clr,
66 static const struct of_device_id rcar_gen2_quirk_match[] = {
67 { .compatible = "dlg,da9063", .data = &da9063_msg },
68 { .compatible = "dlg,da9210", .data = &da9210_msg },
69 {},
72 static int regulator_quirk_notify(struct notifier_block *nb,
73 unsigned long action, void *data)
75 struct regulator_quirk *pos, *tmp;
76 struct device *dev = data;
77 struct i2c_client *client;
78 static bool done;
79 int ret;
80 u32 mon;
82 if (done)
83 return 0;
85 mon = ioread32(irqc + IRQC_MONITOR);
86 dev_dbg(dev, "%s: %ld, IRQC_MONITOR = 0x%x\n", __func__, action, mon);
87 if (mon & REGULATOR_IRQ_MASK)
88 goto remove;
90 if (action != BUS_NOTIFY_ADD_DEVICE || dev->type == &i2c_adapter_type)
91 return 0;
93 client = to_i2c_client(dev);
94 dev_dbg(dev, "Detected %s\n", client->name);
97 * Send message to all PMICs that share an IRQ line to deassert it.
99 * WARNING: This works only if all the PMICs are on the same I2C bus.
101 list_for_each_entry(pos, &quirk_list, list) {
102 if (!pos->shared)
103 continue;
105 if (pos->np->parent != client->dev.parent->of_node)
106 continue;
108 dev_info(&client->dev, "clearing %s@0x%02x interrupts\n",
109 pos->id->compatible, pos->i2c_msg.addr);
111 ret = i2c_transfer(client->adapter, &pos->i2c_msg, 1);
112 if (ret != 1)
113 dev_err(&client->dev, "i2c error %d\n", ret);
116 mon = ioread32(irqc + IRQC_MONITOR);
117 if (mon & REGULATOR_IRQ_MASK)
118 goto remove;
120 return 0;
122 remove:
123 dev_info(dev, "IRQ2 is not asserted, removing quirk\n");
125 list_for_each_entry_safe(pos, tmp, &quirk_list, list) {
126 list_del(&pos->list);
127 kfree(pos);
130 done = true;
131 iounmap(irqc);
132 return 0;
135 static struct notifier_block regulator_quirk_nb = {
136 .notifier_call = regulator_quirk_notify
139 static int __init rcar_gen2_regulator_quirk(void)
141 struct regulator_quirk *quirk, *pos, *tmp;
142 struct of_phandle_args *argsa, *argsb;
143 const struct of_device_id *id;
144 struct device_node *np;
145 u32 mon, addr;
146 int ret;
148 if (!of_machine_is_compatible("renesas,koelsch") &&
149 !of_machine_is_compatible("renesas,lager") &&
150 !of_machine_is_compatible("renesas,stout") &&
151 !of_machine_is_compatible("renesas,gose"))
152 return -ENODEV;
154 for_each_matching_node_and_match(np, rcar_gen2_quirk_match, &id) {
155 if (!of_device_is_available(np))
156 break;
158 ret = of_property_read_u32(np, "reg", &addr);
159 if (ret) /* Skip invalid entry and continue */
160 continue;
162 quirk = kzalloc(sizeof(*quirk), GFP_KERNEL);
163 if (!quirk) {
164 ret = -ENOMEM;
165 goto err_mem;
168 argsa = &quirk->irq_args;
169 memcpy(&quirk->i2c_msg, id->data, sizeof(quirk->i2c_msg));
171 quirk->id = id;
172 quirk->np = np;
173 quirk->i2c_msg.addr = addr;
175 ret = of_irq_parse_one(np, 0, argsa);
176 if (ret) { /* Skip invalid entry and continue */
177 kfree(quirk);
178 continue;
181 list_for_each_entry(pos, &quirk_list, list) {
182 argsb = &pos->irq_args;
184 if (argsa->args_count != argsb->args_count)
185 continue;
187 ret = memcmp(argsa->args, argsb->args,
188 argsa->args_count *
189 sizeof(argsa->args[0]));
190 if (!ret) {
191 pos->shared = true;
192 quirk->shared = true;
196 list_add_tail(&quirk->list, &quirk_list);
199 irqc = ioremap(IRQC_BASE, PAGE_SIZE);
200 if (!irqc) {
201 ret = -ENOMEM;
202 goto err_mem;
205 mon = ioread32(irqc + IRQC_MONITOR);
206 if (mon & REGULATOR_IRQ_MASK) {
207 pr_debug("%s: IRQ2 is not asserted, not installing quirk\n",
208 __func__);
209 ret = 0;
210 goto err_free;
213 pr_info("IRQ2 is asserted, installing da9063/da9210 regulator quirk\n");
215 bus_register_notifier(&i2c_bus_type, &regulator_quirk_nb);
216 return 0;
218 err_free:
219 iounmap(irqc);
220 err_mem:
221 list_for_each_entry_safe(pos, tmp, &quirk_list, list) {
222 list_del(&pos->list);
223 kfree(pos);
226 return ret;
229 arch_initcall(rcar_gen2_regulator_quirk);