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

Linux/Unix编程

开发平台:

Unix_Linux

  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.  *  - Added support for NEC VR4111 and VR4121.
  37.  *
  38.  *  MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com>
  39.  *  - New creation, NEC VR4122 and VR4131 are supported.
  40.  */
  41. #include <linux/init.h>
  42. #include <linux/types.h>
  43. #include <linux/serial.h>
  44. #include <asm/addrspace.h>
  45. #include <asm/cpu.h>
  46. #include <asm/io.h>
  47. #include <asm/vr41xx/vr41xx.h>
  48. /* VR4111 and VR4121 SIU Registers */
  49. #define VR4111_SIURB KSEG1ADDR(0x0c000000)
  50. #define VR4111_SIUIRSEL KSEG1ADDR(0x0c000008)
  51. /* VR4122 and VR4131 SIU Registers */
  52. #define VR4122_SIURB KSEG1ADDR(0x0f000800)
  53. #define VR4122_SIUIRSEL KSEG1ADDR(0x0f000808)
  54.  #define USE_RS232C 0x00
  55.  #define USE_IRDA 0x01
  56.  #define SIU_USES_IRDA 0x00
  57.  #define FIR_USES_IRDA 0x02
  58.  #define IRDA_MODULE_SHARP 0x00
  59.  #define IRDA_MODULE_TEMIC 0x04
  60.  #define IRDA_MODULE_HP 0x08
  61.  #define TMICTX 0x10
  62.  #define TMICMODE 0x20
  63. #define SIU_BASE_BAUD 1152000
  64. #define SIU_CLOCK 0x0102
  65. #define SIU_IRQ 17
  66. /* VR4122 and VR4131 DSIU Registers */
  67. #define DSIURB KSEG1ADDR(0x0f000820)
  68. #define MDSIUINTREG KSEG1ADDR(0x0f000096)
  69.  #define INTDSIU 0x0800
  70. #define DSIU_BASE_BAUD 1152000
  71. #define DSIU_CLOCK 0x0802
  72. #define DSIU_IRQ 29
  73. int vr41xx_serial_ports = 0;
  74. void vr41xx_siu_ifselect(int interface, int module)
  75. {
  76. u16 val = USE_RS232C; /* Select RS-232C */
  77. /* Select IrDA */
  78. if (interface == SIU_IRDA) {
  79. switch (module) {
  80. case IRDA_SHARP:
  81. val = IRDA_MODULE_SHARP;
  82. break;
  83. case IRDA_TEMIC:
  84. val = IRDA_MODULE_TEMIC;
  85. break;
  86. case IRDA_HP:
  87. val = IRDA_MODULE_HP;
  88. break;
  89. }
  90. val |= USE_IRDA | SIU_USES_IRDA;
  91. }
  92. switch (mips_cpu.cputype) {
  93. case CPU_VR4111:
  94. case CPU_VR4121:
  95. writew(val, VR4111_SIUIRSEL);
  96. break;
  97. case CPU_VR4122:
  98. case CPU_VR4131:
  99. writew(val, VR4122_SIUIRSEL);
  100. break;
  101. default:
  102. printk(KERN_INFO "Unexpected CPU of NEC VR4100 seriesn");
  103. break;
  104. }
  105. }
  106. void __init vr41xx_siu_init(int interface, int module)
  107. {
  108. struct serial_struct s;
  109. vr41xx_siu_ifselect(interface, module);
  110. memset(&s, 0, sizeof(s));
  111. s.line = vr41xx_serial_ports;
  112. s.baud_base = SIU_BASE_BAUD;
  113. s.irq = SIU_IRQ;
  114. s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  115. switch (mips_cpu.cputype) {
  116. case CPU_VR4111:
  117. case CPU_VR4121:
  118. s.iomem_base = (unsigned char *)VR4111_SIURB;
  119. break;
  120. case CPU_VR4122:
  121. case CPU_VR4131:
  122. s.iomem_base = (unsigned char *)VR4122_SIURB;
  123. break;
  124. default:
  125. panic("Unexpected CPU of NEC VR4100 series");
  126. break;
  127. }
  128. s.iomem_reg_shift = 0;
  129. s.io_type = SERIAL_IO_MEM;
  130. if (early_serial_setup(&s) != 0)
  131. printk(KERN_ERR "SIU setup failed!n");
  132. vr41xx_clock_supply(SIU_CLOCK);
  133. vr41xx_serial_ports++;
  134. }
  135. void __init vr41xx_dsiu_init(void)
  136. {
  137. struct serial_struct s;
  138. if (mips_cpu.cputype != CPU_VR4122 && mips_cpu.cputype != CPU_VR4131)
  139. return;
  140. memset(&s, 0, sizeof(s));
  141. s.line = vr41xx_serial_ports;
  142. s.baud_base = DSIU_BASE_BAUD;
  143. s.irq = DSIU_IRQ;
  144. s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  145. s.iomem_base = (unsigned char *)DSIURB;
  146. s.iomem_reg_shift = 0;
  147. s.io_type = SERIAL_IO_MEM;
  148. if (early_serial_setup(&s) != 0)
  149. printk(KERN_ERR "DSIU setup failed!n");
  150. vr41xx_clock_supply(DSIU_CLOCK);
  151. writew(INTDSIU, MDSIUINTREG);
  152. vr41xx_serial_ports++;
  153. }