Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cb710.h
Go to the documentation of this file.
1 /*
2  * cb710/cb710.h
3  *
4  * Copyright by Michał Mirosław, 2008-2009
5  *
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
12 
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>
19 
20 struct cb710_slot;
21 
22 typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
23 
24 /* per-virtual-slot structure */
25 struct cb710_slot {
27  void __iomem *iobase;
29 };
30 
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;
42  struct cb710_slot slot[0];
43 };
44 
45 /* NOTE: cb710_chip.slots is modified only during device init/exit and
46  * they are all serialized wrt themselves */
47 
48 /* cb710_chip.slot_mask values */
49 #define CB710_SLOT_MMC 1
50 #define CB710_SLOT_MS 2
51 #define CB710_SLOT_SM 4
52 
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 } \
60  \
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 } \
66  \
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); \
73 }
74 
78 
80  int reg, uint32_t and, uint32_t xor);
82  cb710_irq_handler_t handler);
83 
84 /* some device struct walking */
85 
86 static inline struct cb710_slot *cb710_pdev_to_slot(
87  struct platform_device *pdev)
88 {
89  return container_of(pdev, struct cb710_slot, pdev);
90 }
91 
92 static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot)
93 {
94  return dev_get_drvdata(slot->pdev.dev.parent);
95 }
96 
97 static inline struct device *cb710_slot_dev(struct cb710_slot *slot)
98 {
99  return &slot->pdev.dev;
100 }
101 
102 static inline struct device *cb710_chip_dev(struct cb710_chip *chip)
103 {
104  return &chip->pdev->dev;
105 }
106 
107 /* debugging aids */
108 
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
114 
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
120 
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
126 
127 #endif /* LINUX_CB710_DRIVER_H */
128 /*
129  * cb710/sgbuf2.h
130  *
131  * Copyright by Michał Mirosław, 2008-2009
132  *
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.
136  */
137 #ifndef LINUX_CB710_SG_H
138 #define LINUX_CB710_SG_H
139 
140 #include <linux/highmem.h>
141 #include <linux/scatterlist.h>
142 
143 /*
144  * 32-bit PIO mapping sg iterator
145  *
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).
149  *
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();
154  *
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();
159  */
160 
163 
179 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
180  void __iomem *port, size_t count)
181 {
182  while (count-- > 0)
184 }
185 
201 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
202  void __iomem *port, size_t count)
203 {
204  while (count-- > 0)
206 }
207 
208 #endif /* LINUX_CB710_SG_H */