1
2
3
4
5
6
7#ifndef LINUX_CB710_DRIVER_H
8#define LINUX_CB710_DRIVER_H
9
10#include <linux/io.h>
11#include <linux/interrupt.h>
12#include <linux/spinlock.h>
13#include <linux/pci.h>
14#include <linux/platform_device.h>
15#include <linux/mmc/host.h>
16
17struct cb710_slot;
18
19typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
20
21
22struct cb710_slot {
23 struct platform_device pdev;
24 void __iomem *iobase;
25 cb710_irq_handler_t irq_handler;
26};
27
28
29struct cb710_chip {
30 struct pci_dev *pdev;
31 void __iomem *iobase;
32 unsigned platform_id;
33#ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
34 atomic_t slot_refs_count;
35#endif
36 unsigned slot_mask;
37 unsigned slots;
38 spinlock_t irq_lock;
39 struct cb710_slot slot[];
40};
41
42
43
44
45
46#define CB710_SLOT_MMC 1
47#define CB710_SLOT_MS 2
48#define CB710_SLOT_SM 4
49
50
51#define CB710_PORT_ACCESSORS(t) \
52static inline void cb710_write_port_##t(struct cb710_slot *slot, \
53 unsigned port, u##t value) \
54{ \
55 iowrite##t(value, slot->iobase + port); \
56} \
57 \
58static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
59 unsigned port) \
60{ \
61 return ioread##t(slot->iobase + port); \
62} \
63 \
64static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
65 unsigned port, u##t set, u##t clear) \
66{ \
67 iowrite##t( \
68 (ioread##t(slot->iobase + port) & ~clear)|set, \
69 slot->iobase + port); \
70}
71
72CB710_PORT_ACCESSORS(8)
73CB710_PORT_ACCESSORS(16)
74CB710_PORT_ACCESSORS(32)
75
76void cb710_pci_update_config_reg(struct pci_dev *pdev,
77 int reg, uint32_t and, uint32_t xor);
78void cb710_set_irq_handler(struct cb710_slot *slot,
79 cb710_irq_handler_t handler);
80
81
82
83static inline struct cb710_slot *cb710_pdev_to_slot(
84 struct platform_device *pdev)
85{
86 return container_of(pdev, struct cb710_slot, pdev);
87}
88
89static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot)
90{
91 return dev_get_drvdata(slot->pdev.dev.parent);
92}
93
94static inline struct device *cb710_slot_dev(struct cb710_slot *slot)
95{
96 return &slot->pdev.dev;
97}
98
99static inline struct device *cb710_chip_dev(struct cb710_chip *chip)
100{
101 return &chip->pdev->dev;
102}
103
104
105
106#ifdef CONFIG_CB710_DEBUG
107void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);
108#else
109#define cb710_dump_regs(c, d) do {} while (0)
110#endif
111
112#define CB710_DUMP_REGS_MMC 0x0F
113#define CB710_DUMP_REGS_MS 0x30
114#define CB710_DUMP_REGS_SM 0xC0
115#define CB710_DUMP_REGS_ALL 0xFF
116#define CB710_DUMP_REGS_MASK 0xFF
117
118#define CB710_DUMP_ACCESS_8 0x100
119#define CB710_DUMP_ACCESS_16 0x200
120#define CB710_DUMP_ACCESS_32 0x400
121#define CB710_DUMP_ACCESS_ALL 0x700
122#define CB710_DUMP_ACCESS_MASK 0x700
123
124#endif
125
126
127
128
129
130#ifndef LINUX_CB710_SG_H
131#define LINUX_CB710_SG_H
132
133#include <linux/highmem.h>
134#include <linux/scatterlist.h>
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
155void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
173 void __iomem *port, size_t count)
174{
175 while (count-- > 0)
176 cb710_sg_dwiter_write_next_block(miter, ioread32(port));
177}
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
195 void __iomem *port, size_t count)
196{
197 while (count-- > 0)
198 iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
199}
200
201#endif
202