diff options
author | Heiner Kallweit <hkallweit1@gmail.com> | 2017-12-05 23:17:15 +0100 |
---|---|---|
committer | Sudeep Holla <sudeep.holla@arm.com> | 2018-02-23 15:13:27 +0000 |
commit | 96fe77b6d4762604ba034d57319ad6c4ef071205 (patch) | |
tree | c6749df0e04c3082a16db80f0a9e7af2e60e7937 /drivers/firmware/arm_scpi.c | |
parent | 17431b787460d5c365d81224f95bf88b4685588b (diff) |
firmware: arm_scpi: use FIELD_GET/_PREP to simplify macro definitions
Macro definitions can be simplified by making use of the FIELD_GET/_PREP
bitfield macros.
Tested-by: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Diffstat (limited to 'drivers/firmware/arm_scpi.c')
-rw-r--r-- | drivers/firmware/arm_scpi.c | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 5695b1f4d6f9..bc7055a6a617 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -46,27 +46,19 @@ #include <linux/sort.h> #include <linux/spinlock.h> -#define CMD_ID_SHIFT 0 -#define CMD_ID_MASK 0x7f -#define CMD_TOKEN_ID_SHIFT 8 -#define CMD_TOKEN_ID_MASK 0xff -#define CMD_DATA_SIZE_SHIFT 16 -#define CMD_DATA_SIZE_MASK 0x1ff -#define CMD_LEGACY_DATA_SIZE_SHIFT 20 -#define CMD_LEGACY_DATA_SIZE_MASK 0x1ff -#define PACK_SCPI_CMD(cmd_id, tx_sz) \ - ((((cmd_id) & CMD_ID_MASK) << CMD_ID_SHIFT) | \ - (((tx_sz) & CMD_DATA_SIZE_MASK) << CMD_DATA_SIZE_SHIFT)) -#define ADD_SCPI_TOKEN(cmd, token) \ - ((cmd) |= (((token) & CMD_TOKEN_ID_MASK) << CMD_TOKEN_ID_SHIFT)) -#define PACK_LEGACY_SCPI_CMD(cmd_id, tx_sz) \ - ((((cmd_id) & CMD_ID_MASK) << CMD_ID_SHIFT) | \ - (((tx_sz) & CMD_LEGACY_DATA_SIZE_MASK) << CMD_LEGACY_DATA_SIZE_SHIFT)) - -#define CMD_SIZE(cmd) (((cmd) >> CMD_DATA_SIZE_SHIFT) & CMD_DATA_SIZE_MASK) -#define CMD_LEGACY_SIZE(cmd) (((cmd) >> CMD_LEGACY_DATA_SIZE_SHIFT) & \ - CMD_LEGACY_DATA_SIZE_MASK) -#define CMD_UNIQ_MASK (CMD_TOKEN_ID_MASK << CMD_TOKEN_ID_SHIFT | CMD_ID_MASK) +#define CMD_ID_MASK GENMASK(6, 0) +#define CMD_TOKEN_ID_MASK GENMASK(15, 8) +#define CMD_DATA_SIZE_MASK GENMASK(24, 16) +#define CMD_LEGACY_DATA_SIZE_MASK GENMASK(28, 20) +#define PACK_SCPI_CMD(cmd_id, tx_sz) \ + (FIELD_PREP(CMD_ID_MASK, cmd_id) | \ + FIELD_PREP(CMD_DATA_SIZE_MASK, tx_sz)) +#define PACK_LEGACY_SCPI_CMD(cmd_id, tx_sz) \ + (FIELD_PREP(CMD_ID_MASK, cmd_id) | \ + FIELD_PREP(CMD_LEGACY_DATA_SIZE_MASK, tx_sz)) + +#define CMD_SIZE(cmd) FIELD_GET(CMD_DATA_SIZE_MASK, cmd) +#define CMD_UNIQ_MASK (CMD_TOKEN_ID_MASK | CMD_ID_MASK) #define CMD_XTRACT_UNIQ(cmd) ((cmd) & CMD_UNIQ_MASK) #define SCPI_SLOT 0 @@ -412,7 +404,7 @@ static void scpi_process_cmd(struct scpi_chan *ch, u32 cmd) } else { struct scpi_shared_mem __iomem *mem = ch->rx_payload; - len = min(match->rx_len, CMD_SIZE(cmd)); + len = min_t(unsigned int, match->rx_len, CMD_SIZE(cmd)); match->status = ioread32(&mem->status); memcpy_fromio(match->rx_buf, mem->payload, len); @@ -454,7 +446,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) if (t->rx_buf) { if (!(++ch->token)) ++ch->token; - ADD_SCPI_TOKEN(t->cmd, ch->token); + t->cmd |= FIELD_PREP(CMD_TOKEN_ID_MASK, ch->token); spin_lock_irqsave(&ch->rx_lock, flags); list_add_tail(&t->node, &ch->rx_pending); spin_unlock_irqrestore(&ch->rx_lock, flags); |