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