xref: /netbsd-src/sys/arch/hpcmips/dev/plum.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: plum.c,v 1.20 2021/08/07 16:18:54 thorpej Exp $ */
29a758aabSuch 
358f851eeSuch /*-
458f851eeSuch  * Copyright (c) 1999 The NetBSD Foundation, Inc.
59a758aabSuch  * All rights reserved.
69a758aabSuch  *
758f851eeSuch  * This code is derived from software contributed to The NetBSD Foundation
858f851eeSuch  * by UCHIYAMA Yasushi.
958f851eeSuch  *
109a758aabSuch  * Redistribution and use in source and binary forms, with or without
119a758aabSuch  * modification, are permitted provided that the following conditions
129a758aabSuch  * are met:
139a758aabSuch  * 1. Redistributions of source code must retain the above copyright
149a758aabSuch  *    notice, this list of conditions and the following disclaimer.
1558f851eeSuch  * 2. Redistributions in binary form must reproduce the above copyright
1658f851eeSuch  *    notice, this list of conditions and the following disclaimer in the
1758f851eeSuch  *    documentation and/or other materials provided with the distribution.
189a758aabSuch  *
1958f851eeSuch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2058f851eeSuch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2158f851eeSuch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2258f851eeSuch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2358f851eeSuch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2458f851eeSuch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2558f851eeSuch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2658f851eeSuch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2758f851eeSuch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2858f851eeSuch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2958f851eeSuch  * POSSIBILITY OF SUCH DAMAGE.
309a758aabSuch  */
319a758aabSuch 
320c82163cSlukem #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: plum.c,v 1.20 2021/08/07 16:18:54 thorpej Exp $");
340c82163cSlukem 
359a758aabSuch #include <sys/param.h>
369a758aabSuch #include <sys/systm.h>
379a758aabSuch #include <sys/device.h>
38b950ff9aSthorpej #include <sys/kmem.h>
399a758aabSuch 
409a758aabSuch #include <machine/bus.h>
419a758aabSuch #include <machine/intr.h>
429a758aabSuch 
439a758aabSuch #include <hpcmips/tx/tx39var.h>
449a758aabSuch #include <hpcmips/tx/txcsbusvar.h>
459a758aabSuch #include <hpcmips/dev/plumvar.h>
469a758aabSuch #include <hpcmips/dev/plumreg.h>
479a758aabSuch 
48cbab9cadSchs int plum_match(device_t, cfdata_t, void *);
49cbab9cadSchs void plum_attach(device_t, device_t, void *);
5058f851eeSuch int plum_print(void *, const char *);
51cbab9cadSchs int plum_search(device_t, cfdata_t, const int *, void *);
529a758aabSuch 
539a758aabSuch struct plum_softc {
549a758aabSuch 	plum_chipset_tag_t	sc_pc;
559a758aabSuch 	bus_space_tag_t		sc_csregt;
569a758aabSuch 	bus_space_tag_t		sc_csiot;
579a758aabSuch 	bus_space_tag_t		sc_csmemt;
589a758aabSuch 	int			sc_irq;
599a758aabSuch 	int			sc_pri;
609a758aabSuch };
619a758aabSuch 
62cbab9cadSchs CFATTACH_DECL_NEW(plum, sizeof(struct plum_softc),
63c5e91d44Sthorpej     plum_match, plum_attach, NULL, NULL);
649a758aabSuch 
6558f851eeSuch plumreg_t plum_idcheck(bus_space_tag_t);
669a758aabSuch 
679a758aabSuch int
plum_match(device_t parent,cfdata_t cf,void * aux)68cbab9cadSchs plum_match(device_t parent, cfdata_t cf, void *aux)
699a758aabSuch {
709a758aabSuch 	struct cs_attach_args *ca = aux;
719a758aabSuch 
729a758aabSuch 	switch (plum_idcheck(ca->ca_csreg.cstag)) {
739a758aabSuch 	default:
7458f851eeSuch 		return (0);
759a758aabSuch 	case PLUM2_1:
769a758aabSuch 	case PLUM2_2:
77e2c040a1Ssimonb 		/* nothing */;
789a758aabSuch 	}
799a758aabSuch 
8058f851eeSuch 	return (1);
819a758aabSuch }
829a758aabSuch 
839a758aabSuch void
plum_attach(device_t parent,device_t self,void * aux)84cbab9cadSchs plum_attach(device_t parent, device_t self, void *aux)
859a758aabSuch {
869a758aabSuch 	struct cs_attach_args *ca = aux;
87cbab9cadSchs 	struct plum_softc *sc = device_private(self);
889a758aabSuch 	plumreg_t reg;
899a758aabSuch 
909a758aabSuch 	sc->sc_csregt	= ca->ca_csreg.cstag;
919a758aabSuch 	sc->sc_csiot	= ca->ca_csio.cstag;
929a758aabSuch 	sc->sc_csmemt	= ca->ca_csmem.cstag;
939a758aabSuch 	sc->sc_irq	= ca->ca_irq1;
949a758aabSuch 
954918cc92She 	switch (reg = plum_idcheck(sc->sc_csregt)) {
969a758aabSuch 	default:
979a758aabSuch 		printf(": unknown revision %#x\n", reg);
989a758aabSuch 		return;
999a758aabSuch 	case PLUM2_1:
1009a758aabSuch 		printf(": Plum2 #1\n");
1019a758aabSuch 		break;
1029a758aabSuch 	case PLUM2_2:
1039a758aabSuch 		printf(": Plum2 #2\n");
1049a758aabSuch 		break;
1059a758aabSuch 	}
106b950ff9aSthorpej 	sc->sc_pc = kmem_zalloc(sizeof(struct plum_chipset_tag), KM_SLEEP);
1079a758aabSuch 	sc->sc_pc->pc_tc = ca->ca_tc;
1089a758aabSuch 
1099a758aabSuch 	/* Attach Plum devices */
1109a758aabSuch 	/*
1119a758aabSuch 	 * interrupt, power/clock module is used by other plum module.
1129a758aabSuch 	 * attach first.
1139a758aabSuch 	 */
1149a758aabSuch 	sc->sc_pri = 2;
1152685996bSthorpej 	config_search(self, NULL,
116*c7fb772bSthorpej 	    CFARGS(.search = plum_search));
1172685996bSthorpej 
1189a758aabSuch 	/*
1199a758aabSuch 	 * Other plum module.
1209a758aabSuch 	 */
1219a758aabSuch 	sc->sc_pri = 1;
1222685996bSthorpej 	config_search(self, NULL,
123*c7fb772bSthorpej 	    CFARGS(.search = plum_search));
1249a758aabSuch }
1259a758aabSuch 
1269a758aabSuch plumreg_t
plum_idcheck(bus_space_tag_t regt)12758f851eeSuch plum_idcheck(bus_space_tag_t regt)
1289a758aabSuch {
1299a758aabSuch 	bus_space_handle_t regh;
1309a758aabSuch 	plumreg_t reg;
1319a758aabSuch 
1329a758aabSuch 	if (bus_space_map(regt, PLUM_ID_REGBASE,
1339a758aabSuch 	    PLUM_ID_REGSIZE, 0, &regh)) {
1349a758aabSuch 		printf("ID register map failed\n");
13558f851eeSuch 		return (0);
1369a758aabSuch 	}
1379a758aabSuch 	reg = plum_conf_read(regt, regh, PLUM_ID_REG);
1389a758aabSuch 	bus_space_unmap(regt, regh, PLUM_ID_REGSIZE);
1399a758aabSuch 
14058f851eeSuch 	return (reg);
1419a758aabSuch }
1429a758aabSuch 
1439a758aabSuch int
plum_print(void * aux,const char * pnp)14458f851eeSuch plum_print(void *aux, const char *pnp)
1459a758aabSuch {
14658f851eeSuch 
14758f851eeSuch 	return (pnp ? QUIET : UNCONF);
1489a758aabSuch }
1499a758aabSuch 
1509a758aabSuch int
plum_search(device_t parent,cfdata_t cf,const int * ldesc,void * aux)151cbab9cadSchs plum_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
1529a758aabSuch {
153cbab9cadSchs 	struct plum_softc *sc = device_private(parent);
1549a758aabSuch 	struct plum_attach_args pa;
1559a758aabSuch 
1569a758aabSuch 	pa.pa_pc	= sc->sc_pc;
1579a758aabSuch 	pa.pa_regt	= sc->sc_csregt;
1589a758aabSuch 	pa.pa_iot	= sc->sc_csiot;
1599a758aabSuch 	pa.pa_memt	= sc->sc_csmemt;
1609a758aabSuch 	pa.pa_irq	= sc->sc_irq;
1619a758aabSuch 
1622685996bSthorpej 	if (/*XXX*/config_probe(parent, cf, &pa) == sc->sc_pri) {
163*c7fb772bSthorpej 		config_attach(parent, cf, &pa, plum_print, CFARGS_NONE);
1649a758aabSuch 	}
1659a758aabSuch 
1669a758aabSuch 	return 0;
1679a758aabSuch }
1689a758aabSuch 
1699a758aabSuch plumreg_t
plum_conf_read(bus_space_tag_t t,bus_space_handle_t h,int o)17058f851eeSuch plum_conf_read(bus_space_tag_t t, bus_space_handle_t h, int o)
1719a758aabSuch {
1729a758aabSuch 	plumreg_t reg;
17358f851eeSuch 
1749a758aabSuch 	reg = bus_space_read_4(t, h, o);
17558f851eeSuch 
17658f851eeSuch 	return (reg);
1779a758aabSuch }
1789a758aabSuch 
1799a758aabSuch void
plum_conf_write(bus_space_tag_t t,bus_space_handle_t h,int o,plumreg_t v)18058f851eeSuch plum_conf_write(bus_space_tag_t t, bus_space_handle_t h, int o, plumreg_t v)
1819a758aabSuch {
18258f851eeSuch 
1839a758aabSuch 	bus_space_write_4(t, h, o, v);
1849a758aabSuch }
1859a758aabSuch 
1869a758aabSuch void
plum_conf_register_intr(plum_chipset_tag_t t,void * intrt)18758f851eeSuch plum_conf_register_intr(plum_chipset_tag_t t, void *intrt)
1889a758aabSuch {
18958f851eeSuch 
1909a758aabSuch 	if (t->pc_intrt) {
1919a758aabSuch 		panic("duplicate intrt");
1929a758aabSuch 	}
19358f851eeSuch 
1949a758aabSuch 	t->pc_intrt = intrt;
1959a758aabSuch }
1969a758aabSuch 
1979a758aabSuch void
plum_conf_register_power(plum_chipset_tag_t t,void * powert)19858f851eeSuch plum_conf_register_power(plum_chipset_tag_t t, void *powert)
1999a758aabSuch {
20058f851eeSuch 
2019a758aabSuch 	if (t->pc_powert) {
2029a758aabSuch 		panic("duplicate powert");
2039a758aabSuch 	}
20458f851eeSuch 
2059a758aabSuch 	t->pc_powert = powert;
2069a758aabSuch }
207