common-board-devices.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <linux/platform_data/spi-omap2-mcspi.h>
  26. #include "common.h"
  27. #include "common-board-devices.h"
  28. #if IS_ENABLED(CONFIG_TOUCHSCREEN_ADS7846)
  29. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  30. .turbo_mode = 0,
  31. };
  32. static struct ads7846_platform_data ads7846_config = {
  33. .x_max = 0x0fff,
  34. .y_max = 0x0fff,
  35. .x_plate_ohms = 180,
  36. .pressure_max = 255,
  37. .debounce_max = 10,
  38. .debounce_tol = 3,
  39. .debounce_rep = 1,
  40. .gpio_pendown = -EINVAL,
  41. .keep_vref_on = 1,
  42. };
  43. static struct spi_board_info ads7846_spi_board_info __initdata = {
  44. .modalias = "ads7846",
  45. .bus_num = -EINVAL,
  46. .chip_select = 0,
  47. .max_speed_hz = 1500000,
  48. .controller_data = &ads7846_mcspi_config,
  49. .irq = -EINVAL,
  50. .platform_data = &ads7846_config,
  51. };
  52. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  53. struct ads7846_platform_data *board_pdata)
  54. {
  55. struct spi_board_info *spi_bi = &ads7846_spi_board_info;
  56. int err;
  57. /*
  58. * If a board defines get_pendown_state() function, request the pendown
  59. * GPIO and set the GPIO debounce time.
  60. * If a board does not define the get_pendown_state() function, then
  61. * the ads7846 driver will setup the pendown GPIO itself.
  62. */
  63. if (board_pdata && board_pdata->get_pendown_state) {
  64. err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
  65. if (err) {
  66. pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
  67. return;
  68. }
  69. if (gpio_debounce)
  70. gpio_set_debounce(gpio_pendown, gpio_debounce);
  71. gpio_export(gpio_pendown, 0);
  72. }
  73. spi_bi->bus_num = bus_num;
  74. spi_bi->irq = gpio_to_irq(gpio_pendown);
  75. ads7846_config.gpio_pendown = gpio_pendown;
  76. if (board_pdata) {
  77. board_pdata->gpio_pendown = gpio_pendown;
  78. board_pdata->gpio_pendown_debounce = gpio_debounce;
  79. spi_bi->platform_data = board_pdata;
  80. }
  81. spi_register_board_info(&ads7846_spi_board_info, 1);
  82. }
  83. #else
  84. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  85. struct ads7846_platform_data *board_pdata)
  86. {
  87. }
  88. #endif