Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ADAU1977/ADAU1978/ADAU1979 driver
0004  *
0005  * Copyright 2014 Analog Devices Inc.
0006  *  Author: Lars-Peter Clausen <lars@metafoo.de>
0007  */
0008 
0009 #include <linux/mod_devicetable.h>
0010 #include <linux/module.h>
0011 #include <linux/regmap.h>
0012 #include <linux/of.h>
0013 #include <linux/of_device.h>
0014 #include <linux/spi/spi.h>
0015 #include <sound/soc.h>
0016 
0017 #include "adau1977.h"
0018 
0019 static void adau1977_spi_switch_mode(struct device *dev)
0020 {
0021     struct spi_device *spi = to_spi_device(dev);
0022 
0023     /*
0024      * To get the device into SPI mode CLATCH has to be pulled low three
0025      * times.  Do this by issuing three dummy reads.
0026      */
0027     spi_w8r8(spi, 0x00);
0028     spi_w8r8(spi, 0x00);
0029     spi_w8r8(spi, 0x00);
0030 }
0031 
0032 static int adau1977_spi_probe(struct spi_device *spi)
0033 {
0034     const struct spi_device_id *id = spi_get_device_id(spi);
0035     struct regmap_config config;
0036 
0037     if (!id)
0038         return -EINVAL;
0039 
0040     config = adau1977_regmap_config;
0041     config.val_bits = 8;
0042     config.reg_bits = 16;
0043     config.read_flag_mask = 0x1;
0044 
0045     return adau1977_probe(&spi->dev,
0046         devm_regmap_init_spi(spi, &config),
0047         id->driver_data, adau1977_spi_switch_mode);
0048 }
0049 
0050 static const struct spi_device_id adau1977_spi_ids[] = {
0051     { "adau1977", ADAU1977 },
0052     { "adau1978", ADAU1978 },
0053     { "adau1979", ADAU1978 },
0054     { }
0055 };
0056 MODULE_DEVICE_TABLE(spi, adau1977_spi_ids);
0057 
0058 static const struct of_device_id adau1977_spi_of_match[] = {
0059         { .compatible = "adi,adau1977" },
0060         { .compatible = "adi,adau1978" },
0061         { .compatible = "adi,adau1979" },
0062         { },
0063 };
0064 MODULE_DEVICE_TABLE(of, adau1977_spi_of_match);
0065 
0066 static struct spi_driver adau1977_spi_driver = {
0067     .driver = {
0068         .name = "adau1977",
0069         .of_match_table = of_match_ptr(adau1977_spi_of_match),
0070     },
0071     .probe = adau1977_spi_probe,
0072     .id_table = adau1977_spi_ids,
0073 };
0074 module_spi_driver(adau1977_spi_driver);
0075 
0076 MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver");
0077 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
0078 MODULE_LICENSE("GPL");