summaryrefslogtreecommitdiff
path: root/firmware/export/storage.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/export/storage.h')
-rw-r--r--firmware/export/storage.h239
1 files changed, 239 insertions, 0 deletions
diff --git a/firmware/export/storage.h b/firmware/export/storage.h
new file mode 100644
index 0000000000..95e42f67f4
--- /dev/null
+++ b/firmware/export/storage.h
@@ -0,0 +1,239 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 * Copyright (C) 2008 by Frank Gevaerts
12 *
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.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#ifndef __STORAGE_H__
23#define __STORAGE_H__
24
25#include <stdbool.h>
26#include "config.h" /* for HAVE_MULTIVOLUME or not */
27#include "mv.h"
28
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
41
42struct storage_info
43{
44 unsigned int sector_size;
45 unsigned int num_sectors;
46 char *vendor;
47 char *product;
48 char *revision;
49};
50
51void storage_spindown(int seconds);
52
53static inline void storage_enable(bool on)
54{
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
64}
65static inline void storage_sleep(void)
66{
67#if (CONFIG_STORAGE & STORAGE_ATA)
68 ata_sleep();
69#endif
70}
71static inline void storage_sleepnow(void)
72{
73#if (CONFIG_STORAGE & STORAGE_ATA)
74 ata_sleepnow();
75#endif
76}
77static inline bool storage_disk_is_active(void)
78{
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
86}
87static inline int storage_hard_reset(void)
88{
89#if (CONFIG_STORAGE & STORAGE_ATA)
90 return ata_hard_reset();
91#else
92 return 0;
93#endif
94}
95static inline int storage_soft_reset(void)
96{
97#if (CONFIG_STORAGE & STORAGE_ATA)
98 return ata_soft_reset();
99#else
100 return 0;
101#endif
102}
103static inline int storage_init(void)
104{
105#if (CONFIG_STORAGE & STORAGE_ATA)
106 return ata_init();
107#elif (CONFIG_STORAGE & STORAGE_SD)
108 return sd_init();
109#elif (CONFIG_STORAGE & STORAGE_NAND)
110 return nand_init();
111#elif (CONFIG_STORAGE & STORAGE_MMC)
112 return mmc_init();
113#else
114 #error No storage driver!
115#endif
116}
117static inline int storage_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf)
118{
119#if (CONFIG_STORAGE & STORAGE_ATA)
120 return ata_read_sectors(IF_MV2(drive,) start, count, buf);
121#elif (CONFIG_STORAGE & STORAGE_SD)
122 return sd_read_sectors(IF_MV2(drive,) start, count, buf);
123#elif (CONFIG_STORAGE & STORAGE_NAND)
124 return nand_read_sectors(IF_MV2(drive,) start, count, buf);
125#elif (CONFIG_STORAGE & STORAGE_MMC)
126 return mmc_read_sectors(IF_MV2(drive,) start, count, buf);
127#else
128 #error No storage driver!
129#endif
130}
131static inline int storage_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const void* buf)
132{
133#if (CONFIG_STORAGE & STORAGE_ATA)
134 return ata_write_sectors(IF_MV2(drive,) start, count, buf);
135#elif (CONFIG_STORAGE & STORAGE_SD)
136 return sd_write_sectors(IF_MV2(drive,) start, count, buf);
137#elif (CONFIG_STORAGE & STORAGE_NAND)
138 return nand_write_sectors(IF_MV2(drive,) start, count, buf);
139#elif (CONFIG_STORAGE & STORAGE_MMC)
140 return mmc_write_sectors(IF_MV2(drive,) start, count, buf);
141#else
142 #error No storage driver!
143#endif
144}
145static inline void storage_spin(void)
146{
147#if (CONFIG_STORAGE & STORAGE_ATA)
148 ata_spin();
149#endif
150}
151
152#if (CONFIG_LED == LED_REAL)
153static inline void storage_set_led_enabled(bool enabled)
154{
155#if (CONFIG_STORAGE & STORAGE_ATA)
156 ata_set_led_enabled(enabled);
157#elif (CONFIG_STORAGE & STORAGE_SD)
158 sd_set_led_enabled(enabled);
159#elif (CONFIG_STORAGE & STORAGE_NAND)
160 nand_set_led_enabled(enabled);
161#elif (CONFIG_STORAGE & STORAGE_MMC)
162 mmc_set_led_enabled(enabled);
163#else
164 #error No storage driver!
165#endif
166}
167#endif
168
169static inline long storage_last_disk_activity(void)
170{
171#if (CONFIG_STORAGE & STORAGE_ATA)
172 return ata_last_disk_activity();
173#elif (CONFIG_STORAGE & STORAGE_SD)
174 return sd_last_disk_activity();
175#elif (CONFIG_STORAGE & STORAGE_NAND)
176 return nand_last_disk_activity();
177#elif (CONFIG_STORAGE & STORAGE_MMC)
178 return mmc_last_disk_activity();
179#else
180 #error No storage driver!
181#endif
182}
183
184static inline int storage_spinup_time(void)
185{
186#if (CONFIG_STORAGE & STORAGE_ATA)
187 return ata_spinup_time();
188#else
189 return 0;
190#endif
191}
192
193static inline void storage_get_info(IF_MV2(int drive,) struct storage_info *info)
194{
195#if (CONFIG_STORAGE & STORAGE_ATA)
196 return ata_get_info(IF_MV2(drive,) info);
197#elif (CONFIG_STORAGE & STORAGE_SD)
198 return sd_get_info(IF_MV2(drive,) info);
199#elif (CONFIG_STORAGE & STORAGE_NAND)
200 return nand_get_info(IF_MV2(drive,) info);
201#elif (CONFIG_STORAGE & STORAGE_MMC)
202 return mmc_get_info(IF_MV2(drive,) info);
203#else
204 #error No storage driver!
205#endif
206}
207
208#ifdef HAVE_HOTSWAP
209static inline bool storage_removable(IF_MV_NONVOID(int drive))
210{
211#if (CONFIG_STORAGE & STORAGE_ATA)
212 return ata_removable(IF_MV(drive));
213#elif (CONFIG_STORAGE & STORAGE_SD)
214 return sd_removable(IF_MV(drive));
215#elif (CONFIG_STORAGE & STORAGE_NAND)
216 return nand_removable(IF_MV(drive));
217#elif (CONFIG_STORAGE & STORAGE_MMC)
218 return mmc_removable(IF_MV(drive));
219#else
220 #error No storage driver!
221#endif
222}
223
224static inline bool storage_present(IF_MV_NONVOID(int drive))
225{
226#if (CONFIG_STORAGE & STORAGE_ATA)
227 return ata_present(IF_MV(drive));
228#elif (CONFIG_STORAGE & STORAGE_SD)
229 return sd_present(IF_MV(drive));
230#elif (CONFIG_STORAGE & STORAGE_NAND)
231 return nand_present(IF_MV(drive));
232#elif (CONFIG_STORAGE & STORAGE_MMC)
233 return mmc_present(IF_MV(drive));
234#else
235 #error No storage driver!
236#endif
237}
238#endif
239#endif