[U-Boot] [PATCH v3 02/10] armv7: add miscellaneous utility macros

Aneesh V
2011-06-14T11:39:54Z

Dear Wolfgang,

On Tuesday 14 June 2011 04:21 PM, Wolfgang Denk wrote:
> Dear Aneesh V,
>
> In message<4DF71FBF.6030408@ti.com> you wrote:
>>
>> As I start re-working on my patches I realize that there is no
>> alternative to get_bit_field(). clrsetbits_le32() works as an
>> alternative for set_bit_field() but I couldn't find anything in io.h
>> that could replace get_bit_field(). The only option I seem to have is
>> to mask and shift directly every time. Is that what you prefer over
>> get_bit_field()?
>
> I don't understand this comment.
>
> You should NOT use clrsetbits_*() instead of set_bit_field() -
> depending on what you want to do, clrbits_*() or setbits_*() are
> better choices for simple operations.

Yes. I have seen those macros. But more often than not the bit field is
more than 1 bit wide and the value to be set is not necessarily all 0's
or all 1's. That's why I have to use clrsetbits_*()

>
> Also please notice that none of clrbits_*(), setbits_*() or
> clrsetbits_*() perform any masking or shifting. If you don't want to
> do this explicitly when using the macro, you can hide it in
> respective definitions of the mask values. I showed how this could be
> done in the examples I posted in the thread with Simon.
>

The problem I have to deal with is different. get_bit_field() was
intended to extract bit fields from an integer. So, the target usage
will be something like this(where a, b, and c are bit fields in
register my_reg)

u32 my_reg, a_val, b_val, c_val;

u32 my_reg = readl(my_reg_addr);

a_val = get_bit_field(my_reg, a_mask);
b_val = get_bit_field(my_reg, b_mask);
c_val = get_bit_field(my_reg, c_mask);

Do you see an alternative method for doing this using the standard
macros?

br,
Aneesh