soundwire: create master device and use it
Subsystems (3)
Bard Liao
maintainercover soundwire: create master device and use it
This series adds sdw master devices and use it instead of platform devices.
An open needs to be addressed is that should we use differrent bus type for sdw master and slave devices?
Pierre-Louis Bossart (4):
soundwire: bus_type: add sdw_master_device support
soundwire: qcom: fix error handling in probe
soundwire: qcom: add sdw_master_device support
soundwire: intel: transition to sdw_master_device
Srinivas Kandagatla (1):
soundwire: master: use device node pointer from master device
drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.h | 2 + drivers/soundwire/bus_type.c | 19 +- drivers/soundwire/intel.c | 98 ++++++---- drivers/soundwire/intel.h | 8 +- drivers/soundwire/intel_init.c | 293 ++++++++++++++++++++++------- drivers/soundwire/master.c | 168 +++++++++++++++++ drivers/soundwire/qcom.c | 59 ++++-- drivers/soundwire/slave.c | 8 +- include/linux/soundwire/sdw.h | 60 ++++++ include/linux/soundwire/sdw_type.h | 10 +- 11 files changed, 601 insertions(+), 126 deletions(-) create mode 100644 drivers/soundwire/master.c
Signature · 1 line
2.17.1
Bard Liao
maintainerRFC 1/5 soundwire: bus_type: add sdw_master_device support
From: 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).
The SoundWire Master Device provides the clock, synchronization information and command/control channels. When multiple links are supported, a Controller may expose more than one Master Device; they are typically embedded inside a larger audio cluster (be it in an SOC/chipset or an external audio codec), and we need to describe it using the Linux device and driver model. This will allow for configuration functions to account for external dependencies such as power rails, clock sources or wake-up mechanisms. This transition will also allow for better sysfs support without the reference count issues mentioned in the initial reviews.
In this patch, we convert the existing code to use an explicit sdw_slave_type, then define a sdw_master_device structure.
A parent (such as the Intel audio controller or its equivalent on Qualcomm devices) would use sdw_master_device_add() to create the device, the master device would be released when sdw_master_device_del() is invoked by the parent.
The 'Master Device' device can be configured with optional link ops, in case an implementation needs link-specific resources allocated or power-management capabilities. The .add/.del callbacks are handled internally by the SoundWire core, while the optional .startup/.process_wake need to be called by the parent directly (using wrappers). The uevent handling is moved to the slave side since it's not relevant for master devices.
Additional callbacks will be added in the future for e.g. autonomous clock stop modes.
Credits to Jaroslav Kysela <[email protected]> for the idea of using link_ops.
--- drivers/soundwire/Makefile | 2 +- drivers/soundwire/bus.h | 2 + drivers/soundwire/bus_type.c | 19 ++-- drivers/soundwire/master.c | 167 +++++++++++++++++++++++++++++ drivers/soundwire/slave.c | 8 +- include/linux/soundwire/sdw.h | 60 +++++++++++ include/linux/soundwire/sdw_type.h | 10 +- 7 files changed, 258 insertions(+), 10 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.h +2 -0
@@ -173,4 +173,6 @@ sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)void sdw_clear_slave_status (struct sdw_bus *bus,u32 request); +int sdw_slave_uevent (struct device *dev,struct kobj_uevent_env *env); +#endif /* __SDW_BUS_H */
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/master.c new file +167 -0
167 lines not on this page · raw message
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.h +60 -0
72 lines not on this page · raw message
include/linux/soundwire/sdw_type.h +8 -2
@@ -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,8 +21,6 @@ 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); -/** * module_sdw_driver() - Helper macro for registering a Soundwire driver * @__sdw_driver: soundwire slave driver struct
@@ -27,4 +32,5 @@ int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);#define module_sdw_driver (__sdw_driver) \ module_driver(__sdw_driver, sdw_register_driver, \ sdw_unregister_driver) +#endif /* __SOUNDWIRE_TYPES_H */
Signature · 1 line
2.17.1
Vinod Koul
maintainerRe: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Hello Bard,
Quoted 6 lines · Bard Liao
From: 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).
Quoted 10 lines
The SoundWire Master Device provides the clock, synchronization information and command/control channels. When multiple links are supported, a Controller may expose more than one Master Device; they are typically embedded inside a larger audio cluster (be it in an SOC/chipset or an external audio codec), and we need to describe it using the Linux device and driver model. This will allow for configuration functions to account for external dependencies such as power rails, clock sources or wake-up mechanisms. This transition will also allow for better sysfs support without the reference count issues mentioned in the initial reviews.
Well the primary reason for doing sdw_master_device for creating a adding sysfs representation. It *also* helps some vendors due to inherent model should not be constructed as the primary approach for the sdw_master_device.
Quoted 2 lines
In this patch, we convert the existing code to use an explicit
sdw_slave_type, then define asdw_master_devicestructure.
Please split that up, we should do the conversions required first and then do addition of new things.
Quoted 36 lines
drivers/soundwire/master.c new file +36
-0+struct device_type sdw_master_type = { + .name ="soundwire_master" , + .release = sdw_master_device_release, +}; + +/** +* sdw_master_device_add() - create a Linux Master Device representation. +* @parent: the parent Linux device (e.g. a PCI device) +* @fwnode: the parent fwnode (e.g. an ACPI companion device to the parent) +* @link_ops: link-specific ops (optional) +* @link_id: link index as defined by MIPI DisCo specification +* @pdata: private data (e.g. register base, offsets, platform quirks, etc). +* +* The link_ops argument can be NULL, it is only used when link-specific +* initializations and power-management are required. +*/ +struct sdw_master_device +*sdw_master_device_add (struct device *parent, +struct fwnode_handle *fwnode, +struct sdw_link_ops *link_ops, +int link_id, +void *pdata) +{ +struct sdw_master_device *md; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return ERR_PTR (-ENOMEM ); + + md->link_id = link_id; + md->pdata = pdata; + md->link_ops = link_ops; + + md->dev.parent = parent; + md->dev.fwnode = fwnode;
drivers/soundwire/master.c line 62
Quoted 10 lines
drivers/soundwire/master.c new file +10
-0+ md->dev.bus = &sdw_bus_type; + md->dev.type = &sdw_master_type; + md->dev.dma_mask = md->dev.parent->dma_mask; +dev_set_name (&md->dev,"sdw-master-%d" , md->link_id); + +if (link_ops && link_ops->driver) { +/* +* A driver is only needed for ASoC integration (need +* driver->name) and for link-specific power management +* w/ a pm_dev_ops structure.
That is not true for everyone, it is only true for Intel, pls call that out as well...
Quoted 24 lines
drivers/soundwire/master.c new file +24
-0+* +* The driver needs to be registered by the parent +*/ + md->dev.driver = link_ops->driver; + } + + ret =device_register (&md->dev); +if (ret) { +dev_err (parent,"Failed to add master: ret %d\n" , ret); +/* +* On err, don't free but drop ref as this will be freed +* when release method is invoked. +*/ +put_device (&md->dev); + goto device_register_err; + } + +if (link_ops && link_ops->add) { + ret = link_ops->add (md, pdata); +if (ret <0 ) { +dev_err (&md->dev,"link_ops add callback failed: %d\n" , + ret); + goto link_add_err; + }
drivers/soundwire/master.c line 96
Quoted 10 lines
drivers/soundwire/master.c new file +10
-0+ } + +return md; + +link_add_err: +device_unregister (&md->dev); +device_register_err: +return ERR_PTR (ret); +} +EXPORT_SYMBOL_GPL (sdw_master_device_add);
This looks better than last version for sure. But I would like this to be split into two parts, a generic sdw_master_device addition without the link_ops parts. And then the link_ops parts..
As discussed earlier with you, I see no reason why users should have two APIs. We should fold the sdw_master_device_add() within the sdw_add_bus_master() afterall as part of adding bus, we should be creating the sdw_master_dev as well as sdw_slave.
Since you have additional link_ops, we can pass that to sdw_add_bus_master() (set to NULL for rest) and then call sdw_master_device_add() internally..
As requested above, please split this to separate patches, first generic sdw_master_device addition and calling from sdw_add_bus_master() and then adding link_ops parts for Intel.
Ofcourse any preparatory patches should come before that.
Signature · 1 line
~Vinod
Re: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 20 lines · Vinod Koul
Hello Bard,
Quoted 6 lines · Bard Liao
From: 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).
Quoted 10 lines
The SoundWire Master Device provides the clock, synchronization information and command/control channels. When multiple links are supported, a Controller may expose more than one Master Device; they are typically embedded inside a larger audio cluster (be it in an SOC/chipset or an external audio codec), and we need to describe it using the Linux device and driver model. This will allow for configuration functions to account for external dependencies such as power rails, clock sources or wake-up mechanisms. This transition will also allow for better sysfs support without the reference count issues mentioned in the initial reviews.
Quoted 2 lines
Well the primary reason for doing
sdw_master_devicefor creating a adding sysfs representation.
-ENOPARSE :(
Quoted 3 lines
It *also* helps some vendors due to
inherent model should not be constructed as the primary approach for thesdw_master_device.
No, the PRIMARY reason is "it is the correct thing to do". It's how to tie into the driver model correctly, without it, crazy things happen as we have seen.
Quoted 5 lines
Quoted 2 lines
In this patch, we convert the existing code to use an explicit
sdw_slave_type, then define asdw_master_devicestructure.Please split that up, we should do the conversions required first and then do addition of new things.
Can you really do that in two different steps?
Quoted 41 lines
Quoted 41 lines
drivers/soundwire/master.c new file +41
-0+struct device_type sdw_master_type = { + .name ="soundwire_master" , + .release = sdw_master_device_release, +}; + +/** +* sdw_master_device_add() - create a Linux Master Device representation. +* @parent: the parent Linux device (e.g. a PCI device) +* @fwnode: the parent fwnode (e.g. an ACPI companion device to the parent) +* @link_ops: link-specific ops (optional) +* @link_id: link index as defined by MIPI DisCo specification +* @pdata: private data (e.g. register base, offsets, platform quirks, etc). +* +* The link_ops argument can be NULL, it is only used when link-specific +* initializations and power-management are required. +*/ +struct sdw_master_device +*sdw_master_device_add (struct device *parent, +struct fwnode_handle *fwnode, +struct sdw_link_ops *link_ops, +int link_id, +void *pdata) +{ +struct sdw_master_device *md; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return ERR_PTR (-ENOMEM ); + + md->link_id = link_id; + md->pdata = pdata; + md->link_ops = link_ops; + + md->dev.parent = parent; + md->dev.fwnode = fwnode; + md->dev.bus = &sdw_bus_type; + md->dev.type = &sdw_master_type; + md->dev.dma_mask = md->dev.parent->dma_mask; +dev_set_name (&md->dev,"sdw-master-%d" , md->link_id); +
Quoted 8 lines
drivers/soundwire/master.c line 62
Quoted 5 lines
drivers/soundwire/master.c new file +5
-0+if (link_ops && link_ops->driver) { +/* +* A driver is only needed for ASoC integration (need +* driver->name) and for link-specific power management +* w/ a pm_dev_ops structure. That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
thanks,
greg k-h
Vinod Koul
maintainerRe: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Hi Greg,
Quoted 21 lines · Greg KH
Quoted 20 lines · Vinod Koul
Hello Bard,
Quoted 16 lines · Bard Liao
From: 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).
The SoundWire Master Device provides the clock, synchronization information and command/control channels. When multiple links are supported, a Controller may expose more than one Master Device; they are typically embedded inside a larger audio cluster (be it in an SOC/chipset or an external audio codec), and we need to describe it using the Linux device and driver model. This will allow for configuration functions to account for external dependencies such as power rails, clock sources or wake-up mechanisms. This transition will also allow for better sysfs support without the reference count issues mentioned in the initial reviews.
Quoted 4 lines
Quoted 2 lines
Well the primary reason for doing
sdw_master_devicefor creating a adding sysfs representation.
-ENOPARSE:(
Oops, sorry!
Quoted 7 lines
Quoted 3 lines
It *also* helps some vendors due to
inherent model should not be constructed as the primary approach for thesdw_master_device.No, the PRIMARY reason is "it is the correct thing to do". It's how to tie into the driver model correctly, without it, crazy things happen as we have seen.
I agree it is *the* right this to do!
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
In this patch, we convert the existing code to use an explicit
sdw_slave_type, then define asdw_master_devicestructure.Please split that up, we should do the conversions required first and then do addition of new things.
Can you really do that in two different steps?
Looking at it, the move of existing types first and then adding the new type
Quoted 51 lines
Quoted 42 lines
Quoted 42 lines
drivers/soundwire/master.c new file +41
-0+struct device_type sdw_master_type = { + .name ="soundwire_master" , + .release = sdw_master_device_release, +}; + +/** +* sdw_master_device_add() - create a Linux Master Device representation. +* @parent: the parent Linux device (e.g. a PCI device) +* @fwnode: the parent fwnode (e.g. an ACPI companion device to the parent) +* @link_ops: link-specific ops (optional) +* @link_id: link index as defined by MIPI DisCo specification +* @pdata: private data (e.g. register base, offsets, platform quirks, etc). +* +* The link_ops argument can be NULL, it is only used when link-specific +* initializations and power-management are required. +*/ +struct sdw_master_device +*sdw_master_device_add (struct device *parent, +struct fwnode_handle *fwnode, +struct sdw_link_ops *link_ops, +int link_id, +void *pdata) +{ +struct sdw_master_device *md; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return ERR_PTR (-ENOMEM ); + + md->link_id = link_id; + md->pdata = pdata; + md->link_ops = link_ops; + + md->dev.parent = parent; + md->dev.fwnode = fwnode; + md->dev.bus = &sdw_bus_type; + md->dev.type = &sdw_master_type; + md->dev.dma_mask = md->dev.parent->dma_mask; +dev_set_name (&md->dev,"sdw-master-%d" , md->link_id); +Quoted 8 lines
drivers/soundwire/master.c line 62
Quoted 5 lines
drivers/soundwire/master.c new file +5
-0+if (link_ops && link_ops->driver) { +/* +* A driver is only needed for ASoC integration (need +* driver->name) and for link-specific power management +* w/ a pm_dev_ops structure. That is not true for everyone, it is only true for Intel, pls call that out as well...
Quoted 2 lines
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
Thanks
Signature · 1 line
~Vinod
Re: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 6 lines · Vinod Koul
Quoted 5 lines
Quoted 2 lines
That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
Quoted 6 lines
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
If it is not a standalone controller, what exactly is it? I thought it was an acpi device, am I mistaken?
What is the device that the proper soundwire controller driver binds to on an Intel-based system?
thanks,
greg k-h
Vinod Koul
maintainerRe: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 11 lines · Greg KH
Quoted 10 lines · Vinod Koul
Quoted 5 lines
Quoted 2 lines
That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
Quoted 8 lines
Quoted 2 lines
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
If it is not a standalone controller, what exactly is it? I thought it was an acpi device, am I mistaken?
What is the device that the proper soundwire controller driver binds to on an Intel-based system?
The HDA controller which is a PCI device. The device represent HDA function, DSP and Soundwire controller instances (yes it is typically more than one instance)
Thanks
Signature · 1 line
~Vinod
Re: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 18 lines · Vinod Koul
Quoted 17 lines · Greg KH
Quoted 6 lines · Vinod Koul
Quoted 5 lines
Quoted 2 lines
That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
Quoted 6 lines
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
If it is not a standalone controller, what exactly is it? I thought it was an acpi device, am I mistaken?
Quoted 6 lines
Quoted 2 lines
What is the device that the proper soundwire controller driver binds to on an Intel-based system?
The HDA controller which is a PCI device. The device represent HDA function, DSP and Soundwire controller instances (yes it is typically more than one instance)
Then those "instances" should be split up into individual devices that a driver can bind to. See the work happening on the "virtual" bus for examples of how that can be done.
A platform device better not be being used here, I'm afraid to look at the code now...
greg k-h
Vinod Koul
maintainerRe: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 22 lines · Greg KH
Quoted 21 lines · Vinod Koul
Quoted 19 lines · Greg KH
Quoted 6 lines · Vinod Koul
Quoted 5 lines
Quoted 2 lines
That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
Quoted 6 lines
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
If it is not a standalone controller, what exactly is it? I thought it was an acpi device, am I mistaken?
What is the device that the proper soundwire controller driver binds to on an Intel-based system?
Quoted 7 lines
Quoted 3 lines
The HDA controller which is a PCI device. The device represent HDA function, DSP and Soundwire controller instances (yes it is typically more than one instance)
Then those "instances" should be split up into individual devices that a driver can bind to. See the work happening on the "virtual" bus for examples of how that can be done.
Yes removing platform devices is the goal for Intel now :) Pierre & Bard have been diligently trying to solve this.
Only difference is the means to end goal. I am not convinced that this should be in soundwire subsystem.
Looks like folks are trying to review and port to use this bus. Makes sense to me..
https://lore.kernel.org/netdev/[email protected]/
Quoted 2 lines
A platform device better not be being used here, I'm afraid to look at the code now...
Well if the plan for 'virtual-bus' goes well, it should be a simple replacement of platform->virtual for Intel driver. Rest of the driver should not be impacted :)
Thanks
Signature · 1 line
~Vinod
Bard liao
maintainerRe: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 35 lines · Vinod Koul
Quoted 16 lines · Greg KH
Quoted 15 lines · Vinod Koul
Quoted 14 lines · Greg KH
Quoted 10 lines · Vinod Koul
Quoted 4 lines
Quoted 2 lines
That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
If it is not a standalone controller, what exactly is it? I thought it was an acpi device, am I mistaken?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
What is the device that the proper soundwire controller driver binds to on an Intel-based system?
The HDA controller which is a PCI device. The device represent HDA function, DSP and Soundwire controller instances (yes it is typically more than one instance)
Then those "instances" should be split up into individual devices that a driver can bind to. See the work happening on the "virtual" bus for examples of how that can be done.
Yes removing platform devices is the goal for Intel now :) Pierre & Bard have been diligently trying to solve this.
Only difference is the means to end goal. I am not convinced that this should be in soundwire subsystem.
Looks like folks are trying to review and port to use this bus. Makes sense to me..
https://lore.kernel.org/netdev/[email protected]/
Quoted 5 lines
Quoted 2 lines
A platform device better not be being used here, I'm afraid to look at the code now...
Well if the plan for 'virtual-bus' goes well, it should be a simple replacement of
platform->virtualfor Intel driver. Rest of the driver should not be impacted :)
We can't expect when will 'virtual-bus' be upstream and it's not feasible to wait forever. Can we move forward with current solution and switch to 'virtual-bus' whenever it is upstream?
Quoted 1 line
Thanks
Vinod Koul
maintainerRe: [RFC 1/5] soundwire: bus_type: add sdw_master_device support
Quoted 39 lines · Bard liao
Quoted 37 lines · Vinod Koul
Quoted 16 lines · Greg KH
Quoted 15 lines · Vinod Koul
Quoted 14 lines · Greg KH
Quoted 10 lines · Vinod Koul
Quoted 4 lines
Quoted 2 lines
That is not true for everyone, it is only true for Intel, pls call that out as well...
Why is it not true for everyone? How else do you get the pm stuff back to your hardware?
The rest of the world would do using the real controller device. For example the soundwire controller on Qualcomm devices is enumerated as a DT device and is using these...
If Intel had a standalone controller or enumerated as individual functions, it would have been a PCI device and would manage as such
If it is not a standalone controller, what exactly is it? I thought it was an acpi device, am I mistaken?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
What is the device that the proper soundwire controller driver binds to on an Intel-based system?
The HDA controller which is a PCI device. The device represent HDA function, DSP and Soundwire controller instances (yes it is typically more than one instance)
Then those "instances" should be split up into individual devices that a driver can bind to. See the work happening on the "virtual" bus for examples of how that can be done.
Yes removing platform devices is the goal for Intel now :) Pierre & Bard have been diligently trying to solve this.
Only difference is the means to end goal. I am not convinced that this should be in soundwire subsystem.
Looks like folks are trying to review and port to use this bus. Makes sense to me..
https://lore.kernel.org/netdev/[email protected]/Quoted 2 lines
A platform device better not be being used here, I'm afraid to look at the code now...
Quoted 7 lines
Quoted 3 lines
Well if the plan for 'virtual-bus' goes well, it should be a simple replacement of
platform->virtualfor Intel driver. Rest of the driver should not be impacted :)We can't expect when will 'virtual-bus' be upstream and it's not feasible to wait forever. Can we move forward with current solution and switch to 'virtual-bus' whenever it is upstream?
the move from platform-device to virtual-device should happen once the virtual-bus' is accepted upstream. till then imo you should continue with current platform device and once you have virtual-bus upstream, replace it with virtual-device. Note: I am going to hold you on that :)
Rest of the pieces like sdw_master_device and sysfs parts are not dependent upon this and should be sent for review and we can merge when ready, hopefully for 5.8.
Thanks
Signature · 1 line
~Vinod
Bard Liao
maintainerRFC 2/5 soundwire: master: use device node pointer from master device
In reply to Bard LiaoFrom: Srinivas Kandagatla <[email protected]>
device_node pointer is required for scanning slave devices, update it from the master device.
--- drivers/soundwire/master.c | 1 + 1 file changed, 1 insertion(+)
drivers/soundwire/master.c +1 -0
@@ -49,6 +49,7 @@ struct sdw_master_device md->link_ops = link_ops; md->dev.parent = parent; + md->dev.of_node = parent->of_node; md->dev.fwnode = fwnode; md->dev.bus = &sdw_bus_type; md->dev.type = &sdw_master_type;
Signature · 1 line
2.17.1
Bard Liao
maintainerRFC 3/5 soundwire: qcom: fix error handling in probe
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Make sure all error cases are properly handled and all resources freed.
--- drivers/soundwire/qcom.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/soundwire/qcom.c +17 -9
@@ -765,12 +765,16 @@ static int qcom_swrm_probe(struct platform_device *pdev) } ctrl->irq =of_irq_get (dev->of_node,0 ); -if (ctrl->irq <0 ) -return ctrl->irq; +if (ctrl->irq <0 ) { + ret = ctrl->irq; + goto err_init; + } ctrl->hclk =devm_clk_get (dev,"iface" ); -if (IS_ERR (ctrl->hclk)) -return PTR_ERR (ctrl->hclk); +if (IS_ERR (ctrl->hclk)) { + ret =PTR_ERR (ctrl->hclk); + goto err_init; + }clk_prepare_enable (ctrl->hclk);
@@ -787,7 +791,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) ret =qcom_swrm_get_port_config (ctrl);if (ret) -return ret; + goto err_clk; params = &ctrl->bus.params; params->max_dr_freq =DEFAULT_CLK_FREQ ;
@@ -814,28 +818,32 @@ static int qcom_swrm_probe(struct platform_device *pdev) "soundwire", ctrl);if (ret) {dev_err (dev,"Failed to request soundwire irq\n" ); - goto err; + goto err_clk; } ret =sdw_add_bus_master (&ctrl->bus);if (ret) {dev_err (dev,"Failed to register Soundwire controller (%d)\n" , ret); - goto err; + goto err_clk; }qcom_swrm_init (ctrl); ret =qcom_swrm_register_dais (ctrl);if (ret) - goto err; + goto err_master_add;dev_info (dev,"Qualcomm Soundwire controller v%x.%x.%x Registered\n" , (ctrl->version >>24 ) &0xff , (ctrl->version >>16 ) &0xff , ctrl->version &0xffff );return 0 ; -err: + +err_master_add: +sdw_delete_bus_master (&ctrl->bus); +err_clk:clk_disable_unprepare (ctrl->hclk); +err_init:return ret; }
Signature · 1 line
2.17.1
Re: [RFC 3/5] soundwire: qcom: fix error handling in probe
Quoted 7 lines · Bard Liao
From: Pierre-Louis Bossart <[email protected]>
Make sure all error cases are properly handled and all resources freed.
Signed-off-by Pierre-Louis Bossart <[email protected]>Signed-off-by Bard Liao <[email protected]>---
Thanks for the patch,
Quoted 75 lines
drivers/soundwire/qcom.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)drivers/soundwire/qcom.c +17
-9@@ -765,12 +765,16 @@ static int qcom_swrm_probe(struct platform_device *pdev) } ctrl->irq =of_irq_get (dev->of_node,0 ); -if (ctrl->irq <0 ) -return ctrl->irq; +if (ctrl->irq <0 ) { + ret = ctrl->irq; + goto err_init; + } ctrl->hclk =devm_clk_get (dev,"iface" ); -if (IS_ERR (ctrl->hclk)) -return PTR_ERR (ctrl->hclk); +if (IS_ERR (ctrl->hclk)) { + ret =PTR_ERR (ctrl->hclk); + goto err_init; + }clk_prepare_enable (ctrl->hclk);@@ -787,7 +791,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) ret =qcom_swrm_get_port_config (ctrl);if (ret) -return ret; + goto err_clk; params = &ctrl->bus.params; params->max_dr_freq =DEFAULT_CLK_FREQ ;@@ -814,28 +818,32 @@ static int qcom_swrm_probe(struct platform_device *pdev) "soundwire", ctrl);if (ret) {dev_err (dev,"Failed to request soundwire irq\n" ); - goto err; + goto err_clk; } ret =sdw_add_bus_master (&ctrl->bus);if (ret) {dev_err (dev,"Failed to register Soundwire controller (%d)\n" , ret); - goto err; + goto err_clk; }qcom_swrm_init (ctrl); ret =qcom_swrm_register_dais (ctrl);if (ret) - goto err; + goto err_master_add;dev_info (dev,"Qualcomm Soundwire controller v%x.%x.%x Registered\n" , (ctrl->version >>24 ) &0xff , (ctrl->version >>16 ) &0xff , ctrl->version &0xffff );return 0 ; -err: + +err_master_add: +sdw_delete_bus_master (&ctrl->bus); +err_clk:clk_disable_unprepare (ctrl->hclk); +err_init:return ret; }
Bard Liao
maintainerRFC 4/5 soundwire: qcom: add sdw_master_device support
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Add new device as a child of the platform device, following the following hierarchy:
platform_device
sdw_master_device
sdw_slave0
...
sdw_slaveNFor 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.
--- drivers/soundwire/qcom.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-)
drivers/soundwire/qcom.c +34 -5
@@ -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 ;
Signature · 1 line
2.17.1
Bard Liao
maintainerRFC 5/5 soundwire: intel: transition to sdw_master_device
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Use sdw_master_device instead of platform devices
In addition, rather than a plain-vanilla init/exit, this patch provides 3 steps in the initialization (ACPI scan, probe, startup) which makes it easier to detect platform support for SoundWire, allocate required resources as early as possible, and conversely help make the startup() callback lighter-weight with only hardware register setup.
--- drivers/soundwire/intel.c | 98 +++++++---- drivers/soundwire/intel.h | 8 +- drivers/soundwire/intel_init.c | 293 +++++++++++++++++++++++++-------- 3 files changed, 294 insertions(+), 105 deletions(-)
drivers/soundwire/intel.c +62 -36
@@ -11,12 +11,12 @@#include <linux/module.h> #include <linux/interrupt.h> #include <linux/io.h> -#include <linux/platform_device.h> #include <sound/pcm_params.h> #include <sound/soc.h> #include <linux/soundwire/sdw_registers.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_intel.h> +#include <linux/soundwire/sdw_type.h> #include "cadence_master.h" #include "bus.h" #include "intel.h"
@@ -92,8 +92,6 @@#define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0)#define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16) -#define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) -enum intel_pdi_type {INTEL_PDI_IN =0 ,INTEL_PDI_OUT =1 ,
@@ -1083,24 +1081,23 @@ static int intel_init(struct sdw_intel *sdw)/* * probe and init */ -static int intel_probe (struct platform_device *pdev) +static int intel_master_probe (struct sdw_master_device *md,void *link_ctx) { -struct sdw_cdns_stream_config config;struct sdw_intel *sdw;int ret; - sdw =devm_kzalloc (&pdev->dev,sizeof (*sdw),GFP_KERNEL ); + sdw =devm_kzalloc (&md->dev,sizeof (*sdw),GFP_KERNEL );if (!sdw)return -ENOMEM ; - sdw->instance = pdev->id; - sdw->link_res =dev_get_platdata (&pdev->dev); - sdw->cdns.dev = &pdev->dev; + sdw->instance = md->link_id; + sdw->link_res = link_ctx; + sdw->cdns.dev = &md->dev; sdw->cdns.registers = sdw->link_res->registers; - sdw->cdns.instance = sdw->instance; + sdw->cdns.instance = md->link_id; sdw->cdns.msg_count =0 ; - sdw->cdns.bus.dev = &pdev->dev; - sdw->cdns.bus.link_id = pdev->id; + sdw->cdns.bus.dev = &md->dev; + sdw->cdns.bus.link_id = md->link_id;sdw_cdns_probe (&sdw->cdns);
@@ -1108,16 +1105,51 @@ static int intel_probe(struct platform_device *pdev) sdw_intel_ops.read_prop = intel_prop_read; sdw->cdns.bus.ops = &sdw_intel_ops; -platform_set_drvdata (pdev, sdw); + md->bus = &sdw->cdns.bus; + md->pdata = sdw; + +/* set driver data, accessed by snd_soc_dai_set_drvdata() */ +dev_set_drvdata (&md->dev, &sdw->cdns); ret =sdw_add_bus_master (&sdw->cdns.bus);if (ret) { -dev_err (&pdev->dev,"sdw_add_bus_master fail: %d\n" , ret); +dev_err (&md->dev,"sdw_add_bus_master fail: %d\n" , ret);return ret; } +if (sdw->cdns.bus.prop.hw_disabled) +dev_info (&md->dev, +"SoundWire master %d is disabled, will be ignored\n" , + sdw->cdns.bus.link_id); + +/* Acquire IRQ */ + ret =request_threaded_irq (sdw->link_res->irq, + sdw_cdns_irq, sdw_cdns_thread, +IRQF_SHARED ,KBUILD_MODNAME , &sdw->cdns); +if (ret <0 ) { +dev_err (sdw->cdns.dev,"unable to grab IRQ %d, disabling device\n" , + sdw->link_res->irq); + goto err_init; + } + +return 0 ; + +err_init: +sdw_delete_bus_master (&sdw->cdns.bus); +return ret; +} + +static int intel_master_startup (struct sdw_master_device *md) +{ +struct sdw_cdns_stream_config config; +struct sdw_intel *sdw; +int ret; + + sdw = md->pdata; +if (sdw->cdns.bus.prop.hw_disabled) { -dev_info (&pdev->dev,"SoundWire master %d is disabled, ignoring\n" , +dev_info (&md->dev, +"SoundWire master %d is disabled, ignoring\n" , sdw->cdns.bus.link_id);return 0 ; }
@@ -1135,16 +1167,6 @@ static int intel_probe(struct platform_device *pdev)intel_pdi_ch_update (sdw); -/* Acquire IRQ */ - ret =request_threaded_irq (sdw->link_res->irq, - sdw_cdns_irq, sdw_cdns_thread, -IRQF_SHARED ,KBUILD_MODNAME , &sdw->cdns); -if (ret <0 ) { -dev_err (sdw->cdns.dev,"unable to grab IRQ %d, disabling device\n" , - sdw->link_res->irq); - goto err_init; - } - ret =sdw_cdns_enable_interrupt (&sdw->cdns, true);if (ret <0 ) {dev_err (sdw->cdns.dev,"cannot enable interrupts\n" );
@@ -1171,17 +1193,17 @@ static int intel_probe(struct platform_device *pdev) err_interrupt:sdw_cdns_enable_interrupt (&sdw->cdns, false); -free_irq (sdw->link_res->irq, sdw); err_init: +free_irq (sdw->link_res->irq, sdw);sdw_delete_bus_master (&sdw->cdns.bus);return ret; } -static int intel_remove (struct platform_device *pdev) +static int intel_master_remove (struct sdw_master_device *md) {struct sdw_intel *sdw; - sdw =platform_get_drvdata (pdev); + sdw = md->pdata;if (!sdw->cdns.bus.prop.hw_disabled) {intel_debugfs_exit (sdw);
@@ -1194,17 +1216,21 @@ static int intel_remove(struct platform_device *pdev)return 0 ; } -static struct platform_driver sdw_intel_drv = { - .probe = intel_probe, - .remove = intel_remove, - .driver = { - .name ="int-sdw" , - }, +static struct device_driver sdw_intel_driver = { + .name ="intel-master" , + .bus = &sdw_bus_type, }; -module_platform_driver (sdw_intel_drv); +struct sdw_link_ops sdw_intel_link_ops = { + .driver = &sdw_intel_driver, + .add = intel_master_probe, + .startup = intel_master_startup, + .del = intel_master_remove, + .process_wake_event = intel_master_process_wakeen_event, +}; +EXPORT_SYMBOL (sdw_intel_link_ops);MODULE_LICENSE ("Dual BSD/GPL" ); -MODULE_ALIAS ("platform:int-sdw" ); +MODULE_ALIAS ("sdw:intel-master" );MODULE_DESCRIPTION ("Intel Soundwire Master Driver" );
drivers/soundwire/intel.h +6 -2
@@ -7,7 +7,7 @@/** * struct sdw_intel_link_res - Soundwire Intel link resource structure, * typically populated by the controller driver. -* @pdev: platform_device +* @md: master device * @mmio_base: mmio base of SoundWire registers * @registers: Link IO registers base * @shim: Audio shim pointer
@@ -17,7 +17,7 @@* @dev: device implementing hw_params and free callbacks */ struct sdw_intel_link_res { -struct platform_device *pdev; +struct sdw_master_device *md;void __iomem *mmio_base;/* not strictly needed, useful for debug */ void __iomem *registers;void __iomem *shim;
@@ -27,4 +27,8 @@ struct sdw_intel_link_res { struct device *dev; }; +#define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) + +extern struct sdw_link_ops sdw_intel_link_ops; +#endif /* __SDW_INTEL_LOCAL_H */
drivers/soundwire/intel_init.c +226 -67
410 lines not on this page · raw message
Signature · 1 line
2.17.1