static int cx20442_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec); u8 *reg_cache = codec->reg_cache; int vls, vsp, old, len; char buf[18]; if (reg >= codec->driver->reg_cache_size) return -EINVAL; /* hw_write and control_data pointers required for talking to the modem * are expected to be set by the line discipline initialization code */ if (!codec->hw_write || !cx20442->control_data) return -EIO; old = reg_cache[reg]; reg_cache[reg] = value; vls = cx20442_pm_to_v253_vls(value); if (vls < 0) return vls; vsp = cx20442_pm_to_v253_vsp(value); if (vsp < 0) return vsp; if ((vls == V253_VLS_T) || (vls == cx20442_pm_to_v253_vls(old))) { if (vsp == cx20442_pm_to_v253_vsp(old)) return 0; len = snprintf(buf, ARRAY_SIZE(buf), "at+vsp=%d\r", vsp); } else if (vsp == cx20442_pm_to_v253_vsp(old)) len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d\r", vls); else len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d;+vsp=%d\r", vls, vsp); if (unlikely(len > (ARRAY_SIZE(buf) - 1))) return -ENOMEM; dev_dbg(codec->dev, "%s: %s\n", __func__, buf); if (codec->hw_write(cx20442->control_data, buf, len) != len) return -EIO; return 0; }
static int cx20442_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) { u8 *reg_cache = codec->reg_cache; int vls, vsp, old, len; char buf[18]; if (reg >= codec->reg_cache_size) return -EINVAL; if (!codec->hw_write || !codec->control_data) return -EIO; old = reg_cache[reg]; reg_cache[reg] = value; vls = cx20442_pm_to_v253_vls(value); if (vls < 0) return vls; vsp = cx20442_pm_to_v253_vsp(value); if (vsp < 0) return vsp; if ((vls == V253_VLS_T) || (vls == cx20442_pm_to_v253_vls(old))) { if (vsp == cx20442_pm_to_v253_vsp(old)) return 0; len = snprintf(buf, ARRAY_SIZE(buf), "at+vsp=%d\r", vsp); } else if (vsp == cx20442_pm_to_v253_vsp(old)) len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d\r", vls); else len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d;+vsp=%d\r", vls, vsp); if (unlikely(len > (ARRAY_SIZE(buf) - 1))) return -ENOMEM; dev_dbg(codec->dev, "%s: %s\n", __func__, buf); if (codec->hw_write(codec->control_data, buf, len) != len) return -EIO; return 0; }