xref: /linux/sound/soc/codecs/pcm512x-i2c.c (revision 1802d0beecafe581ad584634ba92f8a471d8a63a)
1*1802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
222066226SMark Brown /*
322066226SMark Brown  * Driver for the PCM512x CODECs
422066226SMark Brown  *
5da924c3aSMark Brown  * Author:	Mark Brown <broonie@kernel.org>
622066226SMark Brown  *		Copyright 2014 Linaro Ltd
722066226SMark Brown  */
822066226SMark Brown 
922066226SMark Brown #include <linux/init.h>
1022066226SMark Brown #include <linux/module.h>
1122066226SMark Brown #include <linux/i2c.h>
12b84f48d1SPierre-Louis Bossart #include <linux/acpi.h>
1322066226SMark Brown 
1422066226SMark Brown #include "pcm512x.h"
1522066226SMark Brown 
1622066226SMark Brown static int pcm512x_i2c_probe(struct i2c_client *i2c,
1722066226SMark Brown 			     const struct i2c_device_id *id)
1822066226SMark Brown {
1922066226SMark Brown 	struct regmap *regmap;
20681a1956SPeter Rosin 	struct regmap_config config = pcm512x_regmap;
2122066226SMark Brown 
22681a1956SPeter Rosin 	/* msb needs to be set to enable auto-increment of addresses */
23681a1956SPeter Rosin 	config.read_flag_mask = 0x80;
24681a1956SPeter Rosin 	config.write_flag_mask = 0x80;
25681a1956SPeter Rosin 
26681a1956SPeter Rosin 	regmap = devm_regmap_init_i2c(i2c, &config);
2722066226SMark Brown 	if (IS_ERR(regmap))
2822066226SMark Brown 		return PTR_ERR(regmap);
2922066226SMark Brown 
3022066226SMark Brown 	return pcm512x_probe(&i2c->dev, regmap);
3122066226SMark Brown }
3222066226SMark Brown 
3322066226SMark Brown static int pcm512x_i2c_remove(struct i2c_client *i2c)
3422066226SMark Brown {
3522066226SMark Brown 	pcm512x_remove(&i2c->dev);
3622066226SMark Brown 	return 0;
3722066226SMark Brown }
3822066226SMark Brown 
3922066226SMark Brown static const struct i2c_device_id pcm512x_i2c_id[] = {
4022066226SMark Brown 	{ "pcm5121", },
4122066226SMark Brown 	{ "pcm5122", },
42ba5295e5SPeter Rosin 	{ "pcm5141", },
43ba5295e5SPeter Rosin 	{ "pcm5142", },
4422066226SMark Brown 	{ }
4522066226SMark Brown };
4622066226SMark Brown MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
4722066226SMark Brown 
48b84f48d1SPierre-Louis Bossart #if defined(CONFIG_OF)
4922066226SMark Brown static const struct of_device_id pcm512x_of_match[] = {
5022066226SMark Brown 	{ .compatible = "ti,pcm5121", },
5122066226SMark Brown 	{ .compatible = "ti,pcm5122", },
52ba5295e5SPeter Rosin 	{ .compatible = "ti,pcm5141", },
53ba5295e5SPeter Rosin 	{ .compatible = "ti,pcm5142", },
5422066226SMark Brown 	{ }
5522066226SMark Brown };
5622066226SMark Brown MODULE_DEVICE_TABLE(of, pcm512x_of_match);
57b84f48d1SPierre-Louis Bossart #endif
58b84f48d1SPierre-Louis Bossart 
59b84f48d1SPierre-Louis Bossart #ifdef CONFIG_ACPI
60b84f48d1SPierre-Louis Bossart static const struct acpi_device_id pcm512x_acpi_match[] = {
61b84f48d1SPierre-Louis Bossart 	{ "104C5121", 0 },
62b84f48d1SPierre-Louis Bossart 	{ "104C5122", 0 },
63b84f48d1SPierre-Louis Bossart 	{ "104C5141", 0 },
64b84f48d1SPierre-Louis Bossart 	{ "104C5142", 0 },
65b84f48d1SPierre-Louis Bossart 	{ },
66b84f48d1SPierre-Louis Bossart };
67b84f48d1SPierre-Louis Bossart MODULE_DEVICE_TABLE(acpi, pcm512x_acpi_match);
68b84f48d1SPierre-Louis Bossart #endif
6922066226SMark Brown 
7022066226SMark Brown static struct i2c_driver pcm512x_i2c_driver = {
7122066226SMark Brown 	.probe 		= pcm512x_i2c_probe,
7222066226SMark Brown 	.remove 	= pcm512x_i2c_remove,
7322066226SMark Brown 	.id_table	= pcm512x_i2c_id,
7422066226SMark Brown 	.driver		= {
7522066226SMark Brown 		.name	= "pcm512x",
76b84f48d1SPierre-Louis Bossart 		.of_match_table = of_match_ptr(pcm512x_of_match),
77b84f48d1SPierre-Louis Bossart 		.acpi_match_table = ACPI_PTR(pcm512x_acpi_match),
7822066226SMark Brown 		.pm     = &pcm512x_pm_ops,
7922066226SMark Brown 	},
8022066226SMark Brown };
8122066226SMark Brown 
8222066226SMark Brown module_i2c_driver(pcm512x_i2c_driver);
8322066226SMark Brown 
8422066226SMark Brown MODULE_DESCRIPTION("ASoC PCM512x codec driver - I2C");
85da924c3aSMark Brown MODULE_AUTHOR("Mark Brown <broonie@kernel.org>");
8622066226SMark Brown MODULE_LICENSE("GPL v2");
87