1603597c9SLars-Peter Clausen /* 2603597c9SLars-Peter Clausen * ADAU1977/ADAU1978/ADAU1979 driver 3603597c9SLars-Peter Clausen * 4603597c9SLars-Peter Clausen * Copyright 2014 Analog Devices Inc. 5603597c9SLars-Peter Clausen * Author: Lars-Peter Clausen <lars@metafoo.de> 6603597c9SLars-Peter Clausen * 7603597c9SLars-Peter Clausen * Licensed under the GPL-2. 8603597c9SLars-Peter Clausen */ 9603597c9SLars-Peter Clausen 10603597c9SLars-Peter Clausen #include <linux/mod_devicetable.h> 11603597c9SLars-Peter Clausen #include <linux/module.h> 12603597c9SLars-Peter Clausen #include <linux/regmap.h> 13603597c9SLars-Peter Clausen #include <linux/spi/spi.h> 14603597c9SLars-Peter Clausen #include <sound/soc.h> 15603597c9SLars-Peter Clausen 16603597c9SLars-Peter Clausen #include "adau1977.h" 17603597c9SLars-Peter Clausen 18603597c9SLars-Peter Clausen static void adau1977_spi_switch_mode(struct device *dev) 19603597c9SLars-Peter Clausen { 20603597c9SLars-Peter Clausen struct spi_device *spi = to_spi_device(dev); 21603597c9SLars-Peter Clausen 22603597c9SLars-Peter Clausen /* 23603597c9SLars-Peter Clausen * To get the device into SPI mode CLATCH has to be pulled low three 24603597c9SLars-Peter Clausen * times. Do this by issuing three dummy reads. 25603597c9SLars-Peter Clausen */ 26603597c9SLars-Peter Clausen spi_w8r8(spi, 0x00); 27603597c9SLars-Peter Clausen spi_w8r8(spi, 0x00); 28603597c9SLars-Peter Clausen spi_w8r8(spi, 0x00); 29603597c9SLars-Peter Clausen } 30603597c9SLars-Peter Clausen 31603597c9SLars-Peter Clausen static int adau1977_spi_probe(struct spi_device *spi) 32603597c9SLars-Peter Clausen { 33603597c9SLars-Peter Clausen const struct spi_device_id *id = spi_get_device_id(spi); 34603597c9SLars-Peter Clausen struct regmap_config config; 35603597c9SLars-Peter Clausen 36603597c9SLars-Peter Clausen if (!id) 37603597c9SLars-Peter Clausen return -EINVAL; 38603597c9SLars-Peter Clausen 39603597c9SLars-Peter Clausen config = adau1977_regmap_config; 40603597c9SLars-Peter Clausen config.val_bits = 8; 41603597c9SLars-Peter Clausen config.reg_bits = 16; 42603597c9SLars-Peter Clausen config.read_flag_mask = 0x1; 43603597c9SLars-Peter Clausen 44603597c9SLars-Peter Clausen return adau1977_probe(&spi->dev, 45603597c9SLars-Peter Clausen devm_regmap_init_spi(spi, &config), 46603597c9SLars-Peter Clausen id->driver_data, adau1977_spi_switch_mode); 47603597c9SLars-Peter Clausen } 48603597c9SLars-Peter Clausen 49603597c9SLars-Peter Clausen static int adau1977_spi_remove(struct spi_device *spi) 50603597c9SLars-Peter Clausen { 51603597c9SLars-Peter Clausen snd_soc_unregister_codec(&spi->dev); 52603597c9SLars-Peter Clausen return 0; 53603597c9SLars-Peter Clausen } 54603597c9SLars-Peter Clausen 55603597c9SLars-Peter Clausen static const struct spi_device_id adau1977_spi_ids[] = { 56603597c9SLars-Peter Clausen { "adau1977", ADAU1977 }, 57603597c9SLars-Peter Clausen { "adau1978", ADAU1978 }, 58603597c9SLars-Peter Clausen { "adau1979", ADAU1978 }, 59603597c9SLars-Peter Clausen { } 60603597c9SLars-Peter Clausen }; 61603597c9SLars-Peter Clausen MODULE_DEVICE_TABLE(spi, adau1977_spi_ids); 62603597c9SLars-Peter Clausen 63603597c9SLars-Peter Clausen static struct spi_driver adau1977_spi_driver = { 64603597c9SLars-Peter Clausen .driver = { 65603597c9SLars-Peter Clausen .name = "adau1977", 66603597c9SLars-Peter Clausen .owner = THIS_MODULE, 67603597c9SLars-Peter Clausen }, 68603597c9SLars-Peter Clausen .probe = adau1977_spi_probe, 69603597c9SLars-Peter Clausen .remove = adau1977_spi_remove, 70603597c9SLars-Peter Clausen .id_table = adau1977_spi_ids, 71603597c9SLars-Peter Clausen }; 72603597c9SLars-Peter Clausen module_spi_driver(adau1977_spi_driver); 73603597c9SLars-Peter Clausen 74603597c9SLars-Peter Clausen MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver"); 75603597c9SLars-Peter Clausen MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 76603597c9SLars-Peter Clausen MODULE_LICENSE("GPL"); 77