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