Skip to content

Commit e174462

Browse files
hoshinolinajannau
authored andcommitted
drm/apple: audio: Create a device link to the DMA device
This works even before the DMA device probes. Might help deal with runtime-pm ordering, though it doesn't solve the deferred ordering problem (since we're creating the link while already probing)... Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 8a58516 commit e174462

1 file changed

Lines changed: 31 additions & 36 deletions

File tree

drivers/gpu/drm/apple/audio.c

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
struct dcp_audio {
3636
struct device *dev;
3737
struct device *dcp_dev;
38+
struct device *dma_dev;
39+
struct device_link *dma_link;
3840
struct dma_chan *chan;
3941
struct snd_card *card;
4042
struct snd_jack *jack;
@@ -586,40 +588,13 @@ void dcpaud_disconnect(struct platform_device *pdev)
586588
dcpaud_report_hotplug(dcpaud, false);
587589
}
588590

589-
static ssize_t probe_snd_card_store(struct device *dev,
590-
struct device_attribute *attr,
591-
const char *buf, size_t count)
592-
{
593-
int ret;
594-
bool connected = false;
595-
struct dcp_audio *dcpaud = dev_get_drvdata(dev);
596-
597-
mutex_lock(&dcpaud->data_lock);
598-
599-
if (!dcpaud->chan) {
600-
ret = dcpaud_init_snd_card(dcpaud);
601-
if (ret)
602-
goto out_unlock;
603-
604-
connected = dcpaud->dcp_connected;
605-
if (connected) {
606-
dcpaud_report_hotplug(dcpaud, connected);
607-
goto out;
608-
}
609-
}
610-
out_unlock:
611-
mutex_unlock(&dcpaud->data_lock);
612-
out:
613-
return count;
614-
}
615-
616-
static const DEVICE_ATTR_WO(probe_snd_card);
617-
618591
static int dcpaud_comp_bind(struct device *dev, struct device *main, void *data)
619592
{
620593
struct dcp_audio *dcpaud = dev_get_drvdata(dev);
621594
struct device_node *endpoint, *dcp_node = NULL;
622-
struct platform_device *dcp_pdev;
595+
struct platform_device *dcp_pdev, *dma_pdev;
596+
struct of_phandle_args dma_spec;
597+
int index;
623598
int ret;
624599

625600
/* find linked DCP instance */
@@ -634,6 +609,18 @@ static int dcpaud_comp_bind(struct device *dev, struct device *main, void *data)
634609
return 0;
635610
}
636611

612+
index = of_property_match_string(dev->of_node, "dma-names", "tx");
613+
if (index < 0) {
614+
dev_err(dev, "No dma-names property\n");
615+
return 0;
616+
}
617+
618+
if (of_parse_phandle_with_args(dev->of_node, "dmas", "#dma-cells", index,
619+
&dma_spec) || !dma_spec.np) {
620+
dev_err(dev, "Failed to parse dmas property\n");
621+
return 0;
622+
}
623+
637624
dcp_pdev = of_find_device_by_node(dcp_node);
638625
of_node_put(dcp_node);
639626
if (!dcp_pdev) {
@@ -642,12 +629,17 @@ static int dcpaud_comp_bind(struct device *dev, struct device *main, void *data)
642629
}
643630
dcpaud->dcp_dev = &dcp_pdev->dev;
644631

645-
dcpaud_expose_debugfs_blob(dcpaud, "selected_cookie", &dcpaud->selected_cookie,
646-
sizeof(dcpaud->selected_cookie));
647-
dcpaud_expose_debugfs_blob(dcpaud, "elements", dcpaud->elements,
648-
DCPAUD_ELEMENTS_MAXSIZE);
649-
dcpaud_expose_debugfs_blob(dcpaud, "product_attrs", dcpaud->productattrs,
650-
DCPAUD_PRODUCTATTRS_MAXSIZE);
632+
633+
dma_pdev = of_find_device_by_node(dma_spec.np);
634+
of_node_put(dma_spec.np);
635+
if (!dma_pdev) {
636+
dev_info(dev, "No DMA device\n");
637+
return 0;
638+
}
639+
dcpaud->dma_dev = &dma_pdev->dev;
640+
641+
dcpaud->dma_link = device_link_add(dev, dcpaud->dma_dev, DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE |
642+
DL_FLAG_STATELESS);
651643

652644
mutex_lock(&dcpaud->data_lock);
653645
/* ignore errors to prevent audio issues affecting the display side */
@@ -668,6 +660,9 @@ static void dcpaud_comp_unbind(struct device *dev, struct device *main,
668660

669661
/* snd_card_free_when_closed() checks for NULL */
670662
snd_card_free_when_closed(dcpaud->card);
663+
664+
if (dcpaud->dma_link)
665+
device_link_del(dcpaud->dma_link);
671666
}
672667

673668
static const struct component_ops dcpaud_comp_ops = {

0 commit comments

Comments
 (0)