Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: mtk-pmic-keys - use get_irq_byname() instead of index

Some pmics of the mt6397 family (such as MT6358), have two IRQs per
physical key: one for press event, another for release event.

The mtk-pmic-keys driver assumes that each key only has one
IRQ. The key index and the RES_IRQ resource index have a 1/1 mapping.

This won't work for MT6358, as we have multiple resources (2) for one key.

To prepare mtk-pmic-keys to support MT6358, retrieve IRQs by name
instead of by index.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Link: https://lore.kernel.org/r/20220121140323.4080640-2-mkorpershoek@baylibre.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Mattijs Korpershoek and committed by
Dmitry Torokhov
f4e09e8b 87a0b2fa

+5 -2
+5 -2
drivers/input/keyboard/mtk-pmic-keys.c
··· 241 241 unsigned int keycount; 242 242 struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent); 243 243 struct device_node *node = pdev->dev.of_node, *child; 244 + static const char *const irqnames[] = { "powerkey", "homekey" }; 244 245 struct mtk_pmic_keys *keys; 245 246 const struct mtk_pmic_regs *mtk_pmic_regs; 246 247 struct input_dev *input_dev; ··· 269 268 input_dev->id.version = 0x0001; 270 269 271 270 keycount = of_get_available_child_count(node); 272 - if (keycount > MTK_PMIC_MAX_KEY_COUNT) { 271 + if (keycount > MTK_PMIC_MAX_KEY_COUNT || 272 + keycount > ARRAY_SIZE(irqnames)) { 273 273 dev_err(keys->dev, "too many keys defined (%d)\n", keycount); 274 274 return -EINVAL; 275 275 } ··· 278 276 for_each_child_of_node(node, child) { 279 277 keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index]; 280 278 281 - keys->keys[index].irq = platform_get_irq(pdev, index); 279 + keys->keys[index].irq = 280 + platform_get_irq_byname(pdev, irqnames[index]); 282 281 if (keys->keys[index].irq < 0) { 283 282 of_node_put(child); 284 283 return keys->keys[index].irq;