您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ath5k_gpio.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
  4. *
  5. * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
  6. *
  7. * Permission to use, copy, modify, and distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. *
  19. */
  20. FILE_LICENCE ( MIT );
  21. /****************\
  22. GPIO Functions
  23. \****************/
  24. #include "ath5k.h"
  25. #include "reg.h"
  26. #include "base.h"
  27. /*
  28. * Set GPIO inputs
  29. */
  30. int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
  31. {
  32. if (gpio >= AR5K_NUM_GPIO)
  33. return -EINVAL;
  34. ath5k_hw_reg_write(ah,
  35. (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio))
  36. | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
  37. return 0;
  38. }
  39. /*
  40. * Set GPIO outputs
  41. */
  42. int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
  43. {
  44. if (gpio >= AR5K_NUM_GPIO)
  45. return -EINVAL;
  46. ath5k_hw_reg_write(ah,
  47. (ath5k_hw_reg_read(ah, AR5K_GPIOCR) & ~AR5K_GPIOCR_OUT(gpio))
  48. | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
  49. return 0;
  50. }
  51. /*
  52. * Get GPIO state
  53. */
  54. u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
  55. {
  56. if (gpio >= AR5K_NUM_GPIO)
  57. return 0xffffffff;
  58. /* GPIO input magic */
  59. return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
  60. 0x1;
  61. }
  62. /*
  63. * Set GPIO state
  64. */
  65. int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
  66. {
  67. u32 data;
  68. if (gpio >= AR5K_NUM_GPIO)
  69. return -EINVAL;
  70. /* GPIO output magic */
  71. data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  72. data &= ~(1 << gpio);
  73. data |= (val & 1) << gpio;
  74. ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
  75. return 0;
  76. }
  77. /*
  78. * Initialize the GPIO interrupt (RFKill switch)
  79. */
  80. void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
  81. u32 interrupt_level)
  82. {
  83. u32 data;
  84. if (gpio >= AR5K_NUM_GPIO)
  85. return;
  86. /*
  87. * Set the GPIO interrupt
  88. */
  89. data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
  90. ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
  91. AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
  92. (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
  93. ath5k_hw_reg_write(ah, interrupt_level ? data :
  94. (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
  95. ah->ah_imr |= AR5K_IMR_GPIO;
  96. /* Enable GPIO interrupts */
  97. AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
  98. }