cx25821-gpio.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Driver for the Conexant CX25821 PCIe bridge
  3. *
  4. * Copyright (C) 2009 Conexant Systems Inc.
  5. * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. *
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/module.h>
  19. #include "cx25821.h"
  20. /********************* GPIO stuffs *********************/
  21. void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  22. int pin_number, int pin_logic_value)
  23. {
  24. int bit = pin_number;
  25. u32 gpio_oe_reg = GPIO_LO_OE;
  26. u32 gpio_register = 0;
  27. u32 value = 0;
  28. /* Check for valid pinNumber */
  29. if (pin_number >= 47)
  30. return;
  31. if (pin_number > 31) {
  32. bit = pin_number - 31;
  33. gpio_oe_reg = GPIO_HI_OE;
  34. }
  35. /* Here we will make sure that the GPIOs 0 and 1 are output. keep the
  36. * rest as is */
  37. gpio_register = cx_read(gpio_oe_reg);
  38. if (pin_logic_value == 1)
  39. value = gpio_register | Set_GPIO_Bit(bit);
  40. else
  41. value = gpio_register & Clear_GPIO_Bit(bit);
  42. cx_write(gpio_oe_reg, value);
  43. }
  44. EXPORT_SYMBOL(cx25821_set_gpiopin_direction);
  45. static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
  46. int pin_number, int pin_logic_value)
  47. {
  48. int bit = pin_number;
  49. u32 gpio_reg = GPIO_LO;
  50. u32 value = 0;
  51. /* Check for valid pinNumber */
  52. if (pin_number >= 47)
  53. return;
  54. /* change to output direction */
  55. cx25821_set_gpiopin_direction(dev, pin_number, 0);
  56. if (pin_number > 31) {
  57. bit = pin_number - 31;
  58. gpio_reg = GPIO_HI;
  59. }
  60. value = cx_read(gpio_reg);
  61. if (pin_logic_value == 0)
  62. value &= Clear_GPIO_Bit(bit);
  63. else
  64. value |= Set_GPIO_Bit(bit);
  65. cx_write(gpio_reg, value);
  66. }
  67. void cx25821_gpio_init(struct cx25821_dev *dev)
  68. {
  69. if (dev == NULL)
  70. return;
  71. switch (dev->board) {
  72. case CX25821_BOARD_CONEXANT_ATHENA10:
  73. default:
  74. /* set GPIO 5 to select the path for Medusa/Athena */
  75. cx25821_set_gpiopin_logicvalue(dev, 5, 1);
  76. msleep(20);
  77. break;
  78. }
  79. }