1*0d463d01SJames Schulman // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2*0d463d01SJames Schulman // 3*0d463d01SJames Schulman // cs35l45-i2c.c -- CS35L45 I2C driver 4*0d463d01SJames Schulman // 5*0d463d01SJames Schulman // Copyright 2019-2022 Cirrus Logic, Inc. 6*0d463d01SJames Schulman // 7*0d463d01SJames Schulman // Author: James Schulman <james.schulman@cirrus.com> 8*0d463d01SJames Schulman 9*0d463d01SJames Schulman #include <linux/device.h> 10*0d463d01SJames Schulman #include <linux/module.h> 11*0d463d01SJames Schulman #include <linux/i2c.h> 12*0d463d01SJames Schulman #include <linux/regmap.h> 13*0d463d01SJames Schulman 14*0d463d01SJames Schulman #include "cs35l45.h" 15*0d463d01SJames Schulman 16*0d463d01SJames Schulman static int cs35l45_i2c_probe(struct i2c_client *client) 17*0d463d01SJames Schulman { 18*0d463d01SJames Schulman struct cs35l45_private *cs35l45; 19*0d463d01SJames Schulman struct device *dev = &client->dev; 20*0d463d01SJames Schulman int ret; 21*0d463d01SJames Schulman 22*0d463d01SJames Schulman cs35l45 = devm_kzalloc(dev, sizeof(struct cs35l45_private), GFP_KERNEL); 23*0d463d01SJames Schulman if (!cs35l45) 24*0d463d01SJames Schulman return -ENOMEM; 25*0d463d01SJames Schulman 26*0d463d01SJames Schulman i2c_set_clientdata(client, cs35l45); 27*0d463d01SJames Schulman cs35l45->regmap = devm_regmap_init_i2c(client, &cs35l45_i2c_regmap); 28*0d463d01SJames Schulman if (IS_ERR(cs35l45->regmap)) { 29*0d463d01SJames Schulman ret = PTR_ERR(cs35l45->regmap); 30*0d463d01SJames Schulman dev_err(dev, "Failed to allocate register map: %d\n", ret); 31*0d463d01SJames Schulman return ret; 32*0d463d01SJames Schulman } 33*0d463d01SJames Schulman 34*0d463d01SJames Schulman cs35l45->dev = dev; 35*0d463d01SJames Schulman 36*0d463d01SJames Schulman return cs35l45_probe(cs35l45); 37*0d463d01SJames Schulman } 38*0d463d01SJames Schulman 39*0d463d01SJames Schulman static int cs35l45_i2c_remove(struct i2c_client *client) 40*0d463d01SJames Schulman { 41*0d463d01SJames Schulman struct cs35l45_private *cs35l45 = i2c_get_clientdata(client); 42*0d463d01SJames Schulman 43*0d463d01SJames Schulman return cs35l45_remove(cs35l45); 44*0d463d01SJames Schulman } 45*0d463d01SJames Schulman 46*0d463d01SJames Schulman static const struct of_device_id cs35l45_of_match[] = { 47*0d463d01SJames Schulman { .compatible = "cirrus,cs35l45" }, 48*0d463d01SJames Schulman {}, 49*0d463d01SJames Schulman }; 50*0d463d01SJames Schulman MODULE_DEVICE_TABLE(of, cs35l45_of_match); 51*0d463d01SJames Schulman 52*0d463d01SJames Schulman static const struct i2c_device_id cs35l45_id_i2c[] = { 53*0d463d01SJames Schulman { "cs35l45", 0 }, 54*0d463d01SJames Schulman {} 55*0d463d01SJames Schulman }; 56*0d463d01SJames Schulman MODULE_DEVICE_TABLE(i2c, cs35l45_id_i2c); 57*0d463d01SJames Schulman 58*0d463d01SJames Schulman static struct i2c_driver cs35l45_i2c_driver = { 59*0d463d01SJames Schulman .driver = { 60*0d463d01SJames Schulman .name = "cs35l45", 61*0d463d01SJames Schulman .of_match_table = cs35l45_of_match, 62*0d463d01SJames Schulman .pm = &cs35l45_pm_ops, 63*0d463d01SJames Schulman }, 64*0d463d01SJames Schulman .id_table = cs35l45_id_i2c, 65*0d463d01SJames Schulman .probe_new = cs35l45_i2c_probe, 66*0d463d01SJames Schulman .remove = cs35l45_i2c_remove, 67*0d463d01SJames Schulman }; 68*0d463d01SJames Schulman module_i2c_driver(cs35l45_i2c_driver); 69*0d463d01SJames Schulman 70*0d463d01SJames Schulman MODULE_DESCRIPTION("I2C CS35L45 driver"); 71*0d463d01SJames Schulman MODULE_AUTHOR("James Schulman, Cirrus Logic Inc, <james.schulman@cirrus.com>"); 72*0d463d01SJames Schulman MODULE_LICENSE("Dual BSD/GPL"); 73