cb710.h (5490B)
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * cb710/cb710.h 4 * 5 * Copyright by Michał Mirosław, 2008-2009 6 */ 7#ifndef LINUX_CB710_DRIVER_H 8#define LINUX_CB710_DRIVER_H 9 10#include <linux/io.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> 16 17struct cb710_slot; 18 19typedef int (*cb710_irq_handler_t)(struct cb710_slot *); 20 21/* per-virtual-slot structure */ 22struct cb710_slot { 23 struct platform_device pdev; 24 void __iomem *iobase; 25 cb710_irq_handler_t irq_handler; 26}; 27 28/* per-device structure */ 29struct cb710_chip { 30 struct pci_dev *pdev; 31 void __iomem *iobase; 32 unsigned platform_id; 33#ifdef CONFIG_CB710_DEBUG_ASSUMPTIONS 34 atomic_t slot_refs_count; 35#endif 36 unsigned slot_mask; 37 unsigned slots; 38 spinlock_t irq_lock; 39 struct cb710_slot slot[]; 40}; 41 42/* NOTE: cb710_chip.slots is modified only during device init/exit and 43 * they are all serialized wrt themselves */ 44 45/* cb710_chip.slot_mask values */ 46#define CB710_SLOT_MMC 1 47#define CB710_SLOT_MS 2 48#define CB710_SLOT_SM 4 49 50/* slot port accessors - so the logic is more clear in the code */ 51#define CB710_PORT_ACCESSORS(t) \ 52static inline void cb710_write_port_##t(struct cb710_slot *slot, \ 53 unsigned port, u##t value) \ 54{ \ 55 iowrite##t(value, slot->iobase + port); \ 56} \ 57 \ 58static inline u##t cb710_read_port_##t(struct cb710_slot *slot, \ 59 unsigned port) \ 60{ \ 61 return ioread##t(slot->iobase + port); \ 62} \ 63 \ 64static inline void cb710_modify_port_##t(struct cb710_slot *slot, \ 65 unsigned port, u##t set, u##t clear) \ 66{ \ 67 iowrite##t( \ 68 (ioread##t(slot->iobase + port) & ~clear)|set, \ 69 slot->iobase + port); \ 70} 71 72CB710_PORT_ACCESSORS(8) 73CB710_PORT_ACCESSORS(16) 74CB710_PORT_ACCESSORS(32) 75 76void cb710_pci_update_config_reg(struct pci_dev *pdev, 77 int reg, uint32_t and, uint32_t xor); 78void cb710_set_irq_handler(struct cb710_slot *slot, 79 cb710_irq_handler_t handler); 80 81/* some device struct walking */ 82 83static inline struct cb710_slot *cb710_pdev_to_slot( 84 struct platform_device *pdev) 85{ 86 return container_of(pdev, struct cb710_slot, pdev); 87} 88 89static inline struct cb710_chip *cb710_slot_to_chip(struct cb710_slot *slot) 90{ 91 return dev_get_drvdata(slot->pdev.dev.parent); 92} 93 94static inline struct device *cb710_slot_dev(struct cb710_slot *slot) 95{ 96 return &slot->pdev.dev; 97} 98 99static inline struct device *cb710_chip_dev(struct cb710_chip *chip) 100{ 101 return &chip->pdev->dev; 102} 103 104/* debugging aids */ 105 106#ifdef CONFIG_CB710_DEBUG 107void cb710_dump_regs(struct cb710_chip *chip, unsigned dump); 108#else 109#define cb710_dump_regs(c, d) do {} while (0) 110#endif 111 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 117 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 123 124#endif /* LINUX_CB710_DRIVER_H */ 125/* 126 * cb710/sgbuf2.h 127 * 128 * Copyright by Michał Mirosław, 2008-2009 129 */ 130#ifndef LINUX_CB710_SG_H 131#define LINUX_CB710_SG_H 132 133#include <linux/highmem.h> 134#include <linux/scatterlist.h> 135 136/* 137 * 32-bit PIO mapping sg iterator 138 * 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). 142 * 143 * Best-case reading (transfer from device): 144 * sg_miter_start(, SG_MITER_TO_SG); 145 * cb710_sg_dwiter_write_from_io(); 146 * sg_miter_stop(); 147 * 148 * Best-case writing (transfer to device): 149 * sg_miter_start(, SG_MITER_FROM_SG); 150 * cb710_sg_dwiter_read_to_io(); 151 * sg_miter_stop(); 152 */ 153 154uint32_t cb710_sg_dwiter_read_next_block(struct sg_mapping_iter *miter); 155void cb710_sg_dwiter_write_next_block(struct sg_mapping_iter *miter, uint32_t data); 156 157/** 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 162 * 163 * Description: 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. 168 * 169 * Context: 170 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise. 171 */ 172static inline void cb710_sg_dwiter_write_from_io(struct sg_mapping_iter *miter, 173 void __iomem *port, size_t count) 174{ 175 while (count-- > 0) 176 cb710_sg_dwiter_write_next_block(miter, ioread32(port)); 177} 178 179/** 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 184 * 185 * Description: 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. 190 * 191 * Context: 192 * IRQ disabled if the SG_MITER_ATOMIC is set. Don't care otherwise. 193 */ 194static inline void cb710_sg_dwiter_read_to_io(struct sg_mapping_iter *miter, 195 void __iomem *port, size_t count) 196{ 197 while (count-- > 0) 198 iowrite32(cb710_sg_dwiter_read_next_block(miter), port); 199} 200 201#endif /* LINUX_CB710_SG_H */