common-board-devices.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * common-board-devices.c
  3. *
  4. * Copyright (C) 2011 CompuLab, Ltd.
  5. * Author: Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. */
  22. #include <linux/gpio.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/ads7846.h>
  25. #include <plat/mcspi.h>
  26. #include <plat/nand.h>
  27. #include "common-board-devices.h"
  28. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
  29. defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  30. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  31. .turbo_mode = 0,
  32. };
  33. /*
  34. * ADS7846 driver maybe request a gpio according to the value
  35. * of pdata->get_pendown_state, but we have done this. So set
  36. * get_pendown_state to avoid twice gpio requesting.
  37. */
  38. static int omap3_get_pendown_state(void)
  39. {
  40. return !gpio_get_value(OMAP3_EVM_TS_GPIO);
  41. }
  42. static struct ads7846_platform_data ads7846_config = {
  43. .x_max = 0x0fff,
  44. .y_max = 0x0fff,
  45. .x_plate_ohms = 180,
  46. .pressure_max = 255,
  47. .debounce_max = 10,
  48. .debounce_tol = 3,
  49. .debounce_rep = 1,
  50. .gpio_pendown = -EINVAL,
  51. .keep_vref_on = 1,
  52. .get_pendown_state = &omap3_get_pendown_state,
  53. };
  54. static struct spi_board_info ads7846_spi_board_info __initdata = {
  55. .modalias = "ads7846",
  56. .bus_num = -EINVAL,
  57. .chip_select = 0,
  58. .max_speed_hz = 1500000,
  59. .controller_data = &ads7846_mcspi_config,
  60. .irq = -EINVAL,
  61. .platform_data = &ads7846_config,
  62. };
  63. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  64. struct ads7846_platform_data *board_pdata)
  65. {
  66. struct spi_board_info *spi_bi = &ads7846_spi_board_info;
  67. int err;
  68. err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
  69. if (err) {
  70. pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
  71. return;
  72. }
  73. if (gpio_debounce)
  74. gpio_set_debounce(gpio_pendown, gpio_debounce);
  75. spi_bi->bus_num = bus_num;
  76. spi_bi->irq = gpio_to_irq(gpio_pendown);
  77. if (board_pdata) {
  78. board_pdata->gpio_pendown = gpio_pendown;
  79. spi_bi->platform_data = board_pdata;
  80. if (board_pdata->get_pendown_state)
  81. gpio_export(gpio_pendown, 0);
  82. } else {
  83. ads7846_config.gpio_pendown = gpio_pendown;
  84. }
  85. if (!board_pdata || (board_pdata && !board_pdata->get_pendown_state))
  86. gpio_free(gpio_pendown);
  87. spi_register_board_info(&ads7846_spi_board_info, 1);
  88. }
  89. #else
  90. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  91. struct ads7846_platform_data *board_pdata)
  92. {
  93. }
  94. #endif
  95. #if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE)
  96. static struct omap_nand_platform_data nand_data;
  97. void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
  98. int nr_parts)
  99. {
  100. u8 cs = 0;
  101. u8 nandcs = GPMC_CS_NUM + 1;
  102. /* find out the chip-select on which NAND exists */
  103. while (cs < GPMC_CS_NUM) {
  104. u32 ret = 0;
  105. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  106. if ((ret & 0xC00) == 0x800) {
  107. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  108. if (nandcs > GPMC_CS_NUM)
  109. nandcs = cs;
  110. }
  111. cs++;
  112. }
  113. if (nandcs > GPMC_CS_NUM) {
  114. printk(KERN_INFO "NAND: Unable to find configuration "
  115. "in GPMC\n ");
  116. return;
  117. }
  118. if (nandcs < GPMC_CS_NUM) {
  119. nand_data.cs = nandcs;
  120. nand_data.parts = parts;
  121. nand_data.nr_parts = nr_parts;
  122. nand_data.devsize = options;
  123. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  124. if (gpmc_nand_init(&nand_data) < 0)
  125. printk(KERN_ERR "Unable to register NAND device\n");
  126. }
  127. }
  128. #else
  129. void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
  130. int nr_parts)
  131. {
  132. }
  133. #endif