common-board-devices.c 2.7 KB

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