Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: gpib: Add common include files for GPIB drivers

Common include files used only by the drivers.

Signed-off-by: Dave Penkler <dpenkler@gmail.com>
Link: https://lore.kernel.org/r/20240918121908.19366-4-dpenkler@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dave Penkler and committed by
Greg Kroah-Hartman
6c52d5e3 f11192a2

+1530
+49
drivers/staging/gpib/include/amcc5920.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * Header for amcc5920 pci chip 5 + * 6 + * copyright : (C) 2002 by Frank Mori Hess 7 + ***************************************************************************/ 8 + 9 + // plx pci chip registers and bits 10 + enum amcc_registers { 11 + AMCC_INTCS_REG = 0x38, 12 + AMCC_PASS_THRU_REG = 0x60, 13 + }; 14 + 15 + enum amcc_incsr_bits { 16 + AMCC_ADDON_INTR_ENABLE_BIT = 0x2000, 17 + AMCC_ADDON_INTR_ACTIVE_BIT = 0x400000, 18 + AMCC_INTR_ACTIVE_BIT = 0x800000, 19 + }; 20 + 21 + static const int bits_per_region = 8; 22 + 23 + static inline uint32_t amcc_wait_state_bits(unsigned int region, unsigned int num_wait_states) 24 + { 25 + return (num_wait_states & 0x7) << (-region * bits_per_region); 26 + }; 27 + 28 + enum amcc_prefetch_bits { 29 + PREFETCH_DISABLED = 0x0, 30 + PREFETCH_SMALL = 0x8, 31 + PREFETCH_MEDIUM = 0x10, 32 + PREFETCH_LARGE = 0x18, 33 + }; 34 + 35 + static inline uint32_t amcc_prefetch_bits(unsigned int region, enum amcc_prefetch_bits prefetch) 36 + { 37 + return prefetch << (--region * bits_per_region); 38 + }; 39 + 40 + static inline uint32_t amcc_PTADR_mode_bit(unsigned int region) 41 + { 42 + return 0x80 << (--region * bits_per_region); 43 + }; 44 + 45 + static inline uint32_t amcc_disable_write_fifo_bit(unsigned int region) 46 + { 47 + return 0x20 << (--region * bits_per_region); 48 + }; 49 +
+59
drivers/staging/gpib/include/amccs5933.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * Registers and bits for amccs5933 pci chip 5 + * copyright : (C) 2002 by Frank Mori Hess 6 + ***************************************************************************/ 7 + 8 + // register offsets 9 + enum { 10 + MBEF_REG = 0x34, // mailbux empty/full 11 + INTCSR_REG = 0x38, // interrupt control and status 12 + BMCSR_REG = 0x3c, // bus master control and status 13 + }; 14 + 15 + // incoming mailbox 0-3 register offsets 16 + extern inline int INCOMING_MAILBOX_REG(unsigned int mailbox) 17 + { 18 + return (0x10 + 4 * mailbox); 19 + }; 20 + 21 + // bit definitions 22 + 23 + // INTCSR bits 24 + enum { 25 + OUTBOX_EMPTY_INTR_BIT = 0x10, // enable outbox empty interrupt 26 + INBOX_FULL_INTR_BIT = 0x1000, // enable inbox full interrupt 27 + INBOX_INTR_CS_BIT = 0x20000, // read, or write clear inbox full interrupt 28 + INTR_ASSERTED_BIT = 0x800000, // read only, interrupt asserted 29 + }; 30 + 31 + // select byte 0 to 3 of incoming mailbox 32 + extern inline int INBOX_BYTE_BITS(unsigned int byte) 33 + { 34 + return (byte & 0x3) << 8; 35 + }; 36 + 37 + // select incoming mailbox 0 to 3 38 + extern inline int INBOX_SELECT_BITS(unsigned int mailbox) 39 + { 40 + return (mailbox & 0x3) << 10; 41 + }; 42 + 43 + // select byte 0 to 3 of outgoing mailbox 44 + extern inline int OUTBOX_BYTE_BITS(unsigned int byte) 45 + { 46 + return (byte & 0x3); 47 + }; 48 + 49 + // select outgoing mailbox 0 to 3 50 + extern inline int OUTBOX_SELECT_BITS(unsigned int mailbox) 51 + { 52 + return (mailbox & 0x3) << 2; 53 + }; 54 + 55 + //BMCSR bits 56 + enum { 57 + MBOX_FLAGS_RESET_BIT = 0x08000000, // resets mailbox empty/full flags 58 + }; 59 +
+56
drivers/staging/gpib/include/gpibP.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2002,2003 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _GPIB_P_H 8 + #define _GPIB_P_H 9 + 10 + #include <linux/types.h> 11 + 12 + #include "gpib_types.h" 13 + #include "gpib_proto.h" 14 + #include "gpib_user.h" 15 + #include "gpib_ioctl.h" 16 + 17 + #include <linux/fs.h> 18 + #include <linux/interrupt.h> 19 + 20 + void gpib_register_driver(gpib_interface_t *interface, struct module *mod); 21 + void gpib_unregister_driver(gpib_interface_t *interface); 22 + struct pci_dev *gpib_pci_get_device(const gpib_board_config_t *config, unsigned int vendor_id, 23 + unsigned int device_id, struct pci_dev *from); 24 + struct pci_dev *gpib_pci_get_subsys(const gpib_board_config_t *config, unsigned int vendor_id, 25 + unsigned int device_id, unsigned int ss_vendor, 26 + unsigned int ss_device, struct pci_dev *from); 27 + unsigned int num_gpib_events(const gpib_event_queue_t *queue); 28 + int push_gpib_event(gpib_board_t *board, short event_type); 29 + int pop_gpib_event(gpib_event_queue_t *queue, short *event_type); 30 + int gpib_request_pseudo_irq(gpib_board_t *board, irqreturn_t (*handler)(int, void *)); 31 + void gpib_free_pseudo_irq(gpib_board_t *board); 32 + int gpib_match_device_path(struct device *dev, const char *device_path_in); 33 + 34 + extern gpib_board_t board_array[GPIB_MAX_NUM_BOARDS]; 35 + 36 + extern struct list_head registered_drivers; 37 + 38 + #ifdef GPIB_DEBUG 39 + #define GPIB_DPRINTK(format, args...) pr_info("gpib debug: " format, ## args) 40 + #else 41 + #define GPIB_DPRINTK(arg...) 42 + #endif 43 + 44 + #include <linux/io.h> 45 + 46 + void writeb_wrapper(unsigned int value, void *address); 47 + unsigned int readb_wrapper(void *address); 48 + void outb_wrapper(unsigned int value, void *address); 49 + unsigned int inb_wrapper(void *address); 50 + void writew_wrapper(unsigned int value, void *address); 51 + unsigned int readw_wrapper(void *address); 52 + void outw_wrapper(unsigned int value, void *address); 53 + unsigned int inw_wrapper(void *address); 54 + 55 + #endif // _GPIB_P_H 56 +
+23
drivers/staging/gpib/include/gpib_pci_ids.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef __GPIB_PCI_IDS_H 4 + #define __GPIB_LINUX_PCI_IDS_H 5 + 6 + #ifndef PCI_VENDOR_ID_AMCC 7 + #define PCI_VENDOR_ID_AMCC 0x10e8 8 + #endif 9 + 10 + #ifndef PCI_VENDOR_ID_CBOARDS 11 + #define PCI_VENDOR_ID_CBOARDS 0x1307 12 + #endif 13 + 14 + #ifndef PCI_VENDOR_ID_QUANCOM 15 + #define PCI_VENDOR_ID_QUANCOM 0x8008 16 + #endif 17 + 18 + #ifndef PCI_DEVICE_ID_QUANCOM_GPIB 19 + #define PCI_DEVICE_ID_QUANCOM_GPIB 0x3302 20 + #endif 21 + 22 + #endif // __GPIB_PCI_IDS_H 23 +
+56
drivers/staging/gpib/include/gpib_proto.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef GPIB_PROTO_INCLUDED 4 + #define GPIB_PROTO_INCLUDED 5 + 6 + #include <linux/fs.h> 7 + 8 + int ibopen(struct inode *inode, struct file *filep); 9 + int ibclose(struct inode *inode, struct file *file); 10 + long ibioctl(struct file *filep, unsigned int cmd, unsigned long arg); 11 + int osInit(void); 12 + void osReset(void); 13 + void os_start_timer(gpib_board_t *board, unsigned int usec_timeout); 14 + void os_remove_timer(gpib_board_t *board); 15 + void osSendEOI(void); 16 + void osSendEOI(void); 17 + void init_gpib_board(gpib_board_t *board); 18 + static inline unsigned long usec_to_jiffies(unsigned int usec) 19 + { 20 + unsigned long usec_per_jiffy = 1000000 / HZ; 21 + 22 + return 1 + (usec + usec_per_jiffy - 1) / usec_per_jiffy; 23 + }; 24 + 25 + int serial_poll_all(gpib_board_t *board, unsigned int usec_timeout); 26 + void init_gpib_descriptor(gpib_descriptor_t *desc); 27 + int dvrsp(gpib_board_t *board, unsigned int pad, int sad, 28 + unsigned int usec_timeout, uint8_t *result); 29 + int ibAPWait(gpib_board_t *board, int pad); 30 + int ibAPrsp(gpib_board_t *board, int padsad, char *spb); 31 + void ibAPE(gpib_board_t *board, int pad, int v); 32 + int ibcac(gpib_board_t *board, int sync, int fallback_to_async); 33 + int ibcmd(gpib_board_t *board, uint8_t *buf, size_t length, size_t *bytes_written); 34 + int ibgts(gpib_board_t *board); 35 + int ibonline(gpib_board_t *board); 36 + int iboffline(gpib_board_t *board); 37 + int iblines(const gpib_board_t *board, short *lines); 38 + int ibrd(gpib_board_t *board, uint8_t *buf, size_t length, int *end_flag, size_t *bytes_read); 39 + int ibrpp(gpib_board_t *board, uint8_t *buf); 40 + int ibrsv2(gpib_board_t *board, uint8_t status_byte, int new_reason_for_service); 41 + void ibrsc(gpib_board_t *board, int request_control); 42 + int ibsic(gpib_board_t *board, unsigned int usec_duration); 43 + int ibsre(gpib_board_t *board, int enable); 44 + int ibpad(gpib_board_t *board, unsigned int addr); 45 + int ibsad(gpib_board_t *board, int addr); 46 + int ibeos(gpib_board_t *board, int eos, int eosflags); 47 + int ibwait(gpib_board_t *board, int wait_mask, int clear_mask, int set_mask, 48 + int *status, unsigned long usec_timeout, gpib_descriptor_t *desc); 49 + int ibwrt(gpib_board_t *board, uint8_t *buf, size_t cnt, int send_eoi, size_t *bytes_written); 50 + int ibstatus(gpib_board_t *board); 51 + int general_ibstatus(gpib_board_t *board, const gpib_status_queue_t *device, 52 + int clear_mask, int set_mask, gpib_descriptor_t *desc); 53 + int io_timed_out(gpib_board_t *board); 54 + int ibppc(gpib_board_t *board, uint8_t configuration); 55 + 56 + #endif /* GPIB_PROTO_INCLUDED */
+23
drivers/staging/gpib/include/gpib_state_machines.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2006 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _GPIB_STATE_MACHINES_H 8 + #define _GPIB_STATE_MACHINES_H 9 + 10 + enum talker_function_state { 11 + talker_idle, 12 + talker_addressed, 13 + talker_active, 14 + serial_poll_active 15 + }; 16 + 17 + enum listener_function_state { 18 + listener_idle, 19 + listener_addressed, 20 + listener_active 21 + }; 22 + 23 + #endif // _GPIB_STATE_MACHINES_H
+353
drivers/staging/gpib/include/gpib_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2002 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _GPIB_TYPES_H 8 + #define _GPIB_TYPES_H 9 + 10 + #ifdef __KERNEL__ 11 + /* gpib_interface_t defines the interface 12 + * between the board-specific details dealt with in the drivers 13 + * and generic interface provided by gpib-common. 14 + * This really should be in a different header file. 15 + */ 16 + #include "gpib_user.h" 17 + #include <linux/atomic.h> 18 + #include <linux/device.h> 19 + #include <linux/mutex.h> 20 + #include <linux/wait.h> 21 + #include <linux/sched.h> 22 + #include <linux/timer.h> 23 + #include <linux/interrupt.h> 24 + 25 + typedef struct gpib_interface_struct gpib_interface_t; 26 + typedef struct gpib_board_struct gpib_board_t; 27 + 28 + /* config parameters that are only used by driver attach functions */ 29 + typedef struct { 30 + /* firmware blob */ 31 + void *init_data; 32 + int init_data_length; 33 + /* IO base address to use for non-pnp cards (set by core, driver should make local copy) */ 34 + void *ibbase; 35 + /* IRQ to use for non-pnp cards (set by core, driver should make local copy) */ 36 + unsigned int ibirq; 37 + /* dma channel to use for non-pnp cards (set by core, driver should make local copy) */ 38 + unsigned int ibdma; 39 + /* pci bus of card, useful for distinguishing multiple identical pci cards 40 + * (negative means don't care) 41 + */ 42 + int pci_bus; 43 + /* pci slot of card, useful for distinguishing multiple identical pci cards 44 + * (negative means don't care) 45 + */ 46 + int pci_slot; 47 + /* sysfs device path of hardware to attach */ 48 + char *device_path; 49 + /* serial number of hardware to attach */ 50 + char *serial_number; 51 + } gpib_board_config_t; 52 + 53 + struct gpib_interface_struct { 54 + /* name of board */ 55 + char *name; 56 + /* attach() initializes board and allocates resources */ 57 + int (*attach)(gpib_board_t *board, const gpib_board_config_t *config); 58 + /* detach() shuts down board and frees resources */ 59 + void (*detach)(gpib_board_t *board); 60 + /* read() should read at most 'length' bytes from the bus into 61 + * 'buffer'. It should return when it fills the buffer or 62 + * encounters an END (EOI and or EOS if appropriate). It should set 'end' 63 + * to be nonzero if the read was terminated by an END, otherwise 'end' 64 + * should be zero. 65 + * Ultimately, this will be changed into or replaced by an asynchronous 66 + * read. Zero return value for success, negative 67 + * return indicates error. 68 + * nbytes returns number of bytes read 69 + */ 70 + int (*read)(gpib_board_t *board, uint8_t *buffer, size_t length, int *end, 71 + size_t *bytes_read); 72 + /* write() should write 'length' bytes from buffer to the bus. 73 + * If the boolean value send_eoi is nonzero, then EOI should 74 + * be sent along with the last byte. Returns number of bytes 75 + * written or negative value on error. 76 + */ 77 + int (*write)(gpib_board_t *board, uint8_t *buffer, size_t length, int send_eoi, 78 + size_t *bytes_written); 79 + /* command() writes the command bytes in 'buffer' to the bus 80 + * Returns zero on success or negative value on error. 81 + */ 82 + int (*command)(gpib_board_t *board, uint8_t *buffer, size_t length, 83 + size_t *bytes_written); 84 + /* Take control (assert ATN). If 'asyncronous' is nonzero, take 85 + * control asyncronously (assert ATN immediately without waiting 86 + * for other processes to complete first). Should not return 87 + * until board becomes controller in charge. Returns zero no success, 88 + * nonzero on error. 89 + */ 90 + int (*take_control)(gpib_board_t *board, int asyncronous); 91 + /* De-assert ATN. Returns zero on success, nonzer on error. 92 + */ 93 + int (*go_to_standby)(gpib_board_t *board); 94 + /* request/release control of the IFC and REN lines (system controller) */ 95 + void (*request_system_control)(gpib_board_t *board, int request_control); 96 + /* Asserts or de-asserts 'interface clear' (IFC) depending on 97 + * boolean value of 'assert' 98 + */ 99 + void (*interface_clear)(gpib_board_t *board, int assert); 100 + /* Sends remote enable command if 'enable' is nonzero, disables remote mode 101 + * if 'enable' is zero 102 + */ 103 + void (*remote_enable)(gpib_board_t *board, int enable); 104 + /* enable END for reads, when byte 'eos' is received. If 105 + * 'compare_8_bits' is nonzero, then all 8 bits are compared 106 + * with the eos bytes. Otherwise only the 7 least significant 107 + * bits are compared. 108 + */ 109 + int (*enable_eos)(gpib_board_t *board, uint8_t eos, int compare_8_bits); 110 + /* disable END on eos byte (END on EOI only)*/ 111 + void (*disable_eos)(gpib_board_t *board); 112 + /* configure parallel poll */ 113 + void (*parallel_poll_configure)(gpib_board_t *board, uint8_t configuration); 114 + /* conduct parallel poll */ 115 + int (*parallel_poll)(gpib_board_t *board, uint8_t *result); 116 + /* set/clear ist (individual status bit) */ 117 + void (*parallel_poll_response)(gpib_board_t *board, int ist); 118 + /* select local parallel poll configuration mode PP2 versus remote PP1 */ 119 + void (*local_parallel_poll_mode)(gpib_board_t *board, int local); 120 + /* Returns current status of the bus lines. Should be set to 121 + * NULL if your board does not have the ability to query the 122 + * state of the bus lines. 123 + */ 124 + int (*line_status)(const gpib_board_t *board); 125 + /* updates and returns the board's current status. 126 + * The meaning of the bits are specified in gpib_user.h 127 + * in the IBSTA section. The driver does not need to 128 + * worry about setting the CMPL, END, TIMO, or ERR bits. 129 + */ 130 + unsigned int (*update_status)(gpib_board_t *board, unsigned int clear_mask); 131 + /* Sets primary address 0-30 for gpib interface card. 132 + */ 133 + int (*primary_address)(gpib_board_t *board, unsigned int address); 134 + /* Sets and enables, or disables secondary address 0-30 135 + * for gpib interface card. 136 + */ 137 + int (*secondary_address)(gpib_board_t *board, unsigned int address, 138 + int enable); 139 + /* Sets the byte the board should send in response to a serial poll. 140 + * This function should also start or stop requests for service via 141 + * IEEE 488.2 reqt/reqf, based on MSS (bit 6 of the status_byte). 142 + * If the more flexible serial_poll_response2 is implemented by the 143 + * driver, then this method should be left NULL since it will not 144 + * be used. This method can generate spurious service requests 145 + * which are allowed by IEEE 488.2, but not ideal. 146 + * 147 + * This method should implement the serial poll response method described 148 + * by IEEE 488.2 section 11.3.3.4.3 "Allowed Coupled Control of 149 + * STB, reqt, and reqf". 150 + */ 151 + void (*serial_poll_response)(gpib_board_t *board, uint8_t status_byte); 152 + /* Sets the byte the board should send in response to a serial poll. 153 + * This function should also request service via IEEE 488.2 reqt/reqf 154 + * based on MSS (bit 6 of the status_byte) and new_reason_for_service. 155 + * reqt should be set true if new_reason_for_service is true, 156 + * and reqf should be set true if MSS is false. This function 157 + * will never be called with MSS false and new_reason_for_service 158 + * true simultaneously, so don't worry about that case. 159 + * 160 + * This method implements the serial poll response method described 161 + * by IEEE 488.2 section 11.3.3.4.1 "Preferred Implementation". 162 + * 163 + * If this method is left NULL by the driver, then the user library 164 + * function ibrsv2 will not work. 165 + */ 166 + void (*serial_poll_response2)(gpib_board_t *board, uint8_t status_byte, 167 + int new_reason_for_service); 168 + /* returns the byte the board will send in response to a serial poll. 169 + */ 170 + uint8_t (*serial_poll_status)(gpib_board_t *board); 171 + /* adjust T1 delay */ 172 + unsigned int (*t1_delay)(gpib_board_t *board, unsigned int nano_sec); 173 + /* go to local mode */ 174 + void (*return_to_local)(gpib_board_t *board); 175 + /* board does not support 7 bit eos comparisons */ 176 + unsigned no_7_bit_eos : 1; 177 + /* skip check for listeners before trying to send command bytes */ 178 + unsigned skip_check_for_command_acceptors : 1; 179 + }; 180 + 181 + typedef struct { 182 + struct list_head event_head; 183 + spinlock_t lock; // for access to event list 184 + unsigned int num_events; 185 + unsigned dropped_event : 1; 186 + } gpib_event_queue_t; 187 + 188 + static inline void init_event_queue(gpib_event_queue_t *queue) 189 + { 190 + INIT_LIST_HEAD(&queue->event_head); 191 + queue->num_events = 0; 192 + queue->dropped_event = 0; 193 + spin_lock_init(&queue->lock); 194 + } 195 + 196 + /* struct for supporting polling operation when irq is not available */ 197 + struct gpib_pseudo_irq { 198 + struct timer_list timer; 199 + irqreturn_t (*handler)(int irq, void *arg); 200 + gpib_board_t *board; 201 + atomic_t active; 202 + }; 203 + 204 + static inline void init_gpib_pseudo_irq(struct gpib_pseudo_irq *pseudo_irq) 205 + { 206 + pseudo_irq->handler = NULL; 207 + timer_setup(&pseudo_irq->timer, NULL, 0); 208 + atomic_set(&pseudo_irq->active, 0); 209 + } 210 + 211 + /* list so we can make a linked list of drivers */ 212 + typedef struct gpib_interface_list_struct { 213 + struct list_head list; 214 + gpib_interface_t *interface; 215 + struct module *module; 216 + } gpib_interface_list_t; 217 + 218 + /* One gpib_board_t is allocated for each physical board in the computer. 219 + * It provides storage for variables local to each board, and interface 220 + * functions for performing operations on the board 221 + */ 222 + struct gpib_board_struct { 223 + /* functions used by this board */ 224 + gpib_interface_t *interface; 225 + /* Pointer to module whose use count we should increment when 226 + * interface is in use 227 + */ 228 + struct module *provider_module; 229 + /* buffer used to store read/write data for this board */ 230 + u8 *buffer; 231 + /* length of buffer */ 232 + unsigned int buffer_length; 233 + /* Used to hold the board's current status (see update_status() above) 234 + */ 235 + unsigned long status; 236 + /* Driver should only sleep on this wait queue. It is special in that the 237 + * core will wake this queue and set the TIMO bit in 'status' when the 238 + * watchdog timer times out. 239 + */ 240 + wait_queue_head_t wait; 241 + /* Lock that only allows one process to access this board at a time. 242 + * Has to be first in any locking order, since it can be locked over 243 + * multiple ioctls. 244 + */ 245 + struct mutex user_mutex; 246 + /* Mutex which compensates for removal of "big kernel lock" from kernel. 247 + * Should not be held for extended waits. 248 + */ 249 + struct mutex big_gpib_mutex; 250 + /* pid of last process to lock the board mutex */ 251 + pid_t locking_pid; 252 + spinlock_t locking_pid_spinlock; // lock for setting locking pid 253 + /* Spin lock for dealing with races with the interrupt handler */ 254 + spinlock_t spinlock; 255 + /* Watchdog timer to enable timeouts */ 256 + struct timer_list timer; 257 + /* device of attached driver if any */ 258 + struct device *dev; 259 + /* gpib_common device gpibN */ 260 + struct device *gpib_dev; 261 + /* 'private_data' can be used as seen fit by the driver to 262 + * store additional variables for this board 263 + */ 264 + void *private_data; 265 + /* Number of open file descriptors using this board */ 266 + unsigned int use_count; 267 + /* list of open devices connected to this board */ 268 + struct list_head device_list; 269 + /* primary address */ 270 + unsigned int pad; 271 + /* secondary address */ 272 + int sad; 273 + /* timeout for io operations, in microseconds */ 274 + unsigned int usec_timeout; 275 + /* board's parallel poll configuration byte */ 276 + u8 parallel_poll_configuration; 277 + /* t1 delay we are using */ 278 + unsigned int t1_nano_sec; 279 + /* Count that keeps track of whether board is up and running or not */ 280 + unsigned int online; 281 + /* number of processes trying to autopoll */ 282 + int autospollers; 283 + /* autospoll kernel thread */ 284 + struct task_struct *autospoll_task; 285 + /* queue for recording received trigger/clear/ifc events */ 286 + gpib_event_queue_t event_queue; 287 + /* minor number for this board's device file */ 288 + int minor; 289 + /* struct to deal with polling mode*/ 290 + struct gpib_pseudo_irq pseudo_irq; 291 + /* error dong autopoll */ 292 + atomic_t stuck_srq; 293 + gpib_board_config_t config; 294 + /* Flag that indicates whether board is system controller of the bus */ 295 + unsigned master : 1; 296 + /* individual status bit */ 297 + unsigned ist : 1; 298 + /* one means local parallel poll mode ieee 488.1 PP2 (or no parallel poll PP0), 299 + * zero means remote parallel poll configuration mode ieee 488.1 PP1 300 + */ 301 + unsigned local_ppoll_mode : 1; 302 + }; 303 + 304 + /* element of event queue */ 305 + typedef struct { 306 + struct list_head list; 307 + short event_type; 308 + } gpib_event_t; 309 + 310 + /* Each board has a list of gpib_status_queue_t to keep track of all open devices 311 + * on the bus, so we know what address to poll when we get a service request 312 + */ 313 + typedef struct { 314 + /* list_head so we can make a linked list of devices */ 315 + struct list_head list; 316 + unsigned int pad; /* primary gpib address */ 317 + int sad; /* secondary gpib address (negative means disabled) */ 318 + /* stores serial poll bytes for this device */ 319 + struct list_head status_bytes; 320 + unsigned int num_status_bytes; 321 + /* number of times this address is opened */ 322 + unsigned int reference_count; 323 + /* flags loss of status byte error due to limit on size of queue */ 324 + unsigned dropped_byte : 1; 325 + } gpib_status_queue_t; 326 + 327 + typedef struct { 328 + struct list_head list; 329 + u8 poll_byte; 330 + } status_byte_t; 331 + 332 + void init_gpib_status_queue(gpib_status_queue_t *device); 333 + 334 + /* Used to store device-descriptor-specific information */ 335 + typedef struct { 336 + unsigned int pad; /* primary gpib address */ 337 + int sad; /* secondary gpib address (negative means disabled) */ 338 + atomic_t io_in_progress; 339 + unsigned is_board : 1; 340 + unsigned autopoll_enabled : 1; 341 + } gpib_descriptor_t; 342 + 343 + typedef struct { 344 + atomic_t holding_mutex; 345 + gpib_descriptor_t *descriptors[GPIB_MAX_NUM_DESCRIPTORS]; 346 + /* locked while descriptors are being allocated/deallocated */ 347 + struct mutex descriptors_mutex; 348 + unsigned got_module : 1; 349 + } gpib_file_private_t; 350 + 351 + #endif /* __KERNEL__ */ 352 + 353 + #endif /* _GPIB_TYPES_H */
+138
drivers/staging/gpib/include/nec7210.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2002 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _NEC7210_H 8 + #define _NEC7210_H 9 + 10 + #include "gpib_state_machines.h" 11 + #include <linux/types.h> 12 + #include <linux/spinlock.h> 13 + #include <linux/string.h> 14 + #include <linux/interrupt.h> 15 + 16 + #include "gpib_types.h" 17 + #include "nec7210_registers.h" 18 + 19 + /* struct used to provide variables local to a nec7210 chip */ 20 + struct nec7210_priv { 21 + void *iobase; 22 + unsigned int offset; // offset between successive nec7210 io addresses 23 + unsigned int dma_channel; 24 + u8 *dma_buffer; 25 + unsigned int dma_buffer_length; // length of dma buffer 26 + dma_addr_t dma_buffer_addr; // bus address of board->buffer for use with dma 27 + // software copy of bits written to registers 28 + u8 reg_bits[8]; 29 + u8 auxa_bits; // bits written to auxiliary register A 30 + u8 auxb_bits; // bits written to auxiliary register B 31 + // used to keep track of board's state, bit definitions given below 32 + unsigned long state; 33 + /* lock for chips that extend the nec7210 registers by paging in alternate regs */ 34 + spinlock_t register_page_lock; 35 + // wrappers for outb, inb, readb, or writeb 36 + u8 (*read_byte)(struct nec7210_priv *priv, unsigned int register_number); 37 + void (*write_byte)(struct nec7210_priv *priv, u8 byte, unsigned int register_number); 38 + enum nec7210_chipset type; 39 + enum talker_function_state talker_state; 40 + enum listener_function_state listener_state; 41 + void *private; 42 + unsigned srq_pending : 1; 43 + }; 44 + 45 + static inline void init_nec7210_private(struct nec7210_priv *priv) 46 + { 47 + memset(priv, 0, sizeof(struct nec7210_priv)); 48 + spin_lock_init(&priv->register_page_lock); 49 + } 50 + 51 + // slightly shorter way to access read_byte and write_byte 52 + static inline u8 read_byte(struct nec7210_priv *priv, unsigned int register_number) 53 + { 54 + return priv->read_byte(priv, register_number); 55 + } 56 + 57 + static inline void write_byte(struct nec7210_priv *priv, u8 byte, unsigned int register_number) 58 + { 59 + priv->write_byte(priv, byte, register_number); 60 + } 61 + 62 + // struct nec7210_priv.state bit numbers 63 + enum { 64 + PIO_IN_PROGRESS_BN, // pio transfer in progress 65 + DMA_READ_IN_PROGRESS_BN, // dma read transfer in progress 66 + DMA_WRITE_IN_PROGRESS_BN, // dma write transfer in progress 67 + READ_READY_BN, // board has data byte available to read 68 + WRITE_READY_BN, // board is ready to send a data byte 69 + COMMAND_READY_BN, // board is ready to send a command byte 70 + RECEIVED_END_BN, // received END 71 + BUS_ERROR_BN, // output error has occurred 72 + RFD_HOLDOFF_BN, // rfd holdoff in effect 73 + DEV_CLEAR_BN, // device clear received 74 + ADR_CHANGE_BN, // address state change occurred 75 + }; 76 + 77 + // interface functions 78 + int nec7210_read(gpib_board_t *board, struct nec7210_priv *priv, uint8_t *buffer, 79 + size_t length, int *end, size_t *bytes_read); 80 + int nec7210_write(gpib_board_t *board, struct nec7210_priv *priv, uint8_t *buffer, 81 + size_t length, int send_eoi, size_t *bytes_written); 82 + int nec7210_command(gpib_board_t *board, struct nec7210_priv *priv, uint8_t *buffer, 83 + size_t length, size_t *bytes_written); 84 + int nec7210_take_control(gpib_board_t *board, struct nec7210_priv *priv, int syncronous); 85 + int nec7210_go_to_standby(gpib_board_t *board, struct nec7210_priv *priv); 86 + void nec7210_request_system_control(gpib_board_t *board, 87 + struct nec7210_priv *priv, int request_control); 88 + void nec7210_interface_clear(gpib_board_t *board, struct nec7210_priv *priv, int assert); 89 + void nec7210_remote_enable(gpib_board_t *board, struct nec7210_priv *priv, int enable); 90 + int nec7210_enable_eos(gpib_board_t *board, struct nec7210_priv *priv, uint8_t eos_bytes, 91 + int compare_8_bits); 92 + void nec7210_disable_eos(gpib_board_t *board, struct nec7210_priv *priv); 93 + unsigned int nec7210_update_status(gpib_board_t *board, struct nec7210_priv *priv, 94 + unsigned int clear_mask); 95 + unsigned int nec7210_update_status_nolock(gpib_board_t *board, struct nec7210_priv *priv); 96 + int nec7210_primary_address(const gpib_board_t *board, 97 + struct nec7210_priv *priv, unsigned int address); 98 + int nec7210_secondary_address(const gpib_board_t *board, struct nec7210_priv *priv, 99 + unsigned int address, int enable); 100 + int nec7210_parallel_poll(gpib_board_t *board, struct nec7210_priv *priv, uint8_t *result); 101 + void nec7210_serial_poll_response(gpib_board_t *board, struct nec7210_priv *priv, uint8_t status); 102 + void nec7210_parallel_poll_configure(gpib_board_t *board, 103 + struct nec7210_priv *priv, unsigned int configuration); 104 + void nec7210_parallel_poll_response(gpib_board_t *board, 105 + struct nec7210_priv *priv, int ist); 106 + uint8_t nec7210_serial_poll_status(gpib_board_t *board, 107 + struct nec7210_priv *priv); 108 + unsigned int nec7210_t1_delay(gpib_board_t *board, 109 + struct nec7210_priv *priv, unsigned int nano_sec); 110 + void nec7210_return_to_local(const gpib_board_t *board, struct nec7210_priv *priv); 111 + 112 + // utility functions 113 + void nec7210_board_reset(struct nec7210_priv *priv, const gpib_board_t *board); 114 + void nec7210_board_online(struct nec7210_priv *priv, const gpib_board_t *board); 115 + unsigned int nec7210_set_reg_bits(struct nec7210_priv *priv, unsigned int reg, 116 + unsigned int mask, unsigned int bits); 117 + void nec7210_set_handshake_mode(gpib_board_t *board, struct nec7210_priv *priv, int mode); 118 + void nec7210_release_rfd_holdoff(gpib_board_t *board, struct nec7210_priv *priv); 119 + uint8_t nec7210_read_data_in(gpib_board_t *board, struct nec7210_priv *priv, int *end); 120 + 121 + // wrappers for io functions 122 + uint8_t nec7210_ioport_read_byte(struct nec7210_priv *priv, unsigned int register_num); 123 + void nec7210_ioport_write_byte(struct nec7210_priv *priv, uint8_t data, unsigned int register_num); 124 + uint8_t nec7210_iomem_read_byte(struct nec7210_priv *priv, unsigned int register_num); 125 + void nec7210_iomem_write_byte(struct nec7210_priv *priv, uint8_t data, unsigned int register_num); 126 + uint8_t nec7210_locking_ioport_read_byte(struct nec7210_priv *priv, unsigned int register_num); 127 + void nec7210_locking_ioport_write_byte(struct nec7210_priv *priv, uint8_t data, 128 + unsigned int register_num); 129 + uint8_t nec7210_locking_iomem_read_byte(struct nec7210_priv *priv, unsigned int register_num); 130 + void nec7210_locking_iomem_write_byte(struct nec7210_priv *priv, uint8_t data, 131 + unsigned int register_num); 132 + 133 + // interrupt service routine 134 + irqreturn_t nec7210_interrupt(gpib_board_t *board, struct nec7210_priv *priv); 135 + irqreturn_t nec7210_interrupt_have_status(gpib_board_t *board, 136 + struct nec7210_priv *priv, int status1, int status2); 137 + 138 + #endif //_NEC7210_H
+217
drivers/staging/gpib/include/nec7210_registers.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2002 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _NEC7210_REGISTERS_H 8 + #define _NEC7210_REGISTERS_H 9 + 10 + enum nec7210_chipset { 11 + NEC7210, // The original 12 + TNT4882, // NI 13 + NAT4882, // NI 14 + CB7210, // measurement computing 15 + IOT7210, // iotech 16 + IGPIB7210, // Ines 17 + TNT5004, // NI (minor differences to TNT4882) 18 + }; 19 + 20 + // nec7210 has 8 registers 21 + static const int nec7210_num_registers = 8; 22 + 23 + /* nec7210 register numbers (might need to be multiplied by 24 + * a board-dependent offset to get actually io address offset) 25 + */ 26 + // write registers 27 + enum nec7210_write_regs { 28 + CDOR, // command/data out 29 + IMR1, // interrupt mask 1 30 + IMR2, // interrupt mask 2 31 + SPMR, // serial poll mode 32 + ADMR, // address mode 33 + AUXMR, // auxiliary mode 34 + ADR, // address 35 + EOSR, // end-of-string 36 + }; 37 + 38 + // read registers 39 + enum nec7210_read_regs { 40 + DIR, // data in 41 + ISR1, // interrupt status 1 42 + ISR2, // interrupt status 2 43 + SPSR, // serial poll status 44 + ADSR, // address status 45 + CPTR, // command pass though 46 + ADR0, // address 1 47 + ADR1, // address 2 48 + }; 49 + 50 + //bit definitions common to nec-7210 compatible registers 51 + 52 + // ISR1: interrupt status register 1 53 + enum isr1_bits { 54 + HR_DI = (1 << 0), 55 + HR_DO = (1 << 1), 56 + HR_ERR = (1 << 2), 57 + HR_DEC = (1 << 3), 58 + HR_END = (1 << 4), 59 + HR_DET = (1 << 5), 60 + HR_APT = (1 << 6), 61 + HR_CPT = (1 << 7), 62 + }; 63 + 64 + // IMR1: interrupt mask register 1 65 + enum imr1_bits { 66 + HR_DIIE = (1 << 0), 67 + HR_DOIE = (1 << 1), 68 + HR_ERRIE = (1 << 2), 69 + HR_DECIE = (1 << 3), 70 + HR_ENDIE = (1 << 4), 71 + HR_DETIE = (1 << 5), 72 + HR_APTIE = (1 << 6), 73 + HR_CPTIE = (1 << 7), 74 + }; 75 + 76 + // ISR2, interrupt status register 2 77 + enum isr2_bits { 78 + HR_ADSC = (1 << 0), 79 + HR_REMC = (1 << 1), 80 + HR_LOKC = (1 << 2), 81 + HR_CO = (1 << 3), 82 + HR_REM = (1 << 4), 83 + HR_LOK = (1 << 5), 84 + HR_SRQI = (1 << 6), 85 + HR_INT = (1 << 7), 86 + }; 87 + 88 + // IMR2, interrupt mask register 2 89 + enum imr2_bits { 90 + // all the bits in this register that enable interrupts 91 + IMR2_ENABLE_INTR_MASK = 0x4f, 92 + HR_ACIE = (1 << 0), 93 + HR_REMIE = (1 << 1), 94 + HR_LOKIE = (1 << 2), 95 + HR_COIE = (1 << 3), 96 + HR_DMAI = (1 << 4), 97 + HR_DMAO = (1 << 5), 98 + HR_SRQIE = (1 << 6), 99 + }; 100 + 101 + // SPSR, serial poll status register 102 + enum spsr_bits { 103 + HR_PEND = (1 << 6), 104 + }; 105 + 106 + // SPMR, serial poll mode register 107 + enum spmr_bits { 108 + HR_RSV = (1 << 6), 109 + }; 110 + 111 + // ADSR, address status register 112 + enum adsr_bits { 113 + HR_MJMN = (1 << 0), 114 + HR_TA = (1 << 1), 115 + HR_LA = (1 << 2), 116 + HR_TPAS = (1 << 3), 117 + HR_LPAS = (1 << 4), 118 + HR_SPMS = (1 << 5), 119 + HR_NATN = (1 << 6), 120 + HR_CIC = (1 << 7), 121 + }; 122 + 123 + // ADMR, address mode register 124 + enum admr_bits { 125 + HR_ADM0 = (1 << 0), 126 + HR_ADM1 = (1 << 1), 127 + HR_TRM0 = (1 << 4), 128 + HR_TRM1 = (1 << 5), 129 + HR_TRM_EOIOE_TRIG = 0, 130 + HR_TRM_CIC_TRIG = HR_TRM0, 131 + HR_TRM_CIC_EOIOE = HR_TRM1, 132 + HR_TRM_CIC_PE = HR_TRM0 | HR_TRM1, 133 + HR_LON = (1 << 6), 134 + HR_TON = (1 << 7), 135 + }; 136 + 137 + // ADR, bits used in address0, address1 and address0/1 registers 138 + enum adr_bits { 139 + ADDRESS_MASK = 0x1f, /* mask to specify lower 5 bits */ 140 + HR_DL = (1 << 5), 141 + HR_DT = (1 << 6), 142 + HR_ARS = (1 << 7), 143 + }; 144 + 145 + // ADR1, address1 register 146 + enum adr1_bits { 147 + HR_EOI = (1 << 7), 148 + }; 149 + 150 + // AUXMR, auxiliary mode register 151 + enum auxmr_bits { 152 + ICR = 0x20, 153 + PPR = 0x60, 154 + AUXRA = 0x80, 155 + AUXRB = 0xa0, 156 + AUXRE = 0xc0, 157 + }; 158 + 159 + // auxra, auxiliary register A 160 + enum auxra_bits { 161 + HR_HANDSHAKE_MASK = 0x3, 162 + HR_HLDA = 0x1, 163 + HR_HLDE = 0x2, 164 + HR_LCM = 0x3, /* auxra listen continuous */ 165 + HR_REOS = 0x4, 166 + HR_XEOS = 0x8, 167 + HR_BIN = 0x10, 168 + }; 169 + 170 + // auxrb, auxiliary register B 171 + enum auxrb_bits { 172 + HR_CPTE = (1 << 0), 173 + HR_SPEOI = (1 << 1), 174 + HR_TRI = (1 << 2), 175 + HR_INV = (1 << 3), 176 + HR_ISS = (1 << 4), 177 + }; 178 + 179 + enum auxre_bits { 180 + HR_DAC_HLD_DCAS = 0x1, /* perform DAC holdoff on receiving clear */ 181 + HR_DAC_HLD_DTAS = 0x2, /* perform DAC holdoff on receiving trigger */ 182 + }; 183 + 184 + // parallel poll register 185 + enum ppr_bits { 186 + HR_PPS = (1 << 3), 187 + HR_PPU = (1 << 4), 188 + }; 189 + 190 + /* 7210 Auxiliary Commands */ 191 + enum aux_cmds { 192 + AUX_PON = 0x0, /* Immediate Execute pon */ 193 + AUX_CPPF = 0x1, /* Clear Parallel Poll Flag */ 194 + AUX_CR = 0x2, /* Chip Reset */ 195 + AUX_FH = 0x3, /* Finish Handshake */ 196 + AUX_TRIG = 0x4, /* Trigger */ 197 + AUX_RTL = 0x5, /* Return to local */ 198 + AUX_SEOI = 0x6, /* Send EOI */ 199 + AUX_NVAL = 0x7, /* Non-Valid Secondary Command or Address */ 200 + AUX_SPPF = 0x9, /* Set Parallel Poll Flag */ 201 + AUX_VAL = 0xf, /* Valid Secondary Command or Address */ 202 + AUX_GTS = 0x10, /* Go To Standby */ 203 + AUX_TCA = 0x11, /* Take Control Asynchronously */ 204 + AUX_TCS = 0x12, /* Take Control Synchronously */ 205 + AUX_LTN = 0x13, /* Listen */ 206 + AUX_DSC = 0x14, /* Disable System Control */ 207 + AUX_CIFC = 0x16, /* Clear IFC */ 208 + AUX_CREN = 0x17, /* Clear REN */ 209 + AUX_TCSE = 0x1a, /* Take Control Synchronously on End */ 210 + AUX_LTNC = 0x1b, /* Listen in Continuous Mode */ 211 + AUX_LUN = 0x1c, /* Local Unlisten */ 212 + AUX_EPP = 0x1d, /* Execute Parallel Poll */ 213 + AUX_SIFC = 0x1e, /* Set IFC */ 214 + AUX_SREN = 0x1f, /* Set REN */ 215 + }; 216 + 217 + #endif //_NEC7210_REGISTERS_H
+72
drivers/staging/gpib/include/plx9050.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * Header for plx9050 pci chip 5 + * copyright : (C) 2002 by Frank Mori Hess 6 + ***************************************************************************/ 7 + 8 + #ifndef _PLX9050_GPIB_H 9 + #define _PLX9050_GPIB_H 10 + 11 + // plx pci chip registers and bits 12 + enum { 13 + PLX9050_INTCSR_REG = 0x4c, 14 + PLX9050_CNTRL_REG = 0x50 15 + }; 16 + 17 + enum plx9050_intcsr_bits { 18 + PLX9050_LINTR1_EN_BIT = 0x1, 19 + PLX9050_LINTR1_POLARITY_BIT = 0x2, 20 + PLX9050_LINTR1_STATUS_BIT = 0x4, 21 + PLX9050_LINTR2_EN_BIT = 0x8, 22 + PLX9050_LINTR2_POLARITY_BIT = 0x10, 23 + PLX9050_LINTR2_STATUS_BIT = 0x20, 24 + PLX9050_PCI_INTR_EN_BIT = 0x40, 25 + PLX9050_SOFT_INTR_BIT = 0x80, 26 + PLX9050_LINTR1_SELECT_ENABLE_BIT = 0x100, //9052 extension 27 + PLX9050_LINTR2_SELECT_ENABLE_BIT = 0x200, //9052 extension 28 + PLX9050_LINTR1_EDGE_CLEAR_BIT = 0x400, //9052 extension 29 + PLX9050_LINTR2_EDGE_CLEAR_BIT = 0x800, //9052 extension 30 + }; 31 + 32 + enum plx9050_cntrl_bits { 33 + PLX9050_WAITO_NOT_USER0_SELECT_BIT = 0x1, 34 + PLX9050_USER0_OUTPUT_BIT = 0x2, 35 + PLX9050_USER0_DATA_BIT = 0x4, 36 + PLX9050_LLOCK_NOT_USER1_SELECT_BIT = 0x8, 37 + PLX9050_USER1_OUTPUT_BIT = 0x10, 38 + PLX9050_USER1_DATA_BIT = 0x20, 39 + PLX9050_CS2_NOT_USER2_SELECT_BIT = 0x40, 40 + PLX9050_USER2_OUTPUT_BIT = 0x80, 41 + PLX9050_USER2_DATA_BIT = 0x100, 42 + PLX9050_CS3_NOT_USER3_SELECT_BIT = 0x200, 43 + PLX9050_USER3_OUTPUT_BIT = 0x400, 44 + PLX9050_USER3_DATA_BIT = 0x800, 45 + PLX9050_PCIBAR_ENABLE_MASK = 0x3000, 46 + PLX9050_PCIBAR_MEMORY_AND_IO_ENABLE_BITS = 0x0, 47 + PLX9050_PCIBAR_MEMORY_NO_IO_ENABLE_BITS = 0x1000, 48 + PLX9050_PCIBAR_IO_NO_MEMORY_ENABLE_BITS = 0x2000, 49 + PLX9050_PCIBAR_MEMORY_AND_IO_TOO_ENABLE_BITS = 0x3000, 50 + PLX9050_PCI_READ_MODE_BIT = 0x4000, 51 + PLX9050_PCI_READ_WITH_WRITE_FLUSH_MODE_BIT = 0x8000, 52 + PLX9050_PCI_READ_NO_FLUSH_MODE_BIT = 0x10000, 53 + PLX9050_PCI_READ_NO_WRITE_MODE_BIT = 0x20000, 54 + PLX9050_PCI_WRITE_MODE_BIT = 0x40000, 55 + PLX9050_PCI_RETRY_DELAY_MASK = 0x780000, 56 + PLX9050_DIRECT_SLAVE_LOCK_ENABLE_BIT = 0x800000, 57 + PLX9050_EEPROM_CLOCK_BIT = 0x1000000, 58 + PLX9050_EEPROM_CHIP_SELECT_BIT = 0x2000000, 59 + PLX9050_WRITE_TO_EEPROM_BIT = 0x4000000, 60 + PLX9050_READ_EEPROM_DATA_BIT = 0x8000000, 61 + PLX9050_EEPROM_VALID_BIT = 0x10000000, 62 + PLX9050_RELOAD_CONFIG_REGISTERS_BIT = 0x20000000, 63 + PLX9050_PCI_SOFTWARE_RESET_BIT = 0x40000000, 64 + PLX9050_MASK_REVISION_BIT = 0x80000000 65 + }; 66 + 67 + static inline unsigned int PLX9050_PCI_RETRY_DELAY_BITS(unsigned int clocks) 68 + { 69 + return ((clocks / 8) << 19) & PLX9050_PCI_RETRY_DELAY_MASK; 70 + } 71 + 72 + #endif // _PLX9050_GPIB_H
+22
drivers/staging/gpib/include/quancom_pci.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * Quancom pci stuff 5 + * copyright (C) 2005 by Frank Mori Hess 6 + ***************************************************************************/ 7 + 8 + #ifndef _QUANCOM_PCI_H 9 + #define _QUANCOM_PCI_H 10 + 11 + /* quancom registers */ 12 + enum quancom_regs { 13 + QUANCOM_IRQ_CONTROL_STATUS_REG = 0xfc, 14 + }; 15 + 16 + enum quancom_irq_control_status_bits { 17 + QUANCOM_IRQ_ASSERTED_BIT = 0x1, /* readable */ 18 + /* (any write to the register clears the interrupt)*/ 19 + QUANCOM_IRQ_ENABLE_BIT = 0x4, /* writeable */ 20 + }; 21 + 22 + #endif // _QUANCOM_PCI_H
+272
drivers/staging/gpib/include/tms9914.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2002 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _TMS9914_H 8 + #define _TMS9914_H 9 + 10 + #include <linux/types.h> 11 + #include <linux/interrupt.h> 12 + #include "gpib_state_machines.h" 13 + #include "gpib_types.h" 14 + 15 + enum tms9914_holdoff_mode { 16 + TMS9914_HOLDOFF_NONE, 17 + TMS9914_HOLDOFF_EOI, 18 + TMS9914_HOLDOFF_ALL, 19 + }; 20 + 21 + /* struct used to provide variables local to a tms9914 chip */ 22 + struct tms9914_priv { 23 + void *iobase; 24 + unsigned int offset; // offset between successive tms9914 io addresses 25 + unsigned int dma_channel; 26 + // software copy of bits written to interrupt mask registers 27 + u8 imr0_bits, imr1_bits; 28 + // bits written to address mode register 29 + u8 admr_bits; 30 + u8 auxa_bits; // bits written to auxiliary register A 31 + // used to keep track of board's state, bit definitions given below 32 + unsigned long state; 33 + u8 eos; // eos character 34 + short eos_flags; 35 + u8 spoll_status; 36 + enum tms9914_holdoff_mode holdoff_mode; 37 + unsigned int ppoll_line; 38 + enum talker_function_state talker_state; 39 + enum listener_function_state listener_state; 40 + unsigned ppoll_sense : 1; 41 + unsigned ppoll_enable : 1; 42 + unsigned ppoll_configure_state : 1; 43 + unsigned primary_listen_addressed : 1; 44 + unsigned primary_talk_addressed : 1; 45 + unsigned holdoff_on_end : 1; 46 + unsigned holdoff_on_all : 1; 47 + unsigned holdoff_active : 1; 48 + // wrappers for outb, inb, readb, or writeb 49 + u8 (*read_byte)(struct tms9914_priv *priv, unsigned int register_number); 50 + void (*write_byte)(struct tms9914_priv *priv, u8 byte, unsigned int 51 + register_number); 52 + }; 53 + 54 + // slightly shorter way to access read_byte and write_byte 55 + static inline u8 read_byte(struct tms9914_priv *priv, unsigned int register_number) 56 + { 57 + return priv->read_byte(priv, register_number); 58 + } 59 + 60 + static inline void write_byte(struct tms9914_priv *priv, u8 byte, unsigned int register_number) 61 + { 62 + priv->write_byte(priv, byte, register_number); 63 + } 64 + 65 + // struct tms9914_priv.state bit numbers 66 + enum { 67 + PIO_IN_PROGRESS_BN, // pio transfer in progress 68 + DMA_READ_IN_PROGRESS_BN, // dma read transfer in progress 69 + DMA_WRITE_IN_PROGRESS_BN, // dma write transfer in progress 70 + READ_READY_BN, // board has data byte available to read 71 + WRITE_READY_BN, // board is ready to send a data byte 72 + COMMAND_READY_BN, // board is ready to send a command byte 73 + RECEIVED_END_BN, // received END 74 + BUS_ERROR_BN, // bus error 75 + DEV_CLEAR_BN, // device clear received 76 + }; 77 + 78 + // interface functions 79 + int tms9914_read(gpib_board_t *board, struct tms9914_priv *priv, uint8_t *buffer, 80 + size_t length, int *end, size_t *bytes_read); 81 + int tms9914_write(gpib_board_t *board, struct tms9914_priv *priv, uint8_t *buffer, 82 + size_t length, int send_eoi, size_t *bytes_written); 83 + int tms9914_command(gpib_board_t *board, struct tms9914_priv *priv, uint8_t *buffer, 84 + size_t length, size_t *bytes_written); 85 + int tms9914_take_control(gpib_board_t *board, struct tms9914_priv *priv, int syncronous); 86 + /* alternate version of tms9914_take_control which works around buggy tcs 87 + * implementation. 88 + */ 89 + int tms9914_take_control_workaround(gpib_board_t *board, struct tms9914_priv *priv, 90 + int syncronous); 91 + int tms9914_go_to_standby(gpib_board_t *board, struct tms9914_priv *priv); 92 + void tms9914_request_system_control(gpib_board_t *board, struct tms9914_priv *priv, 93 + int request_control); 94 + void tms9914_interface_clear(gpib_board_t *board, struct tms9914_priv *priv, int assert); 95 + void tms9914_remote_enable(gpib_board_t *board, struct tms9914_priv *priv, int enable); 96 + int tms9914_enable_eos(gpib_board_t *board, struct tms9914_priv *priv, uint8_t eos_bytes, 97 + int compare_8_bits); 98 + void tms9914_disable_eos(gpib_board_t *board, struct tms9914_priv *priv); 99 + unsigned int tms9914_update_status(gpib_board_t *board, struct tms9914_priv *priv, 100 + unsigned int clear_mask); 101 + int tms9914_primary_address(gpib_board_t *board, 102 + struct tms9914_priv *priv, unsigned int address); 103 + int tms9914_secondary_address(gpib_board_t *board, struct tms9914_priv *priv, 104 + unsigned int address, int enable); 105 + int tms9914_parallel_poll(gpib_board_t *board, struct tms9914_priv *priv, uint8_t *result); 106 + void tms9914_parallel_poll_configure(gpib_board_t *board, 107 + struct tms9914_priv *priv, uint8_t config); 108 + void tms9914_parallel_poll_response(gpib_board_t *board, 109 + struct tms9914_priv *priv, int ist); 110 + void tms9914_serial_poll_response(gpib_board_t *board, struct tms9914_priv *priv, uint8_t status); 111 + uint8_t tms9914_serial_poll_status(gpib_board_t *board, struct tms9914_priv *priv); 112 + int tms9914_line_status(const gpib_board_t *board, struct tms9914_priv *priv); 113 + unsigned int tms9914_t1_delay(gpib_board_t *board, struct tms9914_priv *priv, 114 + unsigned int nano_sec); 115 + void tms9914_return_to_local(const gpib_board_t *board, struct tms9914_priv *priv); 116 + 117 + // utility functions 118 + void tms9914_board_reset(struct tms9914_priv *priv); 119 + void tms9914_online(gpib_board_t *board, struct tms9914_priv *priv); 120 + void tms9914_release_holdoff(struct tms9914_priv *priv); 121 + void tms9914_set_holdoff_mode(struct tms9914_priv *priv, enum tms9914_holdoff_mode mode); 122 + 123 + // wrappers for io functions 124 + uint8_t tms9914_ioport_read_byte(struct tms9914_priv *priv, unsigned int register_num); 125 + void tms9914_ioport_write_byte(struct tms9914_priv *priv, uint8_t data, unsigned int register_num); 126 + uint8_t tms9914_iomem_read_byte(struct tms9914_priv *priv, unsigned int register_num); 127 + void tms9914_iomem_write_byte(struct tms9914_priv *priv, uint8_t data, unsigned int register_num); 128 + 129 + // interrupt service routine 130 + irqreturn_t tms9914_interrupt(gpib_board_t *board, struct tms9914_priv *priv); 131 + irqreturn_t tms9914_interrupt_have_status(gpib_board_t *board, struct tms9914_priv *priv, 132 + int status1, int status2); 133 + 134 + // tms9914 has 8 registers 135 + static const int tms9914_num_registers = 8; 136 + 137 + /* tms9914 register numbers (might need to be multiplied by 138 + * a board-dependent offset to get actually io address offset) 139 + */ 140 + // write registers 141 + enum { 142 + IMR0 = 0, /* interrupt mask 0 */ 143 + IMR1 = 1, /* interrupt mask 1 */ 144 + AUXCR = 3, /* auxiliary command */ 145 + ADR = 4, // address register 146 + SPMR = 5, // serial poll mode register 147 + PPR = 6, /* parallel poll */ 148 + CDOR = 7, /* data out register */ 149 + }; 150 + 151 + // read registers 152 + enum { 153 + ISR0 = 0, /* interrupt status 0 */ 154 + ISR1 = 1, /* interrupt status 1 */ 155 + ADSR = 2, /* address status */ 156 + BSR = 3, /* bus status */ 157 + CPTR = 6, /* command pass thru */ 158 + DIR = 7, /* data in register */ 159 + }; 160 + 161 + //bit definitions common to tms9914 compatible registers 162 + 163 + /* ISR0 - Register bits */ 164 + enum isr0_bits { 165 + HR_MAC = (1 << 0), /* My Address Change */ 166 + HR_RLC = (1 << 1), /* Remote/Local change */ 167 + HR_SPAS = (1 << 2), /* Serial Poll active State */ 168 + HR_END = (1 << 3), /* END (EOI or EOS) */ 169 + HR_BO = (1 << 4), /* Byte Out */ 170 + HR_BI = (1 << 5), /* Byte In */ 171 + }; 172 + 173 + /* IMR0 - Register bits */ 174 + enum imr0_bits { 175 + HR_MACIE = (1 << 0), /* */ 176 + HR_RLCIE = (1 << 1), /* */ 177 + HR_SPASIE = (1 << 2), /* */ 178 + HR_ENDIE = (1 << 3), /* */ 179 + HR_BOIE = (1 << 4), /* */ 180 + HR_BIIE = (1 << 5), /* */ 181 + }; 182 + 183 + /* ISR1 - Register bits */ 184 + enum isr1_bits { 185 + HR_IFC = (1 << 0), /* IFC asserted */ 186 + HR_SRQ = (1 << 1), /* SRQ asserted */ 187 + HR_MA = (1 << 2), /* My Address */ 188 + HR_DCAS = (1 << 3), /* Device Clear active State */ 189 + HR_APT = (1 << 4), /* Address pass Through */ 190 + HR_UNC = (1 << 5), /* Unrecognized Command */ 191 + HR_ERR = (1 << 6), /* Data Transmission Error */ 192 + HR_GET = (1 << 7), /* Group execute Trigger */ 193 + }; 194 + 195 + /* IMR1 - Register bits */ 196 + enum imr1_bits { 197 + HR_IFCIE = (1 << 0), /* */ 198 + HR_SRQIE = (1 << 1), /* */ 199 + HR_MAIE = (1 << 2), /* */ 200 + HR_DCASIE = (1 << 3), /* */ 201 + HR_APTIE = (1 << 4), /* */ 202 + HR_UNCIE = (1 << 5), /* */ 203 + HR_ERRIE = (1 << 6), /* */ 204 + HR_GETIE = (1 << 7), /* */ 205 + }; 206 + 207 + /* ADSR - Register bits */ 208 + enum adsr_bits { 209 + HR_ULPA = (1 << 0), /* Store last address LSB */ 210 + HR_TA = (1 << 1), /* Talker Adressed */ 211 + HR_LA = (1 << 2), /* Listener adressed */ 212 + HR_TPAS = (1 << 3), /* talker primary address state */ 213 + HR_LPAS = (1 << 4), /* listener " */ 214 + HR_ATN = (1 << 5), /* ATN active */ 215 + HR_LLO = (1 << 6), /* LLO active */ 216 + HR_REM = (1 << 7), /* REM active */ 217 + }; 218 + 219 + /* ADR - Register bits */ 220 + enum adr_bits { 221 + ADDRESS_MASK = 0x1f, /* mask to specify lower 5 bits for ADR */ 222 + HR_DAT = (1 << 5), /* disable talker */ 223 + HR_DAL = (1 << 6), /* disable listener */ 224 + HR_EDPA = (1 << 7), /* enable dual primary addressing */ 225 + }; 226 + 227 + enum bus_status_bits { 228 + BSR_REN_BIT = 0x1, 229 + BSR_IFC_BIT = 0x2, 230 + BSR_SRQ_BIT = 0x4, 231 + BSR_EOI_BIT = 0x8, 232 + BSR_NRFD_BIT = 0x10, 233 + BSR_NDAC_BIT = 0x20, 234 + BSR_DAV_BIT = 0x40, 235 + BSR_ATN_BIT = 0x80, 236 + }; 237 + 238 + /*---------------------------------------------------------*/ 239 + /* TMS 9914 Auxiliary Commands */ 240 + /*---------------------------------------------------------*/ 241 + 242 + enum aux_cmd_bits { 243 + AUX_CS = 0x80, /* set bit instead of clearing it, used with commands marked 'd' below */ 244 + AUX_CHIP_RESET = 0x0, /* d Chip reset */ 245 + AUX_INVAL = 0x1, // release dac holdoff, invalid command byte 246 + AUX_VAL = (AUX_INVAL | AUX_CS), // release dac holdoff, valid command byte 247 + AUX_RHDF = 0x2, /* X Release RFD holdoff */ 248 + AUX_HLDA = 0x3, /* d holdoff on all data */ 249 + AUX_HLDE = 0x4, /* d holdoff on EOI only */ 250 + AUX_NBAF = 0x5, /* X Set new byte available false */ 251 + AUX_FGET = 0x6, /* d force GET */ 252 + AUX_RTL = 0x7, /* d return to local */ 253 + AUX_SEOI = 0x8, /* X send EOI with next byte */ 254 + AUX_LON = 0x9, /* d Listen only */ 255 + AUX_TON = 0xa, /* d Talk only */ 256 + AUX_GTS = 0xb, /* X goto standby */ 257 + AUX_TCA = 0xc, /* X take control asynchronously */ 258 + AUX_TCS = 0xd, /* X take " synchronously */ 259 + AUX_RPP = 0xe, /* d Request parallel poll */ 260 + AUX_SIC = 0xf, /* d send interface clear */ 261 + AUX_SRE = 0x10, /* d send remote enable */ 262 + AUX_RQC = 0x11, /* X request control */ 263 + AUX_RLC = 0x12, /* X release control */ 264 + AUX_DAI = 0x13, /* d disable all interrupts */ 265 + AUX_PTS = 0x14, /* X pass through next secondary */ 266 + AUX_STDL = 0x15, /* d short T1 delay */ 267 + AUX_SHDW = 0x16, /* d shadow handshake */ 268 + AUX_VSTDL = 0x17, /* d very short T1 delay (smj9914 extension) */ 269 + AUX_RSV2 = 0x18, /* d request service bit 2 (smj9914 extension) */ 270 + }; 271 + 272 + #endif //_TMS9914_H
+190
drivers/staging/gpib/include/tnt4882_registers.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /*************************************************************************** 4 + * copyright : (C) 2002, 2004 by Frank Mori Hess 5 + ***************************************************************************/ 6 + 7 + #ifndef _TNT4882_REGISTERS_H 8 + #define _TNT4882_REGISTERS_H 9 + 10 + // tnt4882 register offsets 11 + enum { 12 + ACCWR = 0x5, 13 + // offset of auxiliary command register in 9914 mode 14 + AUXCR = 0x6, 15 + INTRT = 0x7, 16 + // register number for auxiliary command register when swap bit is set (9914 mode) 17 + SWAPPED_AUXCR = 0xa, 18 + HSSEL = 0xd, // handshake select register 19 + CNT2 = 0x9, 20 + CNT3 = 0xb, 21 + CFG = 0x10, 22 + SASR = 0x1b, 23 + IMR0 = 0x1d, 24 + IMR3 = 0x12, 25 + CNT0 = 0x14, 26 + CNT1 = 0x16, 27 + KEYREG = 0x17, // key control register (7210 mode only) 28 + CSR = KEYREG, 29 + FIFOB = 0x18, 30 + FIFOA = 0x19, 31 + CCR = 0x1a, // carry cycle register 32 + CMDR = 0x1c, // command register 33 + TIMER = 0x1e, // timer register 34 + 35 + STS1 = 0x10, /* T488 Status Register 1 */ 36 + STS2 = 0x1c, /* T488 Status Register 2 */ 37 + ISR0 = IMR0, 38 + ISR3 = 0x1a, /* T488 Interrupt Status Register 3 */ 39 + BCR = 0x1f, /* bus control/status register */ 40 + BSR = BCR, 41 + }; 42 + 43 + static const int tnt_pagein_offset = 0x11; 44 + 45 + /*============================================================*/ 46 + 47 + /* TURBO-488 registers bit definitions */ 48 + 49 + enum bus_control_status_bits { 50 + BCSR_REN_BIT = 0x1, 51 + BCSR_IFC_BIT = 0x2, 52 + BCSR_SRQ_BIT = 0x4, 53 + BCSR_EOI_BIT = 0x8, 54 + BCSR_NRFD_BIT = 0x10, 55 + BCSR_NDAC_BIT = 0x20, 56 + BCSR_DAV_BIT = 0x40, 57 + BCSR_ATN_BIT = 0x80, 58 + }; 59 + 60 + /* CFG -- Configuration Register (write only) */ 61 + enum cfg_bits { 62 + TNT_COMMAND = 0x80, /* bytes are command bytes instead of data bytes 63 + * (tnt4882 one-chip and newer only?) 64 + */ 65 + TNT_TLCHE = (1 << 6), /* halt transfer on imr0, imr1, or imr2 interrupt */ 66 + TNT_IN = (1 << 5), /* transfer is GPIB read */ 67 + TNT_A_B = (1 << 4), /* order to use fifos 1=fifo A first(big endian), 68 + * 0=fifo b first(little endian) 69 + */ 70 + TNT_CCEN = (1 << 3), /* enable carry cycle */ 71 + TNT_TMOE = (1 << 2), /* enable CPU bus time limit */ 72 + TNT_TIM_BYTN = (1 << 1), /* tmot reg is: 1=125ns clocks, 0=num bytes */ 73 + TNT_B_16BIT = (1 << 0), /* 1=FIFO is 16-bit register, 0=8-bit */ 74 + }; 75 + 76 + /* CMDR -- Command Register */ 77 + enum cmdr_bits { 78 + CLRSC = 0x2, /* clear the system controller bit */ 79 + SETSC = 0x3, /* set the system controller bit */ 80 + GO = 0x4, /* start fifos */ 81 + STOP = 0x8, /* stop fifos */ 82 + RESET_FIFO = 0x10, /* reset the FIFOs */ 83 + SOFT_RESET = 0x22, /* issue a software reset */ 84 + HARD_RESET = 0x40 /* 500x only? */ 85 + }; 86 + 87 + /* HSSEL -- handshake select register (write only) */ 88 + enum hssel_bits { 89 + TNT_ONE_CHIP_BIT = 0x1, 90 + NODMA = 0x10, 91 + TNT_GO2SIDS_BIT = 0x20, 92 + }; 93 + 94 + /* IMR0 -- Interrupt Mode Register 0 */ 95 + enum imr0_bits { 96 + TNT_SYNCIE_BIT = 0x1, /* handshake sync */ 97 + TNT_TOIE_BIT = 0x2, /* timeout */ 98 + TNT_ATNIE_BIT = 0x4, /* ATN interrupt */ 99 + TNT_IFCIE_BIT = 0x8, /* interface clear interrupt */ 100 + TNT_BTO_BIT = 0x10, /* byte timeout */ 101 + TNT_NLEN_BIT = 0x20, /* treat new line as EOS char */ 102 + TNT_STBOIE_BIT = 0x40, /* status byte out */ 103 + TNT_IMR0_ALWAYS_BITS = 0x80, /* always set this bit on write */ 104 + }; 105 + 106 + /* ISR0 -- Interrupt Status Register 0 */ 107 + enum isr0_bits { 108 + TNT_SYNC_BIT = 0x1, /* handshake sync */ 109 + TNT_TO_BIT = 0x2, /* timeout */ 110 + TNT_ATNI_BIT = 0x4, /* ATN interrupt */ 111 + TNT_IFCI_BIT = 0x8, /* interface clear interrupt */ 112 + TNT_EOS_BIT = 0x10, /* end of string */ 113 + TNT_NL_BIT = 0x20, /* new line receive */ 114 + TNT_STBO_BIT = 0x40, /* status byte out */ 115 + TNT_NBA_BIT = 0x80, /* new byte available */ 116 + }; 117 + 118 + /* ISR3 -- Interrupt Status Register 3 (read only) */ 119 + enum isr3_bits { 120 + HR_DONE = (1 << 0), /* transfer done */ 121 + HR_TLCI = (1 << 1), /* isr0, isr1, or isr2 interrupt asserted */ 122 + HR_NEF = (1 << 2), /* NOT empty fifo */ 123 + HR_NFF = (1 << 3), /* NOT full fifo */ 124 + HR_STOP = (1 << 4), /* fifo empty or STOP command issued */ 125 + HR_SRQI_CIC = (1 << 5), /* SRQ asserted and we are CIC (500x only?)*/ 126 + HR_INTR = (1 << 7), /* isr3 interrupt active */ 127 + }; 128 + 129 + enum keyreg_bits { 130 + MSTD = 0x20, // enable 350ns T1 delay 131 + }; 132 + 133 + /* STS1 -- Status Register 1 (read only) */ 134 + enum sts1_bits { 135 + S_DONE = 0x80, /* DMA done */ 136 + S_SC = 0x40, /* is system controller */ 137 + S_IN = 0x20, /* DMA in (to memory) */ 138 + S_DRQ = 0x10, /* DRQ line (for diagnostics) */ 139 + S_STOP = 0x08, /* DMA stopped */ 140 + S_NDAV = 0x04, /* inverse of DAV */ 141 + S_HALT = 0x02, /* status of transfer machine */ 142 + S_GSYNC = 0x01, /* indicates if GPIB is in sync w I/O */ 143 + }; 144 + 145 + /* STS2 -- Status Register 2 */ 146 + enum sts2_bits { 147 + AFFN = (1 << 3), /* "A full FIFO NOT" (0=FIFO full) */ 148 + AEFN = (1 << 2), /* "A empty FIFO NOT" (0=FIFO empty) */ 149 + BFFN = (1 << 1), /* "B full FIFO NOT" (0=FIFO full) */ 150 + BEFN = (1 << 0), /* "B empty FIFO NOT" (0=FIFO empty) */ 151 + }; 152 + 153 + // Auxiliary commands 154 + enum tnt4882_aux_cmds { 155 + AUX_9914 = 0x15, // switch to 9914 mode 156 + AUX_REQT = 0x18, 157 + AUX_REQF = 0x19, 158 + AUX_PAGEIN = 0x50, /* page in alternate registers */ 159 + AUX_HLDI = 0x51, // rfd holdoff immediately 160 + AUX_CLEAR_END = 0x55, 161 + AUX_7210 = 0x99, // switch to 7210 mode 162 + }; 163 + 164 + enum tnt4882_aux_regs { 165 + AUXRG = 0x40, 166 + AUXRI = 0xe0, 167 + }; 168 + 169 + enum auxg_bits { 170 + /* no talking when no listeners bit (prevents bus errors when data written at wrong time) */ 171 + NTNL_BIT = 0x8, 172 + RPP2_BIT = 0x4, /* set/clear local rpp message */ 173 + CHES_BIT = 0x1, /*clear holdoff on end select bit*/ 174 + }; 175 + 176 + enum auxi_bits { 177 + SISB = 0x1, // static interrupt bits (don't clear isr1, isr2 on read) 178 + PP2 = 0x4, // ignore remote parallel poll configuration 179 + USTD = 0x8, // ultra short (1100 nanosec) T1 delay 180 + }; 181 + 182 + enum sasr_bits { 183 + ACRDY_BIT = 0x4, /* acceptor ready state */ 184 + ADHS_BIT = 0x8, /* acceptor data holdoff state */ 185 + ANHS2_BIT = 0x10, /* acceptor not ready holdoff immediately state */ 186 + ANHS1_BIT = 0x20, /* acceptor not ready holdoff state */ 187 + AEHS_BIT = 0x40, /* acceptor end holdoff state */ 188 + }; 189 + 190 + #endif // _TNT4882_REGISTERS_H