1 /* $NetBSD: j720pcic.c,v 1.7 2010/08/19 15:17:53 tsutsui 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.7 2010/08/19 15:17:53 tsutsui 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/malloc.h> 46 47 #include <machine/bus.h> 48 #include <machine/platid.h> 49 #include <machine/platid_mask.h> 50 51 #include <dev/pcmcia/pcmciachip.h> 52 #include <dev/pcmcia/pcmciavar.h> 53 54 #include <arm/sa11x0/sa11x0_reg.h> 55 #include <arm/sa11x0/sa11x0_var.h> 56 #include <arm/sa11x0/sa1111_reg.h> 57 #include <arm/sa11x0/sa1111_var.h> 58 #include <arm/sa11x0/sa11x1_pcicreg.h> 59 #include <arm/sa11x0/sa11xx_pcicvar.h> 60 #include <arm/sa11x0/sa11x1_pcicvar.h> 61 62 #include "sacpcic.h" 63 64 static int sacpcic_match(device_t, cfdata_t, void *); 65 static void sacpcic_attach(device_t, device_t, void *); 66 67 static void j720_socket_setup(struct sapcic_socket *); 68 static void j720_set_power(struct sapcic_socket *, int); 69 70 static struct sapcic_tag j720_sacpcic_functions = { 71 sacpcic_read, 72 sacpcic_write, 73 j720_set_power, 74 sacpcic_clear_intr, 75 sacpcic_intr_establish, 76 sacpcic_intr_disestablish 77 }; 78 79 static int j720_power_capability[] = { 80 SAPCIC_POWER_5V | SAPCIC_POWER_3V, SAPCIC_POWER_3V 81 }; 82 83 static struct platid_data sacpcic_platid_table[] = { 84 { &platid_mask_MACH_HP_JORNADA_7XX, j720_power_capability }, 85 { NULL, NULL } 86 }; 87 88 CFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc), 89 sacpcic_match, sacpcic_attach, NULL, NULL); 90 91 92 static int 93 sacpcic_match(device_t parent, cfdata_t cf, void *aux) 94 { 95 96 return 1; 97 } 98 99 static void 100 sacpcic_attach(device_t parent, device_t self, void *aux) 101 { 102 struct sacc_softc *psc; 103 struct sacpcic_softc *sc; 104 105 psc = device_private(parent); 106 sc = device_private(self); 107 sc->sc_pc.sc_dev = self; 108 109 sacpcic_attach_common(psc, sc, aux, j720_socket_setup); 110 } 111 112 static void 113 j720_socket_setup(struct sapcic_socket *sp) 114 { 115 int *ip; 116 struct platid_data *p; 117 int socket = sp->socket; 118 119 p = platid_search_data(&platid, sacpcic_platid_table); 120 121 if (p == NULL) { 122 sp->power_capability = SAPCIC_POWER_5V; 123 } else { 124 ip = (int *)p->data; 125 sp->power_capability = ip[socket]; 126 } 127 128 sp->pcictag = &j720_sacpcic_functions; 129 } 130 131 static void 132 j720_set_power(struct sapcic_socket *so, int arg) 133 { 134 int newval, oldval, s; 135 struct sacc_softc *sc = so->pcictag_cookie; 136 137 /* XXX this isn't well confirmed. DANGER DANGER */ 138 switch (arg) { 139 case SAPCIC_POWER_OFF: 140 newval = 0; 141 break; 142 case SAPCIC_POWER_3V: 143 newval = 2; 144 break; 145 case SAPCIC_POWER_5V: 146 newval = 1; 147 break; 148 default: 149 panic("j720_set_power: bogus arg (%d)", arg); 150 } 151 152 s = splbio(); 153 oldval = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR); 154 155 switch (so->socket) { 156 case 0: 157 newval = newval | (oldval & 0xc); 158 break; 159 case 1: 160 newval = (newval << 2) | (oldval & 3); 161 break; 162 default: 163 splx(s); 164 panic("j720_set_power: bogus socket (%d)", so->socket); 165 } 166 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, newval); 167 splx(s); 168 } 169