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_address.h>
18 #include <linux/of_fdt.h>
19 #include <linux/of_platform.h>
21 #include <asm/machdep.h>
26 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
27 defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
28 #include <linux/interrupt.h>
29 #include <linux/spi/ads7846.h>
30 #include <linux/spi/spi.h>
31 #include <linux/notifier.h>
33 static void *pdm360ng_gpio_base
;
35 static int pdm360ng_get_pendown_state(void)
39 reg
= in_be32(pdm360ng_gpio_base
+ 0xc);
41 setbits32(pdm360ng_gpio_base
+ 0xc, 0x40);
43 reg
= in_be32(pdm360ng_gpio_base
+ 0x8);
45 /* return 1 if pen is down */
46 return (reg
& 0x40) == 0;
49 static struct ads7846_platform_data pdm360ng_ads7846_pdata
= {
51 .get_pendown_state
= pdm360ng_get_pendown_state
,
52 .irq_flags
= IRQF_TRIGGER_LOW
,
55 static int __init
pdm360ng_penirq_init(void)
57 struct device_node
*np
;
59 np
= of_find_compatible_node(NULL
, NULL
, "fsl,mpc5121-gpio");
61 pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__
);
65 pdm360ng_gpio_base
= of_iomap(np
, 0);
67 if (!pdm360ng_gpio_base
) {
68 pr_err("%s: Can't map gpio regs.\n", __func__
);
71 out_be32(pdm360ng_gpio_base
+ 0xc, 0xffffffff);
72 setbits32(pdm360ng_gpio_base
+ 0x18, 0x2000);
73 setbits32(pdm360ng_gpio_base
+ 0x10, 0x40);
78 static int pdm360ng_touchscreen_notifier_call(struct notifier_block
*nb
,
79 unsigned long event
, void *__dev
)
81 struct device
*dev
= __dev
;
83 if ((event
== BUS_NOTIFY_ADD_DEVICE
) &&
84 of_device_is_compatible(dev
->of_node
, "ti,ads7846")) {
85 dev
->platform_data
= &pdm360ng_ads7846_pdata
;
91 static struct notifier_block pdm360ng_touchscreen_nb
= {
92 .notifier_call
= pdm360ng_touchscreen_notifier_call
,
95 static void __init
pdm360ng_touchscreen_init(void)
97 if (pdm360ng_penirq_init())
100 bus_register_notifier(&spi_bus_type
, &pdm360ng_touchscreen_nb
);
103 static inline void __init
pdm360ng_touchscreen_init(void)
106 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
108 void __init
pdm360ng_init(void)
111 pdm360ng_touchscreen_init();
114 static int __init
pdm360ng_probe(void)
116 unsigned long root
= of_get_flat_dt_root();
118 return of_flat_dt_is_compatible(root
, "ifm,pdm360ng");
121 define_machine(pdm360ng
) {
123 .probe
= pdm360ng_probe
,
124 .setup_arch
= mpc512x_setup_arch
,
125 .init
= pdm360ng_init
,
126 .init_early
= mpc512x_init_early
,
127 .init_IRQ
= mpc512x_init_IRQ
,
128 .get_irq
= ipic_get_irq
,
129 .calibrate_decr
= generic_calibrate_decr
,
130 .restart
= mpc512x_restart
,