xref: /openbmc/linux/sound/soc/codecs/adau1781-spi.c (revision fda8d26e61fc518499ddc78ae74ec1aaa89c4134)
1*fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22923af02SLars-Peter Clausen /*
32923af02SLars-Peter Clausen  * Driver for ADAU1381/ADAU1781 CODEC
42923af02SLars-Peter Clausen  *
52923af02SLars-Peter Clausen  * Copyright 2014 Analog Devices Inc.
62923af02SLars-Peter Clausen  *  Author: Lars-Peter Clausen <lars@metafoo.de>
72923af02SLars-Peter Clausen  */
82923af02SLars-Peter Clausen 
92923af02SLars-Peter Clausen #include <linux/mod_devicetable.h>
102923af02SLars-Peter Clausen #include <linux/module.h>
112923af02SLars-Peter Clausen #include <linux/regmap.h>
122923af02SLars-Peter Clausen #include <linux/spi/spi.h>
132923af02SLars-Peter Clausen #include <sound/soc.h>
142923af02SLars-Peter Clausen 
152923af02SLars-Peter Clausen #include "adau1781.h"
162923af02SLars-Peter Clausen 
172923af02SLars-Peter Clausen static void adau1781_spi_switch_mode(struct device *dev)
182923af02SLars-Peter Clausen {
192923af02SLars-Peter Clausen 	struct spi_device *spi = to_spi_device(dev);
202923af02SLars-Peter Clausen 
212923af02SLars-Peter Clausen 	/*
222923af02SLars-Peter Clausen 	 * To get the device into SPI mode CLATCH has to be pulled low three
232923af02SLars-Peter Clausen 	 * times.  Do this by issuing three dummy reads.
242923af02SLars-Peter Clausen 	 */
252923af02SLars-Peter Clausen 	spi_w8r8(spi, 0x00);
262923af02SLars-Peter Clausen 	spi_w8r8(spi, 0x00);
272923af02SLars-Peter Clausen 	spi_w8r8(spi, 0x00);
282923af02SLars-Peter Clausen }
292923af02SLars-Peter Clausen 
302923af02SLars-Peter Clausen static int adau1781_spi_probe(struct spi_device *spi)
312923af02SLars-Peter Clausen {
322923af02SLars-Peter Clausen 	const struct spi_device_id *id = spi_get_device_id(spi);
332923af02SLars-Peter Clausen 	struct regmap_config config;
342923af02SLars-Peter Clausen 
352923af02SLars-Peter Clausen 	if (!id)
362923af02SLars-Peter Clausen 		return -EINVAL;
372923af02SLars-Peter Clausen 
382923af02SLars-Peter Clausen 	config = adau1781_regmap_config;
392923af02SLars-Peter Clausen 	config.val_bits = 8;
402923af02SLars-Peter Clausen 	config.reg_bits = 24;
412923af02SLars-Peter Clausen 	config.read_flag_mask = 0x1;
422923af02SLars-Peter Clausen 
432923af02SLars-Peter Clausen 	return adau1781_probe(&spi->dev,
442923af02SLars-Peter Clausen 		devm_regmap_init_spi(spi, &config),
452923af02SLars-Peter Clausen 		id->driver_data, adau1781_spi_switch_mode);
462923af02SLars-Peter Clausen }
472923af02SLars-Peter Clausen 
482923af02SLars-Peter Clausen static int adau1781_spi_remove(struct spi_device *spi)
492923af02SLars-Peter Clausen {
505d76de61SLars-Peter Clausen 	adau17x1_remove(&spi->dev);
512923af02SLars-Peter Clausen 	return 0;
522923af02SLars-Peter Clausen }
532923af02SLars-Peter Clausen 
542923af02SLars-Peter Clausen static const struct spi_device_id adau1781_spi_id[] = {
552923af02SLars-Peter Clausen 	{ "adau1381", ADAU1381 },
562923af02SLars-Peter Clausen 	{ "adau1781", ADAU1781 },
572923af02SLars-Peter Clausen 	{ }
582923af02SLars-Peter Clausen };
592923af02SLars-Peter Clausen MODULE_DEVICE_TABLE(spi, adau1781_spi_id);
602923af02SLars-Peter Clausen 
61aaf0f3aeSAndreas Irestål #if defined(CONFIG_OF)
62aaf0f3aeSAndreas Irestål static const struct of_device_id adau1781_spi_dt_ids[] = {
63aaf0f3aeSAndreas Irestål 	{ .compatible = "adi,adau1381", },
64aaf0f3aeSAndreas Irestål 	{ .compatible = "adi,adau1781", },
65aaf0f3aeSAndreas Irestål 	{ },
66aaf0f3aeSAndreas Irestål };
67aaf0f3aeSAndreas Irestål MODULE_DEVICE_TABLE(of, adau1781_spi_dt_ids);
68aaf0f3aeSAndreas Irestål #endif
69aaf0f3aeSAndreas Irestål 
702923af02SLars-Peter Clausen static struct spi_driver adau1781_spi_driver = {
712923af02SLars-Peter Clausen 	.driver = {
722923af02SLars-Peter Clausen 		.name = "adau1781",
73aaf0f3aeSAndreas Irestål 		.of_match_table = of_match_ptr(adau1781_spi_dt_ids),
742923af02SLars-Peter Clausen 	},
752923af02SLars-Peter Clausen 	.probe = adau1781_spi_probe,
762923af02SLars-Peter Clausen 	.remove = adau1781_spi_remove,
772923af02SLars-Peter Clausen 	.id_table = adau1781_spi_id,
782923af02SLars-Peter Clausen };
792923af02SLars-Peter Clausen module_spi_driver(adau1781_spi_driver);
802923af02SLars-Peter Clausen 
812923af02SLars-Peter Clausen MODULE_DESCRIPTION("ASoC ADAU1381/ADAU1781 CODEC SPI driver");
822923af02SLars-Peter Clausen MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
832923af02SLars-Peter Clausen MODULE_LICENSE("GPL");
84