1*cf235420Schristos /* $NetBSD: magmareg.h,v 1.20 2018/07/09 14:07:37 christos Exp $ */ 2c4df96adSplunky 3c4df96adSplunky /*- 44e62cce8Spk * Copyright (c) 1998 Iain Hibbert 54e62cce8Spk * All rights reserved. 64e62cce8Spk * 74e62cce8Spk * Redistribution and use in source and binary forms, with or without 84e62cce8Spk * modification, are permitted provided that the following conditions 94e62cce8Spk * are met: 104e62cce8Spk * 1. Redistributions of source code must retain the above copyright 114e62cce8Spk * notice, this list of conditions and the following disclaimer. 124e62cce8Spk * 2. Redistributions in binary form must reproduce the above copyright 134e62cce8Spk * notice, this list of conditions and the following disclaimer in the 144e62cce8Spk * documentation and/or other materials provided with the distribution. 154e62cce8Spk * 164e62cce8Spk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 174e62cce8Spk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 184e62cce8Spk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 194e62cce8Spk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 204e62cce8Spk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 214e62cce8Spk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 224e62cce8Spk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 234e62cce8Spk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 244e62cce8Spk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 254e62cce8Spk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 264e62cce8Spk */ 274e62cce8Spk 284e62cce8Spk #ifdef MAGMA_DEBUG 294e62cce8Spk #define dprintf(x) printf x 304e62cce8Spk #else 314e62cce8Spk #define dprintf(x) 324e62cce8Spk #endif 334e62cce8Spk 344e62cce8Spk /* The mapping of minor device number -> card and port is done as 354e62cce8Spk * follows by default: 364e62cce8Spk * 374e62cce8Spk * +---+---+---+---+---+---+---+---+ 384e62cce8Spk * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 394e62cce8Spk * +---+---+---+---+---+---+---+---+ 404e62cce8Spk * | | | | | | | | 414e62cce8Spk * | | | | +---+---+---+---> port number 424e62cce8Spk * | | | | 436ca6d5d6Schristos * | | | +-------------------> unused 444e62cce8Spk * | | | 454e62cce8Spk * | | +-----------------------> unused 464e62cce8Spk * | | 474e62cce8Spk * +---+---------------------------> card number 484e62cce8Spk * 494e62cce8Spk */ 504e62cce8Spk 514e62cce8Spk #define MAGMA_MAX_CARDS 4 524e62cce8Spk #define MAGMA_MAX_TTY 16 534e62cce8Spk #define MAGMA_MAX_BPP 2 544e62cce8Spk #define MAGMA_MAX_CD1400 4 554e62cce8Spk #define MAGMA_MAX_CD1190 2 564e62cce8Spk 576ca6d5d6Schristos #define MAGMA_CARD(x) ((TTUNIT(x) >> 6) & 0x03) 586ca6d5d6Schristos #define MAGMA_PORT(x) (TTUNIT(x) & 0x0f) 594e62cce8Spk 606ca6d5d6Schristos #define MTTY_DIALOUT(x) TTDIALOUT(x) 614e62cce8Spk 624e62cce8Spk /* 634e62cce8Spk * Supported Card Types 644e62cce8Spk */ 654e62cce8Spk struct magma_board_info { 666c51c2d3Spk const char *mb_sbusname; /* sbus_attach_args.sa_name */ 676c51c2d3Spk const char *mb_name; /* cardname to match against */ 686c51c2d3Spk const char *mb_realname; /* english card name */ 694e62cce8Spk int mb_nser; /* number of serial ports */ 704e62cce8Spk int mb_npar; /* number of parallel ports */ 714e62cce8Spk int mb_ncd1400; /* number of CD1400 chips */ 724e62cce8Spk int mb_svcackr; /* svcackr offset */ 734e62cce8Spk int mb_svcackt; /* svcackt offset */ 744e62cce8Spk int mb_svcackm; /* svcackm offset */ 754e62cce8Spk int mb_cd1400[MAGMA_MAX_CD1400];/* cd1400 chip register offsets */ 764e62cce8Spk int mb_ncd1190; /* number of CD1190 chips */ 774e62cce8Spk int mb_cd1190[MAGMA_MAX_CD1190];/* cd1190 chip register offsets */ 784e62cce8Spk }; 794e62cce8Spk 804e62cce8Spk /* 814e62cce8Spk * cd1400 chip data 824e62cce8Spk */ 834e62cce8Spk struct cd1400 { 8493124077Sperry volatile u_char *cd_reg; /* chip registers */ 854e62cce8Spk int cd_chiprev; /* chip revision */ 8629849ba3Stsutsui int cd_clock; /* clock speed in MHz */ 874e62cce8Spk int cd_parmode; /* parallel mode operation */ 884e62cce8Spk }; 894e62cce8Spk 904e62cce8Spk /* 914e62cce8Spk * cd1190 chip data 924e62cce8Spk */ 934e62cce8Spk struct cd1190 { 9493124077Sperry volatile u_char *cd_reg; /* chip registers */ 954e62cce8Spk int cd_chiprev; /* chip revision */ 964e62cce8Spk }; 974e62cce8Spk 984e62cce8Spk /* software state for each card */ 994e62cce8Spk struct magma_softc { 100cbab9cadSchs device_t ms_dev; /* required. must be first in softc */ 1014e62cce8Spk struct evcnt ms_intrcnt; /* statistics */ 1024e62cce8Spk 1034e62cce8Spk /* cd1400 chip info */ 1044e62cce8Spk int ms_ncd1400; 1054e62cce8Spk struct cd1400 ms_cd1400[MAGMA_MAX_CD1400]; 10693124077Sperry volatile u_char *ms_svcackr; /* CD1400 service acknowledge receive */ 10793124077Sperry volatile u_char *ms_svcackt; /* CD1400 service acknowledge transmit */ 10893124077Sperry volatile u_char *ms_svcackm; /* CD1400 service acknowledge modem */ 1094e62cce8Spk 1104e62cce8Spk /* cd1190 chip info */ 1114e62cce8Spk int ms_ncd1190; 1124e62cce8Spk struct cd1190 ms_cd1190[MAGMA_MAX_CD1190]; 1134e62cce8Spk 1144e62cce8Spk struct magma_board_info *ms_board; /* what am I? */ 1154e62cce8Spk 1164e62cce8Spk struct mtty_softc *ms_mtty; 1174e62cce8Spk struct mbpp_softc *ms_mbpp; 1184e62cce8Spk 1197007959dSpk /* softintr(9) cookie */ 1207007959dSpk void *ms_sicookie; 1214e62cce8Spk }; 1224e62cce8Spk 1234e62cce8Spk #define MTTY_RBUF_SIZE (2 * 512) 1244e62cce8Spk #define MTTY_RX_FIFO_THRESHOLD 6 1254e62cce8Spk #define MTTY_RX_DTR_THRESHOLD 9 1264e62cce8Spk 1274e62cce8Spk struct mtty_port { 1284e62cce8Spk struct cd1400 *mp_cd1400; /* ptr to chip */ 1294e62cce8Spk int mp_channel; /* and channel */ 1304e62cce8Spk struct tty *mp_tty; 1314e62cce8Spk 1324e62cce8Spk int mp_openflags; /* default tty flags */ 1334e62cce8Spk int mp_flags; /* port flags */ 1344e62cce8Spk int mp_carrier; /* state of carrier */ 1354e62cce8Spk 1364e62cce8Spk u_char *mp_rbuf; /* ring buffer start */ 1374e62cce8Spk u_char *mp_rend; /* ring buffer end */ 1384e62cce8Spk u_char *mp_rget; /* ring buffer read pointer */ 1394e62cce8Spk u_char *mp_rput; /* ring buffer write pointer */ 1404e62cce8Spk 1414e62cce8Spk u_char *mp_txp; /* transmit character pointer */ 1424e62cce8Spk int mp_txc; /* transmit character counter */ 1434e62cce8Spk }; 1444e62cce8Spk 1454e62cce8Spk #define MTTYF_CARRIER_CHANGED (1<<0) 1464e62cce8Spk #define MTTYF_SET_BREAK (1<<1) 1474e62cce8Spk #define MTTYF_CLR_BREAK (1<<2) 1484e62cce8Spk #define MTTYF_DONE (1<<3) 1494e62cce8Spk #define MTTYF_STOP (1<<4) 1504e62cce8Spk #define MTTYF_RING_OVERFLOW (1<<5) 1514e62cce8Spk 1524e62cce8Spk struct mtty_softc { 153cbab9cadSchs device_t ms_dev; /* device info */ 1544e62cce8Spk int ms_nports; /* tty ports */ 1554e62cce8Spk struct mtty_port ms_port[MAGMA_MAX_TTY]; 1564e62cce8Spk }; 1574e62cce8Spk 1583f6155e8Spk #define MBPP_RX_FIFO_THRESHOLD 25 1594e62cce8Spk 1604e62cce8Spk struct mbpp_port { 1614e62cce8Spk struct cd1400 *mp_cd1400; /* for LC2+1Sp card */ 1624e62cce8Spk struct cd1190 *mp_cd1190; /* all the others */ 1634e62cce8Spk 164fc96443dSthorpej struct callout mp_timeout_ch; 165fc96443dSthorpej struct callout mp_start_ch; 166fc96443dSthorpej 1674e62cce8Spk int mp_flags; 1684e62cce8Spk 1693f6155e8Spk struct mbpp_param mp_param; 1703f6155e8Spk #define mp_burst mp_param.bp_burst 1713f6155e8Spk #define mp_timeout mp_param.bp_timeout 1723f6155e8Spk #define mp_delay mp_param.bp_delay 1734e62cce8Spk 1743f6155e8Spk u_char *mp_ptr; /* pointer to I/O data */ 1753f6155e8Spk int mp_cnt; /* count of I/O chars */ 1764e62cce8Spk }; 1774e62cce8Spk 1784e62cce8Spk #define MBPPF_OPEN (1<<0) 1793f6155e8Spk #define MBPPF_TIMEOUT (1<<1) 1803f6155e8Spk #define MBPPF_UIO (1<<2) 1813f6155e8Spk #define MBPPF_DELAY (1<<3) 1823f6155e8Spk #define MBPPF_WAKEUP (1<<4) 1834e62cce8Spk 1844e62cce8Spk struct mbpp_softc { 1854e62cce8Spk int ms_nports; /* parallel ports */ 1864e62cce8Spk struct mbpp_port ms_port[MAGMA_MAX_BPP]; 1874e62cce8Spk }; 1884e62cce8Spk 1894e62cce8Spk /* internal function prototypes */ 1904e62cce8Spk 19118db93c7Sperry int cd1400_compute_baud(speed_t, int, int *, int *); 192fbae48b9Sperry __inline void cd1400_write_ccr(struct cd1400 *, u_char); 193fbae48b9Sperry __inline u_char cd1400_read_reg(struct cd1400 *, int); 194fbae48b9Sperry __inline void cd1400_write_reg(struct cd1400 *, int, u_char); 19518db93c7Sperry void cd1400_enable_transmitter(struct cd1400 *, int); 1964e62cce8Spk 1977cf29912Scegger int magma_match(device_t, cfdata_t, void *); 1987cf29912Scegger void magma_attach(device_t, device_t, void *); 19918db93c7Sperry int magma_hard(void *); 20018db93c7Sperry void magma_soft(void *); 2014e62cce8Spk 2027cf29912Scegger int mtty_match(device_t, cfdata_t, void *); 2037cf29912Scegger void mtty_attach(device_t, device_t, void *); 20418db93c7Sperry int mtty_modem_control(struct mtty_port *, int, int); 20518db93c7Sperry int mtty_param(struct tty *, struct termios *); 20618db93c7Sperry void mtty_start(struct tty *); 2074e62cce8Spk 2087cf29912Scegger int mbpp_match(device_t, cfdata_t, void *); 2097cf29912Scegger void mbpp_attach(device_t, device_t, void *); 21018db93c7Sperry void mbpp_timeout(void *); 21118db93c7Sperry void mbpp_start(void *); 21253524e44Schristos int mbpp_send(struct mbpp_port *, void *, int); 21353524e44Schristos int mbpp_recv(struct mbpp_port *, void *, int); 21418db93c7Sperry int mbpp_hztoms(int); 21518db93c7Sperry int mbpp_mstohz(int); 216