4 * Copyright by Michał Mirosław, 2008-2009
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.
10 #ifndef LINUX_CB710_DRIVER_H
11 #define LINUX_CB710_DRIVER_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>
22 typedef int (*cb710_irq_handler_t
)(struct cb710_slot
*);
24 /* per-virtual-slot structure */
26 struct platform_device pdev
;
28 cb710_irq_handler_t irq_handler
;
31 /* per-device structure */
36 #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
37 atomic_t slot_refs_count
;
42 struct cb710_slot slot
[0];
45 /* NOTE: cb710_chip.slots is modified only during device init/exit and
46 * they are all serialized wrt themselves */
48 /* cb710_chip.slot_mask values */
49 #define CB710_SLOT_MMC 1
50 #define CB710_SLOT_MS 2
51 #define CB710_SLOT_SM 4
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) \
58 iowrite##t(value, slot->iobase + port); \
61 static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
64 return ioread##t(slot->iobase + port); \
67 static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
68 unsigned port, u##t set, u##t clear) \
71 (ioread##t(slot->iobase + port) & ~clear)|set, \
72 slot->iobase + port); \
75 CB710_PORT_ACCESSORS(8)
76 CB710_PORT_ACCESSORS(16)
77 CB710_PORT_ACCESSORS(32)
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
);
84 /* some device struct walking */
86 static inline struct cb710_slot
*cb710_pdev_to_slot(
87 struct platform_device
*pdev
)
89 return container_of(pdev
, struct cb710_slot
, pdev
);
92 static inline struct cb710_chip
*cb710_slot_to_chip(struct cb710_slot
*slot
)
94 return dev_get_drvdata(slot
->pdev
.dev
.parent
);
97 static inline struct device
*cb710_slot_dev(struct cb710_slot
*slot
)
99 return &slot
->pdev
.dev
;
102 static inline struct device
*cb710_chip_dev(struct cb710_chip
*chip
)
104 return &chip
->pdev
->dev
;
109 #ifdef CONFIG_CB710_DEBUG
110 void cb710_dump_regs(struct cb710_chip
*chip
, unsigned dump
);
112 #define cb710_dump_regs(c, d) do {} while (0)
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
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
127 #endif /* LINUX_CB710_DRIVER_H */
131 * Copyright by Michał Mirosław, 2008-2009
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.
137 #ifndef LINUX_CB710_SG_H
138 #define LINUX_CB710_SG_H
140 #include <linux/highmem.h>
141 #include <linux/scatterlist.h>
144 * cb710_sg_miter_stop_writing - stop mapping iteration after writing
145 * @miter: sg mapping iter to be stopped
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.
153 * This is a convenience wrapper that will be optimized out for arches
154 * that don't need flush_kernel_dcache_page().
157 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
159 static inline void cb710_sg_miter_stop_writing(struct sg_mapping_iter
*miter
)
162 flush_kernel_dcache_page(miter
->page
);
163 sg_miter_stop(miter
);
167 * 32-bit PIO mapping sg iterator
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).
173 * Best-case reading (transfer from device):
175 * cb710_sg_dwiter_write_from_io();
176 * cb710_sg_miter_stop_writing();
178 * Best-case writing (transfer to device):
180 * cb710_sg_dwiter_read_to_io();
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
);
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
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.
200 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
202 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter
*miter
,
203 void __iomem
*port
, size_t count
)
206 cb710_sg_dwiter_write_next_block(miter
, ioread32(port
));
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
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.
222 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
224 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter
*miter
,
225 void __iomem
*port
, size_t count
)
228 iowrite32(cb710_sg_dwiter_read_next_block(miter
), port
);
231 #endif /* LINUX_CB710_SG_H */