<commit_before>/*
    comedi/drivers/ni_at_ao.c
    Driver for NI AT-AO-6/10 boards

    COMEDI - Linux Control and Measurement Device Interface
    Copyright (C) 2000,2002 <NAME> <<EMAIL>>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
*/
/*
Driver: ni_at_ao
Description: National Instruments AT-AO-6/10
Devices: [National Instruments] AT-AO-6 (at-ao-6), AT-AO-10 (at-ao-10)
Status: should work
Author: ds
Updated: Sun Dec 26 12:26:28 EST 2004

Configuration options:
  [0] - I/O port base address
  [1] - IRQ (unused)
  [2] - DMA (unused)
  [3] - analog output range, set by jumpers on hardware (0 for -10 to 10V
	bipolar, 1 for 0V to 10V unipolar)

*/
/*
 * Register-level programming information can be found in NI
 * document 320379.pdf.
 */

#include <linux/module.h>

#include "../comedidev.h"

#include "8253.h"

/*
 * Register map
 */
#define ATAO_DIO_REG		0x00
#define ATAO_CFG2_REG		0x02
#define ATAO_CFG2_CALLD_NOP	(0 << 14)
#define ATAO_CFG2_CALLD(x)	((((x) >> 3) + 1) << 14)
#define ATAO_CFG2_FFRTEN	(1 << 13)
#define ATAO_CFG2_DACS(x)	(1 << (((x) / 2) + 8))
#define ATAO_CFG2_LDAC(x)	(1 << (((x) / 2) + 3))
#define ATAO_CFG2_PROMEN	(1 << 2)
#define ATAO_CFG2_SCLK		(1 << 1)
#define ATAO_CFG2_SDATA		(1 << 0)
#define ATAO_CFG3_REG		0x04
#define ATAO_CFG3_DMAMODE	(1 << 6)
#define ATAO_CFG3_CLKOUT	(1 << 5)
#define ATAO_CFG3_RCLKEN	(1 << 4)
#define ATAO_CFG3_DOUTEN2	(1 << 3)
#define ATAO_CFG3_DOUTEN1	(1 << 2)
#define ATAO_CFG3_EN2_5V	(1 << 1)
#define ATAO_CFG3_SCANEN	(1 << 0)
#define ATAO_82C53_BASE		0x06
#define ATAO_CFG1_REG		0x0a
#define ATAO_CFG1_EXTINT2EN	(1 << 15)
#define ATAO_CFG1_EXTINT1EN	(1 << 14)
#define ATAO_CFG1_CNTINT2EN	(1 << 13)
#define ATAO_CFG1_CNTINT1EN	(1 << 12)
#define ATAO_CFG1_TCINTEN	(1 << 11)
#define ATAO_CFG1_CNT1SRC	(1 << 10)
#define ATAO_CFG1_CNT2SRC	(1 << 9)
#define ATAO_CFG1_FIFOEN	(1 << 8)
#define ATAO_CFG1_GRP2WR	(1 << 7)
#define ATAO_CFG1_EXTUPDEN	(1 << 6)
#define ATAO_CFG1_DMARQ		(1 << 5)
#define ATAO_CFG1_DMAEN		(1 << 4)
#define ATAO_CFG1_CH(x)		(((x) & 0xf) << 0)
#define ATAO_STATUS_REG		0x0a
#define ATAO_STATUS_FH		(1 << 6)
#define ATAO_STATUS_FE		(1 << 5)
#define ATAO_STATUS_FF		(1 << 4)
#define ATAO_STATUS_INT2	(1 << 3)
#define ATAO_STATUS_INT1	(1 << 2)
#define ATAO_STATUS_TCINT	(1 << 1)
#define ATAO_STATUS_PROMOUT	(1 << 0)
#define ATAO_FIFO_WRITE		0x0c	/* W 16 */
#define ATAO_FIFO_CLEAR		0x0c	/* R 16 */
#define ATAO_DACn(x)		(0x0c + ((x) * 2))	/* W */

/* registers with _2_ are accessed when GRP2WR is set in CFG1 */

#define ATAO_2_DMATCCLR		0x00	/* W 16 */
#define ATAO_2_INT1CLR		0x02	/* W 16 */
#define ATAO_2_INT2CLR		0x04	/* W 16 */
#define ATAO_2_RTSISHFT		0x06	/* W 8 */
#define ATAO_RTSISHFT_RSI	(1 << 0)
#define ATAO_2_RTSISTRB		0x07	/* W 8 */

/*
 * Board descriptions for two imaginary boards.  Describing the
 * boards in this way is optional, and completely driver-dependent.
 * Some drivers use arrays such as this, other do not.
 */
struct atao_board {
	const char *name;
	int n_ao_chans;
};

struct atao_private {
	unsigned short cfg1;
	unsigned short cfg3;

	/* Used for AO readback */
	unsigned int ao_readback[10];

	/* Used for caldac readback */
	unsigned char caldac[21];
};

static void atao_reset(struct comedi_device *dev)
{
	struct atao_private *devpriv = dev->private;

	/* This is the reset sequence described in the manual */

	devpriv->cfg1 = 0;
	outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);

	/* Put outputs of counter 1 and counter 2 in a high state */
	i8254_load(dev->iobase + ATAO_82C53_BASE, 0,
		   0, 0x0003, I8254_MODE4 | I8254_BINARY);
	i8254_set_mode(dev->iobase + ATAO_82C53_BASE, 0,
		   1, I8254_MODE4 | I8254_BINARY);

	outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);

	devpriv->cfg3 = 0;
	outw(devpriv->cfg3, dev->iobase + ATAO_CFG3_REG);

	inw(dev->iobase + ATAO_FIFO_CLEAR);

	devpriv->cfg1 |= ATAO_CFG1_GRP2WR;
	outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);

	outw(0, dev->iobase + ATAO_2_INT1CLR);
	outw(0, dev->iobase + ATAO_2_INT2CLR);
	outw(0, dev->iobase + ATAO_2_DMATCCLR);

	devpriv->cfg1 &= ~ATAO_CFG1_GRP2WR;
	outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
}

static int atao_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
			 struct comedi_insn *insn, unsigned int *data)
{
	struct atao_private *devpriv = dev->private;
	int i;
	int chan = CR_CHAN(insn->chanspec);
	short bits;

	for (i = 0; i < insn->n; i++) {
		bits = data[i] - 0x800;
		if (chan == 0) {
			devpriv->cfg1 |= ATAO_CFG1_GRP2WR;
			outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
		}
		outw(bits, dev->iobase + ATAO_DACn(chan));
		if (chan == 0) {
			devpriv->cfg1 &= ~ATAO_CFG1_GRP2WR;
			outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
		}
		devpriv->ao_readback[chan] = data[i];
	}

	return i;
}

static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
			 struct comedi_insn *insn, unsigned int *data)
{
	struct atao_private *devpriv = dev->private;
	int i;
	int chan = CR_CHAN(insn->chanspec);

	for (i = 0; i < insn->n; i++)
		data[i] = devpriv->ao_readback[chan];

	return i;
}

static int atao_dio_insn_bits(struct comedi_device *dev,
			      struct comedi_subdevice *s,
			      struct comedi_insn *insn,
			      unsigned int *data)
{<commit_msg>staging: comedi: ni_at_ao: rename the rest of the register map<commit_after>/*
    comedi/drivers/ni_at_ao.c
    Driver for NI AT-AO-6/10 boards

    COMEDI - Linux Control and Measurement Device Interface
    Copyright (C) 2000,2002 <NAME> <<EMAIL>>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
*/
/*
Driver: ni_at_ao
Description: National Instruments AT-AO-6/10
Devices: [National Instruments] AT-AO-6 (at-ao-6), AT-AO-10 (at-ao-10)
Status: should work
Author: ds
Updated: Sun Dec 26 12:26:28 EST 2004

Configuration options:
  [0] - I/O port base address
  [1] - IRQ (unused)
  [2] - DMA (unused)
  [3] - analog output range, set by jumpers on hardware (0 for -10 to 10V
	bipolar, 1 for 0V to 10V unipolar)

*/
/*
 * Register-level programming information can be found in NI
 * document 320379.pdf.
 */

#include <linux/module.h>

#include "../comedidev.h"

#include "8253.h"

/*
 * Register map
 */
#define ATAO_DIO_REG		0x00
#define ATAO_CFG2_REG		0x02
#define ATAO_CFG2_CALLD_NOP	(0 << 14)
#define ATAO_CFG2_CALLD(x)	((((x) >> 3) + 1) << 14)
#define ATAO_CFG2_FFRTEN	(1 << 13)
#define ATAO_CFG2_DACS(x)	(1 << (((x) / 2) + 8))
#define ATAO_CFG2_LDAC(x)	(1 << (((x) / 2) + 3))
#define ATAO_CFG2_PROMEN	(1 << 2)
#define ATAO_CFG2_SCLK		(1 << 1)
#define ATAO_CFG2_SDATA		(1 << 0)
#define ATAO_CFG3_REG		0x04
#define ATAO_CFG3_DMAMODE	(1 << 6)
#define ATAO_CFG3_CLKOUT	(1 << 5)
#define ATAO_CFG3_RCLKEN	(1 << 4)
#define ATAO_CFG3_DOUTEN2	(1 << 3)
#define ATAO_CFG3_DOUTEN1	(1 << 2)
#define ATAO_CFG3_EN2_5V	(1 << 1)
#define ATAO_CFG3_SCANEN	(1 << 0)
#define ATAO_82C53_BASE		0x06
#define ATAO_CFG1_REG		0x0a
#define ATAO_CFG1_EXTINT2EN	(1 << 15)
#define ATAO_CFG1_EXTINT1EN	(1 << 14)
#define ATAO_CFG1_CNTINT2EN	(1 << 13)
#define ATAO_CFG1_CNTINT1EN	(1 << 12)
#define ATAO_CFG1_TCINTEN	(1 << 11)
#define ATAO_CFG1_CNT1SRC	(1 << 10)
#define ATAO_CFG1_CNT2SRC	(1 << 9)
#define ATAO_CFG1_FIFOEN	(1 << 8)
#define ATAO_CFG1_GRP2WR	(1 << 7)
#define ATAO_CFG1_EXTUPDEN	(1 << 6)
#define ATAO_CFG1_DMARQ		(1 << 5)
#define ATAO_CFG1_DMAEN		(1 << 4)
#define ATAO_CFG1_CH(x)		(((x) & 0xf) << 0)
#define ATAO_STATUS_REG		0x0a
#define ATAO_STATUS_FH		(1 << 6)
#define ATAO_STATUS_FE		(1 << 5)
#define ATAO_STATUS_FF		(1 << 4)
#define ATAO_STATUS_INT2	(1 << 3)
#define ATAO_STATUS_INT1	(1 << 2)
#define ATAO_STATUS_TCINT	(1 << 1)
#define ATAO_STATUS_PROMOUT	(1 << 0)
#define ATAO_FIFO_WRITE_REG	0x0c
#define ATAO_FIFO_CLEAR_REG	0x0c
#define ATAO_AO_REG(x)		(0x0c + ((x) * 2))

/* registers with _2_ are accessed when GRP2WR is set in CFG1 */
#define ATAO_2_DMATCCLR_REG	0x00
#define ATAO_2_INT1CLR_REG	0x02
#define ATAO_2_INT2CLR_REG	0x04
#define ATAO_2_RTSISHFT_REG	0x06
#define ATAO_2_RTSISHFT_RSI	(1 << 0)
#define ATAO_2_RTSISTRB_REG	0x07

/*
 * Board descriptions for two imaginary boards.  Describing the
 * boards in this way is optional, and completely driver-dependent.
 * Some drivers use arrays such as this, other do not.
 */
struct atao_board {
	const char *name;
	int n_ao_chans;
};

struct atao_private {
	unsigned short cfg1;
	unsigned short cfg3;

	/* Used for AO readback */
	unsigned int ao_readback[10];

	/* Used for caldac readback */
	unsigned char caldac[21];
};

static void atao_reset(struct comedi_device *dev)
{
	struct atao_private *devpriv = dev->private;

	/* This is the reset sequence described in the manual */

	devpriv->cfg1 = 0;
	outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);

	/* Put outputs of counter 1 and counter 2 in a high state */
	i8254_load(dev->iobase + ATAO_82C53_BASE, 0,
		   0, 0x0003, I8254_MODE4 | I8254_BINARY);
	i8254_set_mode(dev->iobase + ATAO_82C53_BASE, 0,
		   1, I8254_MODE4 | I8254_BINARY);

	outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);

	devpriv->cfg3 = 0;
	outw(devpriv->cfg3, dev->iobase + ATAO_CFG3_REG);

	inw(dev->iobase + ATAO_FIFO_CLEAR_REG);

	devpriv->cfg1 |= ATAO_CFG1_GRP2WR;
	outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);

	outw(0, dev->iobase + ATAO_2_INT1CLR_REG);
	outw(0, dev->iobase + ATAO_2_INT2CLR_REG);
	outw(0, dev->iobase + ATAO_2_DMATCCLR_REG);

	devpriv->cfg1 &= ~ATAO_CFG1_GRP2WR;
	outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
}

static int atao_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
			 struct comedi_insn *insn, unsigned int *data)
{
	struct atao_private *devpriv = dev->private;
	int i;
	int chan = CR_CHAN(insn->chanspec);
	short bits;

	for (i = 0; i < insn->n; i++) {
		bits = data[i] - 0x800;
		if (chan == 0) {
			devpriv->cfg1 |= ATAO_CFG1_GRP2WR;
			outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
		}
		outw(bits, dev->iobase + ATAO_AO_REG(chan));
		if (chan == 0) {
			devpriv->cfg1 &= ~ATAO_CFG1_GRP2WR;
			outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
		}
		devpriv->ao_readback[chan] = data[i];
	}

	return i;
}

static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
			 struct comedi_insn *insn, unsigned int *data)
{
	struct atao_private *devpriv = dev->private;
	int i;
	int chan = CR_CHAN(insn->chanspec);

	for (i = 0; i < insn->n; i++)
		data[i] = devpriv->ao_readback[chan];

	return i;
}

static int atao_dio_insn_bits(struct comedi_device *dev,
			      struct comedi_subdevice *s,
			      struct comedi_insn *insn,
			      unsigned int *data)
{
{'fraction_non_alphanumeric': 0.12282398452611218, 'fraction_numerical': 0.05969755582908388, 'mean_word_length': 4.154055278658813, 'pattern_counts': {'":': 0, '<': 159, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2966435', 'n_tokens_mistral': 5365, 'n_tokens_neox': 4813, 'n_words': 1260}