Re: [PATCH v4] Add support for using a MAX3421E chip as a host driver.

2014-04-24 Thread David Mosberger
Greg,

Thanks for taking a look.  Yes, I'll definitely fix those oversights
and send a new patch next week.

Have a good weekend,

  --david

On Thu, Apr 24, 2014 at 2:09 PM, Greg KH gre...@linuxfoundation.org wrote:
 On Fri, Apr 11, 2014 at 11:55:51PM -0600, David Mosberger wrote:
 This is v4 of the patch.  Compared to v3, the only changes are:

   - addition of a platform-data header file which allows a platform
 to define which general-purpose output pin controls Vbus (if any)
   - spi_wr_fifo/spi_rd_fifo got renamed to spi_wr_buf/spi_rd_buf,
 respectively, since that more accurately reflects their function
 (whether or not a FIFO is being written depends on the register
  number).

 Signed-off-by: David Mosberger dav...@egauge.net
 ---
  drivers/usb/Makefile  |1 +
  drivers/usb/host/Kconfig  |   11 +
  drivers/usb/host/Makefile |1 +
  drivers/usb/host/max3421-hcd.c| 1937 
 +
  include/linux/platform_data/max3421-hcd.h |   23 +
  5 files changed, 1973 insertions(+)
  create mode 100644 drivers/usb/host/max3421-hcd.c
  create mode 100644 include/linux/platform_data/max3421-hcd.h

 I get a number of build warnings when building this code:

 drivers/usb/host/max3421-hcd.c: In function 'max3421_transfer_out':
 drivers/usb/host/max3421-hcd.c:570:4: warning: format '%zu' expects argument 
 of type 'size_t', but argument 5 has type 'int' [-Wformat=]
 __func__, max_packet, MAX3421_FIFO_SIZE);

 In file included from 
 /ssd/gregkh-linux/work/usb/arch/x86/include/asm/percpu.h:44:0,
  from 
 /ssd/gregkh-linux/work/usb/arch/x86/include/asm/preempt.h:5,
  from include/linux/preempt.h:18,
  from include/linux/spinlock.h:50,
  from include/linux/seqlock.h:35,
  from include/linux/time.h:5,
  from include/linux/stat.h:18,
  from include/linux/module.h:10,
  from drivers/usb/host/max3421-hcd.c:58:
 include/linux/kernel.h:713:17: warning: comparison of distinct pointer types 
 lacks a cast [enabled by default]
   (void) (_min1 == _min2);  \
  ^
 drivers/usb/host/max3421-hcd.c:574:26: note: in expansion of macro 'min'
   max3421_hcd-curr_len = min((urb-transfer_buffer_length -
   ^
 drivers/usb/host/max3421-hcd.c: In function 'max3421_transfer_in_done':
 drivers/usb/host/max3421-hcd.c:977:4: warning: format '%zu' expects argument 
 of type 'size_t', but argument 5 has type 'int' [-Wformat=]
 __func__, max_packet, MAX3421_FIFO_SIZE);
 ^

 which I could live with and accept a follow-on patch, but then it breaks the 
 build:

 ERROR: spi_register_driver [drivers/usb/host/max3421-hcd.ko] undefined!
 ERROR: spi_sync [drivers/usb/host/max3421-hcd.ko] undefined!
 ERROR: spi_setup [drivers/usb/host/max3421-hcd.ko] undefined!


 It looks like the Kconfig dependancies are not correct.

 Care to fix that up, and resend this patch?  Also, the changelog text above
 needs some work, no one cares what changed from the previous submission once
 the code is in the tree, they just want to know what the code does, put the
 this changed stuff below the cut line.

 thanks,

 greg k-h



-- 
eGauge Systems LLC, http://egauge.net/, 1.877-EGAUGE1, fax 720.545.9768
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] Add support for using a MAX3421E chip as a host driver.

2014-04-11 Thread David Mosberger
This is v4 of the patch.  Compared to v3, the only changes are:

- addition of a platform-data header file which allows a platform
  to define which general-purpose output pin controls Vbus (if any)
- spi_wr_fifo/spi_rd_fifo got renamed to spi_wr_buf/spi_rd_buf,
  respectively, since that more accurately reflects their function
  (whether or not a FIFO is being written depends on the register
   number).

Signed-off-by: David Mosberger dav...@egauge.net
---
 drivers/usb/Makefile  |1 +
 drivers/usb/host/Kconfig  |   11 +
 drivers/usb/host/Makefile |1 +
 drivers/usb/host/max3421-hcd.c| 1937 +
 include/linux/platform_data/max3421-hcd.h |   23 +
 5 files changed, 1973 insertions(+)
 create mode 100644 drivers/usb/host/max3421-hcd.c
 create mode 100644 include/linux/platform_data/max3421-hcd.h

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 1ae2bf3..9bb6721 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_IMX21_HCD)   += host/
 obj-$(CONFIG_USB_FSL_MPH_DR_OF)+= host/
 obj-$(CONFIG_USB_FUSBH200_HCD) += host/
 obj-$(CONFIG_USB_FOTG210_HCD)  += host/
+obj-$(CONFIG_USB_MAX3421_HCD)  += host/
 
 obj-$(CONFIG_USB_C67X00_HCD)   += c67x00/
 
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 3d9e540..e9cd7d8 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -343,6 +343,17 @@ config USB_FOTG210_HCD
  To compile this driver as a module, choose M here: the
  module will be called fotg210-hcd.
 
+config USB_MAX3421_HCD
+   tristate MAX3421 HCD (USB-over-SPI) support
+   depends on USB
+   ---help---
+ The Maxim MAX3421E chip supports standard USB 2.0-compliant
+ full-speed devices either in host or peripheral mode.  This
+ driver supports the host-mode of the MAX3421E only.
+
+ To compile this driver as a module, choose M here: the module will
+ be called max3421-hcd.
+
 config USB_OHCI_HCD
tristate OHCI HCD (USB 1.1) support
select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 7530468..ea2bec5 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -70,3 +70,4 @@ obj-$(CONFIG_USB_HCD_BCMA)+= bcma-hcd.o
 obj-$(CONFIG_USB_HCD_SSB)  += ssb-hcd.o
 obj-$(CONFIG_USB_FUSBH200_HCD) += fusbh200-hcd.o
 obj-$(CONFIG_USB_FOTG210_HCD)  += fotg210-hcd.o
+obj-$(CONFIG_USB_MAX3421_HCD)  += max3421-hcd.o
diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
new file mode 100644
index 000..fe931ea
--- /dev/null
+++ b/drivers/usb/host/max3421-hcd.c
@@ -0,0 +1,1937 @@
+/*
+ * MAX3421 Host Controller driver for USB.
+ *
+ * Author: David Mosberger-Tang dav...@egauge.net
+ *
+ * (C) Copyright 2014 David Mosberger-Tang dav...@egauge.net
+ *
+ * MAX3421 is a chip implementing a USB 2.0 Full-/Low-Speed host
+ * controller on a SPI bus.
+ *
+ * Based on:
+ * o MAX3421E datasheet
+ * http://datasheets.maximintegrated.com/en/ds/MAX3421E.pdf
+ * o MAX3421E Programming Guide
+ * http://www.hdl.co.jp/ftpdata/utl-001/AN3785.pdf
+ * o gadget/dummy_hcd.c
+ * For USB HCD implementation.
+ * o Arduino MAX3421 driver
+ *  https://github.com/felis/USB_Host_Shield_2.0/blob/master/Usb.cpp
+ *
+ * This file is licenced under the GPL v2.
+ *
+ * Important note on worst-case (full-speed) packet size constraints
+ * (See USB 2.0 Section 5.6.3 and following):
+ *
+ * - control:64 bytes
+ * - isochronous:  1023 bytes
+ * - interrupt:  64 bytes
+ * - bulk:   64 bytes
+ *
+ * Since the MAX3421 FIFO size is 64 bytes, we do not have to work about
+ * multi-FIFO writes/reads for a single USB packet *except* for isochronous
+ * transfers.  We don't support isochronous transfers at this time, so we
+ * just assume that a USB packet always fits into a single FIFO buffer.
+ *
+ * NOTE: The June 2006 version of MAX3421E Programming Guide
+ * (AN3785) has conflicting info for the RCVDAVIRQ bit:
+ *
+ * The description of RCVDAVIRQ says The CPU *must* clear
+ * this IRQ bit (by writing a 1 to it) before reading the
+ * RCVFIFO data.
+ *
+ * However, the earlier section on Programming BULK-IN
+ * Transfers says * that:
+ *
+ * After the CPU retrieves the data, it clears the
+ * RCVDAVIRQ bit.
+ *
+ * The December 2006 version has been corrected and it consistently
+ * states the second behavior is the correct one.
+ *
+ * Synchronous SPI transactions sleep so we can't perform any such
+ * transactions while holding a spin-lock (and/or while interrupts are
+ * masked).  To achieve this, all SPI transactions are issued from a
+ * single thread (max3421_spi_thread).
+ */
+
+#include linux/module.h
+#include