[U-Boot] [PATCH 1/2] mmc: add bcm2835 driver

Stephen Warren swarren at wwwdotorg.org
Sat Oct 27 23:28:12 EDT 2012


On 10/26/2012 05:33 AM, Vikram Narayanan wrote:
> Some nitpicks.
> 
> On 10/24/2012 10:20 AM, Stephen Warren wrote:
>> This adds a simple driver for the BCM2835's SD controller.
>>
>> Workarounds are implemented for:
>> * Register writes can't be too close to each-other in time, or they will
>>    be lost.
>> * Register accesses must all be 32-bit, so implement custom accessors.
...

>> +static u8 bcm2835_sdhci_readb(struct sdhci_host *host, int reg)
>> +{
>> +    u32 val = bcm2835_sdhci_raw_readl(host, (reg&  ~3));
>> +    val = val>>  (reg<<  3&  0x18)&  0xff;
>> +
>> +    return (u8)val;
>> +}
> 
> Can the above used magics be made as macros?

This code was taken directly from the downstream Linux kernel, so I
changed it as little as possible, to make comparisons easier. Still, if
people want I can certainly make it easier to understand the expression
a bit.

I don't think the issue is the magic numbers so much as understanding
what the expression does; the magic are obvious then. It's simply
extracting byte n from from a u32. Would the following be more obvious:

byte_num = reg & 3;
byte_shift = bytenum * 8;
byte = (val >> byte_shift) & 0xff;

... and similar for the other functions?



More information about the linux-rpi-kernel mailing list