1/* $NetBSD$ */ 2 3/*- 4 * Copyright (c) 2012 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Nick Hudson 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/* Interface to plcom (PL011) serial driver. */ 33 34#include <sys/cdefs.h> 35__KERNEL_RCSID(0, "$NetBSD$"); 36 37#include <sys/types.h> 38#include <sys/device.h> 39#include <sys/systm.h> 40#include <sys/param.h> 41#include <sys/termios.h> 42#include <sys/bus.h> 43 44#include <arm/broadcom/bcm_amba.h> 45#include <arm/broadcom/bcm2835_intr.h> 46#include <arm/broadcom/bcm2835reg.h> 47 48#include <evbarm/dev/plcomreg.h> 49#include <evbarm/dev/plcomvar.h> 50 51static int bcm2835_plcom_match(device_t, cfdata_t, void *); 52static void bcm2835_plcom_attach(device_t, device_t, void *); 53 54CFATTACH_DECL_NEW(bcmplcom, sizeof(struct plcom_softc), 55 bcm2835_plcom_match, bcm2835_plcom_attach, NULL, NULL); 56 57static int 58bcm2835_plcom_match(device_t parent, cfdata_t cf, void *aux) 59{ 60 struct amba_attach_args *aaa = aux; 61 62 if (strcmp(aaa->aaa_name, "plcom") != 0) 63 return 0; 64 65 return 1; 66} 67 68static void 69bcm2835_plcom_attach(device_t parent, device_t self, void *aux) 70{ 71 struct plcom_softc *sc = device_private(self); 72 struct amba_attach_args *aaa = aux; 73 void *ih; 74 75 sc->sc_dev = self; 76 sc->sc_frequency = BCM2835_UART0_CLK; 77 sc->sc_hwflags = PLCOM_HW_TXFIFO_DISABLE; 78 sc->sc_swflags = 0; 79 sc->sc_set_mcr = NULL; 80 sc->sc_set_mcr_arg = NULL; 81 82 sc->sc_pi.pi_type = PLCOM_TYPE_PL011; 83 sc->sc_pi.pi_flags = PLC_FLAG_32BIT_ACCESS; 84 sc->sc_pi.pi_iot = aaa->aaa_iot; 85 sc->sc_pi.pi_iobase = aaa->aaa_addr; 86 87 if (bus_space_map(aaa->aaa_iot, aaa->aaa_addr, PL011COM_UART_SIZE, 0, 88 &sc->sc_pi.pi_ioh)) { 89 aprint_error_dev(sc->sc_dev, "unable to map device\n"); 90 return; 91 } 92 93 plcom_attach_subr(sc); 94 ih = bcm2835_intr_establish(aaa->aaa_intr, IPL_SERIAL, plcomintr, sc); 95 if (ih == NULL) 96 panic("%s: cannot install interrupt handler", 97 device_xname(sc->sc_dev)); 98} 99