From dd20a7868b291fd5fe6cfc8625f5eca733bf1b74 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Sun, 18 Jul 2010 16:31:42 +0200 Subject: [PATCH] Rename usbserial to usbserial_ftdi --- term/usbserial.c => bus/usb/serial/ftdi.c | 32 ++++++++++++++++++++--- bus/usb/usb.c | 3 ++- conf/i386-pc.rmk | 8 +++--- 3 files changed, 34 insertions(+), 9 deletions(-) rename term/usbserial.c => bus/usb/serial/ftdi.c (90%) diff --git a/term/usbserial.c b/bus/usb/serial/ftdi.c similarity index 90% rename from term/usbserial.c rename to bus/usb/serial/ftdi.c index b27df8ae2..c7a7554ee 100644 --- a/term/usbserial.c +++ b/bus/usb/serial/ftdi.c @@ -172,13 +172,22 @@ static struct grub_serial_driver grub_usbserial_driver = .put = usbserial_hw_put }; +static const struct +{ + grub_uint16_t vendor, product; +} products[] = + { + {0x0403, 0x6001} /* QEMU virtual USBserial. */ + }; + static int -grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno) +grub_ftdi_attach (grub_usb_device_t usbdev, int configno, int interfno) { static struct grub_serial_port *port; int j; - struct grub_usb_desc_if *interf - = usbdev->config[configno].interf[interfno].descif; + struct grub_usb_desc_if *interf; + + interf = usbdev->config[configno].interf[interfno].descif; port = grub_malloc (sizeof (*port)); if (!port) @@ -226,13 +235,28 @@ grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno) return 1; } +static int +grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno) +{ + unsigned j; + + for (j = 0; j < ARRAY_SIZE (products); j++) + if (usbdev->descdev.vendorid == products[j].vendor + && usbdev->descdev.prodid == products[j].product) + break; + if (j == ARRAY_SIZE (products)) + return 0; + + return grub_ftdi_attach (usbdev, configno, interfno); +} + struct grub_usb_attach_desc attach_hook = { .class = 0xff, .hook = grub_usbserial_attach }; -GRUB_MOD_INIT(usbserial) +GRUB_MOD_INIT(usbserial_ftdi) { grub_usb_register_attach_hook_class (&attach_hook); } diff --git a/bus/usb/usb.c b/bus/usb/usb.c index ba052e5ee..b49caacdb 100644 --- a/bus/usb/usb.c +++ b/bus/usb/usb.c @@ -270,7 +270,8 @@ void grub_usb_device_attach (grub_usb_device_t dev) grub_dl_load ("usb_keyboard"); break; case 0xff: - grub_dl_load ("usbserial"); + /* FIXME: don't load useless modules. */ + grub_dl_load ("usbserial_ftdi"); break; } } diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index e1cfe1468..2e95133f3 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -196,10 +196,10 @@ usb_mod_CFLAGS = $(COMMON_CFLAGS) usb_mod_LDFLAGS = $(COMMON_LDFLAGS) # For serial.mod. -pkglib_MODULES += usbserial.mod -usbserial_mod_SOURCES = term/usbserial.c -usbserial_mod_CFLAGS = $(COMMON_CFLAGS) -usbserial_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += usbserial_ftdi.mod +usbserial_ftdi_mod_SOURCES = bus/usb/serial/ftdi.c +usbserial_ftdi_mod_CFLAGS = $(COMMON_CFLAGS) +usbserial_ftdi_mod_LDFLAGS = $(COMMON_LDFLAGS) # For usbtest.mod usbtest_mod_SOURCES = commands/usbtest.c