board-trout-gpio.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * linux/arch/arm/mach-msm/gpio.c
  3. *
  4. * Copyright (C) 2005 HP Labs
  5. * Copyright (C) 2008 Google, Inc.
  6. * Copyright (C) 2009 Pavel Machek <pavel@ucw.cz>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/gpio.h>
  18. #include "board-trout.h"
  19. struct msm_gpio_chip {
  20. struct gpio_chip chip;
  21. void __iomem *reg; /* Base of register bank */
  22. u8 shadow;
  23. };
  24. #define to_msm_gpio_chip(c) container_of(c, struct msm_gpio_chip, chip)
  25. static int msm_gpiolib_get(struct gpio_chip *chip, unsigned offset)
  26. {
  27. struct msm_gpio_chip *msm_gpio = to_msm_gpio_chip(chip);
  28. unsigned mask = 1 << offset;
  29. return !!(readb(msm_gpio->reg) & mask);
  30. }
  31. static void msm_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)
  32. {
  33. struct msm_gpio_chip *msm_gpio = to_msm_gpio_chip(chip);
  34. unsigned mask = 1 << offset;
  35. if (val)
  36. msm_gpio->shadow |= mask;
  37. else
  38. msm_gpio->shadow &= ~mask;
  39. writeb(msm_gpio->shadow, msm_gpio->reg);
  40. }
  41. static int msm_gpiolib_direction_input(struct gpio_chip *chip,
  42. unsigned offset)
  43. {
  44. msm_gpiolib_set(chip, offset, 0);
  45. return 0;
  46. }
  47. static int msm_gpiolib_direction_output(struct gpio_chip *chip,
  48. unsigned offset, int val)
  49. {
  50. msm_gpiolib_set(chip, offset, val);
  51. return 0;
  52. }
  53. #define TROUT_GPIO_BANK(name, reg_num, base_gpio, shadow_val) \
  54. { \
  55. .chip = { \
  56. .label = name, \
  57. .direction_input = msm_gpiolib_direction_input,\
  58. .direction_output = msm_gpiolib_direction_output, \
  59. .get = msm_gpiolib_get, \
  60. .set = msm_gpiolib_set, \
  61. .base = base_gpio, \
  62. .ngpio = 8, \
  63. }, \
  64. .reg = (void *) reg_num + TROUT_CPLD_BASE, \
  65. .shadow = shadow_val, \
  66. }
  67. static struct msm_gpio_chip msm_gpio_banks[] = {
  68. #if defined(CONFIG_MSM_DEBUG_UART1)
  69. /* H2W pins <-> UART1 */
  70. TROUT_GPIO_BANK("MISC2", 0x00, TROUT_GPIO_MISC2_BASE, 0x40),
  71. #else
  72. /* H2W pins <-> UART3, Bluetooth <-> UART1 */
  73. TROUT_GPIO_BANK("MISC2", 0x00, TROUT_GPIO_MISC2_BASE, 0x80),
  74. #endif
  75. /* I2C pull */
  76. TROUT_GPIO_BANK("MISC3", 0x02, TROUT_GPIO_MISC3_BASE, 0x04),
  77. TROUT_GPIO_BANK("MISC4", 0x04, TROUT_GPIO_MISC4_BASE, 0),
  78. /* mmdi 32k en */
  79. TROUT_GPIO_BANK("MISC5", 0x06, TROUT_GPIO_MISC5_BASE, 0x04),
  80. TROUT_GPIO_BANK("INT2", 0x08, TROUT_GPIO_INT2_BASE, 0),
  81. TROUT_GPIO_BANK("MISC1", 0x0a, TROUT_GPIO_MISC1_BASE, 0),
  82. TROUT_GPIO_BANK("VIRTUAL", 0x12, TROUT_GPIO_VIRTUAL_BASE, 0),
  83. };
  84. /*
  85. * Called from the processor-specific init to enable GPIO pin support.
  86. */
  87. int __init trout_init_gpio(void)
  88. {
  89. int i;
  90. for (i = 0; i < ARRAY_SIZE(msm_gpio_banks); i++)
  91. gpiochip_add(&msm_gpio_banks[i].chip);
  92. return 0;
  93. }
  94. postcore_initcall(trout_init_gpio);