sacc_obio.c revision 1.6
11.6Snonaka/* $NetBSD: sacc_obio.c,v 1.6 2006/12/18 15:32:10 nonaka 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.6Snonaka__KERNEL_RCSID(0, "$NetBSD: sacc_obio.c,v 1.6 2006/12/18 15:32:10 nonaka 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.6Snonaka#include <arm/xscale/pxa2x0cpu.h> 671.1Sbsh#include <arm/xscale/pxa2x0reg.h> 681.1Sbsh#include <arm/xscale/pxa2x0var.h> 691.1Sbsh#include <arm/xscale/pxa2x0_gpio.h> 701.1Sbsh 711.1Sbsh#include <evbarm/lubbock/lubbock_reg.h> 721.1Sbsh#include <evbarm/lubbock/lubbock_var.h> 731.1Sbsh 741.1Sbsh 751.1Sbshstatic void sacc_obio_attach(struct device *, struct device *, void *); 761.1Sbshstatic int sacc_obio_intr(void *arg); 771.1Sbsh 781.1SbshCFATTACH_DECL(sacc_obio, sizeof(struct sacc_softc), sacc_probe, 791.1Sbsh sacc_obio_attach, NULL, NULL); 801.1Sbsh 811.1Sbsh#if 0 821.1Sbsh#define DPRINTF(arg) printf arg 831.1Sbsh#else 841.1Sbsh#define DPRINTF(arg) 851.1Sbsh#endif 861.1Sbsh 871.1Sbshuint16_t cs2_memctl_init = 0x7ff0; 881.1Sbsh 891.1Sbshstatic void 901.1Sbshsacc_obio_attach(parent, self, aux) 911.1Sbsh struct device *parent; 921.1Sbsh struct device *self; 931.1Sbsh void *aux; 941.1Sbsh{ 951.1Sbsh int i; 961.1Sbsh u_int32_t skid, tmp; 971.1Sbsh struct sacc_softc *sc = (struct sacc_softc *)self; 981.1Sbsh struct obio_softc *psc = (struct obio_softc *)parent; 991.1Sbsh struct obio_attach_args *sa = aux; 1001.1Sbsh bus_space_tag_t iot = sa->oba_iot; 1011.1Sbsh bus_space_handle_t memctl_ioh; 1021.1Sbsh 1031.1Sbsh printf("\n"); 1041.1Sbsh 1051.1Sbsh /* Set alternative function for GPIO pings 48..57 on PXA2X0 */ 1061.1Sbsh for (i=48; i <= 55; ++i) 1071.1Sbsh pxa2x0_gpio_set_function(i, GPIO_ALT_FN_2_OUT); 1081.1Sbsh pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN); 1091.1Sbsh pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN); 1101.1Sbsh 1111.1Sbsh /* XXX */ 1121.1Sbsh if (bus_space_map(iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, 1131.1Sbsh &memctl_ioh)) 1141.1Sbsh goto fail; 1151.1Sbsh 1161.1Sbsh tmp = bus_space_read_4(iot, memctl_ioh, MEMCTL_MSC2 ); 1171.1Sbsh bus_space_write_4(iot, memctl_ioh, MEMCTL_MSC2, 1181.1Sbsh (tmp & 0xffff0000) | cs2_memctl_init ); 1191.1Sbsh 1201.1Sbsh bus_space_unmap(iot, memctl_ioh, PXA2X0_MEMCTL_SIZE); 1211.1Sbsh 1221.1Sbsh sc->sc_piot = sc->sc_iot = iot; 1231.3Sbjh21 sc->sc_gpioh = 0; /* not used */ 1241.1Sbsh 1251.1Sbsh if (bus_space_map(iot, sa->oba_addr, 0x2000/*size*/, 0, &sc->sc_ioh)) 1261.1Sbsh goto fail; 1271.1Sbsh 1281.1Sbsh skid = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCSBI_SKID); 1291.1Sbsh 1301.1Sbsh printf("%s: SA1111 rev %d.%d\n", sc->sc_dev.dv_xname, 1311.1Sbsh (skid & 0xf0) >> 4, skid & 0xf); 1321.1Sbsh 1331.1Sbsh tmp = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR); 1341.1Sbsh tmp = (tmp & ~SKCR_VCOOFF) | SKCR_PLLBYPASS; 1351.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR, tmp ); 1361.1Sbsh 1371.1Sbsh delay(100); /* XXX */ 1381.1Sbsh 1391.1Sbsh tmp |= SKCR_RCLKEN; 1401.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR, tmp ); 1411.1Sbsh 1421.1Sbsh#if 1 1431.1Sbsh if( tmp != bus_space_read_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR ) ) 1441.1Sbsh printf( "!!! FAIL SKCR\n" ); 1451.1Sbsh#endif 1461.1Sbsh 1471.1Sbsh /* PCMCIA socket0 power control */ 1481.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, 0 ); 1491.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCGPIOA_DDR, 0 ); 1501.1Sbsh 1511.1Sbsh for(i = 0; i < SACCIC_LEN; i++) 1521.1Sbsh sc->sc_intrhand[i] = NULL; 1531.1Sbsh 1541.1Sbsh /* initialize SA1111 interrupt controller */ 1551.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN0, 0); 1561.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN1, 0); 1571.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTTSTSEL, 0); 1581.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 1591.1Sbsh SACCIC_INTSTATCLR0, 0xffffffff); 1601.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 1611.1Sbsh SACCIC_INTSTATCLR1, 0xffffffff); 1621.1Sbsh 1631.1Sbsh /* connect to On-board peripheral interrupt */ 1641.1Sbsh obio_intr_establish(psc, sa->oba_intr, 1651.1Sbsh IPL_HIGH, sacc_obio_intr, sc ); 1661.1Sbsh /* 1671.1Sbsh * Attach each devices 1681.1Sbsh */ 1691.4Sdrochner config_search_ia(sa1111_search, self, "sacc", NULL); 1701.1Sbsh 1711.1Sbsh return; 1721.1Sbsh 1731.1Sbsh fail: 1741.1Sbsh printf("%s: unable to map registers\n", sc->sc_dev.dv_xname); 1751.1Sbsh} 1761.1Sbsh 1771.1Sbshstatic int 1781.1Sbshsacc_obio_intr(void *arg) 1791.1Sbsh{ 1801.1Sbsh int i; 1811.1Sbsh struct sacc_intrvec intstat; 1821.1Sbsh struct sacc_softc *sc = arg; 1831.1Sbsh struct sacc_intrhand *ih; 1841.1Sbsh 1851.1Sbsh intstat.lo = 1861.1Sbsh bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTSTATCLR0); 1871.1Sbsh intstat.hi = 1881.1Sbsh bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTSTATCLR1); 1891.1Sbsh DPRINTF(("sacc_obio_intr_dispatch: %x %x\n", intstat.lo, intstat.hi)); 1901.1Sbsh 1911.2Sbsh while ((i = find_first_bit(intstat.lo)) >= 0) { 1921.1Sbsh 1931.2Sbsh /* 1941.2Sbsh * Clear intr status before calling intr handlers. 1951.2Sbsh * This cause stray interrupts, but clearing 1961.2Sbsh * after calling intr handlers cause intr lossage. 1971.2Sbsh */ 1981.2Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 1991.2Sbsh SACCIC_INTSTATCLR0, 1U<<i ); 2001.2Sbsh 2011.2Sbsh for(ih = sc->sc_intrhand[i]; ih; ih = ih->ih_next) 2021.2Sbsh softintr_schedule(ih->ih_soft); 2031.2Sbsh 2041.2Sbsh intstat.lo &= ~(1U<<i); 2051.1Sbsh } 2061.2Sbsh 2071.2Sbsh while ((i = find_first_bit(intstat.hi)) >= 0) { 2081.2Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 2091.2Sbsh SACCIC_INTSTATCLR1, 1U<<i); 2101.2Sbsh 2111.2Sbsh for(ih = sc->sc_intrhand[i + 32]; ih; ih = ih->ih_next) 2121.2Sbsh softintr_schedule(ih->ih_soft); 2131.2Sbsh 2141.2Sbsh intstat.hi &= ~(1U<<i); 2151.2Sbsh } 2161.2Sbsh 2171.1Sbsh return 1; 2181.1Sbsh} 219