regmap: provide simple bitops and use them in a driver
Subsystems (6)
v3 cover regmap: provide simple bitops and use them in a driver
From: Bartosz Golaszewski <[email protected]>
I noticed that oftentimes I use regmap_update_bits() for simple bit setting or clearing. In this case the fourth argument is superfluous as it's always 0 or equal to the mask argument.
This series proposes to add simple bit operations for setting, clearing and testing specific bits with regmap.
The second patch uses all three in a driver that got recently picked into the net-next tree.
The patches obviously target different trees so - if you're ok with the change itself - I propose you pick the first one into your regmap tree for v5.8 and then I'll resend the second patch to add the first user for these macros for v5.9.
v1 -> v2:
- convert the new macros to static inline functions
v2 -> v3:
- drop unneeded ternary operator
Bartosz Golaszewski (2):
regmap: provide helpers for simple bit operations
net: ethernet: mtk-star-emac: use regmap bitops
drivers/base/regmap/regmap.c | 22 +++++ drivers/net/ethernet/mediatek/mtk_star_emac.c | 80 ++++++++----------- include/linux/regmap.h | 36 +++++++++ 3 files changed, 93 insertions(+), 45 deletions(-)
Signature · 7 lines
2.26.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 1/2 regmap: provide helpers for simple bit operations
From: Bartosz Golaszewski <[email protected]>
In many instances regmap_update_bits() is used for simple bit setting and clearing. In these cases the last argument is redundant and we can hide it with a static inline function.
This adds three new helpers for simple bit operations: set_bits, clear_bits and test_bits (the last one defined as a regular function).
--- drivers/base/regmap/regmap.c | 22 ++++++++++++++++++++++ include/linux/regmap.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
drivers/base/regmap/regmap.c +22 -0
@@ -2936,6 +2936,28 @@ int regmap_update_bits_base(struct regmap *map, unsigned int reg, }EXPORT_SYMBOL_GPL (regmap_update_bits_base); +/** +* regmap_test_bits() - Check if all specified bits are set in a register. +* +* @map: Register map to operate on +* @reg: Register to read from +* @bits: Bits to test +* +* Returns -1 if the underlying regmap_read() fails, 0 if at least one of the +* tested bits is not set and 1 if all tested bits are set. +*/ +int regmap_test_bits (struct regmap *map,unsigned int reg,unsigned int bits) +{ +unsigned int val, ret; + + ret =regmap_read (map, reg, &val); +if (ret) +return ret; + +return (val & bits) == bits; +} +EXPORT_SYMBOL_GPL (regmap_test_bits); +void regmap_async_complete_cb (struct regmap_async *async,int ret) {struct regmap *map = async->map;
include/linux/regmap.h +36 -0
@@ -1111,6 +1111,21 @@ bool regmap_reg_in_ranges(unsigned int reg,const struct regmap_range *ranges, unsigned int nranges); +static inline int regmap_set_bits (struct regmap *map, +unsigned int reg,unsigned int bits) +{ +return regmap_update_bits_base (map, reg, bits, bits, +NULL , false, false); +} + +static inline int regmap_clear_bits (struct regmap *map, +unsigned int reg,unsigned int bits) +{ +return regmap_update_bits_base (map, reg, bits,0 ,NULL , false, false); +} + +int regmap_test_bits (struct regmap *map,unsigned int reg,unsigned int bits); +/** * struct reg_field - Description of an register field *
@@ -1410,6 +1425,27 @@ static inline int regmap_update_bits_base(struct regmap *map, unsigned int reg,return -EINVAL ; } +static inline int regmap_set_bits (struct regmap *map, +unsigned int reg,unsigned int bits) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return -EINVAL ; +} + +static inline int regmap_clear_bits (struct regmap *map, +unsigned int reg,unsigned int bits) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return -EINVAL ; +} + +static inline int regmap_test_bits (struct regmap *map, +unsigned int reg,unsigned int bits) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return -EINVAL ; +} +static inline int regmap_field_update_bits_base (struct regmap_field *field,unsigned int mask,unsigned int val,bool *change,bool async,bool force)
Signature · 1 line
2.26.1
PATCH v3 2/2 net: ethernet: mtk-star-emac: use regmap bitops
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Shrink the code visually by replacing regmap_update_bits() with appropriate regmap bit operations where applicable.
--- drivers/net/ethernet/mediatek/mtk_star_emac.c | 80 ++++++++----------- 1 file changed, 35 insertions(+), 45 deletions(-)
drivers/net/ethernet/mediatek/mtk_star_emac.c +35 -45
@@ -413,8 +413,8 @@ static void mtk_star_dma_unmap_tx(struct mtk_star_priv *priv,static void mtk_star_nic_disable_pd (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_MAC_CFG , -MTK_STAR_BIT_MAC_CFG_NIC_PD ,0 ); +regmap_clear_bits (priv->regs,MTK_STAR_REG_MAC_CFG , +MTK_STAR_BIT_MAC_CFG_NIC_PD ); }/* Unmask the three interrupts we care about, mask all others. */
@@ -434,41 +434,38 @@ static void mtk_star_intr_disable(struct mtk_star_priv *priv)static void mtk_star_intr_enable_tx (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_INT_MASK , -MTK_STAR_BIT_INT_STS_TNTC ,0 ); +regmap_clear_bits (priv->regs,MTK_STAR_REG_INT_MASK , +MTK_STAR_BIT_INT_STS_TNTC ); }static void mtk_star_intr_enable_rx (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_INT_MASK , -MTK_STAR_BIT_INT_STS_FNRC ,0 ); +regmap_clear_bits (priv->regs,MTK_STAR_REG_INT_MASK , +MTK_STAR_BIT_INT_STS_FNRC ); }static void mtk_star_intr_enable_stats (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_INT_MASK , -MTK_STAR_REG_INT_STS_MIB_CNT_TH ,0 ); +regmap_clear_bits (priv->regs,MTK_STAR_REG_INT_MASK , +MTK_STAR_REG_INT_STS_MIB_CNT_TH ); }static void mtk_star_intr_disable_tx (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_INT_MASK , -MTK_STAR_BIT_INT_STS_TNTC , -MTK_STAR_BIT_INT_STS_TNTC ); +regmap_set_bits (priv->regs,MTK_STAR_REG_INT_MASK , +MTK_STAR_BIT_INT_STS_TNTC ); }static void mtk_star_intr_disable_rx (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_INT_MASK , -MTK_STAR_BIT_INT_STS_FNRC , -MTK_STAR_BIT_INT_STS_FNRC ); +regmap_set_bits (priv->regs,MTK_STAR_REG_INT_MASK , +MTK_STAR_BIT_INT_STS_FNRC ); }static void mtk_star_intr_disable_stats (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_INT_MASK , -MTK_STAR_REG_INT_STS_MIB_CNT_TH , -MTK_STAR_REG_INT_STS_MIB_CNT_TH ); +regmap_set_bits (priv->regs,MTK_STAR_REG_INT_MASK , +MTK_STAR_REG_INT_STS_MIB_CNT_TH ); }static unsigned int mtk_star_intr_read (struct mtk_star_priv *priv)
@@ -524,12 +521,10 @@ static void mtk_star_dma_init(struct mtk_star_priv *priv)static void mtk_star_dma_start (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_TX_DMA_CTRL , -MTK_STAR_BIT_TX_DMA_CTRL_START , -MTK_STAR_BIT_TX_DMA_CTRL_START ); -regmap_update_bits (priv->regs,MTK_STAR_REG_RX_DMA_CTRL , -MTK_STAR_BIT_RX_DMA_CTRL_START , -MTK_STAR_BIT_RX_DMA_CTRL_START ); +regmap_set_bits (priv->regs,MTK_STAR_REG_TX_DMA_CTRL , +MTK_STAR_BIT_TX_DMA_CTRL_START ); +regmap_set_bits (priv->regs,MTK_STAR_REG_RX_DMA_CTRL , +MTK_STAR_BIT_RX_DMA_CTRL_START ); }static void mtk_star_dma_stop (struct mtk_star_priv *priv)
@@ -553,16 +548,14 @@ static void mtk_star_dma_disable(struct mtk_star_priv *priv)static void mtk_star_dma_resume_rx (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_RX_DMA_CTRL , -MTK_STAR_BIT_RX_DMA_CTRL_RESUME , -MTK_STAR_BIT_RX_DMA_CTRL_RESUME ); +regmap_set_bits (priv->regs,MTK_STAR_REG_RX_DMA_CTRL , +MTK_STAR_BIT_RX_DMA_CTRL_RESUME ); }static void mtk_star_dma_resume_tx (struct mtk_star_priv *priv) { -regmap_update_bits (priv->regs,MTK_STAR_REG_TX_DMA_CTRL , -MTK_STAR_BIT_TX_DMA_CTRL_RESUME , -MTK_STAR_BIT_TX_DMA_CTRL_RESUME ); +regmap_set_bits (priv->regs,MTK_STAR_REG_TX_DMA_CTRL , +MTK_STAR_BIT_TX_DMA_CTRL_RESUME ); }static void mtk_star_set_mac_addr (struct net_device *ndev)
@@ -845,8 +838,8 @@ static int mtk_star_hash_wait_ok(struct mtk_star_priv *priv)return ret;/* Check the BIST_OK bit. */ -regmap_read (priv->regs,MTK_STAR_REG_HASH_CTRL , &val); -if (!(val &MTK_STAR_BIT_HASH_CTRL_BIST_OK )) +if (!regmap_test_bits (priv->regs,MTK_STAR_REG_HASH_CTRL , +MTK_STAR_BIT_HASH_CTRL_BIST_OK ))return -EIO ;return 0 ;
@@ -880,12 +873,10 @@ static int mtk_star_reset_hash_table(struct mtk_star_priv *priv)if (ret)return ret; -regmap_update_bits (priv->regs,MTK_STAR_REG_HASH_CTRL , -MTK_STAR_BIT_HASH_CTRL_BIST_EN , -MTK_STAR_BIT_HASH_CTRL_BIST_EN ); -regmap_update_bits (priv->regs,MTK_STAR_REG_TEST1 , -MTK_STAR_BIT_TEST1_RST_HASH_MBIST , -MTK_STAR_BIT_TEST1_RST_HASH_MBIST ); +regmap_set_bits (priv->regs,MTK_STAR_REG_HASH_CTRL , +MTK_STAR_BIT_HASH_CTRL_BIST_EN ); +regmap_set_bits (priv->regs,MTK_STAR_REG_TEST1 , +MTK_STAR_BIT_TEST1_RST_HASH_MBIST );return mtk_star_hash_wait_ok (priv); }
@@ -1016,13 +1007,13 @@ static int mtk_star_enable(struct net_device *ndev)return ret;/* Setup the hashing algorithm */ -regmap_update_bits (priv->regs,MTK_STAR_REG_ARL_CFG , -MTK_STAR_BIT_ARL_CFG_HASH_ALG | -MTK_STAR_BIT_ARL_CFG_MISC_MODE ,0 ); +regmap_clear_bits (priv->regs,MTK_STAR_REG_ARL_CFG , +MTK_STAR_BIT_ARL_CFG_HASH_ALG | +MTK_STAR_BIT_ARL_CFG_MISC_MODE );/* Don't strip VLAN tags */ -regmap_update_bits (priv->regs,MTK_STAR_REG_MAC_CFG , -MTK_STAR_BIT_MAC_CFG_VLAN_STRIP ,0 ); +regmap_clear_bits (priv->regs,MTK_STAR_REG_MAC_CFG , +MTK_STAR_BIT_MAC_CFG_VLAN_STRIP );/* Setup DMA */ mtk_star_dma_init (priv);
@@ -1204,9 +1195,8 @@ static void mtk_star_set_rx_mode(struct net_device *ndev)int ret;if (ndev->flags &IFF_PROMISC ) { -regmap_update_bits (priv->regs,MTK_STAR_REG_ARL_CFG , -MTK_STAR_BIT_ARL_CFG_MISC_MODE , -MTK_STAR_BIT_ARL_CFG_MISC_MODE ); +regmap_set_bits (priv->regs,MTK_STAR_REG_ARL_CFG , +MTK_STAR_BIT_ARL_CFG_MISC_MODE ); }else if (netdev_mc_count (ndev) >MTK_STAR_HASHTABLE_MC_LIMIT || ndev->flags &IFF_ALLMULTI ) {for (i =0 ; i <MTK_STAR_HASHTABLE_SIZE_MAX ; i++) {
Signature · 1 line
2.26.1
Mark Brown
maintainerQuoted 8 lines · Bartosz Golaszewski
I noticed that oftentimes I use
regmap_update_bits()for simple bit setting or clearing. In this case the fourth argument is superfluous as it's always 0 or equal to the mask argument.This series proposes to add simple bit operations for setting, clearing and testing specific bits with regmap.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[1/1] regmap: provide helpers for simple bit operations
commit: aa2ff9dbaeddabb5ad166db5f9f1a0580a8bbba8
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Mark Brown
maintainerQuoted 2 lines · Mark Brown
[1/1] regmap: provide helpers for simple bit operations
commit: aa2ff9dbaeddabb5ad166db5f9f1a0580a8bbba8
Let me know if you need a pull request for this, given the merge window is likely to open over the weekend I figured it's likely too late to apply the second patch before then.
David Miller
maintainerFrom: Bartosz Golaszewski <[email protected]>
Date: Thu, 28 May 2020 17:45:01 +0200
Quoted 17 lines
From: Bartosz Golaszewski <[email protected]>
I noticed that oftentimes I use
regmap_update_bits()for simple bit setting or clearing. In this case the fourth argument is superfluous as it's always 0 or equal to the mask argument.This series proposes to add simple bit operations for setting, clearing and testing specific bits with regmap.
The second patch uses all three in a driver that got recently picked into the net-next tree.
The patches obviously target different trees so - if you're ok with the change itself - I propose you pick the first one into your regmap tree for v5.8 and then I'll resend the second patch to add the first user for these macros for v5.9.
Quoted 5 lines
v1 -> v2:
- convert the new macros to static inline functionsv2 -> v3:
- drop unneeded ternary operator
Series applied to net-next, thank you.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mark Brown
maintainerQuoted 4 lines · David Miller
Quoted 2 lines
v2 -> v3:
- drop unneeded ternary operatorSeries applied to net-next, thank you.
I already applied patch 1 and sent a pull request to Linus for it. As I said:
| Let me know if you need a pull request for this, given the merge window | is likely to open over the weekend I figured it's likely too late to | apply the second patch before then.
Hopefully this merges cleanly... ideally we'd have had that pull request.