mailbox: rockchip: Some cleanups
Subsystems (2)
cover mailbox: rockchip: Some cleanups
Hello,
while trying to understand how mailbox drivers work, I used the rockchip driver as a reference for a working driver. I didn't succeed yet (so it's unclear to me how the .send_data() callback can assume that data points to a struct rockchip_mbox_msg).
This patch set is the result of picking up the patch opportunities I noticed while looking through the driver.
Best regards
Uwe
Uwe Kleine-König (3):
mailbox: rockchip: Add a prefix for register defines
mailbox: rockchip: Simplify device variant handling
mailbox: rockchip: Convert to use dev_err_probe()
drivers/mailbox/rockchip-mailbox.c | 60 ++++++++++++++---------------- 1 file changed, 27 insertions(+), 33 deletions(-)
base-commit: a8406e6c0b793ce0788019683837c40855b55995
Signature · 1 line
2.55.0.11.g153666a7d9bb
PATCH 1/3 mailbox: rockchip: Add a prefix for register defines
From: Uwe Kleine-König <[email protected]>
This way the defines don't make the impression to be more generic than they actually are.
--- drivers/mailbox/rockchip-mailbox.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/mailbox/rockchip-mailbox.c +15 -14
@@ -12,15 +12,15 @@#include <linux/module.h> #include <linux/platform_device.h> -#define MAILBOX_A2B_INTEN 0x00 -#define MAILBOX_A2B_STATUS 0x04 -#define MAILBOX_A2B_CMD (x) (0x08 + (x) * 8) -#define MAILBOX_A2B_DAT (x) (0x0c + (x) * 8) +#define ROCKCHIP_MAILBOX_A2B_INTEN 0x00 +#define ROCKCHIP_MAILBOX_A2B_STATUS 0x04 +#define ROCKCHIP_MAILBOX_A2B_CMD (x) (0x08 + (x) * 8) +#define ROCKCHIP_MAILBOX_A2B_DAT (x) (0x0c + (x) * 8) -#define MAILBOX_B2A_INTEN 0x28 -#define MAILBOX_B2A_STATUS 0x2C -#define MAILBOX_B2A_CMD (x) (0x30 + (x) * 8) -#define MAILBOX_B2A_DAT (x) (0x34 + (x) * 8) +#define ROCKCHIP_MAILBOX_B2A_INTEN 0x28 +#define ROCKCHIP_MAILBOX_B2A_STATUS 0x2C +#define ROCKCHIP_MAILBOX_B2A_CMD (x) (0x30 + (x) * 8) +#define ROCKCHIP_MAILBOX_B2A_DAT (x) (0x34 + (x) * 8)struct rockchip_mbox_msg {u32 cmd;
@@ -68,9 +68,10 @@ static int rockchip_mbox_send_data(struct mbox_chan *chan, void *data) mb->chans[chans->idx].msg = msg; -writel_relaxed (msg->cmd, mb->mbox_base +MAILBOX_A2B_CMD (chans->idx)); +writel_relaxed (msg->cmd, mb->mbox_base + +ROCKCHIP_MAILBOX_A2B_CMD (chans->idx));writel_relaxed (msg->rx_size, mb->mbox_base + -MAILBOX_A2B_DAT (chans->idx)); +ROCKCHIP_MAILBOX_A2B_DAT (chans->idx));return 0 ; }
@@ -81,7 +82,7 @@ static int rockchip_mbox_startup(struct mbox_chan *chan)/* Enable all B2A interrupts */ writel_relaxed ((1 << mb->mbox.num_chans) -1 , - mb->mbox_base +MAILBOX_B2A_INTEN ); + mb->mbox_base +ROCKCHIP_MAILBOX_B2A_INTEN );return 0 ; }
@@ -92,7 +93,7 @@ static void rockchip_mbox_shutdown(struct mbox_chan *chan)struct rockchip_mbox_chan *chans = mb->chans;/* Disable all B2A interrupts */ -writel_relaxed (0 , mb->mbox_base +MAILBOX_B2A_INTEN ); +writel_relaxed (0 , mb->mbox_base +ROCKCHIP_MAILBOX_B2A_INTEN ); mb->chans[chans->idx].msg =NULL ; }
@@ -107,13 +108,13 @@ static irqreturn_t rockchip_mbox_irq(int irq, void *dev_id) {int idx;struct rockchip_mbox *mb = (struct rockchip_mbox *)dev_id; -u32 status =readl_relaxed (mb->mbox_base +MAILBOX_B2A_STATUS ); +u32 status =readl_relaxed (mb->mbox_base +ROCKCHIP_MAILBOX_B2A_STATUS );for (idx =0 ; idx < mb->mbox.num_chans; idx++) {if ((status & (1 << idx)) && (irq == mb->chans[idx].irq)) {/* Clear mbox interrupt */ writel_relaxed (1 << idx, - mb->mbox_base +MAILBOX_B2A_STATUS ); + mb->mbox_base +ROCKCHIP_MAILBOX_B2A_STATUS );return IRQ_WAKE_THREAD ; } }
Signature · 1 line
2.55.0.11.g153666a7d9bb
PATCH 2/3 mailbox: rockchip: Simplify device variant handling
In reply to Uwe Kleine-KönigFrom: Uwe Kleine-König <[email protected]>
There is only a single device variant. Let's not use multi-device abstraction for that but hardcode the information relevant for that single device type.
Bloat-o-meter reports the following size reduction for an ARCH=arm64 build:
add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-492 (-492)
Function old new delta
rk3368_drv_data 4 - -4
rockchip_mbox_probe 2084 1596 -488
Total: Before=7185, After=6693, chg -6.85%
--- drivers/mailbox/rockchip-mailbox.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
drivers/mailbox/rockchip-mailbox.c +10 -17
@@ -22,15 +22,13 @@#define ROCKCHIP_MAILBOX_B2A_CMD (x) (0x30 + (x) * 8)#define ROCKCHIP_MAILBOX_B2A_DAT (x) (0x34 + (x) * 8) +#define ROCKCHIP_MAILBOX_NUM_CHANS 4 +struct rockchip_mbox_msg {u32 cmd;int rx_size; }; -struct rockchip_mbox_data { -int num_chans; -}; -struct rockchip_mbox_chan {int idx;int irq;
@@ -151,20 +149,15 @@ static irqreturn_t rockchip_mbox_isr(int irq, void *dev_id)return IRQ_HANDLED ; } -static const struct rockchip_mbox_data rk3368_drv_data = { - .num_chans =4 , -}; -static const struct of_device_id rockchip_mbox_of_match[] = { - { .compatible ="rockchip,rk3368-mailbox" , .data = &rk3368_drv_data}, - { }, + { .compatible ="rockchip,rk3368-mailbox" }, + { } };MODULE_DEVICE_TABLE (of, rockchip_mbox_of_match);static int rockchip_mbox_probe (struct platform_device *pdev) {struct rockchip_mbox *mb; -const struct rockchip_mbox_data *drv_data;struct resource *res;struct clk *pclk;int ret, irq, i;
@@ -172,13 +165,13 @@ static int rockchip_mbox_probe(struct platform_device *pdev)if (!pdev->dev.of_node)return -ENODEV ; - drv_data = (const struct rockchip_mbox_data *)device_get_match_data (&pdev->dev); - - mb =devm_kzalloc (&pdev->dev,struct_size (mb, chans, drv_data->num_chans),GFP_KERNEL ); + mb =devm_kzalloc (&pdev->dev, +struct_size (mb, chans,ROCKCHIP_MAILBOX_NUM_CHANS ), +GFP_KERNEL );if (!mb)return -ENOMEM ; - mb->mbox.chans =devm_kcalloc (&pdev->dev, drv_data->num_chans, + mb->mbox.chans =devm_kcalloc (&pdev->dev,ROCKCHIP_MAILBOX_NUM_CHANS ,sizeof (*mb->mbox.chans),GFP_KERNEL );if (!mb->mbox.chans)return -ENOMEM ;
@@ -186,7 +179,7 @@ static int rockchip_mbox_probe(struct platform_device *pdev)platform_set_drvdata (pdev, mb); mb->mbox.dev = &pdev->dev; - mb->mbox.num_chans = drv_data->num_chans; + mb->mbox.num_chans =ROCKCHIP_MAILBOX_NUM_CHANS ; mb->mbox.ops = &rockchip_mbox_chan_ops; mb->mbox.txdone_irq = true;
@@ -195,7 +188,7 @@ static int rockchip_mbox_probe(struct platform_device *pdev)return PTR_ERR (mb->mbox_base);/* Each channel has two buffers for A2B and B2A */ - mb->buf_size = (size_t )resource_size (res) / (drv_data->num_chans *2 ); + mb->buf_size = (size_t )resource_size (res) / (ROCKCHIP_MAILBOX_NUM_CHANS *2 ); pclk =devm_clk_get_enabled (&pdev->dev,"pclk_mailbox" );if (IS_ERR (pclk))
Signature · 1 line
2.55.0.11.g153666a7d9bb
PATCH 3/3 mailbox: rockchip: Convert to use dev_err_probe()
In reply to Uwe Kleine-KönigFrom: Uwe Kleine-König <[email protected]>
This is more compact in source code and also compiles to smaller code.
Bloat-o-meter reports:
add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-76 (-76)
Function old new delta
rockchip_mbox_probe 1596 1592 -4
_entry_ptr 24 16 -8
__func__ 62 42 -20
_entry 132 88 -44
Total: Before=6693, After=6617, chg -1.14%
--- drivers/mailbox/rockchip-mailbox.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mailbox/rockchip-mailbox.c +2 -2
@@ -215,9 +215,9 @@ static int rockchip_mbox_probe(struct platform_device *pdev) ret =devm_mbox_controller_register (&pdev->dev, &mb->mbox);if (ret <0 ) -dev_err (&pdev->dev,"Failed to register mailbox: %d\n" , ret); +return dev_err_probe (&pdev->dev, ret,"Failed to register mailbox\n" ); -return ret; +return 0 ; }static struct platform_driver rockchip_mbox_driver = {
Signature · 1 line
2.55.0.11.g153666a7d9bb
Quoted 19 lines · Uwe Kleine-König
Hello,
while trying to understand how mailbox drivers work, I used the rockchip driver as a reference for a working driver. I didn't succeed yet (so it's unclear to me how the .send_data() callback can assume that data points to a struct
rockchip_mbox_msg).This patch set is the result of picking up the patch opportunities I noticed while looking through the driver.
Best regards
UweUwe Kleine-König (3):
mailbox: rockchip: Add a prefix for register defines
mailbox: rockchip: Simplify device variant handling
mailbox: rockchip: Convert to usedev_err_probe()
Quoted 8 lines
drivers/mailbox/rockchip-mailbox.c | 60 ++++++++++++++---------------- 1 file changed, 27 insertions(+), 33 deletions(-)base-commit:
a8406e6c0b793ce0788019683837c40855b55995--
2.55.0.11.g153666a7d9bb
Applied to mailbox/for-next
Thanks
Jassi