sacc_obio.c revision 1.3
11.3Sbjh21/*	$NetBSD: sacc_obio.c,v 1.3 2004/02/21 23:25:01 bjh21 Exp $ */
21.1Sbsh
31.1Sbsh/*-
41.1Sbsh * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Sbsh * All rights reserved.
61.1Sbsh *
71.1Sbsh * This code is derived from software contributed to The NetBSD Foundation
81.1Sbsh * by IWAMOTO Toshihiro.
91.1Sbsh *
101.1Sbsh * Redistribution and use in source and binary forms, with or without
111.1Sbsh * modification, are permitted provided that the following conditions
121.1Sbsh * are met:
131.1Sbsh * 1. Redistributions of source code must retain the above copyright
141.1Sbsh *    notice, this list of conditions and the following disclaimer.
151.1Sbsh * 2. Redistributions in binary form must reproduce the above copyright
161.1Sbsh *    notice, this list of conditions and the following disclaimer in the
171.1Sbsh *    documentation and/or other materials provided with the distribution.
181.1Sbsh * 3. All advertising materials mentioning features or use of this software
191.1Sbsh *    must display the following acknowledgement:
201.1Sbsh *        This product includes software developed by the NetBSD
211.1Sbsh *        Foundation, Inc. and its contributors.
221.1Sbsh * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sbsh *    contributors may be used to endorse or promote products derived
241.1Sbsh *    from this software without specific prior written permission.
251.1Sbsh *
261.1Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sbsh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sbsh * POSSIBILITY OF SUCH DAMAGE.
371.1Sbsh */
381.1Sbsh
391.1Sbsh/*
401.1Sbsh * for SA-1111 companion chip on Intel DBPXA250 evaluation board.
411.1Sbsh */
421.1Sbsh
431.1Sbsh#include <sys/cdefs.h>
441.3Sbjh21__KERNEL_RCSID(0, "$NetBSD: sacc_obio.c,v 1.3 2004/02/21 23:25:01 bjh21 Exp $");
451.1Sbsh
461.1Sbsh#include <sys/param.h>
471.1Sbsh#include <sys/systm.h>
481.1Sbsh#include <sys/mbuf.h>
491.1Sbsh#include <sys/socket.h>
501.1Sbsh#include <sys/ioctl.h>
511.1Sbsh#include <sys/errno.h>
521.1Sbsh#include <sys/syslog.h>
531.1Sbsh#include <sys/select.h>
541.1Sbsh#include <sys/device.h>
551.1Sbsh
561.1Sbsh#include <net/if.h>
571.1Sbsh#include <net/if_dl.h>
581.1Sbsh#include <net/if_ether.h>
591.1Sbsh#include <net/if_media.h>
601.1Sbsh
611.1Sbsh#include <machine/intr.h>
621.1Sbsh#include <machine/bus.h>
631.1Sbsh
641.1Sbsh#include <arm/sa11x0/sa1111_reg.h>
651.1Sbsh#include <arm/sa11x0/sa1111_var.h>
661.1Sbsh#include <arm/xscale/pxa2x0reg.h>
671.1Sbsh#include <arm/xscale/pxa2x0var.h>
681.1Sbsh#include <arm/xscale/pxa2x0_gpio.h>
691.1Sbsh
701.1Sbsh#include <evbarm/lubbock/lubbock_reg.h>
711.1Sbsh#include <evbarm/lubbock/lubbock_var.h>
721.1Sbsh
731.1Sbsh
741.1Sbshstatic	void	sacc_obio_attach(struct device *, struct device *, void *);
751.1Sbshstatic	int  sacc_obio_intr(void *arg);
761.1Sbsh
771.1SbshCFATTACH_DECL(sacc_obio, sizeof(struct sacc_softc), sacc_probe,
781.1Sbsh    sacc_obio_attach, NULL, NULL);
791.1Sbsh
801.1Sbsh#if 0
811.1Sbsh#define DPRINTF(arg)	printf arg
821.1Sbsh#else
831.1Sbsh#define DPRINTF(arg)
841.1Sbsh#endif
851.1Sbsh
861.1Sbshuint16_t cs2_memctl_init = 0x7ff0;
871.1Sbsh
881.1Sbshstatic void
891.1Sbshsacc_obio_attach(parent, self, aux)
901.1Sbsh	struct device *parent;
911.1Sbsh	struct device *self;
921.1Sbsh	void *aux;
931.1Sbsh{
941.1Sbsh	int i;
951.1Sbsh	u_int32_t skid, tmp;
961.1Sbsh	struct sacc_softc *sc = (struct sacc_softc *)self;
971.1Sbsh	struct obio_softc *psc = (struct obio_softc *)parent;
981.1Sbsh	struct obio_attach_args *sa = aux;
991.1Sbsh	bus_space_tag_t iot = sa->oba_iot;
1001.1Sbsh	bus_space_handle_t memctl_ioh;
1011.1Sbsh
1021.1Sbsh	printf("\n");
1031.1Sbsh
1041.1Sbsh	/* Set alternative function for GPIO pings 48..57 on PXA2X0 */
1051.1Sbsh	for (i=48; i <= 55; ++i)
1061.1Sbsh		pxa2x0_gpio_set_function(i, GPIO_ALT_FN_2_OUT);
1071.1Sbsh	pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN);
1081.1Sbsh	pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN);
1091.1Sbsh
1101.1Sbsh	/* XXX */
1111.1Sbsh	if (bus_space_map(iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0,
1121.1Sbsh			  &memctl_ioh))
1131.1Sbsh		goto fail;
1141.1Sbsh
1151.1Sbsh	tmp = bus_space_read_4(iot, memctl_ioh, MEMCTL_MSC2 );
1161.1Sbsh	bus_space_write_4(iot, memctl_ioh, MEMCTL_MSC2,
1171.1Sbsh	    (tmp & 0xffff0000) | cs2_memctl_init );
1181.1Sbsh
1191.1Sbsh	bus_space_unmap(iot, memctl_ioh, PXA2X0_MEMCTL_SIZE);
1201.1Sbsh
1211.1Sbsh	sc->sc_piot = sc->sc_iot = iot;
1221.3Sbjh21	sc->sc_gpioh = 0;	/* not used */
1231.1Sbsh
1241.1Sbsh	if (bus_space_map(iot, sa->oba_addr, 0x2000/*size*/, 0, &sc->sc_ioh))
1251.1Sbsh		goto fail;
1261.1Sbsh
1271.1Sbsh	skid = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCSBI_SKID);
1281.1Sbsh
1291.1Sbsh	printf("%s: SA1111 rev %d.%d\n", sc->sc_dev.dv_xname,
1301.1Sbsh	       (skid & 0xf0) >> 4, skid & 0xf);
1311.1Sbsh
1321.1Sbsh	tmp = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR);
1331.1Sbsh	tmp = (tmp & ~SKCR_VCOOFF) | SKCR_PLLBYPASS;
1341.1Sbsh	bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR, tmp );
1351.1Sbsh
1361.1Sbsh	delay(100);			/* XXX */
1371.1Sbsh
1381.1Sbsh	tmp |= SKCR_RCLKEN;
1391.1Sbsh	bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR, tmp );
1401.1Sbsh
1411.1Sbsh#if 1
1421.1Sbsh	if( tmp != bus_space_read_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR ) )
1431.1Sbsh		printf( "!!! FAIL SKCR\n" );
1441.1Sbsh#endif
1451.1Sbsh
1461.1Sbsh	/* PCMCIA socket0 power control */
1471.1Sbsh	bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, 0 );
1481.1Sbsh	bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCGPIOA_DDR, 0 );
1491.1Sbsh
1501.1Sbsh	for(i = 0; i < SACCIC_LEN; i++)
1511.1Sbsh		sc->sc_intrhand[i] = NULL;
1521.1Sbsh
1531.1Sbsh	/* initialize SA1111 interrupt controller */
1541.1Sbsh	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN0, 0);
1551.1Sbsh	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN1, 0);
1561.1Sbsh	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTTSTSEL, 0);
1571.1Sbsh	bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1581.1Sbsh			  SACCIC_INTSTATCLR0, 0xffffffff);
1591.1Sbsh	bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1601.1Sbsh			  SACCIC_INTSTATCLR1, 0xffffffff);
1611.1Sbsh
1621.1Sbsh	/* connect to On-board peripheral interrupt */
1631.1Sbsh	obio_intr_establish(psc, sa->oba_intr,
1641.1Sbsh			    IPL_HIGH, sacc_obio_intr, sc );
1651.1Sbsh	/*
1661.1Sbsh	 *  Attach each devices
1671.1Sbsh	 */
1681.1Sbsh	config_search(sa1111_search, self, NULL);
1691.1Sbsh
1701.1Sbsh	return;
1711.1Sbsh
1721.1Sbsh fail:
1731.1Sbsh	printf("%s: unable to map registers\n", sc->sc_dev.dv_xname);
1741.1Sbsh}
1751.1Sbsh
1761.1Sbshstatic int
1771.1Sbshsacc_obio_intr(void *arg)
1781.1Sbsh{
1791.1Sbsh	int i;
1801.1Sbsh	struct sacc_intrvec intstat;
1811.1Sbsh	struct sacc_softc *sc = arg;
1821.1Sbsh	struct sacc_intrhand *ih;
1831.1Sbsh
1841.1Sbsh	intstat.lo =
1851.1Sbsh	    bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTSTATCLR0);
1861.1Sbsh	intstat.hi =
1871.1Sbsh	    bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTSTATCLR1);
1881.1Sbsh	DPRINTF(("sacc_obio_intr_dispatch: %x %x\n", intstat.lo, intstat.hi));
1891.1Sbsh
1901.2Sbsh	while ((i = find_first_bit(intstat.lo)) >= 0) {
1911.1Sbsh
1921.2Sbsh		/*
1931.2Sbsh		 * Clear intr status before calling intr handlers.
1941.2Sbsh		 * This cause stray interrupts, but clearing
1951.2Sbsh		 * after calling intr handlers cause intr lossage.
1961.2Sbsh		 */
1971.2Sbsh		bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1981.2Sbsh				  SACCIC_INTSTATCLR0, 1U<<i );
1991.2Sbsh
2001.2Sbsh		for(ih = sc->sc_intrhand[i]; ih; ih = ih->ih_next)
2011.2Sbsh			softintr_schedule(ih->ih_soft);
2021.2Sbsh
2031.2Sbsh		intstat.lo &= ~(1U<<i);
2041.1Sbsh	}
2051.2Sbsh
2061.2Sbsh	while ((i = find_first_bit(intstat.hi)) >= 0) {
2071.2Sbsh		bus_space_write_4(sc->sc_iot, sc->sc_ioh,
2081.2Sbsh				  SACCIC_INTSTATCLR1, 1U<<i);
2091.2Sbsh
2101.2Sbsh		for(ih = sc->sc_intrhand[i + 32]; ih; ih = ih->ih_next)
2111.2Sbsh			softintr_schedule(ih->ih_soft);
2121.2Sbsh
2131.2Sbsh		intstat.hi &= ~(1U<<i);
2141.2Sbsh	}
2151.2Sbsh
2161.1Sbsh	return 1;
2171.1Sbsh}
218