Skip to content

Commit 29a269c

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: intel: move to auxiliary bus
Now that the auxiliary_bus exists, there's no reason to use platform devices as children of a PCI device any longer. This patch refactors the code by extending a basic auxiliary device with Intel link-specific structures that need to be passed between controller and link levels. This refactoring is much cleaner with no need for cross-pointers between device and link structures. Note that the auxiliary bus API has separate init and add steps, which requires more attention in the error unwinding paths. The main loop needs to deal with kfree() and auxiliary_device_uninit() for the current iteration before jumping to the common label which releases everything allocated in prior iterations. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://lore.kernel.org/r/20210511052132.28150-1-yung-chuan.liao@linux.intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 1ec9d2e commit 29a269c

5 files changed

Lines changed: 202 additions & 107 deletions

File tree

drivers/soundwire/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ config SOUNDWIRE_INTEL
2525
tristate "Intel SoundWire Master driver"
2626
select SOUNDWIRE_CADENCE
2727
select SOUNDWIRE_GENERIC_ALLOCATION
28+
select AUXILIARY_BUS
2829
depends on ACPI && SND_SOC
2930
help
3031
SoundWire Intel Master driver.

drivers/soundwire/intel.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/module.h>
1212
#include <linux/interrupt.h>
1313
#include <linux/io.h>
14-
#include <linux/platform_device.h>
14+
#include <linux/auxiliary_bus.h>
1515
#include <sound/pcm_params.h>
1616
#include <linux/pm_runtime.h>
1717
#include <sound/soc.h>
@@ -1327,11 +1327,14 @@ static int intel_init(struct sdw_intel *sdw)
13271327
}
13281328

13291329
/*
1330-
* probe and init
1330+
* probe and init (aux_dev_id argument is required by function prototype but not used)
13311331
*/
1332-
static int intel_master_probe(struct platform_device *pdev)
1332+
static int intel_link_probe(struct auxiliary_device *auxdev,
1333+
const struct auxiliary_device_id *aux_dev_id)
1334+
13331335
{
1334-
struct device *dev = &pdev->dev;
1336+
struct device *dev = &auxdev->dev;
1337+
struct sdw_intel_link_dev *ldev = auxiliary_dev_to_sdw_intel_link_dev(auxdev);
13351338
struct sdw_intel *sdw;
13361339
struct sdw_cdns *cdns;
13371340
struct sdw_bus *bus;
@@ -1344,14 +1347,14 @@ static int intel_master_probe(struct platform_device *pdev)
13441347
cdns = &sdw->cdns;
13451348
bus = &cdns->bus;
13461349

1347-
sdw->instance = pdev->id;
1348-
sdw->link_res = dev_get_platdata(dev);
1350+
sdw->instance = auxdev->id;
1351+
sdw->link_res = &ldev->link_res;
13491352
cdns->dev = dev;
13501353
cdns->registers = sdw->link_res->registers;
13511354
cdns->instance = sdw->instance;
13521355
cdns->msg_count = 0;
13531356

1354-
bus->link_id = pdev->id;
1357+
bus->link_id = auxdev->id;
13551358

13561359
sdw_cdns_probe(cdns);
13571360

@@ -1384,10 +1387,10 @@ static int intel_master_probe(struct platform_device *pdev)
13841387
return 0;
13851388
}
13861389

1387-
int intel_master_startup(struct platform_device *pdev)
1390+
int intel_link_startup(struct auxiliary_device *auxdev)
13881391
{
13891392
struct sdw_cdns_stream_config config;
1390-
struct device *dev = &pdev->dev;
1393+
struct device *dev = &auxdev->dev;
13911394
struct sdw_cdns *cdns = dev_get_drvdata(dev);
13921395
struct sdw_intel *sdw = cdns_to_intel(cdns);
13931396
struct sdw_bus *bus = &cdns->bus;
@@ -1524,9 +1527,9 @@ int intel_master_startup(struct platform_device *pdev)
15241527
return ret;
15251528
}
15261529

1527-
static int intel_master_remove(struct platform_device *pdev)
1530+
static void intel_link_remove(struct auxiliary_device *auxdev)
15281531
{
1529-
struct device *dev = &pdev->dev;
1532+
struct device *dev = &auxdev->dev;
15301533
struct sdw_cdns *cdns = dev_get_drvdata(dev);
15311534
struct sdw_intel *sdw = cdns_to_intel(cdns);
15321535
struct sdw_bus *bus = &cdns->bus;
@@ -1542,19 +1545,17 @@ static int intel_master_remove(struct platform_device *pdev)
15421545
snd_soc_unregister_component(dev);
15431546
}
15441547
sdw_bus_master_delete(bus);
1545-
1546-
return 0;
15471548
}
15481549

1549-
int intel_master_process_wakeen_event(struct platform_device *pdev)
1550+
int intel_link_process_wakeen_event(struct auxiliary_device *auxdev)
15501551
{
1551-
struct device *dev = &pdev->dev;
1552+
struct device *dev = &auxdev->dev;
15521553
struct sdw_intel *sdw;
15531554
struct sdw_bus *bus;
15541555
void __iomem *shim;
15551556
u16 wake_sts;
15561557

1557-
sdw = platform_get_drvdata(pdev);
1558+
sdw = dev_get_drvdata(dev);
15581559
bus = &sdw->cdns.bus;
15591560

15601561
if (bus->prop.hw_disabled) {
@@ -1976,17 +1977,22 @@ static const struct dev_pm_ops intel_pm = {
19761977
SET_RUNTIME_PM_OPS(intel_suspend_runtime, intel_resume_runtime, NULL)
19771978
};
19781979

1979-
static struct platform_driver sdw_intel_drv = {
1980-
.probe = intel_master_probe,
1981-
.remove = intel_master_remove,
1980+
static const struct auxiliary_device_id intel_link_id_table[] = {
1981+
{ .name = "soundwire_intel.link" },
1982+
{},
1983+
};
1984+
MODULE_DEVICE_TABLE(auxiliary, intel_link_id_table);
1985+
1986+
static struct auxiliary_driver sdw_intel_drv = {
1987+
.probe = intel_link_probe,
1988+
.remove = intel_link_remove,
19821989
.driver = {
1983-
.name = "intel-sdw",
1990+
/* auxiliary_driver_register() sets .name to be the modname */
19841991
.pm = &intel_pm,
1985-
}
1992+
},
1993+
.id_table = intel_link_id_table
19861994
};
1987-
1988-
module_platform_driver(sdw_intel_drv);
1995+
module_auxiliary_driver(sdw_intel_drv);
19891996

19901997
MODULE_LICENSE("Dual BSD/GPL");
1991-
MODULE_ALIAS("platform:intel-sdw");
1992-
MODULE_DESCRIPTION("Intel Soundwire Master Driver");
1998+
MODULE_DESCRIPTION("Intel Soundwire Link Driver");

drivers/soundwire/intel.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/**
88
* struct sdw_intel_link_res - Soundwire Intel link resource structure,
99
* typically populated by the controller driver.
10-
* @pdev: platform_device
1110
* @mmio_base: mmio base of SoundWire registers
1211
* @registers: Link IO registers base
1312
* @shim: Audio shim pointer
@@ -23,7 +22,6 @@
2322
* @list: used to walk-through all masters exposed by the same controller
2423
*/
2524
struct sdw_intel_link_res {
26-
struct platform_device *pdev;
2725
void __iomem *mmio_base; /* not strictly needed, useful for debug */
2826
void __iomem *registers;
2927
void __iomem *shim;
@@ -48,7 +46,15 @@ struct sdw_intel {
4846
#endif
4947
};
5048

51-
int intel_master_startup(struct platform_device *pdev);
52-
int intel_master_process_wakeen_event(struct platform_device *pdev);
49+
int intel_link_startup(struct auxiliary_device *auxdev);
50+
int intel_link_process_wakeen_event(struct auxiliary_device *auxdev);
51+
52+
struct sdw_intel_link_dev {
53+
struct auxiliary_device auxdev;
54+
struct sdw_intel_link_res link_res;
55+
};
56+
57+
#define auxiliary_dev_to_sdw_intel_link_dev(auxiliary_dev) \
58+
container_of(auxiliary_dev, struct sdw_intel_link_dev, auxdev)
5359

5460
#endif /* __SDW_INTEL_LOCAL_H */

0 commit comments

Comments
 (0)