Path: blob/master/drivers/gpib/agilent_82350b/agilent_82350b.c
54674 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;600601retval = agilent_82350b_allocate_private(board);602if (retval)603return retval;604a_priv = board->private_data;605a_priv->using_fifos = use_fifos;606tms_priv = &a_priv->tms9914_priv;607tms_priv->read_byte = tms9914_iomem_read_byte;608tms_priv->write_byte = tms9914_iomem_write_byte;609tms_priv->offset = 1;610611/* find board */612a_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_AGILENT,613PCI_DEVICE_ID_82350B, NULL);614if (a_priv->pci_device) {615a_priv->model = MODEL_82350B;616dev_dbg(board->gpib_dev, "Agilent 82350B board found\n");617618} else {619a_priv->pci_device = gpib_pci_get_device(config, PCI_VENDOR_ID_AGILENT,620PCI_DEVICE_ID_82351A, NULL);621if (a_priv->pci_device) {622a_priv->model = MODEL_82351A;623dev_dbg(board->gpib_dev, "Agilent 82351B board found\n");624625} else {626a_priv->pci_device = gpib_pci_get_subsys(config, PCI_VENDOR_ID_PLX,627PCI_DEVICE_ID_PLX_9050,628PCI_VENDOR_ID_HP,629PCI_SUBDEVICE_ID_82350A,630a_priv->pci_device);631if (a_priv->pci_device) {632a_priv->model = MODEL_82350A;633dev_dbg(board->gpib_dev, "HP/Agilent 82350A board found\n");634} else {635dev_err(board->gpib_dev, "no 82350/82351 board found\n");636return -ENODEV;637}638}639}640if (pci_enable_device(a_priv->pci_device)) {641dev_err(board->gpib_dev, "error enabling pci device\n");642return -EIO;643}644if (pci_request_regions(a_priv->pci_device, DRV_NAME))645return -ENOMEM;646switch (a_priv->model) {647case MODEL_82350A:648a_priv->plx_base = ioremap(pci_resource_start(a_priv->pci_device, PLX_MEM_REGION),649pci_resource_len(a_priv->pci_device, PLX_MEM_REGION));650dev_dbg(board->gpib_dev, "plx base address remapped to 0x%p\n", a_priv->plx_base);651a_priv->gpib_base = ioremap(pci_resource_start(a_priv->pci_device,652GPIB_82350A_REGION),653pci_resource_len(a_priv->pci_device,654GPIB_82350A_REGION));655dev_dbg(board->gpib_dev, "chip base address remapped to 0x%p\n", a_priv->gpib_base);656tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;657a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device,658SRAM_82350A_REGION),659pci_resource_len(a_priv->pci_device,660SRAM_82350A_REGION));661dev_dbg(board->gpib_dev, "sram base address remapped to 0x%p\n", a_priv->sram_base);662a_priv->borg_base = ioremap(pci_resource_start(a_priv->pci_device,663BORG_82350A_REGION),664pci_resource_len(a_priv->pci_device,665BORG_82350A_REGION));666dev_dbg(board->gpib_dev, "borg base address remapped to 0x%p\n", a_priv->borg_base);667668retval = init_82350a_hardware(board, config);669if (retval < 0)670return retval;671break;672case MODEL_82350B:673case MODEL_82351A:674a_priv->gpib_base = ioremap(pci_resource_start(a_priv->pci_device, GPIB_REGION),675pci_resource_len(a_priv->pci_device, GPIB_REGION));676dev_dbg(board->gpib_dev, "chip base address remapped to 0x%p\n", a_priv->gpib_base);677tms_priv->mmiobase = a_priv->gpib_base + TMS9914_BASE_REG;678a_priv->sram_base = ioremap(pci_resource_start(a_priv->pci_device, SRAM_REGION),679pci_resource_len(a_priv->pci_device, SRAM_REGION));680dev_dbg(board->gpib_dev, "sram base address remapped to 0x%p\n", a_priv->sram_base);681a_priv->misc_base = ioremap(pci_resource_start(a_priv->pci_device, MISC_REGION),682pci_resource_len(a_priv->pci_device, MISC_REGION));683dev_dbg(board->gpib_dev, "misc base address remapped to 0x%p\n", a_priv->misc_base);684break;685default:686dev_err(board->gpib_dev, "invalid board\n");687return -ENODEV;688}689690retval = test_sram(board);691if (retval < 0)692return retval;693694if (request_irq(a_priv->pci_device->irq, agilent_82350b_interrupt,695IRQF_SHARED, DRV_NAME, board)) {696dev_err(board->gpib_dev, "failed to obtain irq %d\n", a_priv->pci_device->irq);697return -EIO;698}699a_priv->irq = a_priv->pci_device->irq;700dev_dbg(board->gpib_dev, " IRQ %d\n", a_priv->irq);701702writeb(0, a_priv->gpib_base + SRAM_ACCESS_CONTROL_REG);703a_priv->card_mode_bits = ENABLE_PCI_IRQ_BIT;704writeb(a_priv->card_mode_bits, a_priv->gpib_base + CARD_MODE_REG);705706if (a_priv->model == MODEL_82350A) {707/* enable PCI interrupts for 82350a */708writel(PLX9050_LINTR1_EN_BIT | PLX9050_LINTR2_POLARITY_BIT |709PLX9050_PCI_INTR_EN_BIT,710a_priv->plx_base + PLX9050_INTCSR_REG);711}712713if (use_fifos) {714writeb(ENABLE_BUFFER_END_EVENTS_BIT | ENABLE_TERM_COUNT_EVENTS_BIT,715a_priv->gpib_base + EVENT_ENABLE_REG);716writeb(ENABLE_TERM_COUNT_INTERRUPT_BIT | ENABLE_BUFFER_END_INTERRUPT_BIT |717ENABLE_TMS9914_INTERRUPTS_BIT, a_priv->gpib_base + INTERRUPT_ENABLE_REG);718/* write-clear event status bits */719writeb(BUFFER_END_STATUS_BIT | TERM_COUNT_STATUS_BIT,720a_priv->gpib_base + EVENT_STATUS_REG);721} else {722writeb(0, a_priv->gpib_base + EVENT_ENABLE_REG);723writeb(ENABLE_TMS9914_INTERRUPTS_BIT,724a_priv->gpib_base + INTERRUPT_ENABLE_REG);725}726board->t1_nano_sec = agilent_82350b_t1_delay(board, 2000);727tms9914_board_reset(tms_priv);728729tms9914_online(board, tms_priv);730731return 0;732}733734static int agilent_82350b_unaccel_attach(struct gpib_board *board,735const struct gpib_board_config *config)736{737return agilent_82350b_generic_attach(board, config, 0);738}739740static int agilent_82350b_accel_attach(struct gpib_board *board,741const struct gpib_board_config *config)742{743return agilent_82350b_generic_attach(board, config, 1);744}745746static void agilent_82350b_detach(struct gpib_board *board)747{748struct agilent_82350b_priv *a_priv = board->private_data;749struct tms9914_priv *tms_priv;750751if (a_priv) {752if (a_priv->plx_base) /* disable interrupts */753writel(0, a_priv->plx_base + PLX9050_INTCSR_REG);754755tms_priv = &a_priv->tms9914_priv;756if (a_priv->irq)757free_irq(a_priv->irq, board);758if (a_priv->gpib_base) {759tms9914_board_reset(tms_priv);760if (a_priv->misc_base)761iounmap(a_priv->misc_base);762if (a_priv->borg_base)763iounmap(a_priv->borg_base);764if (a_priv->sram_base)765iounmap(a_priv->sram_base);766if (a_priv->gpib_base)767iounmap(a_priv->gpib_base);768if (a_priv->plx_base)769iounmap(a_priv->plx_base);770pci_release_regions(a_priv->pci_device);771}772if (a_priv->pci_device)773pci_dev_put(a_priv->pci_device);774}775agilent_82350b_free_private(board);776}777778static struct gpib_interface agilent_82350b_unaccel_interface = {779.name = "agilent_82350b_unaccel",780.attach = agilent_82350b_unaccel_attach,781.detach = agilent_82350b_detach,782.read = agilent_82350b_read,783.write = agilent_82350b_write,784.command = agilent_82350b_command,785.request_system_control = agilent_82350b_request_system_control,786.take_control = agilent_82350b_take_control,787.go_to_standby = agilent_82350b_go_to_standby,788.interface_clear = agilent_82350b_interface_clear,789.remote_enable = agilent_82350b_remote_enable,790.enable_eos = agilent_82350b_enable_eos,791.disable_eos = agilent_82350b_disable_eos,792.parallel_poll = agilent_82350b_parallel_poll,793.parallel_poll_configure = agilent_82350b_parallel_poll_configure,794.parallel_poll_response = agilent_82350b_parallel_poll_response,795.local_parallel_poll_mode = NULL, /* XXX */796.line_status = agilent_82350b_line_status,797.update_status = agilent_82350b_update_status,798.primary_address = agilent_82350b_primary_address,799.secondary_address = agilent_82350b_secondary_address,800.serial_poll_response = agilent_82350b_serial_poll_response,801.serial_poll_status = agilent_82350b_serial_poll_status,802.t1_delay = agilent_82350b_t1_delay,803.return_to_local = agilent_82350b_return_to_local,804};805806static struct gpib_interface agilent_82350b_interface = {807.name = "agilent_82350b",808.attach = agilent_82350b_accel_attach,809.detach = agilent_82350b_detach,810.read = agilent_82350b_accel_read,811.write = agilent_82350b_accel_write,812.command = agilent_82350b_command,813.request_system_control = agilent_82350b_request_system_control,814.take_control = agilent_82350b_take_control,815.go_to_standby = agilent_82350b_go_to_standby,816.interface_clear = agilent_82350b_interface_clear,817.remote_enable = agilent_82350b_remote_enable,818.enable_eos = agilent_82350b_enable_eos,819.disable_eos = agilent_82350b_disable_eos,820.parallel_poll = agilent_82350b_parallel_poll,821.parallel_poll_configure = agilent_82350b_parallel_poll_configure,822.parallel_poll_response = agilent_82350b_parallel_poll_response,823.local_parallel_poll_mode = NULL, /* XXX */824.line_status = agilent_82350b_line_status,825.update_status = agilent_82350b_update_status,826.primary_address = agilent_82350b_primary_address,827.secondary_address = agilent_82350b_secondary_address,828.serial_poll_response = agilent_82350b_serial_poll_response,829.serial_poll_status = agilent_82350b_serial_poll_status,830.t1_delay = agilent_82350b_t1_delay,831.return_to_local = agilent_82350b_return_to_local,832};833834static int agilent_82350b_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)835836{837return 0;838}839840static const struct pci_device_id agilent_82350b_pci_table[] = {841{ PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_VENDOR_ID_HP,842PCI_SUBDEVICE_ID_82350A, 0, 0, 0 },843{ PCI_VENDOR_ID_AGILENT, PCI_DEVICE_ID_82350B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },844{ PCI_VENDOR_ID_AGILENT, PCI_DEVICE_ID_82351A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },845{ 0 }846};847MODULE_DEVICE_TABLE(pci, agilent_82350b_pci_table);848849static struct pci_driver agilent_82350b_pci_driver = {850.name = DRV_NAME,851.id_table = agilent_82350b_pci_table,852.probe = &agilent_82350b_pci_probe853};854855static int __init agilent_82350b_init_module(void)856{857int result;858859result = pci_register_driver(&agilent_82350b_pci_driver);860if (result) {861pr_err("pci_register_driver failed: error = %d\n", result);862return result;863}864865result = gpib_register_driver(&agilent_82350b_unaccel_interface, THIS_MODULE);866if (result) {867pr_err("gpib_register_driver failed: error = %d\n", result);868goto err_unaccel;869}870871result = gpib_register_driver(&agilent_82350b_interface, THIS_MODULE);872if (result) {873pr_err("gpib_register_driver failed: error = %d\n", result);874goto err_interface;875}876877return 0;878879err_interface:880gpib_unregister_driver(&agilent_82350b_unaccel_interface);881err_unaccel:882pci_unregister_driver(&agilent_82350b_pci_driver);883884return result;885}886887static void __exit agilent_82350b_exit_module(void)888{889gpib_unregister_driver(&agilent_82350b_interface);890gpib_unregister_driver(&agilent_82350b_unaccel_interface);891892pci_unregister_driver(&agilent_82350b_pci_driver);893}894895module_init(agilent_82350b_init_module);896module_exit(agilent_82350b_exit_module);897898899