202 lines · c
1/* SPDX-License-Identifier: GPL-2.0-only */2/*3 * cb710/cb710.h4 *5 * Copyright by Michał Mirosław, 2008-20096 */7#ifndef LINUX_CB710_DRIVER_H8#define LINUX_CB710_DRIVER_H9 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_ASSUMPTIONS34 atomic_t slot_refs_count;35#endif36 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 and43 * they are all serialized wrt themselves */44 45/* cb710_chip.slot_mask values */46#define CB710_SLOT_MMC 147#define CB710_SLOT_MS 248#define CB710_SLOT_SM 449 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_DEBUG107void cb710_dump_regs(struct cb710_chip *chip, unsigned dump);108#else109#define cb710_dump_regs(c, d) do {} while (0)110#endif111 112#define CB710_DUMP_REGS_MMC 0x0F113#define CB710_DUMP_REGS_MS 0x30114#define CB710_DUMP_REGS_SM 0xC0115#define CB710_DUMP_REGS_ALL 0xFF116#define CB710_DUMP_REGS_MASK 0xFF117 118#define CB710_DUMP_ACCESS_8 0x100119#define CB710_DUMP_ACCESS_16 0x200120#define CB710_DUMP_ACCESS_32 0x400121#define CB710_DUMP_ACCESS_ALL 0x700122#define CB710_DUMP_ACCESS_MASK 0x700123 124#endif /* LINUX_CB710_DRIVER_H */125/*126 * cb710/sgbuf2.h127 *128 * Copyright by Michał Mirosław, 2008-2009129 */130#ifndef LINUX_CB710_SG_H131#define LINUX_CB710_SG_H132 133#include <linux/highmem.h>134#include <linux/scatterlist.h>135 136/*137 * 32-bit PIO mapping sg iterator138 *139 * Hides scatterlist access issues - fragment boundaries, alignment, page140 * mapping - for drivers using 32-bit-word-at-a-time-PIO (ie. PCI devices141 * 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 port159 * @miter: sg mapping iter160 * @port: PIO port - IO or MMIO address161 * @count: number of 32-bit words to transfer162 *163 * Description:164 * Reads @count 32-bit words from register @port and stores it in165 * buffer iterated by @miter. Data that would overflow the buffer166 * is silently ignored. Iterator is advanced by 4*@count bytes167 * 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 buffer181 * @miter: sg mapping iter182 * @port: PIO port - IO or MMIO address183 * @count: number of 32-bit words to transfer184 *185 * Description:186 * Writes @count 32-bit words to register @port from buffer iterated187 * through @miter. If buffer ends before @count words are written188 * missing data is replaced by zeroes. @miter is advanced by 4*@count189 * 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 */202