65 #include <linux/sched.h>
71 #define MDPRINTK(format, args...)
75 #define NI_TIMEOUT 1000
76 static const unsigned old_RTSI_clock_channel = 7;
79 static const short ni_gainlkup[][16] = {
81 0x100, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107},
82 [
ai_gain_8] = {1, 2, 4, 7, 0x101, 0x102, 0x104, 0x107},
84 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107},
87 0x003, 0x004, 0x005, 0x006},
90 [
ai_gain_6143] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
113 static const struct comedi_lrange range_ni_E_ai_limited = { 8, {
126 static const struct comedi_lrange range_ni_E_ai_limited14 = { 14, {
151 static const struct comedi_lrange range_ni_E_ai_bipolar4 = { 4, {
161 static const struct comedi_lrange range_ni_E_ai_611x = { 8, {
173 static const struct comedi_lrange range_ni_M_ai_622x = { 4, {
181 static const struct comedi_lrange range_ni_M_ai_628x = { 7, {
192 static const struct comedi_lrange range_ni_S_ai_6143 = { 1, {
229 unsigned int trignum);
236 unsigned char data_out,
237 unsigned char *data_in);
240 unsigned char data_out,
241 unsigned char *data_in);
278 #ifdef DEBUG_STATUS_A
281 #define ni_mio_print_status_a(a)
283 #ifdef DEBUG_STATUS_B
286 #define ni_mio_print_status_b(a)
297 unsigned int trignum);
299 unsigned int n_chan,
unsigned int *
list);
303 unsigned int trignum);
307 static int ni_8255_callback(
int dir,
int port,
int data,
unsigned long arg);
324 unsigned short counter_index);
328 unsigned short *
data);
332 #ifdef NI_CS5529_DEBUG
334 unsigned int reg_select_bits);
337 unsigned int reg_select_bits);
348 static void ack_a_interrupt(
struct comedi_device *
dev,
unsigned short a_status);
349 static void ack_b_interrupt(
struct comedi_device *
dev,
unsigned short b_status);
375 static inline unsigned NI_GPCT_SUBDEV(
unsigned counter_index)
377 switch (counter_index) {
396 #define SERIAL_DISABLED 0
397 #define SERIAL_600NS 600
398 #define SERIAL_1_2US 1200
399 #define SERIAL_10US 10000
401 static const int num_adc_stages_611x = 3;
404 unsigned ai_mite_status);
406 unsigned ao_mite_status);
411 unsigned bit_mask,
unsigned bit_values)
418 devpriv->int_a_enable_reg &= ~bit_mask;
419 devpriv->int_a_enable_reg |= bit_values & bit_mask;
424 devpriv->int_b_enable_reg &= ~bit_mask;
425 devpriv->int_b_enable_reg |= bit_values & bit_mask;
430 devpriv->io_bidirection_pin_reg &= ~bit_mask;
431 devpriv->io_bidirection_pin_reg |= bit_values & bit_mask;
436 devpriv->ai_ao_select_reg &= ~bit_mask;
437 devpriv->ai_ao_select_reg |= bit_values & bit_mask;
441 devpriv->g0_g1_select_reg &= ~bit_mask;
442 devpriv->g0_g1_select_reg |= bit_values & bit_mask;
446 printk(
"Warning %s() called with invalid register\n", __func__);
447 printk(
"reg is %d\n", reg);
451 spin_unlock_irqrestore(&
devpriv->soft_reg_copy_lock, flags);
466 (ni_stc_dma_channel_select_bitfield(channel) <<
475 static inline void ni_set_ao_dma_channel(
struct comedi_device *dev,
int channel)
481 (ni_stc_dma_channel_select_bitfield(channel) <<
490 static inline void ni_set_gpct_dma_channel(
struct comedi_device *dev,
496 if (mite_channel >= 0) {
497 bitfield = GPCT_DMA_Select_Bits(gpct_index, mite_channel);
501 ni_set_bitfield(dev,
G0_G1_Select, GPCT_DMA_Select_Mask(gpct_index),
506 static inline void ni_set_cdo_dma_channel(
struct comedi_device *dev,
513 if (mite_channel >= 0) {
517 devpriv->cdio_dma_select_reg |=
518 (ni_stc_dma_channel_select_bitfield(mite_channel) <<
523 spin_unlock_irqrestore(&
devpriv->soft_reg_copy_lock, flags);
526 static int ni_request_ai_mite_channel(
struct comedi_device *dev)
535 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
537 "failed to reserve mite dma channel for analog input.");
541 ni_set_ai_dma_channel(dev,
devpriv->ai_mite_chan->channel);
542 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
546 static int ni_request_ao_mite_channel(
struct comedi_device *dev)
555 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
557 "failed to reserve mite dma channel for analog outut.");
561 ni_set_ao_dma_channel(dev,
devpriv->ao_mite_chan->channel);
562 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
566 static int ni_request_gpct_mite_channel(
struct comedi_device *dev,
571 struct mite_channel *mite_chan;
575 BUG_ON(
devpriv->counter_dev->counters[gpct_index].mite_chan);
577 mite_request_channel(
devpriv->mite,
578 devpriv->gpct_mite_ring[gpct_index]);
579 if (mite_chan ==
NULL) {
580 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
582 "failed to reserve mite dma channel for counter.");
588 ni_set_gpct_dma_channel(dev, gpct_index, mite_chan->
channel);
589 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
595 static int ni_request_cdo_mite_channel(
struct comedi_device *dev)
605 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
607 "failed to reserve mite dma channel for correlated digital outut.");
611 ni_set_cdo_dma_channel(dev,
devpriv->cdo_mite_chan->channel);
612 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
617 static void ni_release_ai_mite_channel(
struct comedi_device *dev)
624 ni_set_ai_dma_channel(dev, -1);
628 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
632 static void ni_release_ao_mite_channel(
struct comedi_device *dev)
639 ni_set_ao_dma_channel(dev, -1);
643 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
648 static void ni_release_gpct_mite_channel(
struct comedi_device *dev,
655 if (
devpriv->counter_dev->counters[gpct_index].mite_chan) {
656 struct mite_channel *mite_chan =
657 devpriv->counter_dev->counters[gpct_index].mite_chan;
659 ni_set_gpct_dma_channel(dev, gpct_index, -1);
661 counter_dev->counters[gpct_index],
665 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
669 static void ni_release_cdo_mite_channel(
struct comedi_device *dev)
676 ni_set_cdo_dma_channel(dev, -1);
680 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
686 static void ni_e_series_enable_second_irq(
struct comedi_device *dev,
687 unsigned gpct_index,
short enable)
691 switch (gpct_index) {
727 ni_writeb(0, M_Offset_Static_AI_Control(0));
728 ni_writeb(1, M_Offset_Static_AI_Control(0));
745 devpriv->stc_writew(dev, data >> 16, reg);
746 devpriv->stc_writew(dev, data & 0xffff, reg + 1);
752 bits =
devpriv->stc_readw(dev, reg) << 16;
753 bits |=
devpriv->stc_readw(dev, reg + 1);
757 #define ao_win_out(data, addr) ni_ao_win_outw(dev, data, addr)
766 spin_unlock_irqrestore(&
devpriv->window_lock, flags);
777 spin_unlock_irqrestore(&
devpriv->window_lock, flags);
788 spin_unlock_irqrestore(&
devpriv->window_lock, flags);
802 static inline void ni_set_bits(
struct comedi_device *dev,
int reg,
803 unsigned bits,
unsigned value)
811 ni_set_bitfield(dev, reg, bits, bit_values);
817 unsigned short a_status;
818 unsigned short b_status;
819 unsigned int ai_mite_status = 0;
820 unsigned int ao_mite_status = 0;
836 unsigned long flags_too;
845 ai_mite_chan->channel));
849 if (ao_mite_status & CHSR_LINKC)
853 ao_mite_chan->channel));
855 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags_too);
858 ack_a_interrupt(dev, a_status);
859 ack_b_interrupt(dev, b_status);
861 handle_a_interrupt(dev, a_status, ai_mite_status);
863 handle_b_interrupt(dev, b_status, ao_mite_status);
864 handle_gpct_interrupt(dev, 0);
865 handle_gpct_interrupt(dev, 1);
866 handle_cdio_interrupt(dev);
868 spin_unlock_irqrestore(&dev->
spinlock, flags);
881 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
884 static void mite_handle_b_linkc(
struct mite_struct *mite,
894 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
897 static int ni_ao_wait_for_dma_load(
struct comedi_device *dev)
899 static const int timeout = 10000;
901 for (i = 0; i < timeout; i++) {
902 unsigned short b_status;
923 static const int timeout = 10;
926 for (i = 0; i < timeout; i++) {
933 ni_handle_fifo_dregs(dev);
939 shutdown_ai_command(dev);
948 ni_ai_drain_dma(dev);
950 ni_handle_fifo_dregs(dev);
951 get_last_sample_611x(dev);
952 get_last_sample_6143(dev);
971 ni_gpct_cancel(dev, s);
974 ni_cdio_cancel(dev, s);
984 unsigned short counter_index)
989 s = &dev->
subdevices[NI_GPCT_SUBDEV(counter_index)];
993 if (s->
async->events)
998 static void ack_a_interrupt(
struct comedi_device *dev,
unsigned short a_status)
1000 unsigned short ack = 0;
1020 unsigned ai_mite_status)
1028 #ifdef DEBUG_INTERRUPT
1030 (
"ni_mio_common: interrupt: a_status=%04x ai_mite_status=%08x\n",
1031 status, ai_mite_status);
1035 if (ai_mite_status & CHSR_LINKC) {
1036 ni_sync_ai_dma(dev);
1043 (
"unknown mite interrupt, ack! (ai_mite_status=%08x)\n",
1053 AI_SC_TC_St | AI_START1_St)) {
1054 if (status == 0xffff) {
1056 (
"ni_mio_common: a_status=0xffff. Card removed?\n");
1068 printk(
"ni_mio_common: ai error a_status=%04x\n",
1072 shutdown_ai_command(dev);
1082 if (status & AI_SC_TC_St) {
1083 #ifdef DEBUG_INTERRUPT
1084 printk(
"ni_mio_common: SC_TC interrupt\n");
1086 if (!
devpriv->ai_continuous) {
1087 shutdown_ai_command(dev);
1094 static const int timeout = 10;
1097 for (i = 0; i < timeout; ++
i) {
1098 ni_handle_fifo_half_full(dev);
1107 if ((status & AI_STOP_St)) {
1108 ni_handle_eos(dev, s);
1113 #ifdef DEBUG_INTERRUPT
1115 if (status & Interrupt_A_St) {
1117 (
"handle_a_interrupt: didn't clear interrupt? status=0x%x\n",
1123 static void ack_b_interrupt(
struct comedi_device *dev,
unsigned short b_status)
1125 unsigned short ack = 0;
1152 unsigned short b_status,
unsigned ao_mite_status)
1156 #ifdef DEBUG_INTERRUPT
1157 printk(
"ni_mio_common: interrupt: b_status=%04x m1_status=%08x\n",
1158 b_status, ao_mite_status);
1164 if (ao_mite_status & CHSR_LINKC) {
1165 mite_handle_b_linkc(
devpriv->mite, dev);
1172 (
"unknown mite interrupt, ack! (ao_mite_status=%08x)\n",
1179 if (b_status == 0xffff)
1181 if (b_status & AO_Overrun_St) {
1183 (
"ni_mio_common: AO FIFO underrun status=0x%04x status2=0x%04x\n",
1188 if (b_status & AO_BC_TC_St) {
1190 (
"ni_mio_common: AO BC_TC status=0x%04x status2=0x%04x\n",
1198 ret = ni_ao_fifo_half_empty(dev, s);
1200 printk(
"ni_mio_common: AO buffer underrun\n");
1212 #ifdef DEBUG_STATUS_A
1213 static const char *
const status_a_strings[] = {
1214 "passthru0",
"fifo",
"G0_gate",
"G0_TC",
1215 "stop",
"start",
"sc_tc",
"start1",
1216 "start2",
"sc_tc_error",
"overflow",
"overrun",
1217 "fifo_empty",
"fifo_half_full",
"fifo_full",
"interrupt_a"
1225 for (i = 15; i >= 0; i--) {
1226 if (status & (1 << i)) {
1227 printk(
" %s", status_a_strings[i]);
1234 #ifdef DEBUG_STATUS_B
1235 static const char *
const status_b_strings[] = {
1236 "passthru1",
"fifo",
"G1_gate",
"G1_TC",
1237 "UI2_TC",
"UPDATE",
"UC_TC",
"BC_TC",
1238 "start1",
"overrun",
"start",
"bc_tc_error",
1239 "fifo_empty",
"fifo_half_full",
"fifo_full",
"interrupt_b"
1247 for (i = 15; i >= 0; i--) {
1248 if (status & (1 << i)) {
1249 printk(
" %s", status_b_strings[i]);
1271 for (i = 0; i <
n; i++) {
1279 packed_data = d & 0xffff;
1287 packed_data |= (d << 16) & 0xffff0000;
1333 ni_ao_fifo_load(dev, s, n);
1359 ni_ao_fifo_load(dev, s, n);
1374 for (i = 0; i < n / 2; i++) {
1377 data[0] = (dl >> 16) & 0xffff;
1378 data[1] = dl & 0xffff;
1384 data[0] = dl & 0xffff;
1385 cfc_write_to_buffer(s, data[0]);
1392 for (i = 0; i < n / 2; i++) {
1395 data[0] = (dl >> 16) & 0xffff;
1396 data[1] = dl & 0xffff;
1403 data[0] = (dl >> 16) & 0xffff;
1404 cfc_write_to_buffer(s, data[0]);
1407 if (n >
sizeof(
devpriv->ai_fifo_buffer) /
1408 sizeof(
devpriv->ai_fifo_buffer[0])) {
1413 for (i = 0; i <
n; i++) {
1419 sizeof(
devpriv->ai_fifo_buffer[0]));
1423 static void ni_handle_fifo_half_full(
struct comedi_device *dev)
1430 ni_ai_fifo_read(dev, s, n);
1438 static const int timeout = 10000;
1439 unsigned long flags;
1444 for (i = 0; i < timeout; i++) {
1454 printk(
"ni_mio_common: wait for dma drain timed out\n");
1456 (
"mite_bytes_in_transit=%i, AI_Status1_Register=0x%x\n",
1462 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
1464 ni_sync_ai_dma(dev);
1481 while ((
devpriv->stc_readw(dev,
1487 data[0] = (dl >> 16);
1488 data[1] = (dl & 0xffff);
1497 data[0] = (dl >> 16);
1498 data[1] = (dl & 0xffff);
1506 data[0] = (dl >> 16) & 0xffff;
1507 cfc_write_to_buffer(s, data[0]);
1514 while (fifo_empty == 0) {
1517 sizeof(
devpriv->ai_fifo_buffer) /
1518 sizeof(
devpriv->ai_fifo_buffer[0]); i++) {
1531 ai_fifo_buffer[0]));
1548 data = (dl & 0xffff);
1549 cfc_write_to_buffer(s, data);
1568 data = (dl >> 16) & 0xffff;
1569 cfc_write_to_buffer(s, data);
1575 unsigned int chan_index)
1580 short *array =
data;
1581 unsigned int *larray =
data;
1582 for (i = 0; i <
length; i++) {
1590 larray[
i] +=
devpriv->ai_offset[chan_index];
1592 array[
i] +=
devpriv->ai_offset[chan_index];
1594 chan_index %= async->
cmd.chanlist_len;
1604 unsigned long flags;
1606 retval = ni_request_ai_mite_channel(dev);
1616 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
1634 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
1643 unsigned long flags;
1645 retval = ni_request_ao_mite_channel(dev);
1664 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
1679 ni_release_ai_mite_channel(dev);
1690 ni_clear_ai_fifo(dev);
1713 AI_CONVERT_Output_Select
1726 AI_CONVERT_Output_Select
1730 unsigned ai_output_control_bits;
1736 ai_output_control_bits =
1742 ai_output_control_bits |=
1743 AI_CONVERT_Output_Select
1746 ai_output_control_bits |=
1747 AI_CONVERT_Output_Select
1749 devpriv->stc_writew(dev, ai_output_control_bits,
1769 unsigned long flags;
1775 ni_handle_fifo_dregs(dev);
1777 ni_sync_ai_dma(dev);
1779 count = s->
async->buf_write_count - s->
async->buf_read_count;
1780 spin_unlock_irqrestore(&dev->
spinlock, flags);
1795 ni_load_channelgain_list(dev, 1, &insn->
chanspec);
1797 ni_clear_ai_fifo(dev);
1799 signbits =
devpriv->ai_offset[0];
1801 for (n = 0; n < num_adc_stages_611x; n++) {
1806 for (n = 0; n < insn->
n; n++) {
1825 if (i == NI_TIMEOUT) {
1827 (
"ni_mio_common: timeout in 611x ni_ai_insn_read\n");
1834 for (n = 0; n < insn->
n; n++) {
1847 if (i == NI_TIMEOUT) {
1849 (
"ni_mio_common: timeout in 6143 ni_ai_insn_read\n");
1852 data[
n] = (((dl >> 16) & 0xFFFF) + signbits) & 0xFFFF;
1855 for (n = 0; n < insn->
n; n++) {
1864 if (i == NI_TIMEOUT) {
1866 (
"ni_mio_common: timeout in ni_ai_insn_read\n");
1882 static void ni_prime_channelgain_list(
struct comedi_device *dev)
1895 printk(
"ni_mio_common: timeout loading channel/gain list\n");
1898 static void ni_m_series_load_channelgain_list(
struct comedi_device *dev,
1902 unsigned int chan,
range, aref;
1906 unsigned range_code;
1912 unsigned bypass_bits;
1918 bypass_bits |= chan;
1925 bypass_bits |= MSeries_AI_Bypass_Gain_Bits(range_code);
1935 for (i = 0; i <
n_chan; i++) {
1936 unsigned config_bits = 0;
1960 config_bits |= MSeries_AI_Config_Channel_Bits(chan);
1962 MSeries_AI_Config_Bank_Bits(
boardtype.reg_type, chan);
1963 config_bits |= MSeries_AI_Config_Gain_Bits(range_code);
1964 if (i == n_chan - 1)
1972 ni_prime_channelgain_list(dev);
2004 static void ni_load_channelgain_list(
struct comedi_device *dev,
2005 unsigned int n_chan,
unsigned int *list)
2007 unsigned int chan,
range, aref;
2009 unsigned int hi,
lo;
2014 ni_m_series_load_channelgain_list(dev, n_chan, list);
2020 &&
devpriv->changain_spec == list[0]) {
2025 devpriv->changain_spec = list[0];
2034 if ((list[0] & CR_ALT_SOURCE)
2035 && !
devpriv->ai_calib_source_enabled) {
2042 devpriv->ai_calib_source_enabled = 1;
2044 }
else if (!(list[0] & CR_ALT_SOURCE)
2045 &&
devpriv->ai_calib_source_enabled) {
2052 devpriv->ai_calib_source_enabled = 0;
2058 for (i = 0; i <
n_chan; i++) {
2061 chan =
devpriv->ai_calib_source;
2074 devpriv->ai_offset[
i] = (range & 0x100) ? 0 : offset;
2077 if ((list[i] & CR_ALT_SOURCE)) {
2100 hi |= AI_CONFIG_CHANNEL(chan);
2106 if (i == n_chan - 1)
2118 ni_prime_channelgain_list(dev);
2122 static int ni_ns_to_timer(
const struct comedi_device *dev,
unsigned nanosec,
2126 switch (round_mode) {
2132 divider = (nanosec) /
devpriv->clock_ns;
2143 return devpriv->clock_ns * (timer + 1);
2146 static unsigned ni_min_ai_scan_period_ns(
struct comedi_device *dev,
2167 unsigned int sources;
2174 err |= cfc_check_trigger_src(&cmd->
start_src,
2183 err |= cfc_check_trigger_src(&cmd->
convert_src, sources);
2193 err |= cfc_check_trigger_is_unique(cmd->
start_src);
2195 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
2196 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
2296 max_count -= num_adc_stages_611x;
2321 ni_timer_to_ns(dev, ni_ns_to_timer(dev,
2334 ni_timer_to_ns(dev, ni_ns_to_timer(dev,
2363 int start_stop_select = 0;
2364 unsigned int stop_count;
2365 int interrupt_a_enable = 0;
2368 if (dev->
irq == 0) {
2369 comedi_error(dev,
"cannot run command without an irq");
2372 ni_clear_ai_fifo(dev);
2403 devpriv->stc_writew(dev, bits,
2422 devpriv->stc_writew(dev, start_stop_select,
2432 stop_count += num_adc_stages_611x;
2443 if (stop_count == 0) {
2448 start_stop_select |=
2484 devpriv->stc_writew(dev, start_stop_select,
2509 start_stop_select |=
2511 devpriv->stc_writew(dev, start_stop_select,
2604 interrupt_a_enable, 1);
2606 MDPRINTK(
"Interrupt_A_Enable_Register = 0x%04x\n",
2613 MDPRINTK(
"interrupting on nothing\n");
2635 int retval = ni_ai_setup_MITE_dma(dev);
2653 s->
async->inttrig = &ni_ai_inttrig;
2663 unsigned int trignum)
2675 static int ni_ai_config_analog_trig(
struct comedi_device *dev,
2678 unsigned int *data);
2689 return ni_ai_config_analog_trig(dev, s, insn, data);
2698 devpriv->ai_calib_source = data[1];
2700 unsigned int calib_source;
2702 calib_source = data[1] & 0xf;
2704 if (calib_source > 0xF)
2707 devpriv->ai_calib_source = calib_source;
2710 unsigned int calib_source;
2711 unsigned int calib_source_adjust;
2713 calib_source = data[1] & 0xf;
2714 calib_source_adjust = (data[1] >> 4) & 0xff;
2716 if (calib_source >= 8)
2718 devpriv->ai_calib_source = calib_source;
2732 static int ni_ai_config_analog_trig(
struct comedi_device *dev,
2737 unsigned int a,
b, modebits;
2754 if (data[3] > 255) {
2758 if (data[4] > 255) {
2779 modebits = data[1] & 0xff;
2780 if (modebits & 0xf0) {
2787 ((data[1] & 0xf) << 4) | ((data[1] & 0xf0) >> 4);
2832 void *data,
unsigned int num_bytes,
2833 unsigned int chan_index)
2839 unsigned int length = num_bytes /
sizeof(
short);
2840 short *array =
data;
2843 for (i = 0; i <
length; i++) {
2844 range =
CR_RANGE(async->
cmd.chanlist[chan_index]);
2845 if (
boardtype.ao_unipolar == 0 || (range & 1) == 0)
2851 chan_index %= async->
cmd.chanlist_len;
2855 static int ni_m_series_ao_config_chanlist(
struct comedi_device *dev,
2857 unsigned int chanspec[],
2858 unsigned int n_chans,
int timed)
2870 M_Offset_AO_Config_Bank(i));
2871 ni_writeb(0xf, M_Offset_AO_Waveform_Order(i));
2874 for (i = 0; i < n_chans; i++) {
2881 switch (krange->
max - krange->
min) {
2884 ni_writeb(0, M_Offset_AO_Reference_Attenuation(chan));
2888 ni_writeb(0, M_Offset_AO_Reference_Attenuation(chan));
2893 M_Offset_AO_Reference_Attenuation(chan));
2898 M_Offset_AO_Reference_Attenuation(chan));
2901 printk(
"%s: bug! unhandled ao reference voltage\n",
2905 switch (krange->
max + krange->
min) {
2913 printk(
"%s: bug! unhandled ao offset voltage\n",
2919 ni_writeb(conf, M_Offset_AO_Config_Bank(chan));
2920 devpriv->ao_conf[chan] = conf;
2921 ni_writeb(i, M_Offset_AO_Waveform_Order(chan));
2926 static int ni_old_ao_config_chanlist(
struct comedi_device *dev,
2928 unsigned int chanspec[],
2929 unsigned int n_chans)
2937 for (i = 0; i < n_chans; i++) {
2943 if ((range & 1) == 0) {
2962 conf |= (
CR_AREF(chanspec[i]) ==
2966 devpriv->ao_conf[chan] = conf;
2973 unsigned int chanspec[],
unsigned int n_chans,
2977 return ni_m_series_ao_config_chanlist(dev, s, chanspec, n_chans,
2980 return ni_old_ao_config_chanlist(dev, s, chanspec, n_chans);
2997 unsigned int invert;
2999 invert = ni_ao_config_chanlist(dev, s, &insn->
chanspec, 1, 0);
3004 ni_writew(data[0], M_Offset_DAC_Direct_Data(chan));
3017 unsigned int invert;
3022 ni_ao_config_chanlist(dev, s, &insn->
chanspec, 1, 0);
3025 ao_win_out(data[0] ^ invert, DACx_Direct_Data_671x(chan));
3040 data[2] +=
devpriv->mite->fifo_size;
3058 unsigned int trignum)
3061 int interrupt_b_bits;
3063 static const int timeout = 1000;
3080 ret = ni_ao_setup_MITE_dma(dev);
3083 ret = ni_ao_wait_for_dma_load(dev);
3087 ret = ni_ao_prep_fifo(dev, s);
3098 for (i = 0; i < timeout; i++) {
3107 "timed out waiting for AO_TMRDACWRs_In_Progress_St to clear");
3134 if (dev->
irq == 0) {
3135 comedi_error(dev,
"cannot run command without an irq");
3267 AO_UPDATE_Output_Select
3325 s->
async->inttrig = &ni_ao_inttrig;
3353 err |= cfc_check_trigger_is_unique(cmd->
start_src);
3355 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
3420 ni_timer_to_ns(dev, ni_ns_to_timer(dev,
3447 ni_release_ao_mite_channel(dev);
3471 devpriv->ao_trigger_select = 0;
3475 unsigned immediate_bits = 0;
3477 for (i = 0; i < s->
n_chan; ++
i) {
3478 immediate_bits |= 1 <<
i;
3495 printk(
"ni_dio_insn_config() chan=%d io=%d\n",
3528 printk(
"ni_dio_insn_bits() mask=0x%x bits=0x%x\n", data[0], data[1]);
3535 &&
devpriv->serial_interval_ns)
3538 s->
state &= ~data[0];
3539 s->
state |= (data[0] & data[1]);
3550 static int ni_m_series_dio_insn_config(
struct comedi_device *dev,
3556 printk(
"ni_m_series_dio_insn_config() chan=%d io=%d\n",
3582 static int ni_m_series_dio_insn_bits(
struct comedi_device *dev,
3588 printk(
"ni_m_series_dio_insn_bits() mask=0x%x bits=0x%x\n", data[0],
3593 s->
state &= ~data[0];
3594 s->
state |= (data[0] & data[1]);
3707 "attempted to run digital output command with no lines configured as outputs");
3710 retval = ni_request_cdo_mite_channel(dev);
3714 s->
async->inttrig = &ni_cdo_inttrig;
3719 unsigned int trignum)
3722 unsigned long flags;
3726 const unsigned timeout = 1000;
3742 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
3751 for (i = 0; i < timeout; ++
i) {
3758 ni_cdio_cancel(dev, s);
3778 ni_release_cdo_mite_channel(dev);
3782 static void handle_cdio_interrupt(
struct comedi_device *dev)
3784 unsigned cdio_status;
3787 unsigned long flags;
3796 unsigned cdo_mite_status =
3798 if (cdo_mite_status & CHSR_LINKC) {
3801 MITE_CHOR(
devpriv->cdo_mite_chan->channel));
3805 spin_unlock_irqrestore(&
devpriv->mite_channel_lock, flags);
3828 unsigned char byte_out, byte_in = 0;
3837 printk(
"SPI serial clock Config cd\n", data[1]);
3847 devpriv->serial_interval_ns = data[1];
3855 devpriv->serial_interval_ns = data[1];
3861 devpriv->serial_interval_ns = data[1];
3871 devpriv->serial_interval_ns = data[1];
3876 data[1] = (data[1] / 1000) * 1000;
3877 devpriv->serial_interval_ns = data[1];
3890 if (
devpriv->serial_interval_ns == 0) {
3894 byte_out = data[1] & 0xFF;
3896 if (
devpriv->serial_hw_mode) {
3897 err = ni_serial_hw_readwrite8(dev, s, byte_out,
3899 }
else if (
devpriv->serial_interval_ns > 0) {
3900 err = ni_serial_sw_readwrite8(dev, s, byte_out,
3903 printk(
"ni_serial_insn_config: serial disabled!\n");
3908 data[1] = byte_in & 0xFF;
3918 static int ni_serial_hw_readwrite8(
struct comedi_device *dev,
3920 unsigned char data_out,
3921 unsigned char *data_in)
3924 int err = 0,
count = 20;
3927 printk(
"ni_serial_hw_readwrite8: outputting 0x%x\n", data_out);
3948 DIO_Serial_IO_In_Progress_St) {
3953 (
"ni_serial_hw_readwrite8: SPI serial I/O didn't finish in time!\n");
3963 if (data_in !=
NULL) {
3966 printk(
"ni_serial_hw_readwrite8: inputted 0x%x\n", *data_in);
3976 static int ni_serial_sw_readwrite8(
struct comedi_device *dev,
3978 unsigned char data_out,
3979 unsigned char *data_in)
3984 printk(
"ni_serial_sw_readwrite8: outputting 0x%x\n", data_out);
3990 for (mask = 0x80;
mask; mask >>= 1) {
3995 if (data_out & mask) {
4024 printk(
"ni_serial_sw_readwrite8: inputted 0x%x\n", input);
4051 for (i = 0; i < s->
n_chan; i++) {
4060 unsigned stc_register;
4141 printk(
"%s: unhandled register 0x%x in switch.\n",
4147 return stc_register;
4150 static void ni_gpct_write_register(
struct ni_gpct *
counter,
unsigned bits,
4154 unsigned stc_register;
4157 static const unsigned gpct_interrupt_a_enable_mask =
4159 static const unsigned gpct_interrupt_b_enable_mask =
4194 stc_register = ni_gpct_to_stc_register(reg);
4195 devpriv->stc_writel(dev, bits, stc_register);
4200 BUG_ON(bits & ~gpct_interrupt_a_enable_mask);
4202 gpct_interrupt_a_enable_mask, bits);
4205 BUG_ON(bits & ~gpct_interrupt_b_enable_mask);
4207 gpct_interrupt_b_enable_mask, bits);
4210 BUG_ON(bits & ~gpct_joint_reset_mask);
4213 stc_register = ni_gpct_to_stc_register(reg);
4214 devpriv->stc_writew(dev, bits, stc_register);
4218 static unsigned ni_gpct_read_register(
struct ni_gpct *counter,
4222 unsigned stc_register;
4237 stc_register = ni_gpct_to_stc_register(reg);
4238 return devpriv->stc_readl(dev, stc_register);
4243 stc_register = ni_gpct_to_stc_register(reg);
4244 return devpriv->stc_readw(dev, stc_register);
4258 static int ni_freq_out_insn_write(
struct comedi_device *dev,
4266 devpriv->clock_and_fout |= FOUT_Divider(data[0]);
4274 unsigned int clock_source)
4276 switch (clock_source) {
4291 static void ni_get_freq_out_clock(
struct comedi_device *dev,
4292 unsigned int *clock_source,
4293 unsigned int *clock_period_ns)
4304 static int ni_freq_out_insn_config(
struct comedi_device *dev,
4310 return ni_set_freq_out_clock(dev, data[1]);
4313 ni_get_freq_out_clock(dev, &data[1], &data[2]);
4325 ret = alloc_private(dev,
sizeof(
struct ni_private));
4344 printk(
"bug! boardtype.n_aochan > MAX_N_AO_CHAN\n");
4374 s->
cancel = &ni_ai_reset;
4375 s->
poll = &ni_ai_poll;
4376 s->
munge = &ni_ai_munge;
4414 s->
munge = ni_ao_munge;
4416 s->
cancel = &ni_ao_reset;
4421 init_ao_67xx(dev, s);
4435 s->
insn_bits = &ni_m_series_dio_insn_bits;
4437 s->
do_cmd = &ni_cdio_cmd;
4439 s->
cancel = &ni_cdio_cancel;
4484 caldac_setup(dev, s);
4494 s->
insn_read = &ni_m_series_eeprom_insn_read;
4510 M_Offset_PFI_Output_Select(i + 1));
4545 devpriv->serial_interval_ns = 0;
4564 &ni_gpct_write_register,
4565 &ni_gpct_read_register,
4583 s->
do_cmd = &ni_gpct_cmd;
4586 s->
cancel = &ni_gpct_cancel;
4590 devpriv->counter_dev->counters[
j].chip_index = 0;
4591 devpriv->counter_dev->counters[
j].counter_index =
j;
4607 ni_ai_reset(dev, s);
4627 ni_ao_reset(dev, s);
4650 ni_writeb(0xf, M_Offset_AO_Waveform_Order(channel));
4652 M_Offset_AO_Reference_Attenuation(channel));
4661 static int ni_8255_callback(
int dir,
int port,
int data,
unsigned long arg)
4695 bitstring = 0x0300 | ((addr & 0x100) << 3) | (addr & 0xff);
4697 for (bit = 0x8000;
bit; bit >>= 1) {
4698 ni_writeb(0x04 | ((bit & bitstring) ? 0x02 : 0),
4700 ni_writeb(0x05 | ((bit & bitstring) ? 0x02 : 0),
4704 for (bit = 0x80;
bit; bit >>= 1) {
4714 static int ni_m_series_eeprom_insn_read(
struct comedi_device *dev,
4724 static int ni_get_pwm_config(
struct comedi_device *dev,
unsigned int *data)
4731 static int ni_m_series_pwm_config(
struct comedi_device *dev,
4735 unsigned up_count, down_count;
4745 up_count = data[2] /
devpriv->clock_ns;
4749 (data[2] +
devpriv->clock_ns -
4763 down_count = data[4] /
devpriv->clock_ns;
4767 (data[4] +
devpriv->clock_ns -
4774 if (up_count *
devpriv->clock_ns != data[2] ||
4775 down_count *
devpriv->clock_ns != data[4]) {
4776 data[2] = up_count *
devpriv->clock_ns;
4777 data[4] = down_count *
devpriv->clock_ns;
4780 ni_writel(MSeries_Cal_PWM_High_Time_Bits(up_count) |
4781 MSeries_Cal_PWM_Low_Time_Bits(down_count),
4783 devpriv->pwm_up_count = up_count;
4784 devpriv->pwm_down_count = down_count;
4788 return ni_get_pwm_config(dev, data);
4801 unsigned up_count, down_count;
4811 up_count = data[2] /
devpriv->clock_ns;
4815 (data[2] +
devpriv->clock_ns -
4829 down_count = data[4] /
devpriv->clock_ns;
4833 (data[4] +
devpriv->clock_ns -
4840 if (up_count *
devpriv->clock_ns != data[2] ||
4841 down_count *
devpriv->clock_ns != data[4]) {
4842 data[2] = up_count *
devpriv->clock_ns;
4843 data[4] = down_count *
devpriv->clock_ns;
4847 devpriv->pwm_up_count = up_count;
4849 devpriv->pwm_down_count = down_count;
4853 return ni_get_pwm_config(dev, data);
4883 static int pack_mb88341(
int addr,
int val,
int *bitstring);
4884 static int pack_dac8800(
int addr,
int val,
int *bitstring);
4885 static int pack_dac8043(
int addr,
int val,
int *bitstring);
4886 static int pack_ad8522(
int addr,
int val,
int *bitstring);
4887 static int pack_ad8804(
int addr,
int val,
int *bitstring);
4888 static int pack_ad8842(
int addr,
int val,
int *bitstring);
4897 [
mb88341] = {12, 8, pack_mb88341},
4898 [
dac8800] = {8, 8, pack_dac8800},
4899 [
dac8043] = {1, 12, pack_dac8043},
4900 [
ad8522] = {2, 12, pack_ad8522},
4901 [
ad8804] = {12, 8, pack_ad8804},
4902 [
ad8842] = {8, 8, pack_ad8842},
4920 for (i = 0; i < 3; i++) {
4924 if (caldacs[type].n_bits != n_bits)
4932 unsigned int *maxdata_list;
4935 printk(
"BUG! MAX_N_CALDACS too small\n");
4939 for (i = 0; i < n_dacs; i++) {
4942 maxdata_list[chan] =
4948 for (chan = 0; chan < s->
n_chan; chan++)
4954 for (chan = 0; chan < s->
n_chan; chan++)
4955 ni_write_caldac(dev, i, s->
maxdata / 2);
4961 unsigned int loadbit = 0, bits = 0,
bit, bitstring = 0;
4966 if (
devpriv->caldacs[addr] == val)
4970 for (i = 0; i < 3; i++) {
4974 if (addr < caldacs[type].n_chans) {
4983 for (bit = 1 << (bits - 1);
bit; bit >>= 1) {
4994 static int pack_mb88341(
int addr,
int val,
int *bitstring)
5006 *bitstring = ((addr & 0x1) << 11) |
5007 ((addr & 0x2) << 9) |
5008 ((addr & 0x4) << 7) | ((addr & 0x8) << 5) | (val & 0xff);
5012 static int pack_dac8800(
int addr,
int val,
int *bitstring)
5014 *bitstring = ((addr & 0x7) << 8) | (val & 0xff);
5018 static int pack_dac8043(
int addr,
int val,
int *bitstring)
5020 *bitstring = val & 0xfff;
5024 static int pack_ad8522(
int addr,
int val,
int *bitstring)
5026 *bitstring = (val & 0xfff) | (addr ? 0xc000 : 0xa000);
5030 static int pack_ad8804(
int addr,
int val,
int *bitstring)
5032 *bitstring = ((addr & 0xf) << 8) | (val & 0xff);
5036 static int pack_ad8842(
int addr,
int val,
int *bitstring)
5038 *bitstring = ((addr + 1) << 8) | (val & 0xff);
5046 static int GPCT_G_Watch(
struct comedi_device *dev,
int chan)
5048 unsigned int hi1, hi2, lo;
5064 }
while (hi1 != hi2);
5066 return (hi1 << 16) | lo;
5071 int temp_ack_reg = 0;
5087 devpriv->stc_writew(dev, temp_ack_reg,
5105 devpriv->stc_writew(dev, temp_ack_reg,
5115 devpriv->gpct_input_select[chan] = 0;
5116 devpriv->gpct_command[chan] = 0;
5162 retval = ni_request_gpct_mite_channel(dev, counter->
counter_index,
5166 "no dma channel available for use by counter");
5170 ni_e_series_enable_second_irq(dev, counter->
counter_index, 1);
5197 ni_e_series_enable_second_irq(dev, counter->
counter_index, 0);
5211 static int ni_m_series_set_pfi_routing(
struct comedi_device *dev,
unsigned chan,
5214 unsigned pfi_reg_index;
5215 unsigned array_offset;
5216 if ((source & 0x1f) != source)
5218 pfi_reg_index = 1 + chan / 3;
5219 array_offset = pfi_reg_index - 1;
5220 devpriv->pfi_output_select_reg[array_offset] &=
5221 ~MSeries_PFI_Output_Select_Mask(chan);
5222 devpriv->pfi_output_select_reg[array_offset] |=
5223 MSeries_PFI_Output_Select_Bits(chan, source);
5225 M_Offset_PFI_Output_Select(pfi_reg_index));
5229 static int ni_old_set_pfi_routing(
struct comedi_device *dev,
unsigned chan,
5233 if (source != ni_old_get_pfi_routing(dev, chan))
5238 static int ni_set_pfi_routing(
struct comedi_device *dev,
unsigned chan,
5242 return ni_m_series_set_pfi_routing(dev, chan, source);
5244 return ni_old_set_pfi_routing(dev, chan, source);
5247 static unsigned ni_m_series_get_pfi_routing(
struct comedi_device *dev,
5250 const unsigned array_offset = chan / 3;
5251 return MSeries_PFI_Output_Select_Source(chan,
5253 pfi_output_select_reg
5257 static unsigned ni_old_get_pfi_routing(
struct comedi_device *dev,
unsigned chan)
5292 printk(
"%s: bug, unhandled case in switch.\n", __func__);
5298 static unsigned ni_get_pfi_routing(
struct comedi_device *dev,
unsigned chan)
5301 return ni_m_series_get_pfi_routing(dev, chan);
5303 return ni_old_get_pfi_routing(dev, chan);
5306 static int ni_config_filter(
struct comedi_device *dev,
unsigned pfi_channel,
5314 bits &= ~MSeries_PFI_Filter_Select_Mask(pfi_channel);
5315 bits |= MSeries_PFI_Filter_Select_Bits(pfi_channel, filter);
5328 s->
state &= ~data[0];
5329 s->
state |= (data[0] & data[1]);
5356 (
devpriv->io_bidirection_pin_reg & (1 << chan)) ?
5361 return ni_set_pfi_routing(dev, chan, data[1]);
5364 data[1] = ni_get_pfi_routing(dev, chan);
5367 return ni_config_filter(dev, chan, data[1]);
5387 printk(
"ni_set_master_clock failed, bug?");
5390 devpriv->rtsi_trig_a_output_reg =
5391 RTSI_Trig_Output_Bits(0,
5393 RTSI_Trig_Output_Bits(1,
5395 RTSI_Trig_Output_Bits(2,
5400 devpriv->rtsi_trig_b_output_reg =
5401 RTSI_Trig_Output_Bits(4,
5403 RTSI_Trig_Output_Bits(5,
5407 devpriv->rtsi_trig_b_output_reg |=
5429 static int ni_mseries_get_pll_parameters(
unsigned reference_period_ns,
5430 unsigned *freq_divider,
5431 unsigned *freq_multiplier,
5432 unsigned *actual_period_ns)
5435 unsigned best_div = 1;
5436 static const unsigned max_div = 0x10;
5438 unsigned best_mult = 1;
5439 static const unsigned max_mult = 0x100;
5440 static const unsigned pico_per_nano = 1000;
5442 const unsigned reference_picosec = reference_period_ns * pico_per_nano;
5445 static const unsigned target_picosec = 12500;
5446 static const unsigned fudge_factor_80_to_20Mhz = 4;
5447 int best_period_picosec = 0;
5448 for (div = 1; div <= max_div; ++
div) {
5449 for (mult = 1; mult <= max_mult; ++
mult) {
5450 unsigned new_period_ps =
5451 (reference_picosec *
div) / mult;
5452 if (
abs(new_period_ps - target_picosec) <
5453 abs(best_period_picosec - target_picosec)) {
5454 best_period_picosec = new_period_ps;
5460 if (best_period_picosec == 0) {
5461 printk(
"%s: bug, failed to find pll parameters\n", __func__);
5464 *freq_divider = best_div;
5465 *freq_multiplier = best_mult;
5467 (best_period_picosec * fudge_factor_80_to_20Mhz +
5468 (pico_per_nano / 2)) / pico_per_nano;
5472 static inline unsigned num_configurable_rtsi_channels(
struct comedi_device *dev)
5480 static int ni_mseries_set_pll_master_clock(
struct comedi_device *dev,
5481 unsigned source,
unsigned period_ns)
5483 static const unsigned min_period_ns = 50;
5484 static const unsigned max_period_ns = 1000;
5485 static const unsigned timeout = 1000;
5486 unsigned pll_control_bits;
5487 unsigned freq_divider;
5488 unsigned freq_multiplier;
5494 if (period_ns < min_period_ns || period_ns > max_period_ns) {
5496 (
"%s: you must specify an input clock frequency between %i and %i nanosec "
5497 "for the phased-lock loop.\n", __func__,
5498 min_period_ns, max_period_ns);
5513 retval = ni_mseries_get_pll_parameters(period_ns, &freq_divider,
5523 retval = ni_mseries_get_pll_parameters(period_ns, &freq_divider,
5531 unsigned rtsi_channel;
5532 static const unsigned max_rtsi_channel = 7;
5533 for (rtsi_channel = 0; rtsi_channel <= max_rtsi_channel;
5536 NI_MIO_PLL_RTSI_CLOCK(rtsi_channel)) {
5538 MSeries_PLL_In_Source_Select_RTSI_Bits
5543 if (rtsi_channel > max_rtsi_channel)
5545 retval = ni_mseries_get_pll_parameters(period_ns,
5557 MSeries_PLL_Divisor_Bits(freq_divider) |
5558 MSeries_PLL_Multiplier_Bits(freq_multiplier);
5566 for (i = 0; i < timeout; ++
i) {
5574 (
"%s: timed out waiting for PLL to lock to reference clock source %i with period %i ns.\n",
5575 __func__, source, period_ns);
5581 static int ni_set_master_clock(
struct comedi_device *dev,
unsigned source,
5600 return ni_mseries_set_pll_master_clock(dev, source,
5604 devpriv->rtsi_trig_direction_reg |=
5608 rtsi_trig_direction_reg,
5610 if (period_ns == 0) {
5612 (
"%s: we don't handle an unspecified clock period correctly yet, returning error.\n",
5616 devpriv->clock_ns = period_ns;
5626 static int ni_valid_rtsi_output_source(
struct comedi_device *dev,
unsigned chan,
5629 if (chan >= num_configurable_rtsi_channels(dev)) {
5630 if (chan == old_RTSI_clock_channel) {
5635 (
"%s: invalid source for channel=%i, channel %i is always the RTSI clock for pre-m-series boards.\n",
5636 __func__, chan, old_RTSI_clock_channel);
5666 static int ni_set_rtsi_routing(
struct comedi_device *dev,
unsigned chan,
5669 if (ni_valid_rtsi_output_source(dev, chan, source) == 0)
5672 devpriv->rtsi_trig_a_output_reg &= ~RTSI_Trig_Output_Mask(chan);
5673 devpriv->rtsi_trig_a_output_reg |=
5674 RTSI_Trig_Output_Bits(chan, source);
5677 }
else if (chan < 8) {
5678 devpriv->rtsi_trig_b_output_reg &= ~RTSI_Trig_Output_Mask(chan);
5679 devpriv->rtsi_trig_b_output_reg |=
5680 RTSI_Trig_Output_Bits(chan, source);
5687 static unsigned ni_get_rtsi_routing(
struct comedi_device *dev,
unsigned chan)
5690 return RTSI_Trig_Output_Source(chan,
5691 devpriv->rtsi_trig_a_output_reg);
5692 }
else if (chan < num_configurable_rtsi_channels(dev)) {
5693 return RTSI_Trig_Output_Source(chan,
5694 devpriv->rtsi_trig_b_output_reg);
5696 if (chan == old_RTSI_clock_channel)
5698 printk(
"%s: bug! should never get here?\n", __func__);
5710 if (chan < num_configurable_rtsi_channels(dev)) {
5711 devpriv->rtsi_trig_direction_reg |=
5712 RTSI_Output_Bit(chan,
5716 }
else if (chan == old_RTSI_clock_channel) {
5717 devpriv->rtsi_trig_direction_reg |=
5724 if (chan < num_configurable_rtsi_channels(dev)) {
5725 devpriv->rtsi_trig_direction_reg &=
5726 ~RTSI_Output_Bit(chan,
5730 }
else if (chan == old_RTSI_clock_channel) {
5731 devpriv->rtsi_trig_direction_reg &=
5738 if (chan < num_configurable_rtsi_channels(dev)) {
5740 (
devpriv->rtsi_trig_direction_reg &
5741 RTSI_Output_Bit(chan,
5746 }
else if (chan == old_RTSI_clock_channel) {
5748 (
devpriv->rtsi_trig_direction_reg &
5755 return ni_set_master_clock(dev, data[1], data[2]);
5758 data[1] =
devpriv->clock_source;
5763 return ni_set_rtsi_routing(dev, chan, data[1]);
5766 data[1] = ni_get_rtsi_routing(dev, chan);
5779 const int timeout =
HZ;
5782 for (i = 0; i < timeout; i++) {
5794 printk(
"%s: %s: timeout\n", __FILE__, __func__);
5800 static void cs5529_command(
struct comedi_device *dev,
unsigned short value)
5802 static const int timeout = 100;
5810 for (i = 0; i < timeout; i++) {
5817 comedi_error(dev,
"possible problem - never saw adc go busy?");
5822 static void cs5529_config_write(
struct comedi_device *dev,
unsigned int value,
5823 unsigned int reg_select_bits)
5825 ni_ao_win_outw(dev, ((value >> 16) & 0xff),
5827 ni_ao_win_outw(dev, (value & 0xffff),
5831 if (cs5529_wait_for_idle(dev))
5832 comedi_error(dev,
"time or signal in cs5529_config_write()");
5835 #ifdef NI_CS5529_DEBUG
5837 static unsigned int cs5529_config_read(
struct comedi_device *dev,
5838 unsigned int reg_select_bits)
5844 if (cs5529_wait_for_idle(dev))
5845 comedi_error(dev,
"timeout or signal in cs5529_config_read()");
5846 value = (ni_ao_win_inw(dev,
5854 static int cs5529_do_conversion(
struct comedi_device *dev,
unsigned short *data)
5860 retval = cs5529_wait_for_idle(dev);
5863 "timeout or signal in cs5529_do_conversion()");
5869 (
"ni_mio_common: cs5529 conversion error, status CSS_OSC_DETECT\n");
5874 (
"ni_mio_common: cs5529 conversion error, overrange (ignoring)\n");
5890 unsigned int channel_select;
5891 const unsigned int INTERNAL_REF = 0x1000;
5896 if (insn->
chanspec & CR_ALT_SOURCE)
5897 channel_select = INTERNAL_REF;
5902 for (n = 0; n < insn->
n; n++) {
5903 retval = cs5529_do_conversion(dev, &sample);
5913 unsigned int config_bits =
5921 cs5529_do_conversion(dev,
NULL);
5927 if (cs5529_wait_for_idle(dev))
5928 comedi_error(dev,
"timeout or signal in init_cs5529()\n");
5930 #ifdef NI_CS5529_DEBUG
5931 printk(
"config: 0x%x\n", cs5529_config_read(dev,
5934 printk(
"offset: 0x%x\n", cs5529_config_read(dev,