it8172_cir.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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. #include <linux/config.h>
  31. #ifdef CONFIG_IT8172_CIR
  32. #include <linux/types.h>
  33. #include <linux/pci.h>
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <asm/it8172/it8172.h>
  37. #include <asm/it8172/it8172_cir.h>
  38. volatile struct it8172_cir_regs *cir_regs[NUM_CIR_PORTS] = {
  39. (volatile struct it8172_cir_regs *)(KSEG1ADDR(IT8172_PCI_IO_BASE + IT_CIR0_BASE)),
  40. (volatile struct it8172_cir_regs *)(KSEG1ADDR(IT8172_PCI_IO_BASE + IT_CIR1_BASE))};
  41. /*
  42.  * Initialize Consumer IR Port.
  43.  */
  44. int cir_port_init(struct cir_port *cir)
  45. {
  46. int port = cir->port;
  47. unsigned char data;
  48. /* set baud rate */
  49. cir_regs[port]->bdlr = cir->baud_rate & 0xff;
  50. cir_regs[port]->bdhr = (cir->baud_rate >> 8) & 0xff;
  51. /* set receiver control register */
  52. cir_regs[port]->rcr = (CIR_SET_RDWOS(cir->rdwos) | CIR_SET_RXDCR(cir->rxdcr));
  53. /* set carrier frequency register */
  54. cir_regs[port]->cfr = (CIR_SET_CF(cir->cfq) | CIR_SET_HS(cir->hcfs));
  55. /* set fifo threshold */
  56. data = cir_regs[port]->mstcr & 0xf3;
  57. data |= CIR_SET_FIFO_TL(cir->fifo_tl);
  58. cir_regs[port]->mstcr = data;
  59. clear_fifo(cir);
  60. enable_receiver(cir);
  61. disable_rx_demodulation(cir);
  62. set_rx_active(cir);
  63. int_enable(cir);
  64. rx_int_enable(cir);
  65. return 0;
  66. }
  67. void clear_fifo(struct cir_port *cir)
  68. {
  69. cir_regs[cir->port]->mstcr |= CIR_FIFO_CLEAR;
  70. }
  71. void enable_receiver(struct cir_port *cir)
  72. {
  73. cir_regs[cir->port]->rcr |= CIR_RXEN;
  74. }
  75. void disable_receiver(struct cir_port *cir)
  76. {
  77. cir_regs[cir->port]->rcr &= ~CIR_RXEN;
  78. }
  79. void enable_rx_demodulation(struct cir_port *cir)
  80. {
  81. cir_regs[cir->port]->rcr |= CIR_RXEND;
  82. }
  83. void disable_rx_demodulation(struct cir_port *cir)
  84. {
  85. cir_regs[cir->port]->rcr &= ~CIR_RXEND;
  86. }
  87. void set_rx_active(struct cir_port *cir)
  88. {
  89. cir_regs[cir->port]->rcr |= CIR_RXACT;
  90. }
  91. void int_enable(struct cir_port *cir)
  92. {
  93. cir_regs[cir->port]->ier |= CIR_IEC;
  94. }
  95. void rx_int_enable(struct cir_port *cir)
  96. {
  97. cir_regs[cir->port]->ier |= CIR_RDAIE;
  98. }
  99. void dump_regs(struct cir_port *cir)
  100. {
  101. printk("mstcr %x ier %x iir %x cfr %x rcr %x tcr %x tfsr %x rfsr %xn",
  102. cir_regs[cir->port]->mstcr,
  103. cir_regs[cir->port]->ier,
  104. cir_regs[cir->port]->iir,
  105. cir_regs[cir->port]->cfr,
  106. cir_regs[cir->port]->rcr,
  107. cir_regs[cir->port]->tcr,
  108. cir_regs[cir->port]->tfsr,
  109. cir_regs[cir->port]->rfsr);
  110. while (cir_regs[cir->port]->iir & CIR_RDAI) {
  111. printk("data %xn", cir_regs[cir->port]->dr);
  112. }
  113. }
  114. void dump_reg_addr(struct cir_port *cir)
  115. {
  116. printk("dr %x mstcr %x ier %x iir %x cfr %x rcr %x tcr %x bdlr %x bdhr %x tfsr %x rfsr %xn",
  117. (unsigned)&cir_regs[cir->port]->dr,
  118. (unsigned)&cir_regs[cir->port]->mstcr,
  119. (unsigned)&cir_regs[cir->port]->ier,
  120. (unsigned)&cir_regs[cir->port]->iir,
  121. (unsigned)&cir_regs[cir->port]->cfr,
  122. (unsigned)&cir_regs[cir->port]->rcr,
  123. (unsigned)&cir_regs[cir->port]->tcr,
  124. (unsigned)&cir_regs[cir->port]->bdlr,
  125. (unsigned)&cir_regs[cir->port]->bdhr,
  126. (unsigned)&cir_regs[cir->port]->tfsr,
  127. (unsigned)&cir_regs[cir->port]->rfsr);
  128. }
  129. int cir_get_rx_count(struct cir_port *cir)
  130. {
  131. return cir_regs[cir->port]->rfsr & CIR_RXFBC_MASK;
  132. }
  133. char cir_read_data(struct cir_port *cir)
  134. {
  135. return cir_regs[cir->port]->dr;
  136. }
  137. char get_int_status(struct cir_port *cir)
  138. {
  139. return cir_regs[cir->port]->iir;
  140. }
  141. #endif