1 /* $NetBSD: lubbock_pcic.c,v 1.4 2008/04/28 20:23:17 martin 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 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: lubbock_pcic.c,v 1.4 2008/04/28 20:23:17 martin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/types.h> 38 #include <sys/conf.h> 39 #include <sys/file.h> 40 #include <sys/device.h> 41 #include <sys/kernel.h> 42 #include <sys/kthread.h> 43 #include <sys/malloc.h> 44 45 #include <machine/bus.h> 46 47 #include <dev/pcmcia/pcmciachip.h> 48 #include <dev/pcmcia/pcmciavar.h> 49 #include <arm/sa11x0/sa11x0_reg.h> 50 #include <arm/sa11x0/sa11x0_var.h> 51 #include <arm/sa11x0/sa1111_reg.h> 52 #include <arm/sa11x0/sa1111_var.h> 53 #include <arm/sa11x0/sa11x1_pcicreg.h> 54 #include <arm/sa11x0/sa11xx_pcicvar.h> 55 #include <arm/sa11x0/sa11x1_pcicvar.h> 56 57 #include <evbarm/lubbock/lubbock_reg.h> 58 #include <evbarm/lubbock/lubbock_var.h> 59 60 static int sacpcic_match(struct device *, struct cfdata *, void *); 61 static void sacpcic_attach(struct device *, struct device *, void *); 62 static void lubbock_set_power(struct sapcic_socket *so, int arg); 63 static void lubbock_socket_setup(struct sapcic_socket *sp); 64 65 static struct sapcic_tag lubbock_sacpcic_functions = { 66 sacpcic_read, 67 sacpcic_write, 68 lubbock_set_power, 69 sacpcic_clear_intr, 70 sacpcic_intr_establish, 71 sacpcic_intr_disestablish 72 }; 73 74 CFATTACH_DECL(sacpcic, sizeof(struct sacpcic_softc), 75 sacpcic_match, sacpcic_attach, NULL, NULL); 76 77 static int 78 sacpcic_match(struct device *parent, struct cfdata *cf, void *aux) 79 { 80 return (1); 81 } 82 83 static void 84 lubbock_socket_setup(struct sapcic_socket *sp) 85 { 86 sp->power_capability = SAPCIC_POWER_5V | SAPCIC_POWER_3V; 87 sp->pcictag = &lubbock_sacpcic_functions; 88 } 89 90 static void 91 sacpcic_attach(struct device *parent, struct device *self, void *aux) 92 { 93 sacpcic_attach_common((struct sacc_softc *)parent, 94 (struct sacpcic_softc *)self, aux, lubbock_socket_setup); 95 } 96 97 98 static void 99 lubbock_set_power(struct sapcic_socket *so, int arg) 100 { 101 struct sacc_softc *sc = so->pcictag_cookie; 102 struct obio_softc *bsc = 103 (struct obio_softc *)device_parent(&sc->sc_dev); 104 int s; 105 uint16_t tmp; 106 107 static const uint8_t vval_socket0[] = { 108 /* for socket0 (pcmcia) */ 109 0x00, /* OFF */ 110 0x08, /* 3.3V */ 111 0x05, /* 5V */ 112 }; 113 static const uint16_t vval_socket1[] = { 114 /* for socket1 (CF) */ 115 0x0000, /* OFF */ 116 0x8000, /* 3.3V */ 117 0x4000, /* 5V */ 118 }; 119 120 if( arg < 0 || SAPCIC_POWER_5V < arg ) 121 panic("sacpcic_set_power: bogus arg\n"); 122 123 switch( so->socket ){ 124 case 0: 125 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, 126 vval_socket0[arg]); 127 break; 128 case 1: 129 s = splhigh(); 130 tmp = bus_space_read_2(bsc->sc_iot, bsc->sc_obioreg_ioh, 131 LUBBOCK_MISCWR); 132 bus_space_write_2(bsc->sc_iot, bsc->sc_obioreg_ioh, 133 LUBBOCK_MISCWR, (tmp & 0x3fff) | vval_socket1[arg] ); 134 splx(s); 135 break; 136 default: 137 printf("unknown socket number: %d\n", so->socket); 138 } 139 } 140