Home | History | Annotate | Line # | Download | only in broadcom
bcm2835_com.c revision 1.1
      1 /* $NetBSD: bcm2835_com.c,v 1.1 2017/07/30 23:48:32 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: bcm2835_com.c,v 1.1 2017/07/30 23:48:32 jmcneill Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/bus.h>
     34 #include <sys/device.h>
     35 #include <sys/intr.h>
     36 #include <sys/systm.h>
     37 #include <sys/termios.h>
     38 
     39 #include <arm/broadcom/bcm_amba.h>
     40 #include <arm/broadcom/bcm2835reg.h>
     41 #include <arm/broadcom/bcm2835var.h>
     42 #include <arm/broadcom/bcm2835_intr.h>
     43 
     44 #include <dev/ic/comvar.h>
     45 
     46 static int	bcm_com_match(device_t, cfdata_t, void *);
     47 static void	bcm_com_attach(device_t, device_t, void *);
     48 
     49 CFATTACH_DECL_NEW(bcmcom, sizeof(struct com_softc),
     50 	bcm_com_match, bcm_com_attach, NULL, NULL);
     51 
     52 static int
     53 bcm_com_match(device_t parent, cfdata_t cf, void *aux)
     54 {
     55 	struct amba_attach_args *aaa = aux;
     56 
     57 	return strcmp(aaa->aaa_name, "com") == 0;
     58 }
     59 
     60 static void
     61 bcm_com_attach(device_t parent, device_t self, void *aux)
     62 {
     63 	struct com_softc * const sc = device_private(self);
     64 	struct amba_attach_args * const aaa = aux;
     65 	const prop_dictionary_t dict = device_properties(self);
     66 	bus_space_tag_t bst = &bcm2835_a4x_bs_tag;
     67 	bus_space_handle_t bsh;
     68 	void *ih;
     69 
     70 	sc->sc_dev = self;
     71 	sc->sc_type = COM_TYPE_NORMAL;
     72 
     73 	prop_dictionary_get_uint32(dict, "frequency", &sc->sc_frequency);
     74 	if (sc->sc_frequency == 0) {
     75 		aprint_error(": couldn't get frequency\n");
     76 		return;
     77 	}
     78 	sc->sc_frequency *= 2;
     79 
     80 	if (bus_space_map(bst, aaa->aaa_addr, aaa->aaa_size, 0, &bsh) != 0) {
     81 		aprint_error(": can't map device\n");
     82 		return;
     83 	}
     84 
     85 	COM_INIT_REGS(sc->sc_regs, bst, bsh, aaa->aaa_addr);
     86 
     87 	com_attach_subr(sc);
     88 	aprint_naive("\n");
     89 
     90 	ih = intr_establish(aaa->aaa_intr, IPL_SERIAL, IST_LEVEL, comintr, sc);
     91 	if (ih == NULL) {
     92 		aprint_error_dev(self, "failed to establish interrupt %d\n",
     93 		    aaa->aaa_intr);
     94 		return;
     95 	}
     96 	aprint_normal_dev(self, "interrupting on intr %d\n", aaa->aaa_intr);
     97 }
     98