From 2c7e581371efa5b195cef3ec15909f56c93b6896 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 24 Oct 2012 16:34:21 -0700 Subject: [PATCH] --- yaml --- r: 337267 b: refs/heads/master c: 809ec5bcc16e42890ec33994baaa58418f4d6859 h: refs/heads/master i: 337265: 1d00e9b1fcaf11f268040ffe18325cc9f91f31e1 337263: 43986769e9ccd25909074736fddac700ab00fd02 v: v3 --- [refs] | 2 +- .../staging/comedi/drivers/cb_pcidda.c | 112 ++++-------------- 2 files changed, 26 insertions(+), 88 deletions(-) diff --git a/[refs] b/[refs] index 40a729764c65..6a44d84f96e5 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 2e54209e0f9bbe9fb38869ff582a04cc86915975 +refs/heads/master: 809ec5bcc16e42890ec33994baaa58418f4d6859 diff --git a/trunk/drivers/staging/comedi/drivers/cb_pcidda.c b/trunk/drivers/staging/comedi/drivers/cb_pcidda.c index 0ad576b8f955..eb03032ccfea 100644 --- a/trunk/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/trunk/drivers/staging/comedi/drivers/cb_pcidda.c @@ -99,6 +99,12 @@ #define CB_DDA_DA_DATA_REG(x) (0x08 + ((x) * 2)) +/* Offsets for the caldac channels */ +#define CB_DDA_CALDAC_FINE_GAIN 0 +#define CB_DDA_CALDAC_COURSE_GAIN 1 +#define CB_DDA_CALDAC_COURSE_OFFSET 2 +#define CB_DDA_CALDAC_FINE_OFFSET 3 + static const struct comedi_lrange cb_pcidda_ranges = { 6, { BIP_RANGE(10), @@ -260,101 +266,33 @@ static void cb_pcidda_write_caldac(struct comedi_device *dev, outw_p(cal2_bits, dev->iobase + DACALIBRATION2); } -/* returns caldac that calibrates given analog out channel */ -static unsigned int caldac_number(unsigned int channel) -{ - return channel / 2; -} - -/* returns caldac channel that provides fine gain for given ao channel */ -static unsigned int fine_gain_channel(unsigned int ao_channel) -{ - return 4 * (ao_channel % 2); -} - -/* returns caldac channel that provides coarse gain for given ao channel */ -static unsigned int coarse_gain_channel(unsigned int ao_channel) -{ - return 1 + 4 * (ao_channel % 2); -} - -/* returns caldac channel that provides coarse offset for given ao channel */ -static unsigned int coarse_offset_channel(unsigned int ao_channel) -{ - return 2 + 4 * (ao_channel % 2); -} - -/* returns caldac channel that provides fine offset for given ao channel */ -static unsigned int fine_offset_channel(unsigned int ao_channel) -{ - return 3 + 4 * (ao_channel % 2); -} - -/* returns eeprom address that provides offset for given ao channel and range */ -static unsigned int offset_eeprom_address(unsigned int ao_channel, - unsigned int range) -{ - return 0x7 + 2 * range + 12 * ao_channel; -} - -/* - * returns eeprom address that provides gain calibration for given ao - * channel and range - */ -static unsigned int gain_eeprom_address(unsigned int ao_channel, - unsigned int range) -{ - return 0x8 + 2 * range + 12 * ao_channel; -} - -/* - * returns upper byte of eeprom entry, which gives the coarse adjustment - * values - */ -static unsigned int eeprom_coarse_byte(unsigned int word) -{ - return (word >> 8) & 0xff; -} - -/* returns lower byte of eeprom entry, which gives the fine adjustment values */ -static unsigned int eeprom_fine_byte(unsigned int word) -{ - return word & 0xff; -} - /* set caldacs to eeprom values for given channel and range */ static void cb_pcidda_calibrate(struct comedi_device *dev, unsigned int channel, unsigned int range) { struct cb_pcidda_private *devpriv = dev->private; - unsigned int coarse_offset, fine_offset, coarse_gain, fine_gain; + unsigned int caldac = channel / 2; /* two caldacs per channel */ + unsigned int chan = 4 * (channel % 2); /* caldac channel base */ + unsigned int index = 2 * range + 12 * channel; + unsigned int offset; + unsigned int gain; - /* remember range so we can tell when we need to readjust calibration */ + /* save range so we can tell when we need to readjust calibration */ devpriv->ao_range[channel] = range; - /* get values from eeprom data */ - coarse_offset = - eeprom_coarse_byte(devpriv->eeprom_data - [offset_eeprom_address(channel, range)]); - fine_offset = - eeprom_fine_byte(devpriv->eeprom_data - [offset_eeprom_address(channel, range)]); - coarse_gain = - eeprom_coarse_byte(devpriv->eeprom_data - [gain_eeprom_address(channel, range)]); - fine_gain = - eeprom_fine_byte(devpriv->eeprom_data - [gain_eeprom_address(channel, range)]); - - /* set caldacs */ - cb_pcidda_write_caldac(dev, caldac_number(channel), - coarse_offset_channel(channel), coarse_offset); - cb_pcidda_write_caldac(dev, caldac_number(channel), - fine_offset_channel(channel), fine_offset); - cb_pcidda_write_caldac(dev, caldac_number(channel), - coarse_gain_channel(channel), coarse_gain); - cb_pcidda_write_caldac(dev, caldac_number(channel), - fine_gain_channel(channel), fine_gain); + /* get values from eeprom data */ + offset = devpriv->eeprom_data[0x7 + index]; + gain = devpriv->eeprom_data[0x8 + index]; + + /* set caldacs */ + cb_pcidda_write_caldac(dev, caldac, chan + CB_DDA_CALDAC_COURSE_OFFSET, + (offset >> 8) & 0xff); + cb_pcidda_write_caldac(dev, caldac, chan + CB_DDA_CALDAC_FINE_OFFSET, + offset & 0xff); + cb_pcidda_write_caldac(dev, caldac, chan + CB_DDA_CALDAC_COURSE_GAIN, + (gain >> 8) & 0xff); + cb_pcidda_write_caldac(dev, caldac, chan + CB_DDA_CALDAC_FINE_GAIN, + gain & 0xff); } static int cb_pcidda_ao_insn_write(struct comedi_device *dev,