1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * CS42L43 I2C driver 4 * 5 * Copyright (C) 2022-2023 Cirrus Logic, Inc. and 6 * Cirrus Logic International Semiconductor Ltd. 7 */ 8 9 #include <linux/array_size.h> 10 #include <linux/err.h> 11 #include <linux/i2c.h> 12 #include <linux/mfd/cs42l43.h> 13 #include <linux/mfd/cs42l43-regs.h> 14 #include <linux/module.h> 15 #include <linux/pm.h> 16 #include <linux/regmap.h> 17 18 #include "cs42l43.h" 19 20 static const struct regmap_config cs42l43_i2c_regmap = { 21 .reg_bits = 32, 22 .reg_stride = 4, 23 .val_bits = 32, 24 .reg_format_endian = REGMAP_ENDIAN_BIG, 25 .val_format_endian = REGMAP_ENDIAN_BIG, 26 27 .max_register = CS42L43_MCU_RAM_MAX, 28 .readable_reg = cs42l43_readable_register, 29 .volatile_reg = cs42l43_volatile_register, 30 .precious_reg = cs42l43_precious_register, 31 32 .cache_type = REGCACHE_MAPLE, 33 .reg_defaults = cs42l43_reg_default, 34 .num_reg_defaults = ARRAY_SIZE(cs42l43_reg_default), 35 }; 36 37 static int cs42l43_i2c_probe(struct i2c_client *i2c) 38 { 39 struct cs42l43 *cs42l43; 40 41 cs42l43 = devm_kzalloc(&i2c->dev, sizeof(*cs42l43), GFP_KERNEL); 42 if (!cs42l43) 43 return -ENOMEM; 44 45 cs42l43->dev = &i2c->dev; 46 cs42l43->irq = i2c->irq; 47 cs42l43->variant_id = (long)device_get_match_data(cs42l43->dev); 48 49 cs42l43->regmap = devm_regmap_init_i2c(i2c, &cs42l43_i2c_regmap); 50 if (IS_ERR(cs42l43->regmap)) 51 return dev_err_probe(cs42l43->dev, PTR_ERR(cs42l43->regmap), 52 "Failed to allocate regmap\n"); 53 54 return cs42l43_dev_probe(cs42l43); 55 } 56 57 #if IS_ENABLED(CONFIG_OF) 58 static const struct of_device_id cs42l43_of_match[] = { 59 { .compatible = "cirrus,cs42l43", .data = (void *)CS42L43_DEVID_VAL }, 60 { .compatible = "cirrus,cs42l43b", .data = (void *)CS42L43B_DEVID_VAL }, 61 {} 62 }; 63 MODULE_DEVICE_TABLE(of, cs42l43_of_match); 64 #endif 65 66 #if IS_ENABLED(CONFIG_ACPI) 67 static const struct acpi_device_id cs42l43_acpi_match[] = { 68 { "CSC4243", CS42L43_DEVID_VAL }, 69 { "CSC2A3B", CS42L43B_DEVID_VAL }, 70 {} 71 }; 72 MODULE_DEVICE_TABLE(acpi, cs42l43_acpi_match); 73 #endif 74 75 static struct i2c_driver cs42l43_i2c_driver = { 76 .driver = { 77 .name = "cs42l43", 78 .pm = pm_ptr(&cs42l43_pm_ops), 79 .of_match_table = of_match_ptr(cs42l43_of_match), 80 .acpi_match_table = ACPI_PTR(cs42l43_acpi_match), 81 }, 82 83 .probe = cs42l43_i2c_probe, 84 }; 85 module_i2c_driver(cs42l43_i2c_driver); 86 87 MODULE_IMPORT_NS("MFD_CS42L43"); 88 89 MODULE_DESCRIPTION("CS42L43 I2C Driver"); 90 MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.cirrus.com>"); 91 MODULE_LICENSE("GPL"); 92