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