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