Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 //
0003 // cs35l41-spi.c -- CS35l41 SPI driver
0004 //
0005 // Copyright 2017-2021 Cirrus Logic, Inc.
0006 //
0007 // Author: David Rhodes <david.rhodes@cirrus.com>
0008 
0009 #include <linux/acpi.h>
0010 #include <linux/delay.h>
0011 #include <linux/init.h>
0012 #include <linux/kernel.h>
0013 #include <linux/module.h>
0014 #include <linux/moduleparam.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/spi/spi.h>
0017 
0018 #include "cs35l41.h"
0019 
0020 static const struct spi_device_id cs35l41_id_spi[] = {
0021     { "cs35l40", 0 },
0022     { "cs35l41", 0 },
0023     { "cs35l51", 0 },
0024     { "cs35l53", 0 },
0025     {}
0026 };
0027 
0028 MODULE_DEVICE_TABLE(spi, cs35l41_id_spi);
0029 
0030 static int cs35l41_spi_probe(struct spi_device *spi)
0031 {
0032     const struct regmap_config *regmap_config = &cs35l41_regmap_spi;
0033     struct cs35l41_hw_cfg *hw_cfg = dev_get_platdata(&spi->dev);
0034     struct cs35l41_private *cs35l41;
0035     int ret;
0036 
0037     cs35l41 = devm_kzalloc(&spi->dev, sizeof(struct cs35l41_private), GFP_KERNEL);
0038     if (!cs35l41)
0039         return -ENOMEM;
0040 
0041     spi->max_speed_hz = CS35L41_SPI_MAX_FREQ;
0042     spi_setup(spi);
0043 
0044     spi_set_drvdata(spi, cs35l41);
0045     cs35l41->regmap = devm_regmap_init_spi(spi, regmap_config);
0046     if (IS_ERR(cs35l41->regmap)) {
0047         ret = PTR_ERR(cs35l41->regmap);
0048         dev_err(&spi->dev, "Failed to allocate register map: %d\n", ret);
0049         return ret;
0050     }
0051 
0052     cs35l41->dev = &spi->dev;
0053     cs35l41->irq = spi->irq;
0054 
0055     return cs35l41_probe(cs35l41, hw_cfg);
0056 }
0057 
0058 static void cs35l41_spi_remove(struct spi_device *spi)
0059 {
0060     struct cs35l41_private *cs35l41 = spi_get_drvdata(spi);
0061 
0062     cs35l41_remove(cs35l41);
0063 }
0064 
0065 #ifdef CONFIG_OF
0066 static const struct of_device_id cs35l41_of_match[] = {
0067     { .compatible = "cirrus,cs35l40" },
0068     { .compatible = "cirrus,cs35l41" },
0069     {},
0070 };
0071 MODULE_DEVICE_TABLE(of, cs35l41_of_match);
0072 #endif
0073 
0074 #ifdef CONFIG_ACPI
0075 static const struct acpi_device_id cs35l41_acpi_match[] = {
0076     { "CSC3541", 0 }, /* Cirrus Logic PnP ID + part ID */
0077     { "CLSA3541", 0 }, /* Cirrus Logic PnP ID + part ID */
0078     {},
0079 };
0080 MODULE_DEVICE_TABLE(acpi, cs35l41_acpi_match);
0081 #endif
0082 
0083 static struct spi_driver cs35l41_spi_driver = {
0084     .driver = {
0085         .name       = "cs35l41",
0086         .pm     = &cs35l41_pm_ops,
0087         .of_match_table = of_match_ptr(cs35l41_of_match),
0088         .acpi_match_table = ACPI_PTR(cs35l41_acpi_match),
0089     },
0090     .id_table   = cs35l41_id_spi,
0091     .probe      = cs35l41_spi_probe,
0092     .remove     = cs35l41_spi_remove,
0093 };
0094 
0095 module_spi_driver(cs35l41_spi_driver);
0096 
0097 MODULE_DESCRIPTION("SPI CS35L41 driver");
0098 MODULE_AUTHOR("David Rhodes, Cirrus Logic Inc, <david.rhodes@cirrus.com>");
0099 MODULE_LICENSE("GPL");