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