~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/soc-io.c

Version: ~ [ linux-5.5-rc7 ] ~ [ linux-5.4.13 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.97 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.166 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.210 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.210 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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>
 16 #include <linux/regmap.h>
 17 #include <linux/export.h>
 18 #include <sound/soc.h>
 19 
 20 #include <trace/events/asoc.h>
 21 
 22 #ifdef CONFIG_REGMAP
 23 static int hw_write(struct snd_soc_codec *codec, unsigned int reg,
 24                     unsigned int value)
 25 {
 26         int ret;
 27 
 28         if (!snd_soc_codec_volatile_register(codec, reg) &&
 29             reg < codec->driver->reg_cache_size &&
 30             !codec->cache_bypass) {
 31                 ret = snd_soc_cache_write(codec, reg, value);
 32                 if (ret < 0)
 33                         return -1;
 34         }
 35 
 36         if (codec->cache_only) {
 37                 codec->cache_sync = 1;
 38                 return 0;
 39         }
 40 
 41         return regmap_write(codec->control_data, reg, value);
 42 }
 43 
 44 static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
 45 {
 46         int ret;
 47         unsigned int val;
 48 
 49         if (reg >= codec->driver->reg_cache_size ||
 50             snd_soc_codec_volatile_register(codec, reg) ||
 51             codec->cache_bypass) {
 52                 if (codec->cache_only)
 53                         return -1;
 54 
 55                 ret = regmap_read(codec->control_data, reg, &val);
 56                 if (ret == 0)
 57                         return val;
 58                 else
 59                         return -1;
 60         }
 61 
 62         ret = snd_soc_cache_read(codec, reg, &val);
 63         if (ret < 0)
 64                 return -1;
 65         return val;
 66 }
 67 
 68 /**
 69  * snd_soc_codec_set_cache_io: Set up standard I/O functions.
 70  *
 71  * @codec: CODEC to configure.
 72  * @addr_bits: Number of bits of register address data.
 73  * @data_bits: Number of bits of data per register.
 74  * @control: Control bus used.
 75  *
 76  * Register formats are frequently shared between many I2C and SPI
 77  * devices.  In order to promote code reuse the ASoC core provides
 78  * some standard implementations of CODEC read and write operations
 79  * which can be set up using this function.
 80  *
 81  * The caller is responsible for allocating and initialising the
 82  * actual cache.
 83  *
 84  * Note that at present this code cannot be used by CODECs with
 85  * volatile registers.
 86  */
 87 int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
 88                                int addr_bits, int data_bits,
 89                                enum snd_soc_control_type control)
 90 {
 91         struct regmap_config config;
 92         int ret;
 93 
 94         memset(&config, 0, sizeof(config));
 95         codec->write = hw_write;
 96         codec->read = hw_read;
 97 
 98         config.reg_bits = addr_bits;
 99         config.val_bits = data_bits;
100 
101         switch (control) {
102 #if defined(CONFIG_REGMAP_I2C) || defined(CONFIG_REGMAP_I2C_MODULE)
103         case SND_SOC_I2C:
104                 codec->control_data = regmap_init_i2c(to_i2c_client(codec->dev),
105                                                       &config);
106                 break;
107 #endif
108 
109 #if defined(CONFIG_REGMAP_SPI) || defined(CONFIG_REGMAP_SPI_MODULE)
110         case SND_SOC_SPI:
111                 codec->control_data = regmap_init_spi(to_spi_device(codec->dev),
112                                                       &config);
113                 break;
114 #endif
115 
116         case SND_SOC_REGMAP:
117                 /* Device has made its own regmap arrangements */
118                 codec->using_regmap = true;
119                 if (!codec->control_data)
120                         codec->control_data = dev_get_regmap(codec->dev, NULL);
121 
122                 if (codec->control_data) {
123                         ret = regmap_get_val_bytes(codec->control_data);
124                         /* Errors are legitimate for non-integer byte
125                          * multiples */
126                         if (ret > 0)
127                                 codec->val_bytes = ret;
128                 }
129                 break;
130 
131         default:
132                 return -EINVAL;
133         }
134 
135         return PTR_ERR_OR_ZERO(codec->control_data);
136 }
137 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
138 #else
139 int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
140                                int addr_bits, int data_bits,
141                                enum snd_soc_control_type control)
142 {
143         return -ENOTSUPP;
144 }
145 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
146 #endif
147 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp