summaryrefslogtreecommitdiffstats
path: root/firmware/export/storage.h
blob: 68867a98b118cd8baef6ad317fe85c5a36f4502c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002 by Alan Korr
 * Copyright (C) 2008 by Frank Gevaerts
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef __STORAGE_H__
#define __STORAGE_H__

#include <stdbool.h>
#include "config.h" /* for HAVE_MULTIVOLUME or not */
#include "mv.h"

#if (CONFIG_STORAGE & STORAGE_SD)
#include "sd.h"
#endif
#if (CONFIG_STORAGE & STORAGE_MMC)
#include "mmc.h"
#endif
#if (CONFIG_STORAGE & STORAGE_ATA)
#include "ata.h"
#endif
#if (CONFIG_STORAGE & STORAGE_NAND)
#include "nand.h"
#endif

struct storage_info
{
    unsigned int sector_size;
    unsigned int num_sectors;
    char *vendor;
    char *product;
    char *revision;
};

#ifndef SIMULATOR
    #ifndef CONFIG_STORAGE_MULTI
    /* storage_spindown, storage_sleep and storage_spin are passed as
     * pointers, which doesn't work with argument-macros.
     */
        #if (CONFIG_STORAGE & STORAGE_ATA)
            #define storage_spindown ata_spindown
            #define storage_sleep ata_sleep
            #define storage_spin ata_spin
    
            #define storage_enable(on) ata_enable(on)
            #define storage_sleepnow() ata_sleepnow()
            #define storage_disk_is_active() ata_disk_is_active()
            #define storage_hard_reset() ata_hard_reset()
            #define storage_soft_reset() ata_soft_reset()
            #define storage_init() ata_init()
            #define storage_close() ata_close()
            #define storage_read_sectors(drive, start, count, buf) ata_read_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_write_sectors(drive, start, count, buf) ata_write_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_last_disk_activity() ata_last_disk_activity()
            #define storage_spinup_time() ata_spinup_time()
            #define storage_get_identify() ata_get_identify()
    
            #if (CONFIG_LED == LED_REAL)
                #define storage_set_led_enabled(enabled) ata_set_led_enabled(enabled)
            #endif
            #ifdef STORAGE_GET_INFO
                #define storage_get_info(drive, info) ata_get_info(IF_MV2(drive,) info)
            #endif
            #ifdef HAVE_HOTSWAP
                #define storage_removable(drive) ata_removable(IF_MV(drive))
                #define storage_present(drive) ata_present(IF_MV(drive))
            #endif
        #elif (CONFIG_STORAGE & STORAGE_SD)
            #define storage_spindown sd_spindown
            #define storage_sleep sd_sleep
            #define storage_spin sd_spin
    
            #define storage_enable(on) sd_enable(on)
            #define storage_sleepnow() sd_sleepnow()
            #define storage_disk_is_active() 0
            #define storage_hard_reset() (void)0
            #define storage_soft_reset() (void)0
            #define storage_init() sd_init()
            #define storage_close() sd_close()
            #define storage_read_sectors(drive, start, count, buf) sd_read_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_write_sectors(drive, start, count, buf) sd_write_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_last_disk_activity() sd_last_disk_activity()
            #define storage_spinup_time() 0
            #define storage_get_identify() sd_get_identify()
    
            #if (CONFIG_LED == LED_REAL)
                #define storage_set_led_enabled(enabled) sd_set_led_enabled(enabled)
            #endif
            #ifdef STORAGE_GET_INFO
                #define storage_get_info(drive, info) sd_get_info(IF_MV2(drive,) info)
            #endif
            #ifdef HAVE_HOTSWAP
                #define storage_removable(drive) sd_removable(IF_MV(drive))
                #define storage_present(drive) sd_present(IF_MV(drive))
            #endif
         #elif (CONFIG_STORAGE & STORAGE_MMC)
            #define storage_spindown mmc_spindown
            #define storage_sleep mmc_sleep
            #define storage_spin mmc_spin
    
            #define storage_enable(on) mmc_enable(on)
            #define storage_sleepnow() mmc_sleepnow()
            #define storage_disk_is_active() mmc_disk_is_active()
            #define storage_hard_reset() (void)0
            #define storage_soft_reset() (void)0
            #define storage_init() mmc_init()
            #define storage_close() mmc_close()
            #define storage_read_sectors(drive, start, count, buf) mmc_read_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_write_sectors(drive, start, count, buf) mmc_write_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_last_disk_activity() mmc_last_disk_activity()
            #define storage_spinup_time() 0
            #define storage_get_identify() mmc_get_identify()
           
            #if (CONFIG_LED == LED_REAL)
                #define storage_set_led_enabled(enabled) mmc_set_led_enabled(enabled)
            #endif
            #ifdef STORAGE_GET_INFO
                #define storage_get_info(drive, info) mmc_get_info(IF_MV2(drive,) info)
            #endif
            #ifdef HAVE_HOTSWAP
                #define storage_removable(drive) mmc_removable(IF_MV(drive))
                #define storage_present(drive) mmc_present(IF_MV(drive))
            #endif
        #elif (CONFIG_STORAGE & STORAGE_NAND)
            #define storage_spindown nand_spindown
            #define storage_sleep nand_sleep
            #define storage_spin nand_spin
    
            #define storage_enable(on) (void)0
            #define storage_sleepnow() nand_sleepnow()
            #define storage_disk_is_active() 0
            #define storage_hard_reset() (void)0
            #define storage_soft_reset() (void)0
            #define storage_init() nand_init()
            #define storage_close() nand_close()
            #define storage_read_sectors(drive, start, count, buf) nand_read_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_write_sectors(drive, start, count, buf) nand_write_sectors(IF_MV2(drive,) start, count, buf)
            #define storage_last_disk_activity() nand_last_disk_activity()
            #define storage_spinup_time() 0
            #define storage_get_identify() nand_get_identify()
           
            #if (CONFIG_LED == LED_REAL)
                #define storage_set_led_enabled(enabled) nand_set_led_enabled(enabled)
            #endif
            #ifdef STORAGE_GET_INFO
                #define storage_get_info(drive, info) nand_get_info(IF_MV2(drive,) info)
            #endif
            #ifdef HAVE_HOTSWAP
                #define storage_removable(drive) nand_removable(IF_MV(drive))
                #define storage_present(drive) nand_present(IF_MV(drive))
            #endif
        #else
            //#error No storage driver!
        #endif
    #else /* NOT CONFIG_STORAGE_MULTI */
    
    /* TODO : implement multi-driver here */
    #error Multi-driver storage not implemented yet
    
    #endif /* NOT CONFIG_STORAGE_MULTI */
#else /*NOT SIMULATOR */
static inline void storage_enable(bool on)
{
    (void)on;
}
static inline void storage_sleep(void)
{
}
static inline void storage_sleepnow(void)
{
}
static inline bool storage_disk_is_active(void)
{
    return 0;
}
static inline int storage_hard_reset(void)
{
    return 0;
}
static inline int storage_soft_reset(void)
{
    return 0;
}
static inline int storage_init(void)
{
    return 0;
}
static inline void storage_close(void)
{
}
static inline int storage_read_sectors(int drive, unsigned long start, int count, void* buf)
{
    (void)drive;
    (void)start;
    (void)count;
    (void)buf;
    return 0;
}
static inline int storage_write_sectors(int drive, unsigned long start, int count, const void* buf)
{
    (void)drive;
    (void)start;
    (void)count;
    (void)buf;
    return 0;
}

static inline void storage_spin(void)
{
}
static inline void storage_spindown(int seconds)
{
    (void)seconds;
}
 
#if (CONFIG_LED == LED_REAL)
static inline void storage_set_led_enabled(bool enabled)
{
    (void)enabled;
}
#endif /*LED*/

static inline long storage_last_disk_activity(void)
{
    return 0;
}

static inline int storage_spinup_time(void)
{
    return 0;
}

#ifdef STORAGE_GET_INFO
static inline void storage_get_info(int drive, struct storage_info *info)
{
    (void)drive;
    (void)info;
}
#endif

#ifdef HAVE_HOTSWAP
static inline bool storage_removable(int drive)
{
    (void)drive;
    return 0;
}

static inline bool storage_present(int drive)
{
    (void)drive;
    return 0;
}
#endif /* HOTSWAP */

#endif/*NOT SIMULATOR */
#endif