2 * Copyright (C) 2010 DENX Software Engineering
4 * Anatolij Gustschin, <agust@denx.de>
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
15 #include <linux/kernel.h>
17 #include <linux/of_platform.h>
19 #include <asm/machdep.h>
24 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
25 defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
26 #include <linux/interrupt.h>
27 #include <linux/spi/ads7846.h>
28 #include <linux/spi/spi.h>
29 #include <linux/notifier.h>
31 static void *pdm360ng_gpio_base
;
33 static int pdm360ng_get_pendown_state(void)
37 reg
= in_be32(pdm360ng_gpio_base
+ 0xc);
39 setbits32(pdm360ng_gpio_base
+ 0xc, 0x40);
41 reg
= in_be32(pdm360ng_gpio_base
+ 0x8);
43 /* return 1 if pen is down */
44 return (reg
& 0x40) == 0;
47 static struct ads7846_platform_data pdm360ng_ads7846_pdata
= {
49 .get_pendown_state
= pdm360ng_get_pendown_state
,
50 .irq_flags
= IRQF_TRIGGER_LOW
,
53 static int __init
pdm360ng_penirq_init(void)
55 struct device_node
*np
;
57 np
= of_find_compatible_node(NULL
, NULL
, "fsl,mpc5121-gpio");
59 pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__
);
63 pdm360ng_gpio_base
= of_iomap(np
, 0);
65 if (!pdm360ng_gpio_base
) {
66 pr_err("%s: Can't map gpio regs.\n", __func__
);
69 out_be32(pdm360ng_gpio_base
+ 0xc, 0xffffffff);
70 setbits32(pdm360ng_gpio_base
+ 0x18, 0x2000);
71 setbits32(pdm360ng_gpio_base
+ 0x10, 0x40);
76 static int pdm360ng_touchscreen_notifier_call(struct notifier_block
*nb
,
77 unsigned long event
, void *__dev
)
79 struct device
*dev
= __dev
;
81 if ((event
== BUS_NOTIFY_ADD_DEVICE
) &&
82 of_device_is_compatible(dev
->of_node
, "ti,ads7846")) {
83 dev
->platform_data
= &pdm360ng_ads7846_pdata
;
89 static struct notifier_block pdm360ng_touchscreen_nb
= {
90 .notifier_call
= pdm360ng_touchscreen_notifier_call
,
93 static void __init
pdm360ng_touchscreen_init(void)
95 if (pdm360ng_penirq_init())
98 bus_register_notifier(&spi_bus_type
, &pdm360ng_touchscreen_nb
);
101 static inline void __init
pdm360ng_touchscreen_init(void)
104 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
106 void __init
pdm360ng_init(void)
109 pdm360ng_touchscreen_init();
112 static int __init
pdm360ng_probe(void)
114 unsigned long root
= of_get_flat_dt_root();
116 return of_flat_dt_is_compatible(root
, "ifm,pdm360ng");
119 define_machine(pdm360ng
) {
121 .probe
= pdm360ng_probe
,
122 .setup_arch
= mpc512x_setup_arch
,
123 .init
= pdm360ng_init
,
124 .init_early
= mpc512x_init_early
,
125 .init_IRQ
= mpc512x_init_IRQ
,
126 .get_irq
= ipic_get_irq
,
127 .calibrate_decr
= generic_calibrate_decr
,
128 .restart
= mpc512x_restart
,