Skip to content

Commit

Permalink
ALSA: ac97: add codecs devicetree binding
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
rjarzmik authored and tiwai committed Jun 25, 2018
1 parent cc51574 commit 2225a3e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sound/ac97/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -76,6 +98,7 @@ static void ac97_codec_release(struct device *dev)
adev = to_ac97_device(dev);
ac97_ctrl = adev->ac97_ctrl;
ac97_ctrl->codecs[adev->num] = NULL;
of_node_put(dev->of_node);
kfree(adev);
}

Expand All @@ -98,13 +121,16 @@ 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)
goto err_free_codec;

return 0;
err_free_codec:
of_node_put(codec->dev.of_node);
put_device(&codec->dev);
kfree(codec);
ac97_ctrl->codecs[idx] = NULL;
Expand Down

0 comments on commit 2225a3e

Please sign in to comment.