lubbock_pcic.c revision 1.7
1/* $NetBSD: lubbock_pcic.c,v 1.7 2011/07/01 20:42:37 dyoung 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.7 2011/07/01 20:42:37 dyoung 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 <sys/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 60static int sacpcic_match(device_t, cfdata_t, void *); 61static void sacpcic_attach(device_t, device_t, void *); 62static void lubbock_set_power(struct sapcic_socket *so, int arg); 63static void lubbock_socket_setup(struct sapcic_socket *sp); 64 65static 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 74CFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc), 75 sacpcic_match, sacpcic_attach, NULL, NULL); 76 77static int 78sacpcic_match(device_t parent, cfdata_t cf, void *aux) 79{ 80 return (1); 81} 82 83static void 84lubbock_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 90static void 91sacpcic_attach(device_t parent, device_t self, void *aux) 92{ 93 struct sacpcic_softc *sc = device_private(self); 94 95 sc->sc_pc.sc_dev = self; 96 sacpcic_attach_common(device_private(parent), 97 sc, aux, lubbock_socket_setup); 98} 99 100 101static void 102lubbock_set_power(struct sapcic_socket *so, int arg) 103{ 104 struct sacc_softc *sc = so->pcictag_cookie; 105 struct obio_softc *bsc = device_private(device_parent(sc->sc_dev)); 106 int s; 107 uint16_t tmp; 108 109 static const uint8_t vval_socket0[] = { 110 /* for socket0 (pcmcia) */ 111 0x00, /* OFF */ 112 0x08, /* 3.3V */ 113 0x05, /* 5V */ 114 }; 115 static const uint16_t vval_socket1[] = { 116 /* for socket1 (CF) */ 117 0x0000, /* OFF */ 118 0x8000, /* 3.3V */ 119 0x4000, /* 5V */ 120 }; 121 122 if( arg < 0 || SAPCIC_POWER_5V < arg ) 123 panic("sacpcic_set_power: bogus arg\n"); 124 125 switch( so->socket ){ 126 case 0: 127 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR, 128 vval_socket0[arg]); 129 break; 130 case 1: 131 s = splhigh(); 132 tmp = bus_space_read_2(bsc->sc_iot, bsc->sc_obioreg_ioh, 133 LUBBOCK_MISCWR); 134 bus_space_write_2(bsc->sc_iot, bsc->sc_obioreg_ioh, 135 LUBBOCK_MISCWR, (tmp & 0x3fff) | vval_socket1[arg] ); 136 splx(s); 137 break; 138 default: 139 aprint_normal("unknown socket number: %d\n", so->socket); 140 } 141} 142