restructure broadcom soc file layout
[AROS.git] / arch / arm-native / soc / broadcom / 283x / sdcard / sdcard_bcm2835bus.c
blob4b639dc5679083066bfe824efe853d4fd1f54a91
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "sdcard_intern.h"
7 #include "timer.h"
9 void FNAME_BCMSDCBUS(BCMLEDCtrl)(int lvl)
11 if (lvl > 0)
12 *(volatile ULONG *)GPCLR0 = (1 << 16); // Turn Activity LED ON
13 else
14 *(volatile ULONG *)GPSET0 = (1 << 16); // Turn Activity LED OFF
17 ULONG FNAME_SDCBUS(GetClockDiv)(ULONG speed, struct sdcard_Bus *bus)
19 ULONG __BCMClkDiv;
21 for (__BCMClkDiv = 0; __BCMClkDiv < V300_MAXCLKDIV; __BCMClkDiv++) {
22 if ((bus->sdcb_ClockMax / (__BCMClkDiv + 1)) <= speed)
23 break;
26 return __BCMClkDiv;
29 UBYTE FNAME_BCMSDCBUS(BCMMMIOReadByte)(ULONG reg, struct sdcard_Bus *bus)
31 ULONG val = *(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3);
33 return (val >> ((reg & 3) << 3)) & 0xFF;
36 UWORD FNAME_BCMSDCBUS(BCMMMIOReadWord)(ULONG reg, struct sdcard_Bus *bus)
38 ULONG val = *(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3);
40 return (val >> (((reg >> 1) & 1) << 4)) & 0xFFFF;
43 ULONG FNAME_BCMSDCBUS(BCMMMIOReadLong)(ULONG reg, struct sdcard_Bus *bus)
45 return *(volatile ULONG *)(bus->sdcb_IOBase + reg);
48 static void FNAME_BCMSDCBUS(BCM2835WriteLong)(ULONG reg, ULONG val, struct sdcard_Bus *bus)
50 /* Bug: two SDC clock cycle delay required between successive chipset writes */
51 while (sdcard_CurrentTime() < (bus->sdcb_Private + 6))
52 sdcard_Udelay(1);
54 *(volatile ULONG *)(bus->sdcb_IOBase + reg) = val;
55 bus->sdcb_Private = (IPTR)sdcard_CurrentTime();
58 void FNAME_BCMSDCBUS(BCMMMIOWriteByte)(ULONG reg, UBYTE val, struct sdcard_Bus *bus)
60 ULONG currval = *(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3);
61 ULONG shift = (reg & 3) << 3;
62 ULONG mask = 0xFF << shift;
63 ULONG newval = (currval & ~mask) | (val << shift);
65 FNAME_BCMSDCBUS(BCM2835WriteLong)(reg & ~3, newval, bus);
68 void FNAME_BCMSDCBUS(BCMMMIOWriteWord)(ULONG reg, UWORD val, struct sdcard_Bus *bus)
70 ULONG currval = *(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3);
71 ULONG shift = ((reg >> 1) & 1) << 4;
72 ULONG mask = 0xFFFF << shift;
73 ULONG newval = (currval & ~mask) | (val << shift);
75 FNAME_BCMSDCBUS(BCM2835WriteLong)(reg & ~3, newval, bus);
78 void FNAME_BCMSDCBUS(BCMMMIOWriteLong)(ULONG reg, ULONG val, struct sdcard_Bus *bus)
80 FNAME_BCMSDCBUS(BCM2835WriteLong)(reg, val, bus);