mmc: extend ricoh_mmc to support Ricoh RL5c476
PATCH 1/1 mmc: extend ricoh_mmc to support Ricoh RL5c476
From: Frank Seidel <[email protected]>
This patch (based on current linus git tree) adds support for the Ricoh RL5c476 chip: with this the mmc adapter that needs this disabler (R5C843) can also be handled correctly when it sits on a RL5c476.
--- drivers/mmc/host/ricoh_mmc.c | 91 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 16 deletions(-)
drivers/mmc/host/ricoh_mmc.c +75 -16
@@ -45,8 +45,10 @@ static int __devinit ricoh_mmc_probe(str const struct pci_device_id *ent) {u8 rev; +u8 ctrlfound =0 ;struct pci_dev *fw_dev =NULL ; +struct pci_dev *main_dev =NULL ;/* for Ricoh RL5c476 II */ BUG_ON (pdev ==NULL );BUG_ON (ent ==NULL );
@@ -58,7 +60,47 @@ static int __devinit ricoh_mmc_probe(strpci_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))) { +/* disable mmc controller via main function (RL5C476) */ +while ((main_dev = +pci_get_device (PCI_VENDOR_ID_RICOH , +PCI_DEVICE_ID_RICOH_RL5C476 , main_dev))) { +if (PCI_SLOT (pdev->devfn) ==PCI_SLOT (main_dev->devfn) && + pdev->bus == main_dev->bus) { +u8 write_enable; +u8 write_target; +u8 disable; + +pci_read_config_byte (main_dev,0xB7 , &disable); +if (disable &0x02 ) { + printk(KERN_INFO DRIVER_NAME +": Controller already disabled. " \ + "Nothing to do.\n"); +return -ENODEV ; + } + +pci_read_config_byte (main_dev,0x8E , &write_enable); +pci_write_config_byte (main_dev,0x8E ,0xAA ); +pci_read_config_byte (main_dev,0x8D , &write_target); +pci_write_config_byte (main_dev,0x8D ,0xB7 ); +pci_write_config_byte (main_dev,0xB7 , disable |0x02 ); +pci_write_config_byte (main_dev,0x8E , write_enable); +pci_write_config_byte (main_dev,0x8D , write_target); + +pci_set_drvdata (pdev, main_dev); + + printk(KERN_INFO DRIVER_NAME +": Controller is now disabled " \ + "(via R5L5C476).\n"); + + ctrlfound =1 ; +break ; + } + } + +/* disable mmc controller via firewire function (R5C832) */ +while (!ctrlfound && + (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;
@@ -67,7 +109,8 @@ static int __devinit ricoh_mmc_probe(strpci_read_config_byte (fw_dev,0xCB , &disable);if (disable &0x02 ) { printk(KERN_INFO DRIVER_NAME - ": Controller already disabled. Nothing to do.\n"); +": Controller already disabled. " \ + "Nothing to do.\n");return -ENODEV ; }
@@ -79,15 +122,16 @@ static int __devinit ricoh_mmc_probe(strpci_set_drvdata (pdev, fw_dev); printk(KERN_INFO DRIVER_NAME - ": Controller is now disabled.\n"); + ": Controller is now disabled (via R5C832).\n"); -break ; + ctrlfound =1 ; } } -if (pci_get_drvdata (pdev) ==NULL ) { +if (!ctrlfound) { printk(KERN_WARNING DRIVER_NAME - ": Main firewire function not found. Cannot disable controller.\n"); +": Needed function was not found. " \ + "Cannot disable controller.\n");return -ENODEV ; }
@@ -97,20 +141,35 @@ static int __devinit ricoh_mmc_probe(str static void __devexit ricoh_mmc_remove(struct pci_dev *pdev) {u8 write_enable; +u8 write_target;u8 disable; -struct pci_dev *fw_dev =NULL ; +struct pci_dev *ctrl_dev =NULL ; - fw_dev =pci_get_drvdata (pdev); -BUG_ON (fw_dev ==NULL ); + ctrl_dev =pci_get_drvdata (pdev); +BUG_ON (ctrl_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); +if (ctrl_dev->device ==PCI_DEVICE_ID_RICOH_RL5C476 ) { +pci_read_config_byte (ctrl_dev,0x8E , &write_enable); +pci_write_config_byte (ctrl_dev,0x8E ,0xAA ); +pci_read_config_byte (ctrl_dev,0x8D , &write_target); +pci_write_config_byte (ctrl_dev,0x8D ,0xB7 ); +pci_read_config_byte (ctrl_dev,0xB7 , &disable); +pci_write_config_byte (ctrl_dev,0xB7 , disable & ~0x02 ); +pci_write_config_byte (ctrl_dev,0x8E , write_enable); +pci_write_config_byte (ctrl_dev,0x8D , write_target); + + printk(KERN_INFO DRIVER_NAME + ": Controller is now re-enabled (via R5L5C476).\n"); + }else { +pci_read_config_byte (ctrl_dev,0xCA , &write_enable); +pci_read_config_byte (ctrl_dev,0xCB , &disable); +pci_write_config_byte (ctrl_dev,0xCA ,0x57 ); +pci_write_config_byte (ctrl_dev,0xCB , disable & ~0x02 ); +pci_write_config_byte (ctrl_dev,0xCA , write_enable); - printk(KERN_INFO DRIVER_NAME - ": Controller is now re-enabled.\n"); + printk(KERN_INFO DRIVER_NAME + ": Controller is now re-enabled (via R5C832).\n"); + }pci_set_drvdata (pdev,NULL ); }
Quoted 6 lines · Frank Seidel
From: Frank Seidel <[email protected]>
This patch (based on current linus git tree) adds support for the Ricoh RL5c476 chip: with this the mmc adapter that needs this disabler (R5C843) can also be handled correctly when it sits on a RL5c476.
Again, thanks a lot for investigating and finding the appropriate magic incantations. My main comment is to please base this on top of my suspend/resume patch which Pierre said he accepted but which isn't in his tree yet - I guess he's busy offline right now - haven't heard from him in a while.
Quoted 8 lines
Signed-off-by Frank Seidel <[email protected]>--- drivers/mmc/host/ricoh_mmc.c | 91 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 16 deletions(-)
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str · line 51
Quoted 7 lines
drivers/mmc/host/ricoh_mmc.c +2
-0@@ -45,8 +45,10 @@ static int __devinit ricoh_mmc_probe(str const struct pci_device_id *ent) {u8 rev; +u8 ctrlfound =0 ;struct pci_dev *fw_dev =NULL ; +struct pci_dev *main_dev =NULL ;/* for Ricoh RL5c476 II */
There's no need to have two pointers. One will do fine.
Quoted 41 lines
drivers/mmc/host/ricoh_mmc.c +34
-1BUG_ON (pdev ==NULL );BUG_ON (ent ==NULL );@@ -58,7 +60,47 @@ static int __devinit ricoh_mmc_probe(strpci_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))) { +/* disable mmc controller via main function (RL5C476) */ +while ((main_dev = +pci_get_device (PCI_VENDOR_ID_RICOH , +PCI_DEVICE_ID_RICOH_RL5C476 , main_dev))) { +if (PCI_SLOT (pdev->devfn) ==PCI_SLOT (main_dev->devfn) && + pdev->bus == main_dev->bus) { +u8 write_enable; +u8 write_target; +u8 disable; + +pci_read_config_byte (main_dev,0xB7 , &disable); +if (disable &0x02 ) { + printk(KERN_INFO DRIVER_NAME +": Controller already disabled. " \ + "Nothing to do.\n"); +return -ENODEV ; + } + +pci_read_config_byte (main_dev,0x8E , &write_enable); +pci_write_config_byte (main_dev,0x8E ,0xAA ); +pci_read_config_byte (main_dev,0x8D , &write_target); +pci_write_config_byte (main_dev,0x8D ,0xB7 ); +pci_write_config_byte (main_dev,0xB7 , disable |0x02 ); +pci_write_config_byte (main_dev,0x8E , write_enable); +pci_write_config_byte (main_dev,0x8D , write_target); + +pci_set_drvdata (pdev, main_dev); + + printk(KERN_INFO DRIVER_NAME +": Controller is now disabled " \ + "(via R5L5C476).\n"); + + ctrlfound =1 ; +break ;
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str · line 106
Quoted 10 lines
drivers/mmc/host/ricoh_mmc.c +7
-0+ } + } + +/* disable mmc controller via firewire function (R5C832) */ +while (!ctrlfound && + (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;
It feels like there's a bit too much code duplication going on here, but I think that after you rebase the patch it'll look a lot tidier and I won't feel bad about it :-)
Quoted 32 lines
drivers/mmc/host/ricoh_mmc.c +7
-5@@ -67,7 +109,8 @@ static int __devinit ricoh_mmc_probe(strpci_read_config_byte (fw_dev,0xCB , &disable);if (disable &0x02 ) { printk(KERN_INFO DRIVER_NAME - ": Controller already disabled. Nothing to do.\n"); +": Controller already disabled. " \ + "Nothing to do.\n");return -ENODEV ; }@@ -79,15 +122,16 @@ static int __devinit ricoh_mmc_probe(strpci_set_drvdata (pdev, fw_dev); printk(KERN_INFO DRIVER_NAME - ": Controller is now disabled.\n"); + ": Controller is now disabled (via R5C832).\n"); -break ; + ctrlfound =1 ; } } -if (pci_get_drvdata (pdev) ==NULL ) { +if (!ctrlfound) { printk(KERN_WARNING DRIVER_NAME - ": Main firewire function not found. Cannot disable controller.\n"); +": Needed function was not found. " \ + "Cannot disable controller.\n");return -ENODEV ; }
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str · line 146
Quoted 7 lines
drivers/mmc/host/ricoh_mmc.c +2
-1@@ -97,20 +141,35 @@ static int __devinit ricoh_mmc_probe(str static void __devexit ricoh_mmc_remove(struct pci_dev *pdev) {u8 write_enable; +u8 write_target;u8 disable; -struct pci_dev *fw_dev =NULL ; +struct pci_dev *ctrl_dev =NULL ;
Same as in probe. Just use one pointer.
Quoted 28 lines
drivers/mmc/host/ricoh_mmc.c +20
-7- fw_dev =pci_get_drvdata (pdev); -BUG_ON (fw_dev ==NULL ); + ctrl_dev =pci_get_drvdata (pdev); +BUG_ON (ctrl_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); +if (ctrl_dev->device ==PCI_DEVICE_ID_RICOH_RL5C476 ) { +pci_read_config_byte (ctrl_dev,0x8E , &write_enable); +pci_write_config_byte (ctrl_dev,0x8E ,0xAA ); +pci_read_config_byte (ctrl_dev,0x8D , &write_target); +pci_write_config_byte (ctrl_dev,0x8D ,0xB7 ); +pci_read_config_byte (ctrl_dev,0xB7 , &disable); +pci_write_config_byte (ctrl_dev,0xB7 , disable & ~0x02 ); +pci_write_config_byte (ctrl_dev,0x8E , write_enable); +pci_write_config_byte (ctrl_dev,0x8D , write_target); + + printk(KERN_INFO DRIVER_NAME + ": Controller is now re-enabled (via R5L5C476).\n"); + }else { +pci_read_config_byte (ctrl_dev,0xCA , &write_enable); +pci_read_config_byte (ctrl_dev,0xCB , &disable); +pci_write_config_byte (ctrl_dev,0xCA ,0x57 ); +pci_write_config_byte (ctrl_dev,0xCB , disable & ~0x02 ); +pci_write_config_byte (ctrl_dev,0xCA , write_enable);
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str
Quoted 10 lines
drivers/mmc/host/ricoh_mmc.c +3
-2- printk(KERN_INFO DRIVER_NAME - ": Controller is now re-enabled.\n"); + printk(KERN_INFO DRIVER_NAME + ": Controller is now re-enabled (via R5C832).\n"); + }pci_set_drvdata (pdev,NULL ); }
--phil
Quoted 4 lines · Philip Langdale
Again, thanks a lot for investigating and finding the appropriate magic incantations. My main comment is to please base this on top of my suspend/resume patch which Pierre said he accepted but which isn't in his tree yet - I guess he's busy offline right now - haven't heard from him in a while.
Yes, sorry, in the meantime i saw your suspend/resume patch .. will rebase this on it, but also due to being a bit bussy now probably not until beginning of next week.
Quoted 4 lines
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str · line 51
Quoted 2 lines
drivers/mmc/host/ricoh_mmc.c +1
-0struct pci_dev *fw_dev =NULL ; +struct pci_dev *main_dev =NULL ;/* for Ricoh RL5c476 II */ There's no need to have two pointers. One will do fine.
yes, fully agree ..
Quoted 3 lines
It feels like there's a bit too much code duplication going on here, but I think that after you rebase the patch it'll look a lot tidier and I won't feel bad about it :-)
yes, also fully agree .. sadfully i was in a bit of a hurry that day needing a working patch for a internal deadline.
Quoted 4 lines
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str · line 146
Quoted 2 lines
drivers/mmc/host/ricoh_mmc.c +1
-1-struct pci_dev *fw_dev =NULL ; +struct pci_dev *ctrl_dev =NULL ;Same as in probe. Just use one pointer.
Hehe, no, not here ... its "-", "+" ;-)
Thanks,
Frank
Hi,
Quoted 4 lines · you (Philip Langdale)
Again, thanks a lot for investigating and finding the appropriate magic incantations. My main comment is to please base this on top of my suspend/resume patch which Pierre said he accepted but which isn't in his tree yet - I guess he's busy offline right now - haven't heard from him in a while.
to any reason i had some strange problems applying your patch. But i finally made it and rebased my patch on top of it.
So, in a few moments i'll sent it here as v2 and also a quilt refreshed version of yours (just in case also somebody had problems.. ah and i fixed a typo in your signed-off and added mine).
Thanks,
Frank
PATCH 1/1 mmc: Handle suspend/resume in Ricoh MMC disabler (resent refreshed)
In reply to Philip LangdaleFrom: Philip Langdale <[email protected]>
As pci config space is reinitialised on suspend/resume cycle, the disabler needs to work its magic at resume time. For symmetry this change also explicitly enables the controller at suspend time but it's not strictly necessary.
--- drivers/mmc/host/ricoh_mmc.c | 97 +++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 25 deletions(-)
drivers/mmc/host/ricoh_mmc.c +72 -25
@@ -41,6 +41,46 @@ static const struct pci_device_id pci_idMODULE_DEVICE_TABLE (pci, pci_ids); +static int ricoh_mmc_disable (struct pci_dev *fw_dev) +{ +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); + + printk(KERN_INFO DRIVER_NAME + ": Controller is now disabled.\n"); + +return 0 ; +} + +static int ricoh_mmc_enable (struct pci_dev *fw_dev) +{ +u8 write_enable; +u8 disable; + +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"); + +return 0 ; +} +static int __devinit ricoh_mmc_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -61,26 +101,12 @@ static int __devinit ricoh_mmc_probe(strwhile ((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"); +if (ricoh_mmc_disable (fw_dev) !=0 ) {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 ; } }
@@ -96,30 +122,51 @@ static int __devinit ricoh_mmc_probe(str 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"); +ricoh_mmc_enable (fw_dev);pci_set_drvdata (pdev,NULL ); } +static int ricoh_mmc_suspend (struct pci_dev *pdev,pm_message_t state) +{ +struct pci_dev *fw_dev =NULL ; + + fw_dev =pci_get_drvdata (pdev); +BUG_ON (fw_dev ==NULL ); + + printk(KERN_INFO DRIVER_NAME ": Suspending.\n"); + +ricoh_mmc_enable (fw_dev); + +return 0 ; +} + +static int ricoh_mmc_resume (struct pci_dev *pdev) +{ +struct pci_dev *fw_dev =NULL ; + + fw_dev =pci_get_drvdata (pdev); +BUG_ON (fw_dev ==NULL ); + + printk(KERN_INFO DRIVER_NAME ": Resuming.\n"); + +ricoh_mmc_disable (fw_dev); + +return 0 ; +} +static struct pci_driver ricoh_mmc_driver = { .name =DRIVER_NAME , .id_table = pci_ids, .probe = ricoh_mmc_probe, .remove =__devexit_p (ricoh_mmc_remove), + .suspend = ricoh_mmc_suspend, + .resume = ricoh_mmc_resume, };/*****************************************************************************\
Re: [PATCH] mmc: Handle suspend/resume in Ricoh MMC disabler (resent refreshed)
Quoted 145 lines · Frank Seidel
From: Philip Langdale <[email protected]>
As pci config space is reinitialised on suspend/resume cycle, the disabler needs to work its magic at resume time. For symmetry this change also explicitly enables the controller at suspend time but it's not strictly necessary.
Signed-off-by Philip Langdale <[email protected]>Signed-off-by Frank Seidel <[email protected]>--- drivers/mmc/host/ricoh_mmc.c | 97 +++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 25 deletions(-)drivers/mmc/host/ricoh_mmc.c +41
-15@@ -41,6 +41,46 @@ static const struct pci_device_id pci_idMODULE_DEVICE_TABLE (pci, pci_ids); +static int ricoh_mmc_disable (struct pci_dev *fw_dev) +{ +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); + + printk(KERN_INFO DRIVER_NAME + ": Controller is now disabled.\n"); + +return 0 ; +} + +static int ricoh_mmc_enable (struct pci_dev *fw_dev) +{ +u8 write_enable; +u8 disable; + +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"); + +return 0 ; +} +static int __devinit ricoh_mmc_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {@@ -61,26 +101,12 @@ static int __devinit ricoh_mmc_probe(strwhile ((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"); +if (ricoh_mmc_disable (fw_dev) !=0 ) {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 ; }drivers/mmc/host/ricoh_mmc.c +29
-10}@@ -96,30 +122,51 @@ static int __devinit ricoh_mmc_probe(str 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"); +ricoh_mmc_enable (fw_dev);pci_set_drvdata (pdev,NULL ); } +static int ricoh_mmc_suspend (struct pci_dev *pdev,pm_message_t state) +{ +struct pci_dev *fw_dev =NULL ; + + fw_dev =pci_get_drvdata (pdev); +BUG_ON (fw_dev ==NULL ); + + printk(KERN_INFO DRIVER_NAME ": Suspending.\n"); + +ricoh_mmc_enable (fw_dev); + +return 0 ; +} + +static int ricoh_mmc_resume (struct pci_dev *pdev) +{ +struct pci_dev *fw_dev =NULL ; + + fw_dev =pci_get_drvdata (pdev); +BUG_ON (fw_dev ==NULL ); + + printk(KERN_INFO DRIVER_NAME ": Resuming.\n"); + +ricoh_mmc_disable (fw_dev); + +return 0 ; +} +
drivers/mmc/host/ricoh_mmc.c static int __devinit ricoh_mmc_probe(str · line 172
Quoted 10 lines
drivers/mmc/host/ricoh_mmc.c +2
-0static struct pci_driver ricoh_mmc_driver = { .name =DRIVER_NAME , .id_table = pci_ids, .probe = ricoh_mmc_probe, .remove =__devexit_p (ricoh_mmc_remove), + .suspend = ricoh_mmc_suspend, + .resume = ricoh_mmc_resume, };
/*****************************************************************************\
ACK.
Thanks for fixing it up.
--phil
PATCH v2 1/1 mmc: extend ricoh_mmc to support Ricoh RL5c476
In reply to Philip LangdaleFrom: Frank Seidel <[email protected]>
This patch (base on current linus git tree plus Philip Langdales suspend/resume patch) adds support for the Ricoh RL5c476 chip:
with this the mmc adapter that needs this disabler (R5C843) can also be handled correctly when it sits on a RL5c476. (+ minor style changes (removed spaces between function names and open parenthesis .. checkpatch warned from previos patch))
--- drivers/mmc/host/ricoh_mmc.c | 101 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 21 deletions(-)
drivers/mmc/host/ricoh_mmc.c +80 -21
@@ -44,19 +44,43 @@ MODULE_DEVICE_TABLE(pci, pci_ids);static int ricoh_mmc_disable (struct pci_dev *fw_dev) {u8 write_enable; +u8 write_target;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 ; - } +if (fw_dev->device ==PCI_DEVICE_ID_RICOH_RL5C476 ) { +/* via RL5C476 */ + +pci_read_config_byte (fw_dev,0xB7 , &disable); +if (disable &0x02 ) { + printk(KERN_INFO DRIVER_NAME +": Controller already disabled. " \ + "Nothing to do.\n"); +return -ENODEV ; + } + +pci_read_config_byte (fw_dev,0x8E , &write_enable); +pci_write_config_byte (fw_dev,0x8E ,0xAA ); +pci_read_config_byte (fw_dev,0x8D , &write_target); +pci_write_config_byte (fw_dev,0x8D ,0xB7 ); +pci_write_config_byte (fw_dev,0xB7 , disable |0x02 ); +pci_write_config_byte (fw_dev,0x8E , write_enable); +pci_write_config_byte (fw_dev,0x8D , write_target); + }else { +/* via R5C832 */ + +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_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); + } printk(KERN_INFO DRIVER_NAME ": Controller is now disabled.\n");
@@ -67,13 +91,29 @@ static int ricoh_mmc_disable(struct pci_static int ricoh_mmc_enable (struct pci_dev *fw_dev) {u8 write_enable; +u8 write_target;u8 disable; -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); +if (fw_dev->device ==PCI_DEVICE_ID_RICOH_RL5C476 ) { +/* via RL5C476 */ + +pci_read_config_byte (fw_dev,0x8E , &write_enable); +pci_write_config_byte (fw_dev,0x8E ,0xAA ); +pci_read_config_byte (fw_dev,0x8D , &write_target); +pci_write_config_byte (fw_dev,0x8D ,0xB7 ); +pci_read_config_byte (fw_dev,0xB7 , &disable); +pci_write_config_byte (fw_dev,0xB7 , disable & ~0x02 ); +pci_write_config_byte (fw_dev,0x8E , write_enable); +pci_write_config_byte (fw_dev,0x8D , write_target); + }else { +/* via R5C832 */ + +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");
@@ -85,6 +125,7 @@ static int __devinit ricoh_mmc_probe(str const struct pci_device_id *ent) {u8 rev; +u8 ctrlfound =0 ;struct pci_dev *fw_dev =NULL ;
@@ -98,20 +139,38 @@ static int __devinit ricoh_mmc_probe(strpci_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))) { +while ((fw_dev = +pci_get_device (PCI_VENDOR_ID_RICOH , +PCI_DEVICE_ID_RICOH_RL5C476 , fw_dev))) {if (PCI_SLOT (pdev->devfn) ==PCI_SLOT (fw_dev->devfn) && pdev->bus == fw_dev->bus) { -if (ricoh_mmc_disable (fw_dev) !=0 ) { +if (ricoh_mmc_disable (fw_dev) !=0 )return -ENODEV ; - }pci_set_drvdata (pdev, fw_dev); + ++ctrlfound;break ; } } -if (pci_get_drvdata (pdev) ==NULL ) { + fw_dev =NULL ; + +while (!ctrlfound && + (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) { +if (ricoh_mmc_disable (fw_dev) !=0 ) +return -ENODEV ; + +pci_set_drvdata (pdev, fw_dev); + + ++ctrlfound; + } + } + +if (!ctrlfound) { printk(KERN_WARNING DRIVER_NAME ": Main firewire function not found. Cannot disable controller.\n");return -ENODEV ;
@@ -132,7 +191,7 @@ static void __devexit ricoh_mmc_remove(spci_set_drvdata (pdev,NULL ); } -static int ricoh_mmc_suspend (struct pci_dev *pdev,pm_message_t state) +static int ricoh_mmc_suspend (struct pci_dev *pdev,pm_message_t state) {struct pci_dev *fw_dev =NULL ;
@@ -146,7 +205,7 @@ static int ricoh_mmc_suspend (struct pcireturn 0 ; } -static int ricoh_mmc_resume (struct pci_dev *pdev) +static int ricoh_mmc_resume (struct pci_dev *pdev) {struct pci_dev *fw_dev =NULL ;
Quoted 169 lines · Frank Seidel
From: Frank Seidel <[email protected]>
This patch (base on current linus git tree plus Philip Langdales suspend/resume patch) adds support for the Ricoh RL5c476 chip:
with this the mmc adapter that needs this disabler (R5C843) can also be handled correctly when it sits on a RL5c476. (+ minor style changes (removed spaces between function names and open parenthesis .. checkpatch warned from previos patch))Signed-off-by Frank Seidel <[email protected]>--- drivers/mmc/host/ricoh_mmc.c | 101 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 21 deletions(-)drivers/mmc/host/ricoh_mmc.c +78
-19@@ -44,19 +44,43 @@ MODULE_DEVICE_TABLE(pci, pci_ids);static int ricoh_mmc_disable (struct pci_dev *fw_dev) {u8 write_enable; +u8 write_target;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 ; - } +if (fw_dev->device ==PCI_DEVICE_ID_RICOH_RL5C476 ) { +/* via RL5C476 */ + +pci_read_config_byte (fw_dev,0xB7 , &disable); +if (disable &0x02 ) { + printk(KERN_INFO DRIVER_NAME +": Controller already disabled. " \ + "Nothing to do.\n"); +return -ENODEV ; + } + +pci_read_config_byte (fw_dev,0x8E , &write_enable); +pci_write_config_byte (fw_dev,0x8E ,0xAA ); +pci_read_config_byte (fw_dev,0x8D , &write_target); +pci_write_config_byte (fw_dev,0x8D ,0xB7 ); +pci_write_config_byte (fw_dev,0xB7 , disable |0x02 ); +pci_write_config_byte (fw_dev,0x8E , write_enable); +pci_write_config_byte (fw_dev,0x8D , write_target); + }else { +/* via R5C832 */ + +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_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); + } printk(KERN_INFO DRIVER_NAME ": Controller is now disabled.\n");@@ -67,13 +91,29 @@ static int ricoh_mmc_disable(struct pci_static int ricoh_mmc_enable (struct pci_dev *fw_dev) {u8 write_enable; +u8 write_target;u8 disable; -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); +if (fw_dev->device ==PCI_DEVICE_ID_RICOH_RL5C476 ) { +/* via RL5C476 */ + +pci_read_config_byte (fw_dev,0x8E , &write_enable); +pci_write_config_byte (fw_dev,0x8E ,0xAA ); +pci_read_config_byte (fw_dev,0x8D , &write_target); +pci_write_config_byte (fw_dev,0x8D ,0xB7 ); +pci_read_config_byte (fw_dev,0xB7 , &disable); +pci_write_config_byte (fw_dev,0xB7 , disable & ~0x02 ); +pci_write_config_byte (fw_dev,0x8E , write_enable); +pci_write_config_byte (fw_dev,0x8D , write_target); + }else { +/* via R5C832 */ + +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");@@ -85,6 +125,7 @@ static int __devinit ricoh_mmc_probe(str const struct pci_device_id *ent) {u8 rev; +u8 ctrlfound =0 ;struct pci_dev *fw_dev =NULL ;@@ -98,20 +139,38 @@ static int __devinit ricoh_mmc_probe(strpci_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))) { +while ((fw_dev = +pci_get_device (PCI_VENDOR_ID_RICOH , +PCI_DEVICE_ID_RICOH_RL5C476 , fw_dev))) {if (PCI_SLOT (pdev->devfn) ==PCI_SLOT (fw_dev->devfn) && pdev->bus == fw_dev->bus) { -if (ricoh_mmc_disable (fw_dev) !=0 ) { +if (ricoh_mmc_disable (fw_dev) !=0 )return -ENODEV ; - }pci_set_drvdata (pdev, fw_dev); + ++ctrlfound;break ; } } -if (pci_get_drvdata (pdev) ==NULL ) { + fw_dev =NULL ; + +while (!ctrlfound && + (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) { +if (ricoh_mmc_disable (fw_dev) !=0 ) +return -ENODEV ; + +pci_set_drvdata (pdev, fw_dev); + + ++ctrlfound; + } + } + +if (!ctrlfound) { printk(KERN_WARNING DRIVER_NAME ": Main firewire function not found. Cannot disablecontroller.\n");
drivers/mmc/host/ricoh_mmc.c +1
-1return -ENODEV ;@@ -132,7 +191,7 @@ static void __devexit ricoh_mmc_remove(spci_set_drvdata (pdev,NULL ); } -static int ricoh_mmc_suspend (struct pci_dev *pdev,pm_message_t state) +static int ricoh_mmc_suspend (struct pci_dev *pdev,pm_message_t state) {struct pci_dev *fw_dev =NULL ;
drivers/mmc/host/ricoh_mmc.c static int ricoh_mmc_suspend (struct pci · line 210
Quoted 7 lines
drivers/mmc/host/ricoh_mmc.c +1
-1@@ -146,7 +205,7 @@ static int ricoh_mmc_suspend (struct pcireturn 0 ; } -static int ricoh_mmc_resume (struct pci_dev *pdev) +static int ricoh_mmc_resume (struct pci_dev *pdev) {struct pci_dev *fw_dev =NULL ;
ACK.
Hopefully Pierre will re-emerge soon to accept this into his tree.
--phil
Quoted 10 lines · On Mon, 4 Feb 2008 19:25:42 +0100 Frank Seidel <[email protected]> wrote:
From: Frank Seidel <[email protected]>
This patch (base on current linus git tree plus Philip Langdales suspend/resume patch) adds support for the Ricoh RL5c476 chip:
with this the mmc adapter that needs this disabler (R5C843) can also be handled correctly when it sits on a RL5c476. (+ minor style changes (removed spaces between function names and open parenthesis .. checkpatch warned from previos patch))Signed-off-by Frank Seidel <[email protected]>
I see you've guys have kept yourself busy in my absence. :)
As for the patch, it looks ok although I'm not really a fan of more voodoo constants that noone knows what they mean. Could you add some comments explaining some of them at least?
Review
Quoted 1 line
(quoted diff) +1
-0+ if (fw_dev->device == PCI_DEVICE_ID_RICOH_RL5C476) {
*snip*
Review
Quoted 2 lines
(quoted diff) +2
-0+ } else { + /* via R5C832 */
Wouldn't it be prudent to have a check that this is indeed a R5C832, and a failure mode if it's none of the two known devices?
Rgds
Pierre
Hi,
Quoted 5 lines · Pierre Ossman
Quoted 1 line · On Mon, 4 Feb 2008 19:25:42 +0100 Frank Seidel <[email protected]> wrote:
Signed-off-by Frank Seidel <[email protected]>I see you've guys have kept yourself busy in my absence. :)
Yes, we really did :)
Quoted 3 lines
As for the patch, it looks ok although I'm not really a fan of more voodoo constants that noone knows what they mean. Could you add some comments explaining some of them at least?
I also don't like that voodoo, but as long as we don't have more information or let alone specs.. well, i really wish i could provide more than the already IMHO obvious sequence.. voodoo-adress and value to make config bit writeable, set voodo-bit and cleanup again.
Quoted 9 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if (fw_dev->device == PCI_DEVICE_ID_RICOH_RL5C476) {*snip*
Review
Quoted 2 lines
(quoted diff) +2
-0+ } else { + /* via R5C832 */Wouldn't it be prudent to have a check that this is indeed a R5C832, and a failure mode if it's none of the two known devices?
Also thought about that, but as far as i can see this cannot happen since we only probe for those two devices and deny to continue if anything else /those two were not found in the beginning.
Thanks,
Frank
Quoted 8 lines · On Thu, 7 Feb 2008 09:20:38 +0100 Frank Seidel <[email protected]> wrote:
Quoted 3 lines
Wouldn't it be prudent to have a check that this is indeed a R5C832, and a failure mode if it's none of the two known devices?
Also thought about that, but as far as i can see this cannot happen since we only probe for those two devices and deny to continue if anything else /those two were not found in the beginning.
Can never be too careful though. :)
I've applied the patch for now. Feel free to keep digging and finding some docs for those regs though.
Rgds
Pierre