WIP FPC-III support
[linux/fpc-iii.git] / arch / powerpc / platforms / 512x / pdm360ng.c
blob1e911f42697d7658c512377a8457ccc1dc6fb112
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2010 DENX Software Engineering
5 * Anatolij Gustschin, <agust@denx.de>
7 * PDM360NG board setup
8 */
10 #include <linux/kernel.h>
11 #include <linux/io.h>
12 #include <linux/of_address.h>
13 #include <linux/of_fdt.h>
14 #include <linux/of_platform.h>
16 #include <asm/machdep.h>
17 #include <asm/ipic.h>
19 #include "mpc512x.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)
32 u32 reg;
34 reg = in_be32(pdm360ng_gpio_base + 0xc);
35 if (reg & 0x40)
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 = {
45 .model = 7845,
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");
55 if (!np) {
56 pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__);
57 return -ENODEV;
60 pdm360ng_gpio_base = of_iomap(np, 0);
61 of_node_put(np);
62 if (!pdm360ng_gpio_base) {
63 pr_err("%s: Can't map gpio regs.\n", __func__);
64 return -ENODEV;
66 out_be32(pdm360ng_gpio_base + 0xc, 0xffffffff);
67 setbits32(pdm360ng_gpio_base + 0x18, 0x2000);
68 setbits32(pdm360ng_gpio_base + 0x10, 0x40);
70 return 0;
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;
81 return NOTIFY_OK;
83 return NOTIFY_DONE;
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())
93 return;
95 bus_register_notifier(&spi_bus_type, &pdm360ng_touchscreen_nb);
97 #else
98 static inline void __init pdm360ng_touchscreen_init(void)
101 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
103 void __init pdm360ng_init(void)
105 mpc512x_init();
106 pdm360ng_touchscreen_init();
109 static int __init pdm360ng_probe(void)
111 if (!of_machine_is_compatible("ifm,pdm360ng"))
112 return 0;
114 mpc512x_init_early();
116 return 1;
119 define_machine(pdm360ng) {
120 .name = "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,