0001
0002
0003
0004
0005
0006
0007 #include <linux/pci.h>
0008 #include <linux/completion.h>
0009 #include <linux/workqueue.h>
0010 #include <linux/mtd/rawnand.h>
0011 #include <linux/spinlock.h>
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #define R852_DATALINE 0x00
0022
0023
0024 #define R852_CTL 0x04
0025 #define R852_CTL_COMMAND 0x01
0026 #define R852_CTL_DATA 0x02
0027 #define R852_CTL_ON 0x04
0028
0029 #define R852_CTL_RESET 0x08
0030 #define R852_CTL_CARDENABLE 0x10
0031 #define R852_CTL_ECC_ENABLE 0x20
0032 #define R852_CTL_ECC_ACCESS 0x40
0033 #define R852_CTL_WRITE 0x80
0034
0035
0036 #define R852_CARD_STA 0x05
0037
0038 #define R852_CARD_STA_CD 0x01
0039 #define R852_CARD_STA_RO 0x02
0040 #define R852_CARD_STA_PRESENT 0x04
0041 #define R852_CARD_STA_ABSENT 0x08
0042 #define R852_CARD_STA_BUSY 0x80
0043
0044
0045 #define R852_CARD_IRQ_STA 0x06
0046 #define R852_CARD_IRQ_ENABLE 0x07
0047
0048 #define R852_CARD_IRQ_CD 0x01
0049 #define R852_CARD_IRQ_REMOVE 0x04
0050 #define R852_CARD_IRQ_INSERT 0x08
0051 #define R852_CARD_IRQ_UNK1 0x10
0052 #define R852_CARD_IRQ_GENABLE 0x80
0053 #define R852_CARD_IRQ_MASK 0x1D
0054
0055
0056
0057
0058 #define R852_HW 0x08
0059 #define R852_HW_ENABLED 0x01
0060 #define R852_HW_UNKNOWN 0x80
0061
0062
0063
0064 #define R852_DMA_CAP 0x09
0065 #define R852_SMBIT 0x20
0066
0067 #define R852_DMA1 0x40
0068 #define R852_DMA2 0x80
0069
0070
0071
0072 #define R852_DMA_ADDR 0x0C
0073
0074
0075
0076 #define R852_DMA_SETTINGS 0x10
0077 #define R852_DMA_MEMORY 0x01
0078 #define R852_DMA_READ 0x02
0079 #define R852_DMA_INTERNAL 0x04
0080
0081
0082 #define R852_DMA_IRQ_STA 0x14
0083
0084
0085 #define R852_DMA_IRQ_ENABLE 0x18
0086
0087 #define R852_DMA_IRQ_MEMORY 0x01
0088 #define R852_DMA_IRQ_ERROR 0x02
0089 #define R852_DMA_IRQ_INTERNAL 0x04
0090 #define R852_DMA_IRQ_MASK 0x07
0091
0092
0093
0094
0095
0096 #define R852_ECC_ERR_BIT_MSK 0x07
0097 #define R852_ECC_CORRECT 0x10
0098 #define R852_ECC_CORRECTABLE 0x20
0099 #define R852_ECC_FAIL 0x40
0100
0101 #define R852_DMA_LEN 512
0102
0103 #define DMA_INTERNAL 0
0104 #define DMA_MEMORY 1
0105
0106 struct r852_device {
0107 struct nand_controller controller;
0108 void __iomem *mmio;
0109 struct nand_chip *chip;
0110 struct pci_dev *pci_dev;
0111
0112
0113 dma_addr_t phys_dma_addr;
0114 struct completion dma_done;
0115
0116 dma_addr_t phys_bounce_buffer;
0117 uint8_t *bounce_buffer;
0118
0119 int dma_dir;
0120 int dma_stage;
0121
0122
0123 int dma_state;
0124 int dma_error;
0125 int dma_usable;
0126
0127
0128 struct delayed_work card_detect_work;
0129 struct workqueue_struct *card_workqueue;
0130 int card_registered;
0131 int card_detected;
0132 int card_unstable;
0133
0134 int readonly;
0135 int sm;
0136
0137
0138 spinlock_t irqlock;
0139 int irq;
0140
0141 void *tmp_buffer;
0142 uint8_t ctlreg;
0143 };
0144
0145 #define dbg(format, ...) \
0146 if (debug) \
0147 pr_debug(format "\n", ## __VA_ARGS__)
0148
0149 #define dbg_verbose(format, ...) \
0150 if (debug > 1) \
0151 pr_debug(format "\n", ## __VA_ARGS__)
0152
0153
0154 #define message(format, ...) \
0155 pr_info(format "\n", ## __VA_ARGS__)