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