memstick: Add Broadcom BCM57765/BCM57785 host driver
Subsystems (2)
RFC PATCH 1/1 memstick: Add Broadcom BCM57765/BCM57785 host driver
Add support for the MemoryStick function of Broadcom BCM57765 and BCM57785 PCI card readers (14e4:16be).
The driver is written by inspecting MMIO traces from the windows driver and experimentally probing the device registers.
It was found that the controller exposes an SDHCI-like interface with TPC command handling. DMA mode was then inferred using the positions of the bits in sdhci.h.
--- MAINTAINERS | 6 + drivers/memstick/host/Kconfig | 10 + drivers/memstick/host/Makefile | 1 + drivers/memstick/host/bcm577x5_ms.c | 754 ++++++++++++++++++++++++++++ drivers/memstick/host/bcm577x5_ms.h | 138 +++++ 5 files changed, 909 insertions(+) create mode 100644 drivers/memstick/host/bcm577x5_ms.c create mode 100644 drivers/memstick/host/bcm577x5_ms.h
MAINTAINERS +6 -0
@@ -5234,6 +5234,12 @@ S: Maintained F: arch/arm/boot/dts/broadcom/bcm47189* F: arch/arm/boot/dts/broadcom/bcm53573* +BROADCOM BCM57765/BCM57785 MEMORYSTICK DRIVER +M: Ho Jie Feng <[email protected]> +L: [email protected] +S: Maintained +F: drivers/memstick/host/bcm577x5_ms.* + BROADCOM BCM63XX/BCM33XX UDC DRIVER M: Kevin Cernekee <[email protected]> L: [email protected]
drivers/memstick/host/Kconfig +10 -0
@@ -53,3 +53,13 @@ config MEMSTICK_REALTEK_USB To compile this driver as a module, choose M here: the module will be called rts5139_ms. + +config MEMSTICK_BCM577X5 + tristate "Broadcom BCM57765/BCM57785 MemoryStick interface support" + depends on PCI + help + Say Y here if you want to access MemoryStick cards with the + Broadcom BCM57765/BCM57785 PCI card reader (14e4:16be). + + To compile this driver as a module, choose M here: the module + will be called bcm577x5_ms.
drivers/memstick/host/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o obj-$(CONFIG_MEMSTICK_R592) += r592.o obj-$(CONFIG_MEMSTICK_REALTEK_USB) += rtsx_usb_ms.o +obj-$(CONFIG_MEMSTICK_BCM577X5) += bcm577x5_ms.o
drivers/memstick/host/bcm577x5_ms.c new file +754 -0
754 lines not on this page · raw message
drivers/memstick/host/bcm577x5_ms.h new file +138 -0
138 lines not on this page · raw message
base-commit: 155f6759c2529d273b6b204c92bd51e3e3989232
Signature · 1 line
2.55.0
Quoted 4 lines · Ho Jie Feng
Add support for the MemoryStick function of Broadcom BCM57765 and BCM57785 PCI card readers (14e4:16be).
Quoted 8 lines
The driver is written by inspecting MMIO traces from the windows driver and experimentally probing the device registers.
It was found that the controller exposes an SDHCI-like interface with TPC command handling. DMA mode was then inferred using the positions of the bits in
sdhci.h.Signed-off-by Ho Jie Feng <[email protected]>
Wow! It's been a while since we received new drivers from memstick controllers!
Overall this looks good to me, but I have few minor comments, see below.
Quoted 80 lines
--- MAINTAINERS | 6 + drivers/memstick/host/Kconfig | 10 + drivers/memstick/host/Makefile | 1 + drivers/memstick/host/bcm577x5_ms.c | 754 ++++++++++++++++++++++++++++ drivers/memstick/host/bcm577x5_ms.h | 138 +++++ 5 files changed, 909 insertions(+) create mode 100644 drivers/memstick/host/bcm577x5_ms.c create mode 100644 drivers/memstick/host/bcm577x5_ms.hMAINTAINERS +6
-0@@ -5234,6 +5234,12 @@ S: Maintained F: arch/arm/boot/dts/broadcom/bcm47189* F: arch/arm/boot/dts/broadcom/bcm53573* +BROADCOM BCM57765/BCM57785 MEMORYSTICK DRIVER +M: Ho Jie Feng <[email protected]> +L: [email protected] +S: Maintained +F: drivers/memstick/host/bcm577x5_ms.* + BROADCOM BCM63XX/BCM33XX UDC DRIVER M: Kevin Cernekee <[email protected]> L: [email protected]drivers/memstick/host/Kconfig +10
-0@@ -53,3 +53,13 @@ config MEMSTICK_REALTEK_USB To compile this driver as a module, choose M here: the module will be called rts5139_ms. + +config MEMSTICK_BCM577X5 + tristate "Broadcom BCM57765/BCM57785 MemoryStick interface support" + depends on PCI + help + Say Y here if you want to access MemoryStick cards with the + Broadcom BCM57765/BCM57785 PCI card reader (14e4:16be). + + To compile this driver as a module, choose M here: the module + will be called bcm577x5_ms.drivers/memstick/host/Makefile +1
-0@@ -7,3 +7,4 @@ obj-$(CONFIG_MEMSTICK_TIFM_MS) += tifm_ms.o obj-$(CONFIG_MEMSTICK_JMICRON_38X) += jmb38x_ms.o obj-$(CONFIG_MEMSTICK_R592) += r592.o obj-$(CONFIG_MEMSTICK_REALTEK_USB) += rtsx_usb_ms.o +obj-$(CONFIG_MEMSTICK_BCM577X5) += bcm577x5_ms.odrivers/memstick/host/bcm577x5_ms.c new file +20
-0@@ -0,0 +1,754 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <linux/align.h> +#include <linux/bits.h> +#include <linux/completion.h> +#include <linux/container_of.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/errno.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/jiffies.h> +#include <linux/memstick.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/pci_ids.h> +#include <linux/pm.h> +#include <linux/scatterlist.h> +#include <linux/slab.h> +#include <linux/types.h>
drivers/memstick/host/bcm577x5_ms.c line 30
Quoted 10 lines
drivers/memstick/host/bcm577x5_ms.c new file +10
-0+#include <linux/workqueue.h> + +#include "bcm577x5_ms.h" + +#define DRV_NAME "bcm577x5_ms" + +static int enable_dma =2 ; +module_param (enable_dma, int,0444 ); +MODULE_PARM_DESC (enable_dma, +"Enable usage of the DMA (0 = no, 1 = yes, 2 = auto,default)" );
I assume this is useful because the DMA functionality is a bit flaky, no?
In any case, I would rather not use a module parameter for this, can you please drop this. If needed at all, can we perhaps use a debugfs file instead to switch dynamically?
Quoted 7 lines
drivers/memstick/host/bcm577x5_ms.c new file +7
-0+ +static const struct pci_device_id bcm577x5_pci_id_tbl[] = { + { +PCI_VDEVICE (BROADCOM ,0x16be ), + }, + {}, +};
[...]
Quoted 5 lines
drivers/memstick/host/bcm577x5_ms.c new file +5
-0+ +static int bcm577x5_reg_waitb (struct bcm577x5_device *dev,int address,u8 mask, +u8 value,int timeout) +{ +unsigned long wait_time = jiffies +msecs_to_jiffies (timeout);
drivers/memstick/host/bcm577x5_ms.c line 88
Quoted 10 lines
drivers/memstick/host/bcm577x5_ms.c new file +10
-0+u8 reg; + +do { + reg =bcm577x5_reg_readb (dev, address); +if ((reg & mask) == value) +return 0 ; + +cpu_relax (); + + }while (time_before (jiffies, wait_time));
Please avoid the open coding and convert to the io polling helpers instead (iopoll.h).
Quoted 8 lines
drivers/memstick/host/bcm577x5_ms.c new file +8
-0+ +return -ETIME ; +} + +static int bcm577x5_reg_waitl_different (struct bcm577x5_device *dev, +int address,u32 value,int timeout) +{ +unsigned long wait_time = jiffies +msecs_to_jiffies (timeout);
drivers/memstick/host/bcm577x5_ms.c line 106
Quoted 10 lines
drivers/memstick/host/bcm577x5_ms.c new file +10
-0+u32 reg; + +do { + reg =bcm577x5_reg_readl (dev, address); +if (reg != value) +return 0 ; + +cpu_relax (); + + }while (time_before (jiffies, wait_time));
Ditto.
drivers/memstick/host/bcm577x5_ms.c line 110
Quoted 4 lines
drivers/memstick/host/bcm577x5_ms.c new file +4
-0+ +return -ETIMEDOUT ; +} +
[...]
Kind regards
Uffe
Quoted 8 lines · Ulf Hansson
Quoted 7 lines · Ho Jie Feng
Add support for the MemoryStick function of Broadcom BCM57765 and BCM57785 PCI card readers (14e4:16be).
The driver is written by inspecting MMIO traces from the windows driver and experimentally probing the device registers.
Quoted 7 lines
Quoted 5 lines
It was found that the controller exposes an SDHCI-like interface with TPC command handling. DMA mode was then inferred using the positions of the bits in
sdhci.h.Signed-off-by Ho Jie Feng <[email protected]>Wow! It's been a while since we received new drivers from memstick controllers!
Yep I wrote this quite a while back and only go around to upstreaming it recently.
Quoted 10 lines
drivers/memstick/host/bcm577x5_ms.c line 30
Quoted 3 lines
drivers/memstick/host/bcm577x5_ms.c new file +3
-0+module_param (enable_dma, int,0444 ); +MODULE_PARM_DESC (enable_dma, +"Enable usage of the DMA (0 = no, 1 = yes, 2 = auto,default)" );I assume this is useful because the DMA functionality is a bit flaky, no?
In any case, I would rather not use a module parameter for this, can you please drop this. If needed at all, can we perhaps use a debugfs file instead to switch dynamically?
The traces from the Windows drivers doesn't use DMA at all, at least only the nice ones which call the kernel APIs to do MMIO operations, unlike some newer drivers which do the MMIO within the driver. The machine doesn't have VT-d so that is not usable. Due to this, I inferred DMA operation from the bits from sdhci.h and doing some experimentation on the device. The flag is only there because I may have missed something and the DMA path isn't reliable.
I will look into the debugfs stuff, thanks.
Quoted 20 lines
Quoted 7 lines
drivers/memstick/host/bcm577x5_ms.c new file +7
-0+ +static const struct pci_device_id bcm577x5_pci_id_tbl[] = { + { +PCI_VDEVICE (BROADCOM ,0x16be ), + }, + {}, +};[...]
Quoted 10 lines
drivers/memstick/host/bcm577x5_ms.c new file +10
-0+ +static int bcm577x5_reg_waitb (struct bcm577x5_device *dev,int address,u8 mask, +u8 value,int timeout) +{ +unsigned long wait_time = jiffies +msecs_to_jiffies (timeout); +u8 reg; + + do { + reg = bcm577x5_reg_readb(dev, address); + if ((reg & mask) == value)
Quoted 8 lines
drivers/memstick/host/bcm577x5_ms.c line 88
Quoted 5 lines
drivers/memstick/host/bcm577x5_ms.c new file +5
-0+return 0 ; + +cpu_relax (); + + }while (time_before (jiffies, wait_time));Please avoid the open coding and convert to the io polling helpers instead (
iopoll.h).
Will fix in v2.