denali_pci.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #define INTEL_CE4100 1
  20. #define INTEL_MRST 2
  21. /* List of platforms this NAND controller has be integrated into */
  22. static const struct pci_device_id denali_pci_ids[] = {
  23. { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
  24. { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
  25. { /* end: all zeroes */ }
  26. };
  27. MODULE_DEVICE_TABLE(pci, denali_pci_ids);
  28. NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
  29. static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  30. {
  31. int ret;
  32. resource_size_t csr_base, mem_base;
  33. unsigned long csr_len, mem_len;
  34. struct denali_nand_info *denali;
  35. denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
  36. if (!denali)
  37. return -ENOMEM;
  38. ret = pcim_enable_device(dev);
  39. if (ret) {
  40. dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
  41. return ret;
  42. }
  43. if (id->driver_data == INTEL_CE4100) {
  44. mem_base = pci_resource_start(dev, 0);
  45. mem_len = pci_resource_len(dev, 1);
  46. csr_base = pci_resource_start(dev, 1);
  47. csr_len = pci_resource_len(dev, 1);
  48. } else {
  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. denali->ecc_caps = &denali_pci_ecc_caps;
  62. denali->nand.ecc.options |= NAND_ECC_MAXIMIZE;
  63. denali->clk_x_rate = 200000000; /* 200 MHz */
  64. ret = pci_request_regions(dev, DENALI_NAND_NAME);
  65. if (ret) {
  66. dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
  67. return ret;
  68. }
  69. denali->reg = ioremap_nocache(csr_base, csr_len);
  70. if (!denali->reg) {
  71. dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
  72. return -ENOMEM;
  73. }
  74. denali->host = ioremap_nocache(mem_base, mem_len);
  75. if (!denali->host) {
  76. dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
  77. ret = -ENOMEM;
  78. goto failed_remap_reg;
  79. }
  80. ret = denali_init(denali);
  81. if (ret)
  82. goto failed_remap_mem;
  83. pci_set_drvdata(dev, denali);
  84. return 0;
  85. failed_remap_mem:
  86. iounmap(denali->host);
  87. failed_remap_reg:
  88. iounmap(denali->reg);
  89. return ret;
  90. }
  91. /* driver exit point */
  92. static void denali_pci_remove(struct pci_dev *dev)
  93. {
  94. struct denali_nand_info *denali = pci_get_drvdata(dev);
  95. denali_remove(denali);
  96. iounmap(denali->reg);
  97. iounmap(denali->host);
  98. }
  99. static struct pci_driver denali_pci_driver = {
  100. .name = DENALI_NAND_NAME,
  101. .id_table = denali_pci_ids,
  102. .probe = denali_pci_probe,
  103. .remove = denali_pci_remove,
  104. };
  105. module_pci_driver(denali_pci_driver);
  106. MODULE_DESCRIPTION("PCI driver for Denali NAND controller");
  107. MODULE_AUTHOR("Intel Corporation and its suppliers");
  108. MODULE_LICENSE("GPL v2");