gpio.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* linux/arch/arm/mach-msm/gpio.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <mach/gpio.h>
  18. #include "proc_comm.h"
  19. int gpio_tlmm_config(unsigned config, unsigned disable)
  20. {
  21. return msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &config, &disable);
  22. }
  23. EXPORT_SYMBOL(gpio_tlmm_config);
  24. int msm_gpios_enable(const struct msm_gpio *table, int size)
  25. {
  26. int rc;
  27. int i;
  28. const struct msm_gpio *g;
  29. for (i = 0; i < size; i++) {
  30. g = table + i;
  31. rc = gpio_tlmm_config(g->gpio_cfg, GPIO_ENABLE);
  32. if (rc) {
  33. pr_err("gpio_tlmm_config(0x%08x, GPIO_ENABLE)"
  34. " <%s> failed: %d\n",
  35. g->gpio_cfg, g->label ?: "?", rc);
  36. pr_err("pin %d func %d dir %d pull %d drvstr %d\n",
  37. GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg),
  38. GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg),
  39. GPIO_DRVSTR(g->gpio_cfg));
  40. goto err;
  41. }
  42. }
  43. return 0;
  44. err:
  45. msm_gpios_disable(table, i);
  46. return rc;
  47. }
  48. EXPORT_SYMBOL(msm_gpios_enable);
  49. void msm_gpios_disable(const struct msm_gpio *table, int size)
  50. {
  51. int rc;
  52. int i;
  53. const struct msm_gpio *g;
  54. for (i = size-1; i >= 0; i--) {
  55. g = table + i;
  56. rc = gpio_tlmm_config(g->gpio_cfg, GPIO_DISABLE);
  57. if (rc) {
  58. pr_err("gpio_tlmm_config(0x%08x, GPIO_DISABLE)"
  59. " <%s> failed: %d\n",
  60. g->gpio_cfg, g->label ?: "?", rc);
  61. pr_err("pin %d func %d dir %d pull %d drvstr %d\n",
  62. GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg),
  63. GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg),
  64. GPIO_DRVSTR(g->gpio_cfg));
  65. }
  66. }
  67. }
  68. EXPORT_SYMBOL(msm_gpios_disable);
  69. int msm_gpios_request_enable(const struct msm_gpio *table, int size)
  70. {
  71. int rc = msm_gpios_enable(table, size);
  72. return rc;
  73. }
  74. EXPORT_SYMBOL(msm_gpios_request_enable);
  75. void msm_gpios_disable_free(const struct msm_gpio *table, int size)
  76. {
  77. msm_gpios_disable(table, size);
  78. }
  79. EXPORT_SYMBOL(msm_gpios_disable_free);