xref: /linux/sound/soc/codecs/pcm512x-i2c.c (revision 9abcd24002bf7997be752b6b48b137c4db3a609b)
11802d0beSThomas 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 
167f7d7214SStephen Kitt static int pcm512x_i2c_probe(struct i2c_client *i2c)
1722066226SMark Brown {
1822066226SMark Brown 	struct regmap *regmap;
19681a1956SPeter Rosin 	struct regmap_config config = pcm512x_regmap;
2022066226SMark Brown 
21681a1956SPeter Rosin 	/* msb needs to be set to enable auto-increment of addresses */
22681a1956SPeter Rosin 	config.read_flag_mask = 0x80;
23681a1956SPeter Rosin 	config.write_flag_mask = 0x80;
24681a1956SPeter Rosin 
25681a1956SPeter Rosin 	regmap = devm_regmap_init_i2c(i2c, &config);
2622066226SMark Brown 	if (IS_ERR(regmap))
2722066226SMark Brown 		return PTR_ERR(regmap);
2822066226SMark Brown 
2922066226SMark Brown 	return pcm512x_probe(&i2c->dev, regmap);
3022066226SMark Brown }
3122066226SMark Brown 
32ed5c2f5fSUwe Kleine-König static void pcm512x_i2c_remove(struct i2c_client *i2c)
3322066226SMark Brown {
3422066226SMark Brown 	pcm512x_remove(&i2c->dev);
3522066226SMark Brown }
3622066226SMark Brown 
3722066226SMark Brown static const struct i2c_device_id pcm512x_i2c_id[] = {
3822066226SMark Brown 	{ "pcm5121", },
3922066226SMark Brown 	{ "pcm5122", },
40ba5295e5SPeter Rosin 	{ "pcm5141", },
41ba5295e5SPeter Rosin 	{ "pcm5142", },
4222066226SMark Brown 	{ }
4322066226SMark Brown };
4422066226SMark Brown MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
4522066226SMark Brown 
46b84f48d1SPierre-Louis Bossart #if defined(CONFIG_OF)
4722066226SMark Brown static const struct of_device_id pcm512x_of_match[] = {
4822066226SMark Brown 	{ .compatible = "ti,pcm5121", },
4922066226SMark Brown 	{ .compatible = "ti,pcm5122", },
50ba5295e5SPeter Rosin 	{ .compatible = "ti,pcm5141", },
51ba5295e5SPeter Rosin 	{ .compatible = "ti,pcm5142", },
5222066226SMark Brown 	{ }
5322066226SMark Brown };
5422066226SMark Brown MODULE_DEVICE_TABLE(of, pcm512x_of_match);
55b84f48d1SPierre-Louis Bossart #endif
56b84f48d1SPierre-Louis Bossart 
57b84f48d1SPierre-Louis Bossart #ifdef CONFIG_ACPI
58b84f48d1SPierre-Louis Bossart static const struct acpi_device_id pcm512x_acpi_match[] = {
59b84f48d1SPierre-Louis Bossart 	{ "104C5121", 0 },
60b84f48d1SPierre-Louis Bossart 	{ "104C5122", 0 },
61b84f48d1SPierre-Louis Bossart 	{ "104C5141", 0 },
62b84f48d1SPierre-Louis Bossart 	{ "104C5142", 0 },
63b84f48d1SPierre-Louis Bossart 	{ },
64b84f48d1SPierre-Louis Bossart };
65b84f48d1SPierre-Louis Bossart MODULE_DEVICE_TABLE(acpi, pcm512x_acpi_match);
66b84f48d1SPierre-Louis Bossart #endif
6722066226SMark Brown 
6822066226SMark Brown static struct i2c_driver pcm512x_i2c_driver = {
69*9abcd240SUwe Kleine-König 	.probe		= pcm512x_i2c_probe,
7022066226SMark Brown 	.remove 	= pcm512x_i2c_remove,
7122066226SMark Brown 	.id_table	= pcm512x_i2c_id,
7222066226SMark Brown 	.driver		= {
7322066226SMark Brown 		.name	= "pcm512x",
74b84f48d1SPierre-Louis Bossart 		.of_match_table = of_match_ptr(pcm512x_of_match),
75b84f48d1SPierre-Louis Bossart 		.acpi_match_table = ACPI_PTR(pcm512x_acpi_match),
7622066226SMark Brown 		.pm     = &pcm512x_pm_ops,
7722066226SMark Brown 	},
7822066226SMark Brown };
7922066226SMark Brown 
8022066226SMark Brown module_i2c_driver(pcm512x_i2c_driver);
8122066226SMark Brown 
8222066226SMark Brown MODULE_DESCRIPTION("ASoC PCM512x codec driver - I2C");
83da924c3aSMark Brown MODULE_AUTHOR("Mark Brown <broonie@kernel.org>");
8422066226SMark Brown MODULE_LICENSE("GPL v2");
85