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