1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Copyright by Michał Mirosław, 2008-2009
7 #ifndef LINUX_CB710_DRIVER_H
8 #define LINUX_CB710_DRIVER_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>
19 typedef int (*cb710_irq_handler_t
)(struct cb710_slot
*);
21 /* per-virtual-slot structure */
23 struct platform_device pdev
;
25 cb710_irq_handler_t irq_handler
;
28 /* per-device structure */
33 #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
34 atomic_t slot_refs_count
;
39 struct cb710_slot slot
[];
42 /* NOTE: cb710_chip.slots is modified only during device init/exit and
43 * they are all serialized wrt themselves */
45 /* cb710_chip.slot_mask values */
46 #define CB710_SLOT_MMC 1
47 #define CB710_SLOT_MS 2
48 #define CB710_SLOT_SM 4
50 /* slot port accessors - so the logic is more clear in the code */
51 #define CB710_PORT_ACCESSORS(t) \
52 static inline void cb710_write_port_##t(struct cb710_slot *slot, \
53 unsigned port, u##t value) \
55 iowrite##t(value, slot->iobase + port); \
58 static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
61 return ioread##t(slot->iobase + port); \
64 static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
65 unsigned port, u##t set, u##t clear) \
68 (ioread##t(slot->iobase + port) & ~clear)|set, \
69 slot->iobase + port); \
72 CB710_PORT_ACCESSORS(8)
73 CB710_PORT_ACCESSORS(16)
74 CB710_PORT_ACCESSORS(32)
76 void cb710_pci_update_config_reg(struct pci_dev
*pdev
,
77 int reg
, uint32_t and, uint32_t xor);
78 void cb710_set_irq_handler(struct cb710_slot
*slot
,
79 cb710_irq_handler_t handler
);
81 /* some device struct walking */
83 static inline struct cb710_slot
*cb710_pdev_to_slot(
84 struct platform_device
*pdev
)
86 return container_of(pdev
, struct cb710_slot
, pdev
);
89 static inline struct cb710_chip
*cb710_slot_to_chip(struct cb710_slot
*slot
)
91 return dev_get_drvdata(slot
->pdev
.dev
.parent
);
94 static inline struct device
*cb710_slot_dev(struct cb710_slot
*slot
)
96 return &slot
->pdev
.dev
;
99 static inline struct device
*cb710_chip_dev(struct cb710_chip
*chip
)
101 return &chip
->pdev
->dev
;
106 #ifdef CONFIG_CB710_DEBUG
107 void cb710_dump_regs(struct cb710_chip
*chip
, unsigned dump
);
109 #define cb710_dump_regs(c, d) do {} while (0)
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
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
124 #endif /* LINUX_CB710_DRIVER_H */
128 * Copyright by Michał Mirosław, 2008-2009
130 #ifndef LINUX_CB710_SG_H
131 #define LINUX_CB710_SG_H
133 #include <linux/highmem.h>
134 #include <linux/scatterlist.h>
137 * 32-bit PIO mapping sg iterator
139 * Hides scatterlist access issues - fragment boundaries, alignment, page
140 * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices
141 * without DMA support).
143 * Best-case reading (transfer from device):
144 * sg_miter_start(, SG_MITER_TO_SG);
145 * cb710_sg_dwiter_write_from_io();
148 * Best-case writing (transfer to device):
149 * sg_miter_start(, SG_MITER_FROM_SG);
150 * cb710_sg_dwiter_read_to_io();
154 uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter
*miter
);
155 void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter
*miter
, uint32_t data
);
158 * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port
159 * @miter: sg mapping iter
160 * @port: PIO port - IO or MMIO address
161 * @count: number of 32-bit words to transfer
164 * Reads @count 32-bit words from register @port and stores it in
165 * buffer iterated by @miter. Data that would overflow the buffer
166 * is silently ignored. Iterator is advanced by 4*@count bytes
167 * or to the buffer's end whichever is closer.
170 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
172 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter
*miter
,
173 void __iomem
*port
, size_t count
)
176 cb710_sg_dwiter_write_next_block(miter
, ioread32(port
));
180 * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer
181 * @miter: sg mapping iter
182 * @port: PIO port - IO or MMIO address
183 * @count: number of 32-bit words to transfer
186 * Writes @count 32-bit words to register @port from buffer iterated
187 * through @miter. If buffer ends before @count words are written
188 * missing data is replaced by zeroes. @miter is advanced by 4*@count
189 * bytes or to the buffer's end whichever is closer.
192 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise.
194 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter
*miter
,
195 void __iomem
*port
, size_t count
)
198 iowrite32(cb710_sg_dwiter_read_next_block(miter
), port
);
201 #endif /* LINUX_CB710_SG_H */