2002-08-04 18:36:36 +00:00
|
|
|
/* $OpenBSD: sab.c,v 1.7 2002/04/08 17:49:42 jason Exp $ */
|
|
|
|
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2002-08-04 18:36:36 +00:00
|
|
|
* Copyright (c) 2001 Jason L. Wright (jason@thought.net)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Jason L. Wright
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Effort sponsored in part by the Defense Advanced Research Projects
|
|
|
|
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
|
|
|
* Materiel Command, USAF, under agreement number F30602-01-2-0537.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 18:03:45 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
/*
|
|
|
|
* SAB82532 Dual UART driver
|
|
|
|
*/
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
#include "opt_comconsole.h"
|
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <sys/bus.h>
|
2002-08-04 18:36:36 +00:00
|
|
|
#include <sys/conf.h>
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <sys/cons.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/interrupt.h>
|
2004-07-10 21:09:47 +00:00
|
|
|
#include <sys/kdb.h>
|
2002-08-04 18:36:36 +00:00
|
|
|
#include <sys/kernel.h>
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <sys/ktr.h>
|
2002-09-08 04:45:16 +00:00
|
|
|
#include <sys/mutex.h>
|
2004-06-03 06:10:02 +00:00
|
|
|
#include <sys/module.h>
|
2002-08-04 18:36:36 +00:00
|
|
|
#include <sys/proc.h>
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
|
|
|
|
#include <dev/ofw/ofw_bus.h>
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <sys/rman.h>
|
2004-06-25 20:32:51 +00:00
|
|
|
#include <sys/serial.h>
|
2002-08-04 18:36:36 +00:00
|
|
|
#include <sys/syslog.h>
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <sys/tty.h>
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
#include <dev/sab/sab82532reg.h>
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
#define SAB_READ(sc, r) \
|
|
|
|
bus_space_read_1((sc)->sc_bt, (sc)->sc_bh, (r))
|
|
|
|
#define SAB_WRITE(sc, r, v) \
|
|
|
|
bus_space_write_1((sc)->sc_bt, (sc)->sc_bh, (r), (v))
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
#define SABTTY_LOCK(sc) mtx_lock_spin(&sc->sc_mtx)
|
|
|
|
#define SABTTY_UNLOCK(sc) mtx_unlock_spin(&sc->sc_mtx)
|
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
struct sabtty_softc {
|
2002-08-04 18:41:27 +00:00
|
|
|
device_t sc_dev;
|
2002-11-17 16:00:51 +00:00
|
|
|
struct sab_softc *sc_parent;
|
2002-08-04 18:36:36 +00:00
|
|
|
bus_space_tag_t sc_bt;
|
|
|
|
bus_space_handle_t sc_bh;
|
2002-08-04 18:41:27 +00:00
|
|
|
struct tty *sc_tty;
|
2003-01-05 04:07:31 +00:00
|
|
|
int sc_channel;
|
|
|
|
int sc_icnt;
|
|
|
|
uint8_t *sc_iput;
|
|
|
|
uint8_t *sc_iget;
|
|
|
|
int sc_ocnt;
|
|
|
|
uint8_t *sc_oget;
|
|
|
|
int sc_alt_break_state;
|
|
|
|
struct mtx sc_mtx;
|
|
|
|
uint8_t sc_console;
|
|
|
|
uint8_t sc_tx_done;
|
2002-08-04 18:41:27 +00:00
|
|
|
uint8_t sc_pvr_dtr;
|
|
|
|
uint8_t sc_pvr_dsr;
|
|
|
|
uint8_t sc_imr0;
|
|
|
|
uint8_t sc_imr1;
|
2003-01-05 04:07:31 +00:00
|
|
|
uint8_t sc_ibuf[CBLOCK];
|
|
|
|
uint8_t sc_obuf[CBLOCK];
|
2002-08-04 18:36:36 +00:00
|
|
|
};
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sab_softc {
|
|
|
|
device_t sc_dev;
|
|
|
|
bus_space_tag_t sc_bt;
|
|
|
|
bus_space_handle_t sc_bh;
|
|
|
|
struct sabtty_softc *sc_child[SAB_NCHAN];
|
|
|
|
void *sc_ih;
|
|
|
|
void *sc_softih;
|
|
|
|
struct resource *sc_irqres;
|
|
|
|
int sc_irqrid;
|
|
|
|
struct resource *sc_iores;
|
|
|
|
int sc_iorid;
|
2002-11-17 16:00:51 +00:00
|
|
|
uint8_t sc_ipc;
|
2002-08-04 18:36:36 +00:00
|
|
|
};
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int sab_probe(device_t dev);
|
|
|
|
static int sab_attach(device_t dev);
|
|
|
|
static int sab_detach(device_t dev);
|
|
|
|
|
|
|
|
static void sab_intr(void *vsc);
|
|
|
|
static void sab_softintr(void *vsc);
|
2002-11-17 16:00:51 +00:00
|
|
|
static void sab_shutdown(void *vsc);
|
2002-08-04 18:41:27 +00:00
|
|
|
|
|
|
|
static int sabtty_probe(device_t dev);
|
|
|
|
static int sabtty_attach(device_t dev);
|
|
|
|
static int sabtty_detach(device_t dev);
|
|
|
|
|
|
|
|
static int sabtty_intr(struct sabtty_softc *sc);
|
|
|
|
static void sabtty_softintr(struct sabtty_softc *sc);
|
2004-07-01 15:19:08 +00:00
|
|
|
static void sabttybreak(struct tty *tp, int brk);
|
2004-06-25 20:32:51 +00:00
|
|
|
static int sabttymodem(struct tty *tp, int biton, int bitoff);
|
2002-08-04 18:41:27 +00:00
|
|
|
static int sabtty_param(struct sabtty_softc *sc, struct tty *tp,
|
|
|
|
struct termios *t);
|
|
|
|
static void sabtty_cec_wait(struct sabtty_softc *sc);
|
|
|
|
static void sabtty_tec_wait(struct sabtty_softc *sc);
|
|
|
|
static void sabtty_reset(struct sabtty_softc *sc);
|
|
|
|
static void sabtty_flush(struct sabtty_softc *sc);
|
|
|
|
static int sabtty_speed(int);
|
2002-09-08 04:45:16 +00:00
|
|
|
static int sabtty_console(device_t dev, char *mode, int len);
|
2002-08-04 18:41:27 +00:00
|
|
|
|
|
|
|
static cn_probe_t sab_cnprobe;
|
|
|
|
static cn_init_t sab_cninit;
|
|
|
|
static cn_term_t sab_cnterm;
|
|
|
|
static cn_getc_t sab_cngetc;
|
|
|
|
static cn_checkc_t sab_cncheckc;
|
|
|
|
static cn_putc_t sab_cnputc;
|
|
|
|
static cn_dbctl_t sab_cndbctl;
|
|
|
|
|
|
|
|
static int sabtty_cngetc(struct sabtty_softc *sc);
|
|
|
|
static int sabtty_cncheckc(struct sabtty_softc *sc);
|
|
|
|
static void sabtty_cnputc(struct sabtty_softc *sc, int c);
|
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
static t_open_t sabttyopen;
|
2002-08-04 18:41:27 +00:00
|
|
|
|
|
|
|
static void sabttystart(struct tty *tp);
|
|
|
|
static void sabttystop(struct tty *tp, int rw);
|
|
|
|
static int sabttyparam(struct tty *tp, struct termios *t);
|
|
|
|
|
|
|
|
static device_method_t sab_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, sab_probe),
|
|
|
|
DEVMETHOD(device_attach, sab_attach),
|
|
|
|
DEVMETHOD(device_detach, sab_detach),
|
|
|
|
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
2002-08-04 18:36:36 +00:00
|
|
|
};
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static device_method_t sabtty_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, sabtty_probe),
|
|
|
|
DEVMETHOD(device_attach, sabtty_attach),
|
|
|
|
DEVMETHOD(device_detach, sabtty_detach),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t sab_driver = {
|
|
|
|
"sab",
|
|
|
|
sab_methods,
|
|
|
|
sizeof(struct sab_softc),
|
2002-08-04 18:36:36 +00:00
|
|
|
};
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static driver_t sabtty_driver = {
|
|
|
|
"sabtty",
|
|
|
|
sabtty_methods,
|
|
|
|
sizeof(struct sabtty_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t sab_devclass;
|
|
|
|
static devclass_t sabtty_devclass;
|
|
|
|
|
|
|
|
static struct sabtty_softc *sabtty_cons;
|
|
|
|
|
|
|
|
DRIVER_MODULE(sab, ebus, sab_driver, sab_devclass, 0, 0);
|
|
|
|
DRIVER_MODULE(sabtty, sab, sabtty_driver, sabtty_devclass, 0, 0);
|
|
|
|
|
|
|
|
CONS_DRIVER(sab, sab_cnprobe, sab_cninit, sab_cnterm, sab_cngetc,
|
|
|
|
sab_cncheckc, sab_cnputc, sab_cndbctl);
|
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
struct sabtty_rate {
|
|
|
|
int baud;
|
|
|
|
int n, m;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sabtty_rate sabtty_baudtable[] = {
|
|
|
|
{ 50, 35, 10 },
|
|
|
|
{ 75, 47, 9 },
|
|
|
|
{ 110, 32, 9 },
|
|
|
|
{ 134, 53, 8 },
|
|
|
|
{ 150, 47, 8 },
|
|
|
|
{ 200, 35, 8 },
|
|
|
|
{ 300, 47, 7 },
|
|
|
|
{ 600, 47, 6 },
|
|
|
|
{ 1200, 47, 5 },
|
|
|
|
{ 1800, 31, 5 },
|
|
|
|
{ 2400, 47, 4 },
|
|
|
|
{ 4800, 47, 3 },
|
|
|
|
{ 9600, 47, 2 },
|
|
|
|
{ 19200, 47, 1 },
|
|
|
|
{ 38400, 23, 1 },
|
|
|
|
{ 57600, 15, 1 },
|
|
|
|
{ 115200, 7, 1 },
|
|
|
|
{ 230400, 3, 1 },
|
|
|
|
{ 460800, 1, 1 },
|
|
|
|
{ 76800, 11, 1 },
|
|
|
|
{ 153600, 5, 1 },
|
|
|
|
{ 307200, 3, 1 },
|
|
|
|
{ 614400, 3, 0 },
|
|
|
|
{ 921600, 0, 1 },
|
|
|
|
};
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sab_probe(device_t dev)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct resource *res;
|
|
|
|
bus_space_handle_t handle;
|
|
|
|
bus_space_tag_t tag;
|
|
|
|
uint8_t r;
|
|
|
|
int rid;
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
const char *name;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
name = ofw_bus_get_name(dev);
|
|
|
|
if (strcmp(name, "se") != 0 && strcmp(name, "serial") != 0)
|
2002-08-04 18:41:27 +00:00
|
|
|
return (ENXIO);
|
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
|
2002-08-04 18:41:27 +00:00
|
|
|
RF_ACTIVE);
|
|
|
|
if (res == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
tag = rman_get_bustag(res);
|
|
|
|
handle = rman_get_bushandle(res);
|
|
|
|
r = bus_space_read_1(tag, handle, SAB_VSTR) & SAB_VSTR_VMASK;
|
2002-08-04 18:36:36 +00:00
|
|
|
switch (r) {
|
|
|
|
case SAB_VSTR_V_1:
|
2002-08-04 18:41:27 +00:00
|
|
|
device_set_desc(dev, "Siemens SAB 82532 v1");
|
2002-08-04 18:36:36 +00:00
|
|
|
break;
|
|
|
|
case SAB_VSTR_V_2:
|
2002-08-04 18:41:27 +00:00
|
|
|
device_set_desc(dev, "Siemens SAB 82532 v2");
|
2002-08-04 18:36:36 +00:00
|
|
|
break;
|
|
|
|
case SAB_VSTR_V_32:
|
2002-08-04 18:41:27 +00:00
|
|
|
device_set_desc(dev, "Siemens SAB 82532 v3.2");
|
2002-08-04 18:36:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-08-04 18:41:27 +00:00
|
|
|
device_set_desc(dev, "Siemens SAB 82532 ???");
|
2002-08-04 18:36:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-08-04 18:41:27 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sab_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct device *child[SAB_NCHAN];
|
|
|
|
struct resource *irqres;
|
|
|
|
struct resource *iores;
|
|
|
|
struct sab_softc *sc;
|
|
|
|
int irqrid;
|
|
|
|
int iorid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
iorid = 0;
|
|
|
|
irqrid = 0;
|
|
|
|
irqres = NULL;
|
|
|
|
sc = device_get_softc(dev);
|
2004-03-17 17:50:55 +00:00
|
|
|
iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &iorid,
|
2002-08-04 18:41:27 +00:00
|
|
|
RF_ACTIVE);
|
|
|
|
if (iores == NULL)
|
|
|
|
goto error;
|
2004-03-17 17:50:55 +00:00
|
|
|
irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqrid,
|
2002-08-04 18:41:27 +00:00
|
|
|
RF_ACTIVE);
|
|
|
|
if (irqres == NULL)
|
|
|
|
goto error;
|
|
|
|
if (bus_setup_intr(dev, irqres, INTR_TYPE_TTY | INTR_FAST, sab_intr,
|
|
|
|
sc, &sc->sc_ih) != 0)
|
|
|
|
goto error;
|
|
|
|
sc->sc_dev = dev;
|
|
|
|
sc->sc_irqres = irqres;
|
|
|
|
sc->sc_iores = iores;
|
|
|
|
sc->sc_iorid = iorid;
|
|
|
|
sc->sc_irqres = irqres;
|
|
|
|
sc->sc_irqrid = irqrid;
|
|
|
|
sc->sc_bt = rman_get_bustag(iores);
|
|
|
|
sc->sc_bh = rman_get_bushandle(iores);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
/* Set all pins, except DTR pins to be inputs */
|
|
|
|
SAB_WRITE(sc, SAB_PCR, ~(SAB_PVR_DTR_A | SAB_PVR_DTR_B));
|
|
|
|
/* Disable port interrupts */
|
|
|
|
SAB_WRITE(sc, SAB_PIM, 0xff);
|
|
|
|
SAB_WRITE(sc, SAB_PVR, SAB_PVR_DTR_A | SAB_PVR_DTR_B | SAB_PVR_MAGIC);
|
2002-11-17 16:00:51 +00:00
|
|
|
sc->sc_ipc = SAB_IPC_ICPL | SAB_IPC_VIS;
|
|
|
|
SAB_WRITE(sc, SAB_IPC, sc->sc_ipc);
|
|
|
|
|
|
|
|
for (i = 0; i < SAB_NCHAN; i++)
|
2003-01-27 18:39:09 +00:00
|
|
|
child[i] = device_add_child(dev, "sabtty", -1);
|
2002-11-17 16:00:51 +00:00
|
|
|
bus_generic_attach(dev);
|
|
|
|
for (i = 0; i < SAB_NCHAN; i++)
|
|
|
|
sc->sc_child[i] = device_get_softc(child[i]);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
swi_add(&tty_ithd, "tty:sab", sab_softintr, sc, SWI_TTY,
|
|
|
|
INTR_TYPE_TTY, &sc->sc_softih);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
if (sabtty_cons != NULL) {
|
2002-11-18 04:02:42 +00:00
|
|
|
DELAY(50000);
|
2002-08-04 18:41:27 +00:00
|
|
|
cninit();
|
2002-09-08 04:45:16 +00:00
|
|
|
}
|
2002-08-04 18:41:27 +00:00
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, sab_shutdown, sc,
|
|
|
|
SHUTDOWN_PRI_DEFAULT);
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (irqres != NULL)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, irqrid, irqres);
|
|
|
|
if (iores != NULL)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, iorid, iores);
|
|
|
|
return (ENXIO);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sab_detach(device_t dev)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sab_softc *sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
bus_generic_detach(dev);
|
|
|
|
if (sc->sc_iores != NULL)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_iorid,
|
|
|
|
sc->sc_iores);
|
|
|
|
return (0);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
2003-01-05 04:07:31 +00:00
|
|
|
sab_intr(void *v)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2003-01-05 04:07:31 +00:00
|
|
|
struct sab_softc *sc = v;
|
2002-08-04 18:41:27 +00:00
|
|
|
int needsoft = 0;
|
|
|
|
uint8_t gis;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
gis = SAB_READ(sc, SAB_GIS);
|
|
|
|
|
|
|
|
/* channel A */
|
2002-09-08 04:45:16 +00:00
|
|
|
if ((gis & (SAB_GIS_ISA1 | SAB_GIS_ISA0)) != 0)
|
2002-08-04 18:41:27 +00:00
|
|
|
needsoft |= sabtty_intr(sc->sc_child[0]);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
/* channel B */
|
2002-09-08 04:45:16 +00:00
|
|
|
if ((gis & (SAB_GIS_ISB1 | SAB_GIS_ISB0)) != 0)
|
2002-08-04 18:41:27 +00:00
|
|
|
needsoft |= sabtty_intr(sc->sc_child[1]);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
if (needsoft)
|
2002-08-04 18:41:27 +00:00
|
|
|
swi_sched(sc->sc_softih, 0);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
2003-01-05 04:07:31 +00:00
|
|
|
sab_softintr(void *v)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2003-01-05 04:07:31 +00:00
|
|
|
struct sab_softc *sc = v;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
sabtty_softintr(sc->sc_child[0]);
|
|
|
|
sabtty_softintr(sc->sc_child[1]);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
static void
|
2003-01-05 04:07:31 +00:00
|
|
|
sab_shutdown(void *v)
|
2002-11-17 16:00:51 +00:00
|
|
|
{
|
2003-01-05 04:07:31 +00:00
|
|
|
struct sab_softc *sc = v;
|
2002-11-17 16:00:51 +00:00
|
|
|
|
|
|
|
SAB_WRITE(sc, SAB_IPC, SAB_IPC_ICPL | SAB_IPC_VIS);
|
|
|
|
SAB_WRITE(sc, SAB_RFC, SAB_READ(sc, SAB_RFC) & ~SAB_RFC_RFDF);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabtty_probe(device_t dev)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2003-01-27 18:39:09 +00:00
|
|
|
char desc[32];
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
snprintf(desc, sizeof(desc), "ttyz%d", device_get_unit(dev));
|
2003-01-27 18:39:09 +00:00
|
|
|
device_set_desc_copy(dev, desc);
|
2002-08-04 18:36:36 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabtty_attach(device_t dev)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sabtty_softc *sc;
|
2002-09-08 04:45:16 +00:00
|
|
|
struct tty *tp;
|
|
|
|
char mode[32];
|
|
|
|
int baud;
|
|
|
|
int clen;
|
|
|
|
char parity;
|
|
|
|
int stop;
|
|
|
|
char c;
|
2002-08-04 18:41:27 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2002-09-08 04:45:16 +00:00
|
|
|
mtx_init(&sc->sc_mtx, "sabtty", NULL, MTX_SPIN);
|
2002-08-04 18:41:27 +00:00
|
|
|
sc->sc_dev = dev;
|
2002-11-17 16:00:51 +00:00
|
|
|
sc->sc_parent = device_get_softc(device_get_parent(dev));
|
|
|
|
sc->sc_bt = sc->sc_parent->sc_bt;
|
2003-01-05 04:07:31 +00:00
|
|
|
sc->sc_channel = device_get_unit(dev) & 1;
|
|
|
|
sc->sc_iput = sc->sc_iget = sc->sc_ibuf;
|
|
|
|
sc->sc_oget = sc->sc_obuf;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
switch (sc->sc_channel) {
|
2002-08-04 18:36:36 +00:00
|
|
|
case 0: /* port A */
|
|
|
|
sc->sc_pvr_dtr = SAB_PVR_DTR_A;
|
|
|
|
sc->sc_pvr_dsr = SAB_PVR_DSR_A;
|
2003-01-08 04:30:30 +00:00
|
|
|
bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh,
|
|
|
|
SAB_CHAN_A, SAB_CHANLEN, &sc->sc_bh);
|
2002-08-04 18:36:36 +00:00
|
|
|
break;
|
|
|
|
case 1: /* port B */
|
|
|
|
sc->sc_pvr_dtr = SAB_PVR_DTR_B;
|
|
|
|
sc->sc_pvr_dsr = SAB_PVR_DSR_B;
|
2003-01-08 04:30:30 +00:00
|
|
|
bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh,
|
|
|
|
SAB_CHAN_B, SAB_CHANLEN, &sc->sc_bh);
|
2002-08-04 18:36:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-08-04 18:41:27 +00:00
|
|
|
return (ENXIO);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2004-09-17 07:28:07 +00:00
|
|
|
tp = ttyalloc();
|
2004-10-12 22:33:19 +00:00
|
|
|
tp->t_sc = sc;
|
2002-09-08 04:45:16 +00:00
|
|
|
sc->sc_tty = tp;
|
|
|
|
|
|
|
|
tp->t_oproc = sabttystart;
|
|
|
|
tp->t_param = sabttyparam;
|
2004-06-25 20:32:51 +00:00
|
|
|
tp->t_modem = sabttymodem;
|
|
|
|
tp->t_break = sabttybreak;
|
2002-09-08 04:45:16 +00:00
|
|
|
tp->t_stop = sabttystop;
|
2004-10-12 22:33:19 +00:00
|
|
|
tp->t_open = sabttyopen;
|
|
|
|
|
|
|
|
ttycreate(tp, NULL, 0, 0, "z%r", device_get_unit(dev));
|
2002-09-08 04:45:16 +00:00
|
|
|
|
|
|
|
if (sabtty_console(dev, mode, sizeof(mode))) {
|
|
|
|
if (sscanf(mode, "%d,%d,%c,%d,%c", &baud, &clen, &parity,
|
|
|
|
&stop, &c) == 5) {
|
2004-10-12 22:33:19 +00:00
|
|
|
ttyconsolemode(tp, baud);
|
2002-11-18 05:56:43 +00:00
|
|
|
tp->t_cflag = CREAD | CLOCAL;
|
2002-09-08 04:45:16 +00:00
|
|
|
|
|
|
|
switch (clen) {
|
|
|
|
case 5:
|
|
|
|
tp->t_cflag |= CS5;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
tp->t_cflag |= CS6;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
tp->t_cflag |= CS7;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
default:
|
|
|
|
tp->t_cflag |= CS8;
|
|
|
|
break;
|
|
|
|
}
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
if (parity == 'e')
|
|
|
|
tp->t_cflag |= PARENB;
|
|
|
|
else if (parity == 'o')
|
|
|
|
tp->t_cflag |= PARENB | PARODD;
|
|
|
|
|
|
|
|
if (stop == 2)
|
|
|
|
tp->t_cflag |= CSTOPB;
|
|
|
|
}
|
2003-01-05 04:07:31 +00:00
|
|
|
device_printf(dev, "console %s\n", mode);
|
|
|
|
sc->sc_console = 1;
|
2002-08-04 18:41:27 +00:00
|
|
|
sabtty_cons = sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
return (0);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabtty_detach(device_t dev)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
return (bus_generic_detach(dev));
|
2002-08-04 18:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sabtty_intr(struct sabtty_softc *sc)
|
|
|
|
{
|
2003-01-05 04:07:31 +00:00
|
|
|
int clearfifo;
|
|
|
|
int needsoft;
|
|
|
|
uint8_t isr0;
|
|
|
|
uint8_t isr1;
|
|
|
|
uint8_t c;
|
|
|
|
int brk;
|
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
brk = 0;
|
|
|
|
len = 0;
|
|
|
|
clearfifo = 0;
|
|
|
|
needsoft = 0;
|
2002-09-08 04:45:16 +00:00
|
|
|
|
|
|
|
SABTTY_LOCK(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
isr0 = SAB_READ(sc, SAB_ISR0);
|
|
|
|
isr1 = SAB_READ(sc, SAB_ISR1);
|
|
|
|
|
|
|
|
if (isr0 & SAB_ISR0_RPF) {
|
|
|
|
len = 32;
|
|
|
|
clearfifo = 1;
|
|
|
|
}
|
|
|
|
if (isr0 & SAB_ISR0_TCD) {
|
|
|
|
len = (32 - 1) & SAB_READ(sc, SAB_RBCL);
|
|
|
|
clearfifo = 1;
|
|
|
|
}
|
|
|
|
if (isr0 & SAB_ISR0_TIME) {
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RFRD);
|
|
|
|
}
|
2003-01-05 04:07:31 +00:00
|
|
|
if (isr0 & SAB_ISR0_RFO)
|
2002-08-04 18:36:36 +00:00
|
|
|
clearfifo = 1;
|
|
|
|
if (len != 0) {
|
|
|
|
for (i = 0; i < len; i++) {
|
2003-01-05 04:07:31 +00:00
|
|
|
c = SAB_READ(sc, SAB_RFIFO);
|
2004-07-10 21:09:47 +00:00
|
|
|
#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
|
2003-01-05 04:07:31 +00:00
|
|
|
if (sc->sc_console != 0 && (i & 1) == 0)
|
2004-07-10 21:09:47 +00:00
|
|
|
brk = kdb_alt_break(c,
|
|
|
|
&sc->sc_alt_break_state);
|
2002-11-17 16:00:51 +00:00
|
|
|
#endif
|
2003-01-05 04:07:31 +00:00
|
|
|
*sc->sc_iput++ = c;
|
|
|
|
if (sc->sc_iput == sc->sc_ibuf + sizeof(sc->sc_ibuf))
|
|
|
|
sc->sc_iput = sc->sc_ibuf;
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
needsoft = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clearfifo) {
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RMC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isr1 & SAB_ISR1_ALLS) {
|
2003-01-05 04:07:31 +00:00
|
|
|
sc->sc_tx_done = 1;
|
2002-08-04 18:36:36 +00:00
|
|
|
sc->sc_imr1 |= SAB_IMR1_ALLS;
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
needsoft = 1;
|
|
|
|
}
|
|
|
|
|
2004-06-08 11:58:34 +00:00
|
|
|
#if defined(DDB) && defined(BREAK_TO_DEBUGGER)
|
|
|
|
if (sc->sc_console != 0 && (isr1 & SAB_ISR1_BRK) != 0) {
|
|
|
|
brk = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
if (isr1 & SAB_ISR1_XPR) {
|
2003-01-05 04:07:31 +00:00
|
|
|
if (sc->sc_ocnt > 0) {
|
|
|
|
len = min(sc->sc_ocnt, 32);
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
SAB_WRITE(sc, SAB_XFIFO + i, *sc->sc_oget++);
|
|
|
|
sc->sc_ocnt -= len;
|
2002-09-08 04:45:16 +00:00
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XF);
|
|
|
|
}
|
2003-01-05 04:07:31 +00:00
|
|
|
if (sc->sc_ocnt == 0) {
|
2002-08-04 18:36:36 +00:00
|
|
|
sc->sc_imr1 |= SAB_IMR1_XPR;
|
|
|
|
sc->sc_imr1 &= ~SAB_IMR1_ALLS;
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
SABTTY_UNLOCK(sc);
|
2002-11-17 16:00:51 +00:00
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
if (brk != 0)
|
2002-11-17 16:00:51 +00:00
|
|
|
breakpoint();
|
2004-07-10 21:09:47 +00:00
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
return (needsoft);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sabtty_softintr(struct sabtty_softc *sc)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
struct tty *tp = sc->sc_tty;
|
2003-01-05 04:07:31 +00:00
|
|
|
int data;
|
|
|
|
int stat;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0)
|
|
|
|
return;
|
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
while (sc->sc_iget != sc->sc_iput) {
|
|
|
|
data = *sc->sc_iget++;
|
|
|
|
stat = *sc->sc_iget++;
|
2002-08-04 18:36:36 +00:00
|
|
|
if (stat & SAB_RSTAT_PE)
|
|
|
|
data |= TTY_PE;
|
|
|
|
if (stat & SAB_RSTAT_FE)
|
|
|
|
data |= TTY_FE;
|
2003-01-05 04:07:31 +00:00
|
|
|
if (sc->sc_iget == sc->sc_ibuf + sizeof(sc->sc_ibuf))
|
|
|
|
sc->sc_iget = sc->sc_ibuf;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_rint(tp, data);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
if (sc->sc_tx_done != 0) {
|
|
|
|
sc->sc_tx_done = 0;
|
2002-08-04 18:36:36 +00:00
|
|
|
tp->t_state &= ~TS_BUSY;
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_start(tp);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
2004-10-12 22:33:19 +00:00
|
|
|
sabttyopen(struct tty *tp, struct cdev *dev __unused)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
struct sabtty_softc *sc;
|
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc = tp->t_sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc->sc_iput = sc->sc_iget = sc->sc_ibuf;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
SABTTY_LOCK(sc);
|
2002-08-04 18:41:27 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sabtty_reset(sc);
|
|
|
|
sc->sc_parent->sc_ipc = SAB_IPC_ICPL;
|
|
|
|
SAB_WRITE(sc->sc_parent, SAB_IPC, sc->sc_parent->sc_ipc);
|
|
|
|
sc->sc_imr0 = SAB_IMR0_PERR | SAB_IMR0_FERR | SAB_IMR0_PLLA;
|
|
|
|
SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
|
|
|
|
#if defined(DDB) && defined(BREAK_TO_DEBUGGER)
|
|
|
|
sc->sc_imr1 = SAB_IMR1_ALLS | SAB_IMR1_XDU |
|
|
|
|
SAB_IMR1_TIN | SAB_IMR1_CSC | SAB_IMR1_XMR | SAB_IMR1_XPR;
|
|
|
|
#else
|
|
|
|
sc->sc_imr1 = SAB_IMR1_BRK | SAB_IMR1_ALLS | SAB_IMR1_XDU |
|
|
|
|
SAB_IMR1_TIN | SAB_IMR1_CSC | SAB_IMR1_XMR | SAB_IMR1_XPR;
|
|
|
|
#endif
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
SAB_WRITE(sc, SAB_CCR0, SAB_READ(sc, SAB_CCR0) | SAB_CCR0_PU);
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XRES);
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
|
|
|
|
sabtty_cec_wait(sc);
|
2003-01-05 04:07:31 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sabtty_flush(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
SABTTY_UNLOCK(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-01 15:19:08 +00:00
|
|
|
static void
|
2004-06-25 20:32:51 +00:00
|
|
|
sabttybreak(struct tty *tp, int brk)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sabtty_softc *sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc = tp->t_sc;
|
2004-06-25 20:32:51 +00:00
|
|
|
if (brk)
|
2002-08-04 18:36:36 +00:00
|
|
|
SAB_WRITE(sc, SAB_DAFO,
|
|
|
|
SAB_READ(sc, SAB_DAFO) | SAB_DAFO_XBRK);
|
2004-06-25 20:32:51 +00:00
|
|
|
else
|
2002-08-04 18:36:36 +00:00
|
|
|
SAB_WRITE(sc, SAB_DAFO,
|
|
|
|
SAB_READ(sc, SAB_DAFO) & ~SAB_DAFO_XBRK);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sabttystart(struct tty *tp)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sabtty_softc *sc;
|
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc = tp->t_sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
if ((tp->t_state & TS_TBLOCK) != 0)
|
|
|
|
/* XXX clear RTS */;
|
|
|
|
else
|
|
|
|
/* XXX set RTS */;
|
|
|
|
|
|
|
|
if ((tp->t_state & (TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) != 0) {
|
|
|
|
ttwwakeup(tp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_olowat) {
|
|
|
|
if ((tp->t_state & TS_SO_OLOWAT) != 0) {
|
|
|
|
tp->t_state &= ~TS_SO_OLOWAT;
|
|
|
|
wakeup(TSA_OLOWAT(tp));
|
|
|
|
}
|
2003-11-09 09:17:26 +00:00
|
|
|
selwakeuppri(&tp->t_wsel, TTOPRI);
|
2003-01-05 04:07:31 +00:00
|
|
|
if (tp->t_outq.c_cc == 0) {
|
|
|
|
if ((tp->t_state & (TS_BUSY | TS_SO_OCOMPLETE)) ==
|
|
|
|
TS_SO_OCOMPLETE && tp->t_outq.c_cc == 0) {
|
|
|
|
tp->t_state &= ~TS_SO_OCOMPLETE;
|
|
|
|
wakeup(TSA_OCOMPLETE(tp));
|
2002-09-08 04:45:16 +00:00
|
|
|
}
|
2003-01-05 04:07:31 +00:00
|
|
|
return;
|
2002-08-04 18:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-05 04:07:31 +00:00
|
|
|
|
|
|
|
sc->sc_ocnt = q_to_b(&tp->t_outq, sc->sc_obuf, sizeof(sc->sc_obuf));
|
|
|
|
if (sc->sc_ocnt == 0)
|
|
|
|
return;
|
|
|
|
sc->sc_oget = sc->sc_obuf;
|
|
|
|
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
|
|
|
|
sc->sc_imr1 &= ~SAB_IMR1_XPR;
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
ttwwakeup(tp);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
2003-01-05 04:07:31 +00:00
|
|
|
sabttystop(struct tty *tp, int flag)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sabtty_softc *sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc = tp->t_sc;
|
2002-08-04 18:41:27 +00:00
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
if ((flag & FREAD) != 0) {
|
|
|
|
/* XXX stop reading, anything to do? */;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flag & FWRITE) != 0) {
|
|
|
|
if ((tp->t_state & TS_BUSY) != 0) {
|
|
|
|
/* XXX do what? */
|
|
|
|
if ((tp->t_state & TS_TTSTOP) == 0)
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
}
|
|
|
|
}
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabttyparam(struct tty *tp, struct termios *t)
|
|
|
|
{
|
2002-08-04 18:36:36 +00:00
|
|
|
struct sabtty_softc *sc;
|
2002-08-04 18:41:27 +00:00
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc = tp->t_sc;
|
2002-08-04 18:41:27 +00:00
|
|
|
return (sabtty_param(sc, tp, t));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-06-25 20:32:51 +00:00
|
|
|
sabttymodem(struct tty *tp, int biton, int bitoff)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2004-06-25 20:32:51 +00:00
|
|
|
struct sabtty_softc *sc;
|
2002-08-04 18:36:36 +00:00
|
|
|
u_int8_t r;
|
|
|
|
|
2004-10-12 22:33:19 +00:00
|
|
|
sc = tp->t_sc;
|
2004-06-25 20:32:51 +00:00
|
|
|
if (biton == 0 && bitoff == 0) {
|
2002-08-04 18:36:36 +00:00
|
|
|
if (SAB_READ(sc, SAB_STAR) & SAB_STAR_CTS)
|
2004-06-25 20:32:51 +00:00
|
|
|
biton |= TIOCM_CTS;
|
2002-08-04 18:36:36 +00:00
|
|
|
if ((SAB_READ(sc, SAB_VSTR) & SAB_VSTR_CD) == 0)
|
2004-06-25 20:32:51 +00:00
|
|
|
biton |= TIOCM_CD;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
r = SAB_READ(sc, SAB_PVR);
|
|
|
|
if ((r & sc->sc_pvr_dtr) == 0)
|
2004-06-25 20:32:51 +00:00
|
|
|
biton |= TIOCM_DTR;
|
2002-08-04 18:36:36 +00:00
|
|
|
if ((r & sc->sc_pvr_dsr) == 0)
|
2004-06-25 20:32:51 +00:00
|
|
|
biton |= TIOCM_DSR;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
r = SAB_READ(sc, SAB_MODE);
|
|
|
|
if ((r & (SAB_MODE_RTS|SAB_MODE_FRTS)) == SAB_MODE_RTS)
|
2004-06-25 20:32:51 +00:00
|
|
|
biton |= TIOCM_RTS;
|
|
|
|
return (biton);
|
|
|
|
}
|
|
|
|
bitoff |= biton;
|
|
|
|
if (bitoff & SER_RTS) {
|
2002-08-04 18:36:36 +00:00
|
|
|
r = SAB_READ(sc, SAB_MODE);
|
2004-06-25 20:32:51 +00:00
|
|
|
r &= ~SAB_MODE_FRTS;
|
|
|
|
if (biton & SER_RTS)
|
2002-08-04 18:36:36 +00:00
|
|
|
r |= SAB_MODE_RTS;
|
|
|
|
SAB_WRITE(sc, SAB_MODE, r);
|
2004-06-25 20:32:51 +00:00
|
|
|
}
|
|
|
|
if (bitoff & SER_DTR) {
|
2002-08-04 18:36:36 +00:00
|
|
|
r = SAB_READ(sc, SAB_PVR);
|
2004-06-25 20:32:51 +00:00
|
|
|
r &= ~sc->sc_pvr_dtr;
|
|
|
|
if (biton & SER_DTR)
|
2002-08-04 18:36:36 +00:00
|
|
|
r |= sc->sc_pvr_dtr;
|
|
|
|
SAB_WRITE(sc, SAB_PVR, r);
|
|
|
|
}
|
2004-06-25 20:32:51 +00:00
|
|
|
return (0);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-08-04 18:41:27 +00:00
|
|
|
sabtty_param(struct sabtty_softc *sc, struct tty *tp, struct termios *t)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2003-01-05 04:07:31 +00:00
|
|
|
int ospeed;
|
2002-08-04 18:36:36 +00:00
|
|
|
tcflag_t cflag;
|
|
|
|
u_int8_t dafo, r;
|
|
|
|
|
|
|
|
ospeed = sabtty_speed(t->c_ospeed);
|
|
|
|
if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
|
|
|
|
return (EINVAL);
|
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
/*
|
|
|
|
* If there were no changes, don't do anything. This avoids dropping
|
|
|
|
* input and improves performance when all we did was frob things like
|
|
|
|
* VMIN and VTIME.
|
|
|
|
*/
|
|
|
|
if (tp->t_ospeed == t->c_ospeed &&
|
|
|
|
tp->t_cflag == t->c_cflag)
|
|
|
|
return (0);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
/* hang up line if ospeed is zero, otherwise raise dtr */
|
2004-06-25 20:32:51 +00:00
|
|
|
if (t->c_ospeed != 0)
|
|
|
|
sabttymodem(tp, SER_DTR, 0);
|
|
|
|
else
|
|
|
|
sabttymodem(tp, 0, SER_DTR);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
dafo = SAB_READ(sc, SAB_DAFO);
|
|
|
|
|
|
|
|
cflag = t->c_cflag;
|
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
if (sc->sc_console != 0) {
|
2002-08-04 18:36:36 +00:00
|
|
|
cflag |= CLOCAL;
|
|
|
|
cflag &= ~HUPCL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cflag & CSTOPB)
|
|
|
|
dafo |= SAB_DAFO_STOP;
|
|
|
|
else
|
|
|
|
dafo &= ~SAB_DAFO_STOP;
|
|
|
|
|
|
|
|
dafo &= ~SAB_DAFO_CHL_CSIZE;
|
|
|
|
switch (cflag & CSIZE) {
|
|
|
|
case CS5:
|
|
|
|
dafo |= SAB_DAFO_CHL_CS5;
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
dafo |= SAB_DAFO_CHL_CS6;
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
dafo |= SAB_DAFO_CHL_CS7;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dafo |= SAB_DAFO_CHL_CS8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dafo &= ~SAB_DAFO_PARMASK;
|
|
|
|
if (cflag & PARENB) {
|
|
|
|
if (cflag & PARODD)
|
|
|
|
dafo |= SAB_DAFO_PAR_ODD;
|
|
|
|
else
|
|
|
|
dafo |= SAB_DAFO_PAR_EVEN;
|
|
|
|
} else
|
|
|
|
dafo |= SAB_DAFO_PAR_NONE;
|
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
tp->t_ispeed = 0;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = cflag;
|
|
|
|
|
|
|
|
ttsetwater(tp);
|
|
|
|
|
|
|
|
SABTTY_LOCK(sc);
|
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
if (ospeed != 0) {
|
|
|
|
SAB_WRITE(sc, SAB_BGR, ospeed & 0xff);
|
|
|
|
r = SAB_READ(sc, SAB_CCR2);
|
|
|
|
r &= ~(SAB_CCR2_BR9 | SAB_CCR2_BR8);
|
|
|
|
r |= (ospeed >> 2) & (SAB_CCR2_BR9 | SAB_CCR2_BR8);
|
|
|
|
SAB_WRITE(sc, SAB_CCR2, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = SAB_READ(sc, SAB_MODE);
|
|
|
|
r |= SAB_MODE_RAC;
|
|
|
|
if (cflag & CRTSCTS) {
|
|
|
|
r &= ~(SAB_MODE_RTS | SAB_MODE_FCTS);
|
|
|
|
r |= SAB_MODE_FRTS;
|
|
|
|
sc->sc_imr1 &= ~SAB_IMR1_CSC;
|
|
|
|
} else {
|
|
|
|
r |= SAB_MODE_RTS | SAB_MODE_FCTS;
|
|
|
|
r &= ~SAB_MODE_FRTS;
|
|
|
|
sc->sc_imr1 |= SAB_IMR1_CSC;
|
|
|
|
}
|
|
|
|
SAB_WRITE(sc, SAB_MODE, r);
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
SABTTY_UNLOCK(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sabtty_cec_wait(struct sabtty_softc *sc)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
int i = 50000;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_CEC) == 0)
|
|
|
|
return;
|
|
|
|
if (--i == 0)
|
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sabtty_tec_wait(struct sabtty_softc *sc)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
int i = 200000;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_TEC) == 0)
|
|
|
|
return;
|
|
|
|
if (--i == 0)
|
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
static void
|
2002-08-04 18:41:27 +00:00
|
|
|
sabtty_reset(struct sabtty_softc *sc)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
/* power down */
|
|
|
|
SAB_WRITE(sc, SAB_CCR0, 0);
|
|
|
|
|
|
|
|
/* set basic configuration */
|
|
|
|
SAB_WRITE(sc, SAB_CCR0,
|
|
|
|
SAB_CCR0_MCE | SAB_CCR0_SC_NRZ | SAB_CCR0_SM_ASYNC);
|
|
|
|
SAB_WRITE(sc, SAB_CCR1, SAB_CCR1_ODS | SAB_CCR1_BCR | SAB_CCR1_CM_7);
|
|
|
|
SAB_WRITE(sc, SAB_CCR2, SAB_CCR2_BDF | SAB_CCR2_SSEL | SAB_CCR2_TOE);
|
|
|
|
SAB_WRITE(sc, SAB_CCR3, 0);
|
|
|
|
SAB_WRITE(sc, SAB_CCR4, SAB_CCR4_MCK4 | SAB_CCR4_EBRG);
|
|
|
|
SAB_WRITE(sc, SAB_MODE, SAB_MODE_RTS | SAB_MODE_FCTS | SAB_MODE_RAC);
|
|
|
|
SAB_WRITE(sc, SAB_RFC,
|
|
|
|
SAB_RFC_DPS | SAB_RFC_RFDF | SAB_RFC_RFTH_32CHAR);
|
|
|
|
|
|
|
|
/* clear interrupts */
|
|
|
|
sc->sc_imr0 = sc->sc_imr1 = 0xff;
|
|
|
|
SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
SAB_READ(sc, SAB_ISR0);
|
|
|
|
SAB_READ(sc, SAB_ISR1);
|
|
|
|
}
|
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
static void
|
2002-08-04 18:41:27 +00:00
|
|
|
sabtty_flush(struct sabtty_softc *sc)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
|
2002-08-04 18:36:36 +00:00
|
|
|
/* clear rx fifo */
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RRES);
|
|
|
|
|
|
|
|
/* clear tx fifo */
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_XRES);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabtty_speed(int rate)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
int i, len, r;
|
|
|
|
|
|
|
|
if (rate == 0)
|
|
|
|
return (0);
|
|
|
|
len = sizeof(sabtty_baudtable)/sizeof(sabtty_baudtable[0]);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (rate == sabtty_baudtable[i].baud) {
|
|
|
|
r = sabtty_baudtable[i].n |
|
|
|
|
(sabtty_baudtable[i].m << 6);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sab_cnprobe(struct consdev *cn)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
struct sabtty_softc *sc = sabtty_cons;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
cn->cn_pri = CN_DEAD;
|
|
|
|
else {
|
|
|
|
cn->cn_pri = CN_REMOTE;
|
2004-10-12 22:33:19 +00:00
|
|
|
strcpy(cn->cn_name, device_get_desc(sc->sc_dev));
|
2002-08-04 18:41:27 +00:00
|
|
|
cn->cn_tp = sc->sc_tty;
|
|
|
|
}
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sab_cninit(struct consdev *cn)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sab_cnterm(struct consdev *cn)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-02-20 20:54:45 +00:00
|
|
|
sab_cngetc(struct consdev *cn)
|
2002-08-04 18:41:27 +00:00
|
|
|
{
|
|
|
|
struct sabtty_softc *sc = sabtty_cons;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return (-1);
|
|
|
|
return (sabtty_cngetc(sc));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-02-20 20:54:45 +00:00
|
|
|
sab_cncheckc(struct consdev *cn)
|
2002-08-04 18:41:27 +00:00
|
|
|
{
|
|
|
|
struct sabtty_softc *sc = sabtty_cons;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return (-1);
|
|
|
|
return (sabtty_cncheckc(sc));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-20 20:54:45 +00:00
|
|
|
sab_cnputc(struct consdev *cn, int c)
|
2002-08-04 18:41:27 +00:00
|
|
|
{
|
|
|
|
struct sabtty_softc *sc = sabtty_cons;
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
|
|
|
sabtty_cnputc(sc, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-20 20:54:45 +00:00
|
|
|
sab_cndbctl(struct consdev *cn, int c)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-08-04 18:41:27 +00:00
|
|
|
}
|
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
static void
|
|
|
|
sabtty_cnopen(struct sabtty_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
SAB_WRITE(sc, SAB_IMR0, 0xff);
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, 0xff);
|
|
|
|
SAB_WRITE(sc->sc_parent, SAB_IPC, sc->sc_parent->sc_ipc | SAB_IPC_VIS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sabtty_cnclose(struct sabtty_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
SAB_WRITE(sc, SAB_IMR0, sc->sc_imr0);
|
|
|
|
SAB_WRITE(sc, SAB_IMR1, sc->sc_imr1);
|
|
|
|
SAB_WRITE(sc->sc_parent, SAB_IPC, sc->sc_parent->sc_ipc);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabtty_cngetc(struct sabtty_softc *sc)
|
|
|
|
{
|
|
|
|
uint8_t len;
|
|
|
|
uint8_t r;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
sabtty_cnopen(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
again:
|
|
|
|
do {
|
|
|
|
r = SAB_READ(sc, SAB_STAR);
|
|
|
|
} while ((r & SAB_STAR_RFNE) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, at least one byte in RFIFO, ask for permission to access RFIFO
|
|
|
|
* (I hate this chip... hate hate hate).
|
|
|
|
*/
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RFRD);
|
|
|
|
|
|
|
|
/* Wait for RFIFO to come ready */
|
|
|
|
do {
|
|
|
|
r = SAB_READ(sc, SAB_ISR0);
|
|
|
|
} while ((r & SAB_ISR0_TCD) == 0);
|
|
|
|
|
|
|
|
len = SAB_READ(sc, SAB_RBCL) & (32 - 1);
|
|
|
|
if (len == 0)
|
|
|
|
goto again; /* Shouldn't happen... */
|
|
|
|
|
|
|
|
r = SAB_READ(sc, SAB_RFIFO);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Blow away everything left in the FIFO...
|
|
|
|
*/
|
|
|
|
sabtty_cec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_CMDR, SAB_CMDR_RMC);
|
2002-11-17 16:00:51 +00:00
|
|
|
sabtty_cnclose(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static int
|
|
|
|
sabtty_cncheckc(struct sabtty_softc *sc)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2002-11-17 16:00:51 +00:00
|
|
|
int8_t r;
|
2002-08-04 18:36:36 +00:00
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
r = -1;
|
|
|
|
sabtty_cnopen(sc);
|
2002-08-04 18:41:27 +00:00
|
|
|
if ((SAB_READ(sc, SAB_STAR) & SAB_STAR_RFNE) != 0)
|
2002-11-17 16:00:51 +00:00
|
|
|
r = sabtty_cngetc(sc);
|
|
|
|
sabtty_cnclose(sc);
|
|
|
|
return (r);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 18:41:27 +00:00
|
|
|
static void
|
|
|
|
sabtty_cnputc(struct sabtty_softc *sc, int c)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
|
|
|
|
2002-11-17 16:00:51 +00:00
|
|
|
sabtty_cnopen(sc);
|
2002-08-04 18:41:27 +00:00
|
|
|
sabtty_tec_wait(sc);
|
|
|
|
SAB_WRITE(sc, SAB_TIC, c);
|
|
|
|
sabtty_tec_wait(sc);
|
2002-11-17 16:00:51 +00:00
|
|
|
sabtty_cnclose(sc);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2002-09-08 04:45:16 +00:00
|
|
|
static int
|
|
|
|
sabtty_console(device_t dev, char *mode, int len)
|
2002-08-04 18:36:36 +00:00
|
|
|
{
|
2003-01-05 04:07:31 +00:00
|
|
|
phandle_t chosen;
|
2002-09-08 04:45:16 +00:00
|
|
|
phandle_t options;
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
phandle_t parent;
|
2003-01-05 04:07:31 +00:00
|
|
|
ihandle_t stdin;
|
|
|
|
ihandle_t stdout;
|
2002-09-08 04:45:16 +00:00
|
|
|
char output[32];
|
|
|
|
char input[32];
|
|
|
|
char name[32];
|
2004-10-12 22:33:19 +00:00
|
|
|
int unit;
|
2002-09-08 04:45:16 +00:00
|
|
|
|
2003-01-05 04:07:31 +00:00
|
|
|
chosen = OF_finddevice("/chosen");
|
2002-09-08 04:45:16 +00:00
|
|
|
options = OF_finddevice("/options");
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
parent = ofw_bus_get_node(device_get_parent(dev));
|
2003-01-05 04:07:31 +00:00
|
|
|
if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1 ||
|
|
|
|
OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1 ||
|
|
|
|
OF_getprop(options, "input-device", input, sizeof(input)) == -1 ||
|
2002-09-08 04:45:16 +00:00
|
|
|
OF_getprop(options, "output-device", output, sizeof(output)) == -1)
|
|
|
|
return (0);
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
if (parent != OF_instance_to_package(stdin) ||
|
|
|
|
parent != OF_instance_to_package(stdout))
|
2003-01-26 01:56:20 +00:00
|
|
|
return (0);
|
2004-10-12 22:33:19 +00:00
|
|
|
unit = device_get_unit(dev);
|
|
|
|
switch (unit) {
|
|
|
|
case 0: strcpy(name, "ttya"); break;
|
|
|
|
case 1: strcpy(name, "ttyb"); break;
|
|
|
|
default: strcpy(name, "ttysomething"); break;
|
|
|
|
}
|
|
|
|
if ((strcmp(input, name) == 0 && strcmp(output, name) == 0) ||
|
2003-01-26 01:56:20 +00:00
|
|
|
(strcmp(input, "keyboard") == 0 && strcmp(output, "screen") == 0 &&
|
2004-10-12 22:33:19 +00:00
|
|
|
(unit & 1) == 0)) {
|
2002-11-18 04:02:42 +00:00
|
|
|
if (mode != NULL) {
|
2004-10-12 22:33:19 +00:00
|
|
|
strcat(name, "-mode");
|
2002-11-18 04:02:42 +00:00
|
|
|
return (OF_getprop(options, name, mode, len) != -1);
|
|
|
|
} else
|
|
|
|
return (1);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|
2002-09-08 04:45:16 +00:00
|
|
|
return (0);
|
2002-08-04 18:36:36 +00:00
|
|
|
}
|