示例#1
0
static void
uart_pps_init(struct uart_softc *sc)
{
	struct sysctl_ctx_list *ctx;
	struct sysctl_oid *tree;

	ctx = device_get_sysctl_ctx(sc->sc_dev);
	tree = device_get_sysctl_tree(sc->sc_dev);

	/*
	 * The historical default for pps capture mode is either DCD or CTS,
	 * depending on the UART_PPS_ON_CTS kernel option.  Start with that,
	 * then try to fetch the tunable that overrides the mode for all uart
	 * devices, then try to fetch the sysctl-tunable that overrides the mode
	 * for one specific device.
	 */
#ifdef UART_PPS_ON_CTS
	sc->sc_pps_mode = UART_PPS_CTS;
#else
	sc->sc_pps_mode = UART_PPS_DCD;
#endif
	TUNABLE_INT_FETCH("hw.uart.pps_mode", &sc->sc_pps_mode);
	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "pps_mode",
	    CTLTYPE_INT | CTLFLAG_RWTUN, sc, 0, uart_pps_mode_sysctl, "I",
	    "pulse mode: 0/1/2=disabled/CTS/DCD; "
	    "add 0x10 to invert, 0x20 for narrow pulse");

	if (!uart_pps_mode_valid(sc->sc_pps_mode)) {
		device_printf(sc->sc_dev, 
		    "Invalid pps_mode 0x%02x configured; disabling PPS capture\n",
		    sc->sc_pps_mode);
		sc->sc_pps_mode = UART_PPS_DISABLED;
	} else if (bootverbose) {
		uart_pps_print_mode(sc);
	}

	sc->sc_pps.ppscap = PPS_CAPTUREBOTH;
	sc->sc_pps.driver_mtx = uart_tty_getlock(sc);
	sc->sc_pps.driver_abi = PPS_ABI_VERSION;
	pps_init_abi(&sc->sc_pps);
}
示例#2
0
static int
ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc)
{
	struct tty *tp;
	char buf[32];			/* temporary TTY device name buffer */

	tp = tty_alloc_mutex(&ucom_class, sc, sc->sc_mtx);
	if (tp == NULL)
		return (ENOMEM);

	/* Check if the client has a custom TTY name */
	buf[0] = '\0';
	if (sc->sc_callback->ucom_tty_name) {
		sc->sc_callback->ucom_tty_name(sc, buf,
		    sizeof(buf), ssc->sc_unit, sc->sc_subunit);
	}
	if (buf[0] == 0) {
		/* Use default TTY name */
		if (ssc->sc_subunits > 1) {
			/* multiple modems in one */
			snprintf(buf, sizeof(buf), UCOM_TTY_PREFIX "%u.%u",
			    ssc->sc_unit, sc->sc_subunit);
		} else {
			/* single modem */
			snprintf(buf, sizeof(buf), UCOM_TTY_PREFIX "%u",
			    ssc->sc_unit);
		}
	}
	tty_makedev(tp, NULL, "%s", buf);

	sc->sc_tty = tp;

	sc->sc_pps.ppscap = PPS_CAPTUREBOTH;
	sc->sc_pps.driver_abi = PPS_ABI_VERSION;
	sc->sc_pps.driver_mtx = sc->sc_mtx;
	pps_init_abi(&sc->sc_pps);

	DPRINTF("ttycreate: %s\n", buf);

	/* Check if this device should be a console */
	if ((ucom_cons_softc == NULL) && 
	    (ssc->sc_unit == ucom_cons_unit) &&
	    (sc->sc_subunit == ucom_cons_subunit)) {

		DPRINTF("unit %d subunit %d is console",
		    ssc->sc_unit, sc->sc_subunit);

		ucom_cons_softc = sc;

		tty_init_console(tp, ucom_cons_baud);

		UCOM_MTX_LOCK(ucom_cons_softc);
		ucom_cons_rx_low = 0;
		ucom_cons_rx_high = 0;
		ucom_cons_tx_low = 0;
		ucom_cons_tx_high = 0;
		sc->sc_flag |= UCOM_FLAG_CONSOLE;
		ucom_open(ucom_cons_softc->sc_tty);
		ucom_param(ucom_cons_softc->sc_tty, &tp->t_termios_init_in);
		UCOM_MTX_UNLOCK(ucom_cons_softc);
	}

	return (0);
}