diff options
Diffstat (limited to 'include/linux/cb710.h')
-rw-r--r-- | include/linux/cb710.h | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/include/linux/cb710.h b/include/linux/cb710.h new file mode 100644 index 000000000000..63bc9a4d2926 --- /dev/null +++ b/include/linux/cb710.h | |||
@@ -0,0 +1,231 @@ | |||
1 | /* | ||
2 | * cb710/cb710.h | ||
3 | * | ||
4 | * Copyright by Michał Mirosław, 2008-2009 | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #ifndef LINUX_CB710_DRIVER_H | ||
11 | #define LINUX_CB710_DRIVER_H | ||
12 | |||
13 | #include <linux/io.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | #include <linux/pci.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/mmc/host.h> | ||
19 | |||
20 | struct cb710_slot; | ||
21 | |||
22 | typedef int (*cb710_irq_handler_t)(struct cb710_slot *); | ||
23 | |||
24 | /* per-virtual-slot structure */ | ||
25 | struct cb710_slot { | ||
26 | struct platform_device pdev; | ||
27 | void __iomem *iobase; | ||
28 | cb710_irq_handler_t irq_handler; | ||
29 | }; | ||
30 | |||
31 | /* per-device structure */ | ||
32 | struct cb710_chip { | ||
33 | struct pci_dev *pdev; | ||
34 | void __iomem *iobase; | ||
35 | unsigned platform_id; | ||
36 | #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS | ||
37 | atomic_t slot_refs_count; | ||
38 | #endif | ||
39 | unsigned slot_mask; | ||
40 | unsigned slots; | ||
41 | spinlock_t irq_lock; | ||
42 | struct cb710_slot slot[0]; | ||
43 | }; | ||
44 | |||
45 | /* NOTE: cb710_chip.slots is modified only during device init/exit and | ||
46 | * they are all serialized wrt themselves */ | ||
47 | |||
48 | /* cb710_chip.slot_mask values */ | ||
49 | #define CB710_SLOT_MMC 1 | ||
50 | #define CB710_SLOT_MS 2 | ||
51 | #define CB710_SLOT_SM 4 | ||
52 | |||
53 | /* slot port accessors - so the logic is more clear in the code */ | ||
54 | #define CB710_PORT_ACCESSORS(t) \ | ||
55 | static inline void cb710_write_port_##t(struct cb710_slot *slot, \ | ||
56 | unsigned port, u##t value) \ | ||
57 | { \ | ||
58 | iowrite##t(value, slot->iobase + port); \ | ||
59 | } \ | ||
60 | \ | ||
61 | static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \ | ||
62 | unsigned port) \ | ||
63 | { \ | ||
64 | return ioread##t(slot->iobase + port); \ | ||
65 | } \ | ||
66 | \ | ||
67 | static inline void cb710_modify_port_##t(struct cb710_slot *slot, \ | ||
68 | unsigned port, u##t set, u##t clear) \ | ||
69 | { \ | ||
70 | iowrite##t( \ | ||
71 | (ioread##t(slot->iobase + port) & ~clear)|set, \ | ||
72 | slot->iobase + port); \ | ||
73 | } | ||
74 | |||
75 | CB710_PORT_ACCESSORS(8) | ||
76 | CB710_PORT_ACCESSORS(16) | ||
77 | CB710_PORT_ACCESSORS(32) | ||
78 | |||
79 | void cb710_pci_update_config_reg(struct pci_dev *pdev, | ||
80 | int reg, uint32_t and, uint32_t xor); | ||
81 | void cb710_set_irq_handler(struct cb710_slot *slot, | ||
82 | cb710_irq_handler_t handler); | ||
83 | |||
84 | /* some device struct walking */ | ||
85 | |||
86 | static inline struct cb710_slot *cb710_pdev_to_slot( | ||
87 | struct platform_device *pdev) | ||
88 | { | ||
89 | return container_of(pdev, struct cb710_slot, pdev); | ||
90 | } | ||
91 | |||
92 | static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot) | ||
93 | { | ||
94 | return dev_get_drvdata(slot->pdev.dev.parent); | ||
95 | } | ||
96 | |||
97 | static inline struct device *cb710_slot_dev(struct cb710_slot *slot) | ||
98 | { | ||
99 | return &slot->pdev.dev; | ||
100 | } | ||
101 | |||
102 | static inline struct device *cb710_chip_dev(struct cb710_chip *chip) | ||
103 | { | ||
104 | return &chip->pdev->dev; | ||
105 | } | ||
106 | |||
107 | /* debugging aids */ | ||
108 | |||
109 | #ifdef CONFIG_CB710_DEBUG | ||
110 | void cb710_dump_regs(struct cb710_chip *chip, unsigned dump); | ||
111 | #else | ||
112 | #define cb710_dump_regs(c, d) do {} while (0) | ||
113 | #endif | ||
114 | |||
115 | #define CB710_DUMP_REGS_MMC 0x0F | ||
116 | #define CB710_DUMP_REGS_MS 0x30 | ||
117 | #define CB710_DUMP_REGS_SM 0xC0 | ||
118 | #define CB710_DUMP_REGS_ALL 0xFF | ||
119 | #define CB710_DUMP_REGS_MASK 0xFF | ||
120 | |||
121 | #define CB710_DUMP_ACCESS_8 0x100 | ||
122 | #define CB710_DUMP_ACCESS_16 0x200 | ||
123 | #define CB710_DUMP_ACCESS_32 0x400 | ||
124 | #define CB710_DUMP_ACCESS_ALL 0x700 | ||
125 | #define CB710_DUMP_ACCESS_MASK 0x700 | ||
126 | |||
127 | #endif /* LINUX_CB710_DRIVER_H */ | ||
128 | /* | ||
129 | * cb710/sgbuf2.h | ||
130 | * | ||
131 | * Copyright by Michał Mirosław, 2008-2009 | ||
132 | * | ||
133 | * This program is free software; you can redistribute it and/or modify | ||
134 | * it under the terms of the GNU General Public License version 2 as | ||
135 | * published by the Free Software Foundation. | ||
136 | */ | ||
137 | #ifndef LINUX_CB710_SG_H | ||
138 | #define LINUX_CB710_SG_H | ||
139 | |||
140 | #include <linux/highmem.h> | ||
141 | #include <linux/scatterlist.h> | ||
142 | |||
143 | /** | ||
144 | * cb710_sg_miter_stop_writing - stop mapping iteration after writing | ||
145 | * @miter: sg mapping iter to be stopped | ||
146 | * | ||
147 | * Description: | ||
148 | * Stops mapping iterator @miter. @miter should have been started | ||
149 | * started using sg_miter_start(). A stopped iteration can be | ||
150 | * resumed by calling sg_miter_next() on it. This is useful when | ||
151 | * resources (kmap) need to be released during iteration. | ||
152 | * | ||
153 | * This is a convenience wrapper that will be optimized out for arches | ||
154 | * that don't need flush_kernel_dcache_page(). | ||
155 | * | ||
156 | * Context: | ||
157 | * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise. | ||
158 | */ | ||
159 | static inline void cb710_sg_miter_stop_writing(struct sg_mapping_iter *miter) | ||
160 | { | ||
161 | if (miter->page) | ||
162 | flush_kernel_dcache_page(miter->page); | ||
163 | sg_miter_stop(miter); | ||
164 | } | ||
165 | |||
166 | /* | ||
167 | * 32-bit PIO mapping sg iterator | ||
168 | * | ||
169 | * Hides scatterlist access issues - fragment boundaries, alignment, page | ||
170 | * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices | ||
171 | * without DMA support). | ||
172 | * | ||
173 | * Best-case reading (transfer from device): | ||
174 | * sg_miter_start(); | ||
175 | * cb710_sg_dwiter_write_from_io(); | ||
176 | * cb710_sg_miter_stop_writing(); | ||
177 | * | ||
178 | * Best-case writing (transfer to device): | ||
179 | * sg_miter_start(); | ||
180 | * cb710_sg_dwiter_read_to_io(); | ||
181 | * sg_miter_stop(); | ||
182 | */ | ||
183 | |||
184 | uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter); | ||
185 | void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data); | ||
186 | |||
187 | /** | ||
188 | * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port | ||
189 | * @miter: sg mapping iter | ||
190 | * @port: PIO port - IO or MMIO address | ||
191 | * @count: number of 32-bit words to transfer | ||
192 | * | ||
193 | * Description: | ||
194 | * Reads @count 32-bit words from register @port and stores it in | ||
195 | * buffer iterated by @miter. Data that would overflow the buffer | ||
196 | * is silently ignored. Iterator is advanced by 4*@count bytes | ||
197 | * or to the buffer's end whichever is closer. | ||
198 | * | ||
199 | * Context: | ||
200 | * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise. | ||
201 | */ | ||
202 | static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter, | ||
203 | void __iomem *port, size_t count) | ||
204 | { | ||
205 | while (count-- > 0) | ||
206 | cb710_sg_dwiter_write_next_block(miter, ioread32(port)); | ||
207 | } | ||
208 | |||
209 | /** | ||
210 | * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer | ||
211 | * @miter: sg mapping iter | ||
212 | * @port: PIO port - IO or MMIO address | ||
213 | * @count: number of 32-bit words to transfer | ||
214 | * | ||
215 | * Description: | ||
216 | * Writes @count 32-bit words to register @port from buffer iterated | ||
217 | * through @miter. If buffer ends before @count words are written | ||
218 | * missing data is replaced by zeroes. @miter is advanced by 4*@count | ||
219 | * bytes or to the buffer's end whichever is closer. | ||
220 | * | ||
221 | * Context: | ||
222 | * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise. | ||
223 | */ | ||
224 | static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter, | ||
225 | void __iomem *port, size_t count) | ||
226 | { | ||
227 | while (count-- > 0) | ||
228 | iowrite32(cb710_sg_dwiter_read_next_block(miter), port); | ||
229 | } | ||
230 | |||
231 | #endif /* LINUX_CB710_SG_H */ | ||