linux/drivers/mtd/nand/raw/denali_pci.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * NAND Flash Controller Device Driver
   4 * Copyright © 2009-2010, Intel Corporation and its suppliers.
   5 */
   6
   7#include <linux/errno.h>
   8#include <linux/io.h>
   9#include <linux/kernel.h>
  10#include <linux/module.h>
  11#include <linux/pci.h>
  12
  13#include "denali.h"
  14
  15#define DENALI_NAND_NAME    "denali-nand-pci"
  16
  17#define INTEL_CE4100    1
  18#define INTEL_MRST      2
  19
  20/* List of platforms this NAND controller has be integrated into */
  21static 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};
  26MODULE_DEVICE_TABLE(pci, denali_pci_ids);
  27
  28NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
  29
  30static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  31{
  32        int ret;
  33        resource_size_t csr_base, mem_base;
  34        unsigned long csr_len, mem_len;
  35        struct denali_nand_info *denali;
  36
  37        denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
  38        if (!denali)
  39                return -ENOMEM;
  40
  41        ret = pcim_enable_device(dev);
  42        if (ret) {
  43                dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
  44                return ret;
  45        }
  46
  47        if (id->driver_data == INTEL_CE4100) {
  48                mem_base = pci_resource_start(dev, 0);
  49                mem_len = pci_resource_len(dev, 1);
  50                csr_base = pci_resource_start(dev, 1);
  51                csr_len = pci_resource_len(dev, 1);
  52        } else {
  53                csr_base = pci_resource_start(dev, 0);
  54                csr_len = pci_resource_len(dev, 0);
  55                mem_base = pci_resource_start(dev, 1);
  56                mem_len = pci_resource_len(dev, 1);
  57                if (!mem_len) {
  58                        mem_base = csr_base + csr_len;
  59                        mem_len = csr_len;
  60                }
  61        }
  62
  63        pci_set_master(dev);
  64        denali->dev = &dev->dev;
  65        denali->irq = dev->irq;
  66        denali->ecc_caps = &denali_pci_ecc_caps;
  67        denali->nand.ecc.options |= NAND_ECC_MAXIMIZE;
  68        denali->clk_rate = 50000000;            /* 50 MHz */
  69        denali->clk_x_rate = 200000000;         /* 200 MHz */
  70
  71        ret = pci_request_regions(dev, DENALI_NAND_NAME);
  72        if (ret) {
  73                dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
  74                return ret;
  75        }
  76
  77        denali->reg = ioremap_nocache(csr_base, csr_len);
  78        if (!denali->reg) {
  79                dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
  80                return -ENOMEM;
  81        }
  82
  83        denali->host = ioremap_nocache(mem_base, mem_len);
  84        if (!denali->host) {
  85                dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
  86                ret = -ENOMEM;
  87                goto failed_remap_reg;
  88        }
  89
  90        ret = denali_init(denali);
  91        if (ret)
  92                goto failed_remap_mem;
  93
  94        pci_set_drvdata(dev, denali);
  95
  96        return 0;
  97
  98failed_remap_mem:
  99        iounmap(denali->host);
 100failed_remap_reg:
 101        iounmap(denali->reg);
 102        return ret;
 103}
 104
 105static 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->reg);
 111        iounmap(denali->host);
 112}
 113
 114static 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};
 120module_pci_driver(denali_pci_driver);
 121
 122MODULE_DESCRIPTION("PCI driver for Denali NAND controller");
 123MODULE_AUTHOR("Intel Corporation and its suppliers");
 124MODULE_LICENSE("GPL v2");
 125