1 /* 2 * Copyright (C) 2010 DENX Software Engineering 3 * 4 * Anatolij Gustschin, <agust@denx.de> 5 * 6 * PDM360NG board setup 7 * 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. 12 * 13 */ 14 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> 20 21 #include <asm/machdep.h> 22 #include <asm/ipic.h> 23 24 #include "mpc512x.h" 25 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> 32 33 static void *pdm360ng_gpio_base; 34 35 static int pdm360ng_get_pendown_state(void) 36 { 37 u32 reg; 38 39 reg = in_be32(pdm360ng_gpio_base + 0xc); 40 if (reg & 0x40) 41 setbits32(pdm360ng_gpio_base + 0xc, 0x40); 42 43 reg = in_be32(pdm360ng_gpio_base + 0x8); 44 45 /* return 1 if pen is down */ 46 return (reg & 0x40) == 0; 47 } 48 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, 53 }; 54 55 static int __init pdm360ng_penirq_init(void) 56 { 57 struct device_node *np; 58 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; 63 } 64 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; 70 } 71 out_be32(pdm360ng_gpio_base + 0xc, 0xffffffff); 72 setbits32(pdm360ng_gpio_base + 0x18, 0x2000); 73 setbits32(pdm360ng_gpio_base + 0x10, 0x40); 74 75 return 0; 76 } 77 78 static int pdm360ng_touchscreen_notifier_call(struct notifier_block *nb, 79 unsigned long event, void *__dev) 80 { 81 struct device *dev = __dev; 82 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; 87 } 88 return NOTIFY_DONE; 89 } 90 91 static struct notifier_block pdm360ng_touchscreen_nb = { 92 .notifier_call = pdm360ng_touchscreen_notifier_call, 93 }; 94 95 static void __init pdm360ng_touchscreen_init(void) 96 { 97 if (pdm360ng_penirq_init()) 98 return; 99 100 bus_register_notifier(&spi_bus_type, &pdm360ng_touchscreen_nb); 101 } 102 #else 103 static inline void __init pdm360ng_touchscreen_init(void) 104 { 105 } 106 #endif /* CONFIG_TOUCHSCREEN_ADS7846 */ 107 108 void __init pdm360ng_init(void) 109 { 110 mpc512x_init(); 111 pdm360ng_touchscreen_init(); 112 } 113 114 static int __init pdm360ng_probe(void) 115 { 116 unsigned long root = of_get_flat_dt_root(); 117 118 return of_flat_dt_is_compatible(root, "ifm,pdm360ng"); 119 } 120 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, 131 }; 132