| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// |
| 3 |
// CS35L56 ALSA SoC audio driver SPI 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/module.h> |
| 10 |
#include <linux/moduleparam.h> |
| 11 |
#include <linux/regmap.h> |
| 12 |
#include <linux/spi/spi.h> |
| 13 |
#include <linux/types.h> |
| 14 |
|
| 15 |
#include "cs35l56.h" |
| 16 |
|
| 17 |
static int cs35l56_spi_probe(struct spi_device *spi) |
| 18 |
{ |
| 19 |
const struct regmap_config *regmap_config = &cs35l56_regmap_spi; |
| 20 |
struct cs35l56_private *cs35l56; |
| 21 |
int ret; |
| 22 |
|
| 23 |
cs35l56 = devm_kzalloc(&spi->dev, sizeof(struct cs35l56_private), GFP_KERNEL); |
| 24 |
if (!cs35l56) |
| 25 |
return -ENOMEM; |
| 26 |
|
| 27 |
spi_set_drvdata(spi, cs35l56); |
| 28 |
|
| 29 |
cs35l56->base.type = 0x56; |
| 30 |
|
| 31 |
cs35l56->base.regmap = devm_regmap_init_spi(spi, regmap_config); |
| 32 |
if (IS_ERR(cs35l56->base.regmap)) { |
| 33 |
ret = PTR_ERR(cs35l56->base.regmap); |
| 34 |
return dev_err_probe(&spi->dev, ret, "Failed to allocate register map\n"); |
| 35 |
} |
| 36 |
|
| 37 |
cs35l56->base.dev = &spi->dev; |
| 38 |
cs35l56->base.can_hibernate = true; |
| 39 |
ret = cs35l56_init_config_for_spi(&cs35l56->base, spi); |
| 40 |
if (ret) |
| 41 |
return ret; |
| 42 |
|
| 43 |
ret = cs35l56_common_probe(cs35l56); |
| 44 |
if (ret != 0) |
| 45 |
return ret; |
| 46 |
|
| 47 |
ret = cs35l56_init(cs35l56); |
| 48 |
if (ret == 0) |
| 49 |
ret = cs35l56_irq_request(&cs35l56->base, spi->irq); |
| 50 |
if (ret < 0) |
| 51 |
cs35l56_remove(cs35l56); |
| 52 |
|
| 53 |
return ret; |
| 54 |
} |
| 55 |
|
| 56 |
static void cs35l56_spi_remove(struct spi_device *spi) |
| 57 |
{ |
| 58 |
struct cs35l56_private *cs35l56 = spi_get_drvdata(spi); |
| 59 |
|
| 60 |
cs35l56_remove(cs35l56); |
| 61 |
} |
| 62 |
|
| 63 |
static const struct spi_device_id cs35l56_id_spi[] = { |
| 64 |
{ "cs35l56", 0 }, |
| 65 |
{} |
| 66 |
}; |
| 67 |
MODULE_DEVICE_TABLE(spi, cs35l56_id_spi); |
| 68 |
|
| 69 |
#ifdef CONFIG_ACPI |
| 70 |
static const struct acpi_device_id cs35l56_asoc_acpi_match[] = { |
| 71 |
{ "CSC355C", 0 }, |
| 72 |
{}, |
| 73 |
}; |
| 74 |
MODULE_DEVICE_TABLE(acpi, cs35l56_asoc_acpi_match); |
| 75 |
#endif |
| 76 |
|
| 77 |
static struct spi_driver cs35l56_spi_driver = { |
| 78 |
.driver = { |
| 79 |
.name = "cs35l56", |
| 80 |
.pm = pm_ptr(&cs35l56_pm_ops_i2c_spi), |
| 81 |
.acpi_match_table = ACPI_PTR(cs35l56_asoc_acpi_match), |
| 82 |
}, |
| 83 |
.id_table = cs35l56_id_spi, |
| 84 |
.probe = cs35l56_spi_probe, |
| 85 |
.remove = cs35l56_spi_remove, |
| 86 |
}; |
| 87 |
|
| 88 |
module_spi_driver(cs35l56_spi_driver); |
| 89 |
|
| 90 |
MODULE_DESCRIPTION("ASoC CS35L56 SPI driver"); |
| 91 |
MODULE_IMPORT_NS("SND_SOC_CS35L56_CORE"); |
| 92 |
MODULE_IMPORT_NS("SND_SOC_CS35L56_SHARED"); |
| 93 |
MODULE_AUTHOR("Richard Fitzgerald <[email protected]>"); |
| 94 |
MODULE_AUTHOR("Simon Trimmer <[email protected]>"); |
| 95 |
MODULE_LICENSE("GPL"); |