denali_pci.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "denali.h"
  18. #define DENALI_NAND_NAME "denali-nand-pci"
  19. /* List of platforms this NAND controller has be integrated into */
  20. static const struct pci_device_id denali_pci_ids[] = {
  21. { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
  22. { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
  23. { /* end: all zeroes */ }
  24. };
  25. MODULE_DEVICE_TABLE(pci, denali_pci_ids);
  26. static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  27. {
  28. int ret;
  29. resource_size_t csr_base, mem_base;
  30. unsigned long csr_len, mem_len;
  31. struct denali_nand_info *denali;
  32. denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
  33. if (!denali)
  34. return -ENOMEM;
  35. ret = pcim_enable_device(dev);
  36. if (ret) {
  37. dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
  38. return ret;
  39. }
  40. if (id->driver_data == INTEL_CE4100) {
  41. denali->platform = INTEL_CE4100;
  42. mem_base = pci_resource_start(dev, 0);
  43. mem_len = pci_resource_len(dev, 1);
  44. csr_base = pci_resource_start(dev, 1);
  45. csr_len = pci_resource_len(dev, 1);
  46. } else {
  47. denali->platform = INTEL_MRST;
  48. csr_base = pci_resource_start(dev, 0);
  49. csr_len = pci_resource_len(dev, 0);
  50. mem_base = pci_resource_start(dev, 1);
  51. mem_len = pci_resource_len(dev, 1);
  52. if (!mem_len) {
  53. mem_base = csr_base + csr_len;
  54. mem_len = csr_len;
  55. }
  56. }
  57. pci_set_master(dev);
  58. denali->dev = &dev->dev;
  59. denali->irq = dev->irq;
  60. ret = pci_request_regions(dev, DENALI_NAND_NAME);
  61. if (ret) {
  62. dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
  63. return ret;
  64. }
  65. denali->flash_reg = ioremap_nocache(csr_base, csr_len);
  66. if (!denali->flash_reg) {
  67. dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
  68. return -ENOMEM;
  69. }
  70. denali->flash_mem = ioremap_nocache(mem_base, mem_len);
  71. if (!denali->flash_mem) {
  72. dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
  73. ret = -ENOMEM;
  74. goto failed_remap_reg;
  75. }
  76. ret = denali_init(denali);
  77. if (ret)
  78. goto failed_remap_mem;
  79. pci_set_drvdata(dev, denali);
  80. return 0;
  81. failed_remap_mem:
  82. iounmap(denali->flash_mem);
  83. failed_remap_reg:
  84. iounmap(denali->flash_reg);
  85. return ret;
  86. }
  87. /* driver exit point */
  88. static void denali_pci_remove(struct pci_dev *dev)
  89. {
  90. struct denali_nand_info *denali = pci_get_drvdata(dev);
  91. denali_remove(denali);
  92. iounmap(denali->flash_reg);
  93. iounmap(denali->flash_mem);
  94. }
  95. static struct pci_driver denali_pci_driver = {
  96. .name = DENALI_NAND_NAME,
  97. .id_table = denali_pci_ids,
  98. .probe = denali_pci_probe,
  99. .remove = denali_pci_remove,
  100. };
  101. module_pci_driver(denali_pci_driver);