pdm360ng.c (2818B)
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (C) 2010 DENX Software Engineering 4 * 5 * Anatolij Gustschin, <agust@denx.de> 6 * 7 * PDM360NG board setup 8 */ 9 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> 15 16#include <asm/machdep.h> 17#include <asm/ipic.h> 18 19#include "mpc512x.h" 20 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> 27 28static void *pdm360ng_gpio_base; 29 30static int pdm360ng_get_pendown_state(void) 31{ 32 u32 reg; 33 34 reg = in_be32(pdm360ng_gpio_base + 0xc); 35 if (reg & 0x40) 36 setbits32(pdm360ng_gpio_base + 0xc, 0x40); 37 38 reg = in_be32(pdm360ng_gpio_base + 0x8); 39 40 /* return 1 if pen is down */ 41 return (reg & 0x40) == 0; 42} 43 44static struct ads7846_platform_data pdm360ng_ads7846_pdata = { 45 .model = 7845, 46 .get_pendown_state = pdm360ng_get_pendown_state, 47 .irq_flags = IRQF_TRIGGER_LOW, 48}; 49 50static int __init pdm360ng_penirq_init(void) 51{ 52 struct device_node *np; 53 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; 58 } 59 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; 65 } 66 out_be32(pdm360ng_gpio_base + 0xc, 0xffffffff); 67 setbits32(pdm360ng_gpio_base + 0x18, 0x2000); 68 setbits32(pdm360ng_gpio_base + 0x10, 0x40); 69 70 return 0; 71} 72 73static int pdm360ng_touchscreen_notifier_call(struct notifier_block *nb, 74 unsigned long event, void *__dev) 75{ 76 struct device *dev = __dev; 77 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; 82 } 83 return NOTIFY_DONE; 84} 85 86static struct notifier_block pdm360ng_touchscreen_nb = { 87 .notifier_call = pdm360ng_touchscreen_notifier_call, 88}; 89 90static void __init pdm360ng_touchscreen_init(void) 91{ 92 if (pdm360ng_penirq_init()) 93 return; 94 95 bus_register_notifier(&spi_bus_type, &pdm360ng_touchscreen_nb); 96} 97#else 98static inline void __init pdm360ng_touchscreen_init(void) 99{ 100} 101#endif /* CONFIG_TOUCHSCREEN_ADS7846 */ 102 103void __init pdm360ng_init(void) 104{ 105 mpc512x_init(); 106 pdm360ng_touchscreen_init(); 107} 108 109static int __init pdm360ng_probe(void) 110{ 111 if (!of_machine_is_compatible("ifm,pdm360ng")) 112 return 0; 113 114 mpc512x_init_early(); 115 116 return 1; 117} 118 119define_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, 128};