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