]> git.karo-electronics.de Git - linux-beck.git/commitdiff
mmc: Disabler for Ricoh MMC controller
authorPhilip Langdale <philipl@overt.org>
Sat, 15 Sep 2007 19:54:08 +0000 (12:54 -0700)
committerPierre Ossman <drzeus@drzeus.cx>
Wed, 3 Oct 2007 16:40:05 +0000 (18:40 +0200)
Thanks to Matt Domsch and Rezwanul Kabir at Dell, we know how to disable the
MMC controller on the multi-function Ricoh R5C832. The MMC controller needs
to be disabled or it will steal MMC cards from the SD controller where they
would otherwise be supported by the Linux SDHCI driver.

Signed-off-by: Philipl Langdale <philipl@overt.org>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
drivers/mmc/host/Kconfig
drivers/mmc/host/Makefile
drivers/mmc/host/ricoh_mmc.c [new file with mode: 0644]
include/linux/pci_ids.h

index 68fb052afd3ee12b548bb46298534325f988d2f6..5fef6783c7161fc8cf95b836e49dcc13259ff655 100644 (file)
@@ -35,6 +35,23 @@ config MMC_SDHCI
 
          If unsure, say N.
 
+config MMC_RICOH_MMC
+       tristate "Ricoh MMC Controller Disabler  (EXPERIMENTAL)"
+       depends on PCI && EXPERIMENTAL && MMC_SDHCI
+       help
+         This selects the disabler for the Ricoh MMC Controller. This
+         proprietary controller is unnecessary because the SDHCI driver
+         supports MMC cards on the SD controller, but if it is not
+         disabled, it will steal the MMC cards away - rendering them
+         useless. It is safe to select this driver even if you don't
+         have a Ricoh based card reader.
+
+
+         To compile this driver as a module, choose M here:
+         the module will be called ricoh_mmc.
+
+         If unsure, say Y.
+
 config MMC_OMAP
        tristate "TI OMAP Multimedia Card Interface support"
        depends on ARCH_OMAP
index 8dc82ce647b7baa2128f88c3cabffa3bcf8551dc..3877c87e6da26e699a730959104dc61ce5992290 100644 (file)
@@ -10,6 +10,7 @@ obj-$(CONFIG_MMC_ARMMMCI)     += mmci.o
 obj-$(CONFIG_MMC_PXA)          += pxamci.o
 obj-$(CONFIG_MMC_IMX)          += imxmmc.o
 obj-$(CONFIG_MMC_SDHCI)                += sdhci.o
+obj-$(CONFIG_MMC_RICOH_MMC)    += ricoh_mmc.o
 obj-$(CONFIG_MMC_WBSD)         += wbsd.o
 obj-$(CONFIG_MMC_AU1X)         += au1xmmc.o
 obj-$(CONFIG_MMC_OMAP)         += omap.o
diff --git a/drivers/mmc/host/ricoh_mmc.c b/drivers/mmc/host/ricoh_mmc.c
new file mode 100644 (file)
index 0000000..1e87045
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ *  ricoh_mmc.c - Dummy driver to disable the Rioch MMC controller.
+ *
+ *  Copyright (C) 2007 Philip Langdale, All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ */
+
+/*
+ * This is a conceptually ridiculous driver, but it is required by the way
+ * the Ricoh multi-function R5C832 works. This chip implements firewire
+ * and four different memory card controllers. Two of those controllers are
+ * an SDHCI controller and a proprietary MMC controller. The linux SDHCI
+ * driver supports MMC cards but the chip detects MMC cards in hardware
+ * and directs them to the MMC controller - so the SDHCI driver never sees
+ * them. To get around this, we must disable the useless MMC controller.
+ * At that point, the SDHCI controller will start seeing them. As a bonus,
+ * a detection event occurs immediately, even if the MMC card is already
+ * in the reader.
+ *
+ * The relevant registers live on the firewire function, so this is unavoidably
+ * ugly. Such is life.
+ */
+
+#include <linux/pci.h>
+
+#define DRIVER_NAME "ricoh-mmc"
+
+static const struct pci_device_id pci_ids[] __devinitdata = {
+       {
+               .vendor         = PCI_VENDOR_ID_RICOH,
+               .device         = PCI_DEVICE_ID_RICOH_R5C843,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+       },
+       { /* end: all zeroes */ },
+};
+
+MODULE_DEVICE_TABLE(pci, pci_ids);
+
+static int __devinit ricoh_mmc_probe(struct pci_dev *pdev,
+                                    const struct pci_device_id *ent)
+{
+       u8 rev;
+
+       struct pci_dev *fw_dev = NULL;
+
+       BUG_ON(pdev == NULL);
+       BUG_ON(ent == NULL);
+
+       pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
+
+       printk(KERN_INFO DRIVER_NAME
+               ": Ricoh MMC controller found at %s [%04x:%04x] (rev %x)\n",
+               pci_name(pdev), (int)pdev->vendor, (int)pdev->device,
+               (int)rev);
+
+       while ((fw_dev = pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, fw_dev))) {
+               if (PCI_SLOT(pdev->devfn) == PCI_SLOT(fw_dev->devfn) &&
+                   pdev->bus == fw_dev->bus) {
+                       u8 write_enable;
+                       u8 disable;
+
+                       pci_read_config_byte(fw_dev, 0xCB, &disable);
+                       if (disable & 0x02) {
+                               printk(KERN_INFO DRIVER_NAME
+                                      ": Controller already disabled. Nothing to do.\n");
+                               return -ENODEV;
+                       }
+
+                       pci_read_config_byte(fw_dev, 0xCA, &write_enable);
+                       pci_write_config_byte(fw_dev, 0xCA, 0x57);
+                       pci_write_config_byte(fw_dev, 0xCB, disable | 0x02);
+                       pci_write_config_byte(fw_dev, 0xCA, write_enable);
+
+                       pci_set_drvdata(pdev, fw_dev);
+
+                       printk(KERN_INFO DRIVER_NAME
+                              ": Controller is now disabled.\n");
+
+                       break;
+               }
+       }
+
+       if (pci_get_drvdata(pdev) == NULL) {
+               printk(KERN_WARNING DRIVER_NAME
+                      ": Main firewire function not found. Cannot disable controller.\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static void __devexit ricoh_mmc_remove(struct pci_dev *pdev)
+{
+       u8 write_enable;
+       u8 disable;
+       struct pci_dev *fw_dev = NULL;
+
+       fw_dev = pci_get_drvdata(pdev);
+       BUG_ON(fw_dev == NULL);
+
+       pci_read_config_byte(fw_dev, 0xCA, &write_enable);
+       pci_read_config_byte(fw_dev, 0xCB, &disable);
+       pci_write_config_byte(fw_dev, 0xCA, 0x57);
+       pci_write_config_byte(fw_dev, 0xCB, disable & ~0x02);
+       pci_write_config_byte(fw_dev, 0xCA, write_enable);
+
+       printk(KERN_INFO DRIVER_NAME
+              ": Controller is now re-enabled.\n");
+
+       pci_set_drvdata(pdev, NULL);
+}
+
+static struct pci_driver ricoh_mmc_driver = {
+       .name =         DRIVER_NAME,
+       .id_table =     pci_ids,
+       .probe =        ricoh_mmc_probe,
+       .remove =       __devexit_p(ricoh_mmc_remove),
+};
+
+/*****************************************************************************\
+ *                                                                           *
+ * Driver init/exit                                                          *
+ *                                                                           *
+\*****************************************************************************/
+
+static int __init ricoh_mmc_drv_init(void)
+{
+       printk(KERN_INFO DRIVER_NAME
+               ": Ricoh MMC Controller disabling driver\n");
+       printk(KERN_INFO DRIVER_NAME ": Copyright(c) Philip Langdale\n");
+
+       return pci_register_driver(&ricoh_mmc_driver);
+}
+
+static void __exit ricoh_mmc_drv_exit(void)
+{
+       pci_unregister_driver(&ricoh_mmc_driver);
+}
+
+module_init(ricoh_mmc_drv_init);
+module_exit(ricoh_mmc_drv_exit);
+
+MODULE_AUTHOR("Philip Langdale <philipl@alumni.utexas.net>");
+MODULE_DESCRIPTION("Ricoh MMC Controller disabling driver");
+MODULE_LICENSE("GPL");
+
index 55f307ffbf96ded1724ebc011fea173dc7cee1e6..c8636bb3e3a76fd9146ee5ce1c0fe17cd5a03a51 100644 (file)
 #define PCI_DEVICE_ID_RICOH_RL5C476    0x0476
 #define PCI_DEVICE_ID_RICOH_RL5C478    0x0478
 #define PCI_DEVICE_ID_RICOH_R5C822     0x0822
+#define PCI_DEVICE_ID_RICOH_R5C832     0x0832
+#define PCI_DEVICE_ID_RICOH_R5C843     0x0843
 
 #define PCI_VENDOR_ID_DLINK            0x1186
 #define PCI_DEVICE_ID_DLINK_DGE510T    0x4c00