it8172_cir.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * IT8172 Consumer IR port generic routines.
  5. *
  6. * Copyright 2001 MontaVista Software Inc.
  7. * Author: MontaVista Software, Inc.
  8. * ppopov@mvista.com or source@mvista.com
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  16. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  18. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  21. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * You should have received a copy of the GNU General Public License along
  27. * with this program; if not, write to the Free Software Foundation, Inc.,
  28. * 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. #ifdef CONFIG_IT8172_CIR
  31. #include <linux/types.h>
  32. #include <linux/pci.h>
  33. #include <linux/kernel.h>
  34. #include <linux/init.h>
  35. #include <asm/it8172/it8172.h>
  36. #include <asm/it8172/it8172_cir.h>
  37. volatile struct it8172_cir_regs *cir_regs[NUM_CIR_PORTS] = {
  38. (volatile struct it8172_cir_regs *)(KSEG1ADDR(IT8172_PCI_IO_BASE + IT_CIR0_BASE)),
  39. (volatile struct it8172_cir_regs *)(KSEG1ADDR(IT8172_PCI_IO_BASE + IT_CIR1_BASE))};
  40. /*
  41. * Initialize Consumer IR Port.
  42. */
  43. int cir_port_init(struct cir_port *cir)
  44. {
  45. int port = cir->port;
  46. unsigned char data;
  47. /* set baud rate */
  48. cir_regs[port]->bdlr = cir->baud_rate & 0xff;
  49. cir_regs[port]->bdhr = (cir->baud_rate >> 8) & 0xff;
  50. /* set receiver control register */
  51. cir_regs[port]->rcr = (CIR_SET_RDWOS(cir->rdwos) | CIR_SET_RXDCR(cir->rxdcr));
  52. /* set carrier frequency register */
  53. cir_regs[port]->cfr = (CIR_SET_CF(cir->cfq) | CIR_SET_HS(cir->hcfs));
  54. /* set fifo threshold */
  55. data = cir_regs[port]->mstcr & 0xf3;
  56. data |= CIR_SET_FIFO_TL(cir->fifo_tl);
  57. cir_regs[port]->mstcr = data;
  58. clear_fifo(cir);
  59. enable_receiver(cir);
  60. disable_rx_demodulation(cir);
  61. set_rx_active(cir);
  62. int_enable(cir);
  63. rx_int_enable(cir);
  64. return 0;
  65. }
  66. void clear_fifo(struct cir_port *cir)
  67. {
  68. cir_regs[cir->port]->mstcr |= CIR_FIFO_CLEAR;
  69. }
  70. void enable_receiver(struct cir_port *cir)
  71. {
  72. cir_regs[cir->port]->rcr |= CIR_RXEN;
  73. }
  74. void disable_receiver(struct cir_port *cir)
  75. {
  76. cir_regs[cir->port]->rcr &= ~CIR_RXEN;
  77. }
  78. void enable_rx_demodulation(struct cir_port *cir)
  79. {
  80. cir_regs[cir->port]->rcr |= CIR_RXEND;
  81. }
  82. void disable_rx_demodulation(struct cir_port *cir)
  83. {
  84. cir_regs[cir->port]->rcr &= ~CIR_RXEND;
  85. }
  86. void set_rx_active(struct cir_port *cir)
  87. {
  88. cir_regs[cir->port]->rcr |= CIR_RXACT;
  89. }
  90. void int_enable(struct cir_port *cir)
  91. {
  92. cir_regs[cir->port]->ier |= CIR_IEC;
  93. }
  94. void rx_int_enable(struct cir_port *cir)
  95. {
  96. cir_regs[cir->port]->ier |= CIR_RDAIE;
  97. }
  98. void dump_regs(struct cir_port *cir)
  99. {
  100. printk("mstcr %x ier %x iir %x cfr %x rcr %x tcr %x tfsr %x rfsr %x\n",
  101. cir_regs[cir->port]->mstcr,
  102. cir_regs[cir->port]->ier,
  103. cir_regs[cir->port]->iir,
  104. cir_regs[cir->port]->cfr,
  105. cir_regs[cir->port]->rcr,
  106. cir_regs[cir->port]->tcr,
  107. cir_regs[cir->port]->tfsr,
  108. cir_regs[cir->port]->rfsr);
  109. while (cir_regs[cir->port]->iir & CIR_RDAI) {
  110. printk("data %x\n", cir_regs[cir->port]->dr);
  111. }
  112. }
  113. void dump_reg_addr(struct cir_port *cir)
  114. {
  115. printk("dr %x mstcr %x ier %x iir %x cfr %x rcr %x tcr %x bdlr %x bdhr %x tfsr %x rfsr %x\n",
  116. (unsigned)&cir_regs[cir->port]->dr,
  117. (unsigned)&cir_regs[cir->port]->mstcr,
  118. (unsigned)&cir_regs[cir->port]->ier,
  119. (unsigned)&cir_regs[cir->port]->iir,
  120. (unsigned)&cir_regs[cir->port]->cfr,
  121. (unsigned)&cir_regs[cir->port]->rcr,
  122. (unsigned)&cir_regs[cir->port]->tcr,
  123. (unsigned)&cir_regs[cir->port]->bdlr,
  124. (unsigned)&cir_regs[cir->port]->bdhr,
  125. (unsigned)&cir_regs[cir->port]->tfsr,
  126. (unsigned)&cir_regs[cir->port]->rfsr);
  127. }
  128. int cir_get_rx_count(struct cir_port *cir)
  129. {
  130. return cir_regs[cir->port]->rfsr & CIR_RXFBC_MASK;
  131. }
  132. char cir_read_data(struct cir_port *cir)
  133. {
  134. return cir_regs[cir->port]->dr;
  135. }
  136. char get_int_status(struct cir_port *cir)
  137. {
  138. return cir_regs[cir->port]->iir;
  139. }
  140. #endif