[BACK]Return to scifcons.c CVS log [TXT][DIR] Up to [local] / sys / arch / landisk / stand / boot

Annotation of sys/arch/landisk/stand/boot/scifcons.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: scifcons.c,v 1.2 2006/10/10 05:26:54 miod Exp $       */
        !             2: /*     $NetBSD: scifcons.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */
        !             3: /*     NetBSD: scif.c,v 1.38 2004/12/13 02:14:13 chs Exp */
        !             4:
        !             5: /*-
        !             6:  * Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu.  All rights reserved.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms, with or without
        !             9:  * modification, are permitted provided that the following conditions
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. The name of the author may not be used to endorse or promote products
        !            17:  *    derived from this software without specific prior written permission.
        !            18:  *
        !            19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            20:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            21:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            22:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            23:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            24:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            25:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            26:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            27:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        !            28:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            29:  */
        !            30: /*-
        !            31:  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
        !            32:  * All rights reserved.
        !            33:  *
        !            34:  * This code is derived from software contributed to The NetBSD Foundation
        !            35:  * by Charles M. Hannum.
        !            36:  *
        !            37:  * Redistribution and use in source and binary forms, with or without
        !            38:  * modification, are permitted provided that the following conditions
        !            39:  * are met:
        !            40:  * 1. Redistributions of source code must retain the above copyright
        !            41:  *    notice, this list of conditions and the following disclaimer.
        !            42:  * 2. Redistributions in binary form must reproduce the above copyright
        !            43:  *    notice, this list of conditions and the following disclaimer in the
        !            44:  *    documentation and/or other materials provided with the distribution.
        !            45:  * 3. All advertising materials mentioning features or use of this software
        !            46:  *    must display the following acknowledgement:
        !            47:  *        This product includes software developed by the NetBSD
        !            48:  *        Foundation, Inc. and its contributors.
        !            49:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            50:  *    contributors may be used to endorse or promote products derived
        !            51:  *    from this software without specific prior written permission.
        !            52:  *
        !            53:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            54:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            55:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            56:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            57:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            58:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            59:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            60:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            61:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            62:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            63:  * POSSIBILITY OF SUCH DAMAGE.
        !            64:  */
        !            65: /*
        !            66:  * Copyright (c) 1991 The Regents of the University of California.
        !            67:  * All rights reserved.
        !            68:  *
        !            69:  * Redistribution and use in source and binary forms, with or without
        !            70:  * modification, are permitted provided that the following conditions
        !            71:  * are met:
        !            72:  * 1. Redistributions of source code must retain the above copyright
        !            73:  *    notice, this list of conditions and the following disclaimer.
        !            74:  * 2. Redistributions in binary form must reproduce the above copyright
        !            75:  *    notice, this list of conditions and the following disclaimer in the
        !            76:  *    documentation and/or other materials provided with the distribution.
        !            77:  * 3. Neither the name of the University nor the names of its contributors
        !            78:  *    may be used to endorse or promote products derived from this software
        !            79:  *    without specific prior written permission.
        !            80:  *
        !            81:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            82:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            83:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            84:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            85:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            86:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            87:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            88:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            89:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            90:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            91:  * SUCH DAMAGE.
        !            92:  *
        !            93:  *     @(#)com.c       7.5 (Berkeley) 5/16/91
        !            94:  */
        !            95: /*
        !            96:  * SH internal serial driver
        !            97:  *
        !            98:  * This code is derived from both z8530tty.c and com.c
        !            99:  */
        !           100:
        !           101: #include <libsa.h>
        !           102:
        !           103: #include <arch/sh/dev/scifreg.h>
        !           104:
        !           105: #define scif_smr_read()                SHREG_SCSMR2
        !           106: #define scif_smr_write(v)      (SHREG_SCSMR2 = (v))
        !           107:
        !           108: #define scif_brr_read()                SHREG_SCBRR2
        !           109: #define scif_brr_write(v)      (SHREG_SCBRR2 = (v))
        !           110:
        !           111: #define scif_scr_read()                SHREG_SCSCR2
        !           112: #define scif_scr_write(v)      (SHREG_SCSCR2 = (v))
        !           113:
        !           114: #define scif_ftdr_write(v)     (SHREG_SCFTDR2 = (v))
        !           115:
        !           116: #define scif_ssr_read()                SHREG_SCSSR2
        !           117: #define scif_ssr_write(v)      (SHREG_SCSSR2 = (v))
        !           118:
        !           119: #define scif_frdr_read()       SHREG_SCFRDR2
        !           120:
        !           121: #define scif_fcr_read()                SHREG_SCFCR2
        !           122: #define scif_fcr_write(v)      (SHREG_SCFCR2 = (v))
        !           123:
        !           124: #define scif_fdr_read()                SHREG_SCFDR2
        !           125:
        !           126: #define scif_sptr_read()       SHREG_SCSPTR2
        !           127: #define scif_sptr_write(v)     (SHREG_SCSPTR2 = (v))
        !           128:
        !           129: #define scif_lsr_read()                SHREG_SCLSR2
        !           130: #define scif_lsr_write(v)      (SHREG_SCLSR2 = (v))
        !           131:
        !           132: #define        divrnd(n, q)    (((n)*2/(q)+1)/2)       /* divide and round off */
        !           133:
        !           134: #define        SERBUFSIZE      16
        !           135: static u_char serbuf[SERBUFSIZE];
        !           136: static int serbuf_read = 0;
        !           137: static int serbuf_write = 0;
        !           138:
        !           139: void
        !           140: scif_init(unsigned int bps)
        !           141: {
        !           142:
        !           143:        serbuf_read = 0;
        !           144:        serbuf_write = 0;
        !           145:
        !           146:        /* Initialize SCR */
        !           147:        scif_scr_write(0x00);
        !           148:
        !           149:        /* Clear FIFO */
        !           150:        scif_fcr_write(SCFCR2_TFRST | SCFCR2_RFRST);
        !           151:
        !           152:        /* Serial Mode Register */
        !           153:        scif_smr_write(0x00);   /* 8bit,NonParity,Even,1Stop */
        !           154:
        !           155:        /* Bit Rate Register */
        !           156:        scif_brr_write(divrnd(PCLOCK, 32 * bps) - 1);
        !           157:
        !           158:        delay(100);
        !           159:
        !           160:        scif_sptr_write(SCSPTR2_RTSIO);
        !           161:
        !           162:        scif_fcr_write(FIFO_RCV_TRIGGER_1 | FIFO_XMT_TRIGGER_8);
        !           163:
        !           164:        /* Send permission, Receive permission ON */
        !           165:        scif_scr_write(SCSCR2_TE | SCSCR2_RE);
        !           166:
        !           167:        /* Serial Status Register */
        !           168:        scif_ssr_write(scif_ssr_read() & SCSSR2_TDFE); /* Clear Status */
        !           169: }
        !           170:
        !           171: int
        !           172: scif_getc(void)
        !           173: {
        !           174:        unsigned char c, err_c;
        !           175:        unsigned short err_c2;
        !           176:
        !           177:        if (serbuf_read != serbuf_write) {
        !           178:                c = serbuf[serbuf_read];
        !           179:                serbuf_read = (serbuf_read + 1) % SERBUFSIZE;
        !           180:                return (c);
        !           181:        }
        !           182:
        !           183:        for (;;) {
        !           184:                /* wait for ready */
        !           185:                while ((scif_fdr_read() & SCFDR2_RECVCNT) == 0)
        !           186:                        continue;
        !           187:
        !           188:                c = scif_frdr_read();
        !           189:                err_c = scif_ssr_read();
        !           190:                scif_ssr_write(scif_ssr_read()
        !           191:                        & ~(SCSSR2_ER | SCSSR2_BRK | SCSSR2_RDF | SCSSR2_DR));
        !           192:
        !           193:                err_c2 = scif_lsr_read();
        !           194:                scif_lsr_write(scif_lsr_read() & ~SCLSR2_ORER);
        !           195:
        !           196:                if ((err_c & (SCSSR2_ER | SCSSR2_BRK | SCSSR2_FER
        !           197:                    | SCSSR2_PER)) == 0) {
        !           198:                        if ((err_c2 & SCLSR2_ORER) == 0) {
        !           199:                                return (c);
        !           200:                        }
        !           201:                }
        !           202:        }
        !           203: }
        !           204:
        !           205: void
        !           206: scif_putc(int c)
        !           207: {
        !           208:
        !           209:        /* wait for ready */
        !           210:        while ((scif_fdr_read() & SCFDR2_TXCNT) == SCFDR2_TXF_FULL)
        !           211:                continue;
        !           212:
        !           213:        /* write send data to send register */
        !           214:        scif_ftdr_write(c);
        !           215:
        !           216:        /* clear ready flag */
        !           217:        scif_ssr_write(scif_ssr_read() & ~(SCSSR2_TDFE | SCSSR2_TEND));
        !           218: }
        !           219:
        !           220: int
        !           221: cnischar(void)
        !           222: {
        !           223:        unsigned char c, err_c;
        !           224:        unsigned short err_c2;
        !           225:
        !           226:        /* check if any preread input is already there */
        !           227:        if (serbuf_read != serbuf_write)
        !           228:                return (1);
        !           229:
        !           230:        if (scif_fdr_read() & SCFDR2_RECVCNT) {
        !           231:                c = scif_frdr_read();
        !           232:                err_c = scif_ssr_read();
        !           233:                scif_ssr_write(scif_ssr_read()
        !           234:                        & ~(SCSSR2_ER | SCSSR2_BRK | SCSSR2_RDF | SCSSR2_DR));
        !           235:
        !           236:                err_c2 = scif_lsr_read();
        !           237:                scif_lsr_write(scif_lsr_read() & ~SCLSR2_ORER);
        !           238:
        !           239:                if ((err_c & (SCSSR2_ER | SCSSR2_BRK | SCSSR2_FER
        !           240:                    | SCSSR2_PER)) == 0) {
        !           241:                        if ((err_c2 & SCLSR2_ORER) == 0) {
        !           242:                                /* stuff char into preread buffer */
        !           243:                                serbuf[serbuf_write] = (u_char)c;
        !           244:                                serbuf_write = (serbuf_write + 1) % SERBUFSIZE;
        !           245:                                return (1);
        !           246:                        }
        !           247:                }
        !           248:        }
        !           249:        return (0);     /* nothing out there... */
        !           250: }

CVSweb