1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765 |
- #include <sys/param.h>
- #include <sys/systm.h>
- #include <sys/proc.h>
- #include <sys/device.h>
- #include <sys/file.h>
- #include <sys/ioctl.h>
- #include <sys/malloc.h>
- #include <sys/tty.h>
- #include <sys/time.h>
- #include <sys/kernel.h>
- #include <sys/syslog.h>
- #include <sys/conf.h>
- #include <sys/errno.h>
- #include <machine/autoconf.h>
- #include <machine/conf.h>
- #include <machine/bus.h>
- #include <machine/bppioctl.h>
- #include <dev/sbus/sbusvar.h>
- #include <dev/ic/cd1400reg.h>
- #include <dev/ic/cd1190reg.h>
- #include <dev/sbus/magmareg.h>
- static const struct magma_board_info supported_cards[] = {
- {
- "MAGMA_Sp", "MAGMA,4_Sp", "Magma 4 Sp", 4, 0,
- 1, 0xa000, 0xc000, 0xe000, { 0x8000, 0, 0, 0 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,8_Sp", "Magma 8 Sp", 8, 0,
- 2, 0xa000, 0xc000, 0xe000, { 0x4000, 0x6000, 0, 0 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,_8HS_Sp", "Magma Fast 8 Sp", 8, 0,
- 2, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0, 0 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,_8SP_422", "Magma 8 Sp - 422", 8, 0,
- 2, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0, 0 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,12_Sp", "Magma 12 Sp", 12, 0,
- 3, 0xa000, 0xc000, 0xe000, { 0x2000, 0x4000, 0x6000, 0 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,16_Sp", "Magma 16 Sp", 16, 0,
- 4, 0xd000, 0xe000, 0xf000, { 0x8000, 0x9000, 0xa000, 0xb000 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,16_Sp_2", "Magma 16 Sp", 16, 0,
- 4, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0xc000, 0xe000 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,16HS_Sp", "Magma Fast 16 Sp", 16, 0,
- 4, 0x2000, 0x4000, 0x6000, { 0x8000, 0xa000, 0xc000, 0xe000 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,21_Sp", "Magma LC 2+1 Sp", 2, 1,
- 1, 0xa000, 0xc000, 0xe000, { 0x8000, 0, 0, 0 },
- 0, { 0, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,21HS_Sp", "Magma 2+1 Sp", 2, 1,
- 1, 0xa000, 0xc000, 0xe000, { 0x4000, 0, 0, 0 },
- 1, { 0x6000, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,41_Sp", "Magma 4+1 Sp", 4, 1,
- 1, 0xa000, 0xc000, 0xe000, { 0x4000, 0, 0, 0 },
- 1, { 0x6000, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,82_Sp", "Magma 8+2 Sp", 8, 2,
- 2, 0xd000, 0xe000, 0xf000, { 0x8000, 0x9000, 0, 0 },
- 2, { 0xa000, 0xb000 }
- },
- {
- "MAGMA_Sp", "MAGMA,P1_Sp", "Magma P1 Sp", 0, 1,
- 0, 0, 0, 0, { 0, 0, 0, 0 },
- 1, { 0x8000, 0 }
- },
- {
- "MAGMA_Sp", "MAGMA,P2_Sp", "Magma P2 Sp", 0, 2,
- 0, 0, 0, 0, { 0, 0, 0, 0 },
- 2, { 0x4000, 0x8000 }
- },
- {
- "MAGMA 2+1HS Sp", "", "Magma 2+1HS Sp", 2, 0,
- 1, 0xa000, 0xc000, 0xe000, { 0x4000, 0, 0, 0 },
- 1, { 0x8000, 0 }
- },
- {
- NULL, NULL, NULL, 0, 0,
- 0, 0, 0, 0, { 0, 0, 0, 0 },
- 0, { 0, 0 }
- }
- };
- struct cfattach magma_ca = {
- sizeof(struct magma_softc), magma_match, magma_attach
- };
- struct cfdriver magma_cd = {
- NULL, "magma", DV_DULL
- };
- struct cfattach mtty_ca = {
- sizeof(struct mtty_softc), mtty_match, mtty_attach
- };
- struct cfdriver mtty_cd = {
- NULL, "mtty", DV_TTY
- };
- struct cfattach mbpp_ca = {
- sizeof(struct mbpp_softc), mbpp_match, mbpp_attach
- };
- struct cfdriver mbpp_cd = {
- NULL, "mbpp", DV_DULL
- };
- int
- cd1400_compute_baud(speed_t speed, int clock, int *cor, int *bpr)
- {
- int c, co, br;
- if (speed < 50 || speed > 150000)
- return (1);
- for (c = 0, co = 8 ; co <= 2048 ; co <<= 2, c++) {
- br = ((clock * 1000000) + (co * speed) / 2) / (co * speed);
- if (br < 0x100) {
- *bpr = br;
- *cor = c;
- return (0);
- }
- }
- return (1);
- }
- #define CD1400_READ_REG(cd,reg) \
- bus_space_read_1((cd)->cd_regt, (cd)->cd_regh, (reg))
- #define CD1400_WRITE_REG(cd,reg,value) \
- bus_space_write_1((cd)->cd_regt, (cd)->cd_regh, (reg), (value))
- __inline void
- cd1400_write_ccr(struct cd1400 *cd, u_char cmd)
- {
- while (CD1400_READ_REG(cd, CD1400_CCR))
- ;
- CD1400_WRITE_REG(cd, CD1400_CCR, cmd);
- }
- void
- cd1400_enable_transmitter(struct cd1400 *cd, int channel)
- {
- int s, srer;
- s = spltty();
- CD1400_WRITE_REG(cd, CD1400_CAR, channel);
- srer = CD1400_READ_REG(cd, CD1400_SRER);
- SET(srer, CD1400_SRER_TXRDY);
- CD1400_WRITE_REG(cd, CD1400_SRER, srer);
- splx(s);
- }
- int
- magma_match(struct device *parent, void *vcf, void *aux)
- {
- struct sbus_attach_args *sa = aux;
- const struct magma_board_info *card;
-
- for (card = supported_cards; ; card++) {
- if (card->mb_sbusname == NULL)
-
- return (0);
- if (strcmp(sa->sa_name, card->mb_sbusname) == 0)
- break;
- }
- return (1);
- }
- void
- magma_attach(struct device *parent, struct device *dev, void *aux)
- {
- struct sbus_attach_args *sa = aux;
- struct magma_softc *sc = (struct magma_softc *)dev;
- const struct magma_board_info *card;
- char magma_prom[40], *clockstr;
- int chip, cd_clock;
- getpropstringA(sa->sa_node, "magma_prom", magma_prom);
- for (card = supported_cards; card->mb_name != NULL; card++) {
- if (strcmp(sa->sa_name, card->mb_sbusname) != 0)
- continue;
- if (strcmp(magma_prom, card->mb_name) == 0)
- break;
- }
- if (card->mb_name == NULL) {
- printf(": %s (unsupported)\n", magma_prom);
- return;
- }
- sc->sc_bustag = sa->sa_bustag;
- clockstr = getpropstring(sa->sa_node, "clock");
- if (strlen(clockstr) == 0)
- cd_clock = 25;
- else {
- cd_clock = 0;
- while (*clockstr != '\0')
- cd_clock = cd_clock * 10 + *clockstr++ - '0';
- }
- if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
- sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size,
- 0, 0, &sc->sc_iohandle) != 0) {
- printf(": can't map registers\n");
- return;
- }
- if (sa->sa_nintr < 1) {
- printf(": can't find interrupt\n");
- return;
- }
- sc->sc_ih = bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY, 0,
- magma_hard, sc, dev->dv_xname);
- if (sc->sc_ih == NULL) {
- printf(": couldn't establish interrupt, pri %d\n",
- INTLEV(sa->sa_pri));
- bus_space_unmap(sc->sc_bustag, sc->sc_iohandle,
- sa->sa_reg[0].sbr_size);
- return;
- }
- sc->sc_sih = softintr_establish(IPL_TTY, magma_soft, sc);
- if (sc->sc_sih == NULL) {
- printf(": can't get soft intr\n");
- bus_space_unmap(sc->sc_bustag, sc->sc_iohandle,
- sa->sa_reg[0].sbr_size);
- return;
- }
- printf(": %s\n", card->mb_realname);
- sc->ms_board = card;
- sc->ms_ncd1400 = card->mb_ncd1400;
- sc->ms_ncd1190 = card->mb_ncd1190;
-
- if (bus_space_subregion(sc->sc_bustag, sc->sc_iohandle,
- card->mb_svcackr, 1, &sc->sc_svcackrh)) {
- printf(": failed to map svcackr\n");
- return;
- }
- if (bus_space_subregion(sc->sc_bustag, sc->sc_iohandle,
- card->mb_svcackt, 1, &sc->sc_svcackth)) {
- printf(": failed to map svcackt\n");
- return;
- }
- if (bus_space_subregion(sc->sc_bustag, sc->sc_iohandle,
- card->mb_svcackm, 1, &sc->sc_svcackmh)) {
- printf(": failed to map svcackm\n");
- return;
- }
-
- for (chip = 0 ; chip < card->mb_ncd1400 ; chip++) {
- struct cd1400 *cd = &sc->ms_cd1400[chip];
- cd->cd_clock = cd_clock;
- if (bus_space_subregion(sc->sc_bustag, sc->sc_iohandle,
- card->mb_cd1400[chip], CD1400_REGMAPSIZE, &cd->cd_regh)) {
- printf(": failed to map cd1400 regs\n");
- return;
- }
- cd->cd_regt = sc->sc_bustag;
-
-
- cd->cd_chiprev = CD1400_READ_REG(cd, CD1400_GFRCR);
- dprintf(("%s attach CD1400 %d addr 0x%x rev %x clock %dMHz\n",
- sc->ms_dev.dv_xname, chip, cd->cd_reg,
- cd->cd_chiprev, cd->cd_clock));
-
- CD1400_WRITE_REG(cd, CD1400_GFRCR, 0x00);
-
- cd1400_write_ccr(cd,
- CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
-
- while (CD1400_READ_REG(cd, CD1400_GFRCR) != cd->cd_chiprev)
- ;
-
- CD1400_WRITE_REG(cd, CD1400_PPR,
- ((cd->cd_clock * 1000000 / CD1400_PPR_PRESCALER + 500)
- / 1000));
-
- if (card->mb_npar && card->mb_ncd1190 == 0) {
- CD1400_WRITE_REG(cd, CD1400_GCR, CD1400_GCR_PARALLEL);
- cd->cd_parmode = 1;
- }
- }
-
- for (chip = 0 ; chip < card->mb_ncd1190 ; chip++) {
- struct cd1190 *cd = &sc->ms_cd1190[chip];
- if (bus_space_subregion(sc->sc_bustag, sc->sc_iohandle,
- card->mb_cd1190[chip], CD1190_REGMAPSIZE, &cd->cd_regh)) {
- printf(": failed to map cd1190 regs\n");
- return;
- }
- cd->cd_regt = sc->sc_bustag;
- dprintf(("%s attach CD1190 %d addr 0x%x (failed)\n",
- sc->ms_dev.dv_xname, chip, cd->cd_reg));
-
- }
-
- (void)config_found(dev, mtty_match, NULL);
- (void)config_found(dev, mbpp_match, NULL);
- }
- int
- magma_hard(void *arg)
- {
- struct magma_softc *sc = arg;
- struct cd1400 *cd;
- int chip, status = 0;
- int serviced = 0;
- int needsoftint = 0;
-
- for (chip = 0 ; chip < sc->ms_ncd1400 ; chip++)
- status |= CD1400_READ_REG(&sc->ms_cd1400[chip], CD1400_SVRR);
- if (ISSET(status, CD1400_SVRR_RXRDY)) {
-
- u_int8_t rivr = bus_space_read_1(sc->sc_bustag, sc->sc_svcackrh, 0);
- int port = rivr >> 4;
- if (rivr & (1<<3)) {
- struct mbpp_port *mbpp;
- int n_chars;
- mbpp = &sc->ms_mbpp->ms_port[port];
- cd = mbpp->mp_cd1400;
-
- n_chars = CD1400_READ_REG(cd, CD1400_RDCR);
- while (n_chars--) {
- if (mbpp->mp_cnt == 0) {
- SET(mbpp->mp_flags, MBPPF_WAKEUP);
- needsoftint = 1;
- break;
- }
- *mbpp->mp_ptr = CD1400_READ_REG(cd, CD1400_RDSR);
- mbpp->mp_ptr++;
- mbpp->mp_cnt--;
- }
- } else {
- struct mtty_port *mtty;
- u_char *ptr, n_chars, line_stat;
- mtty = &sc->ms_mtty->ms_port[port];
- cd = mtty->mp_cd1400;
- if (ISSET(rivr, CD1400_RIVR_EXCEPTION)) {
- line_stat = CD1400_READ_REG(cd, CD1400_RDSR);
- n_chars = 1;
- } else {
- line_stat = 0;
- n_chars = CD1400_READ_REG(cd, CD1400_RDCR);
- }
- ptr = mtty->mp_rput;
- while (n_chars--) {
- *ptr++ = line_stat;
- *ptr++ = CD1400_READ_REG(cd, CD1400_RDSR);
- if (ptr == mtty->mp_rend)
- ptr = mtty->mp_rbuf;
- if (ptr == mtty->mp_rget) {
- if (ptr == mtty->mp_rbuf)
- ptr = mtty->mp_rend;
- ptr -= 2;
- SET(mtty->mp_flags,
- MTTYF_RING_OVERFLOW);
- break;
- }
- }
- mtty->mp_rput = ptr;
- needsoftint = 1;
- }
- CD1400_WRITE_REG(cd, CD1400_EOSRR, 0);
- serviced = 1;
- }
- if (ISSET(status, CD1400_SVRR_MDMCH)) {
- u_int8_t mivr = bus_space_read_1(sc->sc_bustag, sc->sc_svcackmh, 0);
- int port = mivr >> 4;
- struct mtty_port *mtty;
- int carrier;
- u_char msvr;
-
- mtty = &sc->ms_mtty->ms_port[port];
- cd = mtty->mp_cd1400;
- msvr = CD1400_READ_REG(cd, CD1400_MSVR2);
- carrier = ISSET(msvr, cd->cd_parmode ? CD1400_MSVR2_DSR : CD1400_MSVR2_CD);
- if (mtty->mp_carrier != carrier) {
- SET(mtty->mp_flags, MTTYF_CARRIER_CHANGED);
- mtty->mp_carrier = carrier;
- needsoftint = 1;
- }
- CD1400_WRITE_REG(cd, CD1400_EOSRR, 0);
- serviced = 1;
- }
- if (ISSET(status, CD1400_SVRR_TXRDY)) {
-
- u_int8_t tivr = bus_space_read_1(sc->sc_bustag, sc->sc_svcackth, 0);
- int port = tivr >> 4;
- if (tivr & (1<<3)) {
- struct mbpp_port *mbpp;
- mbpp = &sc->ms_mbpp->ms_port[port];
- cd = mbpp->mp_cd1400;
- if (mbpp->mp_cnt) {
- int count = 0;
-
- while (mbpp->mp_cnt && count++ < CD1400_PAR_FIFO_SIZE) {
- CD1400_WRITE_REG(cd, CD1400_TDR, *mbpp->mp_ptr);
- mbpp->mp_ptr++;
- mbpp->mp_cnt--;
- }
- } else {
-
- CD1400_WRITE_REG(cd, CD1400_SRER, 0);
- SET(mbpp->mp_flags, MBPPF_WAKEUP);
- needsoftint = 1;
- }
- } else {
- struct mtty_port *mtty;
- struct tty *tp;
- mtty = &sc->ms_mtty->ms_port[port];
- cd = mtty->mp_cd1400;
- tp = mtty->mp_tty;
- if (!ISSET(mtty->mp_flags, MTTYF_STOP)) {
- int count = 0;
-
- if (ISSET(mtty->mp_flags, MTTYF_SET_BREAK)) {
- CD1400_WRITE_REG(cd, CD1400_TDR, 0);
- CD1400_WRITE_REG(cd, CD1400_TDR, 0x81);
-
- CLR(mtty->mp_flags, MTTYF_SET_BREAK);
- count += 2;
- }
- if (ISSET(mtty->mp_flags, MTTYF_CLR_BREAK)) {
- CD1400_WRITE_REG(cd, CD1400_TDR, 0);
- CD1400_WRITE_REG(cd, CD1400_TDR, 0x83);
- CLR(mtty->mp_flags, MTTYF_CLR_BREAK);
- count += 2;
- }
-
- while (mtty->mp_txc > 0 && count < CD1400_TX_FIFO_SIZE - 1) {
- u_char ch;
- ch = *mtty->mp_txp;
- mtty->mp_txc--;
- mtty->mp_txp++;
- if (ch == 0) {
- CD1400_WRITE_REG(cd, CD1400_TDR, ch);
- count++;
- }
- CD1400_WRITE_REG(cd, CD1400_TDR, ch);
- count++;
- }
- }
-
- if (mtty->mp_txc == 0 || ISSET(mtty->mp_flags, MTTYF_STOP)) {
- int srer;
- srer = CD1400_READ_REG(cd, CD1400_SRER);
- CLR(srer, CD1400_SRER_TXRDY);
- CD1400_WRITE_REG(cd, CD1400_SRER, srer);
- CLR(mtty->mp_flags, MTTYF_STOP);
- SET(mtty->mp_flags, MTTYF_DONE);
- needsoftint = 1;
- }
- }
- CD1400_WRITE_REG(cd, CD1400_EOSRR, 0);
- serviced = 1;
- }
-
- if (needsoftint)
- softintr_schedule(sc->sc_sih);
- return (serviced);
- }
- void
- magma_soft(void *arg)
- {
- struct magma_softc *sc = arg;
- struct mtty_softc *mtty = sc->ms_mtty;
- struct mbpp_softc *mbpp = sc->ms_mbpp;
- int port;
- int serviced = 0;
- int s, flags;
-
- if (mtty) {
- for (port = 0 ; port < mtty->ms_nports ; port++) {
- struct mtty_port *mp = &mtty->ms_port[port];
- struct tty *tp = mp->mp_tty;
- if (!ISSET(tp->t_state, TS_ISOPEN))
- continue;
-
- while (mp->mp_rget != mp->mp_rput) {
- u_char stat;
- int data;
- stat = mp->mp_rget[0];
- data = mp->mp_rget[1];
- mp->mp_rget = ((mp->mp_rget + 2) == mp->mp_rend) ? mp->mp_rbuf : (mp->mp_rget + 2);
- if (stat & (CD1400_RDSR_BREAK | CD1400_RDSR_FE))
- data |= TTY_FE;
- if (stat & CD1400_RDSR_PE)
- data |= TTY_PE;
- if (stat & CD1400_RDSR_OE)
- log(LOG_WARNING, "%s%x: fifo overflow\n", mtty->ms_dev.dv_xname, port);
- (*linesw[tp->t_line].l_rint)(data, tp);
- serviced = 1;
- }
- s = splhigh();
- flags = mp->mp_flags;
- CLR(mp->mp_flags, MTTYF_DONE | MTTYF_CARRIER_CHANGED | MTTYF_RING_OVERFLOW);
- splx(s);
- if (ISSET(flags, MTTYF_CARRIER_CHANGED)) {
- dprintf(("%s%x: cd %s\n", mtty->ms_dev.dv_xname, port, mp->mp_carrier ? "on" : "off"));
- (*linesw[tp->t_line].l_modem)(tp, mp->mp_carrier);
- serviced = 1;
- }
- if (ISSET(flags, MTTYF_RING_OVERFLOW)) {
- log(LOG_WARNING, "%s%x: ring buffer overflow\n", mtty->ms_dev.dv_xname, port);
- serviced = 1;
- }
- if (ISSET(flags, MTTYF_DONE)) {
- ndflush(&tp->t_outq, mp->mp_txp - tp->t_outq.c_cf);
- CLR(tp->t_state, TS_BUSY);
- (*linesw[tp->t_line].l_start)(tp);
- serviced = 1;
- }
- }
- }
-
- if (mbpp) {
- for (port = 0 ; port < mbpp->ms_nports ; port++) {
- struct mbpp_port *mp = &mbpp->ms_port[port];
- if (!ISSET(mp->mp_flags, MBPPF_OPEN))
- continue;
- s = splhigh();
- flags = mp->mp_flags;
- CLR(mp->mp_flags, MBPPF_WAKEUP);
- splx(s);
- if (ISSET(flags, MBPPF_WAKEUP)) {
- wakeup(mp);
- serviced = 1;
- }
- }
- }
- }
- int
- mtty_match(struct device *parent, void *vcf, void *args)
- {
- struct magma_softc *sc = (struct magma_softc *)parent;
- return (args == mtty_match && sc->ms_board->mb_nser &&
- sc->ms_mtty == NULL);
- }
- void
- mtty_attach(struct device *parent, struct device *dev, void *args)
- {
- struct magma_softc *sc = (struct magma_softc *)parent;
- struct mtty_softc *ms = (struct mtty_softc *)dev;
- int port, chip, chan;
- sc->ms_mtty = ms;
- dprintf((" addr 0x%x", ms));
- for (port = 0, chip = 0, chan = 0;
- port < sc->ms_board->mb_nser; port++) {
- struct mtty_port *mp = &ms->ms_port[port];
- struct tty *tp;
- mp->mp_cd1400 = &sc->ms_cd1400[chip];
- if (mp->mp_cd1400->cd_parmode && chan == 0) {
-
- chan = 1;
- }
- mp->mp_channel = chan;
- tp = ttymalloc(0);
- tp->t_oproc = mtty_start;
- tp->t_param = mtty_param;
- mp->mp_tty = tp;
- mp->mp_rbuf = malloc(MTTY_RBUF_SIZE, M_DEVBUF, M_NOWAIT);
- if (mp->mp_rbuf == NULL)
- break;
- mp->mp_rend = mp->mp_rbuf + MTTY_RBUF_SIZE;
- chan = (chan + 1) % CD1400_NO_OF_CHANNELS;
- if (chan == 0)
- chip++;
- }
- ms->ms_nports = port;
- printf(": %d tty%s\n", port, port == 1 ? "" : "s");
- }
- int
- mttyopen(dev_t dev, int flags, int mode, struct proc *p)
- {
- int card = MAGMA_CARD(dev);
- int port = MAGMA_PORT(dev);
- struct mtty_softc *ms;
- struct mtty_port *mp;
- struct tty *tp;
- struct cd1400 *cd;
- int s;
- if (card >= mtty_cd.cd_ndevs || (ms = mtty_cd.cd_devs[card]) == NULL
- || port >= ms->ms_nports)
- return (ENXIO);
- mp = &ms->ms_port[port];
- tp = mp->mp_tty;
- tp->t_dev = dev;
- if (!ISSET(tp->t_state, TS_ISOPEN)) {
- SET(tp->t_state, TS_WOPEN);
-
- ttychars(tp);
- tp->t_iflag = TTYDEF_IFLAG;
- tp->t_oflag = TTYDEF_OFLAG;
- tp->t_cflag = TTYDEF_CFLAG;
- if (ISSET(mp->mp_openflags, TIOCFLAG_CLOCAL))
- SET(tp->t_cflag, CLOCAL);
- if (ISSET(mp->mp_openflags, TIOCFLAG_CRTSCTS))
- SET(tp->t_cflag, CRTSCTS);
- if (ISSET(mp->mp_openflags, TIOCFLAG_MDMBUF))
- SET(tp->t_cflag, MDMBUF);
- tp->t_lflag = TTYDEF_LFLAG;
- tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
-
- mp->mp_rput = mp->mp_rget = mp->mp_rbuf;
- s = spltty();
-
- cd = mp->mp_cd1400;
- CD1400_WRITE_REG(cd, CD1400_CAR, mp->mp_channel);
- cd1400_write_ccr(cd, CD1400_CCR_CMDRESET);
-
- CD1400_WRITE_REG(cd, CD1400_LIVR, port << 4);
-
- (void)mtty_param(tp, &tp->t_termios);
-
- ttsetwater(tp);
-
- CD1400_WRITE_REG(cd, CD1400_SRER, CD1400_SRER_RXDATA | CD1400_SRER_MDMCH);
-
- if (ISSET(mp->mp_openflags, TIOCFLAG_SOFTCAR) || mp->mp_carrier)
- SET(tp->t_state, TS_CARR_ON);
- else
- CLR(tp->t_state, TS_CARR_ON);
- } else if (ISSET(tp->t_state, TS_XCLUDE) && suser(p, 0) != 0) {
- return (EBUSY);
- } else {
- s = spltty();
- }
-
- if (!ISSET(flags, O_NONBLOCK)) {
- while (!ISSET(tp->t_cflag, CLOCAL) && !ISSET(tp->t_state, TS_CARR_ON)) {
- int error;
- SET(tp->t_state, TS_WOPEN);
- error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH, "mttydcd", 0);
- if (error != 0) {
- splx(s);
- CLR(tp->t_state, TS_WOPEN);
- return (error);
- }
- }
- }
- splx(s);
- return ((*linesw[tp->t_line].l_open)(dev, tp, p));
- }
- int
- mttyclose(dev_t dev, int flag, int mode, struct proc *p)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- struct tty *tp = mp->mp_tty;
- int s;
- (*linesw[tp->t_line].l_close)(tp, flag, p);
- s = spltty();
-
- if (ISSET(tp->t_cflag, HUPCL) || !ISSET(tp->t_state, TS_ISOPEN)) {
-
-
- (void)mtty_modem_control(mp, 0, DMSET);
-
- }
- splx(s);
- ttyclose(tp);
- return (0);
- }
- int
- mttyread(dev_t dev, struct uio *uio, int flags)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- struct tty *tp = mp->mp_tty;
- return ((*linesw[tp->t_line].l_read)(tp, uio, flags));
- }
- int
- mttywrite(dev_t dev, struct uio *uio, int flags)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- struct tty *tp = mp->mp_tty;
- return ((*linesw[tp->t_line].l_write)(tp, uio, flags));
- }
- struct tty *
- mttytty(dev_t dev)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- return (mp->mp_tty);
- }
- int
- mttyioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- struct tty *tp = mp->mp_tty;
- int error;
- error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flags, p);
- if (error >= 0)
- return (error);
- error = ttioctl(tp, cmd, data, flags, p);
- if (error >= 0)
- return (error);
- error = 0;
- switch(cmd) {
- case TIOCSBRK:
- SET(mp->mp_flags, MTTYF_SET_BREAK);
- cd1400_enable_transmitter(mp->mp_cd1400, mp->mp_channel);
- break;
- case TIOCCBRK:
- SET(mp->mp_flags, MTTYF_CLR_BREAK);
- cd1400_enable_transmitter(mp->mp_cd1400, mp->mp_channel);
- break;
- case TIOCSDTR:
- mtty_modem_control(mp, TIOCM_DTR, DMBIS);
- break;
- case TIOCCDTR:
- mtty_modem_control(mp, TIOCM_DTR, DMBIC);
- break;
- case TIOCMSET:
- mtty_modem_control(mp, *((int *)data), DMSET);
- break;
- case TIOCMBIS:
- mtty_modem_control(mp, *((int *)data), DMBIS);
- break;
- case TIOCMBIC:
- mtty_modem_control(mp, *((int *)data), DMBIC);
- break;
- case TIOCMGET:
- *((int *)data) = mtty_modem_control(mp, 0, DMGET);
- break;
- case TIOCGFLAGS:
- *((int *)data) = mp->mp_openflags;
- break;
- case TIOCSFLAGS:
- if (suser(p, 0))
- error = EPERM;
- else
- mp->mp_openflags = *((int *)data) &
- (TIOCFLAG_SOFTCAR | TIOCFLAG_CLOCAL |
- TIOCFLAG_CRTSCTS | TIOCFLAG_MDMBUF);
- break;
- default:
- error = ENOTTY;
- }
- return (error);
- }
- int
- mttystop(struct tty *tp, int flags)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(tp->t_dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(tp->t_dev)];
- int s;
- s = spltty();
- if (ISSET(tp->t_state, TS_BUSY)) {
- if (!ISSET(tp->t_state, TS_TTSTOP))
- SET(tp->t_state, TS_FLUSH);
-
- SET(mp->mp_flags, MTTYF_STOP);
- }
- splx(s);
- return (0);
- }
- void
- mtty_start(struct tty *tp)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(tp->t_dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(tp->t_dev)];
- int s;
- s = spltty();
-
- if (!ISSET(tp->t_state, TS_TTSTOP | TS_TIMEOUT | TS_BUSY)) {
-
- ttwakeupwr(tp);
-
- if (tp->t_outq.c_cc) {
- mp->mp_txc = ndqb(&tp->t_outq, 0);
- mp->mp_txp = tp->t_outq.c_cf;
- SET(tp->t_state, TS_BUSY);
- cd1400_enable_transmitter(mp->mp_cd1400, mp->mp_channel);
- }
- }
- splx(s);
- }
- int
- mtty_modem_control(struct mtty_port *mp, int bits, int howto)
- {
- struct cd1400 *cd = mp->mp_cd1400;
- struct tty *tp = mp->mp_tty;
- int s, msvr;
- s = spltty();
- CD1400_WRITE_REG(cd, CD1400_CAR, mp->mp_channel);
- switch(howto) {
- case DMGET:
- bits = 0;
- bits |= TIOCM_LE;
- msvr = CD1400_READ_REG(cd, CD1400_MSVR1);
- if (msvr & CD1400_MSVR1_RTS)
- bits |= TIOCM_DTR;
- msvr = CD1400_READ_REG(cd, CD1400_MSVR2);
- if (msvr & CD1400_MSVR2_DTR)
- bits |= TIOCM_RTS;
- if (msvr & CD1400_MSVR2_CTS)
- bits |= TIOCM_CTS;
- if (msvr & CD1400_MSVR2_RI)
- bits |= TIOCM_RI;
- if (msvr & CD1400_MSVR2_DSR)
- bits |= (cd->cd_parmode ? TIOCM_CD : TIOCM_DSR);
- if (msvr & CD1400_MSVR2_CD)
- bits |= (cd->cd_parmode ? 0 : TIOCM_CD);
- break;
- case DMSET:
- if (!ISSET(tp->t_cflag, CRTSCTS))
- CD1400_WRITE_REG(cd, CD1400_MSVR2,
- ((bits & TIOCM_RTS) ? CD1400_MSVR2_DTR : 0));
- CD1400_WRITE_REG(cd, CD1400_MSVR1,
- ((bits & TIOCM_DTR) ? CD1400_MSVR1_RTS : 0));
- break;
- case DMBIS:
- if ((bits & TIOCM_RTS) && !ISSET(tp->t_cflag, CRTSCTS))
- CD1400_WRITE_REG(cd, CD1400_MSVR2, CD1400_MSVR2_DTR);
- if (bits & TIOCM_DTR)
- CD1400_WRITE_REG(cd, CD1400_MSVR1, CD1400_MSVR1_RTS);
- break;
- case DMBIC:
- if ((bits & TIOCM_RTS) && !ISSET(tp->t_cflag, CRTSCTS))
- CD1400_WRITE_REG(cd, CD1400_MSVR2, 0);
- if (bits & TIOCM_DTR)
- CD1400_WRITE_REG(cd, CD1400_MSVR1, 0);
- break;
- }
- splx(s);
- return (bits);
- }
- int
- mtty_param(struct tty *tp, struct termios *t)
- {
- struct mtty_softc *ms = mtty_cd.cd_devs[MAGMA_CARD(tp->t_dev)];
- struct mtty_port *mp = &ms->ms_port[MAGMA_PORT(tp->t_dev)];
- struct cd1400 *cd = mp->mp_cd1400;
- int rbpr, tbpr, rcor, tcor;
- u_char mcor1 = 0, mcor2 = 0;
- int s, opt;
- if (t->c_ospeed &&
- cd1400_compute_baud(t->c_ospeed, cd->cd_clock, &tcor, &tbpr))
- return (EINVAL);
- if (t->c_ispeed &&
- cd1400_compute_baud(t->c_ispeed, cd->cd_clock, &rcor, &rbpr))
- return (EINVAL);
- s = spltty();
-
- (void)mtty_modem_control(mp, TIOCM_DTR,
- (t->c_ospeed == 0 ? DMBIC : DMBIS));
-
-
-
- if (t->c_ospeed) {
- CD1400_WRITE_REG(cd, CD1400_TCOR, tcor);
- CD1400_WRITE_REG(cd, CD1400_TBPR, tbpr);
- }
-
- if (t->c_ispeed) {
- CD1400_WRITE_REG(cd, CD1400_RCOR, rcor);
- CD1400_WRITE_REG(cd, CD1400_RBPR, rbpr);
- }
-
- opt = CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN | CD1400_CCR_RCVEN;
- cd1400_write_ccr(cd, opt);
-
- opt = 0;
- if (ISSET(t->c_cflag, PARENB))
- opt |= (ISSET(t->c_cflag, PARODD) ? CD1400_COR1_PARODD : CD1400_COR1_PARNORMAL);
- if (!ISSET(t->c_iflag, INPCK))
- opt |= CD1400_COR1_NOINPCK;
- if (ISSET(t->c_cflag, CSTOPB))
- opt |= CD1400_COR1_STOP2;
- switch( t->c_cflag & CSIZE) {
- case CS5:
- opt |= CD1400_COR1_CS5;
- break;
- case CS6:
- opt |= CD1400_COR1_CS6;
- break;
- case CS7:
- opt |= CD1400_COR1_CS7;
- break;
- default:
- opt |= CD1400_COR1_CS8;
- break;
- }
- CD1400_WRITE_REG(cd, CD1400_COR1, opt);
-
- opt = CD1400_COR2_ETC;
- if (ISSET(t->c_cflag, CRTSCTS))
- opt |= CD1400_COR2_CCTS_OFLOW;
- CD1400_WRITE_REG(cd, CD1400_COR2, opt);
- CD1400_WRITE_REG(cd, CD1400_COR3, MTTY_RX_FIFO_THRESHOLD);
- cd1400_write_ccr(cd, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR1 | CD1400_CCR_COR2 | CD1400_CCR_COR3);
- CD1400_WRITE_REG(cd, CD1400_COR4, CD1400_COR4_PFO_EXCEPTION);
- CD1400_WRITE_REG(cd, CD1400_COR5, 0);
-
- if (ISSET(t->c_cflag, CRTSCTS))
- mcor1 = MTTY_RX_DTR_THRESHOLD;
-
- if (cd->cd_parmode) {
- SET(mcor1, CD1400_MCOR1_DSRzd);
- SET(mcor2, CD1400_MCOR2_DSRod);
- } else {
- SET(mcor1, CD1400_MCOR1_CDzd);
- SET(mcor2, CD1400_MCOR2_CDod);
- }
- CD1400_WRITE_REG(cd, CD1400_MCOR1, mcor1);
- CD1400_WRITE_REG(cd, CD1400_MCOR2, mcor2);
-
- CD1400_WRITE_REG(cd, CD1400_RTPR, 2);
- splx(s);
- return (0);
- }
- int
- mbpp_match(struct device *parent, void *vcf, void *args)
- {
- struct magma_softc *sc = (struct magma_softc *)parent;
- return (args == mbpp_match && sc->ms_board->mb_npar &&
- sc->ms_mbpp == NULL);
- }
- void
- mbpp_attach(struct device *parent, struct device *dev, void *args)
- {
- struct magma_softc *sc = (struct magma_softc *)parent;
- struct mbpp_softc *ms = (struct mbpp_softc *)dev;
- struct mbpp_port *mp;
- int port;
- sc->ms_mbpp = ms;
- dprintf((" addr 0x%x", ms));
- for (port = 0 ; port < sc->ms_board->mb_npar ; port++) {
- mp = &ms->ms_port[port];
- if (sc->ms_ncd1190)
- mp->mp_cd1190 = &sc->ms_cd1190[port];
- else
- mp->mp_cd1400 = &sc->ms_cd1400[0];
- timeout_set(&mp->mp_timeout_tmo, mbpp_timeout, mp);
- timeout_set(&mp->mp_start_tmo, mbpp_start, mp);
- }
- ms->ms_nports = port;
- printf(": %d port%s\n", port, port == 1 ? "" : "s");
- }
- int
- mbppopen(dev_t dev, int flags, int mode, struct proc *p)
- {
- int card = MAGMA_CARD(dev);
- int port = MAGMA_PORT(dev);
- struct mbpp_softc *ms;
- struct mbpp_port *mp;
- int s;
- if (card >= mbpp_cd.cd_ndevs || (ms = mbpp_cd.cd_devs[card]) == NULL || port >= ms->ms_nports)
- return (ENXIO);
- mp = &ms->ms_port[port];
- s = spltty();
- if (ISSET(mp->mp_flags, MBPPF_OPEN)) {
- splx(s);
- return (EBUSY);
- }
- SET(mp->mp_flags, MBPPF_OPEN);
- splx(s);
-
- mp->mp_burst = BPP_BURST;
- mp->mp_timeout = mbpp_mstohz(BPP_TIMEOUT);
- mp->mp_delay = mbpp_mstohz(BPP_DELAY);
-
- if (mp->mp_cd1400) {
- struct cd1400 *cd = mp->mp_cd1400;
-
- s = spltty();
- CD1400_WRITE_REG(cd, CD1400_CAR, 0);
- cd1400_write_ccr(cd, CD1400_CCR_CMDRESET);
- CD1400_WRITE_REG(cd, CD1400_LIVR, (1<<3));
- splx(s);
- } else {
- mp->mp_flags = 0;
- return (ENXIO);
- }
- return (0);
- }
- int
- mbppclose(dev_t dev, int flag, int mode, struct proc *p)
- {
- struct mbpp_softc *ms = mbpp_cd.cd_devs[MAGMA_CARD(dev)];
- struct mbpp_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- mp->mp_flags = 0;
- return (0);
- }
- int
- mbppread(dev_t dev, struct uio *uio, int flags)
- {
- return (mbpp_rw(dev, uio));
- }
- int
- mbppwrite(dev_t dev, struct uio *uio, int flags)
- {
- return (mbpp_rw(dev, uio));
- }
- int
- mbppioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
- {
- struct mbpp_softc *ms = mbpp_cd.cd_devs[MAGMA_CARD(dev)];
- struct mbpp_port *mp = &ms->ms_port[MAGMA_PORT(dev)];
- struct bpp_param *bp;
- int error = 0;
- int s;
- switch(cmd) {
- case BPPIOCSPARAM:
- bp = (struct bpp_param *)data;
- if (bp->bp_burst < BPP_BURST_MIN || bp->bp_burst > BPP_BURST_MAX ||
- bp->bp_delay < BPP_DELAY_MIN || bp->bp_delay > BPP_DELAY_MIN) {
- error = EINVAL;
- } else {
- mp->mp_burst = bp->bp_burst;
- mp->mp_timeout = mbpp_mstohz(bp->bp_timeout);
- mp->mp_delay = mbpp_mstohz(bp->bp_delay);
- }
- break;
- case BPPIOCGPARAM:
- bp = (struct bpp_param *)data;
- bp->bp_burst = mp->mp_burst;
- bp->bp_timeout = mbpp_hztoms(mp->mp_timeout);
- bp->bp_delay = mbpp_hztoms(mp->mp_delay);
- break;
- case BPPIOCGSTAT:
-
- s = spltty();
- CD1400_WRITE_REG(mp->mp_cd1400, CD1400_CAR, 0);
- *(int *)data = CD1400_READ_REG(mp->mp_cd1400, CD1400_PSVR);
- splx(s);
- break;
- default:
- error = ENOTTY;
- }
- return (error);
- }
- int
- mbpppoll(dev_t dev, int events, struct proc *p)
- {
- return (seltrue(dev, events, p));
- }
- int
- mbpp_rw(dev_t dev, struct uio *uio)
- {
- int card = MAGMA_CARD(dev);
- int port = MAGMA_PORT(dev);
- struct mbpp_softc *ms = mbpp_cd.cd_devs[card];
- struct mbpp_port *mp = &ms->ms_port[port];
- caddr_t buffer, ptr;
- int buflen, cnt, len;
- int s, error = 0;
- int gotdata = 0;
- if (uio->uio_resid == 0)
- return (0);
- buflen = min(uio->uio_resid, mp->mp_burst);
- buffer = malloc(buflen, M_DEVBUF, M_WAITOK);
- SET(mp->mp_flags, MBPPF_UIO);
-
- if (mp->mp_timeout > 0) {
- SET(mp->mp_flags, MBPPF_TIMEOUT);
- timeout_add(&mp->mp_timeout_tmo, mp->mp_timeout);
- }
- len = cnt = 0;
- while (uio->uio_resid > 0) {
- len = min(buflen, uio->uio_resid);
- ptr = buffer;
- if (uio->uio_rw == UIO_WRITE) {
- error = uiomovei(ptr, len, uio);
- if (error)
- break;
- }
- again:
-
- if (!ISSET(mp->mp_flags, MBPPF_UIO))
- break;
-
- if (uio->uio_rw == UIO_WRITE) {
- cnt = mbpp_send(mp, ptr, len);
- } else {
- cnt = mbpp_recv(mp, ptr, len);
- }
- if (uio->uio_rw == UIO_READ) {
- if (cnt) {
- error = uiomovei(ptr, cnt, uio);
- if (error)
- break;
- gotdata++;
- }
- else if (gotdata)
- break;
- }
-
- if (!ISSET(mp->mp_flags, MBPPF_UIO))
- break;
-
- if (mp->mp_delay > 0) {
- s = spltty();
- SET(mp->mp_flags, MBPPF_DELAY);
- timeout_add(&mp->mp_start_tmo, mp->mp_delay);
- error = tsleep(mp, PCATCH | PZERO, "mbppdelay", 0);
- splx(s);
- if (error)
- break;
- }
-
- if (uio->uio_rw == UIO_WRITE && cnt != len) {
- ptr += cnt;
- len -= cnt;
- cnt = 0;
- goto again;
- }
- }
-
- s = spltty();
- if (ISSET(mp->mp_flags, MBPPF_TIMEOUT)) {
- timeout_del(&mp->mp_timeout_tmo);
- CLR(mp->mp_flags, MBPPF_TIMEOUT);
- }
- if (ISSET(mp->mp_flags, MBPPF_DELAY)) {
- timeout_del(&mp->mp_start_tmo);
- CLR(mp->mp_flags, MBPPF_DELAY);
- }
- splx(s);
-
- if (uio->uio_rw == UIO_WRITE && cnt != len) {
- uio->uio_resid += (len - cnt);
- }
- free(buffer, M_DEVBUF, 0);
- return (error);
- }
- void
- mbpp_timeout(void *arg)
- {
- struct mbpp_port *mp = arg;
- CLR(mp->mp_flags, MBPPF_UIO | MBPPF_TIMEOUT);
- wakeup(mp);
- }
- void
- mbpp_start(void *arg)
- {
- struct mbpp_port *mp = arg;
- CLR(mp->mp_flags, MBPPF_DELAY);
- wakeup(mp);
- }
- int
- mbpp_send(struct mbpp_port *mp, caddr_t ptr, int len)
- {
- int s;
- struct cd1400 *cd = mp->mp_cd1400;
-
- mp->mp_ptr = ptr;
- mp->mp_cnt = len;
-
- s = spltty();
- if (cd) {
- CD1400_WRITE_REG(cd, CD1400_CAR, 0);
-
- CD1400_WRITE_REG(cd, CD1400_TBPR, 10);
-
- cd1400_write_ccr(cd, CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN);
- CD1400_WRITE_REG(cd, CD1400_SRER, CD1400_SRER_TXRDY);
- }
-
- tsleep(mp, PCATCH | PZERO, "mbpp_send", 0);
-
- if (cd) {
- CD1400_WRITE_REG(cd, CD1400_CAR, 0);
-
- CD1400_WRITE_REG(cd, CD1400_SRER, 0);
- cd1400_write_ccr(cd, CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTDIS);
-
- cd1400_write_ccr(cd, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
- }
- splx(s);
-
- return (len - mp->mp_cnt);
- }
- int
- mbpp_recv(struct mbpp_port *mp, caddr_t ptr, int len)
- {
- int s;
- struct cd1400 *cd = mp->mp_cd1400;
-
- mp->mp_ptr = ptr;
- mp->mp_cnt = len;
-
- s = spltty();
- if (cd) {
- int rcor, rbpr;
- CD1400_WRITE_REG(cd, CD1400_CAR, 0);
-
- cd1400_compute_baud(100000, cd->cd_clock, &rcor, &rbpr);
- CD1400_WRITE_REG(cd, CD1400_RCOR, rcor);
- CD1400_WRITE_REG(cd, CD1400_RBPR, rbpr);
-
- CD1400_WRITE_REG(cd, CD1400_COR3, MBPP_RX_FIFO_THRESHOLD);
- cd1400_write_ccr(cd, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
-
- cd1400_write_ccr(cd, CD1400_CCR_CMDCHANCTL | CD1400_CCR_RCVEN);
- CD1400_WRITE_REG(cd, CD1400_SRER, CD1400_SRER_RXDATA);
- }
-
- tsleep(mp, PCATCH | PZERO, "mbpp_recv", 0);
-
- if (cd) {
- CD1400_WRITE_REG(cd, CD1400_CAR, 0);
-
- CD1400_WRITE_REG(cd, CD1400_SRER, 0);
- cd1400_write_ccr(cd, CD1400_CCR_CMDCHANCTL | CD1400_CCR_RCVDIS);
- }
- splx(s);
-
- return (len - mp->mp_cnt);
- }
- int
- mbpp_hztoms(int h)
- {
- int m = h;
- if (m > 0)
- m = m * 1000 / hz;
- return (m);
- }
- int
- mbpp_mstohz(int m)
- {
- int h = m;
- if (h > 0) {
- h = h * hz / 1000;
- if (h == 0)
- h = 1000 / hz;
- }
- return (h);
- }
|