| 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 |
#ifdef CONFIG_HAS_IOPORT |
| 24 |
u32 iobase; |
| 25 |
#endif |
| 26 |
void __iomem *mmiobase; |
| 27 |
unsigned int offset; // offset between successive tms9914 io addresses |
| 28 |
unsigned int dma_channel; |
| 29 |
// software copy of bits written to interrupt mask registers |
| 30 |
u8 imr0_bits, imr1_bits; |
| 31 |
// bits written to address mode register |
| 32 |
u8 admr_bits; |
| 33 |
u8 auxa_bits; // bits written to auxiliary register A |
| 34 |
// used to keep track of board's state, bit definitions given below |
| 35 |
unsigned long state; |
| 36 |
u8 eos; // eos character |
| 37 |
short eos_flags; |
| 38 |
u8 spoll_status; |
| 39 |
enum tms9914_holdoff_mode holdoff_mode; |
| 40 |
unsigned int ppoll_line; |
| 41 |
enum talker_function_state talker_state; |
| 42 |
enum listener_function_state listener_state; |
| 43 |
unsigned ppoll_sense : 1; |
| 44 |
unsigned ppoll_enable : 1; |
| 45 |
unsigned ppoll_configure_state : 1; |
| 46 |
unsigned primary_listen_addressed : 1; |
| 47 |
unsigned primary_talk_addressed : 1; |
| 48 |
unsigned holdoff_on_end : 1; |
| 49 |
unsigned holdoff_on_all : 1; |
| 50 |
unsigned holdoff_active : 1; |
| 51 |
// wrappers for outb, inb, readb, or writeb |
| 52 |
u8 (*read_byte)(struct tms9914_priv *priv, unsigned int register_number); |
| 53 |
void (*write_byte)(struct tms9914_priv *priv, u8 byte, unsigned int |
| 54 |
register_number); |
| 55 |
}; |
| 56 |
|
| 57 |
// slightly shorter way to access read_byte and write_byte |
| 58 |
static inline u8 read_byte(struct tms9914_priv *priv, unsigned int register_number) |
| 59 |
{ |
| 60 |
return priv->read_byte(priv, register_number); |
| 61 |
} |
| 62 |
|
| 63 |
static inline void write_byte(struct tms9914_priv *priv, u8 byte, unsigned int register_number) |
| 64 |
{ |
| 65 |
priv->write_byte(priv, byte, register_number); |
| 66 |
} |
| 67 |
|
| 68 |
// struct tms9914_priv.state bit numbers |
| 69 |
enum { |
| 70 |
PIO_IN_PROGRESS_BN, // pio transfer in progress |
| 71 |
DMA_READ_IN_PROGRESS_BN, // dma read transfer in progress |
| 72 |
DMA_WRITE_IN_PROGRESS_BN, // dma write transfer in progress |
| 73 |
READ_READY_BN, // board has data byte available to read |
| 74 |
WRITE_READY_BN, // board is ready to send a data byte |
| 75 |
COMMAND_READY_BN, // board is ready to send a command byte |
| 76 |
RECEIVED_END_BN, // received END |
| 77 |
BUS_ERROR_BN, // bus error |
| 78 |
DEV_CLEAR_BN, // device clear received |
| 79 |
}; |
| 80 |
|
| 81 |
// interface functions |
| 82 |
int tms9914_read(struct gpib_board *board, struct tms9914_priv *priv, u8 *buffer, |
| 83 |
size_t length, int *end, size_t *bytes_read); |
| 84 |
int tms9914_write(struct gpib_board *board, struct tms9914_priv *priv, u8 *buffer, |
| 85 |
size_t length, int send_eoi, size_t *bytes_written); |
| 86 |
int tms9914_command(struct gpib_board *board, struct tms9914_priv *priv, u8 *buffer, |
| 87 |
size_t length, size_t *bytes_written); |
| 88 |
int tms9914_take_control(struct gpib_board *board, struct tms9914_priv *priv, int syncronous); |
| 89 |
/* |
| 90 |
* alternate version of tms9914_take_control which works around buggy tcs |
| 91 |
* implementation. |
| 92 |
*/ |
| 93 |
int tms9914_take_control_workaround(struct gpib_board *board, struct tms9914_priv *priv, |
| 94 |
int syncronous); |
| 95 |
int tms9914_go_to_standby(struct gpib_board *board, struct tms9914_priv *priv); |
| 96 |
int tms9914_request_system_control(struct gpib_board *board, struct tms9914_priv *priv, |
| 97 |
int request_control); |
| 98 |
void tms9914_interface_clear(struct gpib_board *board, struct tms9914_priv *priv, int assert); |
| 99 |
void tms9914_remote_enable(struct gpib_board *board, struct tms9914_priv *priv, int enable); |
| 100 |
int tms9914_enable_eos(struct gpib_board *board, struct tms9914_priv *priv, u8 eos_bytes, |
| 101 |
int compare_8_bits); |
| 102 |
void tms9914_disable_eos(struct gpib_board *board, struct tms9914_priv *priv); |
| 103 |
unsigned int tms9914_update_status(struct gpib_board *board, struct tms9914_priv *priv, |
| 104 |
unsigned int clear_mask); |
| 105 |
int tms9914_primary_address(struct gpib_board *board, |
| 106 |
struct tms9914_priv *priv, unsigned int address); |
| 107 |
int tms9914_secondary_address(struct gpib_board *board, struct tms9914_priv *priv, |
| 108 |
unsigned int address, int enable); |
| 109 |
int tms9914_parallel_poll(struct gpib_board *board, struct tms9914_priv *priv, u8 *result); |
| 110 |
void tms9914_parallel_poll_configure(struct gpib_board *board, |
| 111 |
struct tms9914_priv *priv, u8 config); |
| 112 |
void tms9914_parallel_poll_response(struct gpib_board *board, |
| 113 |
struct tms9914_priv *priv, int ist); |
| 114 |
void tms9914_serial_poll_response(struct gpib_board *board, |
| 115 |
struct tms9914_priv *priv, u8 status); |
| 116 |
u8 tms9914_serial_poll_status(struct gpib_board *board, struct tms9914_priv *priv); |
| 117 |
int tms9914_line_status(const struct gpib_board *board, struct tms9914_priv *priv); |
| 118 |
unsigned int tms9914_t1_delay(struct gpib_board *board, struct tms9914_priv *priv, |
| 119 |
unsigned int nano_sec); |
| 120 |
void tms9914_return_to_local(const struct gpib_board *board, struct tms9914_priv *priv); |
| 121 |
|
| 122 |
// utility functions |
| 123 |
void tms9914_board_reset(struct tms9914_priv *priv); |
| 124 |
void tms9914_online(struct gpib_board *board, struct tms9914_priv *priv); |
| 125 |
void tms9914_release_holdoff(struct tms9914_priv *priv); |
| 126 |
void tms9914_set_holdoff_mode(struct tms9914_priv *priv, enum tms9914_holdoff_mode mode); |
| 127 |
|
| 128 |
// wrappers for io functions |
| 129 |
u8 tms9914_ioport_read_byte(struct tms9914_priv *priv, unsigned int register_num); |
| 130 |
void tms9914_ioport_write_byte(struct tms9914_priv *priv, u8 data, unsigned int register_num); |
| 131 |
u8 tms9914_iomem_read_byte(struct tms9914_priv *priv, unsigned int register_num); |
| 132 |
void tms9914_iomem_write_byte(struct tms9914_priv *priv, u8 data, unsigned int register_num); |
| 133 |
|
| 134 |
// interrupt service routine |
| 135 |
irqreturn_t tms9914_interrupt(struct gpib_board *board, struct tms9914_priv *priv); |
| 136 |
irqreturn_t tms9914_interrupt_have_status(struct gpib_board *board, struct tms9914_priv *priv, |
| 137 |
int status1, int status2); |
| 138 |
|
| 139 |
// tms9914 has 8 registers |
| 140 |
enum { |
| 141 |
ms9914_num_registers = 8, |
| 142 |
}; |
| 143 |
|
| 144 |
/* |
| 145 |
* tms9914 register numbers (might need to be multiplied by |
| 146 |
* a board-dependent offset to get actually io address offset) |
| 147 |
*/ |
| 148 |
// write registers |
| 149 |
enum { |
| 150 |
IMR0 = 0, /* interrupt mask 0 */ |
| 151 |
IMR1 = 1, /* interrupt mask 1 */ |
| 152 |
AUXCR = 3, /* auxiliary command */ |
| 153 |
ADR = 4, /* address register */ |
| 154 |
SPMR = 5, /* serial poll mode register */ |
| 155 |
PPR = 6, /* parallel poll */ |
| 156 |
CDOR = 7, /* data out register */ |
| 157 |
}; |
| 158 |
|
| 159 |
// read registers |
| 160 |
enum { |
| 161 |
ISR0 = 0, /* interrupt status 0 */ |
| 162 |
ISR1 = 1, /* interrupt status 1 */ |
| 163 |
ADSR = 2, /* address status */ |
| 164 |
BSR = 3, /* bus status */ |
| 165 |
CPTR = 6, /* command pass thru */ |
| 166 |
DIR = 7, /* data in register */ |
| 167 |
}; |
| 168 |
|
| 169 |
// bit definitions common to tms9914 compatible registers |
| 170 |
|
| 171 |
/* ISR0 - Register bits */ |
| 172 |
enum isr0_bits { |
| 173 |
HR_MAC = (1 << 0), /* My Address Change */ |
| 174 |
HR_RLC = (1 << 1), /* Remote/Local change */ |
| 175 |
HR_SPAS = (1 << 2), /* Serial Poll active State */ |
| 176 |
HR_END = (1 << 3), /* END (EOI or EOS) */ |
| 177 |
HR_BO = (1 << 4), /* Byte Out */ |
| 178 |
HR_BI = (1 << 5), /* Byte In */ |
| 179 |
}; |
| 180 |
|
| 181 |
/* IMR0 - Register bits */ |
| 182 |
enum imr0_bits { |
| 183 |
HR_MACIE = (1 << 0), /* */ |
| 184 |
HR_RLCIE = (1 << 1), /* */ |
| 185 |
HR_SPASIE = (1 << 2), /* */ |
| 186 |
HR_ENDIE = (1 << 3), /* */ |
| 187 |
HR_BOIE = (1 << 4), /* */ |
| 188 |
HR_BIIE = (1 << 5), /* */ |
| 189 |
}; |
| 190 |
|
| 191 |
/* ISR1 - Register bits */ |
| 192 |
enum isr1_bits { |
| 193 |
HR_IFC = (1 << 0), /* IFC asserted */ |
| 194 |
HR_SRQ = (1 << 1), /* SRQ asserted */ |
| 195 |
HR_MA = (1 << 2), /* My Address */ |
| 196 |
HR_DCAS = (1 << 3), /* Device Clear active State */ |
| 197 |
HR_APT = (1 << 4), /* Address pass Through */ |
| 198 |
HR_UNC = (1 << 5), /* Unrecognized Command */ |
| 199 |
HR_ERR = (1 << 6), /* Data Transmission Error */ |
| 200 |
HR_GET = (1 << 7), /* Group execute Trigger */ |
| 201 |
}; |
| 202 |
|
| 203 |
/* IMR1 - Register bits */ |
| 204 |
enum imr1_bits { |
| 205 |
HR_IFCIE = (1 << 0), /* */ |
| 206 |
HR_SRQIE = (1 << 1), /* */ |
| 207 |
HR_MAIE = (1 << 2), /* */ |
| 208 |
HR_DCASIE = (1 << 3), /* */ |
| 209 |
HR_APTIE = (1 << 4), /* */ |
| 210 |
HR_UNCIE = (1 << 5), /* */ |
| 211 |
HR_ERRIE = (1 << 6), /* */ |
| 212 |
HR_GETIE = (1 << 7), /* */ |
| 213 |
}; |
| 214 |
|
| 215 |
/* ADSR - Register bits */ |
| 216 |
enum adsr_bits { |
| 217 |
HR_ULPA = (1 << 0), /* Store last address LSB */ |
| 218 |
HR_TA = (1 << 1), /* Talker Adressed */ |
| 219 |
HR_LA = (1 << 2), /* Listener adressed */ |
| 220 |
HR_TPAS = (1 << 3), /* talker primary address state */ |
| 221 |
HR_LPAS = (1 << 4), /* listener " */ |
| 222 |
HR_ATN = (1 << 5), /* ATN active */ |
| 223 |
HR_LLO = (1 << 6), /* LLO active */ |
| 224 |
HR_REM = (1 << 7), /* REM active */ |
| 225 |
}; |
| 226 |
|
| 227 |
/* ADR - Register bits */ |
| 228 |
enum adr_bits { |
| 229 |
ADDRESS_MASK = 0x1f, /* mask to specify lower 5 bits for ADR */ |
| 230 |
HR_DAT = (1 << 5), /* disable talker */ |
| 231 |
HR_DAL = (1 << 6), /* disable listener */ |
| 232 |
HR_EDPA = (1 << 7), /* enable dual primary addressing */ |
| 233 |
}; |
| 234 |
|
| 235 |
enum bus_status_bits { |
| 236 |
BSR_REN_BIT = 0x1, |
| 237 |
BSR_IFC_BIT = 0x2, |
| 238 |
BSR_SRQ_BIT = 0x4, |
| 239 |
BSR_EOI_BIT = 0x8, |
| 240 |
BSR_NRFD_BIT = 0x10, |
| 241 |
BSR_NDAC_BIT = 0x20, |
| 242 |
BSR_DAV_BIT = 0x40, |
| 243 |
BSR_ATN_BIT = 0x80, |
| 244 |
}; |
| 245 |
|
| 246 |
/*---------------------------------------------------------*/ |
| 247 |
/* TMS 9914 Auxiliary Commands */ |
| 248 |
/*---------------------------------------------------------*/ |
| 249 |
|
| 250 |
enum aux_cmd_bits { |
| 251 |
AUX_CS = 0x80, /* set bit instead of clearing it, used with commands marked 'd' below */ |
| 252 |
AUX_CHIP_RESET = 0x0, /* d Chip reset */ |
| 253 |
AUX_INVAL = 0x1, /* release dac holdoff, invalid command byte */ |
| 254 |
AUX_VAL = (AUX_INVAL | AUX_CS), /* release dac holdoff, valid command byte */ |
| 255 |
AUX_RHDF = 0x2, /* X Release RFD holdoff */ |
| 256 |
AUX_HLDA = 0x3, /* d holdoff on all data */ |
| 257 |
AUX_HLDE = 0x4, /* d holdoff on EOI only */ |
| 258 |
AUX_NBAF = 0x5, /* X Set new byte available false */ |
| 259 |
AUX_FGET = 0x6, /* d force GET */ |
| 260 |
AUX_RTL = 0x7, /* d return to local */ |
| 261 |
AUX_SEOI = 0x8, /* X send EOI with next byte */ |
| 262 |
AUX_LON = 0x9, /* d Listen only */ |
| 263 |
AUX_TON = 0xa, /* d Talk only */ |
| 264 |
AUX_GTS = 0xb, /* X goto standby */ |
| 265 |
AUX_TCA = 0xc, /* X take control asynchronously */ |
| 266 |
AUX_TCS = 0xd, /* X take " synchronously */ |
| 267 |
AUX_RPP = 0xe, /* d Request parallel poll */ |
| 268 |
AUX_SIC = 0xf, /* d send interface clear */ |
| 269 |
AUX_SRE = 0x10, /* d send remote enable */ |
| 270 |
AUX_RQC = 0x11, /* X request control */ |
| 271 |
AUX_RLC = 0x12, /* X release control */ |
| 272 |
AUX_DAI = 0x13, /* d disable all interrupts */ |
| 273 |
AUX_PTS = 0x14, /* X pass through next secondary */ |
| 274 |
AUX_STDL = 0x15, /* d short T1 delay */ |
| 275 |
AUX_SHDW = 0x16, /* d shadow handshake */ |
| 276 |
AUX_VSTDL = 0x17, /* d very short T1 delay (smj9914 extension) */ |
| 277 |
AUX_RSV2 = 0x18, /* d request service bit 2 (smj9914 extension) */ |
| 278 |
}; |
| 279 |
|
| 280 |
#endif //_TMS9914_H |