Skip to content

Commit b2d8957

Browse files
AlexanderSteintiwai
authored andcommitted
ALSA: sound/atmel/ac97c.c: Add device tree support
This adds device tree support for the AC97 controller. It uses the soc-ac97link bindings, but actually only ac97-reset is used. Signed-off-by: Alexander Stein <[email protected]> Acked-by: Alexandre Belloni <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent ff6defa commit b2d8957

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

sound/atmel/ac97c.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <linux/gpio.h>
2323
#include <linux/types.h>
2424
#include <linux/io.h>
25+
#include <linux/of.h>
26+
#include <linux/of_gpio.h>
27+
#include <linux/of_device.h>
2528

2629
#include <sound/core.h>
2730
#include <sound/initval.h>
@@ -902,6 +905,40 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip)
902905
}
903906
}
904907

908+
#ifdef CONFIG_OF
909+
static const struct of_device_id atmel_ac97c_dt_ids[] = {
910+
{ .compatible = "atmel,at91sam9263-ac97c", },
911+
{ }
912+
};
913+
MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids);
914+
915+
static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev)
916+
{
917+
struct ac97c_platform_data *pdata;
918+
struct device_node *node = dev->of_node;
919+
const struct of_device_id *match;
920+
921+
if (!node) {
922+
dev_err(dev, "Device does not have associated DT data\n");
923+
return ERR_PTR(-EINVAL);
924+
}
925+
926+
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
927+
if (!pdata)
928+
return ERR_PTR(-ENOMEM);
929+
930+
pdata->reset_pin = of_get_named_gpio(dev->of_node, "ac97-gpios", 2);
931+
932+
return pdata;
933+
}
934+
#else
935+
static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev)
936+
{
937+
dev_err(dev, "no platform data defined\n");
938+
return ERR_PTR(-ENXIO);
939+
}
940+
#endif
941+
905942
static int atmel_ac97c_probe(struct platform_device *pdev)
906943
{
907944
struct snd_card *card;
@@ -922,10 +959,11 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
922959
return -ENXIO;
923960
}
924961

925-
pdata = pdev->dev.platform_data;
962+
pdata = dev_get_platdata(&pdev->dev);
926963
if (!pdata) {
927-
dev_dbg(&pdev->dev, "no platform data\n");
928-
return -ENXIO;
964+
pdata = atmel_ac97c_probe_dt(&pdev->dev);
965+
if (IS_ERR(pdata))
966+
return PTR_ERR(pdata);
929967
}
930968

931969
irq = platform_get_irq(pdev, 0);
@@ -1204,6 +1242,7 @@ static struct platform_driver atmel_ac97c_driver = {
12041242
.driver = {
12051243
.name = "atmel_ac97c",
12061244
.pm = ATMEL_AC97C_PM_OPS,
1245+
.of_match_table = of_match_ptr(atmel_ac97c_dt_ids),
12071246
},
12081247
};
12091248
module_platform_driver(atmel_ac97c_driver);

0 commit comments

Comments
 (0)