xref: /linux/sound/pci/hda/cs35l56_hda_spi.c (revision 2d0401ee)
173cfbfa9SSimon Trimmer // SPDX-License-Identifier: GPL-2.0-only
273cfbfa9SSimon Trimmer //
373cfbfa9SSimon Trimmer // CS35L56 HDA audio driver SPI binding
473cfbfa9SSimon Trimmer //
573cfbfa9SSimon Trimmer // Copyright (C) 2023 Cirrus Logic, Inc. and
673cfbfa9SSimon Trimmer //                    Cirrus Logic International Semiconductor Ltd.
773cfbfa9SSimon Trimmer 
873cfbfa9SSimon Trimmer #include <linux/module.h>
973cfbfa9SSimon Trimmer #include <linux/regmap.h>
1073cfbfa9SSimon Trimmer #include <linux/spi/spi.h>
1173cfbfa9SSimon Trimmer 
1273cfbfa9SSimon Trimmer #include "cs35l56_hda.h"
1373cfbfa9SSimon Trimmer 
cs35l56_hda_spi_probe(struct spi_device * spi)1473cfbfa9SSimon Trimmer static int cs35l56_hda_spi_probe(struct spi_device *spi)
1573cfbfa9SSimon Trimmer {
16769dca23SSimon Trimmer 	const struct spi_device_id *id = spi_get_device_id(spi);
1773cfbfa9SSimon Trimmer 	struct cs35l56_hda *cs35l56;
1873cfbfa9SSimon Trimmer 	int ret;
1973cfbfa9SSimon Trimmer 
2073cfbfa9SSimon Trimmer 	cs35l56 = devm_kzalloc(&spi->dev, sizeof(*cs35l56), GFP_KERNEL);
2173cfbfa9SSimon Trimmer 	if (!cs35l56)
2273cfbfa9SSimon Trimmer 		return -ENOMEM;
2373cfbfa9SSimon Trimmer 
2473cfbfa9SSimon Trimmer 	cs35l56->base.dev = &spi->dev;
25732c678eSRichard Fitzgerald 
26732c678eSRichard Fitzgerald #ifdef CS35L56_WAKE_HOLD_TIME_US
27732c678eSRichard Fitzgerald 	cs35l56->base.can_hibernate = true;
28732c678eSRichard Fitzgerald #endif
2973cfbfa9SSimon Trimmer 	cs35l56->base.regmap = devm_regmap_init_spi(spi, &cs35l56_regmap_spi);
3073cfbfa9SSimon Trimmer 	if (IS_ERR(cs35l56->base.regmap)) {
3173cfbfa9SSimon Trimmer 		ret = PTR_ERR(cs35l56->base.regmap);
3273cfbfa9SSimon Trimmer 		dev_err(cs35l56->base.dev, "Failed to allocate register map: %d\n",
3373cfbfa9SSimon Trimmer 			ret);
3473cfbfa9SSimon Trimmer 		return ret;
3573cfbfa9SSimon Trimmer 	}
3673cfbfa9SSimon Trimmer 
37769dca23SSimon Trimmer 	ret = cs35l56_hda_common_probe(cs35l56, id->driver_data, spi_get_chipselect(spi, 0));
3873cfbfa9SSimon Trimmer 	if (ret)
3973cfbfa9SSimon Trimmer 		return ret;
4073cfbfa9SSimon Trimmer 	ret = cs35l56_irq_request(&cs35l56->base, spi->irq);
4173cfbfa9SSimon Trimmer 	if (ret < 0)
4273cfbfa9SSimon Trimmer 		cs35l56_hda_remove(cs35l56->base.dev);
4373cfbfa9SSimon Trimmer 
4473cfbfa9SSimon Trimmer 	return ret;
4573cfbfa9SSimon Trimmer }
4673cfbfa9SSimon Trimmer 
cs35l56_hda_spi_remove(struct spi_device * spi)4773cfbfa9SSimon Trimmer static void cs35l56_hda_spi_remove(struct spi_device *spi)
4873cfbfa9SSimon Trimmer {
4973cfbfa9SSimon Trimmer 	cs35l56_hda_remove(&spi->dev);
5073cfbfa9SSimon Trimmer }
5173cfbfa9SSimon Trimmer 
5273cfbfa9SSimon Trimmer static const struct spi_device_id cs35l56_hda_spi_id[] = {
53769dca23SSimon Trimmer 	{ "cs35l54-hda", 0x3554 },
54769dca23SSimon Trimmer 	{ "cs35l56-hda", 0x3556 },
55769dca23SSimon Trimmer 	{ "cs35l57-hda", 0x3557 },
5673cfbfa9SSimon Trimmer 	{}
5773cfbfa9SSimon Trimmer };
5873cfbfa9SSimon Trimmer 
59*2d0401eeSSimon Trimmer static const struct acpi_device_id cs35l56_acpi_hda_match[] = {
60*2d0401eeSSimon Trimmer 	{ "CSC3554", 0 },
61*2d0401eeSSimon Trimmer 	{ "CSC3556", 0 },
62*2d0401eeSSimon Trimmer 	{ "CSC3557", 0 },
63*2d0401eeSSimon Trimmer 	{}
64*2d0401eeSSimon Trimmer };
65*2d0401eeSSimon Trimmer MODULE_DEVICE_TABLE(acpi, cs35l56_acpi_hda_match);
66*2d0401eeSSimon Trimmer 
6773cfbfa9SSimon Trimmer static struct spi_driver cs35l56_hda_spi_driver = {
6873cfbfa9SSimon Trimmer 	.driver = {
6973cfbfa9SSimon Trimmer 		.name		  = "cs35l56-hda",
70*2d0401eeSSimon Trimmer 		.acpi_match_table = cs35l56_acpi_hda_match,
7173cfbfa9SSimon Trimmer 		.pm		  = &cs35l56_hda_pm_ops,
7273cfbfa9SSimon Trimmer 	},
7373cfbfa9SSimon Trimmer 	.id_table	= cs35l56_hda_spi_id,
7473cfbfa9SSimon Trimmer 	.probe		= cs35l56_hda_spi_probe,
7573cfbfa9SSimon Trimmer 	.remove		= cs35l56_hda_spi_remove,
7673cfbfa9SSimon Trimmer };
7773cfbfa9SSimon Trimmer module_spi_driver(cs35l56_hda_spi_driver);
7873cfbfa9SSimon Trimmer 
7973cfbfa9SSimon Trimmer MODULE_DESCRIPTION("HDA CS35L56 SPI driver");
8073cfbfa9SSimon Trimmer MODULE_IMPORT_NS(SND_HDA_SCODEC_CS35L56);
8173cfbfa9SSimon Trimmer MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED);
8273cfbfa9SSimon Trimmer MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
8373cfbfa9SSimon Trimmer MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
8473cfbfa9SSimon Trimmer MODULE_LICENSE("GPL");
85