1 // SPDX-License-Identifier: GPL-2.0-only 2 // 3 // CS35L56 ALSA SoC audio driver I2C binding 4 // 5 // Copyright (C) 2023 Cirrus Logic, Inc. and 6 // Cirrus Logic International Semiconductor Ltd. 7 8 #include <linux/acpi.h> 9 #include <linux/i2c.h> 10 #include <linux/module.h> 11 #include <linux/moduleparam.h> 12 #include <linux/regmap.h> 13 #include <linux/slab.h> 14 #include <linux/types.h> 15 16 #include "cs35l56.h" 17 18 static int cs35l56_i2c_probe(struct i2c_client *client) 19 { 20 struct cs35l56_private *cs35l56; 21 struct device *dev = &client->dev; 22 const struct regmap_config *regmap_config = &cs35l56_regmap_i2c; 23 int ret; 24 25 cs35l56 = devm_kzalloc(dev, sizeof(struct cs35l56_private), GFP_KERNEL); 26 if (!cs35l56) 27 return -ENOMEM; 28 29 cs35l56->dev = dev; 30 cs35l56->can_hibernate = true; 31 32 i2c_set_clientdata(client, cs35l56); 33 cs35l56->regmap = devm_regmap_init_i2c(client, regmap_config); 34 if (IS_ERR(cs35l56->regmap)) { 35 ret = PTR_ERR(cs35l56->regmap); 36 return dev_err_probe(cs35l56->dev, ret, "Failed to allocate register map\n"); 37 } 38 39 ret = cs35l56_common_probe(cs35l56); 40 if (ret != 0) 41 return ret; 42 43 ret = cs35l56_init(cs35l56); 44 if (ret == 0) 45 ret = cs35l56_irq_request(cs35l56, client->irq); 46 if (ret < 0) 47 cs35l56_remove(cs35l56); 48 49 return ret; 50 } 51 52 static void cs35l56_i2c_remove(struct i2c_client *client) 53 { 54 struct cs35l56_private *cs35l56 = i2c_get_clientdata(client); 55 56 cs35l56_remove(cs35l56); 57 } 58 59 static const struct i2c_device_id cs35l56_id_i2c[] = { 60 { "cs35l56", 0 }, 61 {} 62 }; 63 MODULE_DEVICE_TABLE(i2c, cs35l56_id_i2c); 64 65 static struct i2c_driver cs35l56_i2c_driver = { 66 .driver = { 67 .name = "cs35l56", 68 .pm = &cs35l56_pm_ops_i2c_spi, 69 }, 70 .id_table = cs35l56_id_i2c, 71 .probe_new = cs35l56_i2c_probe, 72 .remove = cs35l56_i2c_remove, 73 }; 74 75 module_i2c_driver(cs35l56_i2c_driver); 76 77 MODULE_DESCRIPTION("ASoC CS35L56 I2C driver"); 78 MODULE_IMPORT_NS(SND_SOC_CS35L56_CORE); 79 MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED); 80 MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>"); 81 MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>"); 82 MODULE_LICENSE("GPL"); 83