Path: blob/master/drivers/gpib/agilent_82350b/agilent_82350b.c
38184 views
// SPDX-License-Identifier: GPL-2.012/***************************************************************************3* copyright : (C) 2002, 2004 by Frank Mori Hess *4***************************************************************************/56#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt7#define dev_fmt pr_fmt8#define DRV_NAME KBUILD_MODNAME910#include "agilent_82350b.h"11#include <linux/delay.h>12#include <linux/ioport.h>13#include <linux/sched.h>14#include <linux/module.h>15#include <linux/slab.h>16#include <asm/dma.h>17#include <linux/pci.h>18#include <linux/pci_ids.h>19#include <linux/string.h>20#include <linux/init.h>21#include <linux/wait.h>2223MODULE_LICENSE("GPL");24MODULE_DESCRIPTION("GPIB driver for Agilent 82350b");2526static int read_transfer_counter(struct agilent_82350b_priv *a_priv);27static unsigned short read_and_clear_event_status(struct gpib_board *board);28static void set_transfer_counter(struct agilent_82350b_priv *a_priv, int count);29static int agilent_82350b_write(struct gpib_board *board, u8 *buffer,30size_t length, int send_eoi, size_t *bytes_written);3132static int agilent_82350b_accel_read(struct gpib_board *board, u8 *buffer,33size_t length, int *end, size_t *bytes_read)3435{36struct agilent_82350b_priv *a_priv = board->private_data;37struct tms9914_priv *tms_priv = &a_priv->tms9914_priv;38int retval = 0;39unsigned short event_status;40int i, num_fifo_bytes;41/* hardware doesn't support checking for end-of-string character when using fifo */42if (tms_priv->eos_flags & REOS)43return tms9914_read(board, tms_priv, buffer, length, end, bytes_read);4445clear_bit(DEV_CLEAR_BN, &tms_priv->state);4647read_and_clear_event_status(board);48*end = 0;49*bytes_read = 0;50if (length == 0)51return 0;52/* disable fifo for the moment */53writeb(DIRECTION_GPIB_TO_HOST, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);54/* handle corner case of board not in holdoff and one byte might slip in early */55if (tms_priv->holdoff_active == 0 && length > 1) {56size_t num_bytes;5758retval = tms9914_read(board, tms_priv, buffer, 1, end, &num_bytes);59*bytes_read += num_bytes;60if (retval < 0 || *end)61return retval;62++buffer;63--length;64}65tms9914_set_holdoff_mode(tms_priv, TMS9914_HOLDOFF_EOI);66tms9914_release_holdoff(tms_priv);67i = 0;68num_fifo_bytes = length - 1;69/* disable BI interrupts */70write_byte(tms_priv, tms_priv->imr0_bits & ~HR_BIIE, IMR0);71while (i < num_fifo_bytes && *end == 0) {72int block_size;73int j;74int count;7576block_size = min(num_fifo_bytes - i, agilent_82350b_fifo_size);77set_transfer_counter(a_priv, block_size);78writeb(ENABLE_TI_TO_SRAM | DIRECTION_GPIB_TO_HOST,79a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);80if (agilent_82350b_fifo_is_halted(a_priv))81writeb(RESTART_STREAM_BIT, a_priv->gpib_base + STREAM_STATUS_REG);8283clear_bit(READ_READY_BN, &tms_priv->state);8485retval = wait_event_interruptible(board->wait,86((event_status =87read_and_clear_event_status(board)) &88(TERM_COUNT_STATUS_BIT |89BUFFER_END_STATUS_BIT)) ||90test_bit(DEV_CLEAR_BN, &tms_priv->state) ||91test_bit(TIMO_NUM, &board->status));92if (retval) {93retval = -ERESTARTSYS;94break;95}96count = block_size - read_transfer_counter(a_priv);97for (j = 0; j < count && i < num_fifo_bytes; ++j)98buffer[i++] = readb(a_priv->sram_base + j);99if (event_status & BUFFER_END_STATUS_BIT) {100clear_bit(RECEIVED_END_BN, &tms_priv->state);101102tms_priv->holdoff_active = 1;103*end = 1;104}105if (test_bit(TIMO_NUM, &board->status)) {106retval = -ETIMEDOUT;107break;108}109if (test_bit(DEV_CLEAR_BN, &tms_priv->state)) {110retval = -EINTR;111break;112}113}114/* re-enable BI interrupts */115write_byte(tms_priv, tms_priv->imr0_bits, IMR0);116*bytes_read += i;117buffer += i;118length -= i;119writeb(DIRECTION_GPIB_TO_HOST, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);120if (retval < 0)121return retval;122/* read last bytes if we havn't received an END yet */123if (*end == 0) {124size_t num_bytes;125/* try to make sure we holdoff after last byte read */126retval = tms9914_read(board, tms_priv, buffer, length, end, &num_bytes);127*bytes_read += num_bytes;128if (retval < 0)129return retval;130}131return 0;132}133134static int translate_wait_return_value(struct gpib_board *board, int retval)135136{137struct agilent_82350b_priv *a_priv = board->private_data;138struct tms9914_priv *tms_priv = &a_priv->tms9914_priv;139140if (retval)141return -ERESTARTSYS;142if (test_bit(TIMO_NUM, &board->status))143return -ETIMEDOUT;144if (test_bit(DEV_CLEAR_BN, &tms_priv->state))145return -EINTR;146return 0;147}148149static int agilent_82350b_accel_write(struct gpib_board *board, u8 *buffer,150size_t length, int send_eoi,151size_t *bytes_written)152{153struct agilent_82350b_priv *a_priv = board->private_data;154struct tms9914_priv *tms_priv = &a_priv->tms9914_priv;155int i, j;156unsigned short event_status;157int retval = 0;158int fifotransferlength = length;159int block_size = 0;160size_t num_bytes;161162*bytes_written = 0;163if (send_eoi)164--fifotransferlength;165166clear_bit(DEV_CLEAR_BN, &tms_priv->state);167168writeb(0, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);169170event_status = read_and_clear_event_status(board);171172#ifdef EXPERIMENTAL173/* wait for previous BO to complete if any */174retval = wait_event_interruptible(board->wait,175test_bit(DEV_CLEAR_BN, &tms_priv->state) ||176test_bit(WRITE_READY_BN, &tms_priv->state) ||177test_bit(TIMO_NUM, &board->status));178retval = translate_wait_return_value(board, retval);179180if (retval)181return retval;182#endif183184if (fifotransferlength > 0) {185retval = agilent_82350b_write(board, buffer, 1, 0, &num_bytes);186*bytes_written += num_bytes;187if (retval < 0)188return retval;189}190191write_byte(tms_priv, tms_priv->imr0_bits & ~HR_BOIE, IMR0);192for (i = 1; i < fifotransferlength;) {193clear_bit(WRITE_READY_BN, &tms_priv->state);194195block_size = min(fifotransferlength - i, agilent_82350b_fifo_size);196set_transfer_counter(a_priv, block_size);197for (j = 0; j < block_size; ++j, ++i) {198/* load data into board's sram */199writeb(buffer[i], a_priv->sram_base + j);200}201writeb(ENABLE_TI_TO_SRAM, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);202203if (agilent_82350b_fifo_is_halted(a_priv))204writeb(RESTART_STREAM_BIT, a_priv->gpib_base + STREAM_STATUS_REG);205206retval = wait_event_interruptible(board->wait,207((event_status =208read_and_clear_event_status(board)) &209TERM_COUNT_STATUS_BIT) ||210test_bit(DEV_CLEAR_BN, &tms_priv->state) ||211test_bit(TIMO_NUM, &board->status));212writeb(0, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);213num_bytes = block_size - read_transfer_counter(a_priv);214215*bytes_written += num_bytes;216retval = translate_wait_return_value(board, retval);217if (retval)218break;219}220write_byte(tms_priv, tms_priv->imr0_bits, IMR0);221if (retval < 0)222return retval;223224if (send_eoi) {225retval = agilent_82350b_write(board, buffer + fifotransferlength, 1, send_eoi,226&num_bytes);227*bytes_written += num_bytes;228if (retval < 0)229return retval;230}231return 0;232}233234static unsigned short read_and_clear_event_status(struct gpib_board *board)235{236struct agilent_82350b_priv *a_priv = board->private_data;237unsigned long flags;238unsigned short status;239240spin_lock_irqsave(&board->spinlock, flags);241status = a_priv->event_status_bits;242a_priv->event_status_bits = 0;243spin_unlock_irqrestore(&board->spinlock, flags);244return status;245}246247static irqreturn_t agilent_82350b_interrupt(int irq, void *arg)248249{250int tms9914_status1 = 0, tms9914_status2 = 0;251int event_status;252struct gpib_board *board = arg;253struct agilent_82350b_priv *a_priv = board->private_data;254unsigned long flags;255irqreturn_t retval = IRQ_NONE;256257spin_lock_irqsave(&board->spinlock, flags);258event_status = readb(a_priv->gpib_base + EVENT_STATUS_REG);259if (event_status & IRQ_STATUS_BIT)260retval = IRQ_HANDLED;261262if (event_status & TMS9914_IRQ_STATUS_BIT) {263tms9914_status1 = read_byte(&a_priv->tms9914_priv, ISR0);264tms9914_status2 = read_byte(&a_priv->tms9914_priv, ISR1);265tms9914_interrupt_have_status(board, &a_priv->tms9914_priv, tms9914_status1,266tms9914_status2);267}268/* write-clear status bits */269if (event_status & (BUFFER_END_STATUS_BIT | TERM_COUNT_STATUS_BIT)) {270writeb(event_status & (BUFFER_END_STATUS_BIT | TERM_COUNT_STATUS_BIT),271a_priv->gpib_base + EVENT_STATUS_REG);272a_priv->event_status_bits |= event_status;273wake_up_interruptible(&board->wait);274}275spin_unlock_irqrestore(&board->spinlock, flags);276return retval;277}278279static void agilent_82350b_detach(struct gpib_board *board);280281static int read_transfer_counter(struct agilent_82350b_priv *a_priv)282{283int lo, mid, value;284285lo = readb(a_priv->gpib_base + XFER_COUNT_LO_REG);286mid = readb(a_priv->gpib_base + XFER_COUNT_MID_REG);287value = (lo & 0xff) | ((mid << 8) & 0x7f00);288value = ~(value - 1) & 0x7fff;289return value;290}291292static void set_transfer_counter(struct agilent_82350b_priv *a_priv, int count)293{294int complement = -count;295296writeb(complement & 0xff, a_priv->gpib_base + XFER_COUNT_LO_REG);297writeb((complement >> 8) & 0xff, a_priv->gpib_base + XFER_COUNT_MID_REG);298/* I don't think the hi count reg is even used, but oh well */299writeb((complement >> 16) & 0xf, a_priv->gpib_base + XFER_COUNT_HI_REG);300}301302/* wrappers for interface functions */303static int agilent_82350b_read(struct gpib_board *board, u8 *buffer,304size_t length, int *end, size_t *bytes_read)305{306struct agilent_82350b_priv *priv = board->private_data;307308return tms9914_read(board, &priv->tms9914_priv, buffer, length, end, bytes_read);309}310311static int agilent_82350b_write(struct gpib_board *board, u8 *buffer,312size_t length, int send_eoi, size_t *bytes_written)313314{315struct agilent_82350b_priv *priv = board->private_data;316317return tms9914_write(board, &priv->tms9914_priv, buffer, length, send_eoi, bytes_written);318}319320static int agilent_82350b_command(struct gpib_board *board, u8 *buffer,321size_t length, size_t *bytes_written)322323{324struct agilent_82350b_priv *priv = board->private_data;325326return tms9914_command(board, &priv->tms9914_priv, buffer, length, bytes_written);327}328329static int agilent_82350b_take_control(struct gpib_board *board, int synchronous)330331{332struct agilent_82350b_priv *priv = board->private_data;333334return tms9914_take_control_workaround(board, &priv->tms9914_priv, synchronous);335}336337static int agilent_82350b_go_to_standby(struct gpib_board *board)338339{340struct agilent_82350b_priv *priv = board->private_data;341342return tms9914_go_to_standby(board, &priv->tms9914_priv);343}344345static int agilent_82350b_request_system_control(struct gpib_board *board, int request_control)346{347struct agilent_82350b_priv *a_priv = board->private_data;348349if (request_control) {350a_priv->card_mode_bits |= CM_SYSTEM_CONTROLLER_BIT;351if (a_priv->model != MODEL_82350A)352writeb(IC_SYSTEM_CONTROLLER_BIT, a_priv->gpib_base + INTERNAL_CONFIG_REG);353} else {354a_priv->card_mode_bits &= ~CM_SYSTEM_CONTROLLER_BIT;355if (a_priv->model != MODEL_82350A)356writeb(0, a_priv->gpib_base + INTERNAL_CONFIG_REG);357}358writeb(a_priv->card_mode_bits, a_priv->gpib_base + CARD_MODE_REG);359return tms9914_request_system_control(board, &a_priv->tms9914_priv, request_control);360}361362static void agilent_82350b_interface_clear(struct gpib_board *board, int assert)363364{365struct agilent_82350b_priv *priv = board->private_data;366367tms9914_interface_clear(board, &priv->tms9914_priv, assert);368}369370static void agilent_82350b_remote_enable(struct gpib_board *board, int enable)371{372struct agilent_82350b_priv *priv = board->private_data;373374tms9914_remote_enable(board, &priv->tms9914_priv, enable);375}376377static int agilent_82350b_enable_eos(struct gpib_board *board, u8 eos_byte,378int compare_8_bits)379{380struct agilent_82350b_priv *priv = board->private_data;381382return tms9914_enable_eos(board, &priv->tms9914_priv, eos_byte, compare_8_bits);383}384385static void agilent_82350b_disable_eos(struct gpib_board *board)386{387struct agilent_82350b_priv *priv = board->private_data;388389tms9914_disable_eos(board, &priv->tms9914_priv);390}391392static unsigned int agilent_82350b_update_status(struct gpib_board *board,393unsigned int clear_mask)394{395struct agilent_82350b_priv *priv = board->private_data;396397return tms9914_update_status(board, &priv->tms9914_priv, clear_mask);398}399400static int agilent_82350b_primary_address(struct gpib_board *board,401unsigned int address)402{403struct agilent_82350b_priv *priv = board->private_data;404405return tms9914_primary_address(board, &priv->tms9914_priv, address);406}407408static int agilent_82350b_secondary_address(struct gpib_board *board,409unsigned int address, int enable)410{411struct agilent_82350b_priv *priv = board->private_data;412413return tms9914_secondary_address(board, &priv->tms9914_priv, address, enable);414}415416static int agilent_82350b_parallel_poll(struct gpib_board *board, u8 *result)417{418struct agilent_82350b_priv *priv = board->private_data;419420return tms9914_parallel_poll(board, &priv->tms9914_priv, result);421}422423static void agilent_82350b_parallel_poll_configure(struct gpib_board *board,424u8 config)425{426struct agilent_82350b_priv *priv = board->private_data;427428tms9914_parallel_poll_configure(board, &priv->tms9914_priv, config);429}430431static void agilent_82350b_parallel_poll_response(struct gpib_board *board, int ist)432{433struct agilent_82350b_priv *priv = board->private_data;434435tms9914_parallel_poll_response(board, &priv->tms9914_priv, ist);436}437438static void agilent_82350b_serial_poll_response(struct gpib_board *board, u8 status)439{440struct agilent_82350b_priv *priv = board->private_data;441442tms9914_serial_poll_response(board, &priv->tms9914_priv, status);443}444445static u8 agilent_82350b_serial_poll_status(struct gpib_board *board)446{447struct agilent_82350b_priv *priv = board->private_data;448449return tms9914_serial_poll_status(board, &priv->tms9914_priv);450}451452static int agilent_82350b_line_status(const struct gpib_board *board)453{454struct agilent_82350b_priv *priv = board->private_data;455456return tms9914_line_status(board, &priv->tms9914_priv);457}458459static int agilent_82350b_t1_delay(struct gpib_board *board, unsigned int nanosec)460{461struct agilent_82350b_priv *a_priv = board->private_data;462static const int nanosec_per_clock = 30;463unsigned int value;464465tms9914_t1_delay(board, &a_priv->tms9914_priv, nanosec);466467value = (nanosec + nanosec_per_clock - 1) / nanosec_per_clock;468if (value > 0xff)469value = 0xff;470writeb(value, a_priv->gpib_base + T1_DELAY_REG);471return value * nanosec_per_clock;472}473474static void agilent_82350b_return_to_local(struct gpib_board *board)475{476struct agilent_82350b_priv *priv = board->private_data;477478tms9914_return_to_local(board, &priv->tms9914_priv);479}480481static int agilent_82350b_allocate_private(struct gpib_board *board)482{483board->private_data = kzalloc(sizeof(struct agilent_82350b_priv), GFP_KERNEL);484if (!board->private_data)485return -ENOMEM;486return 0;487}488489static void agilent_82350b_free_private(struct gpib_board *board)490{491kfree(board->private_data);492board->private_data = NULL;493}494495static int init_82350a_hardware(struct gpib_board *board,496const struct gpib_board_config *config)497{498struct agilent_82350b_priv *a_priv = board->private_data;499static const unsigned int firmware_length = 5302;500unsigned int borg_status;501static const unsigned int timeout = 1000;502int i, j;503const char *firmware_data = config->init_data;504const unsigned int plx_cntrl_static_bits = PLX9050_WAITO_NOT_USER0_SELECT_BIT |505PLX9050_USER0_OUTPUT_BIT |506PLX9050_LLOCK_NOT_USER1_SELECT_BIT |507PLX9050_USER1_OUTPUT_BIT |508PLX9050_USER2_OUTPUT_BIT |509PLX9050_USER3_OUTPUT_BIT |510PLX9050_PCI_READ_MODE_BIT |511PLX9050_PCI_WRITE_MODE_BIT |512PLX9050_PCI_RETRY_DELAY_BITS(64) |513PLX9050_DIRECT_SLAVE_LOCK_ENABLE_BIT;514515/* load borg data */516borg_status = readb(a_priv->borg_base);517if ((borg_status & BORG_DONE_BIT))518return 0;519/* need to programme borg */520if (!config->init_data || config->init_data_length != firmware_length) {521dev_err(board->gpib_dev, "the 82350A board requires firmware after powering on.\n");522return -EIO;523}524dev_dbg(board->gpib_dev, "Loading firmware...\n");525526/* tickle the borg */527writel(plx_cntrl_static_bits | PLX9050_USER3_DATA_BIT,528a_priv->plx_base + PLX9050_CNTRL_REG);529usleep_range(1000, 2000);530writel(plx_cntrl_static_bits, a_priv->plx_base + PLX9050_CNTRL_REG);531usleep_range(1000, 2000);532writel(plx_cntrl_static_bits | PLX9050_USER3_DATA_BIT,533a_priv->plx_base + PLX9050_CNTRL_REG);534usleep_range(1000, 2000);535536for (i = 0; i < config->init_data_length; ++i) {537for (j = 0; j < timeout && (readb(a_priv->borg_base) & BORG_READY_BIT) == 0; ++j) {538if (need_resched())539schedule();540usleep_range(10, 20);541}542if (j == timeout) {543dev_err(board->gpib_dev, "timed out loading firmware.\n");544return -ETIMEDOUT;545}546writeb(firmware_data[i], a_priv->gpib_base + CONFIG_DATA_REG);547}548for (j = 0; j < timeout && (readb(a_priv->borg_base) & BORG_DONE_BIT) == 0; ++j) {549if (need_resched())550schedule();551usleep_range(10, 20);552}553if (j == timeout) {554dev_err(board->gpib_dev, "timed out waiting for firmware load to complete.\n");555return -ETIMEDOUT;556}557dev_dbg(board->gpib_dev, " ...done.\n");558return 0;559}560561static int test_sram(struct gpib_board *board)562563{564struct agilent_82350b_priv *a_priv = board->private_data;565unsigned int i;566const unsigned int sram_length = pci_resource_len(a_priv->pci_device, SRAM_82350A_REGION);567/* test SRAM */568const unsigned int byte_mask = 0xff;569570for (i = 0; i < sram_length; ++i) {571writeb(i & byte_mask, a_priv->sram_base + i);572if (need_resched())573schedule();574}575for (i = 0; i < sram_length; ++i) {576unsigned int read_value = readb(a_priv->sram_base + i);577578if ((i & byte_mask) != read_value) {579dev_err(board->gpib_dev, "SRAM test failed at %d wanted %d got %d\n",580i, (i & byte_mask), read_value);581return -EIO;582}583if (need_resched())584schedule();585}586dev_dbg(board->gpib_dev, "SRAM test passed 0x%x bytes checked\n", sram_length);587return 0;588}589590static int agilent_82350b_generic_attach(struct gpib_board *board,591const struct gpib_board_config *config,592int use_fifos)593594{595struct agilent_82350b_priv *a_priv;596struct tms9914_priv *tms_priv;597int retval;598599board->status = 0;600601if (agilent_82350b_allocate_private(board))602return -ENOMEM;603a_priv = board->private_data;604a_priv->using_fifos = use_fifos;605tms_priv = &a_priv->tms9914_priv;606tms_priv->read_byte = tms9914_iomem_read_byte;607tms_priv->write_byte = tms9914_iomem_write_byte;608tms_priv->offset = 1;609610/* find board */611a_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_AGILENT,612PCI_DEVICE_ID_82350B, NULL);613if (a_priv->pci_device) {614a_priv->model = MODEL_82350B;615dev_dbg(board->gpib_dev, "Agilent 82350B board found\n");616617} else {618a_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_AGILENT,619PCI_DEVICE_ID_82351A, NULL);620if (a_priv->pci_device) {621a_priv->model = MODEL_82351A;622dev_dbg(board->gpib_dev, "Agilent 82351B board found\n");623624} else {625a_priv->pci_device = gpib_pci_get_subsys(config, PCI_VENDOR_ID_PLX,626PCI_DEVICE_ID_PLX_9050,627PCI_VENDOR_ID_HP,628PCI_SUBDEVICE_ID_82350A,629a_priv->pci_device);630if (a_priv->pci_device) {631a_priv->model = MODEL_82350A;632dev_dbg(board->gpib_dev, "HP/Agilent 82350A board found\n");633} else {634dev_err(board->gpib_dev, "no 82350/82351 board found\n");635return -ENODEV;636}637}638}639if (pci_enable_device(a_priv->pci_device)) {640dev_err(board->gpib_dev, "error enabling pci device\n");641return -EIO;642}643if (pci_request_regions(a_priv->pci_device, DRV_NAME))644return -ENOMEM;645switch (a_priv->model) {646case MODEL_82350A:647a_priv->plx_base = ioremap(pci_resource_start(a_priv->pci_device, PLX_MEM_REGION),648pci_resource_len(a_priv->pci_device, PLX_MEM_REGION));649dev_dbg(board->gpib_dev, "plx base address remapped to 0x%p\n", a_priv->plx_base);650a_priv->gpib_base = ioremap(pci_resource_start(a_priv->pci_device,651GPIB_82350A_REGION),652pci_resource_len(a_priv->pci_device,653GPIB_82350A_REGION));654dev_dbg(board->gpib_dev, "chip base address remapped to 0x%p\n", a_priv->gpib_base);655tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;656a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device,657SRAM_82350A_REGION),658pci_resource_len(a_priv->pci_device,659SRAM_82350A_REGION));660dev_dbg(board->gpib_dev, "sram base address remapped to 0x%p\n", a_priv->sram_base);661a_priv->borg_base = ioremap(pci_resource_start(a_priv->pci_device,662BORG_82350A_REGION),663pci_resource_len(a_priv->pci_device,664BORG_82350A_REGION));665dev_dbg(board->gpib_dev, "borg base address remapped to 0x%p\n", a_priv->borg_base);666667retval = init_82350a_hardware(board, config);668if (retval < 0)669return retval;670break;671case MODEL_82350B:672case MODEL_82351A:673a_priv->gpib_base = ioremap(pci_resource_start(a_priv->pci_device, GPIB_REGION),674pci_resource_len(a_priv->pci_device, GPIB_REGION));675dev_dbg(board->gpib_dev, "chip base address remapped to 0x%p\n", a_priv->gpib_base);676tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;677a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device, SRAM_REGION),678pci_resource_len(a_priv->pci_device, SRAM_REGION));679dev_dbg(board->gpib_dev, "sram base address remapped to 0x%p\n", a_priv->sram_base);680a_priv->misc_base = ioremap(pci_resource_start(a_priv->pci_device, MISC_REGION),681pci_resource_len(a_priv->pci_device, MISC_REGION));682dev_dbg(board->gpib_dev, "misc base address remapped to 0x%p\n", a_priv->misc_base);683break;684default:685dev_err(board->gpib_dev, "invalid board\n");686return -ENODEV;687}688689retval = test_sram(board);690if (retval < 0)691return retval;692693if (request_irq(a_priv->pci_device->irq, agilent_82350b_interrupt,694IRQF_SHARED, DRV_NAME, board)) {695dev_err(board->gpib_dev, "failed to obtain irq %d\n", a_priv->pci_device->irq);696return -EIO;697}698a_priv->irq = a_priv->pci_device->irq;699dev_dbg(board->gpib_dev, " IRQ %d\n", a_priv->irq);700701writeb(0, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);702a_priv->card_mode_bits = ENABLE_PCI_IRQ_BIT;703writeb(a_priv->card_mode_bits, a_priv->gpib_base + CARD_MODE_REG);704705if (a_priv->model == MODEL_82350A) {706/* enable PCI interrupts for 82350a */707writel(PLX9050_LINTR1_EN_BIT | PLX9050_LINTR2_POLARITY_BIT |708PLX9050_PCI_INTR_EN_BIT,709a_priv->plx_base + PLX9050_INTCSR_REG);710}711712if (use_fifos) {713writeb(ENABLE_BUFFER_END_EVENTS_BIT | ENABLE_TERM_COUNT_EVENTS_BIT,714a_priv->gpib_base + EVENT_ENABLE_REG);715writeb(ENABLE_TERM_COUNT_INTERRUPT_BIT | ENABLE_BUFFER_END_INTERRUPT_BIT |716ENABLE_TMS9914_INTERRUPTS_BIT, a_priv->gpib_base + INTERRUPT_ENABLE_REG);717/* write-clear event status bits */718writeb(BUFFER_END_STATUS_BIT | TERM_COUNT_STATUS_BIT,719a_priv->gpib_base + EVENT_STATUS_REG);720} else {721writeb(0, a_priv->gpib_base + EVENT_ENABLE_REG);722writeb(ENABLE_TMS9914_INTERRUPTS_BIT,723a_priv->gpib_base + INTERRUPT_ENABLE_REG);724}725board->t1_nano_sec = agilent_82350b_t1_delay(board, 2000);726tms9914_board_reset(tms_priv);727728tms9914_online(board, tms_priv);729730return 0;731}732733static int agilent_82350b_unaccel_attach(struct gpib_board *board,734const struct gpib_board_config *config)735{736return agilent_82350b_generic_attach(board, config, 0);737}738739static int agilent_82350b_accel_attach(struct gpib_board *board,740const struct gpib_board_config *config)741{742return agilent_82350b_generic_attach(board, config, 1);743}744745static void agilent_82350b_detach(struct gpib_board *board)746{747struct agilent_82350b_priv *a_priv = board->private_data;748struct tms9914_priv *tms_priv;749750if (a_priv) {751if (a_priv->plx_base) /* disable interrupts */752writel(0, a_priv->plx_base + PLX9050_INTCSR_REG);753754tms_priv = &a_priv->tms9914_priv;755if (a_priv->irq)756free_irq(a_priv->irq, board);757if (a_priv->gpib_base) {758tms9914_board_reset(tms_priv);759if (a_priv->misc_base)760iounmap(a_priv->misc_base);761if (a_priv->borg_base)762iounmap(a_priv->borg_base);763if (a_priv->sram_base)764iounmap(a_priv->sram_base);765if (a_priv->gpib_base)766iounmap(a_priv->gpib_base);767if (a_priv->plx_base)768iounmap(a_priv->plx_base);769pci_release_regions(a_priv->pci_device);770}771if (a_priv->pci_device)772pci_dev_put(a_priv->pci_device);773}774agilent_82350b_free_private(board);775}776777static struct gpib_interface agilent_82350b_unaccel_interface = {778.name = "agilent_82350b_unaccel",779.attach = agilent_82350b_unaccel_attach,780.detach = agilent_82350b_detach,781.read = agilent_82350b_read,782.write = agilent_82350b_write,783.command = agilent_82350b_command,784.request_system_control = agilent_82350b_request_system_control,785.take_control = agilent_82350b_take_control,786.go_to_standby = agilent_82350b_go_to_standby,787.interface_clear = agilent_82350b_interface_clear,788.remote_enable = agilent_82350b_remote_enable,789.enable_eos = agilent_82350b_enable_eos,790.disable_eos = agilent_82350b_disable_eos,791.parallel_poll = agilent_82350b_parallel_poll,792.parallel_poll_configure = agilent_82350b_parallel_poll_configure,793.parallel_poll_response = agilent_82350b_parallel_poll_response,794.local_parallel_poll_mode = NULL, /* XXX */795.line_status = agilent_82350b_line_status,796.update_status = agilent_82350b_update_status,797.primary_address = agilent_82350b_primary_address,798.secondary_address = agilent_82350b_secondary_address,799.serial_poll_response = agilent_82350b_serial_poll_response,800.serial_poll_status = agilent_82350b_serial_poll_status,801.t1_delay = agilent_82350b_t1_delay,802.return_to_local = agilent_82350b_return_to_local,803};804805static struct gpib_interface agilent_82350b_interface = {806.name = "agilent_82350b",807.attach = agilent_82350b_accel_attach,808.detach = agilent_82350b_detach,809.read = agilent_82350b_accel_read,810.write = agilent_82350b_accel_write,811.command = agilent_82350b_command,812.request_system_control = agilent_82350b_request_system_control,813.take_control = agilent_82350b_take_control,814.go_to_standby = agilent_82350b_go_to_standby,815.interface_clear = agilent_82350b_interface_clear,816.remote_enable = agilent_82350b_remote_enable,817.enable_eos = agilent_82350b_enable_eos,818.disable_eos = agilent_82350b_disable_eos,819.parallel_poll = agilent_82350b_parallel_poll,820.parallel_poll_configure = agilent_82350b_parallel_poll_configure,821.parallel_poll_response = agilent_82350b_parallel_poll_response,822.local_parallel_poll_mode = NULL, /* XXX */823.line_status = agilent_82350b_line_status,824.update_status = agilent_82350b_update_status,825.primary_address = agilent_82350b_primary_address,826.secondary_address = agilent_82350b_secondary_address,827.serial_poll_response = agilent_82350b_serial_poll_response,828.serial_poll_status = agilent_82350b_serial_poll_status,829.t1_delay = agilent_82350b_t1_delay,830.return_to_local = agilent_82350b_return_to_local,831};832833static int agilent_82350b_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)834835{836return 0;837}838839static const struct pci_device_id agilent_82350b_pci_table[] = {840{ PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_VENDOR_ID_HP,841PCI_SUBDEVICE_ID_82350A, 0, 0, 0 },842{ PCI_VENDOR_ID_AGILENT, PCI_DEVICE_ID_82350B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },843{ PCI_VENDOR_ID_AGILENT, PCI_DEVICE_ID_82351A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },844{ 0 }845};846MODULE_DEVICE_TABLE(pci, agilent_82350b_pci_table);847848static struct pci_driver agilent_82350b_pci_driver = {849.name = DRV_NAME,850.id_table = agilent_82350b_pci_table,851.probe = &agilent_82350b_pci_probe852};853854static int __init agilent_82350b_init_module(void)855{856int result;857858result = pci_register_driver(&agilent_82350b_pci_driver);859if (result) {860pr_err("pci_register_driver failed: error = %d\n", result);861return result;862}863864result = gpib_register_driver(&agilent_82350b_unaccel_interface, THIS_MODULE);865if (result) {866pr_err("gpib_register_driver failed: error = %d\n", result);867goto err_unaccel;868}869870result = gpib_register_driver(&agilent_82350b_interface, THIS_MODULE);871if (result) {872pr_err("gpib_register_driver failed: error = %d\n", result);873goto err_interface;874}875876return 0;877878err_interface:879gpib_unregister_driver(&agilent_82350b_unaccel_interface);880err_unaccel:881pci_unregister_driver(&agilent_82350b_pci_driver);882883return result;884}885886static void __exit agilent_82350b_exit_module(void)887{888gpib_unregister_driver(&agilent_82350b_interface);889gpib_unregister_driver(&agilent_82350b_unaccel_interface);890891pci_unregister_driver(&agilent_82350b_pci_driver);892}893894module_init(agilent_82350b_init_module);895module_exit(agilent_82350b_exit_module);896897898