2 * soc-io.c -- ASoC register I/O helpers
4 * Copyright 2009-2011 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/i2c.h>
15 #include <linux/spi/spi.h>
16 #include <linux/regmap.h>
17 #include <linux/export.h>
18 #include <sound/soc.h>
20 #include <trace/events/asoc.h>
23 static int hw_write(struct snd_soc_codec *codec, unsigned int reg,
26 return regmap_write(codec->control_data, reg, value);
29 static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
34 ret = regmap_read(codec->control_data, reg, &val);
42 * snd_soc_codec_set_cache_io: Set up standard I/O functions.
44 * @codec: CODEC to configure.
45 * @map: Register map to write to
47 * Register formats are frequently shared between many I2C and SPI
48 * devices. In order to promote code reuse the ASoC core provides
49 * some standard implementations of CODEC read and write operations
50 * which can be set up using this function.
52 * The caller is responsible for allocating and initialising the
55 * Note that at present this code cannot be used by CODECs with
58 int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
59 struct regmap *regmap)
63 /* Device has made its own regmap arrangements */
65 codec->control_data = dev_get_regmap(codec->dev, NULL);
67 codec->control_data = regmap;
69 if (IS_ERR(codec->control_data))
70 return PTR_ERR(codec->control_data);
72 codec->write = hw_write;
73 codec->read = hw_read;
75 ret = regmap_get_val_bytes(codec->control_data);
76 /* Errors are legitimate for non-integer byte
79 codec->val_bytes = ret;
81 codec->using_regmap = true;
85 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
87 int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
88 struct regmap *regmap)
92 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);