Skip to content

Commit 2971c57

Browse files
dwmw2David Woodhouse
authored andcommitted
keyspan: use request_firmware()
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent 0a2a736 commit 2971c57

29 files changed

Lines changed: 1712 additions & 5078 deletions

‎drivers/usb/serial/Kconfig‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,79 +304,79 @@ config USB_SERIAL_KEYSPAN
304304

305305
config USB_SERIAL_KEYSPAN_MPR
306306
bool "USB Keyspan MPR Firmware"
307-
depends on USB_SERIAL_KEYSPAN
307+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
308308
help
309309
Say Y here to include firmware for the Keyspan MPR converter.
310310

311311
config USB_SERIAL_KEYSPAN_USA28
312312
bool "USB Keyspan USA-28 Firmware"
313-
depends on USB_SERIAL_KEYSPAN
313+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
314314
help
315315
Say Y here to include firmware for the USA-28 converter.
316316

317317
config USB_SERIAL_KEYSPAN_USA28X
318318
bool "USB Keyspan USA-28X Firmware"
319-
depends on USB_SERIAL_KEYSPAN
319+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
320320
help
321321
Say Y here to include firmware for the USA-28X converter.
322322
Be sure you have a USA-28X, there are also 28XA and 28XB
323323
models, the label underneath has the actual part number.
324324

325325
config USB_SERIAL_KEYSPAN_USA28XA
326326
bool "USB Keyspan USA-28XA Firmware"
327-
depends on USB_SERIAL_KEYSPAN
327+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
328328
help
329329
Say Y here to include firmware for the USA-28XA converter.
330330
Be sure you have a USA-28XA, there are also 28X and 28XB
331331
models, the label underneath has the actual part number.
332332

333333
config USB_SERIAL_KEYSPAN_USA28XB
334334
bool "USB Keyspan USA-28XB Firmware"
335-
depends on USB_SERIAL_KEYSPAN
335+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
336336
help
337337
Say Y here to include firmware for the USA-28XB converter.
338338
Be sure you have a USA-28XB, there are also 28X and 28XA
339339
models, the label underneath has the actual part number.
340340

341341
config USB_SERIAL_KEYSPAN_USA19
342342
bool "USB Keyspan USA-19 Firmware"
343-
depends on USB_SERIAL_KEYSPAN
343+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
344344
help
345345
Say Y here to include firmware for the USA-19 converter.
346346

347347
config USB_SERIAL_KEYSPAN_USA18X
348348
bool "USB Keyspan USA-18X Firmware"
349-
depends on USB_SERIAL_KEYSPAN
349+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
350350
help
351351
Say Y here to include firmware for the USA-18X converter.
352352

353353
config USB_SERIAL_KEYSPAN_USA19W
354354
bool "USB Keyspan USA-19W Firmware"
355-
depends on USB_SERIAL_KEYSPAN
355+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
356356
help
357357
Say Y here to include firmware for the USA-19W converter.
358358

359359
config USB_SERIAL_KEYSPAN_USA19QW
360360
bool "USB Keyspan USA-19QW Firmware"
361-
depends on USB_SERIAL_KEYSPAN
361+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
362362
help
363363
Say Y here to include firmware for the USA-19QW converter.
364364

365365
config USB_SERIAL_KEYSPAN_USA19QI
366366
bool "USB Keyspan USA-19QI Firmware"
367-
depends on USB_SERIAL_KEYSPAN
367+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
368368
help
369369
Say Y here to include firmware for the USA-19QI converter.
370370

371371
config USB_SERIAL_KEYSPAN_USA49W
372372
bool "USB Keyspan USA-49W Firmware"
373-
depends on USB_SERIAL_KEYSPAN
373+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
374374
help
375375
Say Y here to include firmware for the USA-49W converter.
376376

377377
config USB_SERIAL_KEYSPAN_USA49WLC
378378
bool "USB Keyspan USA-49WLC Firmware"
379-
depends on USB_SERIAL_KEYSPAN
379+
depends on USB_SERIAL_KEYSPAN && FIRMWARE_IN_KERNEL
380380
help
381381
Say Y here to include firmware for the USA-49WLC converter.
382382

‎drivers/usb/serial/keyspan.c‎

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
#include <linux/tty_flip.h>
106106
#include <linux/module.h>
107107
#include <linux/spinlock.h>
108+
#include <linux/firmware.h>
109+
#include <linux/ihex.h>
108110
#include <asm/uaccess.h>
109111
#include <linux/usb.h>
110112
#include <linux/usb/serial.h>
@@ -1339,13 +1341,13 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
13391341
port->tty = NULL;
13401342
}
13411343

1342-
13431344
/* download the firmware to a pre-renumeration device */
13441345
static int keyspan_fake_startup (struct usb_serial *serial)
13451346
{
13461347
int response;
1347-
const struct ezusb_hex_record *record;
1348+
const struct ihex_binrec *record;
13481349
char *fw_name;
1350+
const struct firmware *fw;
13491351

13501352
dbg("Keyspan startup version %04x product %04x",
13511353
le16_to_cpu(serial->dev->descriptor.bcdDevice),
@@ -1359,72 +1361,60 @@ static int keyspan_fake_startup (struct usb_serial *serial)
13591361
/* Select firmware image on the basis of idProduct */
13601362
switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
13611363
case keyspan_usa28_pre_product_id:
1362-
record = &keyspan_usa28_firmware[0];
1363-
fw_name = "USA28";
1364+
fw_name = "keyspan/usa28.fw";
13641365
break;
13651366

13661367
case keyspan_usa28x_pre_product_id:
1367-
record = &keyspan_usa28x_firmware[0];
1368-
fw_name = "USA28X";
1368+
fw_name = "keyspan/usa28x.fw";
13691369
break;
13701370

13711371
case keyspan_usa28xa_pre_product_id:
1372-
record = &keyspan_usa28xa_firmware[0];
1373-
fw_name = "USA28XA";
1372+
fw_name = "keyspan/usa28xa.fw";
13741373
break;
13751374

13761375
case keyspan_usa28xb_pre_product_id:
1377-
record = &keyspan_usa28xb_firmware[0];
1378-
fw_name = "USA28XB";
1376+
fw_name = "keyspan/usa28xb.fw";
13791377
break;
13801378

13811379
case keyspan_usa19_pre_product_id:
1382-
record = &keyspan_usa19_firmware[0];
1383-
fw_name = "USA19";
1380+
fw_name = "keyspan/usa19.fw";
13841381
break;
13851382

13861383
case keyspan_usa19qi_pre_product_id:
1387-
record = &keyspan_usa19qi_firmware[0];
1388-
fw_name = "USA19QI";
1384+
fw_name = "keyspan/usa19qi.fw";
13891385
break;
13901386

13911387
case keyspan_mpr_pre_product_id:
1392-
record = &keyspan_mpr_firmware[0];
1393-
fw_name = "MPR";
1388+
fw_name = "keyspan/mpr.fw";
13941389
break;
13951390

13961391
case keyspan_usa19qw_pre_product_id:
1397-
record = &keyspan_usa19qw_firmware[0];
1398-
fw_name = "USA19QI";
1392+
fw_name = "keyspan/usa19qw.fw";
13991393
break;
14001394

14011395
case keyspan_usa18x_pre_product_id:
1402-
record = &keyspan_usa18x_firmware[0];
1403-
fw_name = "USA18X";
1396+
fw_name = "keyspan/usa18x.fw";
14041397
break;
14051398

14061399
case keyspan_usa19w_pre_product_id:
1407-
record = &keyspan_usa19w_firmware[0];
1408-
fw_name = "USA19W";
1400+
fw_name = "keyspan/usa19w.fw";
14091401
break;
14101402

14111403
case keyspan_usa49w_pre_product_id:
1412-
record = &keyspan_usa49w_firmware[0];
1413-
fw_name = "USA49W";
1404+
fw_name = "keyspan/usa49w.fw";
14141405
break;
14151406

14161407
case keyspan_usa49wlc_pre_product_id:
1417-
record = &keyspan_usa49wlc_firmware[0];
1418-
fw_name = "USA49WLC";
1408+
fw_name = "keyspan/usa49wlc.fw";
14191409
break;
14201410

14211411
default:
1422-
record = NULL;
1423-
fw_name = "Unknown";
1424-
break;
1412+
dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1413+
le16_to_cpu(serial->dev->descriptor.idProduct));
1414+
return 1;
14251415
}
14261416

1427-
if (record == NULL) {
1417+
if (request_ihex_firmware(&fw, fw_name, &serial->dev->dev)) {
14281418
dev_err(&serial->dev->dev, "Required keyspan firmware image (%s) unavailable.\n", fw_name);
14291419
return(1);
14301420
}
@@ -1434,19 +1424,22 @@ static int keyspan_fake_startup (struct usb_serial *serial)
14341424
/* download the firmware image */
14351425
response = ezusb_set_reset(serial, 1);
14361426

1437-
while(record->address != 0xffff) {
1438-
response = ezusb_writememory(serial, record->address,
1427+
record = (const struct ihex_binrec *)fw->data;
1428+
1429+
while (record) {
1430+
response = ezusb_writememory(serial, be32_to_cpu(record->addr),
14391431
(unsigned char *)record->data,
1440-
record->data_size, 0xa0);
1432+
be16_to_cpu(record->len), 0xa0);
14411433
if (response < 0) {
14421434
dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan"
14431435
"firmware (%d %04X %p %d)\n",
1444-
response,
1445-
record->address, record->data, record->data_size);
1436+
response, be32_to_cpu(record->addr),
1437+
record->data, be16_to_cpu(record->len));
14461438
break;
14471439
}
1448-
record++;
1440+
record = ihex_next_binrec(record);
14491441
}
1442+
release_firmware(fw);
14501443
/* bring device out of reset. Renumeration will occur in a
14511444
moment and the new device will bind to the real driver */
14521445
response = ezusb_set_reset(serial, 0);
@@ -2756,6 +2749,19 @@ MODULE_AUTHOR( DRIVER_AUTHOR );
27562749
MODULE_DESCRIPTION( DRIVER_DESC );
27572750
MODULE_LICENSE("GPL");
27582751

2752+
MODULE_FIRMWARE("keyspan/usa28.fw");
2753+
MODULE_FIRMWARE("keyspan/usa28x.fw");
2754+
MODULE_FIRMWARE("keyspan/usa28xa.fw");
2755+
MODULE_FIRMWARE("keyspan/usa28xb.fw");
2756+
MODULE_FIRMWARE("keyspan/usa19.fw");
2757+
MODULE_FIRMWARE("keyspan/usa19qi.fw");
2758+
MODULE_FIRMWARE("keyspan/mpr.fw");
2759+
MODULE_FIRMWARE("keyspan/usa19qw.fw");
2760+
MODULE_FIRMWARE("keyspan/usa18x.fw");
2761+
MODULE_FIRMWARE("keyspan/usa19w.fw");
2762+
MODULE_FIRMWARE("keyspan/usa49w.fw");
2763+
MODULE_FIRMWARE("keyspan/usa49wlc.fw");
2764+
27592765
module_param(debug, bool, S_IRUGO | S_IWUSR);
27602766
MODULE_PARM_DESC(debug, "Debug enabled or not");
27612767

‎drivers/usb/serial/keyspan.h‎

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -103,90 +103,6 @@ static int keyspan_usa67_send_setup (struct usb_serial *serial,
103103
struct usb_serial_port *port,
104104
int reset_port);
105105

106-
/* Struct used for firmware - increased size of data section
107-
to allow Keyspan's 'C' firmware struct to be used unmodified */
108-
struct ezusb_hex_record {
109-
__u16 address;
110-
__u8 data_size;
111-
__u8 data[64];
112-
};
113-
114-
/* Conditionally include firmware images, if they aren't
115-
included create a null pointer instead. Current
116-
firmware images aren't optimised to remove duplicate
117-
addresses in the image itself. */
118-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA28
119-
#include "keyspan_usa28_fw.h"
120-
#else
121-
static const struct ezusb_hex_record *keyspan_usa28_firmware = NULL;
122-
#endif
123-
124-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA28X
125-
#include "keyspan_usa28x_fw.h"
126-
#else
127-
static const struct ezusb_hex_record *keyspan_usa28x_firmware = NULL;
128-
#endif
129-
130-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA28XA
131-
#include "keyspan_usa28xa_fw.h"
132-
#else
133-
static const struct ezusb_hex_record *keyspan_usa28xa_firmware = NULL;
134-
#endif
135-
136-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA28XB
137-
#include "keyspan_usa28xb_fw.h"
138-
#else
139-
static const struct ezusb_hex_record *keyspan_usa28xb_firmware = NULL;
140-
#endif
141-
142-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA19
143-
#include "keyspan_usa19_fw.h"
144-
#else
145-
static const struct ezusb_hex_record *keyspan_usa19_firmware = NULL;
146-
#endif
147-
148-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA19QI
149-
#include "keyspan_usa19qi_fw.h"
150-
#else
151-
static const struct ezusb_hex_record *keyspan_usa19qi_firmware = NULL;
152-
#endif
153-
154-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_MPR
155-
#include "keyspan_mpr_fw.h"
156-
#else
157-
static const struct ezusb_hex_record *keyspan_mpr_firmware = NULL;
158-
#endif
159-
160-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA19QW
161-
#include "keyspan_usa19qw_fw.h"
162-
#else
163-
static const struct ezusb_hex_record *keyspan_usa19qw_firmware = NULL;
164-
#endif
165-
166-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA18X
167-
#include "keyspan_usa18x_fw.h"
168-
#else
169-
static const struct ezusb_hex_record *keyspan_usa18x_firmware = NULL;
170-
#endif
171-
172-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA19W
173-
#include "keyspan_usa19w_fw.h"
174-
#else
175-
static const struct ezusb_hex_record *keyspan_usa19w_firmware = NULL;
176-
#endif
177-
178-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA49W
179-
#include "keyspan_usa49w_fw.h"
180-
#else
181-
static const struct ezusb_hex_record *keyspan_usa49w_firmware = NULL;
182-
#endif
183-
184-
#ifdef CONFIG_USB_SERIAL_KEYSPAN_USA49WLC
185-
#include "keyspan_usa49wlc_fw.h"
186-
#else
187-
static const struct ezusb_hex_record *keyspan_usa49wlc_firmware = NULL;
188-
#endif
189-
190106
/* Values used for baud rate calculation - device specific */
191107
#define KEYSPAN_INVALID_BAUD_RATE (-1)
192108
#define KEYSPAN_BAUD_RATE_OK (0)

0 commit comments

Comments
 (0)