162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * driver for the carrier TEWS TPCI-200 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2009-2012 CERN (www.cern.ch) 662306a36Sopenharmony_ci * Author: Nicolas Serafini, EIC2 SA 762306a36Sopenharmony_ci * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _TPCI200_H_ 1162306a36Sopenharmony_ci#define _TPCI200_H_ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/limits.h> 1462306a36Sopenharmony_ci#include <linux/pci.h> 1562306a36Sopenharmony_ci#include <linux/spinlock.h> 1662306a36Sopenharmony_ci#include <linux/swab.h> 1762306a36Sopenharmony_ci#include <linux/io.h> 1862306a36Sopenharmony_ci#include <linux/ipack.h> 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define TPCI200_NB_SLOT 0x4 2162306a36Sopenharmony_ci#define TPCI200_NB_BAR 0x6 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define TPCI200_VENDOR_ID 0x1498 2462306a36Sopenharmony_ci#define TPCI200_DEVICE_ID 0x30C8 2562306a36Sopenharmony_ci#define TPCI200_SUBVENDOR_ID 0x1498 2662306a36Sopenharmony_ci#define TPCI200_SUBDEVICE_ID 0x300A 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#define TPCI200_CFG_MEM_BAR 0 2962306a36Sopenharmony_ci#define TPCI200_IP_INTERFACE_BAR 2 3062306a36Sopenharmony_ci#define TPCI200_IO_ID_INT_SPACES_BAR 3 3162306a36Sopenharmony_ci#define TPCI200_MEM16_SPACE_BAR 4 3262306a36Sopenharmony_ci#define TPCI200_MEM8_SPACE_BAR 5 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_cistruct tpci200_regs { 3562306a36Sopenharmony_ci __le16 revision; 3662306a36Sopenharmony_ci /* writes to control should occur with the mutex held to protect 3762306a36Sopenharmony_ci * read-modify-write operations */ 3862306a36Sopenharmony_ci __le16 control[4]; 3962306a36Sopenharmony_ci __le16 reset; 4062306a36Sopenharmony_ci __le16 status; 4162306a36Sopenharmony_ci u8 reserved[242]; 4262306a36Sopenharmony_ci} __packed; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define TPCI200_IFACE_SIZE 0x100 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define TPCI200_IO_SPACE_OFF 0x0000 4762306a36Sopenharmony_ci#define TPCI200_IO_SPACE_INTERVAL 0x0100 4862306a36Sopenharmony_ci#define TPCI200_IO_SPACE_SIZE 0x0080 4962306a36Sopenharmony_ci#define TPCI200_ID_SPACE_OFF 0x0080 5062306a36Sopenharmony_ci#define TPCI200_ID_SPACE_INTERVAL 0x0100 5162306a36Sopenharmony_ci#define TPCI200_ID_SPACE_SIZE 0x0040 5262306a36Sopenharmony_ci#define TPCI200_INT_SPACE_OFF 0x00C0 5362306a36Sopenharmony_ci#define TPCI200_INT_SPACE_INTERVAL 0x0100 5462306a36Sopenharmony_ci#define TPCI200_INT_SPACE_SIZE 0x0040 5562306a36Sopenharmony_ci#define TPCI200_IOIDINT_SIZE 0x0400 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define TPCI200_MEM8_SPACE_INTERVAL 0x00400000 5862306a36Sopenharmony_ci#define TPCI200_MEM8_SPACE_SIZE 0x00400000 5962306a36Sopenharmony_ci#define TPCI200_MEM16_SPACE_INTERVAL 0x00800000 6062306a36Sopenharmony_ci#define TPCI200_MEM16_SPACE_SIZE 0x00800000 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* control field in tpci200_regs */ 6362306a36Sopenharmony_ci#define TPCI200_INT0_EN 0x0040 6462306a36Sopenharmony_ci#define TPCI200_INT1_EN 0x0080 6562306a36Sopenharmony_ci#define TPCI200_INT0_EDGE 0x0010 6662306a36Sopenharmony_ci#define TPCI200_INT1_EDGE 0x0020 6762306a36Sopenharmony_ci#define TPCI200_ERR_INT_EN 0x0008 6862306a36Sopenharmony_ci#define TPCI200_TIME_INT_EN 0x0004 6962306a36Sopenharmony_ci#define TPCI200_RECOVER_EN 0x0002 7062306a36Sopenharmony_ci#define TPCI200_CLK32 0x0001 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* reset field in tpci200_regs */ 7362306a36Sopenharmony_ci#define TPCI200_A_RESET 0x0001 7462306a36Sopenharmony_ci#define TPCI200_B_RESET 0x0002 7562306a36Sopenharmony_ci#define TPCI200_C_RESET 0x0004 7662306a36Sopenharmony_ci#define TPCI200_D_RESET 0x0008 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci/* status field in tpci200_regs */ 7962306a36Sopenharmony_ci#define TPCI200_A_TIMEOUT 0x1000 8062306a36Sopenharmony_ci#define TPCI200_B_TIMEOUT 0x2000 8162306a36Sopenharmony_ci#define TPCI200_C_TIMEOUT 0x4000 8262306a36Sopenharmony_ci#define TPCI200_D_TIMEOUT 0x8000 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci#define TPCI200_A_ERROR 0x0100 8562306a36Sopenharmony_ci#define TPCI200_B_ERROR 0x0200 8662306a36Sopenharmony_ci#define TPCI200_C_ERROR 0x0400 8762306a36Sopenharmony_ci#define TPCI200_D_ERROR 0x0800 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci#define TPCI200_A_INT0 0x0001 9062306a36Sopenharmony_ci#define TPCI200_A_INT1 0x0002 9162306a36Sopenharmony_ci#define TPCI200_B_INT0 0x0004 9262306a36Sopenharmony_ci#define TPCI200_B_INT1 0x0008 9362306a36Sopenharmony_ci#define TPCI200_C_INT0 0x0010 9462306a36Sopenharmony_ci#define TPCI200_C_INT1 0x0020 9562306a36Sopenharmony_ci#define TPCI200_D_INT0 0x0040 9662306a36Sopenharmony_ci#define TPCI200_D_INT1 0x0080 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define TPCI200_SLOT_INT_MASK 0x00FF 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* PCI Configuration registers. The PCI bridge is a PLX Technology PCI9030. */ 10162306a36Sopenharmony_ci#define LAS1_DESC 0x2C 10262306a36Sopenharmony_ci#define LAS2_DESC 0x30 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/* Bits in the LAS?_DESC registers */ 10562306a36Sopenharmony_ci#define LAS_BIT_BIGENDIAN 24 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define VME_IOID_SPACE "IOID" 10862306a36Sopenharmony_ci#define VME_MEM_SPACE "MEM" 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/** 11162306a36Sopenharmony_ci * struct slot_irq - slot IRQ definition. 11262306a36Sopenharmony_ci * @vector Vector number 11362306a36Sopenharmony_ci * @handler Handler called when IRQ arrives 11462306a36Sopenharmony_ci * @arg Handler argument 11562306a36Sopenharmony_ci * 11662306a36Sopenharmony_ci */ 11762306a36Sopenharmony_cistruct slot_irq { 11862306a36Sopenharmony_ci struct ipack_device *holder; 11962306a36Sopenharmony_ci int vector; 12062306a36Sopenharmony_ci irqreturn_t (*handler)(void *); 12162306a36Sopenharmony_ci void *arg; 12262306a36Sopenharmony_ci}; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci/** 12562306a36Sopenharmony_ci * struct tpci200_slot - data specific to the tpci200 slot. 12662306a36Sopenharmony_ci * @slot_id Slot identification gived to external interface 12762306a36Sopenharmony_ci * @irq Slot IRQ infos 12862306a36Sopenharmony_ci * @io_phys IO physical base address register of the slot 12962306a36Sopenharmony_ci * @id_phys ID physical base address register of the slot 13062306a36Sopenharmony_ci * @int_phys INT physical base address register of the slot 13162306a36Sopenharmony_ci * @mem_phys MEM physical base address register of the slot 13262306a36Sopenharmony_ci * 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_cistruct tpci200_slot { 13562306a36Sopenharmony_ci struct slot_irq *irq; 13662306a36Sopenharmony_ci}; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/** 13962306a36Sopenharmony_ci * struct tpci200_infos - informations specific of the TPCI200 tpci200. 14062306a36Sopenharmony_ci * @pci_dev PCI device 14162306a36Sopenharmony_ci * @interface_regs Pointer to IP interface space (Bar 2) 14262306a36Sopenharmony_ci * @ioidint_space Pointer to IP ID, IO and INT space (Bar 3) 14362306a36Sopenharmony_ci * @mem8_space Pointer to MEM space (Bar 4) 14462306a36Sopenharmony_ci * 14562306a36Sopenharmony_ci */ 14662306a36Sopenharmony_cistruct tpci200_infos { 14762306a36Sopenharmony_ci struct pci_dev *pdev; 14862306a36Sopenharmony_ci struct pci_device_id *id_table; 14962306a36Sopenharmony_ci struct tpci200_regs __iomem *interface_regs; 15062306a36Sopenharmony_ci void __iomem *cfg_regs; 15162306a36Sopenharmony_ci struct ipack_bus_device *ipack_bus; 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_cistruct tpci200_board { 15462306a36Sopenharmony_ci unsigned int number; 15562306a36Sopenharmony_ci struct mutex mutex; 15662306a36Sopenharmony_ci spinlock_t regs_lock; 15762306a36Sopenharmony_ci struct tpci200_slot *slots; 15862306a36Sopenharmony_ci struct tpci200_infos *info; 15962306a36Sopenharmony_ci phys_addr_t mod_mem[IPACK_SPACE_COUNT]; 16062306a36Sopenharmony_ci}; 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#endif /* _TPCI200_H_ */ 163