GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / dev / dev_atapi.c
blob0813063f2f088e88e8bf2589a03801cb3df1fb47
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * ATAPI device driver File: dev_atapi.c
5 *
6 * This is a simple driver for ATAPI devices. The disks
7 * are expected to be connected to the generic bus (this
8 * driver doesn't support PCI).
9 *
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 *********************************************************************
14 * Copyright 2000,2001,2002,2003
15 * Broadcom Corporation. All rights reserved.
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions
26 * as they appear in the source file.
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. The "Broadcom Corporation"
30 * name may not be used to endorse or promote products derived
31 * from this software without the prior written permission of
32 * Broadcom Corporation.
34 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46 * THE POSSIBILITY OF SUCH DAMAGE.
47 ********************************************************************* */
50 #include "sbmips.h"
51 #include "lib_types.h"
52 #include "lib_malloc.h"
53 #include "lib_printf.h"
54 #include "lib_string.h"
55 #include "cfe_timer.h"
56 #include "cfe_iocb.h"
57 #include "cfe_device.h"
58 #include "cfe_ioctl.h"
60 #include "dev_ide_common.h"
62 /* *********************************************************************
63 * Macros
64 ********************************************************************* */
66 #define GETWORD_LE(buf,wordidx) (((unsigned int) (buf)[(wordidx)*2]) + \
67 (((unsigned int) (buf)[(wordidx)*2+1]) << 8))
70 /* *********************************************************************
71 * Forward declarations
72 ********************************************************************* */
74 extern void _wbflush(void);
75 static void atapidrv_probe(cfe_driver_t *drv,
76 unsigned long probe_a, unsigned long probe_b,
77 void *probe_ptr);
80 const static cfe_devdisp_t atapidrv_dispatch = {
81 idecommon_open,
82 idecommon_read,
83 idecommon_inpstat,
84 idecommon_write,
85 idecommon_ioctl,
86 idecommon_close,
87 NULL,
88 NULL
91 const cfe_driver_t atapidrv = {
92 "ATAPI device",
93 "atapi",
94 CFE_DEV_DISK,
95 &atapidrv_dispatch,
96 atapidrv_probe
101 /* *********************************************************************
102 * Port I/O routines
104 * These routines are called back from the common code to do
105 * I/O cycles to the IDE disk. We provide routines for
106 * reading and writing bytes, words, and strings of words.
107 ********************************************************************* */
109 static uint8_t atapidrv_inb(idecommon_dispatch_t *disp,uint32_t reg)
111 return *((volatile uint8_t *) PHYS_TO_K1(reg+disp->baseaddr));
114 static uint16_t atapidrv_inw(idecommon_dispatch_t *disp,uint32_t reg)
116 return *((volatile uint16_t *) PHYS_TO_K1((reg+disp->baseaddr)));
119 static void atapidrv_ins(idecommon_dispatch_t *disp,uint32_t reg,uint8_t *buf,int len)
121 uint16_t data;
123 while (len > 0) {
124 data = *((volatile uint16_t *) PHYS_TO_K1(reg+disp->baseaddr));
126 #ifdef _BYTESWAP_
127 *buf++ = (data >> 8) & 0xFF;
128 *buf++ = (data & 0xFF);
129 #else
130 *buf++ = (data & 0xFF);
131 *buf++ = (data >> 8) & 0xFF;
132 #endif
133 len--;
134 len--;
139 static void atapidrv_outb(idecommon_dispatch_t *disp,uint32_t reg,uint8_t val)
141 *((volatile uint8_t *) PHYS_TO_K1(reg+disp->baseaddr)) = val;
142 _wbflush();
145 static void atapidrv_outw(idecommon_dispatch_t *disp,uint32_t reg,uint16_t val)
147 *((volatile uint16_t *) PHYS_TO_K1(reg+disp->baseaddr)) = val;
148 _wbflush();
151 static void atapidrv_outs(idecommon_dispatch_t *disp,uint32_t reg,uint8_t *buf,int len)
153 uint16_t data;
155 while (len > 0) {
156 #ifdef _BYTESWAP_
157 data = (uint16_t) buf[1] + ((uint16_t) buf[0] << 8);
158 #else
159 data = (uint16_t) buf[0] + ((uint16_t) buf[1] << 8);
160 #endif
162 *((volatile uint16_t *) PHYS_TO_K1(reg+disp->baseaddr)) = data;
163 _wbflush();
165 buf++;
166 buf++;
167 len--;
168 len--;
174 static void atapidrv_probe(cfe_driver_t *drv,
175 unsigned long probe_a, unsigned long probe_b,
176 void *probe_ptr)
178 idecommon_t *softc;
179 idecommon_dispatch_t *disp;
180 char descr[80];
181 char unitstr[50];
182 int res;
185 * probe_a is the IDE base address
186 * probe_b is the unit number and other flags
187 * probe_ptr is unused.
190 softc = (idecommon_t *) KMALLOC(sizeof(idecommon_t),0);
191 disp = (idecommon_dispatch_t *) KMALLOC(sizeof(idecommon_dispatch_t),0);
193 if (softc && disp) {
194 softc->idecommon_addr = probe_a;
195 softc->idecommon_unit = probe_b;
197 disp->ref = softc;
198 disp->baseaddr = softc->idecommon_addr;
199 softc->idecommon_dispatch = disp;
201 disp->outb = atapidrv_outb;
202 disp->outw = atapidrv_outw;
203 disp->outs = atapidrv_outs;
205 disp->inb = atapidrv_inb;
206 disp->inw = atapidrv_inw;
207 disp->ins = atapidrv_ins;
209 res = idecommon_devprobe(softc);
210 if (res < 0) {
211 KFREE(softc);
212 KFREE(disp);
213 return;
216 xsprintf(descr,"%s unit %d at %08X",drv->drv_description,probe_b,probe_a);
217 xsprintf(unitstr,"%d",probe_b);
218 cfe_attach(drv,softc,unitstr,descr);