aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-pci.c
diff options
context:
space:
mode:
authorEmmanuel Grumbach <emmanuel.grumbach@intel.com>2011-07-11 03:48:51 -0400
committerWey-Yi Guy <wey-yi.w.guy@intel.com>2011-07-21 10:29:55 -0400
commitd593411084a56124aa9d80aafa15db8463b2d8f7 (patch)
treecbe550ecb8e7c0a7700e0ed168f1553c25b3d183 /drivers/net/wireless/iwlwifi/iwl-pci.c
parent41c50542669cd7aec45ad708f5120ff8fdaa1194 (diff)
iwlagn: simplify the bus architecture
Call iwl_probe with a ready iwl_bus struct. This means that the bus layer assigns the irq, dev and iwl_bus_ops pointers to iwl_bus before giving it to iwl_probe. The device specific struct is allocated together with the common iwl_bus struct by the bus specific layer. The pointer to the aggregate struct is passed to the upper layer that holds a pointer to iwl_bus instead of an embedded iw_bus. The private data given to the PCI subsystem is now iwl_bus and not iwl_priv. Provide bus_* inliners on the way in order to simplify the syntax. Rename iwl-pci.h -> iwl-bus.h since it is bus agnostic and represent the external of the bus layer. Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com> Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-pci.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-pci.c64
1 files changed, 29 insertions, 35 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-pci.c b/drivers/net/wireless/iwlwifi/iwl-pci.c
index 74911348a2ee..66448895f7ba 100644
--- a/drivers/net/wireless/iwlwifi/iwl-pci.c
+++ b/drivers/net/wireless/iwlwifi/iwl-pci.c
@@ -63,11 +63,10 @@
63#include <linux/pci.h> 63#include <linux/pci.h>
64#include <linux/pci-aspm.h> 64#include <linux/pci-aspm.h>
65 65
66#include "iwl-pci.h" 66#include "iwl-bus.h"
67#include "iwl-agn.h" 67#include "iwl-agn.h"
68#include "iwl-core.h" 68#include "iwl-core.h"
69#include "iwl-io.h" 69#include "iwl-io.h"
70#include "iwl-trans.h"
71 70
72/* PCI registers */ 71/* PCI registers */
73#define PCI_CFG_RETRY_TIMEOUT 0x041 72#define PCI_CFG_RETRY_TIMEOUT 0x041
@@ -132,19 +131,9 @@ static void iwl_pci_apm_config(struct iwl_bus *bus)
132 } 131 }
133} 132}
134 133
135static void iwl_pci_set_drv_data(struct iwl_bus *bus, void *drv_priv) 134static void iwl_pci_set_drv_data(struct iwl_bus *bus, void *drv_data)
136{ 135{
137 pci_set_drvdata(IWL_BUS_GET_PCI_DEV(bus), drv_priv); 136 bus->priv = drv_data;
138}
139
140static struct device *iwl_pci_get_dev(const struct iwl_bus *bus)
141{
142 return &(IWL_BUS_GET_PCI_DEV(bus)->dev);
143}
144
145static unsigned int iwl_pci_get_irq(const struct iwl_bus *bus)
146{
147 return IWL_BUS_GET_PCI_DEV(bus)->irq;
148} 137}
149 138
150static void iwl_pci_get_hw_id(struct iwl_bus *bus, char buf[], 139static void iwl_pci_get_hw_id(struct iwl_bus *bus, char buf[],
@@ -176,8 +165,6 @@ static struct iwl_bus_ops pci_ops = {
176 .get_pm_support = iwl_pci_is_pm_supported, 165 .get_pm_support = iwl_pci_is_pm_supported,
177 .apm_config = iwl_pci_apm_config, 166 .apm_config = iwl_pci_apm_config,
178 .set_drv_data = iwl_pci_set_drv_data, 167 .set_drv_data = iwl_pci_set_drv_data,
179 .get_dev = iwl_pci_get_dev,
180 .get_irq = iwl_pci_get_irq,
181 .get_hw_id = iwl_pci_get_hw_id, 168 .get_hw_id = iwl_pci_get_hw_id,
182 .write8 = iwl_pci_write8, 169 .write8 = iwl_pci_write8,
183 .write32 = iwl_pci_write32, 170 .write32 = iwl_pci_write32,
@@ -383,18 +370,20 @@ MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
383static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 370static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
384{ 371{
385 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); 372 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
386 struct iwl_pci_bus *bus; 373 struct iwl_bus *bus;
374 struct iwl_pci_bus *pci_bus;
387 u16 pci_cmd; 375 u16 pci_cmd;
388 int err; 376 int err;
389 377
390 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 378 bus = kzalloc(sizeof(*bus) + sizeof(*pci_bus), GFP_KERNEL);
391 if (!bus) { 379 if (!bus) {
392 pr_err("Couldn't allocate iwl_pci_bus"); 380 pr_err("Couldn't allocate iwl_pci_bus");
393 err = -ENOMEM; 381 err = -ENOMEM;
394 goto out_no_pci; 382 goto out_no_pci;
395 } 383 }
396 384
397 bus->pci_dev = pdev; 385 pci_bus = IWL_BUS_GET_PCI_BUS(bus);
386 pci_bus->pci_dev = pdev;
398 387
399 /* W/A - seems to solve weird behavior. We need to remove this if we 388 /* W/A - seems to solve weird behavior. We need to remove this if we
400 * don't want to stay in L1 all the time. This wastes a lot of power */ 389 * don't want to stay in L1 all the time. This wastes a lot of power */
@@ -429,8 +418,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
429 goto out_pci_disable_device; 418 goto out_pci_disable_device;
430 } 419 }
431 420
432 bus->hw_base = pci_iomap(pdev, 0, 0); 421 pci_bus->hw_base = pci_iomap(pdev, 0, 0);
433 if (!bus->hw_base) { 422 if (!pci_bus->hw_base) {
434 pr_err("pci_iomap failed"); 423 pr_err("pci_iomap failed");
435 err = -ENODEV; 424 err = -ENODEV;
436 goto out_pci_release_regions; 425 goto out_pci_release_regions;
@@ -438,7 +427,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
438 427
439 pr_info("pci_resource_len = 0x%08llx\n", 428 pr_info("pci_resource_len = 0x%08llx\n",
440 (unsigned long long) pci_resource_len(pdev, 0)); 429 (unsigned long long) pci_resource_len(pdev, 0));
441 pr_info("pci_resource_base = %p\n", bus->hw_base); 430 pr_info("pci_resource_base = %p\n", pci_bus->hw_base);
442 431
443 pr_info("HW Revision ID = 0x%X\n", pdev->revision); 432 pr_info("HW Revision ID = 0x%X\n", pdev->revision);
444 433
@@ -460,7 +449,13 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
460 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); 449 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
461 } 450 }
462 451
463 err = iwl_probe((void *) bus, &pci_ops, cfg); 452 pci_set_drvdata(pdev, bus);
453
454 bus->dev = &pdev->dev;
455 bus->irq = pdev->irq;
456 bus->ops = &pci_ops;
457
458 err = iwl_probe(bus, cfg);
464 if (err) 459 if (err)
465 goto out_disable_msi; 460 goto out_disable_msi;
466 return 0; 461 return 0;
@@ -468,7 +463,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
468out_disable_msi: 463out_disable_msi:
469 pci_disable_msi(pdev); 464 pci_disable_msi(pdev);
470out_iounmap: 465out_iounmap:
471 pci_iounmap(pdev, bus->hw_base); 466 pci_iounmap(pdev, pci_bus->hw_base);
472out_pci_release_regions: 467out_pci_release_regions:
473 pci_set_drvdata(pdev, NULL); 468 pci_set_drvdata(pdev, NULL);
474 pci_release_regions(pdev); 469 pci_release_regions(pdev);
@@ -479,9 +474,9 @@ out_no_pci:
479 return err; 474 return err;
480} 475}
481 476
482static void iwl_pci_down(void *bus) 477static void iwl_pci_down(struct iwl_bus *bus)
483{ 478{
484 struct iwl_pci_bus *pci_bus = (struct iwl_pci_bus *) bus; 479 struct iwl_pci_bus *pci_bus = (struct iwl_pci_bus *) bus->bus_specific;
485 480
486 pci_disable_msi(pci_bus->pci_dev); 481 pci_disable_msi(pci_bus->pci_dev);
487 pci_iounmap(pci_bus->pci_dev, pci_bus->hw_base); 482 pci_iounmap(pci_bus->pci_dev, pci_bus->hw_base);
@@ -489,17 +484,16 @@ static void iwl_pci_down(void *bus)
489 pci_disable_device(pci_bus->pci_dev); 484 pci_disable_device(pci_bus->pci_dev);
490 pci_set_drvdata(pci_bus->pci_dev, NULL); 485 pci_set_drvdata(pci_bus->pci_dev, NULL);
491 486
492 kfree(pci_bus); 487 kfree(bus);
493} 488}
494 489
495static void __devexit iwl_pci_remove(struct pci_dev *pdev) 490static void __devexit iwl_pci_remove(struct pci_dev *pdev)
496{ 491{
497 struct iwl_priv *priv = pci_get_drvdata(pdev); 492 struct iwl_bus *bus = pci_get_drvdata(pdev);
498 void *bus_specific = priv->bus.bus_specific;
499 493
500 iwl_remove(priv); 494 iwl_remove(bus->priv);
501 495
502 iwl_pci_down(bus_specific); 496 iwl_pci_down(bus);
503} 497}
504 498
505#ifdef CONFIG_PM 499#ifdef CONFIG_PM
@@ -507,15 +501,15 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
507static int iwl_pci_suspend(struct device *device) 501static int iwl_pci_suspend(struct device *device)
508{ 502{
509 struct pci_dev *pdev = to_pci_dev(device); 503 struct pci_dev *pdev = to_pci_dev(device);
510 struct iwl_priv *priv = pci_get_drvdata(pdev); 504 struct iwl_bus *bus = pci_get_drvdata(pdev);
511 505
512 return iwl_suspend(priv); 506 return iwl_suspend(bus->priv);
513} 507}
514 508
515static int iwl_pci_resume(struct device *device) 509static int iwl_pci_resume(struct device *device)
516{ 510{
517 struct pci_dev *pdev = to_pci_dev(device); 511 struct pci_dev *pdev = to_pci_dev(device);
518 struct iwl_priv *priv = pci_get_drvdata(pdev); 512 struct iwl_bus *bus = pci_get_drvdata(pdev);
519 513
520 /* 514 /*
521 * We disable the RETRY_TIMEOUT register (0x41) to keep 515 * We disable the RETRY_TIMEOUT register (0x41) to keep
@@ -523,7 +517,7 @@ static int iwl_pci_resume(struct device *device)
523 */ 517 */
524 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); 518 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
525 519
526 return iwl_resume(priv); 520 return iwl_resume(bus->priv);
527} 521}
528 522
529static SIMPLE_DEV_PM_OPS(iwl_dev_pm_ops, iwl_pci_suspend, iwl_pci_resume); 523static SIMPLE_DEV_PM_OPS(iwl_dev_pm_ops, iwl_pci_suspend, iwl_pci_resume);