soundwire: bus_type: add sdw_master_device support
Bard Liao
maintainerv2 cover soundwire: bus_type: add sdw_master_device support
This series adds sdw master devices support.
changes in v2:
- Allocate sdw_master_device dynamically
- Use unique bus id as master id
- Keep checking parent devices
- Enable runtime_pm on Master device
Bard Liao (2):
soundwire: bus: add unique bus id
soundwire: master: add runtime pm support
Pierre-Louis Bossart (3):
soundwire: bus: rename sdw_bus_master_add/delete, add arguments
soundwire: bus_type: introduce sdw_slave_type and sdw_master_type
soundwire: bus_type: add sdw_master_device support
.../driver-api/soundwire/summary.rst | 7 +- drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.c | 47 ++++++++-- drivers/soundwire/bus.h | 3 + drivers/soundwire/bus_type.c | 19 ++-- drivers/soundwire/intel.c | 9 +- drivers/soundwire/master.c | 88 +++++++++++++++++++ drivers/soundwire/qcom.c | 7 +- drivers/soundwire/slave.c | 8 +- include/linux/soundwire/sdw.h | 24 ++++- include/linux/soundwire/sdw_type.h | 9 +- 11 files changed, 191 insertions(+), 32 deletions(-) create mode 100644 drivers/soundwire/master.c
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 1/5 soundwire: bus: rename sdw_bus_master_add/delete, add arguments
From: Pierre-Louis Bossart <[email protected]>
In preparation for future extensions, rename functions to use sdw_bus_master prefix and add a parent and fwnode argument to sdw_bus_master_add to help with device registration in follow-up patches.
No functionality change, just renames and additional arguments.
The Intel code is currently unused, the two additional arguments are only needed for compilation.
--- Documentation/driver-api/soundwire/summary.rst | 7 ++++--- drivers/soundwire/bus.c | 15 +++++++++------ drivers/soundwire/intel.c | 8 ++++---- drivers/soundwire/qcom.c | 6 +++--- include/linux/soundwire/sdw.h | 5 +++-- 5 files changed, 23 insertions(+), 18 deletions(-)
Documentation/driver-api/soundwire/summary.rst +4 -3
@@ -101,10 +101,11 @@ Following is the Bus API to register the SoundWire Bus: .. code-block:: c - int sdw_add_bus_master(struct sdw_bus *bus) + int sdw_bus_master_add(struct sdw_bus *bus, + struct device *parent, + struct fwnode_handle) { - if (!bus->dev) - return -ENODEV; + sdw_master_device_add(bus, parent, fwnode); mutex_init(&bus->lock); INIT_LIST_HEAD(&bus->slaves);
drivers/soundwire/bus.c +9 -6
@@ -10,13 +10,16 @@#include "bus.h" /** -* sdw_add_bus_master() - add a bus Master instance +* sdw_bus_master_add() - add a bus Master instance * @bus: bus instance +* @parent: parent device +* @fwnode: firmware node handle * * Initializes the bus instance, read properties and create child * devices. */ -int sdw_add_bus_master (struct sdw_bus *bus) +int sdw_bus_master_add (struct sdw_bus *bus,struct device *parent, +struct fwnode_handle *fwnode) {struct sdw_master_prop *prop =NULL ;int ret;
@@ -107,7 +110,7 @@ int sdw_add_bus_master(struct sdw_bus *bus)return 0 ; } -EXPORT_SYMBOL (sdw_add_bus_master); +EXPORT_SYMBOL (sdw_bus_master_add);static int sdw_delete_slave (struct device *dev,void *data) {
@@ -131,18 +134,18 @@ static int sdw_delete_slave(struct device *dev, void *data) }/** -* sdw_delete_bus_master() - delete the bus master instance +* sdw_bus_master_delete() - delete the bus master instance * @bus: bus to be deleted * * Remove the instance, delete the child devices. */ -void sdw_delete_bus_master (struct sdw_bus *bus) +void sdw_bus_master_delete (struct sdw_bus *bus) {device_for_each_child (bus->dev,NULL , sdw_delete_slave);sdw_bus_debugfs_exit (bus); } -EXPORT_SYMBOL (sdw_delete_bus_master); +EXPORT_SYMBOL (sdw_bus_master_delete);/* * SDW IO Calls
drivers/soundwire/intel.c +4 -4
@@ -1110,9 +1110,9 @@ static int intel_probe(struct platform_device *pdev)platform_set_drvdata (pdev, sdw); - ret =sdw_add_bus_master (&sdw->cdns.bus); + ret =sdw_bus_master_add (&sdw->cdns.bus, &pdev->dev, pdev->dev.fwnode);if (ret) { -dev_err (&pdev->dev,"sdw_add_bus_master fail: %d\n" , ret); +dev_err (&pdev->dev,"sdw_bus_master_add fail: %d\n" , ret);return ret; }
@@ -1173,7 +1173,7 @@ static int intel_probe(struct platform_device *pdev)sdw_cdns_enable_interrupt (&sdw->cdns, false);free_irq (sdw->link_res->irq, sdw); err_init: -sdw_delete_bus_master (&sdw->cdns.bus); +sdw_bus_master_delete (&sdw->cdns.bus);return ret; }
@@ -1189,7 +1189,7 @@ static int intel_remove(struct platform_device *pdev)free_irq (sdw->link_res->irq, sdw);snd_soc_unregister_component (sdw->cdns.dev); } -sdw_delete_bus_master (&sdw->cdns.bus); +sdw_bus_master_delete (&sdw->cdns.bus);return 0 ; }
drivers/soundwire/qcom.c +3 -3
@@ -821,7 +821,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) goto err_clk; } - ret =sdw_add_bus_master (&ctrl->bus); + ret =sdw_bus_master_add (&ctrl->bus, dev, dev->fwnode);if (ret) {dev_err (dev,"Failed to register Soundwire controller (%d)\n" , ret);
@@ -840,7 +840,7 @@ static int qcom_swrm_probe(struct platform_device *pdev)return 0 ; err_master_add: -sdw_delete_bus_master (&ctrl->bus); +sdw_bus_master_delete (&ctrl->bus); err_clk:clk_disable_unprepare (ctrl->hclk); err_init:
@@ -851,7 +851,7 @@ static int qcom_swrm_remove(struct platform_device *pdev) {struct qcom_swrm_ctrl *ctrl =dev_get_drvdata (&pdev->dev); -sdw_delete_bus_master (&ctrl->bus); +sdw_bus_master_delete (&ctrl->bus);clk_disable_unprepare (ctrl->hclk);return 0 ;
include/linux/soundwire/sdw.h +3 -2
@@ -832,8 +832,9 @@ struct sdw_bus {bool multi_link; }; -int sdw_add_bus_master (struct sdw_bus *bus); -void sdw_delete_bus_master (struct sdw_bus *bus); +int sdw_bus_master_add (struct sdw_bus *bus,struct device *parent, +struct fwnode_handle *fwnode); +void sdw_bus_master_delete (struct sdw_bus *bus);/** * sdw_port_config: Master or Slave Port configuration
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 2/5 soundwire: bus_type: introduce sdw_slave_type and sdw_master_type
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
this is a preparatory patch before the introduction of the sdw_master_type. The SoundWire slave support is slightly modified with the use of a sdw_slave_type, and the uevent handling move to slave.c (since it's not necessary for the master).
No functionality change other than moving code around.
--- drivers/soundwire/bus_type.c | 19 +++++++++++++------ drivers/soundwire/slave.c | 8 +++++++- include/linux/soundwire/sdw_type.h | 9 ++++++++- 3 files changed, 28 insertions(+), 8 deletions(-)
drivers/soundwire/bus_type.c +13 -6
@@ -33,13 +33,21 @@ sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)static int sdw_bus_match (struct device *dev,struct device_driver *ddrv) { -struct sdw_slave *slave =dev_to_sdw_dev (dev); -struct sdw_driver *drv =drv_to_sdw_driver (ddrv); +struct sdw_slave *slave; +struct sdw_driver *drv; +int ret =0 ; + +if (is_sdw_slave (dev)) { + slave =dev_to_sdw_dev (dev); + drv =drv_to_sdw_driver (ddrv); -return !!sdw_get_device_id (slave, drv); + ret = !!sdw_get_device_id (slave, drv); + } +return ret; } -int sdw_slave_modalias (const struct sdw_slave *slave,char *buf,size_t size) +static int sdw_slave_modalias (const struct sdw_slave *slave,char *buf, +size_t size) {/* modalias is sdw:m<mfg_id>p<part_id> */
@@ -47,7 +55,7 @@ int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size) slave->id.mfg_id, slave->id.part_id); } -static int sdw_uevent (struct device *dev,struct kobj_uevent_env *env) +int sdw_slave_uevent (struct device *dev,struct kobj_uevent_env *env) {struct sdw_slave *slave =dev_to_sdw_dev (dev);char modalias[32 ];
@@ -63,7 +71,6 @@ static int sdw_uevent(struct device *dev, struct kobj_uevent_env *env)struct bus_type sdw_bus_type = { .name ="soundwire" , .match = sdw_bus_match, - .uevent = sdw_uevent, };EXPORT_SYMBOL_GPL (sdw_bus_type);
drivers/soundwire/slave.c +7 -1
@@ -14,6 +14,12 @@ static void sdw_slave_release(struct device *dev)kfree (slave); } +struct device_type sdw_slave_type = { + .name ="sdw_slave" , + .release = sdw_slave_release, + .uevent = sdw_slave_uevent, +}; +static int sdw_slave_add (struct sdw_bus *bus,struct sdw_slave_id *id,struct fwnode_handle *fwnode) {
@@ -41,9 +47,9 @@ static int sdw_slave_add(struct sdw_bus *bus, id->class_id, id->unique_id); } - slave->dev.release = sdw_slave_release; slave->dev.bus = &sdw_bus_type; slave->dev.of_node =of_node_get (to_of_node (fwnode)); + slave->dev.type = &sdw_slave_type; slave->bus = bus; slave->status =SDW_SLAVE_UNATTACHED ;init_completion (&slave->enumeration_complete);
include/linux/soundwire/sdw_type.h +8 -1
@@ -5,6 +5,13 @@#define __SOUNDWIRE_TYPES_Hextern struct bus_type sdw_bus_type; +extern struct device_type sdw_slave_type; +extern struct device_type sdw_master_type; + +static inline int is_sdw_slave (const struct device *dev) +{ +return dev->type == &sdw_slave_type; +}#define drv_to_sdw_driver (_drv) container_of(_drv, struct sdw_driver, driver)
@@ -14,7 +21,7 @@ extern struct bus_type sdw_bus_type;int __sdw_register_driver (struct sdw_driver *drv,struct module *owner);void sdw_unregister_driver (struct sdw_driver *drv); -int sdw_slave_modalias (const struct sdw_slave *slave,char *buf,size_t size); +int sdw_slave_uevent (struct device *dev,struct kobj_uevent_env *env);/** * module_sdw_driver() - Helper macro for registering a Soundwire driver
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 3/5 soundwire: bus: add unique bus id
In reply to Bard LiaoAdding an unique id for each bus.
--- drivers/soundwire/bus.c | 20 ++++++++++++++++++++ include/linux/soundwire/sdw.h | 2 ++ 2 files changed, 22 insertions(+)
drivers/soundwire/bus.c +20 -0
@@ -9,6 +9,19 @@#include <linux/soundwire/sdw.h> #include "bus.h" +static DEFINE_IDA (sdw_ida); + +static int sdw_get_id (struct sdw_bus *bus) +{ +int rc =ida_alloc (&sdw_ida,GFP_KERNEL ); + +if (rc <0 ) +return rc; + + bus->id = rc; +return 0 ; +} +/** * sdw_bus_master_add() - add a bus Master instance * @bus: bus instance
@@ -29,6 +42,12 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,return -ENODEV ; } + ret =sdw_get_id (bus); +if (ret) { +dev_err (bus->dev,"Failed to get bus id\n" ); +return ret; + } +if (!bus->ops) {dev_err (bus->dev,"SoundWire Bus ops are not set\n" );return -EINVAL ;
@@ -144,6 +163,7 @@ void sdw_bus_master_delete(struct sdw_bus *bus)device_for_each_child (bus->dev,NULL , sdw_delete_slave);sdw_bus_debugfs_exit (bus); +ida_free (&sdw_ida, bus->id); }EXPORT_SYMBOL (sdw_bus_master_delete);
include/linux/soundwire/sdw.h +2 -0
@@ -789,6 +789,7 @@ struct sdw_master_ops {* struct sdw_bus - SoundWire bus * @dev: Master linux device * @link_id: Link id number, can be 0 to N, unique for each Master +* @id: bus system-wide unique id * @slaves: list of Slaves on this bus * @assigned: Bitmap for Slave device numbers. * Bit set implies used number, bit clear implies unused number.
@@ -813,6 +814,7 @@ struct sdw_master_ops {struct sdw_bus {struct device *dev;unsigned int link_id; +int id;struct list_head slaves; DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);struct mutex bus_lock;
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 4/5 soundwire: bus_type: add sdw_master_device support
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
In the existing SoundWire code, Master Devices are not explicitly represented - only SoundWire Slave Devices are exposed (the use of capital letters follows the SoundWire specification conventions).
With the existing code, the bus is handled without using a proper device, and bus->dev typically points to a platform device. The right thing to do as discussed in multiple reviews is use a device for each bus.
The sdw_master_device addition is done with minimal internal plumbing and not exposed externally. The existing API based on sdw_bus_master_add() and sdw_bus_master_delete() will deal with the sdw_master_device life cycle, which minimizes changes to existing drivers.
Note that the Intel code will be modified in follow-up patches (no impact on any platform since the connection with ASoC is not supported upstream so far).
--- drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.c | 14 ++++-- drivers/soundwire/bus.h | 3 ++ drivers/soundwire/intel.c | 1 - drivers/soundwire/master.c | 81 +++++++++++++++++++++++++++++++++++ drivers/soundwire/qcom.c | 1 - include/linux/soundwire/sdw.h | 17 +++++++- 7 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 drivers/soundwire/master.c
drivers/soundwire/Makefile +1 -1
@@ -4,7 +4,7 @@ # #Bus Objs -soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o stream.o +soundwire-bus-objs := bus_type.o bus.o master.o slave.o mipi_disco.o stream.o obj-$(CONFIG_SOUNDWIRE) += soundwire-bus.o ifdef CONFIG_DEBUG_FS
drivers/soundwire/bus.c +11 -3
@@ -37,14 +37,21 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,struct sdw_master_prop *prop =NULL ;int ret; -if (!bus->dev) { -pr_err ("SoundWire bus has no device\n" ); +if (!parent) { +pr_err ("SoundWire parent device is not set\n" );return -ENODEV ; } ret =sdw_get_id (bus);if (ret) { -dev_err (bus->dev,"Failed to get bus id\n" ); +dev_err (parent,"Failed to get bus id\n" ); +return ret; + } + + ret =sdw_master_device_add (bus, parent, fwnode); +if (ret) { +dev_err (parent,"Failed to add master device at link %d\n" , + bus->link_id);return ret; }
@@ -161,6 +168,7 @@ static int sdw_delete_slave(struct device *dev, void *data)void sdw_bus_master_delete (struct sdw_bus *bus) {device_for_each_child (bus->dev,NULL , sdw_delete_slave); +sdw_master_device_del (bus);sdw_bus_debugfs_exit (bus);ida_free (&sdw_ida, bus->id);
drivers/soundwire/bus.h +3 -0
@@ -19,6 +19,9 @@ static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)int sdw_of_find_slaves (struct sdw_bus *bus);void sdw_extract_slave_id (struct sdw_bus *bus,u64 addr,struct sdw_slave_id *id); +int sdw_master_device_add (struct sdw_bus *bus,struct device *parent, +struct fwnode_handle *fwnode); +int sdw_master_device_del (struct sdw_bus *bus);#ifdef CONFIG_DEBUG_FS void sdw_bus_debugfs_init (struct sdw_bus *bus);
drivers/soundwire/intel.c +0 -1
@@ -1099,7 +1099,6 @@ static int intel_probe(struct platform_device *pdev) sdw->cdns.registers = sdw->link_res->registers; sdw->cdns.instance = sdw->instance; sdw->cdns.msg_count =0 ; - sdw->cdns.bus.dev = &pdev->dev; sdw->cdns.bus.link_id = pdev->id;sdw_cdns_probe (&sdw->cdns);
drivers/soundwire/master.c new file +81 -0
81 lines not on this page · raw message
drivers/soundwire/qcom.c +0 -1
@@ -784,7 +784,6 @@ 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; ctrl->bus.ops = &qcom_swrm_ops; ctrl->bus.port_ops = &qcom_swrm_port_ops; ctrl->bus.compute_params = &qcom_swrm_compute_params;
include/linux/soundwire/sdw.h +16 -1
@@ -632,6 +632,19 @@ struct sdw_slave {#define dev_to_sdw_dev (_dev) container_of(_dev, struct sdw_slave, dev) +/** +* struct sdw_master_device - SoundWire 'Master Device' representation +* @dev: Linux device for this Master +* @bus: Bus handle shortcut +*/ +struct sdw_master_device { +struct device dev; +struct sdw_bus *bus; +}; + +#define dev_to_sdw_master_device (d) \ + container_of(d, struct sdw_master_device, dev) +struct sdw_driver {const char *name;
@@ -787,7 +800,8 @@ struct sdw_master_ops {/** * struct sdw_bus - SoundWire bus -* @dev: Master linux device +* @dev: Shortcut to &bus->md->dev to avoid changing the entire code. +* @md: Master device * @link_id: Link id number, can be 0 to N, unique for each Master * @id: bus system-wide unique id * @slaves: list of Slaves on this bus
@@ -813,6 +827,7 @@ struct sdw_master_ops {*/ struct sdw_bus {struct device *dev; +struct sdw_master_device *md;unsigned int link_id;int id;struct list_head slaves;
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 5/5 soundwire: master: add runtime pm support
In reply to Bard LiaoWe need to enable runtime_pm on master device with generic helpers, so that a Slave-initiated wake is propagated to the bus parent.
--- drivers/soundwire/master.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/soundwire/master.c +7 -0
@@ -3,6 +3,7 @@#include <linux/device.h> #include <linux/acpi.h> +#include <linux/pm_runtime.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_type.h> #include "bus.h"
@@ -14,9 +15,15 @@ static void sdw_master_device_release(struct device *dev)kfree (md); } +static const struct dev_pm_ops master_dev_pm = { +SET_RUNTIME_PM_OPS (pm_generic_runtime_suspend, + pm_generic_runtime_resume,NULL ) +}; +struct device_type sdw_master_type = { .name ="soundwire_master" , .release = sdw_master_device_release, + .pm = &master_dev_pm, };/**
Signature · 1 line
2.17.1
Dne 18. 05. 20 v 19:43 Bard Liao napsal(a):
Quoted 29 lines
This series adds sdw master devices support.
changes in v2:
- Allocatesdw_master_devicedynamically
- Use unique bus id as master id
- Keep checking parent devices
- Enableruntime_pmon Master deviceBard Liao (2):
soundwire: bus: add unique bus id
soundwire: master: add runtime pm supportPierre-Louis Bossart (3):
soundwire: bus: rename sdw_bus_master_add/delete, add arguments
soundwire:bus_type: introducesdw_slave_typeandsdw_master_type
soundwire:bus_type: addsdw_master_devicesupport.../driver-api/soundwire/summary.rst | 7 +- drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.c | 47 ++++++++-- drivers/soundwire/bus.h | 3 + drivers/soundwire/bus_type.c | 19 ++-- drivers/soundwire/intel.c | 9 +- drivers/soundwire/master.c | 88 +++++++++++++++++++ drivers/soundwire/qcom.c | 7 +- drivers/soundwire/slave.c | 8 +- include/linux/soundwire/sdw.h | 24 ++++- include/linux/soundwire/sdw_type.h | 9 +- 11 files changed, 191 insertions(+), 32 deletions(-)
Quoted 2 lines
create mode 100644
drivers/soundwire/master.c
The code looks really clean now. Thank you for your work.
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Vinod Koul
maintainerQuoted 7 lines · Bard Liao
This series adds sdw master devices support.
changes in v2:
- Allocatesdw_master_devicedynamically
- Use unique bus id as master id
- Keep checking parent devices
- Enableruntime_pmon Master device
I tested on RB3 board and it looks good to me, Applied all now.
Thanks for the good cleanup :)
Signature · 1 line
~Vinod