nec7210.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /***************************************************************************
  2. nec7210.h
  3. -------------------
  4. begin : Jan 2002
  5. copyright : (C) 2002 by Frank Mori Hess
  6. email : fmhess@users.sourceforge.net
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #ifndef _NEC7210_H
  17. #define _NEC7210_H
  18. #include "gpib_state_machines.h"
  19. #include <linux/types.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/string.h>
  22. #include <linux/interrupt.h>
  23. #include "gpib_types.h"
  24. #include "nec7210_registers.h"
  25. /* struct used to provide variables local to a nec7210 chip */
  26. typedef struct nec7210_private_struct nec7210_private_t;
  27. struct nec7210_private_struct
  28. {
  29. void *iobase;
  30. unsigned int offset; // offset between successive nec7210 io addresses
  31. unsigned int dma_channel;
  32. uint8_t *dma_buffer;
  33. unsigned int dma_buffer_length; // length of dma buffer
  34. dma_addr_t dma_buffer_addr; // bus address of board->buffer for use with dma
  35. // software copy of bits written to registers
  36. volatile uint8_t reg_bits[ 8 ];
  37. volatile uint8_t auxa_bits; // bits written to auxilliary register A
  38. volatile uint8_t auxb_bits; // bits written to auxilliary register B
  39. // used to keep track of board's state, bit definitions given below
  40. volatile unsigned long state;
  41. /* lock for chips that extend the nec7210 registers by paging in alternate regs */
  42. spinlock_t register_page_lock;
  43. // wrappers for outb, inb, readb, or writeb
  44. uint8_t (*read_byte)(nec7210_private_t *priv, unsigned int register_number);
  45. void (*write_byte)(nec7210_private_t *priv, uint8_t byte, unsigned int register_number);
  46. enum nec7210_chipset type;
  47. enum talker_function_state talker_state;
  48. enum listener_function_state listener_state;
  49. void *private;
  50. unsigned srq_pending : 1;
  51. };
  52. static inline void init_nec7210_private( nec7210_private_t *priv )
  53. {
  54. memset( priv, 0, sizeof( nec7210_private_t ) );
  55. spin_lock_init( &priv->register_page_lock );
  56. }
  57. // slightly shorter way to access read_byte and write_byte
  58. static inline uint8_t read_byte(nec7210_private_t *priv, unsigned int register_number)
  59. {
  60. return priv->read_byte(priv, register_number);
  61. }
  62. static inline void write_byte(nec7210_private_t *priv, uint8_t byte, unsigned int register_number)
  63. {
  64. priv->write_byte(priv, byte, register_number);
  65. }
  66. // nec7210_private_t.state bit numbers
  67. enum
  68. {
  69. PIO_IN_PROGRESS_BN, // pio transfer in progress
  70. DMA_READ_IN_PROGRESS_BN, // dma read transfer in progress
  71. DMA_WRITE_IN_PROGRESS_BN, // dma write transfer in progress
  72. READ_READY_BN, // board has data byte available to read
  73. WRITE_READY_BN, // board is ready to send a data byte
  74. COMMAND_READY_BN, // board is ready to send a command byte
  75. RECEIVED_END_BN, // received END
  76. BUS_ERROR_BN, // output error has occurred
  77. RFD_HOLDOFF_BN, // rfd holdoff in effect
  78. DEV_CLEAR_BN, // device clear received
  79. };
  80. // interface functions
  81. int nec7210_read(gpib_board_t *board, nec7210_private_t *priv,
  82. uint8_t *buffer, size_t length, int *end, size_t *bytes_read);
  83. int nec7210_write(gpib_board_t *board, nec7210_private_t *priv,
  84. uint8_t *buffer, size_t length, int send_eoi, size_t *bytes_written);
  85. ssize_t nec7210_command(gpib_board_t *board, nec7210_private_t *priv,
  86. uint8_t *buffer, size_t length);
  87. int nec7210_take_control(gpib_board_t *board, nec7210_private_t *priv,
  88. int syncronous);
  89. int nec7210_go_to_standby(gpib_board_t *board, nec7210_private_t *priv);
  90. void nec7210_request_system_control( gpib_board_t *board,
  91. nec7210_private_t *priv, int request_control );
  92. void nec7210_interface_clear(gpib_board_t *board, nec7210_private_t *priv, int assert);
  93. void nec7210_remote_enable(gpib_board_t *board, nec7210_private_t *priv, int enable);
  94. int nec7210_enable_eos(gpib_board_t *board, nec7210_private_t *priv,
  95. uint8_t eos_bytes, int compare_8_bits);
  96. void nec7210_disable_eos(gpib_board_t *board, nec7210_private_t *priv);
  97. unsigned int nec7210_update_status( gpib_board_t *board, nec7210_private_t *priv,
  98. unsigned int clear_mask );
  99. void nec7210_primary_address( const gpib_board_t *board,
  100. nec7210_private_t *priv, unsigned int address);
  101. void nec7210_secondary_address( const gpib_board_t *board, nec7210_private_t *priv,
  102. unsigned int address, int enable);
  103. int nec7210_parallel_poll(gpib_board_t *board, nec7210_private_t *priv, uint8_t *result);
  104. void nec7210_serial_poll_response(gpib_board_t *board, nec7210_private_t *priv, uint8_t status);
  105. void nec7210_parallel_poll_configure( gpib_board_t *board,
  106. nec7210_private_t *priv, unsigned int configuration );
  107. void nec7210_parallel_poll_response( gpib_board_t *board,
  108. nec7210_private_t *priv, int ist );
  109. uint8_t nec7210_serial_poll_status( gpib_board_t *board,
  110. nec7210_private_t *priv );
  111. unsigned int nec7210_t1_delay( gpib_board_t *board,
  112. nec7210_private_t *priv, unsigned int nano_sec );
  113. void nec7210_return_to_local( const gpib_board_t *board, nec7210_private_t *priv );
  114. // utility functions
  115. void nec7210_board_reset( nec7210_private_t *priv, const gpib_board_t *board );
  116. void nec7210_board_online( nec7210_private_t *priv, const gpib_board_t *board );
  117. unsigned int nec7210_set_reg_bits( nec7210_private_t *priv, unsigned int reg,
  118. unsigned int mask, unsigned int bits );
  119. void nec7210_set_handshake_mode( gpib_board_t *board, nec7210_private_t *priv, int mode );
  120. void nec7210_release_rfd_holdoff( gpib_board_t *board, nec7210_private_t *priv );
  121. uint8_t nec7210_read_data_in( gpib_board_t *board, nec7210_private_t *priv, int *end );
  122. // wrappers for io functions
  123. uint8_t nec7210_ioport_read_byte(nec7210_private_t *priv, unsigned int register_num);
  124. void nec7210_ioport_write_byte(nec7210_private_t *priv, uint8_t data, unsigned int register_num);
  125. uint8_t nec7210_iomem_read_byte(nec7210_private_t *priv, unsigned int register_num);
  126. void nec7210_iomem_write_byte(nec7210_private_t *priv, uint8_t data, unsigned int register_num);
  127. uint8_t nec7210_locking_ioport_read_byte(nec7210_private_t *priv, unsigned int register_num);
  128. void nec7210_locking_ioport_write_byte(nec7210_private_t *priv, uint8_t data, unsigned int register_num);
  129. uint8_t nec7210_locking_iomem_read_byte(nec7210_private_t *priv, unsigned int register_num);
  130. void nec7210_locking_iomem_write_byte(nec7210_private_t *priv, uint8_t data, unsigned int register_num);
  131. // interrupt service routine
  132. irqreturn_t nec7210_interrupt(gpib_board_t *board, nec7210_private_t *priv);
  133. irqreturn_t nec7210_interrupt_have_status( gpib_board_t *board,
  134. nec7210_private_t *priv, int status1, int status2 );
  135. #endif //_NEC7210_H