pdm360ng.c 2.9 KB

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