1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Load Analog Devices SigmaStudio firmware files
5 * Copyright 2009-2011 Analog Devices Inc.
8 #include <linux/export.h>
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <asm/unaligned.h>
16 static int sigmadsp_write_i2c(void *control_data
,
17 unsigned int addr
, const uint8_t data
[], size_t len
)
22 buf
= kzalloc(2 + len
, GFP_KERNEL
| GFP_DMA
);
26 put_unaligned_be16(addr
, buf
);
27 memcpy(buf
+ 2, data
, len
);
29 ret
= i2c_master_send(control_data
, buf
, len
+ 2);
39 static int sigmadsp_read_i2c(void *control_data
,
40 unsigned int addr
, uint8_t data
[], size_t len
)
42 struct i2c_client
*client
= control_data
;
43 struct i2c_msg msgs
[2];
47 put_unaligned_be16(addr
, buf
);
49 msgs
[0].addr
= client
->addr
;
50 msgs
[0].len
= sizeof(buf
);
54 msgs
[1].addr
= client
->addr
;
57 msgs
[1].flags
= I2C_M_RD
;
59 ret
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
62 else if (ret
!= ARRAY_SIZE(msgs
))
68 * devm_sigmadsp_init_i2c() - Initialize SigmaDSP instance
69 * @client: The parent I2C device
70 * @ops: The sigmadsp_ops to use for this instance
71 * @firmware_name: Name of the firmware file to load
73 * Allocates a SigmaDSP instance and loads the specified firmware file.
75 * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
77 struct sigmadsp
*devm_sigmadsp_init_i2c(struct i2c_client
*client
,
78 const struct sigmadsp_ops
*ops
, const char *firmware_name
)
80 struct sigmadsp
*sigmadsp
;
82 sigmadsp
= devm_sigmadsp_init(&client
->dev
, ops
, firmware_name
);
86 sigmadsp
->control_data
= client
;
87 sigmadsp
->write
= sigmadsp_write_i2c
;
88 sigmadsp
->read
= sigmadsp_read_i2c
;
92 EXPORT_SYMBOL_GPL(devm_sigmadsp_init_i2c
);
94 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
95 MODULE_DESCRIPTION("SigmaDSP I2C firmware loader");
96 MODULE_LICENSE("GPL");