Blackfin: fix indentation with bfin_read() helper
[zen-stable.git] / include / linux / cb710.h
blob8cc10411bab206f757bee1c87f45465e03686946
1 /*
2 * cb710/cb710.h
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.
9 */
10 #ifndef LINUX_CB710_DRIVER_H
11 #define LINUX_CB710_DRIVER_H
13 #include <linux/io.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>
20 struct cb710_slot;
22 typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
24 /* per-virtual-slot structure */
25 struct cb710_slot {
26 struct platform_device pdev;
27 void __iomem *iobase;
28 cb710_irq_handler_t irq_handler;
31 /* per-device structure */
32 struct cb710_chip {
33 struct pci_dev *pdev;
34 void __iomem *iobase;
35 unsigned platform_id;
36 #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
37 atomic_t slot_refs_count;
38 #endif
39 unsigned slot_mask;
40 unsigned slots;
41 spinlock_t irq_lock;
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) \
57 { \
58 iowrite##t(value, slot->iobase + port); \
59 } \
61 static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
62 unsigned port) \
63 { \
64 return ioread##t(slot->iobase + port); \
65 } \
67 static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
68 unsigned port, u##t set, u##t clear) \
69 { \
70 iowrite##t( \
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;
107 /* debugging aids */
109 #ifdef CONFIG_CB710_DEBUG
110 void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);
111 #else
112 #define cb710_dump_regs(c, d) do {} while (0)
113 #endif
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 */
129 * cb710/sgbuf2.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 * 32-bit PIO mapping sg iterator
146 * Hides scatterlist access issues - fragment boundaries, alignment, page
147 * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices
148 * without DMA support).
150 * Best-case reading (transfer from device):
151 * sg_miter_start(, SG_MITER_TO_SG);
152 * cb710_sg_dwiter_write_from_io();
153 * sg_miter_stop();
155 * Best-case writing (transfer to device):
156 * sg_miter_start(, SG_MITER_FROM_SG);
157 * cb710_sg_dwiter_read_to_io();
158 * sg_miter_stop();
161 uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
162 void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
165 * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port
166 * @miter: sg mapping iter
167 * @port: PIO port - IO or MMIO address
168 * @count: number of 32-bit words to transfer
170 * Description:
171 * Reads @count 32-bit words from register @port and stores it in
172 * buffer iterated by @miter. Data that would overflow the buffer
173 * is silently ignored. Iterator is advanced by 4*@count bytes
174 * or to the buffer's end whichever is closer.
176 * Context:
177 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
179 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
180 void __iomem *port, size_t count)
182 while (count-- > 0)
183 cb710_sg_dwiter_write_next_block(miter, ioread32(port));
187 * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer
188 * @miter: sg mapping iter
189 * @port: PIO port - IO or MMIO address
190 * @count: number of 32-bit words to transfer
192 * Description:
193 * Writes @count 32-bit words to register @port from buffer iterated
194 * through @miter. If buffer ends before @count words are written
195 * missing data is replaced by zeroes. @miter is advanced by 4*@count
196 * bytes or to the buffer's end whichever is closer.
198 * Context:
199 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
201 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
202 void __iomem *port, size_t count)
204 while (count-- > 0)
205 iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
208 #endif /* LINUX_CB710_SG_H */