diff options
author | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2008-03-01 06:36:42 -0500 |
---|---|---|
committer | Stefan Richter <stefanr@s5r6.in-berlin.de> | 2008-04-18 11:55:30 -0400 |
commit | b25d166616ea30adedee70d99c40ba82d126d7cb (patch) | |
tree | e9729780e2dd075638ad6fd769de92e9015729d6 /drivers | |
parent | 38275ac36d60882db750d6301ef507881b4c8420 (diff) |
ieee1394: ohci1394: refactor probe, remove, suspend, resume
Clean up shared code and variable names.
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ieee1394/ohci1394.c | 113 |
1 files changed, 49 insertions, 64 deletions
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index b4cad9f45862..29b891084ca7 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c | |||
@@ -2993,15 +2993,9 @@ do { \ | |||
2993 | return err; \ | 2993 | return err; \ |
2994 | } while (0) | 2994 | } while (0) |
2995 | 2995 | ||
2996 | static int __devinit ohci1394_pci_probe(struct pci_dev *dev, | ||
2997 | const struct pci_device_id *ent) | ||
2998 | { | ||
2999 | struct hpsb_host *host; | ||
3000 | struct ti_ohci *ohci; /* shortcut to currently handled device */ | ||
3001 | resource_size_t ohci_base; | ||
3002 | |||
3003 | #ifdef CONFIG_PPC_PMAC | 2996 | #ifdef CONFIG_PPC_PMAC |
3004 | /* Necessary on some machines if ohci1394 was loaded/ unloaded before */ | 2997 | static void ohci1394_pmac_on(struct pci_dev *dev) |
2998 | { | ||
3005 | if (machine_is(powermac)) { | 2999 | if (machine_is(powermac)) { |
3006 | struct device_node *ofn = pci_device_to_OF_node(dev); | 3000 | struct device_node *ofn = pci_device_to_OF_node(dev); |
3007 | 3001 | ||
@@ -3010,8 +3004,32 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev, | |||
3010 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1); | 3004 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1); |
3011 | } | 3005 | } |
3012 | } | 3006 | } |
3007 | } | ||
3008 | |||
3009 | static void ohci1394_pmac_off(struct pci_dev *dev) | ||
3010 | { | ||
3011 | if (machine_is(powermac)) { | ||
3012 | struct device_node *ofn = pci_device_to_OF_node(dev); | ||
3013 | |||
3014 | if (ofn) { | ||
3015 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0); | ||
3016 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0); | ||
3017 | } | ||
3018 | } | ||
3019 | } | ||
3020 | #else | ||
3021 | #define ohci1394_pmac_on(dev) | ||
3022 | #define ohci1394_pmac_off(dev) | ||
3013 | #endif /* CONFIG_PPC_PMAC */ | 3023 | #endif /* CONFIG_PPC_PMAC */ |
3014 | 3024 | ||
3025 | static int __devinit ohci1394_pci_probe(struct pci_dev *dev, | ||
3026 | const struct pci_device_id *ent) | ||
3027 | { | ||
3028 | struct hpsb_host *host; | ||
3029 | struct ti_ohci *ohci; /* shortcut to currently handled device */ | ||
3030 | resource_size_t ohci_base; | ||
3031 | |||
3032 | ohci1394_pmac_on(dev); | ||
3015 | if (pci_enable_device(dev)) | 3033 | if (pci_enable_device(dev)) |
3016 | FAIL(-ENXIO, "Failed to enable OHCI hardware"); | 3034 | FAIL(-ENXIO, "Failed to enable OHCI hardware"); |
3017 | pci_set_master(dev); | 3035 | pci_set_master(dev); |
@@ -3203,16 +3221,16 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev, | |||
3203 | #undef FAIL | 3221 | #undef FAIL |
3204 | } | 3222 | } |
3205 | 3223 | ||
3206 | static void ohci1394_pci_remove(struct pci_dev *pdev) | 3224 | static void ohci1394_pci_remove(struct pci_dev *dev) |
3207 | { | 3225 | { |
3208 | struct ti_ohci *ohci; | 3226 | struct ti_ohci *ohci; |
3209 | struct device *dev; | 3227 | struct device *device; |
3210 | 3228 | ||
3211 | ohci = pci_get_drvdata(pdev); | 3229 | ohci = pci_get_drvdata(dev); |
3212 | if (!ohci) | 3230 | if (!ohci) |
3213 | return; | 3231 | return; |
3214 | 3232 | ||
3215 | dev = get_device(&ohci->host->device); | 3233 | device = get_device(&ohci->host->device); |
3216 | 3234 | ||
3217 | switch (ohci->init_state) { | 3235 | switch (ohci->init_state) { |
3218 | case OHCI_INIT_DONE: | 3236 | case OHCI_INIT_DONE: |
@@ -3246,7 +3264,7 @@ static void ohci1394_pci_remove(struct pci_dev *pdev) | |||
3246 | /* Soft reset before we start - this disables | 3264 | /* Soft reset before we start - this disables |
3247 | * interrupts and clears linkEnable and LPS. */ | 3265 | * interrupts and clears linkEnable and LPS. */ |
3248 | ohci_soft_reset(ohci); | 3266 | ohci_soft_reset(ohci); |
3249 | free_irq(ohci->dev->irq, ohci); | 3267 | free_irq(dev->irq, ohci); |
3250 | 3268 | ||
3251 | case OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE: | 3269 | case OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE: |
3252 | /* The ohci_soft_reset() stops all DMA contexts, so we | 3270 | /* The ohci_soft_reset() stops all DMA contexts, so we |
@@ -3257,12 +3275,12 @@ static void ohci1394_pci_remove(struct pci_dev *pdev) | |||
3257 | free_dma_trm_ctx(&ohci->at_resp_context); | 3275 | free_dma_trm_ctx(&ohci->at_resp_context); |
3258 | 3276 | ||
3259 | case OHCI_INIT_HAVE_SELFID_BUFFER: | 3277 | case OHCI_INIT_HAVE_SELFID_BUFFER: |
3260 | pci_free_consistent(ohci->dev, OHCI1394_SI_DMA_BUF_SIZE, | 3278 | pci_free_consistent(dev, OHCI1394_SI_DMA_BUF_SIZE, |
3261 | ohci->selfid_buf_cpu, | 3279 | ohci->selfid_buf_cpu, |
3262 | ohci->selfid_buf_bus); | 3280 | ohci->selfid_buf_bus); |
3263 | 3281 | ||
3264 | case OHCI_INIT_HAVE_CONFIG_ROM_BUFFER: | 3282 | case OHCI_INIT_HAVE_CONFIG_ROM_BUFFER: |
3265 | pci_free_consistent(ohci->dev, OHCI_CONFIG_ROM_LEN, | 3283 | pci_free_consistent(dev, OHCI_CONFIG_ROM_LEN, |
3266 | ohci->csr_config_rom_cpu, | 3284 | ohci->csr_config_rom_cpu, |
3267 | ohci->csr_config_rom_bus); | 3285 | ohci->csr_config_rom_bus); |
3268 | 3286 | ||
@@ -3270,35 +3288,24 @@ static void ohci1394_pci_remove(struct pci_dev *pdev) | |||
3270 | iounmap(ohci->registers); | 3288 | iounmap(ohci->registers); |
3271 | 3289 | ||
3272 | case OHCI_INIT_HAVE_MEM_REGION: | 3290 | case OHCI_INIT_HAVE_MEM_REGION: |
3273 | release_mem_region(pci_resource_start(ohci->dev, 0), | 3291 | release_mem_region(pci_resource_start(dev, 0), |
3274 | OHCI1394_REGISTER_SIZE); | 3292 | OHCI1394_REGISTER_SIZE); |
3275 | 3293 | ||
3276 | #ifdef CONFIG_PPC_PMAC | 3294 | ohci1394_pmac_off(dev); |
3277 | /* On UniNorth, power down the cable and turn off the chip clock | ||
3278 | * to save power on laptops */ | ||
3279 | if (machine_is(powermac)) { | ||
3280 | struct device_node* ofn = pci_device_to_OF_node(ohci->dev); | ||
3281 | |||
3282 | if (ofn) { | ||
3283 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0); | ||
3284 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0); | ||
3285 | } | ||
3286 | } | ||
3287 | #endif /* CONFIG_PPC_PMAC */ | ||
3288 | 3295 | ||
3289 | case OHCI_INIT_ALLOC_HOST: | 3296 | case OHCI_INIT_ALLOC_HOST: |
3290 | pci_set_drvdata(ohci->dev, NULL); | 3297 | pci_set_drvdata(dev, NULL); |
3291 | } | 3298 | } |
3292 | 3299 | ||
3293 | if (dev) | 3300 | if (device) |
3294 | put_device(dev); | 3301 | put_device(device); |
3295 | } | 3302 | } |
3296 | 3303 | ||
3297 | #ifdef CONFIG_PM | 3304 | #ifdef CONFIG_PM |
3298 | static int ohci1394_pci_suspend(struct pci_dev *pdev, pm_message_t state) | 3305 | static int ohci1394_pci_suspend(struct pci_dev *dev, pm_message_t state) |
3299 | { | 3306 | { |
3300 | int err; | 3307 | int err; |
3301 | struct ti_ohci *ohci = pci_get_drvdata(pdev); | 3308 | struct ti_ohci *ohci = pci_get_drvdata(dev); |
3302 | 3309 | ||
3303 | if (!ohci) { | 3310 | if (!ohci) { |
3304 | printk(KERN_ERR "%s: tried to suspend nonexisting host\n", | 3311 | printk(KERN_ERR "%s: tried to suspend nonexisting host\n", |
@@ -3326,34 +3333,23 @@ static int ohci1394_pci_suspend(struct pci_dev *pdev, pm_message_t state) | |||
3326 | ohci_devctl(ohci->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT); | 3333 | ohci_devctl(ohci->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT); |
3327 | ohci_soft_reset(ohci); | 3334 | ohci_soft_reset(ohci); |
3328 | 3335 | ||
3329 | err = pci_save_state(pdev); | 3336 | err = pci_save_state(dev); |
3330 | if (err) { | 3337 | if (err) { |
3331 | PRINT(KERN_ERR, "pci_save_state failed with %d", err); | 3338 | PRINT(KERN_ERR, "pci_save_state failed with %d", err); |
3332 | return err; | 3339 | return err; |
3333 | } | 3340 | } |
3334 | err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); | 3341 | err = pci_set_power_state(dev, pci_choose_state(dev, state)); |
3335 | if (err) | 3342 | if (err) |
3336 | DBGMSG("pci_set_power_state failed with %d", err); | 3343 | DBGMSG("pci_set_power_state failed with %d", err); |
3337 | 3344 | ohci1394_pmac_off(dev); | |
3338 | /* PowerMac suspend code comes last */ | ||
3339 | #ifdef CONFIG_PPC_PMAC | ||
3340 | if (machine_is(powermac)) { | ||
3341 | struct device_node *ofn = pci_device_to_OF_node(pdev); | ||
3342 | |||
3343 | if (ofn) { | ||
3344 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 0); | ||
3345 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 0); | ||
3346 | } | ||
3347 | } | ||
3348 | #endif /* CONFIG_PPC_PMAC */ | ||
3349 | 3345 | ||
3350 | return 0; | 3346 | return 0; |
3351 | } | 3347 | } |
3352 | 3348 | ||
3353 | static int ohci1394_pci_resume(struct pci_dev *pdev) | 3349 | static int ohci1394_pci_resume(struct pci_dev *dev) |
3354 | { | 3350 | { |
3355 | int err; | 3351 | int err; |
3356 | struct ti_ohci *ohci = pci_get_drvdata(pdev); | 3352 | struct ti_ohci *ohci = pci_get_drvdata(dev); |
3357 | 3353 | ||
3358 | if (!ohci) { | 3354 | if (!ohci) { |
3359 | printk(KERN_ERR "%s: tried to resume nonexisting host\n", | 3355 | printk(KERN_ERR "%s: tried to resume nonexisting host\n", |
@@ -3362,21 +3358,10 @@ static int ohci1394_pci_resume(struct pci_dev *pdev) | |||
3362 | } | 3358 | } |
3363 | DBGMSG("resume called"); | 3359 | DBGMSG("resume called"); |
3364 | 3360 | ||
3365 | /* PowerMac resume code comes first */ | 3361 | ohci1394_pmac_on(dev); |
3366 | #ifdef CONFIG_PPC_PMAC | 3362 | pci_set_power_state(dev, PCI_D0); |
3367 | if (machine_is(powermac)) { | 3363 | pci_restore_state(dev); |
3368 | struct device_node *ofn = pci_device_to_OF_node(pdev); | 3364 | err = pci_enable_device(dev); |
3369 | |||
3370 | if (ofn) { | ||
3371 | pmac_call_feature(PMAC_FTR_1394_CABLE_POWER, ofn, 0, 1); | ||
3372 | pmac_call_feature(PMAC_FTR_1394_ENABLE, ofn, 0, 1); | ||
3373 | } | ||
3374 | } | ||
3375 | #endif /* CONFIG_PPC_PMAC */ | ||
3376 | |||
3377 | pci_set_power_state(pdev, PCI_D0); | ||
3378 | pci_restore_state(pdev); | ||
3379 | err = pci_enable_device(pdev); | ||
3380 | if (err) { | 3365 | if (err) { |
3381 | PRINT(KERN_ERR, "pci_enable_device failed with %d", err); | 3366 | PRINT(KERN_ERR, "pci_enable_device failed with %d", err); |
3382 | return err; | 3367 | return err; |