xref: /linux/sound/soc/codecs/cs35l45-i2c.c (revision 6085f9e6dc1973cf98ee7f5dcf629939e50f1b84)
10d463d01SJames Schulman // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
20d463d01SJames Schulman //
30d463d01SJames Schulman // cs35l45-i2c.c -- CS35L45 I2C driver
40d463d01SJames Schulman //
50d463d01SJames Schulman // Copyright 2019-2022 Cirrus Logic, Inc.
60d463d01SJames Schulman //
70d463d01SJames Schulman // Author: James Schulman <james.schulman@cirrus.com>
80d463d01SJames Schulman 
90d463d01SJames Schulman #include <linux/device.h>
100d463d01SJames Schulman #include <linux/module.h>
110d463d01SJames Schulman #include <linux/i2c.h>
120d463d01SJames Schulman #include <linux/regmap.h>
130d463d01SJames Schulman 
140d463d01SJames Schulman #include "cs35l45.h"
150d463d01SJames Schulman 
160d463d01SJames Schulman static int cs35l45_i2c_probe(struct i2c_client *client)
170d463d01SJames Schulman {
180d463d01SJames Schulman 	struct cs35l45_private *cs35l45;
190d463d01SJames Schulman 	struct device *dev = &client->dev;
200d463d01SJames Schulman 	int ret;
210d463d01SJames Schulman 
220d463d01SJames Schulman 	cs35l45 = devm_kzalloc(dev, sizeof(struct cs35l45_private), GFP_KERNEL);
230d463d01SJames Schulman 	if (!cs35l45)
240d463d01SJames Schulman 		return -ENOMEM;
250d463d01SJames Schulman 
260d463d01SJames Schulman 	i2c_set_clientdata(client, cs35l45);
270d463d01SJames Schulman 	cs35l45->regmap = devm_regmap_init_i2c(client, &cs35l45_i2c_regmap);
280d463d01SJames Schulman 	if (IS_ERR(cs35l45->regmap)) {
290d463d01SJames Schulman 		ret = PTR_ERR(cs35l45->regmap);
300d463d01SJames Schulman 		dev_err(dev, "Failed to allocate register map: %d\n", ret);
310d463d01SJames Schulman 		return ret;
320d463d01SJames Schulman 	}
330d463d01SJames Schulman 
340d463d01SJames Schulman 	cs35l45->dev = dev;
35*6085f9e6SVlad.Karpovich 	cs35l45->irq = client->irq;
360d463d01SJames Schulman 
370d463d01SJames Schulman 	return cs35l45_probe(cs35l45);
380d463d01SJames Schulman }
390d463d01SJames Schulman 
40ed5c2f5fSUwe Kleine-König static void cs35l45_i2c_remove(struct i2c_client *client)
410d463d01SJames Schulman {
420d463d01SJames Schulman 	struct cs35l45_private *cs35l45 = i2c_get_clientdata(client);
430d463d01SJames Schulman 
4484965cc6SUwe Kleine-König 	cs35l45_remove(cs35l45);
450d463d01SJames Schulman }
460d463d01SJames Schulman 
470d463d01SJames Schulman static const struct of_device_id cs35l45_of_match[] = {
480d463d01SJames Schulman 	{ .compatible = "cirrus,cs35l45" },
490d463d01SJames Schulman 	{},
500d463d01SJames Schulman };
510d463d01SJames Schulman MODULE_DEVICE_TABLE(of, cs35l45_of_match);
520d463d01SJames Schulman 
530d463d01SJames Schulman static const struct i2c_device_id cs35l45_id_i2c[] = {
540d463d01SJames Schulman 	{ "cs35l45", 0 },
550d463d01SJames Schulman 	{}
560d463d01SJames Schulman };
570d463d01SJames Schulman MODULE_DEVICE_TABLE(i2c, cs35l45_id_i2c);
580d463d01SJames Schulman 
590d463d01SJames Schulman static struct i2c_driver cs35l45_i2c_driver = {
600d463d01SJames Schulman 	.driver = {
610d463d01SJames Schulman 		.name		= "cs35l45",
620d463d01SJames Schulman 		.of_match_table = cs35l45_of_match,
630d463d01SJames Schulman 		.pm		= &cs35l45_pm_ops,
640d463d01SJames Schulman 	},
650d463d01SJames Schulman 	.id_table	= cs35l45_id_i2c,
660d463d01SJames Schulman 	.probe_new	= cs35l45_i2c_probe,
670d463d01SJames Schulman 	.remove		= cs35l45_i2c_remove,
680d463d01SJames Schulman };
690d463d01SJames Schulman module_i2c_driver(cs35l45_i2c_driver);
700d463d01SJames Schulman 
710d463d01SJames Schulman MODULE_DESCRIPTION("I2C CS35L45 driver");
720d463d01SJames Schulman MODULE_AUTHOR("James Schulman, Cirrus Logic Inc, <james.schulman@cirrus.com>");
730d463d01SJames Schulman MODULE_LICENSE("Dual BSD/GPL");
7431c90dd5SRichard Fitzgerald MODULE_IMPORT_NS(SND_SOC_CS35L45);
75