Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 363700
b: refs/heads/master
c: bc3fc44
h: refs/heads/master
v: v3
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Mar 25, 2013
1 parent e15205a commit b5beddf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 88 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dd2aef646c9cfcc2647cae52a5097ce70f1e13c3
refs/heads/master: bc3fc446800aff41abf3af82f673590b6b39c642
168 changes: 81 additions & 87 deletions trunk/drivers/staging/comedi/drivers/ni_labpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@ static void labpc_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd,
#ifdef CONFIG_ISA_DMA_API
static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd);
#endif
static unsigned int labpc_eeprom_read_status(struct comedi_device *dev);
static int labpc_eeprom_write(struct comedi_device *dev,
unsigned int address,
unsigned int value);
static void write_caldac(struct comedi_device *dev, unsigned int channel,
unsigned int value);

/* analog input ranges */
#define NUM_LABPC_PLUS_AI_RANGES 16
Expand Down Expand Up @@ -1370,59 +1364,6 @@ static int labpc_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
return 1;
}

static int labpc_calib_read_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct labpc_private *devpriv = dev->private;

data[0] = devpriv->caldac[CR_CHAN(insn->chanspec)];

return 1;
}

static int labpc_calib_write_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
int channel = CR_CHAN(insn->chanspec);

write_caldac(dev, channel, data[0]);
return 1;
}

static int labpc_eeprom_read_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct labpc_private *devpriv = dev->private;

data[0] = devpriv->eeprom_data[CR_CHAN(insn->chanspec)];

return 1;
}

static int labpc_eeprom_write_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
int channel = CR_CHAN(insn->chanspec);
int ret;

/* only allow writes to user area of eeprom */
if (channel < 16 || channel > 127) {
dev_dbg(dev->class_dev,
"eeprom writes are only allowed to channels 16 through 127 (the pointer and user areas)\n");
return -EINVAL;
}

ret = labpc_eeprom_write(dev, channel, data[0]);
if (ret < 0)
return ret;

return 1;
}

#ifdef CONFIG_ISA_DMA_API
/* utility function that suggests a dma transfer size in bytes */
static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd)
Expand Down Expand Up @@ -1645,6 +1586,34 @@ static unsigned int labpc_eeprom_read(struct comedi_device *dev,
return value;
}

static unsigned int labpc_eeprom_read_status(struct comedi_device *dev)
{
struct labpc_private *devpriv = dev->private;
unsigned int value;
const int read_status_instruction = 0x5;
const int write_length = 8; /* 8 bit write lengths to eeprom */

/* enable read/write to eeprom */
devpriv->command5_bits &= ~EEPROM_EN_BIT;
udelay(1);
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
devpriv->command5_bits |= EEPROM_EN_BIT | EEPROM_WRITE_UNPROTECT_BIT;
udelay(1);
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);

/* send read status instruction */
labpc_serial_out(dev, read_status_instruction, write_length);
/* read result */
value = labpc_serial_in(dev);

/* disable read/write to eeprom */
devpriv->command5_bits &= ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT;
udelay(1);
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);

return value;
}

static int labpc_eeprom_write(struct comedi_device *dev,
unsigned int address, unsigned int value)
{
Expand Down Expand Up @@ -1704,34 +1673,6 @@ static int labpc_eeprom_write(struct comedi_device *dev,
return 0;
}

static unsigned int labpc_eeprom_read_status(struct comedi_device *dev)
{
struct labpc_private *devpriv = dev->private;
unsigned int value;
const int read_status_instruction = 0x5;
const int write_length = 8; /* 8 bit write lengths to eeprom */

/* enable read/write to eeprom */
devpriv->command5_bits &= ~EEPROM_EN_BIT;
udelay(1);
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
devpriv->command5_bits |= EEPROM_EN_BIT | EEPROM_WRITE_UNPROTECT_BIT;
udelay(1);
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);

/* send read status instruction */
labpc_serial_out(dev, read_status_instruction, write_length);
/* read result */
value = labpc_serial_in(dev);

/* disable read/write to eeprom */
devpriv->command5_bits &= ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT;
udelay(1);
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);

return value;
}

/* writes to 8 bit calibration dacs */
static void write_caldac(struct comedi_device *dev, unsigned int channel,
unsigned int value)
Expand Down Expand Up @@ -1762,6 +1703,59 @@ static void write_caldac(struct comedi_device *dev, unsigned int channel,
devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
}

static int labpc_calib_write_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
int channel = CR_CHAN(insn->chanspec);

write_caldac(dev, channel, data[0]);
return 1;
}

static int labpc_calib_read_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct labpc_private *devpriv = dev->private;

data[0] = devpriv->caldac[CR_CHAN(insn->chanspec)];

return 1;
}

static int labpc_eeprom_write_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
int channel = CR_CHAN(insn->chanspec);
int ret;

/* only allow writes to user area of eeprom */
if (channel < 16 || channel > 127) {
dev_dbg(dev->class_dev,
"eeprom writes are only allowed to channels 16 through 127 (the pointer and user areas)\n");
return -EINVAL;
}

ret = labpc_eeprom_write(dev, channel, data[0]);
if (ret < 0)
return ret;

return 1;
}

static int labpc_eeprom_read_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct labpc_private *devpriv = dev->private;

data[0] = devpriv->eeprom_data[CR_CHAN(insn->chanspec)];

return 1;
}

int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
unsigned int irq, unsigned int dma_chan)
{
Expand Down

0 comments on commit b5beddf

Please sign in to comment.