summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/sigmadsp-i2c.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2014-11-19 20:29:05 +0300
committerMark Brown <broonie@kernel.org>2014-11-20 12:55:34 +0300
commitd48b088e3ec45eeccf0fce0b75378e41428f47e9 (patch)
tree2a81e6d82c6aeeaf35620938f4079d290748b4bf /sound/soc/codecs/sigmadsp-i2c.c
parent6b25730f68073ee95079d241ea6aa7be00805254 (diff)
downloadlinux-d48b088e3ec45eeccf0fce0b75378e41428f47e9.tar.xz
ASoC: sigmadsp: Restructure in preparation for fw v2 support
The v2 file format of the SigmaDSP takes a more declarative style compared to the imperative style of the v1 format. In addition some features that are supported with v2 require the driver to keep state around for the firmware. This requires a bit of restructuring of both the firmware loader itself and the drivers making use of the firmware loader. Instead of loading and executing the firmware in place when the DSP is configured the firmware is now loaded at driver probe time. This is required since the new firmware format will in addition to the firmware data itself contain meta information describing the firmware and its requirements and capabilities. Those will for example be used to restrict the supported samplerates advertised by the driver to userspace to the list of samplerates supported for the firmware. This only does the restructuring required by the v2 format, but does not yet add support for the new format itself. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/codecs/sigmadsp-i2c.c')
-rw-r--r--sound/soc/codecs/sigmadsp-i2c.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/sound/soc/codecs/sigmadsp-i2c.c b/sound/soc/codecs/sigmadsp-i2c.c
index 246081aae8ca..bf6a2be72692 100644
--- a/sound/soc/codecs/sigmadsp-i2c.c
+++ b/sound/soc/codecs/sigmadsp-i2c.c
@@ -6,29 +6,59 @@
* Licensed under the GPL-2 or later.
*/
-#include <linux/i2c.h>
#include <linux/export.h>
+#include <linux/i2c.h>
#include <linux/module.h>
+#include <linux/slab.h>
+#include <asm/unaligned.h>
#include "sigmadsp.h"
-static int sigma_action_write_i2c(void *control_data,
- const struct sigma_action *sa, size_t len)
+static int sigmadsp_write_i2c(void *control_data,
+ unsigned int addr, const uint8_t data[], size_t len)
{
- return i2c_master_send(control_data, (const unsigned char *)&sa->addr,
- len);
+ uint8_t *buf;
+ int ret;
+
+ buf = kzalloc(2 + len, GFP_KERNEL | GFP_DMA);
+ if (!buf)
+ return -ENOMEM;
+
+ put_unaligned_be16(addr, buf);
+ memcpy(buf + 2, data, len);
+
+ ret = i2c_master_send(control_data, buf, len + 2);
+
+ kfree(buf);
+
+ return ret;
}
-int process_sigma_firmware(struct i2c_client *client, const char *name)
+/**
+ * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance
+ * @client: The parent I2C device
+ * @ops: The sigmadsp_ops to use for this instance
+ * @firmware_name: Name of the firmware file to load
+ *
+ * Allocates a SigmaDSP instance and loads the specified firmware file.
+ *
+ * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
+ */
+struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client,
+ const struct sigmadsp_ops *ops, const char *firmware_name)
{
- struct sigma_firmware ssfw;
+ struct sigmadsp *sigmadsp;
+
+ sigmadsp = devm_sigmadsp_init(&client->dev, ops, firmware_name);
+ if (IS_ERR(sigmadsp))
+ return sigmadsp;
- ssfw.control_data = client;
- ssfw.write = sigma_action_write_i2c;
+ sigmadsp->control_data = client;
+ sigmadsp->write = sigmadsp_write_i2c;
- return _process_sigma_firmware(&client->dev, &ssfw, name);
+ return sigmadsp;
}
-EXPORT_SYMBOL(process_sigma_firmware);
+EXPORT_SYMBOL_GPL(devm_sigmadsp_init_i2c);
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
MODULE_DESCRIPTION("SigmaDSP I2C firmware loader");