1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /***************************************************************************
4 * copyright : (C) 2002, 2004 by Frank Mori Hess *
5 ***************************************************************************/
6
7 #include "gpibP.h"
8 #include "plx9050.h"
9 #include "tms9914.h"
10
11 enum pci_vendor_ids {
12 PCI_VENDOR_ID_AGILENT = 0x15bc,
13 };
14
15 enum pci_device_ids {
16 PCI_DEVICE_ID_82350B = 0x0b01,
17 PCI_DEVICE_ID_82351A = 0x1218
18 };
19
20 enum pci_subdevice_ids {
21 PCI_SUBDEVICE_ID_82350A = 0x10b0,
22 };
23
24 enum pci_regions_82350a {
25 PLX_MEM_REGION = 0,
26 PLX_IO_REGION = 1,
27 GPIB_82350A_REGION = 2,
28 SRAM_82350A_REGION = 3,
29 BORG_82350A_REGION = 4
30 };
31
32 enum pci_regions_82350b {
33 GPIB_REGION = 0,
34 SRAM_REGION = 1,
35 MISC_REGION = 2,
36 };
37
38 enum board_model {
39 MODEL_82350A,
40 MODEL_82350B,
41 MODEL_82351A
42 };
43
44 // struct which defines private_data for board
45 struct agilent_82350b_priv {
46 struct tms9914_priv tms9914_priv;
47 struct pci_dev *pci_device;
48 void __iomem *plx_base; //82350a only
49 void __iomem *gpib_base;
50 void __iomem *sram_base;
51 void __iomem *misc_base;
52 void __iomem *borg_base;
53 int irq;
54 unsigned short card_mode_bits;
55 unsigned short event_status_bits;
56 enum board_model model;
57 bool using_fifos;
58 };
59
60 // driver name
61 extern const char *driver_name;
62
63 // init functions
64
65 int agilent_82350b_unaccel_attach(gpib_board_t *board, const gpib_board_config_t *config);
66 int agilent_82350b_accel_attach(gpib_board_t *board, const gpib_board_config_t *config);
67
68 // interface functions
69 int agilent_82350b_accel_read(gpib_board_t *board, uint8_t *buffer, size_t length, int *end,
70 size_t *bytes_read);
71 int agilent_82350b_accel_write(gpib_board_t *board, uint8_t *buffer, size_t length, int send_eoi,
72 size_t *bytes_written);
73 int agilent_82350b_read(gpib_board_t *board, uint8_t *buffer, size_t length, int *end,
74 size_t *bytes_read);
75 int agilent_82350b_write(gpib_board_t *board, uint8_t *buffer, size_t length, int send_eoi,
76 size_t *bytes_written);
77 int agilent_82350b_command(gpib_board_t *board, uint8_t *buffer, size_t length,
78 size_t *bytes_written);
79 int agilent_82350b_take_control(gpib_board_t *board, int synchronous);
80 int agilent_82350b_go_to_standby(gpib_board_t *board);
81 void agilent_82350b_request_system_control(gpib_board_t *board, int request_control);
82 void agilent_82350b_interface_clear(gpib_board_t *board, int assert);
83 void agilent_82350b_remote_enable(gpib_board_t *board, int enable);
84 int agilent_82350b_enable_eos(gpib_board_t *board, uint8_t eos_byte, int
85 compare_8_bits);
86 void agilent_82350b_disable_eos(gpib_board_t *board);
87 unsigned int agilent_82350b_update_status(gpib_board_t *board, unsigned int clear_mask);
88 int agilent_82350b_primary_address(gpib_board_t *board, unsigned int address);
89 int agilent_82350b_secondary_address(gpib_board_t *board, unsigned int address, int
90 enable);
91 int agilent_82350b_parallel_poll(gpib_board_t *board, uint8_t *result);
92 void agilent_82350b_parallel_poll_configure(gpib_board_t *board, uint8_t config);
93 void agilent_82350b_parallel_poll_response(gpib_board_t *board, int ist);
94 void agilent_82350b_serial_poll_response(gpib_board_t *board, uint8_t status);
95 void agilent_82350b_return_to_local(gpib_board_t *board);
96 uint8_t agilent_82350b_serial_poll_status(gpib_board_t *board);
97 int agilent_82350b_line_status(const gpib_board_t *board);
98 unsigned int agilent_82350b_t1_delay(gpib_board_t *board, unsigned int nanosec);
99
100 // interrupt service routines
101 irqreturn_t agilent_82350b_interrupt(int irq, void *arg);
102
103 // utility functions
104 int agilent_82350b_allocate_private(gpib_board_t *board);
105 void agilent_82350b_free_private(gpib_board_t *board);
106 unsigned short read_and_clear_event_status(gpib_board_t *board);
107 int read_transfer_counter(struct agilent_82350b_priv *a_priv);
108 void set_transfer_counter(struct agilent_82350b_priv *a_priv, int count);
109
110 //registers
111 enum agilent_82350b_gpib_registers
112
113 {
114 CARD_MODE_REG = 0x1,
115 CONFIG_DATA_REG = 0x2, // 82350A specific
116 INTERRUPT_ENABLE_REG = 0x3,
117 EVENT_STATUS_REG = 0x4,
118 EVENT_ENABLE_REG = 0x5,
119 STREAM_STATUS_REG = 0x7,
120 DEBUG_RAM0_REG = 0x8,
121 DEBUG_RAM1_REG = 0x9,
122 DEBUG_RAM2_REG = 0xa,
123 DEBUG_RAM3_REG = 0xb,
124 XFER_COUNT_LO_REG = 0xc,
125 XFER_COUNT_MID_REG = 0xd,
126 XFER_COUNT_HI_REG = 0xe,
127 TMS9914_BASE_REG = 0x10,
128 INTERNAL_CONFIG_REG = 0x18,
129 IMR0_READ_REG = 0x19, //read
130 T1_DELAY_REG = 0x19, // write
131 IMR1_READ_REG = 0x1a,
132 ADR_READ_REG = 0x1b,
133 SPMR_READ_REG = 0x1c,
134 PPR_READ_REG = 0x1d,
135 CDOR_READ_REG = 0x1e,
136 SRAM_ACCESS_CONTROL_REG = 0x1f,
137 };
138
139 enum card_mode_bits
140
141 {
142 ACTIVE_CONTROLLER_BIT = 0x2, // read-only
143 CM_SYSTEM_CONTROLLER_BIT = 0x8,
144 ENABLE_BUS_MONITOR_BIT = 0x10,
145 ENABLE_PCI_IRQ_BIT = 0x20,
146 };
147
148 enum interrupt_enable_bits
149
150 {
151 ENABLE_TMS9914_INTERRUPTS_BIT = 0x1,
152 ENABLE_BUFFER_END_INTERRUPT_BIT = 0x10,
153 ENABLE_TERM_COUNT_INTERRUPT_BIT = 0x20,
154 };
155
156 enum event_enable_bits
157
158 {
159 ENABLE_BUFFER_END_EVENTS_BIT = 0x10,
160 ENABLE_TERM_COUNT_EVENTS_BIT = 0x20,
161 };
162
163 enum event_status_bits
164
165 {
166 TMS9914_IRQ_STATUS_BIT = 0x1,
167 IRQ_STATUS_BIT = 0x2,
168 BUFFER_END_STATUS_BIT = 0x10, // write-clear
169 TERM_COUNT_STATUS_BIT = 0x20, // write-clear
170 };
171
172 enum stream_status_bits
173
174 {
175 HALTED_STATUS_BIT = 0x1, //read
176 RESTART_STREAM_BIT = 0x1, //write
177 };
178
179 enum internal_config_bits
180
181 {
182 IC_SYSTEM_CONTROLLER_BIT = 0x80,
183 };
184
185 enum sram_access_control_bits
186
187 {
188 DIRECTION_GPIB_TO_HOST = 0x20, // transfer direction
189 ENABLE_TI_TO_SRAM = 0x40, // enable fifo
190 ENABLE_FAST_TALKER = 0x80 // added for 82350A (not used)
191 };
192
193 enum borg_bits
194
195 {
196 BORG_READY_BIT = 0x40,
197 BORG_DONE_BIT = 0x80
198 };
199
200 static const int agilent_82350b_fifo_size = 0x8000;
201
agilent_82350b_fifo_is_halted(struct agilent_82350b_priv * a_priv)202 static inline int agilent_82350b_fifo_is_halted(struct agilent_82350b_priv *a_priv)
203
204 {
205 return readb(a_priv->gpib_base + STREAM_STATUS_REG) & HALTED_STATUS_BIT;
206 }
207
208