cx25821-gpio.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/module.h>
  23. #include "cx25821.h"
  24. /********************* GPIO stuffs *********************/
  25. void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
  26. int pin_number, int pin_logic_value)
  27. {
  28. int bit = pin_number;
  29. u32 gpio_oe_reg = GPIO_LO_OE;
  30. u32 gpio_register = 0;
  31. u32 value = 0;
  32. /* Check for valid pinNumber */
  33. if (pin_number >= 47)
  34. return;
  35. if (pin_number > 31) {
  36. bit = pin_number - 31;
  37. gpio_oe_reg = GPIO_HI_OE;
  38. }
  39. /* Here we will make sure that the GPIOs 0 and 1 are output. keep the
  40. * rest as is */
  41. gpio_register = cx_read(gpio_oe_reg);
  42. if (pin_logic_value == 1)
  43. value = gpio_register | Set_GPIO_Bit(bit);
  44. else
  45. value = gpio_register & Clear_GPIO_Bit(bit);
  46. cx_write(gpio_oe_reg, value);
  47. }
  48. EXPORT_SYMBOL(cx25821_set_gpiopin_direction);
  49. static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
  50. int pin_number, int pin_logic_value)
  51. {
  52. int bit = pin_number;
  53. u32 gpio_reg = GPIO_LO;
  54. u32 value = 0;
  55. /* Check for valid pinNumber */
  56. if (pin_number >= 47)
  57. return;
  58. /* change to output direction */
  59. cx25821_set_gpiopin_direction(dev, pin_number, 0);
  60. if (pin_number > 31) {
  61. bit = pin_number - 31;
  62. gpio_reg = GPIO_HI;
  63. }
  64. value = cx_read(gpio_reg);
  65. if (pin_logic_value == 0)
  66. value &= Clear_GPIO_Bit(bit);
  67. else
  68. value |= Set_GPIO_Bit(bit);
  69. cx_write(gpio_reg, value);
  70. }
  71. void cx25821_gpio_init(struct cx25821_dev *dev)
  72. {
  73. if (dev == NULL)
  74. return;
  75. switch (dev->board) {
  76. case CX25821_BOARD_CONEXANT_ATHENA10:
  77. default:
  78. /* set GPIO 5 to select the path for Medusa/Athena */
  79. cx25821_set_gpiopin_logicvalue(dev, 5, 1);
  80. mdelay(20);
  81. break;
  82. }
  83. }