xref: /openbmc/linux/sound/soc/codecs/wm8731-spi.c (revision 5192e395)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * wm8731.c  --  WM8731 ALSA SoC Audio driver
4  *
5  * Copyright 2005 Openedhand Ltd.
6  * Copyright 2006-12 Wolfson Microelectronics, plc
7  *
8  * Author: Richard Purdie <richard@openedhand.com>
9  *
10  * Based on wm8753.c by Liam Girdwood
11  */
12 
13 #include <linux/spi/spi.h>
14 #include <linux/module.h>
15 #include <linux/of_device.h>
16 
17 #include "wm8731.h"
18 
19 static const struct of_device_id wm8731_of_match[] = {
20 	{ .compatible = "wlf,wm8731", },
21 	{ }
22 };
23 MODULE_DEVICE_TABLE(of, wm8731_of_match);
24 
25 static int wm8731_spi_probe(struct spi_device *spi)
26 {
27 	struct wm8731_priv *wm8731;
28 	int ret;
29 
30 	wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL);
31 	if (wm8731 == NULL)
32 		return -ENOMEM;
33 
34 	spi_set_drvdata(spi, wm8731);
35 
36 	wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap);
37 	if (IS_ERR(wm8731->regmap)) {
38 		ret = PTR_ERR(wm8731->regmap);
39 		dev_err(&spi->dev, "Failed to allocate register map: %d\n",
40 			ret);
41 		return ret;
42 	}
43 
44 	return wm8731_init(&spi->dev, wm8731);
45 }
46 
47 static struct spi_driver wm8731_spi_driver = {
48 	.driver = {
49 		.name	= "wm8731",
50 		.of_match_table = wm8731_of_match,
51 	},
52 	.probe		= wm8731_spi_probe,
53 };
54 
55 module_spi_driver(wm8731_spi_driver);
56 
57 MODULE_DESCRIPTION("ASoC WM8731 driver - SPI");
58 MODULE_AUTHOR("Richard Purdie");
59 MODULE_LICENSE("GPL");
60