linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support
@ 2012-08-03 15:06 René Bürgel
  2012-08-03 15:16 ` [PATCH 1/3]: ezusb: remove dependency to usb_serial interface René Bürgel
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: René Bürgel @ 2012-08-03 15:06 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-kernel

Hello,

this is a patches-series for controllers using the ezusb-functions.

ezusb:  remove dependency to usb_serial interface
euzsb: add support for Cypress FX2LP
ezusb: add functions for firmware download

-- 
René Bürgel

SOHARD Embedded Systems GmbH
Wuerzburger Str. 197
90766 Fuerth

Tel: +49 (0)911 97341-541
Fax: +49 (0)911 97341-510

Geschäftsführer: Sebastian Schnitzenbaumer, Peter Feltens
Sitz: Fürth; HRB 11482 beim Amtsgericht Fürth

USt-IdNr. DE 814982820
St-Nr. 218/137/60182
WEEE-Reg.Nr. DE 70097646

Webseite: http://www.sohard.de
Webshop: http://shop.sohard.de


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3]: ezusb: remove dependency to usb_serial interface
  2012-08-03 15:06 [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
@ 2012-08-03 15:16 ` René Bürgel
  2012-08-03 15:17 ` [PATCH 2/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: René Bürgel @ 2012-08-03 15:16 UTC (permalink / raw)
  To: linux-usb, linux-kernel

This patch removes the dependency on the usb_serial interface and names 
some magic constants

Signed-off-by: René Bürgel <rene.buergel@sohard.de>
--
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index 800e8eb..3048b52d 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -9,24 +9,24 @@
   */

  #include <linux/kernel.h>
-#include <linux/errno.h>
  #include <linux/init.h>
  #include <linux/slab.h>
-#include <linux/tty.h>
  #include <linux/module.h>
  #include <linux/usb.h>
-#include <linux/usb/serial.h>

  /* EZ-USB Control and Status Register.  Bit 0 controls 8051 reset */
  #define CPUCS_REG    0x7F92

-int ezusb_writememory(struct usb_serial *serial, int address,
+/* Command for writing to internal memory */
+#define WRITE_INT_RAM 0xA0
+
+int ezusb_writememory(struct usb_device *dev, int address,
                  unsigned char *data, int length, __u8 request)
  {
      int result;
      unsigned char *transfer_buffer;

-    if (!serial->dev) {
+    if (!dev) {
          printk(KERN_ERR "ezusb: %s - no physical device present, "
                 "failing.\n", __func__);
          return -ENODEV;
@@ -34,25 +34,25 @@ int ezusb_writememory(struct usb_serial *serial, int 
address,

      transfer_buffer = kmemdup(data, length, GFP_KERNEL);
      if (!transfer_buffer) {
-        dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n",
+        dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n",
                              __func__, length);
          return -ENOMEM;
      }
-    result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
-             request, 0x40, address, 0, transfer_buffer, length, 3000);
+    result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
+                 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                 address, 0, transfer_buffer, length, 3000);
+
      kfree(transfer_buffer);
      return result;
  }
  EXPORT_SYMBOL_GPL(ezusb_writememory);

-int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit)
+int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit)
  {
-    int response;
-
-    response = ezusb_writememory(serial, CPUCS_REG, &reset_bit, 1, 0xa0);
+    int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, 
WRITE_INT_RAM);
      if (response < 0)
-        dev_err(&serial->dev->dev, "%s- %d failed\n",
-                        __func__, reset_bit);
+        dev_err(&dev->dev, "%s-%d failed: %d\n",
+                        __func__, reset_bit, response);
      return response;
  }
  EXPORT_SYMBOL_GPL(ezusb_set_reset);
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index af0b70e..f0d4f3f 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1241,12 +1241,12 @@ static int keyspan_fake_startup(struct 
usb_serial *serial)
      dbg("Uploading Keyspan %s firmware.", fw_name);

          /* download the firmware image */
-    response = ezusb_set_reset(serial, 1);
+    response = ezusb_set_reset(serial->dev, 1);

      record = (const struct ihex_binrec *)fw->data;

      while (record) {
-        response = ezusb_writememory(serial, be32_to_cpu(record->addr),
+        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
                           (unsigned char *)record->data,
                           be16_to_cpu(record->len), 0xa0);
          if (response < 0) {
@@ -1260,7 +1260,7 @@ static int keyspan_fake_startup(struct usb_serial 
*serial)
      release_firmware(fw);
          /* bring device out of reset. Renumeration will occur in a
             moment and the new device will bind to the real driver */
-    response = ezusb_set_reset(serial, 0);
+    response = ezusb_set_reset(serial->dev, 0);

      /* we don't want this device to have a driver assigned to it. */
      return 1;
diff --git a/drivers/usb/serial/keyspan_pda.c 
b/drivers/usb/serial/keyspan_pda.c
index a4ac3cf..1290b6f 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -682,7 +682,7 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
      const struct firmware *fw;

      /* download the firmware here ... */
-    response = ezusb_set_reset(serial, 1);
+    response = ezusb_set_reset(serial->dev, 1);

      if (0) { ; }
  #ifdef KEYSPAN
@@ -707,7 +707,7 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
      record = (const struct ihex_binrec *)fw->data;

      while (record) {
-        response = ezusb_writememory(serial, be32_to_cpu(record->addr),
+        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
                           (unsigned char *)record->data,
                           be16_to_cpu(record->len), 0xa0);
          if (response < 0) {
@@ -722,7 +722,7 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
      release_firmware(fw);
      /* bring device out of reset. Renumeration will occur in a moment
         and the new device will bind to the real driver */
-    response = ezusb_set_reset(serial, 0);
+    response = ezusb_set_reset(serial->dev, 0);

      /* we want this device to fail to have a driver assigned to it. */
      return 1;
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 473635e..fc72591 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -213,13 +213,13 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          goto out;
      }
      ret = 0;
-    response = ezusb_set_reset (serial, 1);
+    response = ezusb_set_reset(serial->dev, 1);

      record = (const struct ihex_binrec *)loader_fw->data;
      while (record) {
-        response = ezusb_writememory (serial, be32_to_cpu(record->addr),
-                          (unsigned char *)record->data,
-                          be16_to_cpu(record->len), 0xa0);
+        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
+                         (unsigned char *)record->data,
+                         be16_to_cpu(record->len), 0xa0);
          if (response < 0) {
              dev_err(&serial->dev->dev, "%s - ezusb_writememory "
                  "failed for loader (%d %04X %p %d)\n",
@@ -230,15 +230,15 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          record = ihex_next_binrec(record);
      }

-    response = ezusb_set_reset(serial, 0);
+    response = ezusb_set_reset(serial->dev, 0);

      record = (const struct ihex_binrec *)firmware_fw->data;
      while (record && be32_to_cpu(record->addr) < 0x1b40)
          record = ihex_next_binrec(record);
      while (record) {
-        response = ezusb_writememory (serial, be32_to_cpu(record->addr),
-                          (unsigned char *)record->data,
-                          be16_to_cpu(record->len), 0xa3);
+        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
+                         (unsigned char *)record->data,
+                         be16_to_cpu(record->len), 0xa3);
          if (response < 0) {
              dev_err(&serial->dev->dev, "%s - ezusb_writememory "
                  "failed for first firmware step "
@@ -250,13 +250,13 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          ++record;
      }

-    response = ezusb_set_reset(serial, 1);
+    response = ezusb_set_reset(serial->dev, 1);

      record = (const struct ihex_binrec *)firmware_fw->data;
      while (record && be32_to_cpu(record->addr) < 0x1b40) {
-        response = ezusb_writememory (serial, be32_to_cpu(record->addr),
-                          (unsigned char *)record->data,
-                          be16_to_cpu(record->len), 0xa0);
+        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
+                         (unsigned char *)record->data,
+                         be16_to_cpu(record->len), 0xa0);
          if (response < 0) {
              dev_err(&serial->dev->dev, "%s - ezusb_writememory "
                  "failed for second firmware step "
@@ -268,7 +268,7 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          ++record;
      }
      ret = 0;
-    response = ezusb_set_reset (serial, 0);
+    response = ezusb_set_reset(serial->dev, 0);
   out:
      release_firmware(loader_fw);
      release_firmware(firmware_fw);
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 86c0b45..a101507 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -301,9 +301,9 @@ extern void usb_serial_port_softint(struct 
usb_serial_port *port);
  extern int usb_serial_suspend(struct usb_interface *intf, pm_message_t 
message);
  extern int usb_serial_resume(struct usb_interface *intf);

-extern int ezusb_writememory(struct usb_serial *serial, int address,
+extern int ezusb_writememory(struct usb_device *dev, int address,
                   unsigned char *data, int length, __u8 bRequest);
-extern int ezusb_set_reset(struct usb_serial *serial, unsigned char 
reset_bit);
+extern int ezusb_set_reset(struct usb_device *dev, unsigned char 
reset_bit);

  /* USB Serial console functions */
  #ifdef CONFIG_USB_SERIAL_CONSOLE


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-03 15:06 [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
  2012-08-03 15:16 ` [PATCH 1/3]: ezusb: remove dependency to usb_serial interface René Bürgel
@ 2012-08-03 15:17 ` René Bürgel
  2012-08-03 15:18 ` [PATCH 3/3]: " René Bürgel
  2012-08-15 22:20 ` [PATCH 0/3]: " Greg KH
  3 siblings, 0 replies; 9+ messages in thread
From: René Bürgel @ 2012-08-03 15:17 UTC (permalink / raw)
  To: linux-usb, linux-kernel

This Patch adds support for the newer Cypress FX2LP. It also adapts 
three drivers currently using ezusb to the interface change. (whiteheat 
and keyspan[_pda])

Signed-off-by: René Bürgel <rene.buergel@sohard.de>
--
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index 3048b52d..351988d 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -14,11 +14,25 @@
  #include <linux/module.h>
  #include <linux/usb.h>

-/* EZ-USB Control and Status Register.  Bit 0 controls 8051 reset */
-#define CPUCS_REG    0x7F92
+struct ezusb_fx_type {
+    /* EZ-USB Control and Status Register.  Bit 0 controls 8051 reset */
+    unsigned short cpucs_reg;
+    unsigned short max_internal_adress;
+};

-/* Command for writing to internal memory */
+struct ezusb_fx_type ezusb_fx1 = {
+    .cpucs_reg = 0x7F92,
+    .max_internal_adress = 0x1B3F,
+};
+
+struct ezusb_fx_type ezusb_fx2 = {
+    .cpucs_reg = 0xE600,
+    .max_internal_adress = 0x3FFF,
+};
+
+/* Commands for writing to memory */
  #define WRITE_INT_RAM 0xA0
+#define WRITE_EXT_RAM 0xA3

  int ezusb_writememory(struct usb_device *dev, int address,
                  unsigned char *data, int length, __u8 request)
@@ -47,13 +61,24 @@ int ezusb_writememory(struct usb_device *dev, int 
address,
  }
  EXPORT_SYMBOL_GPL(ezusb_writememory);

-int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit)
+int ezusb_set_reset(struct usb_device *dev, unsigned short cpucs_reg,
+             unsigned char reset_bit)
  {
-    int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, 
WRITE_INT_RAM);
+    int response = ezusb_writememory(dev, cpucs_reg, &reset_bit, 1, 
WRITE_INT_RAM);
      if (response < 0)
          dev_err(&dev->dev, "%s-%d failed: %d\n",
                          __func__, reset_bit, response);
      return response;
  }
-EXPORT_SYMBOL_GPL(ezusb_set_reset);

+int ezusb_fx1_set_reset(struct usb_device *dev, unsigned char reset_bit)
+{
+    return ezusb_set_reset(dev, ezusb_fx1.cpucs_reg, reset_bit);
+}
+EXPORT_SYMBOL_GPL(ezusb_fx1_set_reset);
+
+int ezusb_fx2_set_reset(struct usb_device *dev, unsigned char reset_bit)
+{
+    return ezusb_set_reset(dev, ezusb_fx2.cpucs_reg, reset_bit);
+}
+EXPORT_SYMBOL_GPL(ezusb_fx2_set_reset);
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index f0d4f3f..32bebde 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -43,6 +43,7 @@
  #include <linux/uaccess.h>
  #include <linux/usb.h>
  #include <linux/usb/serial.h>
+#include <linux/usb/ezusb.h>
  #include "keyspan.h"

  static bool debug;
@@ -1241,7 +1242,7 @@ static int keyspan_fake_startup(struct usb_serial 
*serial)
      dbg("Uploading Keyspan %s firmware.", fw_name);

          /* download the firmware image */
-    response = ezusb_set_reset(serial->dev, 1);
+    response = ezusb_fx1_set_reset(serial->dev, 1);

      record = (const struct ihex_binrec *)fw->data;

@@ -1260,7 +1261,7 @@ static int keyspan_fake_startup(struct usb_serial 
*serial)
      release_firmware(fw);
          /* bring device out of reset. Renumeration will occur in a
             moment and the new device will bind to the real driver */
-    response = ezusb_set_reset(serial->dev, 0);
+    response = ezusb_fx1_set_reset(serial->dev, 0);

      /* we don't want this device to have a driver assigned to it. */
      return 1;
diff --git a/drivers/usb/serial/keyspan_pda.c 
b/drivers/usb/serial/keyspan_pda.c
index 1290b6f..87c5812 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -30,6 +30,7 @@
  #include <linux/uaccess.h>
  #include <linux/usb.h>
  #include <linux/usb/serial.h>
+#include <linux/usb/ezusb.h>

  static bool debug;

@@ -682,7 +683,7 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
      const struct firmware *fw;

      /* download the firmware here ... */
-    response = ezusb_set_reset(serial->dev, 1);
+    response = ezusb_fx1_set_reset(serial->dev, 1);

      if (0) { ; }
  #ifdef KEYSPAN
@@ -722,7 +723,7 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
      release_firmware(fw);
      /* bring device out of reset. Renumeration will occur in a moment
         and the new device will bind to the real driver */
-    response = ezusb_set_reset(serial->dev, 0);
+    response = ezusb_fx1_set_reset(serial->dev, 0);

      /* we want this device to fail to have a driver assigned to it. */
      return 1;
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index fc72591..228eb64 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -32,6 +32,7 @@
  #include <linux/serial_reg.h>
  #include <linux/serial.h>
  #include <linux/usb/serial.h>
+#include <linux/usb/ezusb.h>
  #include <linux/firmware.h>
  #include <linux/ihex.h>
  #include "whiteheat.h"            /* WhiteHEAT specific commands */
@@ -213,7 +214,7 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          goto out;
      }
      ret = 0;
-    response = ezusb_set_reset(serial->dev, 1);
+    response = ezusb_fx1_set_reset(serial->dev, 1);

      record = (const struct ihex_binrec *)loader_fw->data;
      while (record) {
@@ -230,7 +231,7 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          record = ihex_next_binrec(record);
      }

-    response = ezusb_set_reset(serial->dev, 0);
+    response = ezusb_fx1_set_reset(serial->dev, 0);

      record = (const struct ihex_binrec *)firmware_fw->data;
      while (record && be32_to_cpu(record->addr) < 0x1b40)
@@ -250,7 +251,7 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          ++record;
      }

-    response = ezusb_set_reset(serial->dev, 1);
+    response = ezusb_fx1_set_reset(serial->dev, 1);

      record = (const struct ihex_binrec *)firmware_fw->data;
      while (record && be32_to_cpu(record->addr) < 0x1b40) {
@@ -268,7 +269,7 @@ static int whiteheat_firmware_download(struct 
usb_serial *serial,
          ++record;
      }
      ret = 0;
-    response = ezusb_set_reset(serial->dev, 0);
+    response = ezusb_fx1_set_reset(serial->dev, 0);
   out:
      release_firmware(loader_fw);
      release_firmware(firmware_fw);
diff --git a/include/linux/usb/ezusb.h b/include/linux/usb/ezusb.h
new file mode 100644
index 0000000..fc618d8
--- /dev/null
+++ b/include/linux/usb/ezusb.h
@@ -0,0 +1,16 @@
+#ifndef __EZUSB_H
+#define __EZUSB_H
+
+
+extern int ezusb_writememory(struct usb_device *dev, int address,
+                 unsigned char *data, int length, __u8 bRequest);
+
+extern int ezusb_fx1_set_reset(struct usb_device *dev, unsigned char 
reset_bit);
+extern int ezusb_fx2_set_reset(struct usb_device *dev, unsigned char 
reset_bit);
+
+extern int ezusb_fx1_ihex_firmware_download(struct usb_device *dev,
+                        const char *firmware_path);
+extern int ezusb_fx2_ihex_firmware_download(struct usb_device *dev,
+                        const char *firmware_path);
+
+#endif /* __EZUSB_H */
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index a101507..588861c 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -301,10 +301,6 @@ extern void usb_serial_port_softint(struct 
usb_serial_port *port);
  extern int usb_serial_suspend(struct usb_interface *intf, pm_message_t 
message);
  extern int usb_serial_resume(struct usb_interface *intf);

-extern int ezusb_writememory(struct usb_device *dev, int address,
-                 unsigned char *data, int length, __u8 bRequest);
-extern int ezusb_set_reset(struct usb_device *dev, unsigned char 
reset_bit);
-
  /* USB Serial console functions */
  #ifdef CONFIG_USB_SERIAL_CONSOLE
  extern void usb_serial_console_init(int debug, int minor);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-03 15:06 [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
  2012-08-03 15:16 ` [PATCH 1/3]: ezusb: remove dependency to usb_serial interface René Bürgel
  2012-08-03 15:17 ` [PATCH 2/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
@ 2012-08-03 15:18 ` René Bürgel
  2012-08-15 22:20 ` [PATCH 0/3]: " Greg KH
  3 siblings, 0 replies; 9+ messages in thread
From: René Bürgel @ 2012-08-03 15:18 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-kernel

This patch adds new functions to upload firmware to the controller. The 
drivers currently using ezusb are adapted to use these new functions.

This also fixes a bug occuring during firmware loading in the 
whiteheat-driver:
The driver iterates over an ihex-formatted firmware using ++ on a "const 
struct ihex_binrec*" which leads to faulty results, because ihex data is 
read as length. The function "ihex_next_binrec(record)" has so be used 
to work correctly

Signed-off-by: René Bürgel <rene.buergel@sohard.de>
--
diff --git a/drivers/usb/serial/ezusb.c b/drivers/usb/serial/ezusb.c
index 351988d..867a3e1 100644
--- a/drivers/usb/serial/ezusb.c
+++ b/drivers/usb/serial/ezusb.c
@@ -13,6 +13,8 @@
  #include <linux/slab.h>
  #include <linux/module.h>
  #include <linux/usb.h>
+#include <linux/firmware.h>
+#include <linux/ihex.h>

  struct ezusb_fx_type {
      /* EZ-USB Control and Status Register.  Bit 0 controls 8051 reset */
@@ -82,3 +84,80 @@ int ezusb_fx2_set_reset(struct usb_device *dev, 
unsigned char reset_bit)
      return ezusb_set_reset(dev, ezusb_fx2.cpucs_reg, reset_bit);
  }
  EXPORT_SYMBOL_GPL(ezusb_fx2_set_reset);
+
+static int ezusb_ihex_firmware_download(struct usb_device *dev,
+                    struct ezusb_fx_type fx,
+                    const char *firmware_path)
+{
+    int ret = -ENOENT;
+    const struct firmware *firmware = NULL;
+    const struct ihex_binrec *record;
+
+    if (request_ihex_firmware(&firmware, firmware_path,
+                  &dev->dev)) {
+        dev_err(&dev->dev,
+            "%s - request \"%s\" failed\n",
+            __func__, firmware_path);
+        goto out;
+    }
+
+    ret = ezusb_set_reset(dev, fx.cpucs_reg, 0);
+    if (ret < 0)
+        goto out;
+
+    record = (const struct ihex_binrec *)firmware->data;
+    for (; record; record = ihex_next_binrec(record)) {
+        if (be32_to_cpu(record->addr) > fx.max_internal_adress) {
+            ret = ezusb_writememory(dev, be32_to_cpu(record->addr),
+                        (unsigned char *)record->data,
+                        be16_to_cpu(record->len), WRITE_EXT_RAM);
+            if (ret < 0) {
+                dev_err(&dev->dev, "%s - ezusb_writememory "
+                    "failed writing internal memory "
+                    "(%d %04X %p %d)\n", __func__, ret,
+                    be32_to_cpu(record->addr), record->data,
+                    be16_to_cpu(record->len));
+                goto out;
+            }
+        }
+    }
+
+    ret = ezusb_set_reset(dev, fx.cpucs_reg, 1);
+    if (ret < 0)
+        goto out;
+    record = (const struct ihex_binrec *)firmware->data;
+    for (; record; record = ihex_next_binrec(record)) {
+        if (be32_to_cpu(record->addr) <= fx.max_internal_adress) {
+            ret = ezusb_writememory(dev, be32_to_cpu(record->addr),
+                        (unsigned char *)record->data,
+                        be16_to_cpu(record->len), WRITE_INT_RAM);
+            if (ret < 0) {
+                dev_err(&dev->dev, "%s - ezusb_writememory "
+                    "failed writing external memory "
+                    "(%d %04X %p %d)\n", __func__, ret,
+                    be32_to_cpu(record->addr), record->data,
+                    be16_to_cpu(record->len));
+                goto out;
+            }
+        }
+    }
+    ret = ezusb_set_reset(dev, fx.cpucs_reg, 0);
+out:
+    release_firmware(firmware);
+    return ret;
+}
+
+int ezusb_fx1_ihex_firmware_download(struct usb_device *dev,
+                     const char *firmware_path)
+{
+    return ezusb_ihex_firmware_download(dev, ezusb_fx1, firmware_path);
+}
+EXPORT_SYMBOL_GPL(ezusb_fx1_ihex_firmware_download);
+
+int ezusb_fx2_ihex_firmware_download(struct usb_device *dev,
+                     const char *firmware_path)
+{
+    return ezusb_ihex_firmware_download(dev, ezusb_fx2, firmware_path);
+}
+EXPORT_SYMBOL_GPL(ezusb_fx2_ihex_firmware_download);
+
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 32bebde..523586d 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -38,8 +38,6 @@
  #include <linux/tty_flip.h>
  #include <linux/module.h>
  #include <linux/spinlock.h>
-#include <linux/firmware.h>
-#include <linux/ihex.h>
  #include <linux/uaccess.h>
  #include <linux/usb.h>
  #include <linux/usb/serial.h>
@@ -1163,10 +1161,7 @@ static void keyspan_close(struct usb_serial_port 
*port)
  /* download the firmware to a pre-renumeration device */
  static int keyspan_fake_startup(struct usb_serial *serial)
  {
-    int                 response;
-    const struct ihex_binrec     *record;
-    char                *fw_name;
-    const struct firmware        *fw;
+    char    *fw_name;

      dbg("Keyspan startup version %04x product %04x",
          le16_to_cpu(serial->dev->descriptor.bcdDevice),
@@ -1234,34 +1229,16 @@ static int keyspan_fake_startup(struct 
usb_serial *serial)
          return 1;
      }

-    if (request_ihex_firmware(&fw, fw_name, &serial->dev->dev)) {
-        dev_err(&serial->dev->dev, "Required keyspan firmware image 
(%s) unavailable.\n", fw_name);
-        return 1;
-    }
-
      dbg("Uploading Keyspan %s firmware.", fw_name);

-        /* download the firmware image */
-    response = ezusb_fx1_set_reset(serial->dev, 1);
-
-    record = (const struct ihex_binrec *)fw->data;
-
-    while (record) {
-        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
-                         (unsigned char *)record->data,
-                         be16_to_cpu(record->len), 0xa0);
-        if (response < 0) {
-            dev_err(&serial->dev->dev, "ezusb_writememory failed for 
Keyspan firmware (%d %04X %p %d)\n",
-                response, be32_to_cpu(record->addr),
-                record->data, be16_to_cpu(record->len));
-            break;
-        }
-        record = ihex_next_binrec(record);
+    if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
+        dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
+            fw_name);
+        return -ENOENT;
      }
-    release_firmware(fw);
-        /* bring device out of reset. Renumeration will occur in a
-           moment and the new device will bind to the real driver */
-    response = ezusb_fx1_set_reset(serial->dev, 0);
+
+    /* after downloading firmware Renumeration will occur in a
+      moment and the new device will bind to the real driver */

      /* we don't want this device to have a driver assigned to it. */
      return 1;
diff --git a/drivers/usb/serial/keyspan_pda.c 
b/drivers/usb/serial/keyspan_pda.c
index 87c5812..bf0bb37 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -25,8 +25,6 @@
  #include <linux/module.h>
  #include <linux/spinlock.h>
  #include <linux/workqueue.h>
-#include <linux/firmware.h>
-#include <linux/ihex.h>
  #include <linux/uaccess.h>
  #include <linux/usb.h>
  #include <linux/usb/serial.h>
@@ -679,8 +677,6 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
  {
      int response;
      const char *fw_name;
-    const struct ihex_binrec *record;
-    const struct firmware *fw;

      /* download the firmware here ... */
      response = ezusb_fx1_set_reset(serial->dev, 1);
@@ -700,30 +696,15 @@ static int keyspan_pda_fake_startup(struct 
usb_serial *serial)
              __func__);
          return -ENODEV;
      }
-    if (request_ihex_firmware(&fw, fw_name, &serial->dev->dev)) {
+
+    if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
          dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
              fw_name);
          return -ENOENT;
      }
-    record = (const struct ihex_binrec *)fw->data;
-
-    while (record) {
-        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
-                         (unsigned char *)record->data,
-                         be16_to_cpu(record->len), 0xa0);
-        if (response < 0) {
-            dev_err(&serial->dev->dev, "ezusb_writememory failed "
-                "for Keyspan PDA firmware (%d %04X %p %d)\n",
-                response, be32_to_cpu(record->addr),
-                record->data, be16_to_cpu(record->len));
-            break;
-        }
-        record = ihex_next_binrec(record);
-    }
-    release_firmware(fw);
-    /* bring device out of reset. Renumeration will occur in a moment
-       and the new device will bind to the real driver */
-    response = ezusb_fx1_set_reset(serial->dev, 0);
+
+    /* after downloading firmware Renumeration will occur in a
+      moment and the new device will bind to the real driver */

      /* we want this device to fail to have a driver assigned to it. */
      return 1;
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index b34665c..a9ad0c5 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -33,8 +33,6 @@
  #include <linux/serial.h>
  #include <linux/usb/serial.h>
  #include <linux/usb/ezusb.h>
-#include <linux/firmware.h>
-#include <linux/ihex.h>
  #include "whiteheat.h"            /* WhiteHEAT specific commands */

  static bool debug;
@@ -196,84 +194,15 @@ static int firm_report_tx_done(struct 
usb_serial_port *port);
  static int whiteheat_firmware_download(struct usb_serial *serial,
                      const struct usb_device_id *id)
  {
-    int response, ret = -ENOENT;
-    const struct firmware *loader_fw = NULL, *firmware_fw = NULL;
-    const struct ihex_binrec *record;
+    int response;

-    if (request_ihex_firmware(&firmware_fw, "whiteheat.fw",
-                  &serial->dev->dev)) {
-        dev_err(&serial->dev->dev,
-            "%s - request \"whiteheat.fw\" failed\n", __func__);
-        goto out;
-    }
-    if (request_ihex_firmware(&loader_fw, "whiteheat_loader.fw",
-                 &serial->dev->dev)) {
-        dev_err(&serial->dev->dev,
-            "%s - request \"whiteheat_loader.fw\" failed\n",
-            __func__);
-        goto out;
-    }
-    ret = 0;
-    response = ezusb_fx1_set_reset(serial->dev, 1);
-
-    record = (const struct ihex_binrec *)loader_fw->data;
-    while (record) {
-        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
-                         (unsigned char *)record->data,
-                         be16_to_cpu(record->len), 0xa0);
-        if (response < 0) {
-            dev_err(&serial->dev->dev, "%s - ezusb_writememory "
-                "failed for loader (%d %04X %p %d)\n",
-                __func__, response, be32_to_cpu(record->addr),
-                record->data, be16_to_cpu(record->len));
-            break;
-        }
-        record = ihex_next_binrec(record);
-    }
-
-    response = ezusb_fx1_set_reset(serial->dev, 0);
-
-    record = (const struct ihex_binrec *)firmware_fw->data;
-    while (record && be32_to_cpu(record->addr) < 0x1b40)
-        record = ihex_next_binrec(record);
-    while (record) {
-        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
-                         (unsigned char *)record->data,
-                         be16_to_cpu(record->len), 0xa3);
-        if (response < 0) {
-            dev_err(&serial->dev->dev, "%s - ezusb_writememory "
-                "failed for first firmware step "
-                "(%d %04X %p %d)\n", __func__, response,
-                be32_to_cpu(record->addr), record->data,
-                be16_to_cpu(record->len));
-            break;
-        }
-        ++record;
-    }
-
-    response = ezusb_fx1_set_reset(serial->dev, 1);
-
-    record = (const struct ihex_binrec *)firmware_fw->data;
-    while (record && be32_to_cpu(record->addr) < 0x1b40) {
-        response = ezusb_writememory(serial->dev, 
be32_to_cpu(record->addr),
-                         (unsigned char *)record->data,
-                         be16_to_cpu(record->len), 0xa0);
-        if (response < 0) {
-            dev_err(&serial->dev->dev, "%s - ezusb_writememory "
-                "failed for second firmware step "
-                "(%d %04X %p %d)\n", __func__, response,
-                be32_to_cpu(record->addr), record->data,
-                be16_to_cpu(record->len));
-            break;
-        }
-        ++record;
+    response = ezusb_fx1_ihex_firmware_download(serial->dev, 
"whiteheat_loader.fw");
+    if (response >= 0) {
+        response = ezusb_fx1_ihex_firmware_download(serial->dev, 
"whiteheat.fw");
+        if (response >= 0)
+            return 0;
      }
-    ret = 0;
-    response = ezusb_fx1_set_reset(serial->dev, 0);
- out:
-    release_firmware(loader_fw);
-    release_firmware(firmware_fw);
-    return ret;
+    return -ENOENT;
  }

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-03 15:06 [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
                   ` (2 preceding siblings ...)
  2012-08-03 15:18 ` [PATCH 3/3]: " René Bürgel
@ 2012-08-15 22:20 ` Greg KH
  2012-08-20  8:52   ` Rene Buergel
  3 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2012-08-15 22:20 UTC (permalink / raw)
  To: René Bürgel; +Cc: linux-usb, linux-kernel

On Fri, Aug 03, 2012 at 05:06:27PM +0200, René Bürgel wrote:
> Hello,
> 
> this is a patches-series for controllers using the ezusb-functions.
> 
> ezusb:  remove dependency to usb_serial interface
> euzsb: add support for Cypress FX2LP
> ezusb: add functions for firmware download

Nice series, but your patches are white-space damaged, and I can't apply
them at all.

Also, your third patch has the wrong Subject: line :(

Care to resend them in a format that I can apply them in?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-15 22:20 ` [PATCH 0/3]: " Greg KH
@ 2012-08-20  8:52   ` Rene Buergel
  2012-08-20 14:49     ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Rene Buergel @ 2012-08-20  8:52 UTC (permalink / raw)
  To: linux-usb, linux-kernel

----- Ursprüngliche Mail -----
> On Fri, Aug 03, 2012 at 05:06:27PM +0200, René Bürgel wrote:
> > Hello,
> > 
> > this is a patches-series for controllers using the ezusb-functions.
> > 
> > ezusb:  remove dependency to usb_serial interface
> > euzsb: add support for Cypress FX2LP
> > ezusb: add functions for firmware download
> 
> Nice series, but your patches are white-space damaged, and I can't
> apply
> them at all.
> 
> Also, your third patch has the wrong Subject: line 
> 
> Care to resend them in a format that I can apply them in?
> 
> thanks,
> 
> greg k-h
> 

Thanks for reviewing it. 

I will check my email-settings and resend the patches.

I'm sorry about the wrong Subject line, this will be corrected when resending.

I got some further questions: 
- Although i removed the dependency from ezusb to usb_serial,
  ezusb.c still resides in drivers/usb/serial.
  Can you give me a hint, where to put it instead?
  I would like to do that with an additional patch.
- is it fine to base the soon-to-be-resent patches on 3.6-rc2?


René Bürgel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-20  8:52   ` Rene Buergel
@ 2012-08-20 14:49     ` Greg KH
  2012-08-22  7:26       ` Rene Buergel
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2012-08-20 14:49 UTC (permalink / raw)
  To: Rene Buergel; +Cc: linux-usb, linux-kernel

On Mon, Aug 20, 2012 at 10:52:56AM +0200, Rene Buergel wrote:
> ----- Ursprüngliche Mail -----
> > On Fri, Aug 03, 2012 at 05:06:27PM +0200, René Bürgel wrote:
> > > Hello,
> > > 
> > > this is a patches-series for controllers using the ezusb-functions.
> > > 
> > > ezusb:  remove dependency to usb_serial interface
> > > euzsb: add support for Cypress FX2LP
> > > ezusb: add functions for firmware download
> > 
> > Nice series, but your patches are white-space damaged, and I can't
> > apply
> > them at all.
> > 
> > Also, your third patch has the wrong Subject: line 
> > 
> > Care to resend them in a format that I can apply them in?
> > 
> > thanks,
> > 
> > greg k-h
> > 
> 
> Thanks for reviewing it. 
> 
> I will check my email-settings and resend the patches.
> 
> I'm sorry about the wrong Subject line, this will be corrected when resending.
> 
> I got some further questions: 
> - Although i removed the dependency from ezusb to usb_serial,
>   ezusb.c still resides in drivers/usb/serial.
>   Can you give me a hint, where to put it instead?
>   I would like to do that with an additional patch.

Why do you want to move it?

> - is it fine to base the soon-to-be-resent patches on 3.6-rc2?

You should redo them against the linux-next tree, which has many more
patches than 3.6-rc2.

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-20 14:49     ` Greg KH
@ 2012-08-22  7:26       ` Rene Buergel
  2012-08-24 19:33         ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Rene Buergel @ 2012-08-22  7:26 UTC (permalink / raw)
  To: linux-usb, linux-kernel


> > - Although i removed the dependency from ezusb to usb_serial,
> >   ezusb.c still resides in drivers/usb/serial.
> >   Can you give me a hint, where to put it instead?
> >   I would like to do that with an additional patch.
> 
> Why do you want to move it?

because is has nothing to do with any serial stuff anymore...

> 
> > - is it fine to base the soon-to-be-resent patches on 3.6-rc2?
> 
> You should redo them against the linux-next tree, which has many more
> patches than 3.6-rc2.

ok, thanks!

> 
> greg k-h
> 

René Bürgel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support
  2012-08-22  7:26       ` Rene Buergel
@ 2012-08-24 19:33         ` Greg KH
  0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2012-08-24 19:33 UTC (permalink / raw)
  To: Rene Buergel; +Cc: linux-usb, linux-kernel

On Wed, Aug 22, 2012 at 09:26:41AM +0200, Rene Buergel wrote:
> 
> > > - Although i removed the dependency from ezusb to usb_serial,
> > >   ezusb.c still resides in drivers/usb/serial.
> > >   Can you give me a hint, where to put it instead?
> > >   I would like to do that with an additional patch.
> > 
> > Why do you want to move it?
> 
> because is has nothing to do with any serial stuff anymore...

Fair enough, how about drivers/usb/misc/ instead?

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-08-24 19:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 15:06 [PATCH 0/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
2012-08-03 15:16 ` [PATCH 1/3]: ezusb: remove dependency to usb_serial interface René Bürgel
2012-08-03 15:17 ` [PATCH 2/3]: ezusb cleanup, FX2 support, firmware downloading support René Bürgel
2012-08-03 15:18 ` [PATCH 3/3]: " René Bürgel
2012-08-15 22:20 ` [PATCH 0/3]: " Greg KH
2012-08-20  8:52   ` Rene Buergel
2012-08-20 14:49     ` Greg KH
2012-08-22  7:26       ` Rene Buergel
2012-08-24 19:33         ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).