File Index
Files and directories
Sign in
FILE

cs35l56-i2c.c

File preview with syntax highlighting.

linux-6.19.14/sound/soc/codecs/cs35l56-i2c.c C
  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
 18static int cs35l56_i2c_probe(struct i2c_client *client)
 19{
 20	unsigned int id = (u32)(uintptr_t)i2c_get_match_data(client);
 21	struct cs35l56_private *cs35l56;
 22	struct device *dev = &client->dev;
 23	const struct regmap_config *regmap_config;
 24	int ret;
 25
 26	cs35l56 = devm_kzalloc(dev, sizeof(struct cs35l56_private), GFP_KERNEL);
 27	if (!cs35l56)
 28		return -ENOMEM;
 29
 30	cs35l56->base.dev = dev;
 31	cs35l56->base.can_hibernate = true;
 32
 33	i2c_set_clientdata(client, cs35l56);
 34
 35	switch (id) {
 36	case 0x3556:
 37		regmap_config = &cs35l56_regmap_i2c;
 38		cs35l56->base.type = 0x56;
 39		break;
 40	case 0x3563:
 41		regmap_config = &cs35l63_regmap_i2c;
 42		cs35l56->base.type = 0x63;
 43		break;
 44	default:
 45		return -ENODEV;
 46	}
 47
 48	cs35l56->base.regmap = devm_regmap_init_i2c(client, regmap_config);
 49	if (IS_ERR(cs35l56->base.regmap)) {
 50		ret = PTR_ERR(cs35l56->base.regmap);
 51		return dev_err_probe(cs35l56->base.dev, ret, "Failed to allocate register map\n");
 52	}
 53
 54	ret = cs35l56_common_probe(cs35l56);
 55	if (ret != 0)
 56		return ret;
 57
 58	ret = cs35l56_init(cs35l56);
 59	if (ret == 0)
 60		ret = cs35l56_irq_request(&cs35l56->base, client->irq);
 61	if (ret < 0)
 62		cs35l56_remove(cs35l56);
 63
 64	return ret;
 65}
 66
 67static void cs35l56_i2c_remove(struct i2c_client *client)
 68{
 69	struct cs35l56_private *cs35l56 = i2c_get_clientdata(client);
 70
 71	cs35l56_remove(cs35l56);
 72}
 73
 74static const struct i2c_device_id cs35l56_id_i2c[] = {
 75	{ "cs35l56", 0x3556 },
 76	{ "cs35l63", 0x3563 },
 77	{}
 78};
 79MODULE_DEVICE_TABLE(i2c, cs35l56_id_i2c);
 80
 81#ifdef CONFIG_ACPI
 82static const struct acpi_device_id cs35l56_asoc_acpi_match[] = {
 83	{ "CSC355C", 0x3556 },
 84	{ "CSC356C", 0x3563 },
 85	{},
 86};
 87MODULE_DEVICE_TABLE(acpi, cs35l56_asoc_acpi_match);
 88#endif
 89
 90static struct i2c_driver cs35l56_i2c_driver = {
 91	.driver = {
 92		.name		= "cs35l56",
 93		.pm = pm_ptr(&cs35l56_pm_ops_i2c_spi),
 94		.acpi_match_table = ACPI_PTR(cs35l56_asoc_acpi_match),
 95	},
 96	.id_table	= cs35l56_id_i2c,
 97	.probe		= cs35l56_i2c_probe,
 98	.remove		= cs35l56_i2c_remove,
 99};
100
101module_i2c_driver(cs35l56_i2c_driver);
102
103MODULE_DESCRIPTION("ASoC CS35L56 I2C driver");
104MODULE_IMPORT_NS("SND_SOC_CS35L56_CORE");
105MODULE_IMPORT_NS("SND_SOC_CS35L56_SHARED");
106MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
107MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
108MODULE_LICENSE("GPL");
~/ Read-only file preview.