Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 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 | |
| 19 | #include "denali.h" |
| 20 | |
| 21 | #define DENALI_NAND_NAME "denali-nand-pci" |
| 22 | |
| 23 | /* List of platforms this NAND controller has be integrated into */ |
Jingoo Han | 94f7039 | 2013-12-03 08:18:28 +0900 | [diff] [blame] | 24 | static const struct pci_device_id denali_pci_ids[] = { |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 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 | |
| 31 | static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
| 32 | { |
Andy Shevchenko | add243d | 2015-08-06 16:04:23 +0300 | [diff] [blame] | 33 | int ret; |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 34 | resource_size_t csr_base, mem_base; |
| 35 | unsigned long csr_len, mem_len; |
| 36 | struct denali_nand_info *denali; |
| 37 | |
Andy Shevchenko | add243d | 2015-08-06 16:04:23 +0300 | [diff] [blame] | 38 | denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL); |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 39 | if (!denali) |
| 40 | return -ENOMEM; |
| 41 | |
Andy Shevchenko | add243d | 2015-08-06 16:04:23 +0300 | [diff] [blame] | 42 | ret = pcim_enable_device(dev); |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 43 | if (ret) { |
Andy Shevchenko | af83a67c | 2015-08-06 16:04:24 +0300 | [diff] [blame] | 44 | dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n"); |
Andy Shevchenko | add243d | 2015-08-06 16:04:23 +0300 | [diff] [blame] | 45 | return ret; |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | if (id->driver_data == INTEL_CE4100) { |
| 49 | denali->platform = INTEL_CE4100; |
| 50 | mem_base = pci_resource_start(dev, 0); |
| 51 | mem_len = pci_resource_len(dev, 1); |
| 52 | csr_base = pci_resource_start(dev, 1); |
| 53 | csr_len = pci_resource_len(dev, 1); |
| 54 | } else { |
| 55 | denali->platform = INTEL_MRST; |
| 56 | csr_base = pci_resource_start(dev, 0); |
| 57 | csr_len = pci_resource_len(dev, 0); |
| 58 | mem_base = pci_resource_start(dev, 1); |
| 59 | mem_len = pci_resource_len(dev, 1); |
| 60 | if (!mem_len) { |
| 61 | mem_base = csr_base + csr_len; |
| 62 | mem_len = csr_len; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | pci_set_master(dev); |
| 67 | denali->dev = &dev->dev; |
| 68 | denali->irq = dev->irq; |
| 69 | |
| 70 | ret = pci_request_regions(dev, DENALI_NAND_NAME); |
| 71 | if (ret) { |
Andy Shevchenko | af83a67c | 2015-08-06 16:04:24 +0300 | [diff] [blame] | 72 | dev_err(&dev->dev, "Spectra: Unable to request memory regions\n"); |
Andy Shevchenko | add243d | 2015-08-06 16:04:23 +0300 | [diff] [blame] | 73 | return ret; |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | denali->flash_reg = ioremap_nocache(csr_base, csr_len); |
| 77 | if (!denali->flash_reg) { |
Andy Shevchenko | af83a67c | 2015-08-06 16:04:24 +0300 | [diff] [blame] | 78 | dev_err(&dev->dev, "Spectra: Unable to remap memory region\n"); |
Andy Shevchenko | add243d | 2015-08-06 16:04:23 +0300 | [diff] [blame] | 79 | return -ENOMEM; |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | denali->flash_mem = ioremap_nocache(mem_base, mem_len); |
| 83 | if (!denali->flash_mem) { |
Andy Shevchenko | af83a67c | 2015-08-06 16:04:24 +0300 | [diff] [blame] | 84 | dev_err(&dev->dev, "Spectra: ioremap_nocache failed!"); |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 85 | ret = -ENOMEM; |
| 86 | goto failed_remap_reg; |
| 87 | } |
| 88 | |
| 89 | ret = denali_init(denali); |
| 90 | if (ret) |
| 91 | goto failed_remap_mem; |
| 92 | |
| 93 | pci_set_drvdata(dev, denali); |
| 94 | |
| 95 | return 0; |
| 96 | |
| 97 | failed_remap_mem: |
| 98 | iounmap(denali->flash_mem); |
| 99 | failed_remap_reg: |
| 100 | iounmap(denali->flash_reg); |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | /* driver exit point */ |
| 105 | static void denali_pci_remove(struct pci_dev *dev) |
| 106 | { |
| 107 | struct denali_nand_info *denali = pci_get_drvdata(dev); |
| 108 | |
| 109 | denali_remove(denali); |
| 110 | iounmap(denali->flash_reg); |
| 111 | iounmap(denali->flash_mem); |
Dinh Nguyen | 2a0a288 | 2012-09-27 10:58:05 -0600 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static struct pci_driver denali_pci_driver = { |
| 115 | .name = DENALI_NAND_NAME, |
| 116 | .id_table = denali_pci_ids, |
| 117 | .probe = denali_pci_probe, |
| 118 | .remove = denali_pci_remove, |
| 119 | }; |
| 120 | |
Andy Shevchenko | 2445d33 | 2015-08-06 16:04:22 +0300 | [diff] [blame] | 121 | module_pci_driver(denali_pci_driver); |