static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value, const void *data, int len) { int ret; if (!snd_soc_codec_volatile_register(codec, reg) && reg < codec->driver->reg_cache_size && !codec->cache_bypass) { ret = snd_soc_cache_write(codec, reg, value); if (ret < 0) return -1; } if (codec->cache_only) { codec->cache_sync = 1; return 0; } ret = codec->hw_write(codec->control_data, data, len); if (ret == len) return 0; if (ret < 0) return ret; else return -EIO; }
/* Primitive bulk write support for soc-cache. The data pointed to by * `data' needs to already be in the form the hardware expects. Any * data written through this function will not go through the cache as * it only handles writing to volatile or out of bounds registers. * * This is currently only supported for devices using the regmap API * wrappers. */ static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int reg, const void *data, size_t len) { if (!codec->cache_bypass && !snd_soc_codec_volatile_register(codec, reg) && reg < codec->driver->reg_cache_size) return -EINVAL; return regmap_raw_write(codec->control_data, reg, data, len); }
/* Primitive bulk write support for soc-cache. The data pointed to by * `data' needs to already be in the form the hardware expects. Any * data written through this function will not go through the cache as * it only handles writing to volatile or out of bounds registers. * * This is currently only supported for devices using the regmap API * wrappers. */ static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int reg, const void *data, size_t len) { /* To ensure that we don't get out of sync with the cache, check * whether the base register is volatile or if we've directly asked * to bypass the cache. Out of bounds registers are considered * volatile. */ if (!codec->cache_bypass && !snd_soc_codec_volatile_register(codec, reg) && reg < codec->driver->reg_cache_size) return -EINVAL; return regmap_raw_write(codec->control_data, reg, data, len); }
static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg) { int ret; unsigned int val; if (reg >= codec->driver->reg_cache_size || snd_soc_codec_volatile_register(codec, reg) || codec->cache_bypass) { if (codec->cache_only) return -1; BUG_ON(!codec->hw_read); return codec->hw_read(codec, reg); } ret = snd_soc_cache_read(codec, reg, &val); if (ret < 0) return -1; return val; }
static int hw_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { int ret; if (!snd_soc_codec_volatile_register(codec, reg) && reg < codec->driver->reg_cache_size && !codec->cache_bypass) { ret = snd_soc_cache_write(codec, reg, value); if (ret < 0) return -1; } if (codec->cache_only) { codec->cache_sync = 1; return 0; } return regmap_write(codec->control_data, reg, value); }
static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg) { int ret; unsigned int val; if (reg >= codec->driver->reg_cache_size || snd_soc_codec_volatile_register(codec, reg) || codec->cache_bypass) { if (codec->cache_only) return -1; ret = regmap_read(codec->control_data, reg, &val); if (ret == 0) return val; else return -1; } ret = snd_soc_cache_read(codec, reg, &val); if (ret < 0) return -1; return val; }
/* Primitive bulk write support for soc-cache. The data pointed to by * `data' needs to already be in the form the hardware expects * including any leading register specific data. Any data written * through this function will not go through the cache as it only * handles writing to volatile or out of bounds registers. */ static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int reg, const void *data, size_t len) { int ret; /* To ensure that we don't get out of sync with the cache, check * whether the base register is volatile or if we've directly asked * to bypass the cache. Out of bounds registers are considered * volatile. */ if (!codec->cache_bypass && !snd_soc_codec_volatile_register(codec, reg) && reg < codec->driver->reg_cache_size) return -EINVAL; switch (codec->control_type) { #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) case SND_SOC_I2C: ret = i2c_master_send(to_i2c_client(codec->dev), data, len); break; #endif #if defined(CONFIG_SPI_MASTER) case SND_SOC_SPI: ret = spi_write(to_spi_device(codec->dev), data, len); break; #endif default: BUG(); } if (ret == len) return 0; if (ret < 0) return ret; else return -EIO; }