common-board-devices.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/i2c.h>
  23. #include <linux/i2c/twl.h>
  24. #include <linux/gpio.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/spi/ads7846.h>
  27. #include <plat/i2c.h>
  28. #include <plat/mcspi.h>
  29. #include "common-board-devices.h"
  30. static struct i2c_board_info __initdata pmic_i2c_board_info = {
  31. .addr = 0x48,
  32. .flags = I2C_CLIENT_WAKE,
  33. };
  34. void __init omap_pmic_init(int bus, u32 clkrate,
  35. const char *pmic_type, int pmic_irq,
  36. struct twl4030_platform_data *pmic_data)
  37. {
  38. strncpy(pmic_i2c_board_info.type, pmic_type,
  39. sizeof(pmic_i2c_board_info.type));
  40. pmic_i2c_board_info.irq = pmic_irq;
  41. pmic_i2c_board_info.platform_data = pmic_data;
  42. omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
  43. }
  44. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  45. .turbo_mode = 0,
  46. .single_channel = 1, /* 0: slave, 1: master */
  47. };
  48. static struct ads7846_platform_data ads7846_config = {
  49. .x_max = 0x0fff,
  50. .y_max = 0x0fff,
  51. .x_plate_ohms = 180,
  52. .pressure_max = 255,
  53. .debounce_max = 10,
  54. .debounce_tol = 3,
  55. .debounce_rep = 1,
  56. .gpio_pendown = -EINVAL,
  57. .keep_vref_on = 1,
  58. };
  59. static struct spi_board_info ads7846_spi_board_info __initdata = {
  60. .modalias = "ads7846",
  61. .bus_num = -EINVAL,
  62. .chip_select = 0,
  63. .max_speed_hz = 1500000,
  64. .controller_data = &ads7846_mcspi_config,
  65. .irq = -EINVAL,
  66. .platform_data = &ads7846_config,
  67. };
  68. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  69. struct ads7846_platform_data *board_pdata)
  70. {
  71. struct spi_board_info *spi_bi = &ads7846_spi_board_info;
  72. int err;
  73. err = gpio_request(gpio_pendown, "TS PenDown");
  74. if (err) {
  75. pr_err("Could not obtain gpio for TS PenDown: %d\n", err);
  76. return;
  77. }
  78. gpio_direction_input(gpio_pendown);
  79. gpio_export(gpio_pendown, 0);
  80. if (gpio_debounce)
  81. gpio_set_debounce(gpio_pendown, gpio_debounce);
  82. ads7846_config.gpio_pendown = gpio_pendown;
  83. spi_bi->bus_num = bus_num;
  84. spi_bi->irq = OMAP_GPIO_IRQ(gpio_pendown);
  85. if (board_pdata)
  86. spi_bi->platform_data = board_pdata;
  87. spi_register_board_info(&ads7846_spi_board_info, 1);
  88. }