xref: /linux/sound/soc/codecs/tlv320aic3x-spi.c (revision 33e02dc69afbd8f1b85a51d74d72f139ba4ca623)
1fd4daab3SJiri Prchal /* SPDX-License-Identifier: GPL-2.0
2fd4daab3SJiri Prchal  *
3fd4daab3SJiri Prchal  * ALSA SoC TLV320AIC3x codec driver SPI interface
4fd4daab3SJiri Prchal  *
5fd4daab3SJiri Prchal  * Author:      Arun KS, <arunks@mistralsolutions.com>
6fd4daab3SJiri Prchal  * Copyright:   (C) 2008 Mistral Solutions Pvt Ltd.,
7fd4daab3SJiri Prchal  *
8fd4daab3SJiri Prchal  * Based on sound/soc/codecs/wm8731.c by Richard Purdie
9fd4daab3SJiri Prchal  *
10fd4daab3SJiri Prchal  */
11fd4daab3SJiri Prchal 
12fd4daab3SJiri Prchal #include <linux/spi/spi.h>
13fd4daab3SJiri Prchal #include <linux/module.h>
14fd4daab3SJiri Prchal #include <linux/of.h>
15fd4daab3SJiri Prchal #include <linux/regmap.h>
16fd4daab3SJiri Prchal #include <sound/soc.h>
17fd4daab3SJiri Prchal 
18fd4daab3SJiri Prchal #include "tlv320aic3x.h"
19fd4daab3SJiri Prchal 
aic3x_spi_probe(struct spi_device * spi)20fd4daab3SJiri Prchal static int aic3x_spi_probe(struct spi_device *spi)
21fd4daab3SJiri Prchal {
22fd4daab3SJiri Prchal 	struct regmap *regmap;
23fd4daab3SJiri Prchal 	struct regmap_config config;
24fd4daab3SJiri Prchal 	const struct spi_device_id *id = spi_get_device_id(spi);
25fd4daab3SJiri Prchal 
26fd4daab3SJiri Prchal 	config = aic3x_regmap;
27fd4daab3SJiri Prchal 	config.reg_bits = 7;
28fd4daab3SJiri Prchal 	config.pad_bits = 1;
29fd4daab3SJiri Prchal 	config.val_bits = 8;
30fd4daab3SJiri Prchal 	config.read_flag_mask = 0x01;
31fd4daab3SJiri Prchal 
32fd4daab3SJiri Prchal 	dev_dbg(&spi->dev, "probing tlv320aic3x spi device\n");
33fd4daab3SJiri Prchal 
34fd4daab3SJiri Prchal 	regmap = devm_regmap_init_spi(spi, &config);
35fd4daab3SJiri Prchal 	return aic3x_probe(&spi->dev, regmap, id->driver_data);
36fd4daab3SJiri Prchal }
37fd4daab3SJiri Prchal 
aic3x_spi_remove(struct spi_device * spi)38*a0386bbaSUwe Kleine-König static void aic3x_spi_remove(struct spi_device *spi)
39fd4daab3SJiri Prchal {
402a798513SUwe Kleine-König 	aic3x_remove(&spi->dev);
41fd4daab3SJiri Prchal }
42fd4daab3SJiri Prchal 
43fd4daab3SJiri Prchal static const struct spi_device_id aic3x_spi_id[] = {
44fd4daab3SJiri Prchal 	{ "tlv320aic3x", AIC3X_MODEL_3X },
45fd4daab3SJiri Prchal 	{ "tlv320aic33", AIC3X_MODEL_33 },
46fd4daab3SJiri Prchal 	{ "tlv320aic3007", AIC3X_MODEL_3007 },
47fd4daab3SJiri Prchal 	{ "tlv320aic3104", AIC3X_MODEL_3104 },
48a0bc855fSJiri Prchal 	{ "tlv320aic3106", AIC3X_MODEL_3106 },
49fd4daab3SJiri Prchal 	{ }
50fd4daab3SJiri Prchal };
51fd4daab3SJiri Prchal MODULE_DEVICE_TABLE(spi, aic3x_spi_id);
52fd4daab3SJiri Prchal 
53fd4daab3SJiri Prchal static const struct of_device_id aic3x_of_id[] = {
54fd4daab3SJiri Prchal 	{ .compatible = "ti,tlv320aic3x", },
55fd4daab3SJiri Prchal 	{ .compatible = "ti,tlv320aic33" },
56fd4daab3SJiri Prchal 	{ .compatible = "ti,tlv320aic3007" },
57fd4daab3SJiri Prchal 	{ .compatible = "ti,tlv320aic3104" },
58a0bc855fSJiri Prchal 	{ .compatible = "ti,tlv320aic3106" },
59fd4daab3SJiri Prchal 	{},
60fd4daab3SJiri Prchal };
61fd4daab3SJiri Prchal MODULE_DEVICE_TABLE(of, aic3x_of_id);
62fd4daab3SJiri Prchal 
63fd4daab3SJiri Prchal static struct spi_driver aic3x_spi_driver = {
64fd4daab3SJiri Prchal 	.driver = {
65fd4daab3SJiri Prchal 		.name = "tlv320aic3x",
66fd4daab3SJiri Prchal 		.of_match_table = aic3x_of_id,
67fd4daab3SJiri Prchal 	},
68fd4daab3SJiri Prchal 	.probe = aic3x_spi_probe,
69fd4daab3SJiri Prchal 	.remove = aic3x_spi_remove,
70fd4daab3SJiri Prchal 	.id_table = aic3x_spi_id,
71fd4daab3SJiri Prchal };
72fd4daab3SJiri Prchal 
73fd4daab3SJiri Prchal module_spi_driver(aic3x_spi_driver);
74fd4daab3SJiri Prchal 
75fd4daab3SJiri Prchal MODULE_DESCRIPTION("ASoC TLV320AIC3x codec driver SPI");
76fd4daab3SJiri Prchal MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
77fd4daab3SJiri Prchal MODULE_LICENSE("GPL");
78