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
13 #ifdef CONFIG_CB710_DEBUG
17 /* verify assumptions on platform_device framework */
18 #define CONFIG_CB710_DEBUG_ASSUMPTIONS
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>
29 typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
31 /* per-virtual-slot structure */
33 struct platform_device pdev;
35 cb710_irq_handler_t irq_handler;
38 /* per-device structure */
43 #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
44 atomic_t slot_refs_count;
49 struct cb710_slot slot[0];
52 /* NOTE: cb710_chip.slots is modified only during device init/exit and
53 * they are all serialized wrt themselves */
55 /* cb710_chip.slot_mask values */
56 #define CB710_SLOT_MMC 1
57 #define CB710_SLOT_MS 2
58 #define CB710_SLOT_SM 4
60 /* slot port accessors - so the logic is more clear in the code */
61 #define CB710_PORT_ACCESSORS(t) \
62 static inline void cb710_write_port_##t(struct cb710_slot *slot, \
63 unsigned port, u##t value) \
65 iowrite##t(value, slot->iobase + port); \
68 static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
71 return ioread##t(slot->iobase + port); \
74 static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
75 unsigned port, u##t set, u##t clear) \
78 (ioread##t(slot->iobase + port) & ~clear)|set, \
79 slot->iobase + port); \
82 CB710_PORT_ACCESSORS(8)
83 CB710_PORT_ACCESSORS(16)
84 CB710_PORT_ACCESSORS(32)
86 void cb710_pci_update_config_reg(struct pci_dev *pdev,
87 int reg, uint32_t and, uint32_t xor);
88 void cb710_set_irq_handler(struct cb710_slot *slot,
89 cb710_irq_handler_t handler);
91 /* some device struct walking */
93 static inline struct cb710_slot *cb710_pdev_to_slot(
94 struct platform_device *pdev)
96 return container_of(pdev, struct cb710_slot, pdev);
99 static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot)
101 return dev_get_drvdata(slot->pdev.dev.parent);
104 static inline struct device *cb710_slot_dev(struct cb710_slot *slot)
106 return &slot->pdev.dev;
109 static inline struct device *cb710_chip_dev(struct cb710_chip *chip)
111 return &chip->pdev->dev;
116 #ifdef CONFIG_CB710_DEBUG
117 void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);
119 #define cb710_dump_regs(c, d) do {} while (0)
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
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
134 #endif /* LINUX_CB710_DRIVER_H */
138 * Copyright by Michał Mirosław, 2008-2009
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.
144 #ifndef LINUX_CB710_SG_H
145 #define LINUX_CB710_SG_H
147 #include <linux/highmem.h>
148 #include <linux/scatterlist.h>
151 * cb710_sg_miter_stop_writing - stop mapping iteration after writing
152 * @miter: sg mapping iter to be stopped
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.
160 * This is a convenience wrapper that will be optimized out for arches
161 * that don't need flush_kernel_dcache_page().
164 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
166 static inline void cb710_sg_miter_stop_writing(struct sg_mapping_iter *miter)
169 flush_kernel_dcache_page(miter->page);
170 sg_miter_stop(miter);
174 * 32-bit PIO mapping sg iterator
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).
180 * Best-case reading (transfer from device):
182 * cb710_sg_dwiter_write_from_io();
183 * cb710_sg_miter_stop_writing();
185 * Best-case writing (transfer to device):
187 * cb710_sg_dwiter_read_to_io();
191 uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
192 void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
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
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.
207 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
209 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
210 void __iomem *port, size_t count)
213 cb710_sg_dwiter_write_next_block(miter, ioread32(port));
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
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.
229 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
231 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
232 void __iomem *port, size_t count)
235 iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
238 #endif /* LINUX_CB710_SG_H */