[BACK]Return to sa1111.c CVS log [TXT][DIR] Up to [local] / sys / arch / arm / sa11x0

File: [local] / sys / arch / arm / sa11x0 / sa1111.c (download)

Revision 1.4, Sun May 11 09:26:11 2008 UTC (16 years ago) by nbrk
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +4 -3 lines

Sync up my latest modifications related to OpenBSD/jornada.
At this point PCMCIA is not done (this is primary goal since it's only
expansion bus for SA-1110) but some other chip subsystems rather work.
One of most recent problems sit in ported NetBSD pcic driver. It cause memory
abort passing odd addr to bus_space_write_2 (APB transactions are word-wide,
but I try to emulate 2-bytes accesses in bus_space_map for sa1111).
Other problematic/untested areas: sacic, saic. UART driver is a stub and not
really useful.
But even with this problems I have overdone my plans with this porting effort.

/*	$Id: sa1111.c,v 1.4 2008/05/11 09:26:11 nbrk Exp $	*/
/*
 * Copyright (c) 2002  Genetec Corporation.  All rights reserved.
 * Written by Hiroyuki Bessho for Genetec Corporation.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed for the NetBSD Project by
 *	Genetec Corporation.
 * 4. The name of Genetec Corporation may not be used to endorse or 
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*-
 * Copyright (c) 2001, The NetBSD Foundation, Inc.  All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the NetBSD
 *      Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 */
/*-
 * Copyright (c) 1999
 *         Shin Takemura and PocketBSD Project. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the PocketBSD project
 *	and its contributors.
 * 4. Neither the name of the project nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include <sys/cdefs.h>

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/reboot.h>

#include <machine/cpu.h>
#include <machine/bus.h>

#include <arm/sa11x0/sa1111_reg.h>
#include <arm/sa11x0/sa11x0_var.h>
#include <arm/sa11x0/sa11x1_var.h>

//#include <arm/sa11x0/sa1111_gpiovar.h>

/* prototypes */
int	sacc_match(struct device *, void *, void *);
void	sacc_attach(struct device *, struct device *, void *);
int 	sacc_search(struct device *, void *, void *);
int	sacc_print(void *, const char *);
void	sacc_attach_critical(struct sacc_softc *sc);

/* attach structures */
struct cfattach sacc_ca = {
	sizeof(struct sacc_softc), sacc_match, sacc_attach
};

struct cfdriver sacc_cd = {
	NULL, "sacc", DV_DULL
};

struct sacc_softc *sacc_sc;

int
sacc_match(struct device *parent, void *match, void *aux)
{

	return 1;
}

void
sacc_attach(struct device *parent, struct device *self, void *aux)
{
	struct sacc_softc *sc = (struct sacc_softc *)self;
	struct saip_attach_args *saa = aux;
	uint32_t	skid;

	sacc_sc = sc;
	sc->sc_bust = &sa11x1_bs_tag;
	sc->sc_intr = saa->sai_intr;

	/* XXX preserve our base addr for sa11x1_bs_map() */
	sa11x1_bs_tag.bs_cookie = &saa->sai_addr;

	/*
	 * Map whole I/O space.
	 */
//	if (bus_space_map(sc->sc_bust, 0, 128 * 12, 0, &sc->sc_ioh)) {
	if (bus_space_map(sc->sc_bust, 0, saa->sai_size, 0, &sc->sc_ioh)) {
		printf(": can't map i/o space\n");
		return;
	}

	/*
	 * Identify chip.
	 */
	skid = bus_space_read_4(sc->sc_bust, sc->sc_ioh, SACCSBI_SKID);
	if ((skid & 0xffffff00) != 0x690cc200) {
		printf(": incorrect SA-1111 chip ID\n");
		bus_space_unmap(sc->sc_bust, sc->sc_ioh, 128 * 12);
		return;
	}
	printf(": SA-1111 companion chip rev. %d/%d\n", skid & 0xf0, skid & 0x0f);

	/*
	 * Attach critical devices (GPIO and Interrupt controllers).
	 */
	sacc_attach_critical(sc);

	/*
	 * Attach all other devices.
	 */
	config_search(sacc_search, self, sc);
}

int
sacc_search(struct device *parent, void *c, void *aux)
{
	struct sacc_softc *sc = aux;
	struct sacc_attach_args aa;
	struct cfdata	*cf = c;

	aa.sac_iot = sc->sc_bust;
	aa.sac_dmat = sc->sc_dmat;
	aa.sac_bush = sc->sc_ioh;

	aa.sac_xintr = (cf->cf_loc)[0];

	config_found(parent, &aa, sacc_print);

	return 0;
}

int
sacc_print(void *aux, const char *name)
{
	struct sacc_attach_args *sa = (struct sacc_attach_args*)aux;

	if (sa->sac_xintr != -1)
                printf(" xintr %d", sa->sac_xintr);

	return (UNCONF);
}

void
sacc_attach_critical(struct sacc_softc *sc)
{
	/*
	 * Attach Interrupt and GPIO controllers because
	 * their functionality is needed for the rest of our onboard devices.
	 */
	struct sacc_attach_args saa;

	saa.sac_iot = sc->sc_bust;
	saa.sac_dmat = sc->sc_dmat;
	saa.sac_bush = sc->sc_ioh;

	/* XXX sac_xintr is an internal to us interrupt number, but here we use it
			to inform our INTC about which intr line it uses on main INTC.	*/
	saa.sac_xintr = sc->sc_intr;
	saa.sac_typecookie = SACC_TYPE_INTC;
	config_found(&sc->sc_dev, &saa, sacc_print);

	saa.sac_xintr = -1;	/* is not widely used, spec defines most of them */
	saa.sac_typecookie = SACC_TYPE_GPIO;
	config_found(&sc->sc_dev, &saa, sacc_print);
}