12 #include <linux/kernel.h>
13 #include <linux/i2c.h>
15 #include <linux/module.h>
19 #define SIGMA_MAGIC "ADISIGM"
67 payload = sigma_action_len(sa);
73 payload =
ALIGN(payload, 2);
85 size_t len = sigma_action_len(sa);
88 pr_debug(
"%s: instr:%i addr:%#x len:%zu\n", __func__,
119 while (ssfw->
pos +
sizeof(*sa) <= ssfw->
fw->size) {
122 size = sigma_action_size(sa);
124 if (ssfw->
pos > ssfw->
fw->size || size == 0)
127 ret = process_sigma_action(ssfw, sa);
129 pr_debug(
"%s: action returned %i\n", __func__, ret);
135 if (ssfw->
pos != ssfw->
fw->size)
141 static int _process_sigma_firmware(
struct device *
dev,
149 pr_debug(
"%s: loading firmware %s\n", __func__, name);
154 pr_debug(
"%s: request_firmware() failed with %i\n", __func__, ret);
168 if (fw->
size <
sizeof(*ssfw_head) || fw->
size >= 0x4000000) {
169 dev_err(dev,
"Failed to load firmware: Invalid size\n");
173 ssfw_head = (
void *)fw->
data;
175 dev_err(dev,
"Failed to load firmware: Invalid magic\n");
179 crc =
crc32(0, fw->
data +
sizeof(*ssfw_head),
180 fw->
size -
sizeof(*ssfw_head));
181 pr_debug(
"%s: crc=%x\n", __func__, crc);
183 dev_err(dev,
"Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
188 ssfw->
pos =
sizeof(*ssfw_head);
191 ret = process_sigma_actions(ssfw);
196 pr_debug(
"%s: loaded %s\n", __func__, name);
201 #if IS_ENABLED(CONFIG_I2C)
203 static int sigma_action_write_i2c(
void *control_data,
215 ssfw.
write = sigma_action_write_i2c;
217 return _process_sigma_firmware(&client->
dev, &ssfw, name);
223 #if IS_ENABLED(CONFIG_REGMAP)
225 static int sigma_action_write_regmap(
void *control_data,
238 ssfw.
write = sigma_action_write_regmap;
240 return _process_sigma_firmware(dev, &ssfw, name);