1 /* $OpenBSD: w83l518d.c,v 1.1 2009/10/03 19:51:53 kettenis Exp $ */ 2 /* $NetBSD: w83l518d.c,v 1.1 2009/09/30 20:44:50 jmcneill Exp $ */ 3 4 /* 5 * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/param.h> 30 #include <sys/kernel.h> 31 #include <sys/systm.h> 32 #include <sys/errno.h> 33 #include <sys/ioctl.h> 34 #include <sys/syslog.h> 35 #include <sys/device.h> 36 #include <sys/proc.h> 37 38 #include <machine/bus.h> 39 40 #include <dev/ic/w83l518dreg.h> 41 #include <dev/ic/w83l518dvar.h> 42 #include <dev/ic/w83l518d_sdmmc.h> 43 44 uint8_t 45 wb_idx_read(struct wb_softc *wb, uint8_t reg) 46 { 47 bus_space_write_1(wb->wb_iot, wb->wb_ioh, WB_SD_INDEX, reg); 48 return bus_space_read_1(wb->wb_iot, wb->wb_ioh, WB_SD_DATA); 49 } 50 51 void 52 wb_idx_write(struct wb_softc *wb, uint8_t reg, uint8_t val) 53 { 54 bus_space_write_1(wb->wb_iot, wb->wb_ioh, WB_SD_INDEX, reg); 55 bus_space_write_1(wb->wb_iot, wb->wb_ioh, WB_SD_DATA, val); 56 } 57 58 uint8_t 59 wb_read(struct wb_softc *wb, uint8_t reg) 60 { 61 return bus_space_read_1(wb->wb_iot, wb->wb_ioh, reg); 62 } 63 64 void 65 wb_write(struct wb_softc *wb, uint8_t reg, uint8_t val) 66 { 67 bus_space_write_1(wb->wb_iot, wb->wb_ioh, reg, val); 68 } 69 70 void 71 wb_led(struct wb_softc *wb, int enable) 72 { 73 uint8_t val; 74 75 val = wb_read(wb, WB_SD_CSR); 76 if (enable) 77 val |= WB_CSR_MS_LED; 78 else 79 val &= ~WB_CSR_MS_LED; 80 wb_write(wb, WB_SD_CSR, val); 81 } 82 83 void 84 wb_attach(struct wb_softc *wb) 85 { 86 switch (wb->wb_type) { 87 case WB_DEVNO_SD: 88 wb_sdmmc_attach(wb); 89 break; 90 case WB_DEVNO_MS: 91 break; 92 case WB_DEVNO_SC: 93 break; 94 case WB_DEVNO_GPIO: 95 break; 96 } 97 } 98 99 int 100 wb_detach(struct wb_softc *wb, int flags) 101 { 102 switch (wb->wb_type) { 103 case WB_DEVNO_SD: 104 wb_sdmmc_detach(wb, flags); 105 break; 106 } 107 108 return 0; 109 } 110 111 /* 112 * intr handler 113 */ 114 int 115 wb_intr(void *opaque) 116 { 117 struct wb_softc *wb = opaque; 118 119 switch (wb->wb_type) { 120 case WB_DEVNO_SD: 121 return wb_sdmmc_intr(wb); 122 break; 123 } 124 125 return 0; 126 } 127