0001
0002
0003
0004
0005
0006
0007 #ifndef LINUX_CB710_DRIVER_H
0008 #define LINUX_CB710_DRIVER_H
0009
0010 #include <linux/io.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/pci.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/mmc/host.h>
0016
0017 struct cb710_slot;
0018
0019 typedef int (*cb710_irq_handler_t)(struct cb710_slot *);
0020
0021
0022 struct cb710_slot {
0023 struct platform_device pdev;
0024 void __iomem *iobase;
0025 cb710_irq_handler_t irq_handler;
0026 };
0027
0028
0029 struct cb710_chip {
0030 struct pci_dev *pdev;
0031 void __iomem *iobase;
0032 unsigned platform_id;
0033 #ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS
0034 atomic_t slot_refs_count;
0035 #endif
0036 unsigned slot_mask;
0037 unsigned slots;
0038 spinlock_t irq_lock;
0039 struct cb710_slot slot[];
0040 };
0041
0042
0043
0044
0045
0046 #define CB710_SLOT_MMC 1
0047 #define CB710_SLOT_MS 2
0048 #define CB710_SLOT_SM 4
0049
0050
0051 #define CB710_PORT_ACCESSORS(t) \
0052 static inline void cb710_write_port_##t(struct cb710_slot *slot, \
0053 unsigned port, u##t value) \
0054 { \
0055 iowrite##t(value, slot->iobase + port); \
0056 } \
0057 \
0058 static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \
0059 unsigned port) \
0060 { \
0061 return ioread##t(slot->iobase + port); \
0062 } \
0063 \
0064 static inline void cb710_modify_port_##t(struct cb710_slot *slot, \
0065 unsigned port, u##t set, u##t clear) \
0066 { \
0067 iowrite##t( \
0068 (ioread##t(slot->iobase + port) & ~clear)|set, \
0069 slot->iobase + port); \
0070 }
0071
0072 CB710_PORT_ACCESSORS(8)
0073 CB710_PORT_ACCESSORS(16)
0074 CB710_PORT_ACCESSORS(32)
0075
0076 void cb710_pci_update_config_reg(struct pci_dev *pdev,
0077 int reg, uint32_t and, uint32_t xor);
0078 void cb710_set_irq_handler(struct cb710_slot *slot,
0079 cb710_irq_handler_t handler);
0080
0081
0082
0083 static inline struct cb710_slot *cb710_pdev_to_slot(
0084 struct platform_device *pdev)
0085 {
0086 return container_of(pdev, struct cb710_slot, pdev);
0087 }
0088
0089 static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot)
0090 {
0091 return dev_get_drvdata(slot->pdev.dev.parent);
0092 }
0093
0094 static inline struct device *cb710_slot_dev(struct cb710_slot *slot)
0095 {
0096 return &slot->pdev.dev;
0097 }
0098
0099 static inline struct device *cb710_chip_dev(struct cb710_chip *chip)
0100 {
0101 return &chip->pdev->dev;
0102 }
0103
0104
0105
0106 #ifdef CONFIG_CB710_DEBUG
0107 void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);
0108 #else
0109 #define cb710_dump_regs(c, d) do {} while (0)
0110 #endif
0111
0112 #define CB710_DUMP_REGS_MMC 0x0F
0113 #define CB710_DUMP_REGS_MS 0x30
0114 #define CB710_DUMP_REGS_SM 0xC0
0115 #define CB710_DUMP_REGS_ALL 0xFF
0116 #define CB710_DUMP_REGS_MASK 0xFF
0117
0118 #define CB710_DUMP_ACCESS_8 0x100
0119 #define CB710_DUMP_ACCESS_16 0x200
0120 #define CB710_DUMP_ACCESS_32 0x400
0121 #define CB710_DUMP_ACCESS_ALL 0x700
0122 #define CB710_DUMP_ACCESS_MASK 0x700
0123
0124 #endif
0125
0126
0127
0128
0129
0130 #ifndef LINUX_CB710_SG_H
0131 #define LINUX_CB710_SG_H
0132
0133 #include <linux/highmem.h>
0134 #include <linux/scatterlist.h>
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter);
0155 void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data);
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter,
0173 void __iomem *port, size_t count)
0174 {
0175 while (count-- > 0)
0176 cb710_sg_dwiter_write_next_block(miter, ioread32(port));
0177 }
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter,
0195 void __iomem *port, size_t count)
0196 {
0197 while (count-- > 0)
0198 iowrite32(cb710_sg_dwiter_read_next_block(miter), port);
0199 }
0200
0201 #endif