/arch/arm/mach-fsm/tlmm-msm8660.c

https://bitbucket.org/sammyz/iscream_thunderc-2.6.35-rebase · C · 124 lines · 89 code · 19 blank · 16 comment · 3 complexity · a821ab567de4ac530a795893765bf76b MD5 · raw file

  1. /* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. * 02110-1301, USA.
  16. */
  17. #include <linux/io.h>
  18. #include <linux/module.h>
  19. #include <linux/spinlock.h>
  20. #include <mach/tlmm.h>
  21. #include <mach/msm_iomap.h>
  22. #include <mach/gpio.h>
  23. #include "tlmm-msm8660.h"
  24. enum msm_tlmm_register {
  25. SDC4_HDRV_PULL_CTL = 0x20a0,
  26. SDC3_HDRV_PULL_CTL = 0x20a4,
  27. };
  28. struct tlmm_field_cfg {
  29. enum msm_tlmm_register reg;
  30. u8 off;
  31. };
  32. static struct tlmm_field_cfg tlmm_hdrv_cfgs[] = {
  33. {SDC4_HDRV_PULL_CTL, 6}, /* TLMM_HDRV_SDC4_CLK */
  34. {SDC4_HDRV_PULL_CTL, 3}, /* TLMM_HDRV_SDC4_CMD */
  35. {SDC4_HDRV_PULL_CTL, 0}, /* TLMM_HDRV_SDC4_DATA */
  36. {SDC3_HDRV_PULL_CTL, 6}, /* TLMM_HDRV_SDC3_CLK */
  37. {SDC3_HDRV_PULL_CTL, 3}, /* TLMM_HDRV_SDC3_CMD */
  38. {SDC3_HDRV_PULL_CTL, 0}, /* TLMM_HDRV_SDC3_DATA */
  39. };
  40. static struct tlmm_field_cfg tlmm_pull_cfgs[] = {
  41. {SDC4_HDRV_PULL_CTL, 11}, /* TLMM_PULL_SDC4_CMD */
  42. {SDC4_HDRV_PULL_CTL, 9}, /* TLMM_PULL_SDC4_DATA */
  43. {SDC3_HDRV_PULL_CTL, 11}, /* TLMM_PULL_SDC3_CMD */
  44. {SDC3_HDRV_PULL_CTL, 9}, /* TLMM_PULL_SDC3_DATA */
  45. };
  46. static DEFINE_SPINLOCK(tlmm_lock);
  47. static void msm_tlmm_set_field(struct tlmm_field_cfg *configs,
  48. unsigned id,
  49. unsigned width,
  50. unsigned val)
  51. {
  52. unsigned long irqflags;
  53. u32 mask = (1 << width) - 1;
  54. u32 __iomem *reg = MSM_TLMM_BASE + configs[id].reg;
  55. u32 reg_val;
  56. spin_lock_irqsave(&tlmm_lock, irqflags);
  57. reg_val = readl(reg);
  58. reg_val &= ~(mask << configs[id].off);
  59. reg_val |= (val & mask) << configs[id].off;
  60. writel(reg_val, reg);
  61. spin_unlock_irqrestore(&tlmm_lock, irqflags);
  62. }
  63. void msm_tlmm_set_hdrive(enum msm_tlmm_hdrive_tgt tgt, int drv_str)
  64. {
  65. msm_tlmm_set_field(tlmm_hdrv_cfgs, tgt, 3, drv_str);
  66. }
  67. EXPORT_SYMBOL(msm_tlmm_set_hdrive);
  68. void msm_tlmm_set_pull(enum msm_tlmm_pull_tgt tgt, int pull)
  69. {
  70. msm_tlmm_set_field(tlmm_pull_cfgs, tgt, 2, pull);
  71. }
  72. EXPORT_SYMBOL(msm_tlmm_set_pull);
  73. int gpio_tlmm_config(unsigned config, unsigned disable)
  74. {
  75. uint32_t flags;
  76. unsigned gpio = GPIO_PIN(config);
  77. if (gpio > NR_MSM_GPIOS)
  78. return -EINVAL;
  79. flags = ((GPIO_DIR(config) << 9) & (0x1 << 9)) |
  80. ((GPIO_DRVSTR(config) << 6) & (0x7 << 6)) |
  81. ((GPIO_FUNC(config) << 2) & (0xf << 2)) |
  82. ((GPIO_PULL(config) & 0x3));
  83. writel(flags, GPIO_CONFIG(gpio));
  84. return 0;
  85. }
  86. EXPORT_SYMBOL(gpio_tlmm_config);
  87. int msm_gpio_install_direct_irq(unsigned gpio, unsigned irq)
  88. {
  89. unsigned long irq_flags;
  90. if (gpio >= NR_MSM_GPIOS || irq >= NR_TLMM_SCSS_DIR_CONN_IRQ)
  91. return -EINVAL;
  92. spin_lock_irqsave(&tlmm_lock, irq_flags);
  93. writel(readl(GPIO_CONFIG(gpio)) | BIT(GPIO_OE_BIT),
  94. GPIO_CONFIG(gpio));
  95. writel(readl(GPIO_INTR_CFG(gpio)) &
  96. ~(INTR_RAW_STATUS_EN | INTR_ENABLE),
  97. GPIO_INTR_CFG(gpio));
  98. writel(DC_IRQ_ENABLE | TARGET_PROC_NONE,
  99. GPIO_INTR_CFG_SU(gpio));
  100. writel(DC_POLARITY_HI | TARGET_PROC_SCORPION | (gpio << 3),
  101. DIR_CONN_INTR_CFG_SU(irq));
  102. spin_unlock_irqrestore(&tlmm_lock, irq_flags);
  103. return 0;
  104. }
  105. EXPORT_SYMBOL(msm_gpio_install_direct_irq);