mmc: Unify and generalize UNSTUFF_BITS macro
PATCH 1/3 mmc: Unify and generalize UNSTUFF_BITS macro
Unify duplicated implementations of UNSTUFF_BITS() into a shared .h file. Recode UNSTUFF_BITS() as an invocation of a new more general macro UNSTUFF_BITS_ARRAY() that works on arrays of any multiple of 32 bits.
Signed-off-by [email protected]
--- drivers/mmc/core/core.h | 21 +++++++++++++++++++++ drivers/mmc/core/mmc.c | 14 -------------- drivers/mmc/core/sd.c | 14 -------------- 3 files changed, 21 insertions(+), 28 deletions(-)
drivers/mmc/core/sd.c +0 -14
@@ -41,20 +41,6 @@ static const unsigned int tacc_mant[] = 35, 40, 45, 50, 55, 60, 70, 80, }; -#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; \ - }) -/* * Given the decoded CSD structure, decode the raw CID to our CID structure. */
drivers/mmc/core/core.h +21 -0
@@ -13,6 +13,27 @@#include <linux/delay.h> +#define UNSTUFF_BITS_ARRAY (u32_array, start, size) \ + ({ \ + const int __size = size; \ + const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ + const int __off = (sizeof(u32_array)/4-1) - ((start) / 32); \ + const int __shft = (start) & 31; \ + u32 __res; \ + \ + __res = (u32_array)[__off] >> __shft; \ + if (__size + __shft > 32) \ + __res |= (u32_array)[__off-1] \ + << ((32 - __shft) % 32); \ + __res & __mask; \ + }) + +/* +* Specific to 128-bit arrays, e.g. raw_cid[] and raw_csd[]. +*/ +#define UNSTUFF_BITS (resp, start, size) \ + UNSTUFF_BITS_ARRAY(*(u32(*)[4])resp, start, size) +#define MMC_CMD_RETRIES 3struct mmc_bus_ops {
drivers/mmc/core/mmc.c +0 -14
@@ -39,20 +39,6 @@ static const unsigned int tacc_mant[] = 35, 40, 45, 50, 55, 60, 70, 80, }; -#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; \ - }) -/* * Given the decoded CSD structure, decode the raw CID to our CID structure. */
PATCH RESEND 1/3 mmc: Unify and generalize UNSTUFF_BITS macro
Hi,
No replies on the list, and not merged; any comments on these three patches from Don?
- Chris.
Date: Sun, 29 Nov 2009 19:28:12 -0800
From: [email protected]
Unify duplicated implementations of UNSTUFF_BITS() into a shared .h file. Recode UNSTUFF_BITS() as an invocation of a new more general macro UNSTUFF_BITS_ARRAY() that works on arrays of any multiple of 32 bits.
Signed-off-by [email protected]
--- drivers/mmc/core/core.h | 21 +++++++++++++++++++++ drivers/mmc/core/mmc.c | 14 -------------- drivers/mmc/core/sd.c | 14 -------------- 3 files changed, 21 insertions(+), 28 deletions(-)
drivers/mmc/core/sd.c +0 -14
@@ -41,20 +41,6 @@ static const unsigned int tacc_mant[] = 35, 40, 45, 50, 55, 60, 70, 80, }; -#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; \ - }) -/* * Given the decoded CSD structure, decode the raw CID to our CID structure. */
drivers/mmc/core/core.h +21 -0
@@ -13,6 +13,27 @@#include <linux/delay.h> +#define UNSTUFF_BITS_ARRAY (u32_array, start, size) \ + ({ \ + const int __size = size; \ + const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ + const int __off = (sizeof(u32_array)/4-1) - ((start) / 32); \ + const int __shft = (start) & 31; \ + u32 __res; \ + \ + __res = (u32_array)[__off] >> __shft; \ + if (__size + __shft > 32) \ + __res |= (u32_array)[__off-1] \ + << ((32 - __shft) % 32); \ + __res & __mask; \ + }) + +/* +* Specific to 128-bit arrays, e.g. raw_cid[] and raw_csd[]. +*/ +#define UNSTUFF_BITS (resp, start, size) \ + UNSTUFF_BITS_ARRAY(*(u32(*)[4])resp, start, size) +#define MMC_CMD_RETRIES 3struct mmc_bus_ops {
drivers/mmc/core/mmc.c +0 -14
@@ -39,20 +39,6 @@ static const unsigned int tacc_mant[] = 35, 40, 45, 50, 55, 60, 70, 80, }; -#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; \ - }) -/* * Given the decoded CSD structure, decode the raw CID to our CID structure. */
--
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child