1f9f46d05SCharles Keepax // SPDX-License-Identifier: GPL-2.0
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
cs35l45_i2c_probe(struct i2c_client * client)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;
356085f9e6SVlad.Karpovich cs35l45->irq = client->irq;
366c07be8fSVlad.Karpovich cs35l45->bus_type = CONTROL_BUS_I2C;
376c07be8fSVlad.Karpovich cs35l45->i2c_addr = client->addr;
380d463d01SJames Schulman
390d463d01SJames Schulman return cs35l45_probe(cs35l45);
400d463d01SJames Schulman }
410d463d01SJames Schulman
cs35l45_i2c_remove(struct i2c_client * client)42ed5c2f5fSUwe Kleine-König static void cs35l45_i2c_remove(struct i2c_client *client)
430d463d01SJames Schulman {
440d463d01SJames Schulman struct cs35l45_private *cs35l45 = i2c_get_clientdata(client);
450d463d01SJames Schulman
4684965cc6SUwe Kleine-König cs35l45_remove(cs35l45);
470d463d01SJames Schulman }
480d463d01SJames Schulman
490d463d01SJames Schulman static const struct of_device_id cs35l45_of_match[] = {
500d463d01SJames Schulman { .compatible = "cirrus,cs35l45" },
510d463d01SJames Schulman {},
520d463d01SJames Schulman };
530d463d01SJames Schulman MODULE_DEVICE_TABLE(of, cs35l45_of_match);
540d463d01SJames Schulman
550d463d01SJames Schulman static const struct i2c_device_id cs35l45_id_i2c[] = {
56*ba2a2c37SUwe Kleine-König { "cs35l45" },
570d463d01SJames Schulman {}
580d463d01SJames Schulman };
590d463d01SJames Schulman MODULE_DEVICE_TABLE(i2c, cs35l45_id_i2c);
600d463d01SJames Schulman
610d463d01SJames Schulman static struct i2c_driver cs35l45_i2c_driver = {
620d463d01SJames Schulman .driver = {
630d463d01SJames Schulman .name = "cs35l45",
640d463d01SJames Schulman .of_match_table = cs35l45_of_match,
6512e102b1SRicardo Rivera-Matos .pm = pm_ptr(&cs35l45_pm_ops),
660d463d01SJames Schulman },
670d463d01SJames Schulman .id_table = cs35l45_id_i2c,
689abcd240SUwe Kleine-König .probe = cs35l45_i2c_probe,
690d463d01SJames Schulman .remove = cs35l45_i2c_remove,
700d463d01SJames Schulman };
710d463d01SJames Schulman module_i2c_driver(cs35l45_i2c_driver);
720d463d01SJames Schulman
730d463d01SJames Schulman MODULE_DESCRIPTION("I2C CS35L45 driver");
740d463d01SJames Schulman MODULE_AUTHOR("James Schulman, Cirrus Logic Inc, <james.schulman@cirrus.com>");
75f9f46d05SCharles Keepax MODULE_LICENSE("GPL");
7631c90dd5SRichard Fitzgerald MODULE_IMPORT_NS(SND_SOC_CS35L45);
77