1 /*
2  * FILE NAME
3  *	arch/mips/vr41xx/common/serial.c
4  *
5  * BRIEF MODULE DESCRIPTION
6  *	Serial Interface Unit routines for NEC VR4100 series.
7  *
8  * Author: Yoichi Yuasa
9  *         yyuasa@mvista.com or source@mvista.com
10  *
11  * Copyright 2002 MontaVista Software Inc.
12  *
13  *  This program is free software; you can redistribute it and/or modify it
14  *  under the terms of the GNU General Public License as published by the
15  *  Free Software Foundation; either version 2 of the License, or (at your
16  *  option) any later version.
17  *
18  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *  You should have received a copy of the GNU General Public License along
30  *  with this program; if not, write to the Free Software Foundation, Inc.,
31  *  675 Mass Ave, Cambridge, MA 02139, USA.
32  */
33 /*
34  * Changes:
35  *  MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com>
36  *  - New creation, NEC VR4122 and VR4131 are supported.
37  *  - Added support for NEC VR4111 and VR4121.
38  *
39  *  Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
40  *  - Added support for NEC VR4133.
41  */
42 #include <linux/init.h>
43 #include <linux/types.h>
44 #include <linux/serial.h>
45 
46 #include <asm/addrspace.h>
47 #include <asm/cpu.h>
48 #include <asm/io.h>
49 #include <asm/vr41xx/vr41xx.h>
50 
51 /* VR4111 and VR4121 SIU Registers */
52 #define SIURB_TYPE1		KSEG1ADDR(0x0c000000)
53 #define SIUIRSEL_TYPE1		KSEG1ADDR(0x0c000008)
54 
55 /* VR4122, VR4131 and VR4133 SIU Registers */
56 #define SIURB_TYPE2		KSEG1ADDR(0x0f000800)
57 #define SIUIRSEL_TYPE2		KSEG1ADDR(0x0f000808)
58 
59  #define USE_RS232C		0x00
60  #define USE_IRDA		0x01
61  #define SIU_USES_IRDA		0x00
62  #define FIR_USES_IRDA		0x02
63  #define IRDA_MODULE_SHARP	0x00
64  #define IRDA_MODULE_TEMIC	0x04
65  #define IRDA_MODULE_HP		0x08
66  #define TMICTX			0x10
67  #define TMICMODE		0x20
68 
69 #define SIU_BASE_BAUD		1152000
70 
71 /* VR4122 and VR4131 DSIU Registers */
72 #define DSIURB			KSEG1ADDR(0x0f000820)
73 
74 #define MDSIUINTREG		KSEG1ADDR(0x0f000096)
75  #define INTDSIU		0x0800
76 
77 #define DSIU_BASE_BAUD		1152000
78 
79 int vr41xx_serial_ports = 0;
80 
vr41xx_siu_ifselect(int interface,int module)81 void vr41xx_siu_ifselect(int interface, int module)
82 {
83 	u16 val = USE_RS232C;	/* Select RS-232C */
84 
85 	/* Select IrDA */
86 	if (interface == SIU_IRDA) {
87 		switch (module) {
88 		case IRDA_SHARP:
89 			val = IRDA_MODULE_SHARP;
90 			break;
91 		case IRDA_TEMIC:
92 			val = IRDA_MODULE_TEMIC;
93 			break;
94 		case IRDA_HP:
95 			val = IRDA_MODULE_HP;
96 			break;
97 		}
98 		val |= USE_IRDA | SIU_USES_IRDA;
99 	}
100 
101 	switch (current_cpu_data.cputype) {
102 	case CPU_VR4111:
103 	case CPU_VR4121:
104 		writew(val, SIUIRSEL_TYPE1);
105 		break;
106 	case CPU_VR4122:
107 	case CPU_VR4131:
108 	case CPU_VR4133:
109 		writew(val, SIUIRSEL_TYPE2);
110 		break;
111 	default:
112 		printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
113 		break;
114 	}
115 }
116 
vr41xx_siu_init(int interface,int module)117 void __init vr41xx_siu_init(int interface, int module)
118 {
119 	struct serial_struct s;
120 
121 	vr41xx_siu_ifselect(interface, module);
122 
123 	memset(&s, 0, sizeof(s));
124 
125 	s.line = vr41xx_serial_ports;
126 	s.baud_base = SIU_BASE_BAUD;
127 	s.irq = SIU_IRQ;
128 	s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
129 	switch (current_cpu_data.cputype) {
130 	case CPU_VR4111:
131 	case CPU_VR4121:
132 		s.iomem_base = (unsigned char *)SIURB_TYPE1;
133 		break;
134 	case CPU_VR4122:
135 	case CPU_VR4131:
136 	case CPU_VR4133:
137 		s.iomem_base = (unsigned char *)SIURB_TYPE2;
138 		break;
139 	default:
140 		panic("Unexpected CPU of NEC VR4100 series");
141 		break;
142 	}
143 	s.iomem_reg_shift = 0;
144 	s.io_type = SERIAL_IO_MEM;
145 	if (early_serial_setup(&s) != 0)
146 		printk(KERN_ERR "SIU setup failed!\n");
147 
148 	vr41xx_supply_clock(SIU_CLOCK);
149 
150 	vr41xx_serial_ports++;
151 }
152 
vr41xx_dsiu_init(void)153 void __init vr41xx_dsiu_init(void)
154 {
155 	struct serial_struct s;
156 
157 	if (current_cpu_data.cputype != CPU_VR4122 &&
158 	    current_cpu_data.cputype != CPU_VR4131 &&
159 	    current_cpu_data.cputype != CPU_VR4133)
160 		return;
161 
162 	memset(&s, 0, sizeof(s));
163 
164 	s.line = vr41xx_serial_ports;
165 	s.baud_base = DSIU_BASE_BAUD;
166 	s.irq = DSIU_IRQ;
167 	s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
168 	s.iomem_base = (unsigned char *)DSIURB;
169 	s.iomem_reg_shift = 0;
170 	s.io_type = SERIAL_IO_MEM;
171 	if (early_serial_setup(&s) != 0)
172 		printk(KERN_ERR "DSIU setup failed!\n");
173 
174 	vr41xx_supply_clock(DSIU_CLOCK);
175 
176 	writew(INTDSIU, MDSIUINTREG);
177 
178 	vr41xx_serial_ports++;
179 }
180