1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // cs35l41-i2c.c -- CS35l41 I2C driver 4 // 5 // Copyright 2017-2021 Cirrus Logic, Inc. 6 // 7 // Author: David Rhodes <david.rhodes@cirrus.com> 8 9 #include <linux/acpi.h> 10 #include <linux/delay.h> 11 #include <linux/i2c.h> 12 #include <linux/init.h> 13 #include <linux/kernel.h> 14 #include <linux/module.h> 15 #include <linux/moduleparam.h> 16 #include <linux/of_device.h> 17 #include <linux/platform_device.h> 18 #include <linux/slab.h> 19 20 #include "cs35l41.h" 21 22 static const struct i2c_device_id cs35l41_id_i2c[] = { 23 { "cs35l40", 0 }, 24 { "cs35l41", 0 }, 25 {} 26 }; 27 28 MODULE_DEVICE_TABLE(i2c, cs35l41_id_i2c); 29 30 static int cs35l41_i2c_probe(struct i2c_client *client, 31 const struct i2c_device_id *id) 32 { 33 struct cs35l41_private *cs35l41; 34 struct device *dev = &client->dev; 35 struct cs35l41_platform_data *pdata = dev_get_platdata(dev); 36 const struct regmap_config *regmap_config = &cs35l41_regmap_i2c; 37 int ret; 38 39 cs35l41 = devm_kzalloc(dev, sizeof(struct cs35l41_private), GFP_KERNEL); 40 41 if (!cs35l41) 42 return -ENOMEM; 43 44 cs35l41->dev = dev; 45 cs35l41->irq = client->irq; 46 47 i2c_set_clientdata(client, cs35l41); 48 cs35l41->regmap = devm_regmap_init_i2c(client, regmap_config); 49 if (IS_ERR(cs35l41->regmap)) { 50 ret = PTR_ERR(cs35l41->regmap); 51 dev_err(cs35l41->dev, "Failed to allocate register map: %d\n", ret); 52 return ret; 53 } 54 55 return cs35l41_probe(cs35l41, pdata); 56 } 57 58 static int cs35l41_i2c_remove(struct i2c_client *client) 59 { 60 struct cs35l41_private *cs35l41 = i2c_get_clientdata(client); 61 62 cs35l41_remove(cs35l41); 63 64 return 0; 65 } 66 67 #ifdef CONFIG_OF 68 static const struct of_device_id cs35l41_of_match[] = { 69 { .compatible = "cirrus,cs35l40" }, 70 { .compatible = "cirrus,cs35l41" }, 71 {}, 72 }; 73 MODULE_DEVICE_TABLE(of, cs35l41_of_match); 74 #endif 75 76 #ifdef CONFIG_ACPI 77 static const struct acpi_device_id cs35l41_acpi_match[] = { 78 { "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */ 79 {}, 80 }; 81 MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match); 82 #endif 83 84 static struct i2c_driver cs35l41_i2c_driver = { 85 .driver = { 86 .name = "cs35l41", 87 .of_match_table = of_match_ptr(cs35l41_of_match), 88 .acpi_match_table = ACPI_PTR(cs35l41_acpi_match), 89 }, 90 .id_table = cs35l41_id_i2c, 91 .probe = cs35l41_i2c_probe, 92 .remove = cs35l41_i2c_remove, 93 }; 94 95 module_i2c_driver(cs35l41_i2c_driver); 96 97 MODULE_DESCRIPTION("I2C CS35L41 driver"); 98 MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>"); 99 MODULE_LICENSE("GPL"); 100