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/kernel.h>
12 #include <linux/of_address.h>
13 #include <linux/of_fdt.h>
14 #include <linux/of_platform.h>
16 #include <asm/machdep.h>
21 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
22 defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
23 #include <linux/interrupt.h>
24 #include <linux/spi/ads7846.h>
25 #include <linux/spi/spi.h>
26 #include <linux/notifier.h>
28 static void *pdm360ng_gpio_base
;
30 static int pdm360ng_get_pendown_state(void)
34 reg
= in_be32(pdm360ng_gpio_base
+ 0xc);
36 setbits32(pdm360ng_gpio_base
+ 0xc, 0x40);
38 reg
= in_be32(pdm360ng_gpio_base
+ 0x8);
40 /* return 1 if pen is down */
41 return (reg
& 0x40) == 0;
44 static struct ads7846_platform_data pdm360ng_ads7846_pdata
= {
46 .get_pendown_state
= pdm360ng_get_pendown_state
,
47 .irq_flags
= IRQF_TRIGGER_LOW
,
50 static int __init
pdm360ng_penirq_init(void)
52 struct device_node
*np
;
54 np
= of_find_compatible_node(NULL
, NULL
, "fsl,mpc5121-gpio");
56 pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__
);
60 pdm360ng_gpio_base
= of_iomap(np
, 0);
62 if (!pdm360ng_gpio_base
) {
63 pr_err("%s: Can't map gpio regs.\n", __func__
);
66 out_be32(pdm360ng_gpio_base
+ 0xc, 0xffffffff);
67 setbits32(pdm360ng_gpio_base
+ 0x18, 0x2000);
68 setbits32(pdm360ng_gpio_base
+ 0x10, 0x40);
73 static int pdm360ng_touchscreen_notifier_call(struct notifier_block
*nb
,
74 unsigned long event
, void *__dev
)
76 struct device
*dev
= __dev
;
78 if ((event
== BUS_NOTIFY_ADD_DEVICE
) &&
79 of_device_is_compatible(dev
->of_node
, "ti,ads7846")) {
80 dev
->platform_data
= &pdm360ng_ads7846_pdata
;
86 static struct notifier_block pdm360ng_touchscreen_nb
= {
87 .notifier_call
= pdm360ng_touchscreen_notifier_call
,
90 static void __init
pdm360ng_touchscreen_init(void)
92 if (pdm360ng_penirq_init())
95 bus_register_notifier(&spi_bus_type
, &pdm360ng_touchscreen_nb
);
98 static inline void __init
pdm360ng_touchscreen_init(void)
101 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
103 void __init
pdm360ng_init(void)
106 pdm360ng_touchscreen_init();
109 static int __init
pdm360ng_probe(void)
111 if (!of_machine_is_compatible("ifm,pdm360ng"))
114 mpc512x_init_early();
119 define_machine(pdm360ng
) {
121 .probe
= pdm360ng_probe
,
122 .setup_arch
= mpc512x_setup_arch
,
123 .init
= pdm360ng_init
,
124 .init_IRQ
= mpc512x_init_IRQ
,
125 .get_irq
= ipic_get_irq
,
126 .calibrate_decr
= generic_calibrate_decr
,
127 .restart
= mpc512x_restart
,