mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-24 09:13:20 -05:00
rpmsg: glink: Split rpm_probe to reuse the common code
There is quite some code common in glink_rpm_probe that can reused for glink-smem based transport as well. So split the function and move the code to glink_native_probe that can be used later when we add the support for glink-smem based transport. Also reuse driver's remove as well. Acked-by: Arun Kumar Neelakantam <aneela@codeaurora.org> Signed-off-by: Sricharan R <sricharan@codeaurora.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
parent
e45c5dc26d
commit
6799c434c2
1 changed files with 49 additions and 36 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/of_address.h>
|
#include <linux/of_address.h>
|
||||||
|
#include <linux/of_irq.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
#include <linux/rpmsg.h>
|
#include <linux/rpmsg.h>
|
||||||
|
@ -1155,29 +1156,21 @@ err_inval:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int glink_rpm_probe(struct platform_device *pdev)
|
struct qcom_glink *qcom_glink_native_probe(struct device *dev,
|
||||||
|
struct qcom_glink_pipe *rx,
|
||||||
|
struct qcom_glink_pipe *tx)
|
||||||
{
|
{
|
||||||
struct qcom_glink *glink;
|
|
||||||
struct glink_rpm_pipe *rx_pipe;
|
|
||||||
struct glink_rpm_pipe *tx_pipe;
|
|
||||||
struct device_node *np;
|
|
||||||
void __iomem *msg_ram;
|
|
||||||
size_t msg_ram_size;
|
|
||||||
struct device *dev = &pdev->dev;
|
|
||||||
struct resource r;
|
|
||||||
int irq;
|
int irq;
|
||||||
int ret;
|
int ret;
|
||||||
|
struct qcom_glink *glink;
|
||||||
|
|
||||||
glink = devm_kzalloc(dev, sizeof(*glink), GFP_KERNEL);
|
glink = devm_kzalloc(dev, sizeof(*glink), GFP_KERNEL);
|
||||||
if (!glink)
|
if (!glink)
|
||||||
return -ENOMEM;
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
glink->dev = dev;
|
glink->dev = dev;
|
||||||
|
glink->tx_pipe = tx;
|
||||||
rx_pipe = devm_kzalloc(&pdev->dev, sizeof(*rx_pipe), GFP_KERNEL);
|
glink->rx_pipe = rx;
|
||||||
tx_pipe = devm_kzalloc(&pdev->dev, sizeof(*tx_pipe), GFP_KERNEL);
|
|
||||||
if (!rx_pipe || !tx_pipe)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
mutex_init(&glink->tx_lock);
|
mutex_init(&glink->tx_lock);
|
||||||
spin_lock_init(&glink->rx_lock);
|
spin_lock_init(&glink->rx_lock);
|
||||||
|
@ -1188,14 +1181,48 @@ static int glink_rpm_probe(struct platform_device *pdev)
|
||||||
idr_init(&glink->lcids);
|
idr_init(&glink->lcids);
|
||||||
idr_init(&glink->rcids);
|
idr_init(&glink->rcids);
|
||||||
|
|
||||||
glink->mbox_client.dev = &pdev->dev;
|
glink->mbox_client.dev = dev;
|
||||||
glink->mbox_chan = mbox_request_channel(&glink->mbox_client, 0);
|
glink->mbox_chan = mbox_request_channel(&glink->mbox_client, 0);
|
||||||
if (IS_ERR(glink->mbox_chan)) {
|
if (IS_ERR(glink->mbox_chan)) {
|
||||||
if (PTR_ERR(glink->mbox_chan) != -EPROBE_DEFER)
|
if (PTR_ERR(glink->mbox_chan) != -EPROBE_DEFER)
|
||||||
dev_err(&pdev->dev, "failed to acquire IPC channel\n");
|
dev_err(dev, "failed to acquire IPC channel\n");
|
||||||
return PTR_ERR(glink->mbox_chan);
|
return ERR_CAST(glink->mbox_chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
irq = of_irq_get(dev->of_node, 0);
|
||||||
|
ret = devm_request_irq(dev, irq,
|
||||||
|
qcom_glink_intr,
|
||||||
|
IRQF_NO_SUSPEND | IRQF_SHARED,
|
||||||
|
"glink-native", glink);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(dev, "failed to request IRQ\n");
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qcom_glink_send_version(glink);
|
||||||
|
if (ret)
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
return glink;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int glink_rpm_probe(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
struct qcom_glink *glink;
|
||||||
|
struct glink_rpm_pipe *rx_pipe;
|
||||||
|
struct glink_rpm_pipe *tx_pipe;
|
||||||
|
struct device_node *np;
|
||||||
|
void __iomem *msg_ram;
|
||||||
|
size_t msg_ram_size;
|
||||||
|
struct device *dev = &pdev->dev;
|
||||||
|
struct resource r;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
rx_pipe = devm_kzalloc(&pdev->dev, sizeof(*rx_pipe), GFP_KERNEL);
|
||||||
|
tx_pipe = devm_kzalloc(&pdev->dev, sizeof(*tx_pipe), GFP_KERNEL);
|
||||||
|
if (!rx_pipe || !tx_pipe)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
np = of_parse_phandle(dev->of_node, "qcom,rpm-msg-ram", 0);
|
np = of_parse_phandle(dev->of_node, "qcom,rpm-msg-ram", 0);
|
||||||
ret = of_address_to_resource(np, 0, &r);
|
ret = of_address_to_resource(np, 0, &r);
|
||||||
of_node_put(np);
|
of_node_put(np);
|
||||||
|
@ -1219,27 +1246,13 @@ static int glink_rpm_probe(struct platform_device *pdev)
|
||||||
tx_pipe->native.avail = glink_rpm_tx_avail;
|
tx_pipe->native.avail = glink_rpm_tx_avail;
|
||||||
tx_pipe->native.write = glink_rpm_tx_write;
|
tx_pipe->native.write = glink_rpm_tx_write;
|
||||||
|
|
||||||
glink->tx_pipe = &tx_pipe->native;
|
|
||||||
glink->rx_pipe = &rx_pipe->native;
|
|
||||||
|
|
||||||
writel(0, tx_pipe->head);
|
writel(0, tx_pipe->head);
|
||||||
writel(0, rx_pipe->tail);
|
writel(0, rx_pipe->tail);
|
||||||
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
glink = qcom_glink_native_probe(&pdev->dev, &rx_pipe->native,
|
||||||
ret = devm_request_irq(dev, irq,
|
&tx_pipe->native);
|
||||||
qcom_glink_intr,
|
if (IS_ERR(glink))
|
||||||
IRQF_NO_SUSPEND | IRQF_SHARED,
|
return PTR_ERR(glink);
|
||||||
"glink-rpm", glink);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(dev, "Failed to request IRQ\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
glink->irq = irq;
|
|
||||||
|
|
||||||
ret = qcom_glink_send_version(glink);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, glink);
|
platform_set_drvdata(pdev, glink);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue