denali_pci.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * NAND Flash Controller Device Driver
  3. * Copyright © 2009-2010, Intel Corporation and its suppliers.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include "denali.h"
  19. #define DENALI_NAND_NAME "denali-nand-pci"
  20. /* List of platforms this NAND controller has be integrated into */
  21. static const struct pci_device_id denali_pci_ids[] = {
  22. { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
  23. { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
  24. { /* end: all zeroes */ }
  25. };
  26. MODULE_DEVICE_TABLE(pci, denali_pci_ids);
  27. static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  28. {
  29. int ret;
  30. resource_size_t csr_base, mem_base;
  31. unsigned long csr_len, mem_len;
  32. struct denali_nand_info *denali;
  33. denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
  34. if (!denali)
  35. return -ENOMEM;
  36. ret = pcim_enable_device(dev);
  37. if (ret) {
  38. dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
  39. return ret;
  40. }
  41. if (id->driver_data == INTEL_CE4100) {
  42. denali->platform = INTEL_CE4100;
  43. mem_base = pci_resource_start(dev, 0);
  44. mem_len = pci_resource_len(dev, 1);
  45. csr_base = pci_resource_start(dev, 1);
  46. csr_len = pci_resource_len(dev, 1);
  47. } else {
  48. denali->platform = INTEL_MRST;
  49. csr_base = pci_resource_start(dev, 0);
  50. csr_len = pci_resource_len(dev, 0);
  51. mem_base = pci_resource_start(dev, 1);
  52. mem_len = pci_resource_len(dev, 1);
  53. if (!mem_len) {
  54. mem_base = csr_base + csr_len;
  55. mem_len = csr_len;
  56. }
  57. }
  58. pci_set_master(dev);
  59. denali->dev = &dev->dev;
  60. denali->irq = dev->irq;
  61. ret = pci_request_regions(dev, DENALI_NAND_NAME);
  62. if (ret) {
  63. dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
  64. return ret;
  65. }
  66. denali->flash_reg = ioremap_nocache(csr_base, csr_len);
  67. if (!denali->flash_reg) {
  68. dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
  69. return -ENOMEM;
  70. }
  71. denali->flash_mem = ioremap_nocache(mem_base, mem_len);
  72. if (!denali->flash_mem) {
  73. dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
  74. ret = -ENOMEM;
  75. goto failed_remap_reg;
  76. }
  77. ret = denali_init(denali);
  78. if (ret)
  79. goto failed_remap_mem;
  80. pci_set_drvdata(dev, denali);
  81. return 0;
  82. failed_remap_mem:
  83. iounmap(denali->flash_mem);
  84. failed_remap_reg:
  85. iounmap(denali->flash_reg);
  86. return ret;
  87. }
  88. /* driver exit point */
  89. static void denali_pci_remove(struct pci_dev *dev)
  90. {
  91. struct denali_nand_info *denali = pci_get_drvdata(dev);
  92. denali_remove(denali);
  93. iounmap(denali->flash_reg);
  94. iounmap(denali->flash_mem);
  95. }
  96. static struct pci_driver denali_pci_driver = {
  97. .name = DENALI_NAND_NAME,
  98. .id_table = denali_pci_ids,
  99. .probe = denali_pci_probe,
  100. .remove = denali_pci_remove,
  101. };
  102. module_pci_driver(denali_pci_driver);
  103. MODULE_DESCRIPTION("PCI driver for Denali NAND controller");
  104. MODULE_AUTHOR("Intel Corporation and its suppliers");
  105. MODULE_LICENSE("GPL v2");