1
2
3
4
5
6
7 #include <linux/pci.h>
8 #include <linux/completion.h>
9 #include <linux/workqueue.h>
10 #include <linux/mtd/rawnand.h>
11 #include <linux/spinlock.h>
12
13
14
15
16
17
18
19
20
21 #define R852_DATALINE 0x00
22
23
24 #define R852_CTL 0x04
25 #define R852_CTL_COMMAND 0x01
26 #define R852_CTL_DATA 0x02
27 #define R852_CTL_ON 0x04
28
29 #define R852_CTL_RESET 0x08
30 #define R852_CTL_CARDENABLE 0x10
31 #define R852_CTL_ECC_ENABLE 0x20
32 #define R852_CTL_ECC_ACCESS 0x40
33 #define R852_CTL_WRITE 0x80
34
35
36 #define R852_CARD_STA 0x05
37
38 #define R852_CARD_STA_CD 0x01
39 #define R852_CARD_STA_RO 0x02
40 #define R852_CARD_STA_PRESENT 0x04
41 #define R852_CARD_STA_ABSENT 0x08
42 #define R852_CARD_STA_BUSY 0x80
43
44
45 #define R852_CARD_IRQ_STA 0x06
46 #define R852_CARD_IRQ_ENABLE 0x07
47
48 #define R852_CARD_IRQ_CD 0x01
49 #define R852_CARD_IRQ_REMOVE 0x04
50 #define R852_CARD_IRQ_INSERT 0x08
51 #define R852_CARD_IRQ_UNK1 0x10
52 #define R852_CARD_IRQ_GENABLE 0x80
53 #define R852_CARD_IRQ_MASK 0x1D
54
55
56
57
58 #define R852_HW 0x08
59 #define R852_HW_ENABLED 0x01
60 #define R852_HW_UNKNOWN 0x80
61
62
63
64 #define R852_DMA_CAP 0x09
65 #define R852_SMBIT 0x20
66
67 #define R852_DMA1 0x40
68 #define R852_DMA2 0x80
69
70
71
72 #define R852_DMA_ADDR 0x0C
73
74
75
76 #define R852_DMA_SETTINGS 0x10
77 #define R852_DMA_MEMORY 0x01
78 #define R852_DMA_READ 0x02
79 #define R852_DMA_INTERNAL 0x04
80
81
82 #define R852_DMA_IRQ_STA 0x14
83
84
85 #define R852_DMA_IRQ_ENABLE 0x18
86
87 #define R852_DMA_IRQ_MEMORY 0x01
88 #define R852_DMA_IRQ_ERROR 0x02
89 #define R852_DMA_IRQ_INTERNAL 0x04
90 #define R852_DMA_IRQ_MASK 0x07
91
92
93
94
95
96 #define R852_ECC_ERR_BIT_MSK 0x07
97 #define R852_ECC_CORRECT 0x10
98 #define R852_ECC_CORRECTABLE 0x20
99 #define R852_ECC_FAIL 0x40
100
101 #define R852_DMA_LEN 512
102
103 #define DMA_INTERNAL 0
104 #define DMA_MEMORY 1
105
106 struct r852_device {
107 void __iomem *mmio;
108 struct nand_chip *chip;
109 struct pci_dev *pci_dev;
110
111
112 dma_addr_t phys_dma_addr;
113 struct completion dma_done;
114
115 dma_addr_t phys_bounce_buffer;
116 uint8_t *bounce_buffer;
117
118 int dma_dir;
119 int dma_stage;
120
121
122 int dma_state;
123 int dma_error;
124 int dma_usable;
125
126
127 struct delayed_work card_detect_work;
128 struct workqueue_struct *card_workqueue;
129 int card_registered;
130 int card_detected;
131 int card_unstable;
132
133 int readonly;
134 int sm;
135
136
137 spinlock_t irqlock;
138 int irq;
139
140 void *tmp_buffer;
141 uint8_t ctlreg;
142 };
143
144 #define dbg(format, ...) \
145 if (debug) \
146 pr_debug(format "\n", ## __VA_ARGS__)
147
148 #define dbg_verbose(format, ...) \
149 if (debug > 1) \
150 pr_debug(format "\n", ## __VA_ARGS__)
151
152
153 #define message(format, ...) \
154 pr_info(format "\n", ## __VA_ARGS__)