sdcard for raspi - endianess fixes
[AROS.git] / arch / arm-native / soc / broadcom / 2708 / sdcard / sdcard_bcm2708bus.c
blob4cdd871b527146f3ba2720ea0dc849d88be6c061
1 /*
2 Copyright � 2013-2015, 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)
13 // Activity LED ON
14 if (__arm_periiobase == BCM2835_PERIPHYSBASE)
15 *(volatile unsigned int *)GPCLR0 = AROS_LONG2LE(1 << 16);
16 else
17 *(volatile unsigned int *)GPSET1 = AROS_LONG2LE(1 << (47 - 32));
19 else
21 // Activity LED OFF
22 if (__arm_periiobase == BCM2835_PERIPHYSBASE)
23 *(volatile unsigned int *)GPSET0 = AROS_LONG2LE(1 << 16);
24 else
25 *(volatile unsigned int *)GPCLR1 = AROS_LONG2LE(1 << (47 - 32));
29 ULONG FNAME_SDCBUS(GetClockDiv)(ULONG speed, struct sdcard_Bus *bus)
31 ULONG __BCMClkDiv;
33 for (__BCMClkDiv = 0; __BCMClkDiv < V300_MAXCLKDIV; __BCMClkDiv++) {
34 if ((bus->sdcb_ClockMax / (__BCMClkDiv + 1)) <= speed)
35 break;
38 return __BCMClkDiv;
41 UBYTE FNAME_BCMSDCBUS(BCMMMIOReadByte)(ULONG reg, struct sdcard_Bus *bus)
43 ULONG val = *(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3);
45 return (val >> ((reg & 3) << 3)) & 0xFF;
48 UWORD FNAME_BCMSDCBUS(BCMMMIOReadWord)(ULONG reg, struct sdcard_Bus *bus)
50 ULONG val = AROS_LE2LONG(*(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3));
52 return (val >> (((reg >> 1) & 1) << 4)) & 0xFFFF;
55 ULONG FNAME_BCMSDCBUS(BCMMMIOReadLong)(ULONG reg, struct sdcard_Bus *bus)
57 return AROS_LE2LONG(*(volatile ULONG *)(bus->sdcb_IOBase + reg));
60 static void FNAME_BCMSDCBUS(BCM283xWriteLong)(ULONG reg, ULONG val, struct sdcard_Bus *bus)
62 /* Bug: two SDC clock cycle delay required between successive chipset writes */
63 while (sdcard_CurrentTime() < (bus->sdcb_Private + 6))
64 sdcard_Udelay(1);
66 *(volatile ULONG *)(bus->sdcb_IOBase + reg) = AROS_LONG2LE(val);
67 bus->sdcb_Private = (IPTR)sdcard_CurrentTime();
70 void FNAME_BCMSDCBUS(BCMMMIOWriteByte)(ULONG reg, UBYTE val, struct sdcard_Bus *bus)
72 ULONG currval = AROS_LE2LONG(*(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3));
73 ULONG shift = (reg & 3) << 3;
74 ULONG mask = 0xFF << shift;
75 ULONG newval = (currval & ~mask) | (val << shift);
77 FNAME_BCMSDCBUS(BCM283xWriteLong)(reg & ~3, newval, bus);
80 void FNAME_BCMSDCBUS(BCMMMIOWriteWord)(ULONG reg, UWORD val, struct sdcard_Bus *bus)
82 ULONG currval = AROS_LE2LONG(*(volatile ULONG *)(((ULONG)bus->sdcb_IOBase + reg) & ~3));
83 ULONG shift = ((reg >> 1) & 1) << 4;
84 ULONG mask = 0xFFFF << shift;
85 ULONG newval = (currval & ~mask) | (val << shift);
87 FNAME_BCMSDCBUS(BCM283xWriteLong)(reg & ~3, newval, bus);
90 void FNAME_BCMSDCBUS(BCMMMIOWriteLong)(ULONG reg, ULONG val, struct sdcard_Bus *bus)
92 FNAME_BCMSDCBUS(BCM283xWriteLong)(reg, val, bus);