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 22static const struct i2c_device_id cs35l41_id_i2c[] = { 23 { "cs35l40", 0 }, 24 { "cs35l41", 0 }, 25 { "cs35l51", 0 }, 26 { "cs35l53", 0 }, 27 {} 28}; 29 30MODULE_DEVICE_TABLE(i2c, cs35l41_id_i2c); 31 32static int cs35l41_i2c_probe(struct i2c_client *client) 33{ 34 struct cs35l41_private *cs35l41; 35 struct device *dev = &client->dev; 36 struct cs35l41_hw_cfg *hw_cfg = dev_get_platdata(dev); 37 const struct regmap_config *regmap_config = &cs35l41_regmap_i2c; 38 int ret; 39 40 cs35l41 = devm_kzalloc(dev, sizeof(struct cs35l41_private), GFP_KERNEL); 41 42 if (!cs35l41) 43 return -ENOMEM; 44 45 cs35l41->dev = dev; 46 cs35l41->irq = client->irq; 47 48 i2c_set_clientdata(client, cs35l41); 49 cs35l41->regmap = devm_regmap_init_i2c(client, regmap_config); 50 if (IS_ERR(cs35l41->regmap)) { 51 ret = PTR_ERR(cs35l41->regmap); 52 dev_err(cs35l41->dev, "Failed to allocate register map: %d\n", ret); 53 return ret; 54 } 55 56 return cs35l41_probe(cs35l41, hw_cfg); 57} 58 59static void cs35l41_i2c_remove(struct i2c_client *client) 60{ 61 struct cs35l41_private *cs35l41 = i2c_get_clientdata(client); 62 63 cs35l41_remove(cs35l41); 64} 65 66#ifdef CONFIG_OF 67static const struct of_device_id cs35l41_of_match[] = { 68 { .compatible = "cirrus,cs35l40" }, 69 { .compatible = "cirrus,cs35l41" }, 70 {}, 71}; 72MODULE_DEVICE_TABLE(of, cs35l41_of_match); 73#endif 74 75#ifdef CONFIG_ACPI 76static const struct acpi_device_id cs35l41_acpi_match[] = { 77 { "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */ 78 {}, 79}; 80MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match); 81#endif 82 83static struct i2c_driver cs35l41_i2c_driver = { 84 .driver = { 85 .name = "cs35l41", 86 .pm = &cs35l41_pm_ops, 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 95module_i2c_driver(cs35l41_i2c_driver); 96 97MODULE_DESCRIPTION("I2C CS35L41 driver"); 98MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>"); 99MODULE_LICENSE("GPL"); 100