Merge tag 'driver-core-3.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / sound / soc / soc-io.c
CommitLineData
5bef44f9
MB
1/*
2 * soc-io.c -- ASoC register I/O helpers
3 *
4 * Copyright 2009-2011 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
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.
12 */
13
14#include <linux/i2c.h>
15#include <linux/spi/spi.h>
be3ea3b9 16#include <linux/regmap.h>
d81a6d71 17#include <linux/export.h>
5bef44f9
MB
18#include <sound/soc.h>
19
20#include <trace/events/asoc.h>
21
4835ff9a 22#ifdef CONFIG_REGMAP
be3ea3b9
MB
23static int hw_write(struct snd_soc_codec *codec, unsigned int reg,
24 unsigned int value)
5bef44f9 25{
be3ea3b9 26 return regmap_write(codec->control_data, reg, value);
5bef44f9
MB
27}
28
29static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
30{
31 int ret;
32 unsigned int val;
33
65725471
MB
34 ret = regmap_read(codec->control_data, reg, &val);
35 if (ret == 0)
36 return val;
37 else
5bef44f9 38 return -1;
5bef44f9
MB
39}
40
5bef44f9
MB
41/**
42 * snd_soc_codec_set_cache_io: Set up standard I/O functions.
43 *
44 * @codec: CODEC to configure.
092eba93 45 * @map: Register map to write to
5bef44f9
MB
46 *
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.
51 *
52 * The caller is responsible for allocating and initialising the
53 * actual cache.
54 *
55 * Note that at present this code cannot be used by CODECs with
56 * volatile registers.
57 */
58int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
092eba93 59 struct regmap *regmap)
5bef44f9 60{
2b4bdee2 61 int ret;
5bef44f9 62
092eba93
XL
63 /* Device has made its own regmap arrangements */
64 if (!regmap)
65 codec->control_data = dev_get_regmap(codec->dev, NULL);
66 else
67 codec->control_data = regmap;
68
69 if (IS_ERR(codec->control_data))
70 return PTR_ERR(codec->control_data);
71
be3ea3b9 72 codec->write = hw_write;
5bef44f9 73 codec->read = hw_read;
5bef44f9 74
092eba93
XL
75 ret = regmap_get_val_bytes(codec->control_data);
76 /* Errors are legitimate for non-integer byte
77 * multiples */
78 if (ret > 0)
79 codec->val_bytes = ret;
80
81 codec->using_regmap = true;
5bef44f9 82
092eba93 83 return 0;
5bef44f9
MB
84}
85EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
4835ff9a
MB
86#else
87int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
092eba93 88 struct regmap *regmap)
4835ff9a
MB
89{
90 return -ENOTSUPP;
91}
92EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
93#endif
This page took 0.125927 seconds and 5 git commands to generate.