[PATCH 1/6] mci: use struct cid
Sascha Hauer
s.hauer at pengutronix.de
Mon Mar 17 03:53:00 PDT 2025
On Mon, Mar 17, 2025 at 12:41:22PM +0300, Alexander Shiyan wrote:
> Hello.
>
> > Linux has a struct mmc_cid where the CID data is parsed into whereas
> > in barebox we call the UNSTUFF_BITS macro whenever we need a field
> > from the CID data. Do it like Linux and parse the CID data into the
> > same struct. While at it convert the UNSTUFF_BITS macro into a
> > unstuff_bits static inline function.
> ...
> > diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> > index 7ec2643b8d..34ea775813 100644
> > --- a/drivers/mci/mci-core.c
> > +++ b/drivers/mci/mci-core.c
> > @@ -26,19 +26,19 @@
> >
> > #define MAX_BUFFER_NUMBER 0xffffffff
> >
> > -#define UNSTUFF_BITS(resp,start,size) \
> > - ({ \
> > - const int __size = size; \
> > - const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
> > - const int __off = 3 - ((start) / 32); \
> > - const int __shft = (start) & 31; \
> > - u32 __res; \
> > - \
> > - __res = resp[__off] >> __shft; \
> > - if (__size + __shft > 32) \
> > - __res |= resp[__off-1] << ((32 - __shft) % 32); \
> > - __res & __mask; \
> > - })
> > +static inline u32 unstuff_bits(const u32 *resp, int start, int size)
> > +{
> > + const int __size = size;
> > + const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1;
> > + const int __off = 3 - (start / 32);
> > + const int __shft = start & 31;
> > + u32 __res = resp[__off] >> __shft;
> > +
> > + if (__size + __shft > 32)
> > + __res |= resp[__off - 1] << ((32 - __shft) % 32);
> > +
> > + return __res & __mask;
> > +}
>
> For board specific code where the eMMC ID is used as a unique identifier,
> it would be useful to have this function in the header.
Wouldn't you rather use something like getenv("mmc0.cid_psn") then?
We could also introduce some mmc helper function for convenience.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list