pdm360ng.c 3.0 KB

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