Home | History | Annotate | Line # | Download | only in dev
j720pcic.c revision 1.6.2.1
      1  1.6.2.1  uebayasi /*      $NetBSD: j720pcic.c,v 1.6.2.1 2010/10/22 07:21:18 uebayasi Exp $        */
      2      1.1       bsh 
      3      1.1       bsh /*-
      4      1.1       bsh  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5      1.1       bsh  * All rights reserved.
      6      1.1       bsh  *
      7      1.1       bsh  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1       bsh  * by IWAMOTO Toshihiro.
      9      1.1       bsh  *
     10      1.1       bsh  * Redistribution and use in source and binary forms, with or without
     11      1.1       bsh  * modification, are permitted provided that the following conditions
     12      1.1       bsh  * are met:
     13      1.1       bsh  * 1. Redistributions of source code must retain the above copyright
     14      1.1       bsh  *    notice, this list of conditions and the following disclaimer.
     15      1.1       bsh  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1       bsh  *    notice, this list of conditions and the following disclaimer in the
     17      1.1       bsh  *    documentation and/or other materials provided with the distribution.
     18      1.1       bsh  *
     19      1.1       bsh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1       bsh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1       bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1       bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1       bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1       bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1       bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1       bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1       bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1       bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1       bsh  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1       bsh  */
     31      1.1       bsh 
     32      1.4     peter /* Jornada 720 PCMCIA support. */
     33      1.4     peter 
     34      1.1       bsh #include <sys/cdefs.h>
     35  1.6.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: j720pcic.c,v 1.6.2.1 2010/10/22 07:21:18 uebayasi Exp $");
     36      1.1       bsh 
     37      1.1       bsh #include <sys/param.h>
     38      1.1       bsh #include <sys/systm.h>
     39      1.1       bsh #include <sys/types.h>
     40      1.1       bsh #include <sys/conf.h>
     41      1.1       bsh #include <sys/file.h>
     42      1.1       bsh #include <sys/device.h>
     43      1.1       bsh #include <sys/kernel.h>
     44      1.1       bsh #include <sys/kthread.h>
     45      1.1       bsh #include <sys/malloc.h>
     46      1.1       bsh 
     47      1.1       bsh #include <machine/bus.h>
     48      1.1       bsh #include <machine/platid.h>
     49      1.1       bsh #include <machine/platid_mask.h>
     50      1.1       bsh 
     51      1.1       bsh #include <dev/pcmcia/pcmciachip.h>
     52      1.1       bsh #include <dev/pcmcia/pcmciavar.h>
     53      1.4     peter 
     54      1.1       bsh #include <arm/sa11x0/sa11x0_reg.h>
     55      1.1       bsh #include <arm/sa11x0/sa11x0_var.h>
     56      1.1       bsh #include <arm/sa11x0/sa1111_reg.h>
     57      1.1       bsh #include <arm/sa11x0/sa1111_var.h>
     58      1.1       bsh #include <arm/sa11x0/sa11x1_pcicreg.h>
     59      1.1       bsh #include <arm/sa11x0/sa11xx_pcicvar.h>
     60      1.1       bsh #include <arm/sa11x0/sa11x1_pcicvar.h>
     61      1.1       bsh 
     62      1.1       bsh #include "sacpcic.h"
     63      1.1       bsh 
     64      1.6       rjs static int	sacpcic_match(device_t, cfdata_t, void *);
     65      1.6       rjs static void	sacpcic_attach(device_t, device_t, void *);
     66      1.4     peter 
     67      1.4     peter static void	j720_socket_setup(struct sapcic_socket *);
     68      1.4     peter static void	j720_set_power(struct sapcic_socket *, int);
     69      1.1       bsh 
     70      1.1       bsh static struct sapcic_tag j720_sacpcic_functions = {
     71      1.1       bsh 	sacpcic_read,
     72      1.1       bsh 	sacpcic_write,
     73      1.1       bsh 	j720_set_power,
     74      1.1       bsh 	sacpcic_clear_intr,
     75      1.1       bsh 	sacpcic_intr_establish,
     76      1.1       bsh 	sacpcic_intr_disestablish
     77      1.1       bsh };
     78      1.1       bsh 
     79      1.1       bsh static int j720_power_capability[] = {
     80      1.1       bsh 	SAPCIC_POWER_5V | SAPCIC_POWER_3V, SAPCIC_POWER_3V
     81      1.1       bsh };
     82      1.1       bsh 
     83      1.1       bsh static struct platid_data sacpcic_platid_table[] = {
     84      1.3     peter 	{ &platid_mask_MACH_HP_JORNADA_7XX, j720_power_capability },
     85      1.1       bsh 	{ NULL, NULL }
     86      1.1       bsh };
     87      1.1       bsh 
     88      1.6       rjs CFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc),
     89      1.1       bsh     sacpcic_match, sacpcic_attach, NULL, NULL);
     90      1.1       bsh 
     91      1.4     peter 
     92      1.1       bsh static int
     93      1.6       rjs sacpcic_match(device_t parent, cfdata_t cf, void *aux)
     94      1.1       bsh {
     95      1.4     peter 
     96      1.4     peter 	return 1;
     97      1.4     peter }
     98      1.4     peter 
     99      1.4     peter static void
    100      1.6       rjs sacpcic_attach(device_t parent, device_t self, void *aux)
    101      1.4     peter {
    102  1.6.2.1  uebayasi 	struct sacc_softc *psc;
    103  1.6.2.1  uebayasi 	struct sacpcic_softc *sc;
    104      1.4     peter 
    105  1.6.2.1  uebayasi 	psc = device_private(parent);
    106  1.6.2.1  uebayasi 	sc = device_private(self);
    107  1.6.2.1  uebayasi 	sc->sc_pc.sc_dev = self;
    108  1.6.2.1  uebayasi 
    109  1.6.2.1  uebayasi 	sacpcic_attach_common(psc, sc, aux, j720_socket_setup);
    110      1.1       bsh }
    111      1.1       bsh 
    112      1.1       bsh static void
    113      1.1       bsh j720_socket_setup(struct sapcic_socket *sp)
    114      1.1       bsh {
    115      1.1       bsh 	int *ip;
    116      1.1       bsh 	struct platid_data *p;
    117      1.1       bsh 	int socket = sp->socket;
    118      1.1       bsh 
    119      1.1       bsh 	p = platid_search_data(&platid, sacpcic_platid_table);
    120      1.1       bsh 
    121      1.1       bsh 	if (p == NULL) {
    122      1.1       bsh 		sp->power_capability = SAPCIC_POWER_5V;
    123      1.1       bsh 	} else {
    124      1.1       bsh 		ip = (int *)p->data;
    125      1.1       bsh 		sp->power_capability = ip[socket];
    126      1.1       bsh 	}
    127      1.1       bsh 
    128      1.1       bsh 	sp->pcictag = &j720_sacpcic_functions;
    129      1.1       bsh }
    130      1.1       bsh 
    131      1.1       bsh static void
    132      1.4     peter j720_set_power(struct sapcic_socket *so, int arg)
    133      1.1       bsh {
    134      1.1       bsh 	int newval, oldval, s;
    135      1.1       bsh 	struct sacc_softc *sc = so->pcictag_cookie;
    136      1.1       bsh 
    137      1.1       bsh 	/* XXX this isn't well confirmed. DANGER DANGER */
    138      1.1       bsh 	switch (arg) {
    139      1.1       bsh 	case SAPCIC_POWER_OFF:
    140      1.1       bsh 		newval = 0;
    141      1.1       bsh 		break;
    142      1.1       bsh 	case SAPCIC_POWER_3V:
    143      1.1       bsh 		newval = 2;
    144      1.1       bsh 		break;
    145      1.1       bsh 	case SAPCIC_POWER_5V:
    146      1.1       bsh 		newval = 1;
    147      1.1       bsh 		break;
    148      1.1       bsh 	default:
    149      1.4     peter 		panic("j720_set_power: bogus arg (%d)", arg);
    150      1.1       bsh 	}
    151      1.1       bsh 
    152      1.1       bsh 	s = splbio();
    153      1.4     peter 	oldval = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR);
    154      1.4     peter 
    155      1.1       bsh 	switch (so->socket) {
    156      1.1       bsh 	case 0:
    157      1.1       bsh 		newval = newval | (oldval & 0xc);
    158      1.1       bsh 		break;
    159      1.1       bsh 	case 1:
    160      1.1       bsh 		newval = (newval << 2) | (oldval & 3);
    161      1.1       bsh 		break;
    162      1.1       bsh 	default:
    163      1.1       bsh 		splx(s);
    164      1.4     peter 		panic("j720_set_power: bogus socket (%d)", so->socket);
    165      1.1       bsh 	}
    166      1.1       bsh 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, newval);
    167      1.1       bsh 	splx(s);
    168      1.1       bsh }
    169