2 * soc-cache.c -- ASoC register cache helpers
4 * Copyright 2009 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 <sound/soc.h>
16 static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
19 u16 *cache = codec->reg_cache;
20 if (reg >= codec->reg_cache_size)
25 static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
28 u16 *cache = codec->reg_cache;
32 BUG_ON(codec->volatile_register);
34 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
35 data[1] = value & 0x00ff;
37 if (reg < codec->reg_cache_size)
39 ret = codec->hw_write(codec->control_data, data, 2);
52 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
53 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
55 { 7, 9, snd_soc_7_9_write, snd_soc_7_9_read },
59 * snd_soc_codec_set_cache_io: Set up standard I/O functions.
61 * @codec: CODEC to configure.
62 * @type: Type of cache.
63 * @addr_bits: Number of bits of register address data.
64 * @data_bits: Number of bits of data per register.
66 * Register formats are frequently shared between many I2C and SPI
67 * devices. In order to promote code reuse the ASoC core provides
68 * some standard implementations of CODEC read and write operations
69 * which can be set up using this function.
71 * The caller is responsible for allocating and initialising the
74 * Note that at present this code cannot be used by CODECs with
77 int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
78 int addr_bits, int data_bits)
82 /* We don't support volatile registers yet - refactoring of
83 * the hw_read operation will be required to do so. */
84 if (codec->volatile_register) {
85 printk(KERN_ERR "Volatile registers not yet supported\n");
89 for (i = 0; i < ARRAY_SIZE(io_types); i++)
90 if (io_types[i].addr_bits == addr_bits &&
91 io_types[i].data_bits == data_bits)
93 if (i == ARRAY_SIZE(io_types)) {
95 "No I/O functions for %d bit address %d bit data\n",
96 addr_bits, data_bits);
100 codec->write = io_types[i].write;
101 codec->read = io_types[i].read;
105 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);