0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/spi/spi.h>
0012 #include <linux/module.h>
0013 #include <linux/of.h>
0014 #include <linux/regmap.h>
0015 #include <sound/soc.h>
0016
0017 #include "tlv320aic32x4.h"
0018
0019 static const struct of_device_id aic32x4_of_id[];
0020
0021 static int aic32x4_spi_probe(struct spi_device *spi)
0022 {
0023 struct regmap *regmap;
0024 struct regmap_config config;
0025
0026 config = aic32x4_regmap_config;
0027 config.reg_bits = 7;
0028 config.pad_bits = 1;
0029 config.val_bits = 8;
0030 config.read_flag_mask = 0x01;
0031
0032 regmap = devm_regmap_init_spi(spi, &config);
0033
0034 if (spi->dev.of_node) {
0035 const struct of_device_id *oid;
0036
0037 oid = of_match_node(aic32x4_of_id, spi->dev.of_node);
0038 dev_set_drvdata(&spi->dev, (void *)oid->data);
0039 } else {
0040 const struct spi_device_id *id_entry;
0041
0042 id_entry = spi_get_device_id(spi);
0043 dev_set_drvdata(&spi->dev, (void *)id_entry->driver_data);
0044 }
0045
0046 return aic32x4_probe(&spi->dev, regmap);
0047 }
0048
0049 static void aic32x4_spi_remove(struct spi_device *spi)
0050 {
0051 aic32x4_remove(&spi->dev);
0052 }
0053
0054 static const struct spi_device_id aic32x4_spi_id[] = {
0055 { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 },
0056 { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 },
0057 { }
0058 };
0059 MODULE_DEVICE_TABLE(spi, aic32x4_spi_id);
0060
0061 static const struct of_device_id aic32x4_of_id[] = {
0062 { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 },
0063 { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 },
0064 { }
0065 };
0066 MODULE_DEVICE_TABLE(of, aic32x4_of_id);
0067
0068 static struct spi_driver aic32x4_spi_driver = {
0069 .driver = {
0070 .name = "tlv320aic32x4",
0071 .owner = THIS_MODULE,
0072 .of_match_table = aic32x4_of_id,
0073 },
0074 .probe = aic32x4_spi_probe,
0075 .remove = aic32x4_spi_remove,
0076 .id_table = aic32x4_spi_id,
0077 };
0078
0079 module_spi_driver(aic32x4_spi_driver);
0080
0081 MODULE_DESCRIPTION("ASoC TLV320AIC32x4 codec driver SPI");
0082 MODULE_AUTHOR("Annaliese McDermond <nh6z@nh6z.net>");
0083 MODULE_LICENSE("GPL");