mainbus.c revision 1.2
11.2Smacallan/*	$NetBSD: mainbus.c,v 1.2 2014/12/06 14:30:11 macallan Exp $ */
21.1Smacallan
31.1Smacallan/*-
41.1Smacallan * Copyright (c) 2014 Michael Lorenz
51.1Smacallan * All rights reserved.
61.1Smacallan *
71.1Smacallan * Redistribution and use in source and binary forms, with or without
81.1Smacallan * modification, are permitted provided that the following conditions
91.1Smacallan * are met:
101.1Smacallan * 1. Redistributions of source code must retain the above copyright
111.1Smacallan *    notice, this list of conditions and the following disclaimer.
121.1Smacallan * 2. Redistributions in binary form must reproduce the above copyright
131.1Smacallan *    notice, this list of conditions and the following disclaimer in the
141.1Smacallan *    documentation and/or other materials provided with the distribution.
151.1Smacallan *
161.1Smacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Smacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Smacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Smacallan * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Smacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Smacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Smacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Smacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Smacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Smacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Smacallan * POSSIBILITY OF SUCH DAMAGE.
271.1Smacallan */
281.1Smacallan
291.1Smacallan#include <sys/cdefs.h>
301.2Smacallan__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.2 2014/12/06 14:30:11 macallan Exp $");
311.1Smacallan
321.1Smacallan#include <sys/param.h>
331.1Smacallan#include <sys/systm.h>
341.1Smacallan#include <sys/device.h>
351.1Smacallan
361.1Smacallan#include <mips/cache.h>
371.1Smacallan#include <mips/cpuregs.h>
381.1Smacallan
391.2Smacallan#include <mips/ingenic/ingenic_regs.h>
401.2Smacallan
411.1Smacallan#include "locators.h"
421.1Smacallan
431.1Smacallanstatic int	mainbus_match(device_t, cfdata_t, void *);
441.1Smacallanstatic void	mainbus_attach(device_t, device_t, void *);
451.1Smacallanstatic int	mainbus_print(void *, const char *);
461.1Smacallan
471.1SmacallanCFATTACH_DECL_NEW(mainbus, 0,
481.1Smacallan    mainbus_match, mainbus_attach, NULL, NULL);
491.1Smacallan
501.1Smacallan/* There can be only one. */
511.1Smacallanint	mainbus_found = 0;
521.1Smacallan
531.1Smacallanstruct mainbusdev {
541.1Smacallan	const char *md_name;
551.1Smacallan};
561.1Smacallan
571.1Smacallanstruct mainbusdev mainbusdevs[] = {
581.1Smacallan	{ "cpu",	},
591.1Smacallan	{ "com",	},
601.2Smacallan	{ "apbus",	},
611.1Smacallan	{ NULL,		}
621.1Smacallan};
631.1Smacallan
641.1Smacallanstatic int
651.1Smacallanmainbus_match(device_t parent, cfdata_t match, void *aux)
661.1Smacallan{
671.1Smacallan
681.1Smacallan	if (mainbus_found)
691.1Smacallan		return (0);
701.1Smacallan
711.1Smacallan	return (1);
721.1Smacallan}
731.1Smacallan
741.1Smacallanstatic void
751.1Smacallanmainbus_attach(device_t parent, device_t self, void *aux)
761.1Smacallan{
771.1Smacallan	const struct mainbusdev *md;
781.1Smacallan
791.1Smacallan	mainbus_found = 1;
801.1Smacallan	printf("\n");
811.1Smacallan
821.1Smacallan	for (md = mainbusdevs; md->md_name != NULL; md++) {
831.1Smacallan		struct mainbusdev ma = *md;
841.1Smacallan		config_found_ia(self, "mainbus", &ma, mainbus_print);
851.1Smacallan	}
861.2Smacallan
871.2Smacallan#ifdef INGENIC_DEBUG
881.2Smacallan	printf("TFR: %08x\n", readreg(JZ_TC_TFR));
891.2Smacallan	printf("TMR: %08x\n", readreg(JZ_TC_TMR));
901.2Smacallan
911.2Smacallan	/* send ourselves an IPI */
921.2Smacallan	MTC0(0x12345678, CP0_CORE_MBOX, 0);
931.2Smacallan	delay(1000);
941.2Smacallan#endif
951.1Smacallan}
961.1Smacallan
971.1Smacallanstatic int
981.1Smacallanmainbus_print(void *aux, const char *pnp)
991.1Smacallan{
1001.1Smacallan
1011.1Smacallan	return (QUIET);
1021.1Smacallan}
103