1*7433666eSthorpej /* $NetBSD: j720pcic.c,v 1.9 2023/12/20 14:50:02 thorpej Exp $ */
210c7bfc7Sbsh
310c7bfc7Sbsh /*-
410c7bfc7Sbsh * Copyright (c) 2001 The NetBSD Foundation, Inc.
510c7bfc7Sbsh * All rights reserved.
610c7bfc7Sbsh *
710c7bfc7Sbsh * This code is derived from software contributed to The NetBSD Foundation
810c7bfc7Sbsh * by IWAMOTO Toshihiro.
910c7bfc7Sbsh *
1010c7bfc7Sbsh * Redistribution and use in source and binary forms, with or without
1110c7bfc7Sbsh * modification, are permitted provided that the following conditions
1210c7bfc7Sbsh * are met:
1310c7bfc7Sbsh * 1. Redistributions of source code must retain the above copyright
1410c7bfc7Sbsh * notice, this list of conditions and the following disclaimer.
1510c7bfc7Sbsh * 2. Redistributions in binary form must reproduce the above copyright
1610c7bfc7Sbsh * notice, this list of conditions and the following disclaimer in the
1710c7bfc7Sbsh * documentation and/or other materials provided with the distribution.
1810c7bfc7Sbsh *
1910c7bfc7Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2010c7bfc7Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2110c7bfc7Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2210c7bfc7Sbsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2310c7bfc7Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2410c7bfc7Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2510c7bfc7Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2610c7bfc7Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2710c7bfc7Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2810c7bfc7Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2910c7bfc7Sbsh * POSSIBILITY OF SUCH DAMAGE.
3010c7bfc7Sbsh */
3110c7bfc7Sbsh
32018931a9Speter /* Jornada 720 PCMCIA support. */
33018931a9Speter
3410c7bfc7Sbsh #include <sys/cdefs.h>
35*7433666eSthorpej __KERNEL_RCSID(0, "$NetBSD: j720pcic.c,v 1.9 2023/12/20 14:50:02 thorpej Exp $");
3610c7bfc7Sbsh
3710c7bfc7Sbsh #include <sys/param.h>
3810c7bfc7Sbsh #include <sys/systm.h>
3910c7bfc7Sbsh #include <sys/types.h>
4010c7bfc7Sbsh #include <sys/conf.h>
4110c7bfc7Sbsh #include <sys/file.h>
4210c7bfc7Sbsh #include <sys/device.h>
4310c7bfc7Sbsh #include <sys/kernel.h>
4410c7bfc7Sbsh #include <sys/kthread.h>
459edf49b0Sdyoung #include <sys/bus.h>
4610c7bfc7Sbsh
4710c7bfc7Sbsh #include <machine/platid.h>
4810c7bfc7Sbsh #include <machine/platid_mask.h>
4910c7bfc7Sbsh
5010c7bfc7Sbsh #include <dev/pcmcia/pcmciachip.h>
5110c7bfc7Sbsh #include <dev/pcmcia/pcmciavar.h>
52018931a9Speter
5310c7bfc7Sbsh #include <arm/sa11x0/sa11x0_reg.h>
5410c7bfc7Sbsh #include <arm/sa11x0/sa11x0_var.h>
5510c7bfc7Sbsh #include <arm/sa11x0/sa1111_reg.h>
5610c7bfc7Sbsh #include <arm/sa11x0/sa1111_var.h>
5710c7bfc7Sbsh #include <arm/sa11x0/sa11x1_pcicreg.h>
5810c7bfc7Sbsh #include <arm/sa11x0/sa11xx_pcicvar.h>
5910c7bfc7Sbsh #include <arm/sa11x0/sa11x1_pcicvar.h>
6010c7bfc7Sbsh
6110c7bfc7Sbsh #include "sacpcic.h"
6210c7bfc7Sbsh
634c494f76Srjs static int sacpcic_match(device_t, cfdata_t, void *);
644c494f76Srjs static void sacpcic_attach(device_t, device_t, void *);
65018931a9Speter
66018931a9Speter static void j720_socket_setup(struct sapcic_socket *);
67018931a9Speter static void j720_set_power(struct sapcic_socket *, int);
6810c7bfc7Sbsh
6910c7bfc7Sbsh static struct sapcic_tag j720_sacpcic_functions = {
7010c7bfc7Sbsh sacpcic_read,
7110c7bfc7Sbsh sacpcic_write,
7210c7bfc7Sbsh j720_set_power,
7310c7bfc7Sbsh sacpcic_clear_intr,
7410c7bfc7Sbsh sacpcic_intr_establish,
7510c7bfc7Sbsh sacpcic_intr_disestablish
7610c7bfc7Sbsh };
7710c7bfc7Sbsh
7810c7bfc7Sbsh static int j720_power_capability[] = {
7910c7bfc7Sbsh SAPCIC_POWER_5V | SAPCIC_POWER_3V, SAPCIC_POWER_3V
8010c7bfc7Sbsh };
8110c7bfc7Sbsh
8210c7bfc7Sbsh static struct platid_data sacpcic_platid_table[] = {
83ffc68bd5Speter { &platid_mask_MACH_HP_JORNADA_7XX, j720_power_capability },
8410c7bfc7Sbsh { NULL, NULL }
8510c7bfc7Sbsh };
8610c7bfc7Sbsh
874c494f76Srjs CFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc),
8810c7bfc7Sbsh sacpcic_match, sacpcic_attach, NULL, NULL);
8910c7bfc7Sbsh
90018931a9Speter
9110c7bfc7Sbsh static int
sacpcic_match(device_t parent,cfdata_t cf,void * aux)924c494f76Srjs sacpcic_match(device_t parent, cfdata_t cf, void *aux)
9310c7bfc7Sbsh {
94018931a9Speter
95018931a9Speter return 1;
96018931a9Speter }
97018931a9Speter
98018931a9Speter static void
sacpcic_attach(device_t parent,device_t self,void * aux)994c494f76Srjs sacpcic_attach(device_t parent, device_t self, void *aux)
100018931a9Speter {
101961a253cStsutsui struct sacc_softc *psc;
102961a253cStsutsui struct sacpcic_softc *sc;
103018931a9Speter
104961a253cStsutsui psc = device_private(parent);
105961a253cStsutsui sc = device_private(self);
106961a253cStsutsui sc->sc_pc.sc_dev = self;
107961a253cStsutsui
108961a253cStsutsui sacpcic_attach_common(psc, sc, aux, j720_socket_setup);
10910c7bfc7Sbsh }
11010c7bfc7Sbsh
11110c7bfc7Sbsh static void
j720_socket_setup(struct sapcic_socket * sp)11210c7bfc7Sbsh j720_socket_setup(struct sapcic_socket *sp)
11310c7bfc7Sbsh {
11410c7bfc7Sbsh int *ip;
11510c7bfc7Sbsh struct platid_data *p;
11610c7bfc7Sbsh int socket = sp->socket;
11710c7bfc7Sbsh
11810c7bfc7Sbsh p = platid_search_data(&platid, sacpcic_platid_table);
11910c7bfc7Sbsh
12010c7bfc7Sbsh if (p == NULL) {
12110c7bfc7Sbsh sp->power_capability = SAPCIC_POWER_5V;
12210c7bfc7Sbsh } else {
12310c7bfc7Sbsh ip = (int *)p->data;
12410c7bfc7Sbsh sp->power_capability = ip[socket];
12510c7bfc7Sbsh }
12610c7bfc7Sbsh
12710c7bfc7Sbsh sp->pcictag = &j720_sacpcic_functions;
12810c7bfc7Sbsh }
12910c7bfc7Sbsh
13010c7bfc7Sbsh static void
j720_set_power(struct sapcic_socket * so,int arg)131018931a9Speter j720_set_power(struct sapcic_socket *so, int arg)
13210c7bfc7Sbsh {
13310c7bfc7Sbsh int newval, oldval, s;
13410c7bfc7Sbsh struct sacc_softc *sc = so->pcictag_cookie;
13510c7bfc7Sbsh
13610c7bfc7Sbsh /* XXX this isn't well confirmed. DANGER DANGER */
13710c7bfc7Sbsh switch (arg) {
13810c7bfc7Sbsh case SAPCIC_POWER_OFF:
13910c7bfc7Sbsh newval = 0;
14010c7bfc7Sbsh break;
14110c7bfc7Sbsh case SAPCIC_POWER_3V:
14210c7bfc7Sbsh newval = 2;
14310c7bfc7Sbsh break;
14410c7bfc7Sbsh case SAPCIC_POWER_5V:
14510c7bfc7Sbsh newval = 1;
14610c7bfc7Sbsh break;
14710c7bfc7Sbsh default:
148018931a9Speter panic("j720_set_power: bogus arg (%d)", arg);
14910c7bfc7Sbsh }
15010c7bfc7Sbsh
15110c7bfc7Sbsh s = splbio();
152018931a9Speter oldval = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR);
153018931a9Speter
15410c7bfc7Sbsh switch (so->socket) {
15510c7bfc7Sbsh case 0:
15610c7bfc7Sbsh newval = newval | (oldval & 0xc);
15710c7bfc7Sbsh break;
15810c7bfc7Sbsh case 1:
15910c7bfc7Sbsh newval = (newval << 2) | (oldval & 3);
16010c7bfc7Sbsh break;
16110c7bfc7Sbsh default:
16210c7bfc7Sbsh splx(s);
163018931a9Speter panic("j720_set_power: bogus socket (%d)", so->socket);
16410c7bfc7Sbsh }
16510c7bfc7Sbsh bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, newval);
16610c7bfc7Sbsh splx(s);
16710c7bfc7Sbsh }
168