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 /* verify assumptions on platform_device framework */
14 #define CONFIG_CB710_DEBUG_ASSUMPTIONS
17 #include <linux/interrupt.h>
18 #include <linux/spinlock.h>
19 #include <linux/pci.h>
20 #include <linux/platform_device.h>
21 #include <linux/mmc/host.h>
25 typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
27 /* per-virtual-slot structure */
29 struct platform_device pdev;
31 cb710_irq_handler_t irq_handler;
34 /* per-device structure */
39 #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
40 atomic_t slot_refs_count;
45 struct cb710_slot slot[0];
48 /* NOTE: cb710_chip.slots is modified only during device init/exit and
49 * they are all serialized wrt themselves */
51 /* cb710_chip.slot_mask values */
52 #define CB710_SLOT_MMC 1
53 #define CB710_SLOT_MS 2
54 #define CB710_SLOT_SM 4
56 /* slot port accessors - so the logic is more clear in the code */
57 #define CB710_PORT_ACCESSORS(t) \
58 static inline void cb710_write_port_##t(struct cb710_slot *slot, \
59 unsigned port, u##t value) \
61 iowrite##t(value, slot->iobase + port); \
64 static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
67 return ioread##t(slot->iobase + port); \
70 static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
71 unsigned port, u##t set, u##t clear) \
74 (ioread##t(slot->iobase + port) & ~clear)|set, \
75 slot->iobase + port); \
78 CB710_PORT_ACCESSORS(8)
79 CB710_PORT_ACCESSORS(16)
80 CB710_PORT_ACCESSORS(32)
82 void cb710_pci_update_config_reg(struct pci_dev *pdev,
83 int reg, uint32_t and, uint32_t xor);
84 void cb710_set_irq_handler(struct cb710_slot *slot,
85 cb710_irq_handler_t handler);
87 /* some device struct walking */
89 static inline struct cb710_slot *cb710_pdev_to_slot(
90 struct platform_device *pdev)
92 return container_of(pdev, struct cb710_slot, pdev);
95 static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot)
97 return dev_get_drvdata(slot->pdev.dev.parent);
100 static inline struct device *cb710_slot_dev(struct cb710_slot *slot)
102 return &slot->pdev.dev;
105 static inline struct device *cb710_chip_dev(struct cb710_chip *chip)
107 return &chip->pdev->dev;
112 #ifdef CONFIG_CB710_DEBUG
113 void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);
115 #define cb710_dump_regs(c, d) do {} while (0)
118 #define CB710_DUMP_REGS_MMC 0x0F
119 #define CB710_DUMP_REGS_MS 0x30
120 #define CB710_DUMP_REGS_SM 0xC0
121 #define CB710_DUMP_REGS_ALL 0xFF
122 #define CB710_DUMP_REGS_MASK 0xFF
124 #define CB710_DUMP_ACCESS_8 0x100
125 #define CB710_DUMP_ACCESS_16 0x200
126 #define CB710_DUMP_ACCESS_32 0x400
127 #define CB710_DUMP_ACCESS_ALL 0x700
128 #define CB710_DUMP_ACCESS_MASK 0x700
130 #endif /* LINUX_CB710_DRIVER_H */
134 * Copyright by Michał Mirosław, 2008-2009
136 * This program is free software; you can redistribute it and/or modify
137 * it under the terms of the GNU General Public License version 2 as
138 * published by the Free Software Foundation.
140 #ifndef LINUX_CB710_SG_H
141 #define LINUX_CB710_SG_H
143 #include <linux/highmem.h>
144 #include <linux/scatterlist.h>
147 * cb710_sg_miter_stop_writing - stop mapping iteration after writing
148 * @miter: sg mapping iter to be stopped
151 * Stops mapping iterator @miter. @miter should have been started
152 * started using sg_miter_start(). A stopped iteration can be
153 * resumed by calling sg_miter_next() on it. This is useful when
154 * resources (kmap) need to be released during iteration.
156 * This is a convenience wrapper that will be optimized out for arches
157 * that don't need flush_kernel_dcache_page().
160 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
162 static inline void cb710_sg_miter_stop_writing(struct sg_mapping_iter *miter)
165 flush_kernel_dcache_page(miter->page);
166 sg_miter_stop(miter);
170 * 32-bit PIO mapping sg iterator
172 * Hides scatterlist access issues - fragment boundaries, alignment, page
173 * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices
174 * without DMA support).
176 * Best-case reading (transfer from device):
178 * cb710_sg_dwiter_write_from_io();
179 * cb710_sg_miter_stop_writing();
181 * Best-case writing (transfer to device):
183 * cb710_sg_dwiter_read_to_io();
187 uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
188 void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
191 * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port
192 * @miter: sg mapping iter
193 * @port: PIO port - IO or MMIO address
194 * @count: number of 32-bit words to transfer
197 * Reads @count 32-bit words from register @port and stores it in
198 * buffer iterated by @miter. Data that would overflow the buffer
199 * is silently ignored. Iterator is advanced by 4*@count bytes
200 * or to the buffer's end whichever is closer.
203 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
205 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
206 void __iomem *port, size_t count)
209 cb710_sg_dwiter_write_next_block(miter, ioread32(port));
213 * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer
214 * @miter: sg mapping iter
215 * @port: PIO port - IO or MMIO address
216 * @count: number of 32-bit words to transfer
219 * Writes @count 32-bit words to register @port from buffer iterated
220 * through @miter. If buffer ends before @count words are written
221 * missing data is replaced by zeroes. @miter is advanced by 4*@count
222 * bytes or to the buffer's end whichever is closer.
225 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
227 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
228 void __iomem *port, size_t count)
231 iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
234 #endif /* LINUX_CB710_SG_H */