[PATCH v2] ASoC: cros_ec_codec: Reset I2S RX when probing

From: Yu-Hsuan Hsu
Date: Thu Jul 16 2020 - 13:09:27 EST


It is not guaranteed that I2S RX is disabled when the kernel booting.
For example, if the kernel crashes while it is enabled, it will keep
enabled until the next time EC reboots. Reset I2S RX when probing to
fix this issue.

Signed-off-by: Yu-Hsuan Hsu <yuhsuan@xxxxxxxxxxxx>
---
drivers/platform/chrome/cros_ec_proto.c | 7 ++++++-
include/linux/platform_data/cros_ec_commands.h | 1 +
sound/soc/codecs/cros_ec_codec.c | 9 +++++++++
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 3e745e0fe092c..2c60690d7147c 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -572,7 +572,12 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
return -ENOTSUPP;
} else if (msg->result != EC_RES_SUCCESS) {
dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
- return -EPROTO;
+ switch (msg->result) {
+ case EC_RES_INVALID_PARAM:
+ return -EINVAL;
+ default:
+ return -EPROTO;
+ }
}

return ret;
diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
index 69210881ebac8..11ce917ca924c 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -4598,6 +4598,7 @@ enum ec_codec_i2s_rx_subcmd {
EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
EC_CODEC_I2S_RX_SET_BCLK = 0x4,
+ EC_CODEC_I2S_RX_RESET = 0x5,
EC_CODEC_I2S_RX_SUBCMD_COUNT,
};

diff --git a/sound/soc/codecs/cros_ec_codec.c b/sound/soc/codecs/cros_ec_codec.c
index f23956cf4ed84..b5ff30b7f1aa8 100644
--- a/sound/soc/codecs/cros_ec_codec.c
+++ b/sound/soc/codecs/cros_ec_codec.c
@@ -1034,6 +1034,15 @@ static int cros_ec_codec_platform_probe(struct platform_device *pdev)
}
priv->ec_capabilities = r.capabilities;

+ /* Reset EC codec I2S RX. */
+ p.cmd = EC_CODEC_I2S_RX_RESET;
+ ret = send_ec_host_command(priv->ec_device, EC_CMD_EC_CODEC_I2S_RX,
+ (uint8_t *)&p, sizeof(p), NULL, 0);
+ if (ret == -EINVAL)
+ dev_info(dev, "Missing reset command. Please update your EC firmware.\n");
+ else if (ret)
+ dev_err(dev, "failed to EC_CODEC_I2S_RESET: %d\n", ret);
+
platform_set_drvdata(pdev, priv);

ret = devm_snd_soc_register_component(dev, &i2s_rx_component_driver,
--
2.27.0.389.gc38d7665816-goog