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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 268ba8c..f021931 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -285,7 +285,7 @@ static const struct wps_tag all_tags[] = {
 #if (CONFIG_CODEC == SWCODEC)
     { WPS_TOKEN_SOUND_SPEED,              "Ss",  WPS_REFRESH_DYNAMIC, NULL },
 #endif
-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
     { WPS_TOKEN_VLED_HDD,                 "lh",  WPS_REFRESH_DYNAMIC, NULL },
 #endif

diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index 879262f..f9e6d5d 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -882,7 +882,7 @@ const char *get_token_value(struct gui_wps *gwps,
                 return NULL;
 #endif

-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
         case WPS_TOKEN_VLED_HDD:
             if(led_read(HZ/2))
                 return "h";
diff --git a/apps/gui/skin_engine/skin_tokens.h b/apps/gui/skin_engine/skin_tokens.h
index 68a3fde..1f90bd0 100644
--- a/apps/gui/skin_engine/skin_tokens.h
+++ b/apps/gui/skin_engine/skin_tokens.h
@@ -188,7 +188,7 @@ enum wps_token_type {
   TOKEN_MARKER_MISC,
     WPS_TOKEN_BUTTON_VOLUME,
     WPS_TOKEN_LASTTOUCH,
-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
     /* Virtual LED */
     WPS_TOKEN_VLED_HDD,
 #endif
diff --git a/apps/gui/skin_engine/wps_debug.c b/apps/gui/skin_engine/wps_debug.c
index a0bf970..9cc7d94 100644
--- a/apps/gui/skin_engine/wps_debug.c
+++ b/apps/gui/skin_engine/wps_debug.c
@@ -473,7 +473,7 @@ static char *get_token_desc(struct wps_token *token, char *buf,
             break;
 #endif

-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
         case WPS_TOKEN_VLED_HDD:
             snprintf(buf, bufsize, "display virtual HDD LED");
             break;
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index 4710eba..52494c9 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -122,7 +122,7 @@
                                                 7*ICONS_SPACING
 #define STATUSBAR_LOCKR_WIDTH                   5

-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
 #define STATUSBAR_DISK_WIDTH                    12
 #define STATUSBAR_DISK_X_POS(statusbar_width)   statusbar_width - \
                                                 STATUSBAR_DISK_WIDTH
@@ -145,7 +145,7 @@ static void gui_statusbar_icon_lock(struct screen * display);
 #ifdef HAS_REMOTE_BUTTON_HOLD
 static void gui_statusbar_icon_lock_remote(struct screen * display);
 #endif
-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
 static void gui_statusbar_led(struct screen * display);
 #endif
 #ifdef HAVE_RECORDING
@@ -262,7 +262,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
     bar->info.repeat = global_settings.repeat_mode;
     bar->info.playmode = current_playmode();

-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
     if(!display->has_disk_led)
         bar->info.led = led_read(HZ/2); /* delay should match polling interval */
 #endif
@@ -351,7 +351,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
         gui_statusbar_time(display, bar->time);
         bar->last_tm_min = bar->time->tm_min;
 #endif /* CONFIG_RTC */
-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
         if(!display->has_disk_led && bar->info.led)
             gui_statusbar_led(display);
 #endif
@@ -593,7 +593,7 @@ static void gui_statusbar_icon_lock_remote(struct screen * display)
 }
 #endif

-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
 /*
  * no real LED: disk activity in status bar
  */
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index 28c8105..15e7ba6 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -48,7 +48,7 @@ struct status_info {
 #ifdef HAS_REMOTE_BUTTON_HOLD
     bool keylockremote;
 #endif
-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
     bool led; /* disk LED simulation in the status bar */
 #endif

diff --git a/apps/main.c b/apps/main.c
index 3e98343..d2c8d09 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -446,6 +446,9 @@ static void init(void)
 #if CONFIG_TUNER
     radio_init();
 #endif
+#if CONFIG_LED
+    led_init();
+#endif

     /* Keep the order of this 3 (viewportmanager handles statusbars)
      * Must be done before any code uses the multi-screen API */
diff --git a/apps/recorder/icons.h b/apps/recorder/icons.h
index 5f2185e..6840fe2 100644
--- a/apps/recorder/icons.h
+++ b/apps/recorder/icons.h
@@ -138,7 +138,7 @@ extern void statusbar_icon_lock(void);
 #if CONFIG_RTC
 extern void statusbar_time(int hour, int minute);
 #endif
-#if (CONFIG_LED == LED_VIRTUAL)
+#if (CONFIG_LED & LED_VIRTUAL)
 extern void statusbar_led(void);
 #endif

diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 17c10f7..d3c9ca7 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -63,7 +63,7 @@
 #include "talk.h"
 #include "sound.h"
 #include "storage.h"
-#if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
+#if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED & LED_REAL) \
    && !defined(SIMULATOR)
 #include "ata.h"
 #endif
@@ -1009,7 +1009,7 @@ bool recording_screen(bool no_source)
     int radio_status = (global_settings.rec_source != AUDIO_SRC_FMRADIO) ?
                             FMRADIO_OFF : get_radio_status();
 #endif
-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
     bool led_state = false;
     int led_countdown = 2;
 #endif
@@ -1036,7 +1036,7 @@ bool recording_screen(bool no_source)
     struct audio_recording_options rec_options;
     rec_status = RCSTAT_IN_RECSCREEN;

-#if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
+#if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED & LED_REAL) \
    && !defined(SIMULATOR)
     ata_set_led_enabled(false);
 #endif
@@ -1245,7 +1245,7 @@ bool recording_screen(bool no_source)

         audio_stat = audio_status();

-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)

         /*
          * Flash the LED while waiting to record.  Turn it on while
@@ -1572,7 +1572,7 @@ bool recording_screen(bool no_source)
                     if(audio_stat != AUDIO_STATUS_RECORD)
 #endif
                 {
-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
                     /* led is restored at begin of loop / end of function */
                     led(false);
 #endif
@@ -1598,7 +1598,7 @@ bool recording_screen(bool no_source)
             case ACTION_REC_F2:
                 if(audio_stat != AUDIO_STATUS_RECORD)
                 {
-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
                     /* led is restored at begin of loop / end of function */
                     led(false);
 #endif
@@ -1622,7 +1622,7 @@ bool recording_screen(bool no_source)
                 }
                 else
                 {
-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
                     /* led is restored at begin of loop / end of function */
                     led(false);
 #endif
@@ -1928,7 +1928,7 @@ rec_abort:
     if (rec_status & (RCSTAT_CREATED_DIRECTORY | RCSTAT_HAVE_RECORDED))
         reload_directory();

-#if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED == LED_REAL) \
+#if (CONFIG_STORAGE & STORAGE_ATA) && (CONFIG_LED & LED_REAL) \
    && !defined(SIMULATOR)
     ata_set_led_enabled(true);
 #endif
diff --git a/apps/screen_access.c b/apps/screen_access.c
index 19ab776..2785029 100644
--- a/apps/screen_access.c
+++ b/apps/screen_access.c
@@ -118,7 +118,7 @@ struct screen screens[NB_SCREENS] =
 #endif
         .getcharwidth=screen_helper_getcharwidth,
         .getcharheight=screen_helper_getcharheight,
-#if (CONFIG_LED == LED_VIRTUAL)
+#if (CONFIG_LED & LED_VIRTUAL)
         .has_disk_led=false,
 #elif defined(HAVE_REMOTE_LCD)
         .has_disk_led=true,
diff --git a/apps/screen_access.h b/apps/screen_access.h
index be62478..a5017b0 100644
--- a/apps/screen_access.h
+++ b/apps/screen_access.h
@@ -61,7 +61,7 @@ struct screen
     int (*getcharwidth)(void);
     int (*getcharheight)(void);
     bool is_color;
-#if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
     bool has_disk_led;
 #endif
 #ifdef HAVE_BUTTONBAR
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 5221d3f..0d23853 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -112,7 +112,9 @@ backlight-sw-fading.c
 #endif /* CONFIG_BACKLIGHT_FADING */

 /* Misc. */
+#if CONFIG_LED
 drivers/led.c
+#endif
 drivers/button.c
 #ifndef SIMULATOR
 #ifdef HAVE_DAC3550A
@@ -487,6 +489,7 @@ drivers/i2c.c
 #ifdef ARCHOS_PLAYER
 #ifndef SIMULATOR
 target/sh/archos/ata-archos.c
+target/sh/archos/led-archos.c
 target/sh/archos/timer-archos.c
 target/sh/archos/ata-as-archos.S
 target/sh/archos/player/button-player.c
@@ -505,7 +508,8 @@ target/sh/archos/ata-archos.c
 target/sh/archos/timer-archos.c
 target/sh/archos/ata-as-archos.S
 target/sh/archos/lcd-archos-bitmap.c
-target/sh/archos/lcd-as-archos-bitmap.S   
+target/sh/archos/lcd-as-archos-bitmap.S
+target/sh/archos/led-archos.c   
 target/sh/archos/recorder/button-recorder.c
 target/sh/archos/recorder/power-recorder.c
 target/sh/archos/recorder/powermgmt-recorder.c
@@ -520,6 +524,7 @@ target/sh/archos/timer-archos.c
 target/sh/archos/ata-as-archos.S
 target/sh/archos/lcd-archos-bitmap.c
 target/sh/archos/lcd-as-archos-bitmap.S
+target/sh/archos/led-archos.c
 target/sh/archos/fm_v2/button-fm_v2.c
 target/sh/archos/fm_v2/power-fm_v2.c
 target/sh/archos/fm_v2/powermgmt-fm_v2.c
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 7c0164a..852fbd4 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -158,7 +158,7 @@ static struct mutex ata_mtx SHAREDBSS_ATTR;
 static int ata_device; /* device 0 (master) or 1 (slave) */

 static int spinup_time = 0;
-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
 static bool ata_led_enabled = true;
 static bool ata_led_on = false;
 #endif
@@ -255,7 +255,7 @@ STATICIRAM ICODE_ATTR int wait_for_end_of_transfer(void)
            == STATUS_RDY;
 }    

-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
 /* Conditionally block LED access for the ATA driver, so the LED can be
  * (mis)used for other purposes */
 static void ata_led(bool on) 
@@ -1411,7 +1411,7 @@ void ata_close(void)
 }
 #endif /* ATA_DRIVER_CLOSE */

-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
 void ata_set_led_enabled(bool enabled) 
 {
     ata_led_enabled = enabled;
diff --git a/firmware/drivers/led.c b/firmware/drivers/led.c
index 2258336..bc67b2d 100644
--- a/firmware/drivers/led.c
+++ b/firmware/drivers/led.c
@@ -20,31 +20,19 @@
  ****************************************************************************/
 #include "config.h"
 #include <stdbool.h>
-#include "cpu.h"
 #include "led.h"
 #include "system.h"
 #include "kernel.h"
+#if CONFIG_LED & LED_REAL
+#include "led-target.h"
+#endif

-#if (CONFIG_LED == LED_REAL)
-
-void led(bool on)
-{
-    if ( on )
-    {
-        or_b(0x40, &PBDRL);
-    }
-    else
-    {
-        and_b(~0x40, &PBDRL);
-    }
-}
-
-#elif (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
+#if (CONFIG_LED & LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)

 static bool current;
 static long last_on; /* timestamp of switching off */

-void led(bool on)
+void led_virtual(bool on)
 {
     if (current && !on) /* switching off */
     {
@@ -59,10 +47,25 @@ bool led_read(int delayticks) /* read by status bar update */
     return (current || TIME_BEFORE(current_tick, last_on+delayticks));
 }

-#else
+#endif

 void led(bool on)
 {
+#if CONFIG_LED & LED_REAL
+    led_target(on);
+#endif
+#if CONFIG_LED & LED_VIRTUAL
+    led_virtual(on);
+#endif
+
+#if CONFIG_LED == 0
     (void)on;
+#endif
+}
+
+void led_init(void)
+{
+#if CONFIG_LED & LED_REAL
+    led_init_device();
+#endif
 }
-#endif /* CONFIG_LED, HAVE_REMOTE_LCD */
diff --git a/firmware/export/ata.h b/firmware/export/ata.h
index 5be32da..b53d5f2 100644
--- a/firmware/export/ata.h
+++ b/firmware/export/ata.h
@@ -42,7 +42,7 @@ void ata_close(void);
 int ata_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf);
 int ata_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf);
 void ata_spin(void);
-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
 void ata_set_led_enabled(bool enabled);
 #endif
 unsigned short* ata_get_identify(void);
diff --git a/firmware/export/config-mini2440.h b/firmware/export/config-mini2440.h
index 5dad250..e3dd280 100644
--- a/firmware/export/config-mini2440.h
+++ b/firmware/export/config-mini2440.h
@@ -50,6 +50,7 @@
    that needs spinups and can cause skips when shaked */
 /* #define HAVE_DISK_STORAGE */

+#define CONFIG_LED (LED_REAL|LED_VIRTUAL)
 /* Display */
 /* define this if you have a bitmap LCD display */
 #define HAVE_LCD_BITMAP
diff --git a/firmware/export/led.h b/firmware/export/led.h
index bcc9a31..401bf2e 100644
--- a/firmware/export/led.h
+++ b/firmware/export/led.h
@@ -24,6 +24,7 @@

 #include <stdbool.h>

+extern void led_init(void);
 extern void led( bool on );
 extern bool led_read(int delayticks);

diff --git a/firmware/storage.c b/firmware/storage.c
index d6700d1..8a3abce 100644
--- a/firmware/storage.c
+++ b/firmware/storage.c
@@ -368,7 +368,7 @@ void storage_spindown(int seconds)
 #endif
 }

-#if (CONFIG_LED == LED_REAL)
+#if (CONFIG_LED & LED_REAL)
 void storage_set_led_enabled(bool enabled)
 {
 #if (CONFIG_STORAGE & STORAGE_ATA)
@@ -391,7 +391,7 @@ void storage_set_led_enabled(bool enabled)
     ramdisk_set_led_enabled(enabled);
 #endif
 }
-#endif /* CONFIG_LED == LED_REAL */
+#endif /* CONFIG_LED & LED_REAL */

 long storage_last_disk_activity(void)
 {
diff --git a/firmware/target/arm/s3c2440/crt0.S b/firmware/target/arm/s3c2440/crt0.S
index 2188bc0..2bee37f 100644
--- a/firmware/target/arm/s3c2440/crt0.S
+++ b/firmware/target/arm/s3c2440/crt0.S
@@ -555,7 +555,7 @@ stackmunge:
     ldr     sp, =stackend

     /* Start the main function */
-    adr     lr, vectors
+    ldr     lr, =vectors
     ldr     pc, =main

     /* Should never get here, but let's restart in case (also needed for
diff --git a/firmware/target/arm/s3c2440/mini2440/led-mini2440.c b/firmware/target/arm/s3c2440/mini2440/led-mini2440.c
index f541d75..0b3ee12 100644
--- a/firmware/target/arm/s3c2440/mini2440/led-mini2440.c
+++ b/firmware/target/arm/s3c2440/mini2440/led-mini2440.c
@@ -21,10 +21,10 @@
 #include "config.h"
 #include "cpu.h"
 #include "kernel.h"
-
+#include "led-target.h"
 /* LED functions for debug */

-void led_init (void)
+void led_init_device (void)
 {
     S3C2440_GPIO_CONFIG (GPBCON, 5, GPIO_OUTPUT);
     S3C2440_GPIO_CONFIG (GPBCON, 6, GPIO_OUTPUT);
@@ -36,6 +36,15 @@ void led_init (void)
     S3C2440_GPIO_PULLUP (GPBUP, 7, GPIO_PULLUP_DISABLE);
     S3C2440_GPIO_PULLUP (GPBUP, 8, GPIO_PULLUP_DISABLE);
 }
+#define SD_ACTIVE_LED   LED4
+
+void led_target(bool on)
+{
+    if (on)
+        set_leds(SD_ACTIVE_LED);
+    else
+        clear_leds(SD_ACTIVE_LED);
+}

 /* Turn on one or more LEDS */
 void set_leds (int led_mask)
diff --git a/firmware/target/arm/s3c2440/mini2440/led-mini2440.h b/firmware/target/arm/s3c2440/mini2440/led-mini2440.h
deleted file mode 100644
index 0aaad1c..0000000
--- a/firmware/target/arm/s3c2440/mini2440/led-mini2440.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/***************************************************************************
- *             __________               __   ___.
- *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
- *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
- *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
- *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
- *                     \/            \/     \/    \/            \/
- * $Id$
- *
- * Copyright (C) 2009 by Bob Cousins
- *
- * 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 _LED_MINI2440_H_
-#define _LED_MINI2440_H_
-
-/* LED functions for debug etc */
-
-#define LED1        0x0020      /* GPB5 */
-#define LED2        0x0040      /* GPB6 */
-#define LED3        0x0080      /* GPB7 */
-#define LED4        0x0100      /* GPB8 */
-
-#define LED_NONE    0x0000
-#define LED_ALL (LED1|LED2|LED3|LED4)
-
-void led_init (void);
-
-/* Turn on one or more LEDS */
-void set_leds (int led_mask);
-
-/* Turn off one or more LEDS */
-void clear_leds (int led_mask);
-
-/* Alternate flash of pattern1 and pattern2 - never returns */
-void led_flash (int led_pattern1, int led_pattern2);
-
-#endif /* _LED_MINI2440_H_ */
diff --git a/firmware/target/arm/s3c2440/mini2440/led-target.h b/firmware/target/arm/s3c2440/mini2440/led-target.h
new file mode 100644
index 0000000..ed1d56a
--- /dev/null
+++ b/firmware/target/arm/s3c2440/mini2440/led-target.h
@@ -0,0 +1,49 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id$
+ *
+ * Copyright (C) 2009 by Bob Cousins
+ *
+ * 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 _LED_MINI2440_H_
+#define _LED_MINI2440_H_
+
+#include <stdbool.h>
+
+/* LED functions for debug etc */
+
+#define LED1        0x0020      /* GPB5 */
+#define LED2        0x0040      /* GPB6 */
+#define LED3        0x0080      /* GPB7 */
+#define LED4        0x0100      /* GPB8 */
+
+#define LED_NONE    0x0000
+#define LED_ALL (LED1|LED2|LED3|LED4)
+
+void led_init_device(void);
+void led_target(bool on);
+
+/* Turn on one or more LEDS */
+void set_leds (int led_mask);
+
+/* Turn off one or more LEDS */
+void clear_leds (int led_mask);
+
+/* Alternate flash of pattern1 and pattern2 - never returns */
+void led_flash (int led_pattern1, int led_pattern2);
+
+#endif /* _LED_MINI2440_H_ */
diff --git a/firmware/target/arm/s3c2440/mini2440/power-mini2440.c b/firmware/target/arm/s3c2440/mini2440/power-mini2440.c
index d4b0075..a90cde9 100644
--- a/firmware/target/arm/s3c2440/mini2440/power-mini2440.c
+++ b/firmware/target/arm/s3c2440/mini2440/power-mini2440.c
@@ -25,7 +25,7 @@
 #include "kernel.h"
 #include "system.h"
 #include "power.h"
-#include "led-mini2440.h"
+#include "led-target.h"

 void power_init(void)
 {
diff --git a/firmware/target/arm/s3c2440/sd-s3c2440.c b/firmware/target/arm/s3c2440/sd-s3c2440.c
index 8aa53d8..25d6837 100644
--- a/firmware/target/arm/s3c2440/sd-s3c2440.c
+++ b/firmware/target/arm/s3c2440/sd-s3c2440.c
@@ -37,7 +37,10 @@
 #endif
 #include "dma-target.h"     
 #include "system-target.h"
-#include "led-mini2440.h"
+#if CONFIG_LED & LED_REAL
+#include "led-target.h"
+#endif
+#include "led.h"

 /* The configuration method is not very flexible. */
 #define CARD_NUM_SLOT   0
@@ -75,7 +78,6 @@
 #define SD_CLK       24000000   /* Clock for SD cards */
 #define MMC_CLK      15000000   /* Clock for MMC cards */

-#define SD_ACTIVE_LED   LED4

 #ifdef SD_DEBUG
 #define dbgprintf uart_printf
@@ -683,7 +685,9 @@ static int sd_transfer_sectors(int card_no, unsigned long start,

     mutex_lock(&sd_mtx);
     sd_enable(true);
-    set_leds(SD_ACTIVE_LED);
+#if CONFIG_LED
+    led(true);
+#endif

 #ifdef HAVE_MULTIDRIVE
     curr_card = card_no;
@@ -851,8 +855,10 @@ sd_transfer_error:

     dma_release();

-    clear_leds(SD_ACTIVE_LED);
     sd_enable(false);
+#if CONFIG_LED
+    led(false);
+#endif

     if (ret)    /* error */
         card_info[card_no].initialized = 0;
diff --git a/firmware/target/sh/archos/led-archos.c b/firmware/target/sh/archos/led-archos.c
new file mode 100644
index 0000000..1f62c04
--- /dev/null
+++ b/firmware/target/sh/archos/led-archos.c
@@ -0,0 +1,38 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Thomas Martitz
+ * Copyright (C) 2002 by Alan Korr
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#include "config.h"
+#include "cpu.h"
+#include <stdbool.h>
+#include "system.h"
+
+void led_target(bool on)
+{
+    if ( on )
+    {
+        or_b(0x40, &PBDRL);
+    }
+    else
+    {
+        and_b(~0x40, &PBDRL);
+    }
+}
diff --git a/firmware/target/sh/archos/led-target.h b/firmware/target/sh/archos/led-target.h
new file mode 100644
index 0000000..8c75918
--- /dev/null
+++ b/firmware/target/sh/archos/led-target.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id$
+ *
+ * Copyright (C) 2009 Thomas Martitz
+ *
+ * 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 __LED_TARGET_H__
+#define __LED_TARGET_H__
+
+#include <stdbool.h>
+#define led_init_device()
+extern void led_target(bool on);
+#endif