fmc-adc-100m14b4cha.h 16.2 KB
Newer Older
Federico Vaga's avatar
Federico Vaga committed
1
/*
Federico Vaga's avatar
Federico Vaga committed
2 3
 * Copyright CERN 2012
 * Author: Federico Vaga <federico.vaga@gmail.com>
Federico Vaga's avatar
Federico Vaga committed
4
 *
Federico Vaga's avatar
Federico Vaga committed
5
 * Header for the mezzanine ADC for the SPEC
Federico Vaga's avatar
Federico Vaga committed
6 7
 */

8 9
#ifndef FMC_ADC_100M14B4C_H_
#define FMC_ADC_100M14B4C_H_
10

11 12 13 14
#ifndef BIT
#define BIT(nr) (1UL << (nr))
#endif

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/* Trigger sources */
#define FA100M14B4C_TRG_SRC_EXT BIT(0)
#define FA100M14B4C_TRG_SRC_SW BIT(1)
#define FA100M14B4C_TRG_SRC_TIM BIT(4)
#define FA100M14B4C_TRG_SRC_CH1 BIT(8)
#define FA100M14B4C_TRG_SRC_CH2 BIT(9)
#define FA100M14B4C_TRG_SRC_CH3 BIT(10)
#define FA100M14B4C_TRG_SRC_CH4 BIT(11)
#define FA100M14B4C_TRG_SRC_CHx(_x) (FA100M14B4C_TRG_SRC_CH1 << ((_x) - 1))

/* Trigger Polarity */
#define FA100M14B4C_TRG_POL_EXT FA100M14B4C_TRG_SRC_EXT
#define FA100M14B4C_TRG_POL_CH1 FA100M14B4C_TRG_SRC_CH1
#define FA100M14B4C_TRG_POL_CH2 FA100M14B4C_TRG_SRC_CH2
#define FA100M14B4C_TRG_POL_CH3 FA100M14B4C_TRG_SRC_CH3
#define FA100M14B4C_TRG_POL_CH4 FA100M14B4C_TRG_SRC_CH4
#define FA100M14B4C_TRG_POL_CHx(_x) (FA100M14B4C_TRG_POL_CH1 << ((_x) - 1))


34 35 36
/*
 * Trigger Extended Attribute Enumeration
 */
37
enum fa100m14b4c_trg_ext_attr {
38 39 40 41 42 43 44 45
	/*
	 * The trigger extended attribute order is the same in the declaration
	 * and in the zio_control, so we can always use enumeration. But, the
	 * enumeration must start with 0 followed by only consecutive value.
	 *
	 * The parameters are not exposed to user space by zio_controle, so it
	 * is not necessary to export to user space the correspondent enum
	 */
46 47
	FA100M14B4C_TATTR_STA = 0,
	FA100M14B4C_TATTR_SRC,
48
	FA100M14B4C_TATTR_POL,
49 50 51 52 53 54 55 56 57 58 59 60 61 62
	FA100M14B4C_TATTR_EXT_DLY,
	FA100M14B4C_TATTR_CH1_THRES,
	FA100M14B4C_TATTR_CH2_THRES,
	FA100M14B4C_TATTR_CH3_THRES,
	FA100M14B4C_TATTR_CH4_THRES,
	FA100M14B4C_TATTR_CH1_HYST,
	FA100M14B4C_TATTR_CH2_HYST,
	FA100M14B4C_TATTR_CH3_HYST,
	FA100M14B4C_TATTR_CH4_HYST,
	FA100M14B4C_TATTR_CH1_DLY,
	FA100M14B4C_TATTR_CH2_DLY,
	FA100M14B4C_TATTR_CH3_DLY,
	FA100M14B4C_TATTR_CH4_DLY,

63
#ifdef __KERNEL__
64 65 66 67
	FA100M14B4C_TATTR_SW_FIRE,
	FA100M14B4C_TATTR_TRG_S,
	FA100M14B4C_TATTR_TRG_C,
	FA100M14B4C_TATTR_TRG_F,
68
#endif
69 70
};

71
/*
72
 * Device Extended Attribute Enumeration
73
 */
74
enum fa100m14b4c_dev_ext_attr {
75
	/*
76 77 78
	 * NOTE: At the moment the only extended attributes we have in
	 * the device hierarchy are in the cset level, so we can safely
	 * start from index 0
79
	 */
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
	FA100M14B4C_DATTR_DECI = 0,
	FA100M14B4C_DATTR_CH0_OFFSET,
	FA100M14B4C_DATTR_CH1_OFFSET,
	FA100M14B4C_DATTR_CH2_OFFSET,
	FA100M14B4C_DATTR_CH3_OFFSET,
	FA100M14B4C_DATTR_CH0_VREF,
	FA100M14B4C_DATTR_CH1_VREF,
	FA100M14B4C_DATTR_CH2_VREF,
	FA100M14B4C_DATTR_CH3_VREF,
	FA100M14B4C_DATTR_CH0_50TERM,
	FA100M14B4C_DATTR_CH1_50TERM,
	FA100M14B4C_DATTR_CH2_50TERM,
	FA100M14B4C_DATTR_CH3_50TERM,
	FA100M14B4C_DATTR_ACQ_START_S,
	FA100M14B4C_DATTR_ACQ_START_C,
	FA100M14B4C_DATTR_ACQ_START_F,
96
};
97

98 99 100
#define FA100M14B4C_UTC_CLOCK_FREQ 125000000
#define FA100M14B4C_UTC_CLOCK_NS  8
#define FA100M14B4C_NCHAN 4 /* We have 4 of them,no way out of it */
101
#define FA100M14B4C_NBIT 14
102

103
/* ADC DDR memory */
104
#define FA100M14B4C_MAX_ACQ_BYTE 0x10000000 /* 256MB */
Federico Vaga's avatar
Federico Vaga committed
105

106 107 108 109
enum fa100m14b4c_input_range {
	FA100M14B4C_RANGE_10V = 0x0,
	FA100M14B4C_RANGE_1V,
	FA100M14B4C_RANGE_100mV,
110 111 112 113
	FA100M14B4C_RANGE_OPEN,	/* Channel disconnected from ADC */
	FA100M14B4C_RANGE_10V_CAL,	/* Channel disconnected from ADC */
	FA100M14B4C_RANGE_1V_CAL,	/* Channel disconnected from ADC */
	FA100M14B4C_RANGE_100mV_CAL,	/* Channel disconnected from ADC */
114
};
115

116 117 118 119
enum fa100m14b4c_fsm_cmd {
	FA100M14B4C_CMD_NONE =	0x0,
	FA100M14B4C_CMD_START =	0x1,
	FA100M14B4C_CMD_STOP =	0x2,
120 121
};
/* All possible state of the state machine, other values are invalid*/
122 123 124 125 126 127
enum fa100m14b4c_fsm_state {
	FA100M14B4C_STATE_IDLE = 0x1,
	FA100M14B4C_STATE_PRE,
	FA100M14B4C_STATE_POST,
	FA100M14B4C_STATE_WAIT,
	FA100M14B4C_STATE_DECR,
128
};
129

130

131 132 133 134
#ifdef __KERNEL__ /* All the rest is only of kernel users */
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/workqueue.h>
135
#include <linux/debugfs.h>
Federico Vaga's avatar
Federico Vaga committed
136

137
#include <linux/fmc.h>
138
#include <linux/fmc-sdb.h>
139
#include <linux/zio.h>
140 141 142
#include <linux/zio-dma.h>
#include <linux/zio-sysfs.h>
#include <linux/zio-buffer.h>
143 144 145 146
#include <linux/zio-trigger.h>

#include "field-desc.h"

147 148
extern int fa_enable_test_data_adc;

149 150 151 152
/*
 * ZFA_CHx_MULT : the trick which requires channel regs id grouped and ordered
 * address offset between two registers of the same type on consecutive channel
 */
153
#define ZFA_CHx_MULT 9
Federico Vaga's avatar
Federico Vaga committed
154

Federico Vaga's avatar
Federico Vaga committed
155 156 157 158 159 160 161 162 163 164 165
/* Device registers */
enum zfadc_dregs_enum {
	/* Device */
	/* Control registers */
	ZFA_CTL_FMS_CMD,
	ZFA_CTL_CLK_EN,
	ZFA_CTL_DAC_CLR_N,
	ZFA_CTL_BSLIP,
	ZFA_CTL_TEST_DATA_EN,
	ZFA_CTL_TRIG_LED,
	ZFA_CTL_ACQ_LED,
166
	ZFA_CTL_RST_TRG_STA,
Federico Vaga's avatar
Federico Vaga committed
167 168 169 170 171
	/* Status registers */
	ZFA_STA_FSM,
	ZFA_STA_SERDES_PLL,
	ZFA_STA_SERDES_SYNCED,
	/* Configuration register */
172 173 174
	ZFAT_CFG_STA,
	ZFAT_CFG_SRC,
	ZFAT_CFG_POL,
Federico Vaga's avatar
Federico Vaga committed
175
	/* Delay*/
176
	ZFAT_EXT_DLY,
Federico Vaga's avatar
Federico Vaga committed
177 178 179 180
	/* Software */
	ZFAT_SW,
	/* Number of shots */
	ZFAT_SHOTS_NB,
181 182
	/* Remaining shots counter */
	ZFAT_SHOTS_REM,
Federico Vaga's avatar
Federico Vaga committed
183
	/* Sample rate */
184
	ZFAT_SR_UNDER,
185 186
	/* Sampling clock frequency */
	ZFAT_SAMPLING_HZ,
Federico Vaga's avatar
Federico Vaga committed
187 188 189 190 191 192 193 194
	/* Position address */
	ZFAT_POS,
	/* Pre-sample */
	ZFAT_PRE,
	/* Post-sample */
	ZFAT_POST,
	/* Sample counter */
	ZFAT_CNT,
195 196
	/* Pattern data for the ADC chip */
	ZFAT_ADC_TST_PATTERN,
197
	/* start:declaration block requiring some order */
Federico Vaga's avatar
Federico Vaga committed
198 199
	/* Channel 1 */
	ZFA_CH1_CTL_RANGE,
200
	ZFA_CH1_CTL_TERM,
Federico Vaga's avatar
Federico Vaga committed
201 202 203
	ZFA_CH1_STA,
	ZFA_CH1_GAIN,
	ZFA_CH1_OFFSET,
204
	ZFA_CH1_SAT,
205 206 207 208
	ZFA_CH1_THRES,
	ZFA_CH1_HYST,
	ZFA_CH1_DLY,

Federico Vaga's avatar
Federico Vaga committed
209 210
	/* Channel 2 */
	ZFA_CH2_CTL_RANGE,
211
	ZFA_CH2_CTL_TERM,
Federico Vaga's avatar
Federico Vaga committed
212 213 214
	ZFA_CH2_STA,
	ZFA_CH2_GAIN,
	ZFA_CH2_OFFSET,
215
	ZFA_CH2_SAT,
216 217 218 219
	ZFA_CH2_THRES,
	ZFA_CH2_HYST,
	ZFA_CH2_DLY,

Federico Vaga's avatar
Federico Vaga committed
220 221
	/* Channel 3 */
	ZFA_CH3_CTL_RANGE,
222
	ZFA_CH3_CTL_TERM,
Federico Vaga's avatar
Federico Vaga committed
223 224 225
	ZFA_CH3_STA,
	ZFA_CH3_GAIN,
	ZFA_CH3_OFFSET,
226
	ZFA_CH3_SAT,
227 228 229 230
	ZFA_CH3_THRES,
	ZFA_CH3_HYST,
	ZFA_CH3_DLY,

Federico Vaga's avatar
Federico Vaga committed
231 232
	/* Channel 4 */
	ZFA_CH4_CTL_RANGE,
233
	ZFA_CH4_CTL_TERM,
Federico Vaga's avatar
Federico Vaga committed
234 235 236
	ZFA_CH4_STA,
	ZFA_CH4_GAIN,
	ZFA_CH4_OFFSET,
237
	ZFA_CH4_SAT,
238 239 240 241
	ZFA_CH4_THRES,
	ZFA_CH4_HYST,
	ZFA_CH4_DLY,

242 243 244 245 246 247 248
	/*
	 * CHx__ are specifc ids used by some internal arithmetic
	 * Be carefull: the arithmetic expects
	 * that ch1 to ch4 are declared in the enum just above
	 * in the right order and grouped.
	 * Don't insert any other id in this area
	 */
Federico Vaga's avatar
Federico Vaga committed
249
	ZFA_CHx_CTL_RANGE,
250
	ZFA_CHx_CTL_TERM,
Federico Vaga's avatar
Federico Vaga committed
251 252 253
	ZFA_CHx_STA,
	ZFA_CHx_GAIN,
	ZFA_CHx_OFFSET,
254
	ZFA_CHx_SAT,
255 256 257
	ZFA_CHx_THRES,
	ZFA_CHx_HYST,
	ZFA_CHx_DLY,
258 259
	/* Other options */
	ZFA_MULT_MAX_SAMP,
260 261 262 263 264 265 266 267 268 269
	/* end:declaration block requiring some order */
	/* two wishbone core for IRQ: VIC, ADC */
	ZFA_IRQ_ADC_DISABLE_MASK,
	ZFA_IRQ_ADC_ENABLE_MASK,
	ZFA_IRQ_ADC_MASK_STATUS,
	ZFA_IRQ_ADC_SRC,
	ZFA_IRQ_VIC_CTRL,
	ZFA_IRQ_VIC_DISABLE_MASK,
	ZFA_IRQ_VIC_ENABLE_MASK,
	ZFA_IRQ_VIC_MASK_STATUS,
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
	/* UTC core */
	ZFA_UTC_SECONDS,
	ZFA_UTC_COARSE,
	ZFA_UTC_TRIG_META,
	ZFA_UTC_TRIG_SECONDS,
	ZFA_UTC_TRIG_COARSE,
	ZFA_UTC_TRIG_FINE,
	ZFA_UTC_ACQ_START_META,
	ZFA_UTC_ACQ_START_SECONDS,
	ZFA_UTC_ACQ_START_COARSE,
	ZFA_UTC_ACQ_START_FINE,
	ZFA_UTC_ACQ_STOP_META,
	ZFA_UTC_ACQ_STOP_SECONDS,
	ZFA_UTC_ACQ_STOP_COARSE,
	ZFA_UTC_ACQ_STOP_FINE,
	ZFA_UTC_ACQ_END_META,
	ZFA_UTC_ACQ_END_SECONDS,
	ZFA_UTC_ACQ_END_COARSE,
	ZFA_UTC_ACQ_END_FINE,
289 290 291
	ZFA_HW_PARAM_COMMON_LAST,
};

292 293 294 295 296

/*
 * Acquisition metadata. It contains the trigger timestamp and the trigger
 * source. This block is added after the post-trigger-samples in the DDR.
 */
297
#define FA_TRIG_TIMETAG_BYTES 0x10
298

299 300 301 302 303 304 305 306
/*
 * ADC parameter id not mapped to Hw register
 * Id is used as zio attribute id
 */
enum fa_sw_param_id {
	/* to guarantee unique zio attr id */
	ZFA_SW_R_NOADDRES_NBIT = ZFA_HW_PARAM_COMMON_LAST,

307
	ZFA_SW_R_NOADDRES_TEMP,
308
	ZFA_SW_R_NOADDERS_AUTO,
309 310 311 312
	ZFA_SW_CH1_OFFSET_ZERO,
	ZFA_SW_CH2_OFFSET_ZERO,
	ZFA_SW_CH3_OFFSET_ZERO,
	ZFA_SW_CH4_OFFSET_ZERO,
313
	ZFA_SW_PARAM_COMMON_LAST,
Federico Vaga's avatar
Federico Vaga committed
314
};
315

316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
/*
 * Bit pattern used in order to factorize code  between SVEC and SPEC
 * Depending of the carrier, ADC may have to listen vaious IRQ sources
 * SVEC: only ACQ irq source (end DMA irq is manged by vmebus driver)
 * SPEC: ACQ and DMA irq source
 */
enum fa_irq_src {
	FA_IRQ_SRC_ACQ = 0x1,
	FA_IRQ_SRC_DMA = 0x2,
};

/* adc IRQ values */
enum fa_irq_adc {
	FA_IRQ_ADC_NONE =	0x0,
	FA_IRQ_ADC_ACQ_END =	0x2,
Federico Vaga's avatar
Federico Vaga committed
331 332
};

333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
/* Carrier-specific operations (gateware does not fully decouple
   carrier specific stuff, such as DMA or resets, from
   mezzanine-specific operations). */
struct fa_dev; /* forward declaration */
struct fa_carrier_op {
	char* (*get_gwname)(void);
	int (*init) (struct fa_dev *);
	int (*reset_core) (struct fa_dev *);
	void (*exit) (struct fa_dev *);
	int (*setup_irqs) (struct fa_dev *);
	int (*free_irqs) (struct fa_dev *);
	int (*enable_irqs) (struct fa_dev *);
	int (*disable_irqs) (struct fa_dev *);
	int (*ack_irq) (struct fa_dev *, int irq_id);
	int (*dma_start)(struct zio_cset *cset);
	void (*dma_done)(struct zio_cset *cset);
	void (*dma_error)(struct zio_cset *cset);
};
Federico Vaga's avatar
Federico Vaga committed
351

352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
/* ADC and DAC Calibration, from  EEPROM */
struct fa_calib_stanza {
	int16_t offset[4]; /* One per channel */
	uint16_t gain[4];  /* One per channel */
	uint16_t temperature;
};

struct fa_calib {
	struct fa_calib_stanza adc[3];  /* For input, one per range */
	struct fa_calib_stanza dac[3];  /* For user offset, one per range */
};

/*
 * fa_dev: is the descriptor of the FMC ADC mezzanine
 *
 * @fmc: the pointer to the fmc_device generic structure
 * @zdev: is the pointer to the real zio_device in use
 * @hwzdev: is the pointer to the fake zio_device, used to initialize and
 *          to remove a zio_device
 *
 * @n_shots: total number of programmed shots for an acquisition
 * @n_fires: number of trigger fire occurred within an acquisition
 *
 * @n_dma_err: number of errors
376 377
 * @user_offset: user offset (micro-Volts)
 * @zero_offset: necessary offset to push the channel to zero (micro-Volts)
378 379
 */
struct fa_dev {
380
	struct device *msgdev; /**< device used to print messages */
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
	/* the pointer to the fmc_device generic structure */
	struct fmc_device	*fmc;
	/* the pointer to the real zio_device in use */
	struct zio_device	*zdev;
	/* the pointer to the fake zio_device, used for init/remove */
	struct zio_device	*hwzdev;

	/* carrier common base offset addresses obtained from SDB */
	unsigned int fa_adc_csr_base;
	unsigned int fa_spi_base;
	unsigned int fa_ow_base;
	unsigned int fa_carrier_csr_base;
	unsigned int fa_irq_vic_base;
	unsigned int fa_irq_adc_base;
	unsigned int fa_utc_base;

397
	/* DMA description */
398
	struct zio_dma_sgt *zdma;
399

400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
	/* carrier specific functions (init/exit/reset/readout/irq handling) */
	struct fa_carrier_op *carrier_op;
	/* carrier private data */
	void *carrier_data;
	int irq_src; /* list of irq sources to listen */
	struct work_struct irq_work;
	/*
	 * keep last core having fired an IRQ
	 * Used to check irq sequence: ACQ followed by DMA
	 */
	int last_irq_core_src;

	/* Acquisition */
	unsigned int		n_shots;
	unsigned int		n_fires;
415
	unsigned int		mshot_max_samples;
416 417 418 419 420

	/* Statistic informations */
	unsigned int		n_dma_err;

	/* Configuration */
421 422
	int32_t		user_offset[4]; /* one per channel */
	int32_t		zero_offset[FA100M14B4C_NCHAN];
423 424 425 426 427 428 429 430 431 432
	/* one-wire */
	uint8_t ds18_id[8];
	unsigned long		next_t;
	int			temp;	/* temperature: scaled by 4 bits */

	/* Calibration Data */
	struct fa_calib calib;

	/* flag  */
	int enable_auto_start;
433

434
	struct dentry *reg_dump;
435
};
436

437 438 439 440 441 442 443 444 445 446 447 448 449
/*
 * zfad_block
 * @block is zio_block which contains data and metadata from a single shot
 * @dev_mem_off is the offset in ADC internal memory. It points to the first
 *              sample of the stored shot
 * @first_nent is the index of the first nent used for this block
 */
struct zfad_block {
	struct zio_block *block;
	uint32_t	dev_mem_off;
	unsigned int first_nent;
};

450 451 452 453 454
/*
 * Channel signal transmission delay
 * Trigger and channel signals are not going through the
 * same path on the board and trigger is faster.
 * Trying to sample the trigger itself by connecting
455
 * it to a channel, one can see a delay of 30ns between trigger and
456 457
 * its sampling. This constant is added to the trigger delay to
 * conpensate the channel signal transmission delay.
458
 * Expressed in tick count 3*10ns = 30ns
459
 */
460
#define FA_CH_TX_DELAY		3
461
#define FA_CAL_OFFSET		0x0100 /* Offset in EEPROM */
462 463 464 465 466 467 468 469 470

#define FA_CAL_NO_OFFSET	((int16_t)0x0000)
#define FA_CAL_NO_GAIN		((uint16_t)0x8000)

/* SPI Slave Select lines (as defined in spec_top_fmc_adc_100Ms.vhd) */
#define FA_SPI_SS_ADC		0
#define FA_SPI_SS_DAC(ch)	((ch) + 1)

/* Global variable exported by fa-zio-trg.c */
471 472 473
extern struct zio_trigger_type zfat_type;


474
static inline struct fa_dev *get_zfadc(struct device *dev)
Federico Vaga's avatar
Federico Vaga committed
475 476
{
	switch (to_zio_head(dev)->zobj_type) {
477
		case ZIO_DEV:
Federico Vaga's avatar
Federico Vaga committed
478
			return to_zio_dev(dev)->priv_d;
479
		case ZIO_CSET:
Federico Vaga's avatar
Federico Vaga committed
480
			return to_zio_cset(dev)->zdev->priv_d;
481
		case ZIO_CHAN:
Federico Vaga's avatar
Federico Vaga committed
482
			return to_zio_chan(dev)->cset->zdev->priv_d;
483
		case ZIO_TI:
Federico Vaga's avatar
Federico Vaga committed
484 485 486 487 488 489 490
			return to_zio_ti(dev)->cset->zdev->priv_d;
		default:
			return NULL;
	}
	return NULL;
}

491 492 493 494 495 496 497 498 499 500
static inline u32 fa_ioread(struct fa_dev *fa, unsigned long addr)
{
	return fmc_readl(fa->fmc, addr);
}

static inline void fa_iowrite(struct fa_dev *fa, u32 value, unsigned long addr)
{
	fmc_writel(fa->fmc, value, addr);
}

501 502 503
static inline uint32_t fa_readl(struct fa_dev *fa,
				unsigned int base_off,
				const struct zfa_field_desc *field)
Federico Vaga's avatar
Federico Vaga committed
504
{
505
	uint32_t cur;
Federico Vaga's avatar
Federico Vaga committed
506

507
	cur = fa_ioread(fa, base_off+field->offset);
508 509 510 511 512 513
	if (field->is_bitfield) {
		/* apply mask and shift right accordlying to the mask */
		cur &= field->mask;
		cur /= (field->mask & -(field->mask));
	} else {
		cur &= field->mask; /* bitwise and with the mask */
Federico Vaga's avatar
Federico Vaga committed
514
	}
515
	return cur;
Federico Vaga's avatar
Federico Vaga committed
516
}
517 518 519 520 521

static inline void fa_writel(struct fa_dev *fa,
				unsigned int base_off,
				const struct zfa_field_desc *field,
				uint32_t usr_val)
Federico Vaga's avatar
Federico Vaga committed
522
{
523
	uint32_t cur, val;
Federico Vaga's avatar
Federico Vaga committed
524

525 526 527
	val = usr_val;
	/* Read current register value first if it's a bitfield */
	if (field->is_bitfield) {
528
		cur = fa_ioread(fa, base_off+field->offset);
529 530 531
		/* */
		cur &= ~field->mask; /* clear bits according to the mask */
		val = usr_val * (field->mask & -(field->mask));
532
		if (val & ~field->mask)
533
			dev_warn(fa->msgdev,
534
				"addr 0x%lx: value 0x%x doesn't fit mask 0x%x\n",
535 536
				base_off+field->offset, val, field->mask);
		val &= field->mask;
537 538
		val |= cur;
	}
539
	fa_iowrite(fa, val, base_off+field->offset);
Federico Vaga's avatar
Federico Vaga committed
540 541
}

542 543 544
/* Global variable exported by fa-core.c */
extern struct workqueue_struct *fa_workqueue;

545 546 547 548 549 550 551 552 553
/* Global variable exported by fa-spec.c */
extern struct fa_carrier_op fa_spec_op;

/* Global variable exported by fa-svec.c */
extern struct fa_carrier_op fa_svec_op;

/* Global variable exported by fa-regfield.c */
extern const struct zfa_field_desc zfad_regs[];

554 555
/* Functions exported by fa-core.c */
extern int zfad_fsm_command(struct fa_dev *fa, uint32_t command);
556
extern int zfad_apply_offset(struct zio_channel *chan);
557 558 559 560 561
extern void zfad_reset_offset(struct fa_dev *fa);
extern int zfad_convert_hw_range(uint32_t bitmask);
extern int zfad_set_range(struct fa_dev *fa, struct zio_channel *chan,
			  int range);
extern int zfad_get_chx_index(unsigned long addr, struct zio_channel *chan);
562 563
extern int zfad_pattern_data_enable(struct fa_dev *fa, uint16_t pattern,
				    unsigned int enable);
564

565
/* Functions exported by fa-zio-drv.c */
Federico Vaga's avatar
Federico Vaga committed
566 567
extern int fa_zio_register(void);
extern void fa_zio_unregister(void);
568 569
extern int fa_zio_init(struct fa_dev *fa);
extern void fa_zio_exit(struct fa_dev *fa);
Federico Vaga's avatar
Federico Vaga committed
570

571 572 573 574
/* Functions exported by fa-zio-trg.c */
extern int fa_trig_init(void);
extern void fa_trig_exit(void);

575 576 577 578 579 580 581 582 583 584
/* Functions exported by fa-irq.c */
extern int zfad_dma_start(struct zio_cset *cset);
extern void zfad_dma_done(struct zio_cset *cset);
extern void zfad_dma_error(struct zio_cset *cset);
extern void zfat_irq_trg_fire(struct zio_cset *cset);
extern void zfat_irq_acq_end(struct zio_cset *cset);
extern int fa_setup_irqs(struct fa_dev *fa);
extern int fa_free_irqs(struct fa_dev *fa);
extern int fa_enable_irqs(struct fa_dev *fa);
extern int fa_disable_irqs(struct fa_dev *fa);
585

586
/* Functions exported by onewire.c */
587 588
extern int fa_onewire_init(struct fa_dev *fa);
extern void fa_onewire_exit(struct fa_dev *fa);
589
extern int fa_read_temp(struct fa_dev *fa, int verbose);
590

Federico Vaga's avatar
Federico Vaga committed
591 592 593 594 595
/* functions exported by spi.c */
extern int fa_spi_xfer(struct fa_dev *fa, int cs, int num_bits,
		       uint32_t tx, uint32_t *rx);
extern int fa_spi_init(struct fa_dev *fd);
extern void fa_spi_exit(struct fa_dev *fd);
596 597 598 599 600

/* fmc extended function */
signed long fmc_find_sdb_device_ext(struct sdb_array *tree,
					uint64_t vid, uint32_t did, int index,
					unsigned long *sz);
Federico Vaga's avatar
Federico Vaga committed
601

602 603 604
/* function exporetd by fa-calibration.c */
extern void fa_read_eeprom_calib(struct fa_dev *fa);

605 606 607 608 609
/* functions exported by fa-debug.c */
extern int fa_debug_init(struct fa_dev *fa);
extern void fa_debug_exit(struct fa_dev *fa);


Federico Vaga's avatar
Federico Vaga committed
610
#endif /* __KERNEL__ */
Alessandro Rubini's avatar
Alessandro Rubini committed
611
#endif /*  FMC_ADC_H_ */