37 #include <linux/module.h>
40 #include <linux/slab.h>
58 i1480_init(&i1480_usb->
i1480);
65 struct usb_device *usb_dev = interface_to_usbdev(iface);
70 usb_set_intfdata(iface, i1480_usb);
77 usb_set_intfdata(iface,
NULL);
85 void i1480_usb_destroy(
struct i1480_usb *i1480_usb)
114 struct i1480_usb *i1480_usb =
container_of(i1480,
struct i1480_usb, i1480);
124 memory_address, (memory_address >> 16),
125 i1480->
cmd_buf, buffer_size, 100 );
150 int i1480_usb_read(
struct i1480 *i1480,
u32 addr,
size_t size)
154 struct i1480_usb *i1480_usb =
container_of(i1480,
struct i1480_usb, i1480);
160 if (addr >= 0x8000d200 && addr < 0x8000d400)
164 size_t itr_addr = addr + itr;
165 size_t itr_size =
min(read_size, size - itr);
169 itr_addr, (itr_addr >> 16),
170 i1480->
cmd_buf + itr, itr_size,
173 dev_err(i1480->
dev,
"%s: USB read error: %zd\n",
177 if (result != itr_size) {
180 "%s: partial read got only %zu bytes vs %zu expected\n",
181 __func__, result, itr_size);
198 void i1480_usb_neep_cb(
struct urb *
urb)
200 struct i1480 *i1480 = urb->context;
203 switch (urb->status) {
208 dev_dbg(dev,
"NEEP: reset/noent %d\n", urb->status);
211 dev_dbg(dev,
"NEEP: down %d\n", urb->status);
214 dev_err(dev,
"NEEP: unknown status %d\n", urb->status);
236 int i1480_usb_wait_init_done(
struct i1480 *i1480)
240 struct i1480_usb *i1480_usb =
container_of(i1480,
struct i1480_usb, i1480);
245 epd = &i1480_usb->
usb_iface->cur_altsetting->endpoint[0].desc;
249 i1480_usb_neep_cb, i1480, epd->
bInterval);
252 dev_err(dev,
"init done: cannot submit NEEP read: %d\n",
291 int i1480_usb_cmd(
struct i1480 *i1480,
const char *cmd_name,
size_t cmd_size)
295 struct i1480_usb *i1480_usb =
container_of(i1480,
struct i1480_usb, i1480);
301 iface_no = i1480_usb->
usb_iface->cur_altsetting->desc.bInterfaceNumber;
302 epd = &i1480_usb->
usb_iface->cur_altsetting->endpoint[0].desc;
307 i1480_usb_neep_cb, i1480, epd->
bInterval);
310 dev_err(dev,
"%s: cannot submit NEEP read: %d\n",
312 goto error_submit_ep1;
323 dev_err(dev,
"%s: control request failed: %d\n",
325 goto error_submit_ep0;
344 struct i1480_usb *i1480_usb;
346 struct device *dev = &iface->dev;
350 if (iface->cur_altsetting->desc.bInterfaceNumber != 0) {
351 dev_dbg(dev,
"not attaching to iface %d\n",
352 iface->cur_altsetting->desc.bInterfaceNumber);
355 if (iface->num_altsetting > 1
356 && interface_to_usbdev(iface)->
descriptor.idProduct == 0xbabe) {
361 "can't set altsetting 1 on iface 0: %d\n",
366 i1480_usb = kzalloc(
sizeof(*i1480_usb),
GFP_KERNEL);
367 if (i1480_usb ==
NULL) {
368 dev_err(dev,
"Unable to allocate instance\n");
371 i1480_usb_init(i1480_usb);
373 i1480 = &i1480_usb->
i1480;
377 dev_err(dev,
"Cannot allocate transfer buffers\n");
379 goto error_buf_alloc;
383 result = i1480_usb_create(i1480_usb, iface);
385 dev_err(dev,
"Cannot create instance: %d\n", result);
394 i1480->
dev = &iface->dev;
395 i1480->
write = i1480_usb_write;
396 i1480->
read = i1480_usb_read;
399 i1480->
cmd = i1480_usb_cmd;
406 i1480_usb_destroy(i1480_usb);
419 #define i1480_USB_DEV(v, p) \
421 .match_flags = USB_DEVICE_ID_MATCH_DEVICE \
422 | USB_DEVICE_ID_MATCH_DEV_INFO \
423 | USB_DEVICE_ID_MATCH_INT_INFO, \
426 .bDeviceClass = 0xff, \
427 .bDeviceSubClass = 0xff, \
428 .bDeviceProtocol = 0xff, \
429 .bInterfaceClass = 0xff, \
430 .bInterfaceSubClass = 0xff, \
431 .bInterfaceProtocol = 0xff, \
447 static struct usb_driver i1480_dfu_driver = {
448 .name =
"i1480-dfu-usb",
449 .id_table = i1480_usb_id_table,
450 .probe = i1480_usb_probe,