Home | History | Annotate | Line # | Download | only in ic
      1  1.3       jdc /* $NetBSD: w83l518d.c,v 1.3 2020/05/11 14:55:20 jdc 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.3       jdc __KERNEL_RCSID(0, "$NetBSD: w83l518d.c,v 1.3 2020/05/11 14:55:20 jdc 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/ic/w83l518dreg.h>
     43  1.1  jmcneill #include <dev/ic/w83l518dvar.h>
     44  1.1  jmcneill #include <dev/ic/w83l518d_sdmmc.h>
     45  1.1  jmcneill 
     46  1.1  jmcneill uint8_t
     47  1.1  jmcneill wb_idx_read(struct wb_softc *wb, uint8_t reg)
     48  1.1  jmcneill {
     49  1.1  jmcneill 	bus_space_write_1(wb->wb_iot, wb->wb_ioh, WB_SD_INDEX, reg);
     50  1.1  jmcneill 	return bus_space_read_1(wb->wb_iot, wb->wb_ioh, WB_SD_DATA);
     51  1.1  jmcneill }
     52  1.1  jmcneill 
     53  1.1  jmcneill void
     54  1.1  jmcneill wb_idx_write(struct wb_softc *wb, uint8_t reg, uint8_t val)
     55  1.1  jmcneill {
     56  1.1  jmcneill 	bus_space_write_1(wb->wb_iot, wb->wb_ioh, WB_SD_INDEX, reg);
     57  1.1  jmcneill 	bus_space_write_1(wb->wb_iot, wb->wb_ioh, WB_SD_DATA, val);
     58  1.1  jmcneill }
     59  1.1  jmcneill 
     60  1.1  jmcneill uint8_t
     61  1.1  jmcneill wb_read(struct wb_softc *wb, uint8_t reg)
     62  1.1  jmcneill {
     63  1.1  jmcneill 	return bus_space_read_1(wb->wb_iot, wb->wb_ioh, reg);
     64  1.1  jmcneill }
     65  1.1  jmcneill 
     66  1.1  jmcneill void
     67  1.1  jmcneill wb_write(struct wb_softc *wb, uint8_t reg, uint8_t val)
     68  1.1  jmcneill {
     69  1.1  jmcneill 	bus_space_write_1(wb->wb_iot, wb->wb_ioh, reg, val);
     70  1.1  jmcneill }
     71  1.1  jmcneill 
     72  1.1  jmcneill void
     73  1.1  jmcneill wb_led(struct wb_softc *wb, bool enable)
     74  1.1  jmcneill {
     75  1.1  jmcneill 	uint8_t val;
     76  1.1  jmcneill 
     77  1.1  jmcneill 	val = wb_read(wb, WB_SD_CSR);
     78  1.1  jmcneill 	if (enable)
     79  1.1  jmcneill 		val |= WB_CSR_MS_LED;
     80  1.1  jmcneill 	else
     81  1.1  jmcneill 		val &= ~WB_CSR_MS_LED;
     82  1.1  jmcneill 	wb_write(wb, WB_SD_CSR, val);
     83  1.1  jmcneill }
     84  1.1  jmcneill 
     85  1.1  jmcneill void
     86  1.1  jmcneill wb_attach(struct wb_softc *wb)
     87  1.1  jmcneill {
     88  1.1  jmcneill 	switch (wb->wb_type) {
     89  1.1  jmcneill 	case WB_DEVNO_SD:
     90  1.1  jmcneill 		aprint_verbose_dev(wb->wb_dev,
     91  1.1  jmcneill 		    "SD/MMC Reader\n");
     92  1.1  jmcneill 		wb_sdmmc_attach(wb);
     93  1.1  jmcneill 		break;
     94  1.1  jmcneill 	case WB_DEVNO_MS:
     95  1.1  jmcneill 		aprint_verbose_dev(wb->wb_dev,
     96  1.1  jmcneill 		    "Memory Stick Reader (not supported)\n");
     97  1.1  jmcneill 		break;
     98  1.1  jmcneill 	case WB_DEVNO_SC:
     99  1.1  jmcneill 		aprint_verbose_dev(wb->wb_dev,
    100  1.1  jmcneill 		    "Smart Card Reader (not supported)\n");
    101  1.1  jmcneill 		break;
    102  1.1  jmcneill 	case WB_DEVNO_GPIO:
    103  1.1  jmcneill 		aprint_verbose_dev(wb->wb_dev,
    104  1.1  jmcneill 		    "GPIO (not supported)\n");
    105  1.1  jmcneill 		break;
    106  1.1  jmcneill 	}
    107  1.1  jmcneill }
    108  1.1  jmcneill 
    109  1.1  jmcneill int
    110  1.1  jmcneill wb_detach(struct wb_softc *wb, int flags)
    111  1.1  jmcneill {
    112  1.1  jmcneill 	switch (wb->wb_type) {
    113  1.1  jmcneill 	case WB_DEVNO_SD:
    114  1.1  jmcneill 		wb_sdmmc_detach(wb, flags);
    115  1.1  jmcneill 		break;
    116  1.1  jmcneill 	}
    117  1.1  jmcneill 
    118  1.1  jmcneill 	return 0;
    119  1.1  jmcneill }
    120  1.1  jmcneill 
    121  1.1  jmcneill /*
    122  1.1  jmcneill  * intr handler
    123  1.1  jmcneill  */
    124  1.1  jmcneill int
    125  1.1  jmcneill wb_intr(void *opaque)
    126  1.1  jmcneill {
    127  1.1  jmcneill 	struct wb_softc *wb = opaque;
    128  1.1  jmcneill 
    129  1.1  jmcneill 	switch (wb->wb_type) {
    130  1.1  jmcneill 	case WB_DEVNO_SD:
    131  1.1  jmcneill 		return wb_sdmmc_intr(wb);
    132  1.1  jmcneill 		break;
    133  1.1  jmcneill 	}
    134  1.1  jmcneill 
    135  1.1  jmcneill 	return 0;
    136  1.1  jmcneill }
    137  1.2  jmcneill 
    138  1.2  jmcneill /*
    139  1.2  jmcneill  * pmf
    140  1.2  jmcneill  */
    141  1.2  jmcneill bool
    142  1.2  jmcneill wb_suspend(struct wb_softc *wb)
    143  1.2  jmcneill {
    144  1.2  jmcneill 	if (wb->wb_type == WB_DEVNO_SD)
    145  1.2  jmcneill 		return wb_sdmmc_suspend(wb);
    146  1.2  jmcneill 
    147  1.2  jmcneill 	return false;
    148  1.2  jmcneill }
    149  1.2  jmcneill 
    150  1.2  jmcneill bool
    151  1.2  jmcneill wb_resume(struct wb_softc *wb)
    152  1.2  jmcneill {
    153  1.2  jmcneill 	if (wb->wb_type == WB_DEVNO_SD)
    154  1.2  jmcneill 		return wb_sdmmc_resume(wb);
    155  1.2  jmcneill 
    156  1.2  jmcneill 	return false;
    157  1.2  jmcneill }
    158