1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
11 * Copyright (C) 2008 by Frank Gevaerts
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
26 #include "config.h" /* for HAVE_MULTIDRIVE or not */
29 #if (CONFIG_STORAGE & STORAGE_SD)
32 #if (CONFIG_STORAGE & STORAGE_MMC)
35 #if (CONFIG_STORAGE & STORAGE_ATA)
38 #if (CONFIG_STORAGE & STORAGE_NAND)
41 #if (CONFIG_STORAGE & STORAGE_RAMDISK)
47 unsigned int sector_size
;
48 unsigned int num_sectors
;
54 #if (CONFIG_STORAGE == 0)
55 /* stubs for the plugin api */
56 static inline void stub_storage_sleep(void) {}
57 static inline void stub_storage_spin(void) {}
58 static inline void stub_storage_spindown(int timeout
) { (void)timeout
; }
61 #if defined(CONFIG_STORAGE) && !defined(CONFIG_STORAGE_MULTI)
62 /* storage_spindown, storage_sleep and storage_spin are passed as
63 * pointers, which doesn't work with argument-macros.
65 #define storage_num_drives() NUM_DRIVES
66 #if (CONFIG_STORAGE == 0) /* application */
67 #define STORAGE_FUNCTION(NAME) (stub_## NAME)
68 #define storage_spindown stub_storage_spindown
69 #define storage_sleep stub_storage_sleep
70 #define storage_spin stub_storage_spin
72 #define storage_enable(on)
73 #define storage_sleepnow()
74 #define storage_disk_is_active()
75 #define storage_soft_reset()
76 #define storage_init()
77 #define storage_close()
78 #elif (CONFIG_STORAGE & STORAGE_ATA)
79 #define STORAGE_FUNCTION(NAME) (ata_## NAME)
80 #define storage_spindown ata_spindown
81 #define storage_sleep ata_sleep
82 #define storage_spin ata_spin
84 #define storage_enable(on) ata_enable(on)
85 #define storage_sleepnow() ata_sleepnow()
86 #define storage_disk_is_active() ata_disk_is_active()
87 #define storage_soft_reset() ata_soft_reset()
88 #define storage_init() ata_init()
89 #define storage_close() ata_close()
90 #ifdef HAVE_STORAGE_FLUSH
91 #define storage_flush() (void)0
93 #define storage_last_disk_activity() ata_last_disk_activity()
94 #define storage_spinup_time() ata_spinup_time()
95 #define storage_get_identify() ata_get_identify()
97 #ifdef STORAGE_GET_INFO
98 #define storage_get_info(drive, info) ata_get_info(IF_MD2(drive,) info)
101 #define storage_removable(drive) ata_removable(IF_MD(drive))
102 #define storage_present(drive) ata_present(IF_MD(drive))
104 #elif (CONFIG_STORAGE & STORAGE_SD)
105 #define STORAGE_FUNCTION(NAME) (sd_## NAME)
106 #define storage_spindown sd_spindown
107 #define storage_sleep sd_sleep
108 #define storage_spin sd_spin
110 #define storage_enable(on) sd_enable(on)
111 #define storage_sleepnow() sd_sleepnow()
112 #define storage_disk_is_active() 0
113 #define storage_soft_reset() (void)0
114 #define storage_init() sd_init()
115 #ifdef HAVE_STORAGE_FLUSH
116 #define storage_flush() (void)0
118 #define storage_last_disk_activity() sd_last_disk_activity()
119 #define storage_spinup_time() 0
120 #define storage_get_identify() sd_get_identify()
122 #ifdef STORAGE_GET_INFO
123 #define storage_get_info(drive, info) sd_get_info(IF_MD2(drive,) info)
126 #define storage_removable(drive) sd_removable(IF_MD(drive))
127 #define storage_present(drive) sd_present(IF_MD(drive))
129 #elif (CONFIG_STORAGE & STORAGE_MMC)
130 #define STORAGE_FUNCTION(NAME) (mmc_## NAME)
131 #define storage_spindown mmc_spindown
132 #define storage_sleep mmc_sleep
133 #define storage_spin mmc_spin
135 #define storage_enable(on) mmc_enable(on)
136 #define storage_sleepnow() mmc_sleepnow()
137 #define storage_disk_is_active() mmc_disk_is_active()
138 #define storage_soft_reset() (void)0
139 #define storage_init() mmc_init()
140 #ifdef HAVE_STORAGE_FLUSH
141 #define storage_flush() (void)0
143 #define storage_last_disk_activity() mmc_last_disk_activity()
144 #define storage_spinup_time() 0
145 #define storage_get_identify() mmc_get_identify()
147 #ifdef STORAGE_GET_INFO
148 #define storage_get_info(drive, info) mmc_get_info(IF_MD2(drive,) info)
151 #define storage_removable(drive) mmc_removable(IF_MD(drive))
152 #define storage_present(drive) mmc_present(IF_MD(drive))
154 #elif (CONFIG_STORAGE & STORAGE_NAND)
155 #define STORAGE_FUNCTION(NAME) (nand_## NAME)
156 #define storage_spindown nand_spindown
157 #define storage_sleep nand_sleep
158 #define storage_spin nand_spin
160 #define storage_enable(on) (void)0
161 #define storage_sleepnow() nand_sleepnow()
162 #define storage_disk_is_active() 0
163 #define storage_soft_reset() (void)0
164 #define storage_init() nand_init()
165 #ifdef HAVE_STORAGE_FLUSH
166 #define storage_flush() nand_flush()
168 #define storage_last_disk_activity() nand_last_disk_activity()
169 #define storage_spinup_time() 0
170 #define storage_get_identify() nand_get_identify()
172 #ifdef STORAGE_GET_INFO
173 #define storage_get_info(drive, info) nand_get_info(IF_MD2(drive,) info)
176 #define storage_removable(drive) nand_removable(IF_MD(drive))
177 #define storage_present(drive) nand_present(IF_MD(drive))
179 #elif (CONFIG_STORAGE & STORAGE_RAMDISK)
180 #define STORAGE_FUNCTION(NAME) (ramdisk_## NAME)
181 #define storage_spindown ramdisk_spindown
182 #define storage_sleep ramdisk_sleep
183 #define storage_spin ramdisk_spin
185 #define storage_enable(on) (void)0
186 #define storage_sleepnow() ramdisk_sleepnow()
187 #define storage_disk_is_active() 0
188 #define storage_soft_reset() (void)0
189 #define storage_init() ramdisk_init()
190 #ifdef HAVE_STORAGE_FLUSH
191 #define storage_flush() (void)0
193 #define storage_last_disk_activity() ramdisk_last_disk_activity()
194 #define storage_spinup_time() 0
195 #define storage_get_identify() ramdisk_get_identify()
197 #ifdef STORAGE_GET_INFO
198 #define storage_get_info(drive, info) ramdisk_get_info(IF_MD2(drive,) info)
201 #define storage_removable(drive) ramdisk_removable(IF_MD(drive))
202 #define storage_present(drive) ramdisk_present(IF_MD(drive))
205 //#error No storage driver!
207 #else /* NOT CONFIG_STORAGE_MULTI and PLATFORM_NATIVE*/
209 /* Simulator and multi-driver use normal functions */
211 void storage_enable(bool on
);
212 void storage_sleep(void);
213 void storage_sleepnow(void);
214 bool storage_disk_is_active(void);
215 int storage_soft_reset(void);
216 int storage_init(void);
217 int storage_flush(void);
218 void storage_spin(void);
219 void storage_spindown(int seconds
);
220 long storage_last_disk_activity(void);
221 int storage_spinup_time(void);
222 int storage_num_drives(void);
223 #ifdef STORAGE_GET_INFO
224 void storage_get_info(int drive
, struct storage_info
*info
);
227 bool storage_removable(int drive
);
228 bool storage_present(int drive
);
231 #endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/
233 int storage_read_sectors(IF_MD2(int drive
,) unsigned long start
, int count
, void* buf
);
234 int storage_write_sectors(IF_MD2(int drive
,) unsigned long start
, int count
, const void* buf
);