Linux 4.1.18
[linux/fpc-iii.git] / arch / powerpc / platforms / 512x / pdm360ng.c
blob116f2325b20b54e62c1ebe9517df24e546bb65d9
1 /*
2 * Copyright (C) 2010 DENX Software Engineering
4 * Anatolij Gustschin, <agust@denx.de>
6 * PDM360NG board setup
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>
16 #include <linux/io.h>
17 #include <linux/of_address.h>
18 #include <linux/of_fdt.h>
19 #include <linux/of_platform.h>
21 #include <asm/machdep.h>
22 #include <asm/ipic.h>
24 #include "mpc512x.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)
37 u32 reg;
39 reg = in_be32(pdm360ng_gpio_base + 0xc);
40 if (reg & 0x40)
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 = {
50 .model = 7845,
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");
60 if (!np) {
61 pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__);
62 return -ENODEV;
65 pdm360ng_gpio_base = of_iomap(np, 0);
66 of_node_put(np);
67 if (!pdm360ng_gpio_base) {
68 pr_err("%s: Can't map gpio regs.\n", __func__);
69 return -ENODEV;
71 out_be32(pdm360ng_gpio_base + 0xc, 0xffffffff);
72 setbits32(pdm360ng_gpio_base + 0x18, 0x2000);
73 setbits32(pdm360ng_gpio_base + 0x10, 0x40);
75 return 0;
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;
86 return NOTIFY_OK;
88 return NOTIFY_DONE;
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())
98 return;
100 bus_register_notifier(&spi_bus_type, &pdm360ng_touchscreen_nb);
102 #else
103 static inline void __init pdm360ng_touchscreen_init(void)
106 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
108 void __init pdm360ng_init(void)
110 mpc512x_init();
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) {
122 .name = "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,