Home | History | Annotate | Line # | Download | only in ingenic
apbus.c revision 1.2
      1  1.2  macallan /*	$NetBSD: apbus.c,v 1.2 2014/12/23 15:11:05 macallan Exp $ */
      2  1.1  macallan 
      3  1.1  macallan /*-
      4  1.1  macallan  * Copyright (c) 2014 Michael Lorenz
      5  1.1  macallan  * All rights reserved.
      6  1.1  macallan  *
      7  1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8  1.1  macallan  * modification, are permitted provided that the following conditions
      9  1.1  macallan  * are met:
     10  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15  1.1  macallan  *
     16  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  macallan  */
     28  1.1  macallan 
     29  1.1  macallan /* catch-all for on-chip peripherals */
     30  1.1  macallan 
     31  1.1  macallan #include <sys/cdefs.h>
     32  1.2  macallan __KERNEL_RCSID(0, "$NetBSD: apbus.c,v 1.2 2014/12/23 15:11:05 macallan Exp $");
     33  1.1  macallan 
     34  1.1  macallan #include "locators.h"
     35  1.1  macallan #define	_MIPS_BUS_DMA_PRIVATE
     36  1.1  macallan 
     37  1.1  macallan #include <sys/param.h>
     38  1.1  macallan #include <sys/bus.h>
     39  1.1  macallan #include <sys/device.h>
     40  1.1  macallan #include <sys/extent.h>
     41  1.1  macallan #include <sys/systm.h>
     42  1.1  macallan 
     43  1.1  macallan #include <mips/ingenic/ingenic_var.h>
     44  1.1  macallan #include <mips/ingenic/ingenic_regs.h>
     45  1.1  macallan 
     46  1.2  macallan #include "opt_ingenic.h"
     47  1.2  macallan 
     48  1.1  macallan static int apbus_match(device_t, cfdata_t, void *);
     49  1.1  macallan static void apbus_attach(device_t, device_t, void *);
     50  1.1  macallan static int apbus_print(void *, const char *);
     51  1.1  macallan static void apbus_bus_mem_init(bus_space_tag_t, void *);
     52  1.1  macallan 
     53  1.1  macallan CFATTACH_DECL_NEW(apbus, 0, apbus_match, apbus_attach, NULL, NULL);
     54  1.1  macallan 
     55  1.1  macallan static struct mips_bus_space	apbus_mbst;
     56  1.1  macallan bus_space_tag_t	apbus_memt = NULL;
     57  1.1  macallan 
     58  1.1  macallan struct mips_bus_dma_tag	apbus_dmat = {
     59  1.1  macallan 	._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER,
     60  1.1  macallan 	._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER,
     61  1.1  macallan 	._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER,
     62  1.1  macallan };
     63  1.1  macallan 
     64  1.1  macallan static const char *apbus_devs[] = {
     65  1.1  macallan 	"dwctwo",
     66  1.1  macallan 	"jzgpio",
     67  1.1  macallan 	"jzfb",
     68  1.1  macallan 	NULL
     69  1.1  macallan };
     70  1.1  macallan 
     71  1.1  macallan void
     72  1.1  macallan apbus_init(void)
     73  1.1  macallan {
     74  1.1  macallan 	static bool done = false;
     75  1.1  macallan 	if (done)
     76  1.1  macallan 		return;
     77  1.1  macallan 	done = true;
     78  1.1  macallan 
     79  1.1  macallan 	apbus_bus_mem_init(&apbus_mbst, NULL);
     80  1.1  macallan 	apbus_memt = &apbus_mbst;
     81  1.1  macallan }
     82  1.1  macallan 
     83  1.1  macallan int
     84  1.1  macallan apbus_match(device_t parent, cfdata_t match, void *aux)
     85  1.1  macallan {
     86  1.1  macallan 	struct mainbusdev {
     87  1.1  macallan 		const char *md_name;
     88  1.1  macallan 	} *aa = aux;
     89  1.1  macallan 	if (strcmp(aa->md_name, "apbus") == 0) return 1;
     90  1.1  macallan 	return 0;
     91  1.1  macallan }
     92  1.1  macallan 
     93  1.1  macallan void
     94  1.1  macallan apbus_attach(device_t parent, device_t self, void *aux)
     95  1.1  macallan {
     96  1.2  macallan 	uint32_t reg;
     97  1.1  macallan 	aprint_normal("\n");
     98  1.1  macallan 
     99  1.1  macallan 	/* should have been called early on */
    100  1.1  macallan 	apbus_init();
    101  1.1  macallan 
    102  1.2  macallan #ifdef INGENIC_DEBUG
    103  1.2  macallan 	printf("core ctrl:   %08x\n", MFC0(12, 2));
    104  1.2  macallan 	printf("core status: %08x\n", MFC0(12, 3));
    105  1.2  macallan 	printf("REIM: %08x\n", MFC0(12, 4));
    106  1.2  macallan 	printf("ID: %08x\n", MFC0(15, 1));
    107  1.2  macallan #endif
    108  1.2  macallan 
    109  1.2  macallan 	reg = readreg(JZ_CLKGR1);
    110  1.2  macallan 	reg &= ~(1 << 8);	/* OTG1 clock */
    111  1.2  macallan 	writereg(JZ_CLKGR1, reg);
    112  1.2  macallan 
    113  1.2  macallan 	reg = readreg(JZ_CLKGR0);
    114  1.2  macallan 	reg &= ~(1 << 24);	/* UHC clock */
    115  1.2  macallan 	writereg(JZ_CLKGR0, reg);
    116  1.2  macallan 
    117  1.2  macallan #ifdef INGENIC_DEBUG
    118  1.2  macallan 	printf("JZ_CLKGR0 %08x\n", readreg(JZ_CLKGR0));
    119  1.2  macallan 	printf("JZ_CLKGR1 %08x\n", readreg(JZ_CLKGR1));
    120  1.2  macallan 	printf("JZ_SPCR0  %08x\n", readreg(JZ_SPCR0));
    121  1.2  macallan 	printf("JZ_SPCR1  %08x\n", readreg(JZ_SPCR1));
    122  1.2  macallan 	printf("JZ_SRBC   %08x\n", readreg(JZ_SRBC));
    123  1.2  macallan #endif
    124  1.1  macallan 
    125  1.1  macallan 	for (const char **adv = apbus_devs; *adv != NULL; adv++) {
    126  1.1  macallan 		struct apbus_attach_args aa;
    127  1.1  macallan 		aa.aa_name = *adv;
    128  1.1  macallan 		aa.aa_addr = 0;
    129  1.1  macallan 		aa.aa_dmat = &apbus_dmat;
    130  1.1  macallan 		aa.aa_bst = apbus_memt;
    131  1.1  macallan 
    132  1.1  macallan 		(void) config_found_ia(self, "apbus", &aa, apbus_print);
    133  1.1  macallan 	}
    134  1.1  macallan }
    135  1.1  macallan 
    136  1.1  macallan int
    137  1.1  macallan apbus_print(void *aux, const char *pnp)
    138  1.1  macallan {
    139  1.1  macallan 	struct apbus_attach_args *aa = aux;
    140  1.1  macallan 
    141  1.1  macallan 	if (pnp)
    142  1.1  macallan 		aprint_normal("%s at %s", aa->aa_name, pnp);
    143  1.1  macallan 
    144  1.1  macallan 	if (aa->aa_addr)
    145  1.1  macallan 		aprint_normal(" addr 0x%" PRIxBUSADDR, aa->aa_addr);
    146  1.1  macallan 
    147  1.1  macallan 	return (UNCONF);
    148  1.1  macallan }
    149  1.1  macallan 
    150  1.1  macallan #define CHIP	   		apbus
    151  1.1  macallan #define	CHIP_MEM		/* defined */
    152  1.1  macallan #define	CHIP_W1_BUS_START(v)	0x10000000UL
    153  1.1  macallan #define CHIP_W1_BUS_END(v)	0x20000000UL
    154  1.1  macallan #define	CHIP_W1_SYS_START(v)	0x10000000UL
    155  1.1  macallan #define	CHIP_W1_SYS_END(v)	0x20000000UL
    156  1.1  macallan 
    157  1.1  macallan #include <mips/mips/bus_space_alignstride_chipdep.c>
    158