[RFC 4/5] soundwire: qcom: add sdw_master_device support
From: Bard Liao
Date: Fri Apr 17 2020 - 04:50:48 EST
From: Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxxxxxxxx>
Add new device as a child of the platform device, following the
following hierarchy:
platform_device
sdw_master_device
sdw_slave0
...
sdw_slaveN
For the Qualcomm implementation no sdw_link_ops are provided. All the
dais have to be registered using the platform_device and all power
management is handled at the platform device level.
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxxxxxxxx>
Signed-off-by: Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx>
---
drivers/soundwire/qcom.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index e08a17c13f92..96306044aa84 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -89,6 +89,7 @@ struct qcom_swrm_port_config {
struct qcom_swrm_ctrl {
struct sdw_bus bus;
struct device *dev;
+ struct sdw_master_device *md;
struct regmap *regmap;
struct completion *comp;
struct work_struct slave_work;
@@ -746,7 +747,7 @@ static int qcom_swrm_probe(struct platform_device *pdev)
struct sdw_master_prop *prop;
struct sdw_bus_params *params;
struct qcom_swrm_ctrl *ctrl;
- int ret;
+ int ret, err;
u32 val;
ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
@@ -784,14 +785,34 @@ static int qcom_swrm_probe(struct platform_device *pdev)
mutex_init(&ctrl->port_lock);
INIT_WORK(&ctrl->slave_work, qcom_swrm_slave_wq);
- ctrl->bus.dev = dev;
+ /*
+ * add sdw_master_device.
+ * For the Qualcomm implementation there is no driver.
+ */
+ ctrl->md = sdw_master_device_add(dev, /* platform device is parent */
+ dev->fwnode,
+ NULL, /* no link ops */
+ 0, /* only one link supported */
+ NULL); /* no context */
+ if (IS_ERR(ctrl->md)) {
+ dev_err(dev, "Could not create sdw_master_device\n");
+ ret = PTR_ERR(ctrl->md);
+ goto err_clk;
+ }
+
+ /* add bus handle */
+ ctrl->md->bus = &ctrl->bus;
+
+ /* the bus uses the sdw_master_device, not the platform device */
+ ctrl->bus.dev = &ctrl->md->dev;
+
ctrl->bus.ops = &qcom_swrm_ops;
ctrl->bus.port_ops = &qcom_swrm_port_ops;
ctrl->bus.compute_params = &qcom_swrm_compute_params;
ret = qcom_swrm_get_port_config(ctrl);
if (ret)
- goto err_clk;
+ goto err_md;
params = &ctrl->bus.params;
params->max_dr_freq = DEFAULT_CLK_FREQ;
@@ -818,14 +839,14 @@ static int qcom_swrm_probe(struct platform_device *pdev)
"soundwire", ctrl);
if (ret) {
dev_err(dev, "Failed to request soundwire irq\n");
- goto err_clk;
+ goto err_md;
}
ret = sdw_add_bus_master(&ctrl->bus);
if (ret) {
dev_err(dev, "Failed to register Soundwire controller (%d)\n",
ret);
- goto err_clk;
+ goto err_md;
}
qcom_swrm_init(ctrl);
@@ -841,6 +862,10 @@ static int qcom_swrm_probe(struct platform_device *pdev)
err_master_add:
sdw_delete_bus_master(&ctrl->bus);
+err_md:
+ err = sdw_master_device_del(ctrl->md);
+ if (err < 0) /* log but return initial status */
+ dev_err(dev, "master device del failed %d\n", err);
err_clk:
clk_disable_unprepare(ctrl->hclk);
err_init:
@@ -850,8 +875,12 @@ static int qcom_swrm_probe(struct platform_device *pdev)
static int qcom_swrm_remove(struct platform_device *pdev)
{
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(&pdev->dev);
+ int err;
sdw_delete_bus_master(&ctrl->bus);
+ err = sdw_master_device_del(ctrl->md);
+ if (err < 0)
+ dev_err(&pdev->dev, "master device del failed %d\n", err);
clk_disable_unprepare(ctrl->hclk);
return 0;
--
2.17.1