Home | History | Annotate | Line # | Download | only in ifpga
plcom_ifpga.c revision 1.17.16.1
      1  1.17.16.1   thorpej /*      $NetBSD: plcom_ifpga.c,v 1.17.16.1 2021/08/01 22:42:07 thorpej Exp $ */
      2        1.1  rearnsha 
      3        1.1  rearnsha /*
      4        1.1  rearnsha  * Copyright (c) 2001 ARM Ltd
      5        1.1  rearnsha  * All rights reserved.
      6        1.1  rearnsha  *
      7        1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
      8        1.1  rearnsha  * modification, are permitted provided that the following conditions
      9        1.1  rearnsha  * are met:
     10        1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     11        1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     12        1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     15        1.1  rearnsha  * 3. The name of the company may not be used to endorse or promote
     16        1.1  rearnsha  *    products derived from this software without specific prior written
     17        1.1  rearnsha  *    permission.
     18        1.1  rearnsha  *
     19        1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     20        1.1  rearnsha  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     21        1.1  rearnsha  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22        1.1  rearnsha  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     23        1.1  rearnsha  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24        1.1  rearnsha  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25        1.1  rearnsha  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.1  rearnsha  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.1  rearnsha  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.1  rearnsha  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.1  rearnsha  * SUCH DAMAGE.
     30        1.1  rearnsha  */
     31        1.1  rearnsha 
     32        1.1  rearnsha /* Interface to plcom (PL010) serial driver. */
     33        1.7     lukem 
     34        1.7     lukem #include <sys/cdefs.h>
     35  1.17.16.1   thorpej __KERNEL_RCSID(0, "$NetBSD: plcom_ifpga.c,v 1.17.16.1 2021/08/01 22:42:07 thorpej Exp $");
     36        1.1  rearnsha 
     37  1.17.16.1   thorpej #include <sys/param.h>
     38        1.1  rearnsha #include <sys/types.h>
     39  1.17.16.1   thorpej 
     40  1.17.16.1   thorpej #include <sys/bus.h>
     41        1.1  rearnsha #include <sys/device.h>
     42        1.1  rearnsha #include <sys/systm.h>
     43        1.1  rearnsha #include <sys/termios.h>
     44        1.1  rearnsha 
     45        1.1  rearnsha #include <machine/intr.h>
     46        1.1  rearnsha 
     47        1.1  rearnsha #include <evbarm/dev/plcomreg.h>
     48        1.1  rearnsha #include <evbarm/dev/plcomvar.h>
     49        1.1  rearnsha 
     50        1.1  rearnsha #include <evbarm/ifpga/plcom_ifpgavar.h>
     51        1.1  rearnsha 
     52        1.1  rearnsha #include <evbarm/ifpga/ifpgareg.h>
     53        1.1  rearnsha #include <evbarm/ifpga/ifpgavar.h>
     54        1.1  rearnsha 
     55       1.13     skrll static int  plcom_ifpga_match(device_t, cfdata_t, void *);
     56       1.13     skrll static void plcom_ifpga_attach(device_t, device_t, void *);
     57        1.1  rearnsha static void plcom_ifpga_set_mcr(void *, int, u_int);
     58        1.1  rearnsha 
     59       1.13     skrll CFATTACH_DECL_NEW(plcom_ifpga, sizeof(struct plcom_ifpga_softc),
     60        1.6   thorpej     plcom_ifpga_match, plcom_ifpga_attach, NULL, NULL);
     61        1.1  rearnsha 
     62        1.1  rearnsha static int
     63       1.13     skrll plcom_ifpga_match(device_t parent, cfdata_t cf, void *aux)
     64        1.1  rearnsha {
     65        1.3   thorpej 	return 1;
     66        1.1  rearnsha }
     67        1.1  rearnsha 
     68        1.1  rearnsha static void
     69       1.13     skrll plcom_ifpga_attach(device_t parent, device_t self, void *aux)
     70        1.1  rearnsha {
     71       1.13     skrll 	struct plcom_ifpga_softc *isc = device_private(self);
     72        1.1  rearnsha 	struct plcom_softc *sc = &isc->sc_plcom;
     73        1.1  rearnsha 	struct ifpga_attach_args *ifa = aux;
     74        1.1  rearnsha 
     75        1.1  rearnsha 	isc->sc_iot = ifa->ifa_iot;
     76        1.1  rearnsha 	isc->sc_ioh = ifa->ifa_sc_ioh;
     77       1.14     skrll 
     78       1.13     skrll 	sc->sc_dev = self;
     79       1.16     skrll #if defined(INTEGRATOR_CP)
     80       1.16     skrll 	sc->sc_pi.pi_type = PLCOM_TYPE_PL011;
     81       1.16     skrll #else
     82       1.14     skrll 	sc->sc_pi.pi_type = PLCOM_TYPE_PL010;
     83       1.16     skrll #endif
     84       1.14     skrll 	sc->sc_pi.pi_iot = ifa->ifa_iot;
     85       1.14     skrll 	sc->sc_pi.pi_iobase = ifa->ifa_addr;
     86       1.14     skrll 	sc->sc_pi.pi_size = IFPGA_UART_SIZE;
     87        1.1  rearnsha 	sc->sc_frequency = IFPGA_UART_CLK;
     88        1.1  rearnsha 	sc->sc_hwflags = 0;
     89        1.1  rearnsha 	sc->sc_swflags = 0;
     90        1.1  rearnsha 	sc->sc_set_mcr = plcom_ifpga_set_mcr;
     91        1.1  rearnsha 	sc->sc_set_mcr_arg = (void *)isc;
     92        1.1  rearnsha 
     93       1.14     skrll 	if (bus_space_map(ifa->ifa_iot, ifa->ifa_addr, IFPGA_UART_SIZE, 0,
     94       1.14     skrll 	    &sc->sc_pi.pi_ioh)) {
     95       1.13     skrll 		printf("%s: unable to map device\n", device_xname(sc->sc_dev));
     96        1.1  rearnsha 		return;
     97        1.1  rearnsha 	}
     98        1.1  rearnsha 
     99       1.17  jmcneill 	aprint_naive("\n");
    100       1.17  jmcneill 	aprint_normal("\n");
    101       1.17  jmcneill 
    102        1.1  rearnsha 	plcom_attach_subr(sc);
    103       1.14     skrll 	isc->sc_ih = ifpga_intr_establish(ifa->ifa_irq, IPL_SERIAL,
    104       1.14     skrll 	    plcomintr, sc);
    105        1.1  rearnsha 	if (isc->sc_ih == NULL)
    106        1.4    provos 		panic("%s: cannot install interrupt handler",
    107       1.13     skrll 		    device_xname(sc->sc_dev));
    108        1.1  rearnsha }
    109        1.1  rearnsha 
    110        1.1  rearnsha static void plcom_ifpga_set_mcr(void *aux, int unit, u_int mcr)
    111        1.1  rearnsha {
    112       1.15     skrll 	struct plcom_ifpga_softc *isc = aux;
    113        1.1  rearnsha 	u_int set, clr;
    114        1.1  rearnsha 
    115        1.1  rearnsha 	set = clr = 0;
    116        1.1  rearnsha 
    117        1.1  rearnsha 	switch (unit) {
    118        1.1  rearnsha 	case 0:
    119       1.12     skrll 		if (mcr & PL01X_MCR_RTS)
    120        1.1  rearnsha 			set |= IFPGA_SC_CTRL_UART0RTS;
    121        1.1  rearnsha 		else
    122        1.1  rearnsha 			clr |= IFPGA_SC_CTRL_UART0RTS;
    123       1.12     skrll 		if (mcr & PL01X_MCR_DTR)
    124        1.1  rearnsha 			set |= IFPGA_SC_CTRL_UART0DTR;
    125        1.1  rearnsha 		else
    126        1.1  rearnsha 			clr |= IFPGA_SC_CTRL_UART0DTR;
    127        1.1  rearnsha 	case 1:
    128       1.12     skrll 		if (mcr & PL01X_MCR_RTS)
    129        1.1  rearnsha 			set |= IFPGA_SC_CTRL_UART1RTS;
    130        1.1  rearnsha 		else
    131        1.1  rearnsha 			clr |= IFPGA_SC_CTRL_UART1RTS;
    132       1.12     skrll 		if (mcr & PL01X_MCR_DTR)
    133        1.1  rearnsha 			set |= IFPGA_SC_CTRL_UART1DTR;
    134        1.1  rearnsha 		else
    135        1.1  rearnsha 			clr |= IFPGA_SC_CTRL_UART1DTR;
    136        1.1  rearnsha 	default:
    137        1.1  rearnsha 		return;
    138        1.1  rearnsha 	}
    139        1.1  rearnsha 
    140        1.1  rearnsha 	if (set)
    141        1.1  rearnsha 		bus_space_write_1(isc->sc_iot, isc->sc_ioh, IFPGA_SC_CTRLS,
    142        1.1  rearnsha 		    set);
    143        1.1  rearnsha 	if (clr)
    144        1.1  rearnsha 		bus_space_write_1(isc->sc_iot, isc->sc_ioh, IFPGA_SC_CTRLC,
    145        1.1  rearnsha 		    clr);
    146        1.1  rearnsha }
    147