blob: c9e4ea76149a8880dde2212b0790958e3ecb89a1 [file] [log] [blame]
Charles Keepaxace6d142023-08-04 11:45:59 +01001// 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
Charles Keepax8b9a1f52024-01-29 15:25:53 +00009#include <linux/array_size.h>
Charles Keepaxace6d142023-08-04 11:45:59 +010010#include <linux/err.h>
Charles Keepaxace6d142023-08-04 11:45:59 +010011#include <linux/i2c.h>
Charles Keepax8b9a1f52024-01-29 15:25:53 +000012#include <linux/mfd/cs42l43.h>
Charles Keepaxace6d142023-08-04 11:45:59 +010013#include <linux/mfd/cs42l43-regs.h>
Charles Keepax8b9a1f52024-01-29 15:25:53 +000014#include <linux/mod_devicetable.h>
Charles Keepaxace6d142023-08-04 11:45:59 +010015#include <linux/module.h>
Charles Keepax8b9a1f52024-01-29 15:25:53 +000016#include <linux/pm.h>
17#include <linux/regmap.h>
Charles Keepaxace6d142023-08-04 11:45:59 +010018
19#include "cs42l43.h"
20
21static const struct regmap_config cs42l43_i2c_regmap = {
22 .reg_bits = 32,
23 .reg_stride = 4,
24 .val_bits = 32,
25 .reg_format_endian = REGMAP_ENDIAN_BIG,
26 .val_format_endian = REGMAP_ENDIAN_BIG,
27
28 .max_register = CS42L43_MCU_RAM_MAX,
29 .readable_reg = cs42l43_readable_register,
30 .volatile_reg = cs42l43_volatile_register,
31 .precious_reg = cs42l43_precious_register,
32
33 .cache_type = REGCACHE_MAPLE,
34 .reg_defaults = cs42l43_reg_default,
35 .num_reg_defaults = ARRAY_SIZE(cs42l43_reg_default),
36};
37
38static int cs42l43_i2c_probe(struct i2c_client *i2c)
39{
40 struct cs42l43 *cs42l43;
Charles Keepaxace6d142023-08-04 11:45:59 +010041
42 cs42l43 = devm_kzalloc(&i2c->dev, sizeof(*cs42l43), GFP_KERNEL);
43 if (!cs42l43)
44 return -ENOMEM;
45
46 cs42l43->dev = &i2c->dev;
47 cs42l43->irq = i2c->irq;
48 /* A device on an I2C is always attached by definition. */
49 cs42l43->attached = true;
50
51 cs42l43->regmap = devm_regmap_init_i2c(i2c, &cs42l43_i2c_regmap);
Charles Keepaxd92b9bc2024-01-29 15:25:56 +000052 if (IS_ERR(cs42l43->regmap))
53 return dev_err_probe(cs42l43->dev, PTR_ERR(cs42l43->regmap),
54 "Failed to allocate regmap\n");
Charles Keepaxace6d142023-08-04 11:45:59 +010055
56 return cs42l43_dev_probe(cs42l43);
57}
58
59static void cs42l43_i2c_remove(struct i2c_client *i2c)
60{
61 struct cs42l43 *cs42l43 = dev_get_drvdata(&i2c->dev);
62
63 cs42l43_dev_remove(cs42l43);
64}
65
66#if IS_ENABLED(CONFIG_OF)
67static const struct of_device_id cs42l43_of_match[] = {
68 { .compatible = "cirrus,cs42l43", },
69 {}
70};
71MODULE_DEVICE_TABLE(of, cs42l43_of_match);
72#endif
73
74#if IS_ENABLED(CONFIG_ACPI)
75static const struct acpi_device_id cs42l43_acpi_match[] = {
76 { "CSC4243", 0 },
77 {}
78};
79MODULE_DEVICE_TABLE(acpi, cs42l43_acpi_match);
80#endif
81
82static struct i2c_driver cs42l43_i2c_driver = {
83 .driver = {
84 .name = "cs42l43",
85 .pm = pm_ptr(&cs42l43_pm_ops),
86 .of_match_table = of_match_ptr(cs42l43_of_match),
87 .acpi_match_table = ACPI_PTR(cs42l43_acpi_match),
88 },
89
90 .probe = cs42l43_i2c_probe,
91 .remove = cs42l43_i2c_remove,
92};
93module_i2c_driver(cs42l43_i2c_driver);
94
95MODULE_IMPORT_NS(MFD_CS42L43);
96
97MODULE_DESCRIPTION("CS42L43 I2C Driver");
98MODULE_AUTHOR("Charles Keepax <ckeepax@opensource.cirrus.com>");
99MODULE_LICENSE("GPL");