180503b23SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
26b10998dSLars-Peter Clausen /*
36b10998dSLars-Peter Clausen * Load Analog Devices SigmaStudio firmware files
46b10998dSLars-Peter Clausen *
56b10998dSLars-Peter Clausen * Copyright 2009-2011 Analog Devices Inc.
66b10998dSLars-Peter Clausen */
76b10998dSLars-Peter Clausen
86b10998dSLars-Peter Clausen #include <linux/regmap.h>
96b10998dSLars-Peter Clausen #include <linux/export.h>
106b10998dSLars-Peter Clausen #include <linux/module.h>
116b10998dSLars-Peter Clausen
126b10998dSLars-Peter Clausen #include "sigmadsp.h"
136b10998dSLars-Peter Clausen
sigmadsp_write_regmap(void * control_data,unsigned int addr,const uint8_t data[],size_t len)14d48b088eSLars-Peter Clausen static int sigmadsp_write_regmap(void *control_data,
15d48b088eSLars-Peter Clausen unsigned int addr, const uint8_t data[], size_t len)
166b10998dSLars-Peter Clausen {
17d48b088eSLars-Peter Clausen return regmap_raw_write(control_data, addr,
18d48b088eSLars-Peter Clausen data, len);
196b10998dSLars-Peter Clausen }
206b10998dSLars-Peter Clausen
sigmadsp_read_regmap(void * control_data,unsigned int addr,uint8_t data[],size_t len)21a35daac7SLars-Peter Clausen static int sigmadsp_read_regmap(void *control_data,
22a35daac7SLars-Peter Clausen unsigned int addr, uint8_t data[], size_t len)
23a35daac7SLars-Peter Clausen {
24a35daac7SLars-Peter Clausen return regmap_raw_read(control_data, addr,
25a35daac7SLars-Peter Clausen data, len);
26a35daac7SLars-Peter Clausen }
27a35daac7SLars-Peter Clausen
28d48b088eSLars-Peter Clausen /**
29*5dd902d9SPierre-Louis Bossart * devm_sigmadsp_init_regmap() - Initialize SigmaDSP instance
30d48b088eSLars-Peter Clausen * @dev: The parent device
31d48b088eSLars-Peter Clausen * @regmap: Regmap instance to use
32d48b088eSLars-Peter Clausen * @ops: The sigmadsp_ops to use for this instance
33d48b088eSLars-Peter Clausen * @firmware_name: Name of the firmware file to load
34d48b088eSLars-Peter Clausen *
35d48b088eSLars-Peter Clausen * Allocates a SigmaDSP instance and loads the specified firmware file.
36d48b088eSLars-Peter Clausen *
37d48b088eSLars-Peter Clausen * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
38d48b088eSLars-Peter Clausen */
devm_sigmadsp_init_regmap(struct device * dev,struct regmap * regmap,const struct sigmadsp_ops * ops,const char * firmware_name)39d48b088eSLars-Peter Clausen struct sigmadsp *devm_sigmadsp_init_regmap(struct device *dev,
40d48b088eSLars-Peter Clausen struct regmap *regmap, const struct sigmadsp_ops *ops,
41d48b088eSLars-Peter Clausen const char *firmware_name)
426b10998dSLars-Peter Clausen {
43d48b088eSLars-Peter Clausen struct sigmadsp *sigmadsp;
446b10998dSLars-Peter Clausen
45d48b088eSLars-Peter Clausen sigmadsp = devm_sigmadsp_init(dev, ops, firmware_name);
46d48b088eSLars-Peter Clausen if (IS_ERR(sigmadsp))
47d48b088eSLars-Peter Clausen return sigmadsp;
486b10998dSLars-Peter Clausen
49d48b088eSLars-Peter Clausen sigmadsp->control_data = regmap;
50d48b088eSLars-Peter Clausen sigmadsp->write = sigmadsp_write_regmap;
51a35daac7SLars-Peter Clausen sigmadsp->read = sigmadsp_read_regmap;
52d48b088eSLars-Peter Clausen
53d48b088eSLars-Peter Clausen return sigmadsp;
546b10998dSLars-Peter Clausen }
55d48b088eSLars-Peter Clausen EXPORT_SYMBOL_GPL(devm_sigmadsp_init_regmap);
566b10998dSLars-Peter Clausen
576b10998dSLars-Peter Clausen MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
586b10998dSLars-Peter Clausen MODULE_DESCRIPTION("SigmaDSP regmap firmware loader");
596b10998dSLars-Peter Clausen MODULE_LICENSE("GPL");
60