* [PATCH RESEND 1/3] firmware: imx: Introduce imx_dsp_setup_channels
2020-11-11 11:11 [PATCH RESEND 0/3] Allow on demand channel request / free Daniel Baluta
@ 2020-11-11 11:11 ` Daniel Baluta
2020-11-11 11:11 ` [PATCH RESEND 2/3] firmware: imx: Save channel name for further use Daniel Baluta
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Baluta @ 2020-11-11 11:11 UTC (permalink / raw)
To: shawnguo
Cc: s.hauer, linux-kernel, paul.olaru, linux-imx, kernel, festevam,
shengjiu.wang, linux-arm-kernel
Create a separate function that sets up DSP mailbox channels
so that imx_dsp_probe function will be easier to read.
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
---
drivers/firmware/imx/imx-dsp.c | 41 +++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/drivers/firmware/imx/imx-dsp.c b/drivers/firmware/imx/imx-dsp.c
index 4265e9dbed84..a3a018c87b52 100644
--- a/drivers/firmware/imx/imx-dsp.c
+++ b/drivers/firmware/imx/imx-dsp.c
@@ -60,22 +60,15 @@ static void imx_dsp_handle_rx(struct mbox_client *c, void *msg)
}
}
-static int imx_dsp_probe(struct platform_device *pdev)
+static int imx_dsp_setup_channels(struct imx_dsp_ipc *dsp_ipc)
{
- struct device *dev = &pdev->dev;
- struct imx_dsp_ipc *dsp_ipc;
+ struct device *dev = dsp_ipc->dev;
struct imx_dsp_chan *dsp_chan;
struct mbox_client *cl;
char *chan_name;
int ret;
int i, j;
- device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
-
- dsp_ipc = devm_kzalloc(dev, sizeof(*dsp_ipc), GFP_KERNEL);
- if (!dsp_ipc)
- return -ENOMEM;
-
for (i = 0; i < DSP_MU_CHAN_NUM; i++) {
if (i < 2)
chan_name = kasprintf(GFP_KERNEL, "txdb%d", i);
@@ -108,12 +101,6 @@ static int imx_dsp_probe(struct platform_device *pdev)
kfree(chan_name);
}
- dsp_ipc->dev = dev;
-
- dev_set_drvdata(dev, dsp_ipc);
-
- dev_info(dev, "NXP i.MX DSP IPC initialized\n");
-
return 0;
out:
kfree(chan_name);
@@ -125,6 +112,30 @@ static int imx_dsp_probe(struct platform_device *pdev)
return ret;
}
+static int imx_dsp_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct imx_dsp_ipc *dsp_ipc;
+ int ret;
+
+ device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);
+
+ dsp_ipc = devm_kzalloc(dev, sizeof(*dsp_ipc), GFP_KERNEL);
+ if (!dsp_ipc)
+ return -ENOMEM;
+
+ dsp_ipc->dev = dev;
+ dev_set_drvdata(dev, dsp_ipc);
+
+ ret = imx_dsp_setup_channels(dsp_ipc);
+ if (ret < 0)
+ return ret;
+
+ dev_info(dev, "NXP i.MX DSP IPC initialized\n");
+
+ return 0;
+}
+
static int imx_dsp_remove(struct platform_device *pdev)
{
struct imx_dsp_chan *dsp_chan;
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RESEND 2/3] firmware: imx: Save channel name for further use
2020-11-11 11:11 [PATCH RESEND 0/3] Allow on demand channel request / free Daniel Baluta
2020-11-11 11:11 ` [PATCH RESEND 1/3] firmware: imx: Introduce imx_dsp_setup_channels Daniel Baluta
@ 2020-11-11 11:11 ` Daniel Baluta
2020-11-11 11:11 ` [PATCH RESEND 3/3] firmware: imx-dsp: Export functions to request/free channels Daniel Baluta
2020-11-16 8:34 ` [PATCH RESEND 0/3] Allow on demand channel request / free Shawn Guo
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Baluta @ 2020-11-11 11:11 UTC (permalink / raw)
To: shawnguo
Cc: s.hauer, linux-kernel, paul.olaru, linux-imx, kernel, festevam,
shengjiu.wang, linux-arm-kernel
We want to request / free channels on demand later in order
to save power.
For this for each channel we save the name and use it to
reference the channel later.
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
---
drivers/firmware/imx/imx-dsp.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/firmware/imx/imx-dsp.c b/drivers/firmware/imx/imx-dsp.c
index a3a018c87b52..b6e95d6d34c0 100644
--- a/drivers/firmware/imx/imx-dsp.c
+++ b/drivers/firmware/imx/imx-dsp.c
@@ -79,6 +79,7 @@ static int imx_dsp_setup_channels(struct imx_dsp_ipc *dsp_ipc)
return -ENOMEM;
dsp_chan = &dsp_ipc->chans[i];
+ dsp_chan->name = chan_name;
cl = &dsp_chan->cl;
cl->dev = dev;
cl->tx_block = false;
@@ -97,16 +98,14 @@ static int imx_dsp_setup_channels(struct imx_dsp_ipc *dsp_ipc)
}
dev_dbg(dev, "request mbox chan %s\n", chan_name);
- /* chan_name is not used anymore by framework */
- kfree(chan_name);
}
return 0;
out:
- kfree(chan_name);
for (j = 0; j < i; j++) {
dsp_chan = &dsp_ipc->chans[j];
mbox_free_channel(dsp_chan->ch);
+ kfree(dsp_chan->name);
}
return ret;
@@ -147,6 +146,7 @@ static int imx_dsp_remove(struct platform_device *pdev)
for (i = 0; i < DSP_MU_CHAN_NUM; i++) {
dsp_chan = &dsp_ipc->chans[i];
mbox_free_channel(dsp_chan->ch);
+ kfree(dsp_chan->name);
}
return 0;
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RESEND 3/3] firmware: imx-dsp: Export functions to request/free channels
2020-11-11 11:11 [PATCH RESEND 0/3] Allow on demand channel request / free Daniel Baluta
2020-11-11 11:11 ` [PATCH RESEND 1/3] firmware: imx: Introduce imx_dsp_setup_channels Daniel Baluta
2020-11-11 11:11 ` [PATCH RESEND 2/3] firmware: imx: Save channel name for further use Daniel Baluta
@ 2020-11-11 11:11 ` Daniel Baluta
2020-11-16 8:34 ` [PATCH RESEND 0/3] Allow on demand channel request / free Shawn Guo
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Baluta @ 2020-11-11 11:11 UTC (permalink / raw)
To: shawnguo
Cc: s.hauer, linux-kernel, paul.olaru, linux-imx, kernel, festevam,
shengjiu.wang, linux-arm-kernel
In order to save power, we only need to request a channel
when the communication with the DSP active.
For this we export the following functions:
- imx_dsp_request_channel, gets a channel with a given index
- imx_dsp_free_channel, frees a channel with a given index
Notice that we still request channels at probe to support devices
that do not have PM callbacks implemented.
More explanations about why requesting a channel has an effect
on power savings:
- requesting an mailbox channel will call mailbox's startup
function.
- startup function calls pm_runtime_get_sync which increments device
usage count and will keep the device active. Specifically, mailbox
clock will be always ON when a mailbox channel is requested.
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
---
drivers/firmware/imx/imx-dsp.c | 25 +++++++++++++++++++++++++
include/linux/firmware/imx/dsp.h | 10 ++++++++++
2 files changed, 35 insertions(+)
diff --git a/drivers/firmware/imx/imx-dsp.c b/drivers/firmware/imx/imx-dsp.c
index b6e95d6d34c0..a6c06d7476c3 100644
--- a/drivers/firmware/imx/imx-dsp.c
+++ b/drivers/firmware/imx/imx-dsp.c
@@ -60,6 +60,31 @@ static void imx_dsp_handle_rx(struct mbox_client *c, void *msg)
}
}
+struct mbox_chan *imx_dsp_request_channel(struct imx_dsp_ipc *dsp_ipc, int idx)
+{
+ struct imx_dsp_chan *dsp_chan;
+
+ if (idx >= DSP_MU_CHAN_NUM)
+ return ERR_PTR(-EINVAL);
+
+ dsp_chan = &dsp_ipc->chans[idx];
+ dsp_chan->ch = mbox_request_channel_byname(&dsp_chan->cl, dsp_chan->name);
+ return dsp_chan->ch;
+}
+EXPORT_SYMBOL(imx_dsp_request_channel);
+
+void imx_dsp_free_channel(struct imx_dsp_ipc *dsp_ipc, int idx)
+{
+ struct imx_dsp_chan *dsp_chan;
+
+ if (idx >= DSP_MU_CHAN_NUM)
+ return;
+
+ dsp_chan = &dsp_ipc->chans[idx];
+ mbox_free_channel(dsp_chan->ch);
+}
+EXPORT_SYMBOL(imx_dsp_free_channel);
+
static int imx_dsp_setup_channels(struct imx_dsp_ipc *dsp_ipc)
{
struct device *dev = dsp_ipc->dev;
diff --git a/include/linux/firmware/imx/dsp.h b/include/linux/firmware/imx/dsp.h
index 7562099c9e46..4f7895a3b73c 100644
--- a/include/linux/firmware/imx/dsp.h
+++ b/include/linux/firmware/imx/dsp.h
@@ -55,6 +55,9 @@ static inline void *imx_dsp_get_data(struct imx_dsp_ipc *ipc)
int imx_dsp_ring_doorbell(struct imx_dsp_ipc *dsp, unsigned int chan_idx);
+struct mbox_chan *imx_dsp_request_channel(struct imx_dsp_ipc *ipc, int idx);
+void imx_dsp_free_channel(struct imx_dsp_ipc *ipc, int idx);
+
#else
static inline int imx_dsp_ring_doorbell(struct imx_dsp_ipc *ipc,
@@ -63,5 +66,12 @@ static inline int imx_dsp_ring_doorbell(struct imx_dsp_ipc *ipc,
return -ENOTSUPP;
}
+struct mbox_chan *imx_dsp_request_channel(struct imx_dsp_ipc *ipc, int idx)
+{
+ return ERR_PTR(-EOPNOTSUPP);
+}
+
+void imx_dsp_free_channel(struct imx_dsp_ipc *ipc, int idx) { }
+
#endif
#endif /* _IMX_DSP_IPC_H */
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND 0/3] Allow on demand channel request / free
2020-11-11 11:11 [PATCH RESEND 0/3] Allow on demand channel request / free Daniel Baluta
` (2 preceding siblings ...)
2020-11-11 11:11 ` [PATCH RESEND 3/3] firmware: imx-dsp: Export functions to request/free channels Daniel Baluta
@ 2020-11-16 8:34 ` Shawn Guo
3 siblings, 0 replies; 5+ messages in thread
From: Shawn Guo @ 2020-11-16 8:34 UTC (permalink / raw)
To: Daniel Baluta
Cc: s.hauer, linux-kernel, paul.olaru, linux-imx, kernel, festevam,
shengjiu.wang, linux-arm-kernel
On Wed, Nov 11, 2020 at 01:11:15PM +0200, Daniel Baluta wrote:
> Requesting an mailbox channel will call mailbox's startup
> function.
>
> startup function calls pm_runtime_get_sync which increments device usage
> count and will keep the device active. Specifically, mailbox clock will
> be always ON when a mailbox channel is requested.
>
> For this, reason we introduce a way to request/free IMX DSP channels
> on demand to save power when the channels are not used.
>
> First two patches are doing code refactoring preparing the path
> for 3rd patch which exports functions for on demand channel request/free
>
>
> Daniel Baluta (3):
> firmware: imx: Introduce imx_dsp_setup_channels
> firmware: imx: Save channel name for further use
> firmware: imx-dsp: Export functions to request/free channels
Applied all, thanks.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread