common-board-devices.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <plat/nand.h>
  30. #include "common-board-devices.h"
  31. static struct i2c_board_info __initdata pmic_i2c_board_info = {
  32. .addr = 0x48,
  33. .flags = I2C_CLIENT_WAKE,
  34. };
  35. void __init omap_pmic_init(int bus, u32 clkrate,
  36. const char *pmic_type, int pmic_irq,
  37. struct twl4030_platform_data *pmic_data)
  38. {
  39. strncpy(pmic_i2c_board_info.type, pmic_type,
  40. sizeof(pmic_i2c_board_info.type));
  41. pmic_i2c_board_info.irq = pmic_irq;
  42. pmic_i2c_board_info.platform_data = pmic_data;
  43. omap_register_i2c_bus(bus, clkrate, &pmic_i2c_board_info, 1);
  44. }
  45. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
  46. defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  47. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  48. .turbo_mode = 0,
  49. .single_channel = 1, /* 0: slave, 1: master */
  50. };
  51. static struct ads7846_platform_data ads7846_config = {
  52. .x_max = 0x0fff,
  53. .y_max = 0x0fff,
  54. .x_plate_ohms = 180,
  55. .pressure_max = 255,
  56. .debounce_max = 10,
  57. .debounce_tol = 3,
  58. .debounce_rep = 1,
  59. .gpio_pendown = -EINVAL,
  60. .keep_vref_on = 1,
  61. };
  62. static struct spi_board_info ads7846_spi_board_info __initdata = {
  63. .modalias = "ads7846",
  64. .bus_num = -EINVAL,
  65. .chip_select = 0,
  66. .max_speed_hz = 1500000,
  67. .controller_data = &ads7846_mcspi_config,
  68. .irq = -EINVAL,
  69. .platform_data = &ads7846_config,
  70. };
  71. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  72. struct ads7846_platform_data *board_pdata)
  73. {
  74. struct spi_board_info *spi_bi = &ads7846_spi_board_info;
  75. int err;
  76. if (board_pdata && board_pdata->get_pendown_state) {
  77. err = gpio_request_one(gpio_pendown, GPIOF_IN, "TSPenDown");
  78. if (err) {
  79. pr_err("Couldn't obtain gpio for TSPenDown: %d\n", err);
  80. return;
  81. }
  82. gpio_export(gpio_pendown, 0);
  83. if (gpio_debounce)
  84. gpio_set_debounce(gpio_pendown, gpio_debounce);
  85. }
  86. ads7846_config.gpio_pendown = gpio_pendown;
  87. spi_bi->bus_num = bus_num;
  88. spi_bi->irq = OMAP_GPIO_IRQ(gpio_pendown);
  89. if (board_pdata)
  90. spi_bi->platform_data = board_pdata;
  91. spi_register_board_info(&ads7846_spi_board_info, 1);
  92. }
  93. #else
  94. void __init omap_ads7846_init(int bus_num, int gpio_pendown, int gpio_debounce,
  95. struct ads7846_platform_data *board_pdata)
  96. {
  97. }
  98. #endif
  99. #if defined(CONFIG_MTD_NAND_OMAP2) || defined(CONFIG_MTD_NAND_OMAP2_MODULE)
  100. static struct omap_nand_platform_data nand_data = {
  101. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  102. };
  103. void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
  104. int nr_parts)
  105. {
  106. u8 cs = 0;
  107. u8 nandcs = GPMC_CS_NUM + 1;
  108. /* find out the chip-select on which NAND exists */
  109. while (cs < GPMC_CS_NUM) {
  110. u32 ret = 0;
  111. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  112. if ((ret & 0xC00) == 0x800) {
  113. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  114. if (nandcs > GPMC_CS_NUM)
  115. nandcs = cs;
  116. }
  117. cs++;
  118. }
  119. if (nandcs > GPMC_CS_NUM) {
  120. printk(KERN_INFO "NAND: Unable to find configuration "
  121. "in GPMC\n ");
  122. return;
  123. }
  124. if (nandcs < GPMC_CS_NUM) {
  125. nand_data.cs = nandcs;
  126. nand_data.parts = parts;
  127. nand_data.nr_parts = nr_parts;
  128. nand_data.options = options;
  129. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  130. if (gpmc_nand_init(&nand_data) < 0)
  131. printk(KERN_ERR "Unable to register NAND device\n");
  132. }
  133. }
  134. #else
  135. void __init omap_nand_flash_init(int options, struct mtd_partition *parts,
  136. int nr_parts)
  137. {
  138. }
  139. #endif