xref: /openbmc/linux/sound/soc/codecs/pcm186x-i2c.c (revision 3577a8a0)
1993a3450SAndreas Dannenberg // SPDX-License-Identifier: GPL-2.0
2993a3450SAndreas Dannenberg /*
3993a3450SAndreas Dannenberg  * Texas Instruments PCM186x Universal Audio ADC - I2C
4993a3450SAndreas Dannenberg  *
55856d8bdSAlexander A. Klimov  * Copyright (C) 2015-2017 Texas Instruments Incorporated - https://www.ti.com
6993a3450SAndreas Dannenberg  *	Andreas Dannenberg <dannenberg@ti.com>
7993a3450SAndreas Dannenberg  *	Andrew F. Davis <afd@ti.com>
8993a3450SAndreas Dannenberg  */
9993a3450SAndreas Dannenberg 
10993a3450SAndreas Dannenberg #include <linux/init.h>
11993a3450SAndreas Dannenberg #include <linux/module.h>
12993a3450SAndreas Dannenberg #include <linux/i2c.h>
13993a3450SAndreas Dannenberg 
14993a3450SAndreas Dannenberg #include "pcm186x.h"
15993a3450SAndreas Dannenberg 
16993a3450SAndreas Dannenberg static const struct of_device_id pcm186x_of_match[] = {
17993a3450SAndreas Dannenberg 	{ .compatible = "ti,pcm1862", .data = (void *)PCM1862 },
18993a3450SAndreas Dannenberg 	{ .compatible = "ti,pcm1863", .data = (void *)PCM1863 },
19993a3450SAndreas Dannenberg 	{ .compatible = "ti,pcm1864", .data = (void *)PCM1864 },
20993a3450SAndreas Dannenberg 	{ .compatible = "ti,pcm1865", .data = (void *)PCM1865 },
21993a3450SAndreas Dannenberg 	{ }
22993a3450SAndreas Dannenberg };
23993a3450SAndreas Dannenberg MODULE_DEVICE_TABLE(of, pcm186x_of_match);
24993a3450SAndreas Dannenberg 
25*3577a8a0SStephen Kitt static const struct i2c_device_id pcm186x_i2c_id[] = {
26*3577a8a0SStephen Kitt 	{ "pcm1862", PCM1862 },
27*3577a8a0SStephen Kitt 	{ "pcm1863", PCM1863 },
28*3577a8a0SStephen Kitt 	{ "pcm1864", PCM1864 },
29*3577a8a0SStephen Kitt 	{ "pcm1865", PCM1865 },
30*3577a8a0SStephen Kitt 	{ }
31*3577a8a0SStephen Kitt };
32*3577a8a0SStephen Kitt MODULE_DEVICE_TABLE(i2c, pcm186x_i2c_id);
33*3577a8a0SStephen Kitt 
34*3577a8a0SStephen Kitt static int pcm186x_i2c_probe(struct i2c_client *i2c)
35993a3450SAndreas Dannenberg {
36*3577a8a0SStephen Kitt 	const struct i2c_device_id *id = i2c_match_id(pcm186x_i2c_id, i2c);
37993a3450SAndreas Dannenberg 	const enum pcm186x_type type = (enum pcm186x_type)id->driver_data;
38993a3450SAndreas Dannenberg 	int irq = i2c->irq;
39993a3450SAndreas Dannenberg 	struct regmap *regmap;
40993a3450SAndreas Dannenberg 
41993a3450SAndreas Dannenberg 	regmap = devm_regmap_init_i2c(i2c, &pcm186x_regmap);
42993a3450SAndreas Dannenberg 	if (IS_ERR(regmap))
43993a3450SAndreas Dannenberg 		return PTR_ERR(regmap);
44993a3450SAndreas Dannenberg 
45993a3450SAndreas Dannenberg 	return pcm186x_probe(&i2c->dev, type, irq, regmap);
46993a3450SAndreas Dannenberg }
47993a3450SAndreas Dannenberg 
48993a3450SAndreas Dannenberg static struct i2c_driver pcm186x_i2c_driver = {
49*3577a8a0SStephen Kitt 	.probe_new	= pcm186x_i2c_probe,
50993a3450SAndreas Dannenberg 	.id_table	= pcm186x_i2c_id,
51993a3450SAndreas Dannenberg 	.driver		= {
52993a3450SAndreas Dannenberg 		.name	= "pcm186x",
53993a3450SAndreas Dannenberg 		.of_match_table = pcm186x_of_match,
54993a3450SAndreas Dannenberg 	},
55993a3450SAndreas Dannenberg };
56993a3450SAndreas Dannenberg module_i2c_driver(pcm186x_i2c_driver);
57993a3450SAndreas Dannenberg 
58993a3450SAndreas Dannenberg MODULE_AUTHOR("Andreas Dannenberg <dannenberg@ti.com>");
59993a3450SAndreas Dannenberg MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
60993a3450SAndreas Dannenberg MODULE_DESCRIPTION("PCM186x Universal Audio ADC I2C Interface Driver");
61993a3450SAndreas Dannenberg MODULE_LICENSE("GPL v2");
62