2 * ricoh_mmc.c - Dummy driver to disable the Rioch MMC controller.
4 * Copyright (C) 2007 Philip Langdale, All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
13 * This is a conceptually ridiculous driver, but it is required by the way
14 * the Ricoh multi-function R5C832 works. This chip implements firewire
15 * and four different memory card controllers. Two of those controllers are
16 * an SDHCI controller and a proprietary MMC controller. The linux SDHCI
17 * driver supports MMC cards but the chip detects MMC cards in hardware
18 * and directs them to the MMC controller - so the SDHCI driver never sees
19 * them. To get around this, we must disable the useless MMC controller.
20 * At that point, the SDHCI controller will start seeing them. As a bonus,
21 * a detection event occurs immediately, even if the MMC card is already
24 * The relevant registers live on the firewire function, so this is unavoidably
28 #include <linux/pci.h>
30 #define DRIVER_NAME "ricoh-mmc"
32 static const struct pci_device_id pci_ids
[] __devinitdata
= {
34 .vendor
= PCI_VENDOR_ID_RICOH
,
35 .device
= PCI_DEVICE_ID_RICOH_R5C843
,
36 .subvendor
= PCI_ANY_ID
,
37 .subdevice
= PCI_ANY_ID
,
39 { /* end: all zeroes */ },
42 MODULE_DEVICE_TABLE(pci
, pci_ids
);
44 static int __devinit
ricoh_mmc_probe(struct pci_dev
*pdev
,
45 const struct pci_device_id
*ent
)
49 struct pci_dev
*fw_dev
= NULL
;
54 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &rev
);
56 printk(KERN_INFO DRIVER_NAME
57 ": Ricoh MMC controller found at %s [%04x:%04x] (rev %x)\n",
58 pci_name(pdev
), (int)pdev
->vendor
, (int)pdev
->device
,
61 while ((fw_dev
= pci_get_device(PCI_VENDOR_ID_RICOH
, PCI_DEVICE_ID_RICOH_R5C832
, fw_dev
))) {
62 if (PCI_SLOT(pdev
->devfn
) == PCI_SLOT(fw_dev
->devfn
) &&
63 pdev
->bus
== fw_dev
->bus
) {
67 pci_read_config_byte(fw_dev
, 0xCB, &disable
);
69 printk(KERN_INFO DRIVER_NAME
70 ": Controller already disabled. Nothing to do.\n");
74 pci_read_config_byte(fw_dev
, 0xCA, &write_enable
);
75 pci_write_config_byte(fw_dev
, 0xCA, 0x57);
76 pci_write_config_byte(fw_dev
, 0xCB, disable
| 0x02);
77 pci_write_config_byte(fw_dev
, 0xCA, write_enable
);
79 pci_set_drvdata(pdev
, fw_dev
);
81 printk(KERN_INFO DRIVER_NAME
82 ": Controller is now disabled.\n");
88 if (pci_get_drvdata(pdev
) == NULL
) {
89 printk(KERN_WARNING DRIVER_NAME
90 ": Main firewire function not found. Cannot disable controller.\n");
97 static void __devexit
ricoh_mmc_remove(struct pci_dev
*pdev
)
101 struct pci_dev
*fw_dev
= NULL
;
103 fw_dev
= pci_get_drvdata(pdev
);
104 BUG_ON(fw_dev
== NULL
);
106 pci_read_config_byte(fw_dev
, 0xCA, &write_enable
);
107 pci_read_config_byte(fw_dev
, 0xCB, &disable
);
108 pci_write_config_byte(fw_dev
, 0xCA, 0x57);
109 pci_write_config_byte(fw_dev
, 0xCB, disable
& ~0x02);
110 pci_write_config_byte(fw_dev
, 0xCA, write_enable
);
112 printk(KERN_INFO DRIVER_NAME
113 ": Controller is now re-enabled.\n");
115 pci_set_drvdata(pdev
, NULL
);
118 static struct pci_driver ricoh_mmc_driver
= {
121 .probe
= ricoh_mmc_probe
,
122 .remove
= __devexit_p(ricoh_mmc_remove
),
125 /*****************************************************************************\
129 \*****************************************************************************/
131 static int __init
ricoh_mmc_drv_init(void)
133 printk(KERN_INFO DRIVER_NAME
134 ": Ricoh MMC Controller disabling driver\n");
135 printk(KERN_INFO DRIVER_NAME
": Copyright(c) Philip Langdale\n");
137 return pci_register_driver(&ricoh_mmc_driver
);
140 static void __exit
ricoh_mmc_drv_exit(void)
142 pci_unregister_driver(&ricoh_mmc_driver
);
145 module_init(ricoh_mmc_drv_init
);
146 module_exit(ricoh_mmc_drv_exit
);
148 MODULE_AUTHOR("Philip Langdale <philipl@alumni.utexas.net>");
149 MODULE_DESCRIPTION("Ricoh MMC Controller disabling driver");
150 MODULE_LICENSE("GPL");