fix reds
[kugel-rb.git] / firmware / export / storage.h
blob8a0219c52313c6c53dde309e82a50b801d387549
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #ifndef __STORAGE_H__
23 #define __STORAGE_H__
25 #include <stdbool.h>
26 #include "config.h" /* for HAVE_MULTIVOLUME or not */
27 #include "mv.h"
29 #if (CONFIG_STORAGE & STORAGE_SD)
30 #include "sd.h"
31 #endif
32 #if (CONFIG_STORAGE & STORAGE_MMC)
33 #include "mmc.h"
34 #endif
35 #if (CONFIG_STORAGE & STORAGE_ATA)
36 #include "ata.h"
37 #endif
38 #if (CONFIG_STORAGE & STORAGE_NAND)
39 #include "nand.h"
40 #endif
42 struct storage_info
44 unsigned int sector_size;
45 unsigned int num_sectors;
46 char *vendor;
47 char *product;
48 char *revision;
51 void storage_spindown(int seconds);
53 static inline void storage_enable(bool on)
55 #if (CONFIG_STORAGE & STORAGE_ATA)
56 ata_enable(on);
57 #elif (CONFIG_STORAGE & STORAGE_SD)
58 sd_enable(on);
59 #elif (CONFIG_STORAGE & STORAGE_MMC)
60 mmc_enable(on);
61 #else
62 (void)on;
63 #endif
65 static inline void storage_sleep(void)
67 #if (CONFIG_STORAGE & STORAGE_ATA)
68 ata_sleep();
69 #endif
71 static inline void storage_sleepnow(void)
73 #if (CONFIG_STORAGE & STORAGE_ATA)
74 ata_sleepnow();
75 #endif
77 static inline bool storage_disk_is_active(void)
79 #if (CONFIG_STORAGE & STORAGE_ATA)
80 return ata_disk_is_active();
81 #elif (CONFIG_STORAGE & STORAGE_MMC)
82 return mmc_disk_is_active();
83 #else
84 return 0;
85 #endif
87 static inline int storage_hard_reset(void)
89 #if (CONFIG_STORAGE & STORAGE_ATA)
90 return ata_hard_reset();
91 #else
92 return 0;
93 #endif
95 static inline int storage_soft_reset(void)
97 #if (CONFIG_STORAGE & STORAGE_ATA)
98 return ata_soft_reset();
99 #else
100 return 0;
101 #endif
103 static inline int storage_init(void)
105 #ifndef SIMULATOR
106 #if (CONFIG_STORAGE & STORAGE_ATA)
107 return ata_init();
108 #elif (CONFIG_STORAGE & STORAGE_SD)
109 return sd_init();
110 #elif (CONFIG_STORAGE & STORAGE_NAND)
111 return nand_init();
112 #elif (CONFIG_STORAGE & STORAGE_MMC)
113 return mmc_init();
114 #else
115 #error No storage driver!
116 #endif
117 #else
118 return 0;
119 #endif
121 static inline void storage_close(void)
123 #if (CONFIG_STORAGE & STORAGE_ATA)
124 ata_close();
125 #endif
127 static inline int storage_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf)
129 #if (CONFIG_STORAGE & STORAGE_ATA)
130 return ata_read_sectors(IF_MV2(drive,) start, count, buf);
131 #elif (CONFIG_STORAGE & STORAGE_SD)
132 return sd_read_sectors(IF_MV2(drive,) start, count, buf);
133 #elif (CONFIG_STORAGE & STORAGE_NAND)
134 return nand_read_sectors(IF_MV2(drive,) start, count, buf);
135 #elif (CONFIG_STORAGE & STORAGE_MMC)
136 return mmc_read_sectors(IF_MV2(drive,) start, count, buf);
137 #else
138 #error No storage driver!
139 #endif
141 static inline int storage_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf)
143 #if (CONFIG_STORAGE & STORAGE_ATA)
144 return ata_write_sectors(IF_MV2(drive,) start, count, buf);
145 #elif (CONFIG_STORAGE & STORAGE_SD)
146 return sd_write_sectors(IF_MV2(drive,) start, count, buf);
147 #elif (CONFIG_STORAGE & STORAGE_NAND)
148 return nand_write_sectors(IF_MV2(drive,) start, count, buf);
149 #elif (CONFIG_STORAGE & STORAGE_MMC)
150 return mmc_write_sectors(IF_MV2(drive,) start, count, buf);
151 #else
152 #error No storage driver!
153 #endif
155 static inline void storage_spin(void)
157 #if (CONFIG_STORAGE & STORAGE_ATA)
158 ata_spin();
159 #endif
162 #if (CONFIG_LED == LED_REAL)
163 static inline void storage_set_led_enabled(bool enabled)
165 #if (CONFIG_STORAGE & STORAGE_ATA)
166 ata_set_led_enabled(enabled);
167 #elif (CONFIG_STORAGE & STORAGE_SD)
168 sd_set_led_enabled(enabled);
169 #elif (CONFIG_STORAGE & STORAGE_NAND)
170 nand_set_led_enabled(enabled);
171 #elif (CONFIG_STORAGE & STORAGE_MMC)
172 mmc_set_led_enabled(enabled);
173 #else
174 #error No storage driver!
175 #endif
177 #endif
179 static inline long storage_last_disk_activity(void)
181 #if (CONFIG_STORAGE & STORAGE_ATA)
182 return ata_last_disk_activity();
183 #elif (CONFIG_STORAGE & STORAGE_SD)
184 return sd_last_disk_activity();
185 #elif (CONFIG_STORAGE & STORAGE_NAND)
186 return nand_last_disk_activity();
187 #elif (CONFIG_STORAGE & STORAGE_MMC)
188 return mmc_last_disk_activity();
189 #else
190 #error No storage driver!
191 #endif
194 static inline int storage_spinup_time(void)
196 #if (CONFIG_STORAGE & STORAGE_ATA)
197 return ata_spinup_time();
198 #else
199 return 0;
200 #endif
203 static inline void storage_get_info(IF_MV2(int drive,) struct storage_info *info)
205 #if (CONFIG_STORAGE & STORAGE_ATA)
206 return ata_get_info(IF_MV2(drive,) info);
207 #elif (CONFIG_STORAGE & STORAGE_SD)
208 return sd_get_info(IF_MV2(drive,) info);
209 #elif (CONFIG_STORAGE & STORAGE_NAND)
210 return nand_get_info(IF_MV2(drive,) info);
211 #elif (CONFIG_STORAGE & STORAGE_MMC)
212 return mmc_get_info(IF_MV2(drive,) info);
213 #else
214 #error No storage driver!
215 #endif
218 #ifdef HAVE_HOTSWAP
219 static inline bool storage_removable(IF_MV_NONVOID(int drive))
221 #if (CONFIG_STORAGE & STORAGE_ATA)
222 return ata_removable(IF_MV(drive));
223 #elif (CONFIG_STORAGE & STORAGE_SD)
224 return sd_removable(IF_MV(drive));
225 #elif (CONFIG_STORAGE & STORAGE_NAND)
226 return nand_removable(IF_MV(drive));
227 #elif (CONFIG_STORAGE & STORAGE_MMC)
228 return mmc_removable(IF_MV(drive));
229 #else
230 #error No storage driver!
231 #endif
234 static inline bool storage_present(IF_MV_NONVOID(int drive))
236 #if (CONFIG_STORAGE & STORAGE_ATA)
237 return ata_present(IF_MV(drive));
238 #elif (CONFIG_STORAGE & STORAGE_SD)
239 return sd_present(IF_MV(drive));
240 #elif (CONFIG_STORAGE & STORAGE_NAND)
241 return nand_present(IF_MV(drive));
242 #elif (CONFIG_STORAGE & STORAGE_MMC)
243 return mmc_present(IF_MV(drive));
244 #else
245 #error No storage driver!
246 #endif
248 #endif
249 #endif