Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  cb710/cb710.h
0004  *
0005  *  Copyright by Michał Mirosław, 2008-2009
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 /* per-virtual-slot structure */
0022 struct cb710_slot {
0023     struct platform_device  pdev;
0024     void __iomem        *iobase;
0025     cb710_irq_handler_t irq_handler;
0026 };
0027 
0028 /* per-device structure */
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 /* NOTE: cb710_chip.slots is modified only during device init/exit and
0043  * they are all serialized wrt themselves */
0044 
0045 /* cb710_chip.slot_mask values */
0046 #define CB710_SLOT_MMC      1
0047 #define CB710_SLOT_MS       2
0048 #define CB710_SLOT_SM       4
0049 
0050 /* slot port accessors - so the logic is more clear in the code */
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 /* some device struct walking */
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 /* debugging aids */
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 /* LINUX_CB710_DRIVER_H */
0125 /*
0126  *  cb710/sgbuf2.h
0127  *
0128  *  Copyright by Michał Mirosław, 2008-2009
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  * 32-bit PIO mapping sg iterator
0138  *
0139  * Hides scatterlist access issues - fragment boundaries, alignment, page
0140  * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices
0141  * without DMA support).
0142  *
0143  * Best-case reading (transfer from device):
0144  *   sg_miter_start(, SG_MITER_TO_SG);
0145  *   cb710_sg_dwiter_write_from_io();
0146  *   sg_miter_stop();
0147  *
0148  * Best-case writing (transfer to device):
0149  *   sg_miter_start(, SG_MITER_FROM_SG);
0150  *   cb710_sg_dwiter_read_to_io();
0151  *   sg_miter_stop();
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  * cb710_sg_dwiter_write_from_io - transfer data to mapped buffer from 32-bit IO port
0159  * @miter: sg mapping iter
0160  * @port: PIO port - IO or MMIO address
0161  * @count: number of 32-bit words to transfer
0162  *
0163  * Description:
0164  *   Reads @count 32-bit words from register @port and stores it in
0165  *   buffer iterated by @miter.  Data that would overflow the buffer
0166  *   is silently ignored.  Iterator is advanced by 4*@count bytes
0167  *   or to the buffer's end whichever is closer.
0168  *
0169  * Context:
0170  *   IRQ disabled if the SG_MITER_ATOMIC is set.  Don't care otherwise.
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  * cb710_sg_dwiter_read_to_io - transfer data to 32-bit IO port from mapped buffer
0181  * @miter: sg mapping iter
0182  * @port: PIO port - IO or MMIO address
0183  * @count: number of 32-bit words to transfer
0184  *
0185  * Description:
0186  *   Writes @count 32-bit words to register @port from buffer iterated
0187  *   through @miter.  If buffer ends before @count words are written
0188  *   missing data is replaced by zeroes. @miter is advanced by 4*@count
0189  *   bytes or to the buffer's end whichever is closer.
0190  *
0191  * Context:
0192  *   IRQ disabled if the SG_MITER_ATOMIC is set.  Don't care otherwise.
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 /* LINUX_CB710_SG_H */