pdm360ng.c 2.8 KB

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