All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ALSA: ac97: add bus binding for codecs
@ 2018-06-21 15:43 ` Robert Jarzmik
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Jarzmik @ 2018-06-21 15:43 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Jaroslav Kysela, Takashi Iwai
  Cc: alsa-devel, devicetree, linux-kernel, Robert Jarzmik

Add the generic ac97 bus binding, especially for ac97 codecs discovered
by ac97 hardware probing.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 .../devicetree/bindings/sound/ac97-bus.txt         | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ac97-bus.txt

diff --git a/Documentation/devicetree/bindings/sound/ac97-bus.txt b/Documentation/devicetree/bindings/sound/ac97-bus.txt
new file mode 100644
index 000000000000..103c428f2595
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ac97-bus.txt
@@ -0,0 +1,32 @@
+Generic AC97 Device Properties
+
+This documents describes the devicetree bindings for an ac97 controller child
+node describing ac97 codecs.
+
+Required properties:
+-compatible : Must be "ac97,vendor_id1,vendor_id2
+	      The ids shall be the 4 characters hexadecimal encoding, such as
+	      given by "%04x" formatting of printf
+-reg	    : Must be the ac97 codec number, between 0 and 3
+
+Example:
+ac97: sound@40500000 {
+	compatible = "marvell,pxa270-ac97";
+	reg = < 0x40500000 0x1000 >;
+	interrupts = <14>;
+	reset-gpios = <&gpio 95 GPIO_ACTIVE_HIGH>;
+	#sound-dai-cells = <1>;
+	pinctrl-names = "default";
+	pinctrl-0 = < &pinctrl_ac97_default >;
+	clocks = <&clks CLK_AC97>, <&clks CLK_AC97CONF>;
+	clock-names = "AC97CLK", "AC97CONFCLK";
+
+	#address-cells = <1>;
+	#size-cells = <0>;
+	audio-codec@0 {
+		reg = <0>;
+		compatible = "ac97,574d,4c13";
+		clocks = <&fixed_wm9713_clock>;
+		clock-names = "ac97_clk";
+	}
+};
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 1/2] ALSA: ac97: add bus binding for codecs
@ 2018-06-21 15:43 ` Robert Jarzmik
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Jarzmik @ 2018-06-21 15:43 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Jaroslav Kysela, Takashi Iwai
  Cc: devicetree, alsa-devel, Robert Jarzmik, linux-kernel

Add the generic ac97 bus binding, especially for ac97 codecs discovered
by ac97 hardware probing.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
 .../devicetree/bindings/sound/ac97-bus.txt         | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ac97-bus.txt

diff --git a/Documentation/devicetree/bindings/sound/ac97-bus.txt b/Documentation/devicetree/bindings/sound/ac97-bus.txt
new file mode 100644
index 000000000000..103c428f2595
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ac97-bus.txt
@@ -0,0 +1,32 @@
+Generic AC97 Device Properties
+
+This documents describes the devicetree bindings for an ac97 controller child
+node describing ac97 codecs.
+
+Required properties:
+-compatible : Must be "ac97,vendor_id1,vendor_id2
+	      The ids shall be the 4 characters hexadecimal encoding, such as
+	      given by "%04x" formatting of printf
+-reg	    : Must be the ac97 codec number, between 0 and 3
+
+Example:
+ac97: sound@40500000 {
+	compatible = "marvell,pxa270-ac97";
+	reg = < 0x40500000 0x1000 >;
+	interrupts = <14>;
+	reset-gpios = <&gpio 95 GPIO_ACTIVE_HIGH>;
+	#sound-dai-cells = <1>;
+	pinctrl-names = "default";
+	pinctrl-0 = < &pinctrl_ac97_default >;
+	clocks = <&clks CLK_AC97>, <&clks CLK_AC97CONF>;
+	clock-names = "AC97CLK", "AC97CONFCLK";
+
+	#address-cells = <1>;
+	#size-cells = <0>;
+	audio-codec@0 {
+		reg = <0>;
+		compatible = "ac97,574d,4c13";
+		clocks = <&fixed_wm9713_clock>;
+		clock-names = "ac97_clk";
+	}
+};
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
  2018-06-21 15:43 ` Robert Jarzmik
@ 2018-06-21 15:43   ` Robert Jarzmik
  -1 siblings, 0 replies; 12+ messages in thread
From: Robert Jarzmik @ 2018-06-21 15:43 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Jaroslav Kysela, Takashi Iwai
  Cc: alsa-devel, devicetree, linux-kernel, Robert Jarzmik

Add a devicetree binding for codecs. This is especially useful if the
AC97 bitclk clock is provided by the codec, as it has to be described in
the devicetree description for the ac97 bus code to aquire it.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
Special review query: review the "return of_node_get(node)", which
assumes that upon device removal, of_put_node(dev.of_node) will be
called...
---
 sound/ac97/bus.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c
index 31f858eceffc..c8e20dd8786f 100644
--- a/sound/ac97/bus.c
+++ b/sound/ac97/bus.c
@@ -13,6 +13,7 @@
 #include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
@@ -68,6 +69,27 @@ ac97_codec_find(struct ac97_controller *ac97_ctrl, unsigned int codec_num)
 	return ac97_ctrl->codecs[codec_num];
 }
 
+static struct device_node *
+ac97_of_get_child_device(struct ac97_controller *ac97_ctrl, int idx,
+			 unsigned int vendor_id)
+{
+	struct device_node *node;
+	u32 reg;
+	char compat[] = "ac97,0000,0000";
+
+	snprintf(compat, sizeof(compat), "ac97,%04x,%04x",
+		 vendor_id >> 16, vendor_id & 0xffff);
+
+	for_each_child_of_node(ac97_ctrl->parent->of_node, node) {
+		if ((idx != of_property_read_u32(node, "reg", &reg)) ||
+		    !of_device_is_compatible(node, compat))
+			continue;
+		return of_node_get(node);
+	}
+
+	return NULL;
+}
+
 static void ac97_codec_release(struct device *dev)
 {
 	struct ac97_codec_device *adev;
@@ -98,6 +120,8 @@ static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx,
 
 	device_initialize(&codec->dev);
 	dev_set_name(&codec->dev, "%s:%u", dev_name(ac97_ctrl->parent), idx);
+	codec->dev.of_node = ac97_of_get_child_device(ac97_ctrl, idx,
+						      vendor_id);
 
 	ret = device_add(&codec->dev);
 	if (ret)
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
@ 2018-06-21 15:43   ` Robert Jarzmik
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Jarzmik @ 2018-06-21 15:43 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Rob Herring, Mark Rutland,
	Jaroslav Kysela, Takashi Iwai
  Cc: devicetree, alsa-devel, Robert Jarzmik, linux-kernel

Add a devicetree binding for codecs. This is especially useful if the
AC97 bitclk clock is provided by the codec, as it has to be described in
the devicetree description for the ac97 bus code to aquire it.

Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
---
Special review query: review the "return of_node_get(node)", which
assumes that upon device removal, of_put_node(dev.of_node) will be
called...
---
 sound/ac97/bus.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c
index 31f858eceffc..c8e20dd8786f 100644
--- a/sound/ac97/bus.c
+++ b/sound/ac97/bus.c
@@ -13,6 +13,7 @@
 #include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
@@ -68,6 +69,27 @@ ac97_codec_find(struct ac97_controller *ac97_ctrl, unsigned int codec_num)
 	return ac97_ctrl->codecs[codec_num];
 }
 
+static struct device_node *
+ac97_of_get_child_device(struct ac97_controller *ac97_ctrl, int idx,
+			 unsigned int vendor_id)
+{
+	struct device_node *node;
+	u32 reg;
+	char compat[] = "ac97,0000,0000";
+
+	snprintf(compat, sizeof(compat), "ac97,%04x,%04x",
+		 vendor_id >> 16, vendor_id & 0xffff);
+
+	for_each_child_of_node(ac97_ctrl->parent->of_node, node) {
+		if ((idx != of_property_read_u32(node, "reg", &reg)) ||
+		    !of_device_is_compatible(node, compat))
+			continue;
+		return of_node_get(node);
+	}
+
+	return NULL;
+}
+
 static void ac97_codec_release(struct device *dev)
 {
 	struct ac97_codec_device *adev;
@@ -98,6 +120,8 @@ static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx,
 
 	device_initialize(&codec->dev);
 	dev_set_name(&codec->dev, "%s:%u", dev_name(ac97_ctrl->parent), idx);
+	codec->dev.of_node = ac97_of_get_child_device(ac97_ctrl, idx,
+						      vendor_id);
 
 	ret = device_add(&codec->dev);
 	if (ret)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
  2018-06-21 15:43   ` Robert Jarzmik
@ 2018-06-21 19:45     ` Takashi Iwai
  -1 siblings, 0 replies; 12+ messages in thread
From: Takashi Iwai @ 2018-06-21 19:45 UTC (permalink / raw)
  To: Robert Jarzmik
  Cc: Mark Rutland, Liam Girdwood, Mark Brown, Rob Herring,
	Jaroslav Kysela, alsa-devel, devicetree, linux-kernel

On Thu, 21 Jun 2018 17:43:56 +0200,
Robert Jarzmik wrote:
> 
> Add a devicetree binding for codecs. This is especially useful if the
> AC97 bitclk clock is provided by the codec, as it has to be described in
> the devicetree description for the ac97 bus code to aquire it.
> 
> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
> ---
> Special review query: review the "return of_node_get(node)", which
> assumes that upon device removal, of_put_node(dev.of_node) will be
> called...

Is it really done automagically?  I couldn't spot it.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
@ 2018-06-21 19:45     ` Takashi Iwai
  0 siblings, 0 replies; 12+ messages in thread
From: Takashi Iwai @ 2018-06-21 19:45 UTC (permalink / raw)
  To: Robert Jarzmik
  Cc: Mark Rutland, devicetree, alsa-devel, linux-kernel,
	Liam Girdwood, Rob Herring, Mark Brown

On Thu, 21 Jun 2018 17:43:56 +0200,
Robert Jarzmik wrote:
> 
> Add a devicetree binding for codecs. This is especially useful if the
> AC97 bitclk clock is provided by the codec, as it has to be described in
> the devicetree description for the ac97 bus code to aquire it.
> 
> Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>
> ---
> Special review query: review the "return of_node_get(node)", which
> assumes that upon device removal, of_put_node(dev.of_node) will be
> called...

Is it really done automagically?  I couldn't spot it.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
  2018-06-21 19:45     ` Takashi Iwai
@ 2018-06-22 10:41       ` Robert Jarzmik
  -1 siblings, 0 replies; 12+ messages in thread
From: Robert Jarzmik @ 2018-06-22 10:41 UTC (permalink / raw)
  To: Takashi Iwai, Mark Rutland, Rob Herring
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, alsa-devel,
	devicetree, linux-kernel

Takashi Iwai <tiwai@suse.de> writes:

>> Special review query: review the "return of_node_get(node)", which
>> assumes that upon device removal, of_put_node(dev.of_node) will be
>> called...
>
> Is it really done automagically?  I couldn't spot it.
Neither could I ...

I based this on device_set_of_node_from_dev(), and the it "seemed" logical to me
that a device probed from devicetree would take a refcnt on the devicetree node.

As the "logical" conflicted with my search for the automagical of_node_get(), I
need the special review query.

Cheers.

-- 
Robert

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
@ 2018-06-22 10:41       ` Robert Jarzmik
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Jarzmik @ 2018-06-22 10:41 UTC (permalink / raw)
  To: Takashi Iwai, Mark Rutland, Rob Herring
  Cc: devicetree, alsa-devel, Liam Girdwood, linux-kernel, Mark Brown

Takashi Iwai <tiwai@suse.de> writes:

>> Special review query: review the "return of_node_get(node)", which
>> assumes that upon device removal, of_put_node(dev.of_node) will be
>> called...
>
> Is it really done automagically?  I couldn't spot it.
Neither could I ...

I based this on device_set_of_node_from_dev(), and the it "seemed" logical to me
that a device probed from devicetree would take a refcnt on the devicetree node.

As the "logical" conflicted with my search for the automagical of_node_get(), I
need the special review query.

Cheers.

-- 
Robert

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
  2018-06-22 10:41       ` Robert Jarzmik
@ 2018-06-22 10:49         ` Takashi Iwai
  -1 siblings, 0 replies; 12+ messages in thread
From: Takashi Iwai @ 2018-06-22 10:49 UTC (permalink / raw)
  To: Robert Jarzmik
  Cc: Mark Rutland, Rob Herring, Liam Girdwood, Mark Brown,
	Jaroslav Kysela, alsa-devel, devicetree, linux-kernel

On Fri, 22 Jun 2018 12:41:14 +0200,
Robert Jarzmik wrote:
> 
> Takashi Iwai <tiwai@suse.de> writes:
> 
> >> Special review query: review the "return of_node_get(node)", which
> >> assumes that upon device removal, of_put_node(dev.of_node) will be
> >> called...
> >
> > Is it really done automagically?  I couldn't spot it.
> Neither could I ...
> 
> I based this on device_set_of_node_from_dev(), and the it "seemed" logical to me
> that a device probed from devicetree would take a refcnt on the devicetree node.
> 
> As the "logical" conflicted with my search for the automagical of_node_get(), I
> need the special review query.

Hm, some of these users (e.g. drivers/usb/core/*) do call
of_node_put() properly at releasing, but some look leaking to me.
I don't think we have the common code in the driver core to release
dev->of_node, at least.

If any, this should be done in ac97_codec_release(), I suppose.


Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
@ 2018-06-22 10:49         ` Takashi Iwai
  0 siblings, 0 replies; 12+ messages in thread
From: Takashi Iwai @ 2018-06-22 10:49 UTC (permalink / raw)
  To: Robert Jarzmik
  Cc: Mark Rutland, devicetree, alsa-devel, linux-kernel,
	Liam Girdwood, Rob Herring, Mark Brown

On Fri, 22 Jun 2018 12:41:14 +0200,
Robert Jarzmik wrote:
> 
> Takashi Iwai <tiwai@suse.de> writes:
> 
> >> Special review query: review the "return of_node_get(node)", which
> >> assumes that upon device removal, of_put_node(dev.of_node) will be
> >> called...
> >
> > Is it really done automagically?  I couldn't spot it.
> Neither could I ...
> 
> I based this on device_set_of_node_from_dev(), and the it "seemed" logical to me
> that a device probed from devicetree would take a refcnt on the devicetree node.
> 
> As the "logical" conflicted with my search for the automagical of_node_get(), I
> need the special review query.

Hm, some of these users (e.g. drivers/usb/core/*) do call
of_node_put() properly at releasing, but some look leaking to me.
I don't think we have the common code in the driver core to release
dev->of_node, at least.

If any, this should be done in ac97_codec_release(), I suppose.


Takashi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
  2018-06-22 10:49         ` Takashi Iwai
@ 2018-06-22 14:43           ` Mark Brown
  -1 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-06-22 14:43 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Robert Jarzmik, Mark Rutland, Rob Herring, Liam Girdwood,
	Jaroslav Kysela, alsa-devel, devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 404 bytes --]

On Fri, Jun 22, 2018 at 12:49:49PM +0200, Takashi Iwai wrote:

> Hm, some of these users (e.g. drivers/usb/core/*) do call
> of_node_put() properly at releasing, but some look leaking to me.
> I don't think we have the common code in the driver core to release
> dev->of_node, at least.

> If any, this should be done in ac97_codec_release(), I suppose.

Yeah, I'd expect this to be handled in each bus.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] ALSA: ac97: add codecs devicetree binding
@ 2018-06-22 14:43           ` Mark Brown
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2018-06-22 14:43 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Mark Rutland, devicetree, alsa-devel, linux-kernel,
	Liam Girdwood, Rob Herring, Robert Jarzmik


[-- Attachment #1.1: Type: text/plain, Size: 404 bytes --]

On Fri, Jun 22, 2018 at 12:49:49PM +0200, Takashi Iwai wrote:

> Hm, some of these users (e.g. drivers/usb/core/*) do call
> of_node_put() properly at releasing, but some look leaking to me.
> I don't think we have the common code in the driver core to release
> dev->of_node, at least.

> If any, this should be done in ac97_codec_release(), I suppose.

Yeah, I'd expect this to be handled in each bus.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-06-22 14:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-21 15:43 [PATCH 1/2] ALSA: ac97: add bus binding for codecs Robert Jarzmik
2018-06-21 15:43 ` Robert Jarzmik
2018-06-21 15:43 ` [PATCH 2/2] ALSA: ac97: add codecs devicetree binding Robert Jarzmik
2018-06-21 15:43   ` Robert Jarzmik
2018-06-21 19:45   ` Takashi Iwai
2018-06-21 19:45     ` Takashi Iwai
2018-06-22 10:41     ` Robert Jarzmik
2018-06-22 10:41       ` Robert Jarzmik
2018-06-22 10:49       ` Takashi Iwai
2018-06-22 10:49         ` Takashi Iwai
2018-06-22 14:43         ` Mark Brown
2018-06-22 14:43           ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.