1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2010 DENX Software Engineering
5 * Anatolij Gustschin, <agust@denx.de>
10 #include <linux/device.h>
11 #include <linux/kernel.h>
14 #include <linux/of_address.h>
15 #include <linux/of_fdt.h>
17 #include <asm/machdep.h>
22 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
23 defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
24 #include <linux/interrupt.h>
25 #include <linux/spi/ads7846.h>
26 #include <linux/spi/spi.h>
27 #include <linux/notifier.h>
29 static void *pdm360ng_gpio_base;
31 static int pdm360ng_get_pendown_state(void)
35 reg = in_be32(pdm360ng_gpio_base + 0xc);
37 setbits32(pdm360ng_gpio_base + 0xc, 0x40);
39 reg = in_be32(pdm360ng_gpio_base + 0x8);
41 /* return 1 if pen is down */
42 return (reg & 0x40) == 0;
45 static struct ads7846_platform_data pdm360ng_ads7846_pdata = {
47 .get_pendown_state = pdm360ng_get_pendown_state,
48 .irq_flags = IRQF_TRIGGER_LOW,
51 static int __init pdm360ng_penirq_init(void)
53 struct device_node *np;
55 np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-gpio");
57 pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__);
61 pdm360ng_gpio_base = of_iomap(np, 0);
63 if (!pdm360ng_gpio_base) {
64 pr_err("%s: Can't map gpio regs.\n", __func__);
67 out_be32(pdm360ng_gpio_base + 0xc, 0xffffffff);
68 setbits32(pdm360ng_gpio_base + 0x18, 0x2000);
69 setbits32(pdm360ng_gpio_base + 0x10, 0x40);
74 static int pdm360ng_touchscreen_notifier_call(struct notifier_block *nb,
75 unsigned long event, void *__dev)
77 struct device *dev = __dev;
79 if ((event == BUS_NOTIFY_ADD_DEVICE) &&
80 of_device_is_compatible(dev->of_node, "ti,ads7846")) {
81 dev->platform_data = &pdm360ng_ads7846_pdata;
87 static struct notifier_block pdm360ng_touchscreen_nb = {
88 .notifier_call = pdm360ng_touchscreen_notifier_call,
91 static void __init pdm360ng_touchscreen_init(void)
93 if (pdm360ng_penirq_init())
96 bus_register_notifier(&spi_bus_type, &pdm360ng_touchscreen_nb);
99 static inline void __init pdm360ng_touchscreen_init(void)
102 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
104 void __init pdm360ng_init(void)
107 pdm360ng_touchscreen_init();
110 static int __init pdm360ng_probe(void)
112 mpc512x_init_early();
117 define_machine(pdm360ng) {
119 .compatible = "ifm,pdm360ng",
120 .probe = pdm360ng_probe,
121 .setup_arch = mpc512x_setup_arch,
122 .init = pdm360ng_init,
123 .init_IRQ = mpc512x_init_IRQ,
124 .get_irq = ipic_get_irq,
125 .restart = mpc512x_restart,