1 /* 2 * ADAU1977/ADAU1978/ADAU1979 driver 3 * 4 * Copyright 2014 Analog Devices Inc. 5 * Author: Lars-Peter Clausen <lars@metafoo.de> 6 * 7 * Licensed under the GPL-2. 8 */ 9 10 #include <linux/mod_devicetable.h> 11 #include <linux/module.h> 12 #include <linux/regmap.h> 13 #include <linux/of.h> 14 #include <linux/of_device.h> 15 #include <linux/spi/spi.h> 16 #include <sound/soc.h> 17 18 #include "adau1977.h" 19 20 static void adau1977_spi_switch_mode(struct device *dev) 21 { 22 struct spi_device *spi = to_spi_device(dev); 23 24 /* 25 * To get the device into SPI mode CLATCH has to be pulled low three 26 * times. Do this by issuing three dummy reads. 27 */ 28 spi_w8r8(spi, 0x00); 29 spi_w8r8(spi, 0x00); 30 spi_w8r8(spi, 0x00); 31 } 32 33 static int adau1977_spi_probe(struct spi_device *spi) 34 { 35 const struct spi_device_id *id = spi_get_device_id(spi); 36 struct regmap_config config; 37 38 if (!id) 39 return -EINVAL; 40 41 config = adau1977_regmap_config; 42 config.val_bits = 8; 43 config.reg_bits = 16; 44 config.read_flag_mask = 0x1; 45 46 return adau1977_probe(&spi->dev, 47 devm_regmap_init_spi(spi, &config), 48 id->driver_data, adau1977_spi_switch_mode); 49 } 50 51 static const struct spi_device_id adau1977_spi_ids[] = { 52 { "adau1977", ADAU1977 }, 53 { "adau1978", ADAU1978 }, 54 { "adau1979", ADAU1978 }, 55 { } 56 }; 57 MODULE_DEVICE_TABLE(spi, adau1977_spi_ids); 58 59 static const struct of_device_id adau1977_spi_of_match[] = { 60 { .compatible = "adi,adau1977" }, 61 { .compatible = "adi,adau1978" }, 62 { .compatible = "adi,adau1979" }, 63 { }, 64 }; 65 MODULE_DEVICE_TABLE(of, adau1977_spi_of_match); 66 67 static struct spi_driver adau1977_spi_driver = { 68 .driver = { 69 .name = "adau1977", 70 .of_match_table = of_match_ptr(adau1977_spi_of_match), 71 }, 72 .probe = adau1977_spi_probe, 73 .id_table = adau1977_spi_ids, 74 }; 75 module_spi_driver(adau1977_spi_driver); 76 77 MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver"); 78 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 79 MODULE_LICENSE("GPL"); 80