pdm360ng.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <linux/device.h>
  10. #include <linux/kernel.h>
  11. #include <linux/io.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <linux/of_fdt.h>
  15. #include <asm/machdep.h>
  16. #include <asm/ipic.h>
  17. #include "mpc512x.h"
  18. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
  19. defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  20. #include <linux/interrupt.h>
  21. #include <linux/spi/ads7846.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/notifier.h>
  24. static void *pdm360ng_gpio_base;
  25. static int pdm360ng_get_pendown_state(void)
  26. {
  27. u32 reg;
  28. reg = in_be32(pdm360ng_gpio_base + 0xc);
  29. if (reg & 0x40)
  30. setbits32(pdm360ng_gpio_base + 0xc, 0x40);
  31. reg = in_be32(pdm360ng_gpio_base + 0x8);
  32. /* return 1 if pen is down */
  33. return (reg & 0x40) == 0;
  34. }
  35. static struct ads7846_platform_data pdm360ng_ads7846_pdata = {
  36. .model = 7845,
  37. .get_pendown_state = pdm360ng_get_pendown_state,
  38. .irq_flags = IRQF_TRIGGER_LOW,
  39. };
  40. static int __init pdm360ng_penirq_init(void)
  41. {
  42. struct device_node *np;
  43. np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-gpio");
  44. if (!np) {
  45. pr_err("%s: Can't find 'mpc5121-gpio' node\n", __func__);
  46. return -ENODEV;
  47. }
  48. pdm360ng_gpio_base = of_iomap(np, 0);
  49. of_node_put(np);
  50. if (!pdm360ng_gpio_base) {
  51. pr_err("%s: Can't map gpio regs.\n", __func__);
  52. return -ENODEV;
  53. }
  54. out_be32(pdm360ng_gpio_base + 0xc, 0xffffffff);
  55. setbits32(pdm360ng_gpio_base + 0x18, 0x2000);
  56. setbits32(pdm360ng_gpio_base + 0x10, 0x40);
  57. return 0;
  58. }
  59. static int pdm360ng_touchscreen_notifier_call(struct notifier_block *nb,
  60. unsigned long event, void *__dev)
  61. {
  62. struct device *dev = __dev;
  63. if ((event == BUS_NOTIFY_ADD_DEVICE) &&
  64. of_device_is_compatible(dev->of_node, "ti,ads7846")) {
  65. dev->platform_data = &pdm360ng_ads7846_pdata;
  66. return NOTIFY_OK;
  67. }
  68. return NOTIFY_DONE;
  69. }
  70. static struct notifier_block pdm360ng_touchscreen_nb = {
  71. .notifier_call = pdm360ng_touchscreen_notifier_call,
  72. };
  73. static void __init pdm360ng_touchscreen_init(void)
  74. {
  75. if (pdm360ng_penirq_init())
  76. return;
  77. bus_register_notifier(&spi_bus_type, &pdm360ng_touchscreen_nb);
  78. }
  79. #else
  80. static inline void __init pdm360ng_touchscreen_init(void)
  81. {
  82. }
  83. #endif /* CONFIG_TOUCHSCREEN_ADS7846 */
  84. static void __init pdm360ng_init(void)
  85. {
  86. mpc512x_init();
  87. pdm360ng_touchscreen_init();
  88. }
  89. static int __init pdm360ng_probe(void)
  90. {
  91. mpc512x_init_early();
  92. return 1;
  93. }
  94. define_machine(pdm360ng) {
  95. .name = "PDM360NG",
  96. .compatible = "ifm,pdm360ng",
  97. .probe = pdm360ng_probe,
  98. .setup_arch = mpc512x_setup_arch,
  99. .init = pdm360ng_init,
  100. .init_IRQ = mpc512x_init_IRQ,
  101. .get_irq = ipic_get_irq,
  102. .restart = mpc512x_restart,
  103. };