Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/drivers/gpib/include/nec7210.h
38184 views
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
#ifdef CONFIG_HAS_IOPORT
22
u32 iobase;
23
#endif
24
void __iomem *mmiobase;
25
unsigned int offset; // offset between successive nec7210 io addresses
26
unsigned int dma_channel;
27
u8 *dma_buffer;
28
unsigned int dma_buffer_length; // length of dma buffer
29
dma_addr_t dma_buffer_addr; // bus address of board->buffer for use with dma
30
// software copy of bits written to registers
31
u8 reg_bits[8];
32
u8 auxa_bits; // bits written to auxiliary register A
33
u8 auxb_bits; // bits written to auxiliary register B
34
// used to keep track of board's state, bit definitions given below
35
unsigned long state;
36
// lock for chips that extend the nec7210 registers by paging in alternate regs
37
spinlock_t register_page_lock;
38
// wrappers for outb, inb, readb, or writeb
39
u8 (*read_byte)(struct nec7210_priv *priv, unsigned int register_number);
40
void (*write_byte)(struct nec7210_priv *priv, u8 byte, unsigned int register_number);
41
enum nec7210_chipset type;
42
enum talker_function_state talker_state;
43
enum listener_function_state listener_state;
44
void *private;
45
unsigned srq_pending : 1;
46
};
47
48
static inline void init_nec7210_private(struct nec7210_priv *priv)
49
{
50
memset(priv, 0, sizeof(struct nec7210_priv));
51
spin_lock_init(&priv->register_page_lock);
52
}
53
54
// slightly shorter way to access read_byte and write_byte
55
static inline u8 read_byte(struct nec7210_priv *priv, unsigned int register_number)
56
{
57
return priv->read_byte(priv, register_number);
58
}
59
60
static inline void write_byte(struct nec7210_priv *priv, u8 byte, unsigned int register_number)
61
{
62
priv->write_byte(priv, byte, register_number);
63
}
64
65
// struct nec7210_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, // output error has occurred
75
RFD_HOLDOFF_BN, // rfd holdoff in effect
76
DEV_CLEAR_BN, // device clear received
77
ADR_CHANGE_BN, // address state change occurred
78
};
79
80
// interface functions
81
int nec7210_read(struct gpib_board *board, struct nec7210_priv *priv, u8 *buffer,
82
size_t length, int *end, size_t *bytes_read);
83
int nec7210_write(struct gpib_board *board, struct nec7210_priv *priv, u8 *buffer,
84
size_t length, int send_eoi, size_t *bytes_written);
85
int nec7210_command(struct gpib_board *board, struct nec7210_priv *priv, u8 *buffer,
86
size_t length, size_t *bytes_written);
87
int nec7210_take_control(struct gpib_board *board, struct nec7210_priv *priv, int syncronous);
88
int nec7210_go_to_standby(struct gpib_board *board, struct nec7210_priv *priv);
89
int nec7210_request_system_control(struct gpib_board *board,
90
struct nec7210_priv *priv, int request_control);
91
void nec7210_interface_clear(struct gpib_board *board, struct nec7210_priv *priv, int assert);
92
void nec7210_remote_enable(struct gpib_board *board, struct nec7210_priv *priv, int enable);
93
int nec7210_enable_eos(struct gpib_board *board, struct nec7210_priv *priv, u8 eos_bytes,
94
int compare_8_bits);
95
void nec7210_disable_eos(struct gpib_board *board, struct nec7210_priv *priv);
96
unsigned int nec7210_update_status(struct gpib_board *board, struct nec7210_priv *priv,
97
unsigned int clear_mask);
98
unsigned int nec7210_update_status_nolock(struct gpib_board *board, struct nec7210_priv *priv);
99
int nec7210_primary_address(const struct gpib_board *board,
100
struct nec7210_priv *priv, unsigned int address);
101
int nec7210_secondary_address(const struct gpib_board *board, struct nec7210_priv *priv,
102
unsigned int address, int enable);
103
int nec7210_parallel_poll(struct gpib_board *board, struct nec7210_priv *priv, u8 *result);
104
void nec7210_serial_poll_response(struct gpib_board *board,
105
struct nec7210_priv *priv, u8 status);
106
void nec7210_parallel_poll_configure(struct gpib_board *board,
107
struct nec7210_priv *priv, unsigned int configuration);
108
void nec7210_parallel_poll_response(struct gpib_board *board,
109
struct nec7210_priv *priv, int ist);
110
u8 nec7210_serial_poll_status(struct gpib_board *board, struct nec7210_priv *priv);
111
int nec7210_t1_delay(struct gpib_board *board,
112
struct nec7210_priv *priv, unsigned int nano_sec);
113
void nec7210_return_to_local(const struct gpib_board *board, struct nec7210_priv *priv);
114
115
// utility functions
116
void nec7210_board_reset(struct nec7210_priv *priv, const struct gpib_board *board);
117
void nec7210_board_online(struct nec7210_priv *priv, const struct gpib_board *board);
118
unsigned int nec7210_set_reg_bits(struct nec7210_priv *priv, unsigned int reg,
119
unsigned int mask, unsigned int bits);
120
void nec7210_set_handshake_mode(struct gpib_board *board, struct nec7210_priv *priv, int mode);
121
void nec7210_release_rfd_holdoff(struct gpib_board *board, struct nec7210_priv *priv);
122
u8 nec7210_read_data_in(struct gpib_board *board, struct nec7210_priv *priv, int *end);
123
124
// wrappers for io functions
125
u8 nec7210_ioport_read_byte(struct nec7210_priv *priv, unsigned int register_num);
126
void nec7210_ioport_write_byte(struct nec7210_priv *priv, u8 data, unsigned int register_num);
127
u8 nec7210_iomem_read_byte(struct nec7210_priv *priv, unsigned int register_num);
128
void nec7210_iomem_write_byte(struct nec7210_priv *priv, u8 data, unsigned int register_num);
129
u8 nec7210_locking_ioport_read_byte(struct nec7210_priv *priv, unsigned int register_num);
130
void nec7210_locking_ioport_write_byte(struct nec7210_priv *priv, u8 data,
131
unsigned int register_num);
132
u8 nec7210_locking_iomem_read_byte(struct nec7210_priv *priv, unsigned int register_num);
133
void nec7210_locking_iomem_write_byte(struct nec7210_priv *priv, u8 data,
134
unsigned int register_num);
135
136
// interrupt service routine
137
irqreturn_t nec7210_interrupt(struct gpib_board *board, struct nec7210_priv *priv);
138
irqreturn_t nec7210_interrupt_have_status(struct gpib_board *board,
139
struct nec7210_priv *priv, int status1, int status2);
140
141
#endif //_NEC7210_H
142
143