sacc_obio.c revision 1.10
11.10Srjs/* $NetBSD: sacc_obio.c,v 1.10 2009/05/29 14:15:44 rjs 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 * 191.1Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sbsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sbsh * POSSIBILITY OF SUCH DAMAGE. 301.1Sbsh */ 311.1Sbsh 321.1Sbsh/* 331.1Sbsh * for SA-1111 companion chip on Intel DBPXA250 evaluation board. 341.1Sbsh */ 351.1Sbsh 361.1Sbsh#include <sys/cdefs.h> 371.10Srjs__KERNEL_RCSID(0, "$NetBSD: sacc_obio.c,v 1.10 2009/05/29 14:15:44 rjs Exp $"); 381.1Sbsh 391.1Sbsh#include <sys/param.h> 401.1Sbsh#include <sys/systm.h> 411.1Sbsh#include <sys/mbuf.h> 421.1Sbsh#include <sys/socket.h> 431.1Sbsh#include <sys/ioctl.h> 441.1Sbsh#include <sys/errno.h> 451.1Sbsh#include <sys/syslog.h> 461.1Sbsh#include <sys/select.h> 471.1Sbsh#include <sys/device.h> 481.1Sbsh 491.1Sbsh#include <net/if.h> 501.1Sbsh#include <net/if_dl.h> 511.1Sbsh#include <net/if_ether.h> 521.1Sbsh#include <net/if_media.h> 531.1Sbsh 541.1Sbsh#include <machine/intr.h> 551.1Sbsh#include <machine/bus.h> 561.1Sbsh 571.1Sbsh#include <arm/sa11x0/sa1111_reg.h> 581.1Sbsh#include <arm/sa11x0/sa1111_var.h> 591.6Snonaka#include <arm/xscale/pxa2x0cpu.h> 601.1Sbsh#include <arm/xscale/pxa2x0reg.h> 611.1Sbsh#include <arm/xscale/pxa2x0var.h> 621.1Sbsh#include <arm/xscale/pxa2x0_gpio.h> 631.1Sbsh 641.1Sbsh#include <evbarm/lubbock/lubbock_reg.h> 651.1Sbsh#include <evbarm/lubbock/lubbock_var.h> 661.1Sbsh 671.1Sbsh 681.10Srjsstatic void sacc_obio_attach(device_t, device_t, void *); 691.1Sbshstatic int sacc_obio_intr(void *arg); 701.1Sbsh 711.10SrjsCFATTACH_DECL_NEW(sacc_obio, sizeof(struct sacc_softc), sacc_probe, 721.1Sbsh sacc_obio_attach, NULL, NULL); 731.1Sbsh 741.1Sbsh#if 0 751.10Srjs#define DPRINTF(arg) aprint_normal arg 761.1Sbsh#else 771.1Sbsh#define DPRINTF(arg) 781.1Sbsh#endif 791.1Sbsh 801.1Sbshuint16_t cs2_memctl_init = 0x7ff0; 811.1Sbsh 821.1Sbshstatic void 831.10Srjssacc_obio_attach(device_t parent, device_t self, void *aux) 841.1Sbsh{ 851.1Sbsh int i; 861.1Sbsh u_int32_t skid, tmp; 871.10Srjs struct sacc_softc *sc = device_private(self); 881.10Srjs struct obio_softc *psc = device_private(parent); 891.1Sbsh struct obio_attach_args *sa = aux; 901.1Sbsh bus_space_tag_t iot = sa->oba_iot; 911.1Sbsh bus_space_handle_t memctl_ioh; 921.1Sbsh 931.10Srjs aprint_normal("\n"); 941.1Sbsh 951.1Sbsh /* Set alternative function for GPIO pings 48..57 on PXA2X0 */ 961.1Sbsh for (i=48; i <= 55; ++i) 971.1Sbsh pxa2x0_gpio_set_function(i, GPIO_ALT_FN_2_OUT); 981.1Sbsh pxa2x0_gpio_set_function(56, GPIO_ALT_FN_1_IN); 991.1Sbsh pxa2x0_gpio_set_function(57, GPIO_ALT_FN_1_IN); 1001.1Sbsh 1011.1Sbsh /* XXX */ 1021.1Sbsh if (bus_space_map(iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 0, 1031.1Sbsh &memctl_ioh)) 1041.1Sbsh goto fail; 1051.1Sbsh 1061.1Sbsh tmp = bus_space_read_4(iot, memctl_ioh, MEMCTL_MSC2 ); 1071.1Sbsh bus_space_write_4(iot, memctl_ioh, MEMCTL_MSC2, 1081.1Sbsh (tmp & 0xffff0000) | cs2_memctl_init ); 1091.1Sbsh 1101.1Sbsh bus_space_unmap(iot, memctl_ioh, PXA2X0_MEMCTL_SIZE); 1111.1Sbsh 1121.10Srjs sc->sc_dev = self; 1131.1Sbsh sc->sc_piot = sc->sc_iot = iot; 1141.3Sbjh21 sc->sc_gpioh = 0; /* not used */ 1151.1Sbsh 1161.1Sbsh if (bus_space_map(iot, sa->oba_addr, 0x2000/*size*/, 0, &sc->sc_ioh)) 1171.1Sbsh goto fail; 1181.1Sbsh 1191.1Sbsh skid = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCSBI_SKID); 1201.1Sbsh 1211.10Srjs aprint_normal_dev(self, "SA1111 rev %d.%d\n", 1221.10Srjs (skid & 0xf0) >> 4, skid & 0xf); 1231.1Sbsh 1241.1Sbsh tmp = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR); 1251.1Sbsh tmp = (tmp & ~SKCR_VCOOFF) | SKCR_PLLBYPASS; 1261.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR, tmp ); 1271.1Sbsh 1281.1Sbsh delay(100); /* XXX */ 1291.1Sbsh 1301.1Sbsh tmp |= SKCR_RCLKEN; 1311.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR, tmp ); 1321.1Sbsh 1331.1Sbsh#if 1 1341.1Sbsh if( tmp != bus_space_read_4( sc->sc_iot, sc->sc_ioh, SACCSBI_SKCR ) ) 1351.1Sbsh printf( "!!! FAIL SKCR\n" ); 1361.1Sbsh#endif 1371.1Sbsh 1381.1Sbsh /* PCMCIA socket0 power control */ 1391.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, 0 ); 1401.1Sbsh bus_space_write_4( sc->sc_iot, sc->sc_ioh, SACCGPIOA_DDR, 0 ); 1411.1Sbsh 1421.1Sbsh for(i = 0; i < SACCIC_LEN; i++) 1431.1Sbsh sc->sc_intrhand[i] = NULL; 1441.1Sbsh 1451.1Sbsh /* initialize SA1111 interrupt controller */ 1461.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN0, 0); 1471.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN1, 0); 1481.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTTSTSEL, 0); 1491.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 1501.1Sbsh SACCIC_INTSTATCLR0, 0xffffffff); 1511.1Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 1521.1Sbsh SACCIC_INTSTATCLR1, 0xffffffff); 1531.1Sbsh 1541.1Sbsh /* connect to On-board peripheral interrupt */ 1551.1Sbsh obio_intr_establish(psc, sa->oba_intr, 1561.1Sbsh IPL_HIGH, sacc_obio_intr, sc ); 1571.1Sbsh /* 1581.1Sbsh * Attach each devices 1591.1Sbsh */ 1601.4Sdrochner config_search_ia(sa1111_search, self, "sacc", NULL); 1611.1Sbsh 1621.1Sbsh return; 1631.1Sbsh 1641.1Sbsh fail: 1651.10Srjs aprint_normal_dev(self, "unable to map registers\n"); 1661.1Sbsh} 1671.1Sbsh 1681.1Sbshstatic int 1691.1Sbshsacc_obio_intr(void *arg) 1701.1Sbsh{ 1711.1Sbsh int i; 1721.1Sbsh struct sacc_intrvec intstat; 1731.1Sbsh struct sacc_softc *sc = arg; 1741.1Sbsh struct sacc_intrhand *ih; 1751.1Sbsh 1761.1Sbsh intstat.lo = 1771.1Sbsh bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTSTATCLR0); 1781.1Sbsh intstat.hi = 1791.1Sbsh bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTSTATCLR1); 1801.1Sbsh DPRINTF(("sacc_obio_intr_dispatch: %x %x\n", intstat.lo, intstat.hi)); 1811.1Sbsh 1821.2Sbsh while ((i = find_first_bit(intstat.lo)) >= 0) { 1831.1Sbsh 1841.2Sbsh /* 1851.2Sbsh * Clear intr status before calling intr handlers. 1861.2Sbsh * This cause stray interrupts, but clearing 1871.2Sbsh * after calling intr handlers cause intr lossage. 1881.2Sbsh */ 1891.2Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 1901.2Sbsh SACCIC_INTSTATCLR0, 1U<<i ); 1911.2Sbsh 1921.2Sbsh for(ih = sc->sc_intrhand[i]; ih; ih = ih->ih_next) 1931.7Smatt softint_schedule(ih->ih_soft); 1941.2Sbsh 1951.2Sbsh intstat.lo &= ~(1U<<i); 1961.1Sbsh } 1971.2Sbsh 1981.2Sbsh while ((i = find_first_bit(intstat.hi)) >= 0) { 1991.2Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, 2001.2Sbsh SACCIC_INTSTATCLR1, 1U<<i); 2011.2Sbsh 2021.2Sbsh for(ih = sc->sc_intrhand[i + 32]; ih; ih = ih->ih_next) 2031.7Smatt softint_schedule(ih->ih_soft); 2041.2Sbsh 2051.2Sbsh intstat.hi &= ~(1U<<i); 2061.2Sbsh } 2071.2Sbsh 2081.1Sbsh return 1; 2091.1Sbsh} 210