fa-core.c 16.6 KB
Newer Older
Federico Vaga's avatar
Federico Vaga committed
1
/*
2
 * core fmc-adc-100m14b driver
Federico Vaga's avatar
Federico Vaga committed
3 4 5 6 7 8 9 10 11 12
 *
 * Copyright (C) 2012 CERN (www.cern.ch)
 * Author: Federico Vaga <federico.vaga@gmail.com>
 *		Copied from fine-delay fd-core.c
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
13
#include <linux/version.h>
14

15
#include "fmc-adc-100m14b4cha.h"
Federico Vaga's avatar
Federico Vaga committed
16

17
/* Module parameters */
18
static struct fmc_driver fa_dev_drv;
19
FMC_PARAM_BUSID(fa_dev_drv);
20
FMC_PARAM_GATEWARE(fa_dev_drv);
21

22 23
static int fa_enable_test_data_fpga;
module_param_named(enable_test_data_fpga, fa_enable_test_data_fpga, int, 0444);
24
int fa_enable_test_data_adc = 0;
25
module_param_named(enable_test_data_adc, fa_enable_test_data_adc, int, 0444);
26

27
static const int zfad_hw_range[] = {
28 29 30 31
	[FA100M14B4C_RANGE_10V]   = 0x45,
	[FA100M14B4C_RANGE_1V]    = 0x11,
	[FA100M14B4C_RANGE_100mV] = 0x23,
	[FA100M14B4C_RANGE_OPEN]  = 0x00,
32 33
};

34 35 36
/* fmc-adc specific workqueue */
struct workqueue_struct *fa_workqueue;

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
/*
 * zfad_convert_hw_range
 * @usr_val: range value
 *
 * return the enum associated to the range value
 */
int zfad_convert_hw_range(uint32_t bitmask)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(zfad_hw_range); i++)
		if (zfad_hw_range[i] == bitmask)
			return i;
	return -EINVAL;
}

53 54
/* Calculate correct index in fa_regfield array for channel from CHx indexes */
int zfad_get_chx_index(unsigned long addr, struct zio_channel *chan)
55 56 57
{
	int offset;

58
	offset = ZFA_CHx_MULT  * (FA100M14B4C_NCHAN - chan->index);
59 60 61 62

	return addr - offset;
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

/**
 * It enables or disables the pattern data on the ADC
 * @fa The ADC device instance
 * @pattern the pattern data to get from the ADC
 * @enable 0 to disable, 1 to enable
 */
int zfad_pattern_data_enable(struct fa_dev *fa, uint16_t pattern,
			     unsigned int enable)
{
	uint32_t frame_tx;
	int err;

	frame_tx  = 0x0000; /* write mode */
	frame_tx |= 0x0400; /* A4 pattern */
	frame_tx |= pattern & 0xFF; /* LSB pattern */
	err = fa_spi_xfer(fa, FA_SPI_SS_ADC, 16, frame_tx, NULL);
	if (err)
		return err;

	frame_tx  = 0x0000; /* write mode */
	frame_tx |= 0x0300; /* A3 pattern + enable */
	frame_tx |= (pattern & 0xFF00) >> 8; /* MSB pattern */
	frame_tx |= (enable ? 0x80 : 0x00); /* Enable the pattern data */
	err = fa_spi_xfer(fa, FA_SPI_SS_ADC, 16, frame_tx, NULL);
	if (err)
		return err;

	return 0;
}

94 95 96 97 98 99 100 101 102 103 104 105 106 107
/**
 * It sets the DAC voltage to apply an offset on the input channel
 * @chan
 * @val DAC values (-5V: 0x0000, 0V: 0x8000, +5V: 0x7FFF)
 *
 * Return: 0 on success, otherwise a negative error number
 */
static int zfad_dac_set(struct zio_channel *chan, uint32_t val)
{
	struct fa_dev *fa = get_zfadc(&chan->cset->zdev->head.dev);

	return fa_spi_xfer(fa, FA_SPI_SS_DAC(chan->index), 16, val, NULL);
}

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/*
 * zfad_apply_user_offset
 * @fa: the fmc-adc descriptor
 * @chan: the channel where apply offset
 * @usr_val: the offset value to apply, expressed as millivolts (-5000..5000)
 *
 * Apply user offset to the channel input. Before apply the user offset it must
 * be corrected with offset and gain calibration value. An open input does not
 * need any correction.
 */
int zfad_apply_user_offset(struct fa_dev *fa, struct zio_channel *chan,
				  uint32_t usr_val)
{
	uint32_t range_reg;
	int32_t uval =  (int32_t)usr_val;
	int offset, gain, hwval, i, range;

	if (uval < -5000 || uval > 5000)
		return -EINVAL;

	i = zfad_get_chx_index(ZFA_CHx_CTL_RANGE, chan);
129
	range_reg = fa_readl(fa, fa->fa_adc_csr_base, &zfad_regs[i]);
130 131 132 133 134

	range = zfad_convert_hw_range(range_reg);
	if (range < 0)
		return range;

135
	if (range == FA100M14B4C_RANGE_OPEN || fa_enable_test_data_adc) {
136
		range = FA100M14B4C_RANGE_1V;
137 138
	}

139 140 141
	offset = fa->calib.dac[range].offset[chan->index];
	gain = fa->calib.dac[range].gain[chan->index];

142
	hwval = uval * 0x8000 / 5000;
143 144
	if (hwval == 0x8000)
		hwval = 0x7fff; /* -32768 .. 32767 */
145 146 147 148 149 150 151 152

	hwval = ((hwval + offset) * gain) >> 15; /* signed */
	hwval += 0x8000; /* offset binary */
	if (hwval < 0)
		hwval = 0;
	if (hwval > 0xffff)
		hwval = 0xffff;

153
	return zfad_dac_set(chan, hwval);
154 155 156 157 158 159 160 161 162 163 164 165
}

/*
 * zfad_reset_offset
 * @fa: the fmc-adc descriptor
 *
 * Reset channel's offsets
 */
void zfad_reset_offset(struct fa_dev *fa)
{
	int i;

166
	for (i = 0; i < FA100M14B4C_NCHAN; ++i)
167 168 169
		zfad_apply_user_offset(fa, &fa->zdev->cset->chan[i], 0);
}

170 171 172 173 174 175 176 177 178 179
/*
 * zfad_init_saturation
 * @fa: the fmc-adc descriptor
 *
 * Initialize all saturation registers to the maximum value
 */
void zfad_init_saturation(struct fa_dev *fa)
{
	int idx, i;

180
	for (i = 0, idx = ZFA_CH1_SAT; i < FA100M14B4C_NCHAN; ++i, idx += ZFA_CHx_MULT)
181 182 183
		fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[idx], 0x7fff);
}

184 185 186 187 188 189
/*
 * zfad_set_range
 * @fa: the fmc-adc descriptor
 * @chan: the channel to calibrate
 * @usr_val: the volt range to set and calibrate
 *
190 191 192
 * When the input range changes, we must write new fixup values.
 * Gain ad offsets must be corrected with offset and gain calibration value.
 * An open input and test data do not need any correction.
193 194 195 196 197 198 199 200
 */
int zfad_set_range(struct fa_dev *fa, struct zio_channel *chan,
			  int range)
{
	int i, offset, gain;

	/* Actually set the range */
	i = zfad_get_chx_index(ZFA_CHx_CTL_RANGE, chan);
201
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[i], zfad_hw_range[range]);
202

203 204 205 206 207 208 209
	if (range == FA100M14B4C_RANGE_OPEN || fa_enable_test_data_adc) {
		/*
		 * With OPEN range we do not use calibration values
		 *
		 * In test mode we do not apply the gain/offset because
		 * this compromises the test pattern
		 */
210 211 212 213
		offset = FA_CAL_NO_OFFSET;
		gain = FA_CAL_NO_GAIN;
	} else {
		if (range < 0 || range > ARRAY_SIZE(fa->calib.adc)) {
214
			dev_info(fa->msgdev, "Invalid range %i or ch %i\n",
215 216 217 218 219 220 221 222
				 range, chan->index);
			return -EINVAL;
		}
		offset = fa->calib.adc[range].offset[chan->index];
		gain = fa->calib.adc[range].gain[chan->index];
	}

	i = zfad_get_chx_index(ZFA_CHx_OFFSET, chan);
223
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[i],
Federico Vaga's avatar
Federico Vaga committed
224
		  offset & 0xffff /* prevent warning */);
225
	i = zfad_get_chx_index(ZFA_CHx_GAIN, chan);
226
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[i], gain);
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

	/* recalculate user offset for the new range */
	zfad_apply_user_offset(fa, chan, fa->user_offset[chan->index]);

	return 0;
}

/*
 * zfad_fsm_command
 * @fa: the fmc-adc descriptor
 * @command: the command to apply to FSM
 *
 * This function checks if the command can be done and performs some
 * preliminary operation beforehand
 */
int zfad_fsm_command(struct fa_dev *fa, uint32_t command)
{
	struct zio_cset *cset = fa->zdev->cset;
	uint32_t val;

Federico Vaga's avatar
Federico Vaga committed
247 248
	if (command != FA100M14B4C_CMD_START &&
	    command != FA100M14B4C_CMD_STOP) {
249
		dev_info(fa->msgdev, "Invalid command %i\n", command);
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
		return -EINVAL;
	}

	/*
	 * When any command occurs we are ready to start a new acquisition, so
	 * we must abort any previous one. If it is STOP, we abort because we
	 * abort an acquisition. If it is START, we abort because if there was
	 * a previous start but the acquisition end interrupt doesn't occurs,
	 * START mean RESTART. If it is a clean START, the abort has not
	 * effects.
	 *
	 * This is done only if ADC is using its own trigger, otherwise it is
	 * not necessary.
	 *
	 * The case of fmc-adc-trg is optimized because is the most common
	 * case
	 */
267
	if (likely(cset->trig == &zfat_type || command == FA100M14B4C_CMD_STOP))
268 269 270 271 272 273 274
		zio_trigger_abort_disable(cset, 0);

	/* Reset counters */
	fa->n_shots = 0;
	fa->n_fires = 0;

	/* If START, check if we can start */
275
	if (command == FA100M14B4C_CMD_START) {
276
		/* Verify that SerDes PLL is lockes */
277 278
		val = fa_readl(fa, fa->fa_adc_csr_base,
			       &zfad_regs[ZFA_STA_SERDES_PLL]);
279
		if (!val) {
280
			dev_info(fa->msgdev, "Cannot start acquisition: "
281 282 283 284
				 "SerDes PLL not locked\n");
			return -EBUSY;
		}
		/* Verify that SerDes is synched */
285 286
		val = fa_readl(fa, fa->fa_adc_csr_base,
			       &zfad_regs[ZFA_STA_SERDES_SYNCED]);
287
		if (!val) {
288
			dev_info(fa->msgdev, "Cannot start acquisition: "
289 290 291 292 293 294 295 296 297 298 299 300 301 302
				 "SerDes not synchronized\n");
			return -EBUSY;
		}

		/* Now we can arm the trigger for the incoming acquisition */
		zio_arm_trigger(cset->ti);
		/*
		 *  FIXME maybe zio_arm_trigger() can return an error when it
		 * is not able to arm a trigger.
		 *
		 * It returns -EPERM, but the error can be -ENOMEM or -EINVAL
		 * from zfat_arm_trigger() or zfad_input_cset()
		 */
		if (!(cset->ti->flags & ZIO_TI_ARMED)) {
303
			dev_info(fa->msgdev, "Cannot start acquisition: "
304 305 306 307
				 "Trigger refuses to arm\n");
			return -EIO;
		}

308
		dev_dbg(fa->msgdev, "FSM START Command, Enable interrupts\n");
309
		fa_enable_irqs(fa);
310

311 312
		fa_writel(fa, fa->fa_adc_csr_base,
			  &zfad_regs[ZFA_CTL_RST_TRG_STA], 1);
313
	} else {
314
		dev_dbg(fa->msgdev, "FSM STOP Command, Disable interrupts\n");
315
		fa->enable_auto_start = 0;
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
		fa_disable_irqs(fa);
	}

	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_CTL_FMS_CMD],
		  command);
	return 0;
}

/* Extract from SDB the base address of the core components */
/* which are not carrier specific */
static int __fa_sdb_get_device(struct fa_dev *fa)
{
	struct fmc_device *fmc = fa->fmc;
	int ret;

	ret = fmc_scan_sdb_tree(fmc, 0);
332 333 334 335 336
	if (ret == -EBUSY) {
		/* Not a problem, it's already there. We assume that
		   it's the correct one */
		ret = 0;
	}
337
	if (ret < 0) {
338
		dev_err(fa->msgdev,
339 340 341 342 343 344 345 346 347 348 349 350 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 376
			"%s: no SDB in the bitstream."
			"Are you sure you've provided the correct one?\n",
			KBUILD_MODNAME);
		return ret;
	}

	/* Now use SDB to find the base addresses */
	fa->fa_irq_vic_base = fmc_find_sdb_device(fmc->sdb, 0xce42,
						  0x13, NULL);
	fa->fa_adc_csr_base = fmc_find_sdb_device_ext(fmc->sdb, 0xce42,
						      0x608,
						      fmc->slot_id, NULL);
	fa->fa_irq_adc_base = fmc_find_sdb_device_ext(fmc->sdb, 0xce42,
						      0x26ec6086,
						      fmc->slot_id, NULL);
	fa->fa_utc_base = fmc_find_sdb_device_ext(fmc->sdb, 0xce42,
						  0x604, fmc->slot_id, NULL);
	fa->fa_spi_base = fmc_find_sdb_device_ext(fmc->sdb, 0xce42, 0xe503947e,
							fmc->slot_id, NULL);
	fa->fa_ow_base = fmc_find_sdb_device_ext(fmc->sdb, 0xce42, 0x779c5443,
							fmc->slot_id, NULL);

	return ret;
}

/*
 * Specific check and init
 */
static int __fa_init(struct fa_dev *fa)
{
	struct device *hwdev = fa->fmc->hwdev;
	struct zio_device *zdev = fa->zdev;
	int i, addr;

	/* Check if hardware supports 64-bit DMA */
	if (dma_set_mask(hwdev, DMA_BIT_MASK(64))) {
		/* Check if hardware supports 32-bit DMA */
		if (dma_set_mask(hwdev, DMA_BIT_MASK(32))) {
377
			dev_err(fa->msgdev, "32-bit DMA addressing not available\n");
378 379 380 381 382 383
			return -EINVAL;
		}
	}

	/* Retrieve calibration from the eeprom and validate*/
	fa_read_eeprom_calib(fa);
384 385
	fa->mshot_max_samples = fa_readl(fa, fa->fa_adc_csr_base,
					 &zfad_regs[ZFA_MULT_MAX_SAMP]);
386 387 388

	/* Force stop FSM to prevent early trigger fire */
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_CTL_FMS_CMD],
389
		   FA100M14B4C_CMD_STOP);
390 391 392 393 394
	/* Initialize channels to use 1V range */
	for (i = 0; i < 4; ++i) {
		addr = zfad_get_chx_index(ZFA_CHx_CTL_RANGE,
						&zdev->cset->chan[i]);
		fa_writel(fa,  fa->fa_adc_csr_base, &zfad_regs[addr],
395 396
			  FA100M14B4C_RANGE_1V);
		zfad_set_range(fa, &zdev->cset->chan[i], FA100M14B4C_RANGE_1V);
397 398 399 400 401 402
	}
	zfad_reset_offset(fa);

	/* Enable mezzanine clock */
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_CTL_CLK_EN], 1);
	/* Set decimation to minimum */
403
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFAT_SR_UNDER], 1);
404 405
	/* Set test data register */
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_CTL_TEST_DATA_EN],
406
		  fa_enable_test_data_fpga);
407

408 409
	/* Set to single shot mode by default */
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFAT_SHOTS_NB], 1);
410

411 412 413
	/* Enable the software trigger by default: there is no arm in this */
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFAT_CFG_SRC],
		  FA100M14B4C_TRG_SRC_SW);
414

415 416 417 418
	/* Zero offsets and release the DAC clear */
	zfad_reset_offset(fa);
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_CTL_DAC_CLR_N], 1);

419 420 421
	/* Initialize channel saturation values */
	zfad_init_saturation(fa);

422 423 424 425
	/* Set UTC seconds from the kernel seconds */
	fa_writel(fa, fa->fa_utc_base, &zfad_regs[ZFA_UTC_SECONDS],
		  get_seconds());

426
	fa_writel(fa, fa->fa_adc_csr_base, &zfad_regs[ZFAT_EXT_DLY], 0);
427

428 429
	/* disable auto_start */
	fa->enable_auto_start = 0;
430 431 432
	return 0;
}

433 434 435
/* This structure lists the various subsystems */
struct fa_modlist {
	char *name;
436 437
	int (*init)(struct fa_dev *);
	void (*exit)(struct fa_dev *);
438
};
439

440
static struct fa_modlist mods[] = {
Alessandro Rubini's avatar
Alessandro Rubini committed
441
	{"spi", fa_spi_init, fa_spi_exit},
442 443
	{"onewire", fa_onewire_init, fa_onewire_exit},
	{"zio", fa_zio_init, fa_zio_exit},
444
	{"debug", fa_debug_init, fa_debug_exit},
445 446 447
};

/* probe and remove are called by fa-spec.c */
448
int fa_probe(struct fmc_device *fmc)
Federico Vaga's avatar
Federico Vaga committed
449
{
450
	struct fa_modlist *m = NULL;
451
	struct fa_dev *fa;
452
	int err, i = 0;
453
	char *fwname;
Federico Vaga's avatar
Federico Vaga committed
454

455
	/* Validate the new FMC device */
456
	i = fmc_validate(fmc, &fa_dev_drv);
457
	if (i < 0) {
458
		dev_info(&fmc->dev, "not using \"%s\" according to "
459 460 461 462
			 "modparam\n", KBUILD_MODNAME);
		return -ENODEV;
	}

463
	/* Driver data */
464
	fa = devm_kzalloc(&fmc->dev, sizeof(struct fa_dev), GFP_KERNEL);
Federico Vaga's avatar
Federico Vaga committed
465 466
	if (!fa)
		return -ENOMEM;
467 468
	fmc_set_drvdata(fmc, fa);
	fa->fmc = fmc;
469
	fa->msgdev = &fa->fmc->dev;
Federico Vaga's avatar
Federico Vaga committed
470

471
	/* apply carrier-specific hacks and workarounds */
472 473
	fa->carrier_op = NULL;
	if (!strcmp(fmc->carrier_name, "SPEC")) {
474
		fa->carrier_op = &fa_spec_op;
475 476
	} else if (!strcmp(fmc->carrier_name, "SVEC")) {
#ifdef CONFIG_FMC_ADC_SVEC
Michel Arruat's avatar
Michel Arruat committed
477
		fa->carrier_op = &fa_svec_op;
478 479 480 481 482 483 484 485
#endif
	}

	/*
	 * Check if carrier operations exists. Otherwise it means that the
	 * driver was compiled without enable any carrier, so it cannot work
	 */
	if (!fa->carrier_op) {
486
		dev_err(fa->msgdev,
487 488
			"This binary doesn't support the '%s' carrier\n",
			fmc->carrier_name);
489 490 491
		return -ENODEV;
	}

492 493 494 495 496 497 498 499 500 501 502 503
	/*
	 * If the carrier is still using the golden bitstream or the user is
	 * asking for a particular one, then program our bistream, otherwise
	 * we already have our bitstream
	 */
	if (fmc->flags & FMC_DEVICE_HAS_GOLDEN || fa_dev_drv.gw_n) {
		if (fa_dev_drv.gw_n)
			fwname = ""; /* reprogram will pick from module parameter */
		else
			fwname = fa->carrier_op->get_gwname();

		/* We first write a new binary (and lm32) within the carrier */
504
		err = fmc_reprogram(fmc, &fa_dev_drv, fwname, 0x0);
505
		if (err) {
506
			dev_err(fa->msgdev, "write firmware \"%s\": error %i\n",
507
				fwname, err);
508 509 510
			goto out;
		}
	} else {
511
		dev_info(fa->msgdev,
512
			 "Gateware already there. Set the \"gateware\" parameter to overwrite the current gateware\n");
513 514
	}

515 516 517 518 519 520 521 522 523 524 525 526
	/* Extract whisbone core base address fron SDB */
	err = __fa_sdb_get_device(fa);
	if (err < 0)
		goto out;

	err = fa->carrier_op->init(fa);
	if (err < 0)
		goto out;

	err = fa->carrier_op->reset_core(fa);
	if (err < 0)
		goto out;
527

528 529
	/* init all subsystems */
	for (i = 0, m = mods; i < ARRAY_SIZE(mods); i++, m++) {
530
		dev_dbg(fa->msgdev, "Calling init for \"%s\"\n", m->name);
531 532
		err = m->init(fa);
		if (err) {
533
			dev_err(fa->msgdev, "error initializing %s\n", m->name);
534 535
			goto out;
		}
Federico Vaga's avatar
Federico Vaga committed
536
	}
537

538 539 540 541 542 543 544 545 546
	/* time to execute specific driver init */
	err = __fa_init(fa);
	if (err < 0)
		goto out;

	err = fa_setup_irqs(fa);
	if (err < 0)
		goto out;

547 548 549 550
	/* Pin the carrier */
	if (!try_module_get(fmc->owner))
		goto out_mod;

Federico Vaga's avatar
Federico Vaga committed
551
	return 0;
552

553 554
out_mod:
	fa_free_irqs(fa);
555 556 557 558 559
out:
	while (--m, --i >= 0)
		if (m->exit)
			m->exit(fa);
	return err;
Federico Vaga's avatar
Federico Vaga committed
560
}
561

562
int fa_remove(struct fmc_device *fmc)
Federico Vaga's avatar
Federico Vaga committed
563
{
564
	struct fa_dev *fa = fmc_get_drvdata(fmc);
565 566 567
	struct fa_modlist *m;
	int i = ARRAY_SIZE(mods);

568
	fa_free_irqs(fa);
569
	flush_workqueue(fa_workqueue);
570

571 572 573 574 575
	while (--i >= 0) {
		m = mods + i;
		if (m->exit)
			m->exit(fa);
	}
576

577 578
	fa->carrier_op->exit(fa);

579 580 581
	/* Release the carrier */
	module_put(fmc->owner);

582
	return 0;
Federico Vaga's avatar
Federico Vaga committed
583
}
584 585 586 587 588 589 590

static struct fmc_fru_id fa_fru_id[] = {
	{
		.product_name = "FmcAdc100m14b4cha",
	},
};

591
static struct fmc_driver fa_dev_drv = {
592
	.version = FMC_VERSION,
593 594 595
	.driver.name = KBUILD_MODNAME,
	.probe = fa_probe,
	.remove = fa_remove,
596 597 598 599
	.id_table = {
		.fru_id = fa_fru_id,
		.fru_id_nr = ARRAY_SIZE(fa_fru_id),
	},
600
};
Federico Vaga's avatar
Federico Vaga committed
601 602 603 604 605

static int fa_init(void)
{
	int ret;

606
	#if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0)
607
	fa_workqueue = alloc_workqueue(fa_dev_drv.driver.name,
Federico Vaga's avatar
Federico Vaga committed
608 609
					WQ_NON_REENTRANT | WQ_UNBOUND |
					WQ_MEM_RECLAIM, 1);
610 611 612 613
	#else
	fa_workqueue = alloc_workqueue(fa_dev_drv.driver.name,
				       WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
	#endif
614 615 616
	if (fa_workqueue == NULL)
		return -ENOMEM;

617 618
	/* First trigger and zio driver */
	ret = fa_trig_init();
619
	if (ret)
620
		goto out1;
621 622

	ret = fa_zio_register();
623 624 625
	if (ret)
		goto out2;

626 627
	/* Finally the fmc driver, whose probe instantiates zio devices */
	ret = fmc_driver_register(&fa_dev_drv);
628 629 630 631 632 633 634 635 636 637 638 639 640
	if (ret)
		goto out3;

	return ret;

out3:
	fa_zio_unregister();
out2:
	fa_trig_exit();
out1:
	destroy_workqueue(fa_workqueue);

	return ret;
Federico Vaga's avatar
Federico Vaga committed
641 642 643 644
}

static void fa_exit(void)
{
645
	fmc_driver_unregister(&fa_dev_drv);
646 647
	fa_zio_unregister();
	fa_trig_exit();
648 649
	if (fa_workqueue != NULL)
		destroy_workqueue(fa_workqueue);
Federico Vaga's avatar
Federico Vaga committed
650 651 652 653 654 655
}

module_init(fa_init);
module_exit(fa_exit);

MODULE_AUTHOR("Federico Vaga");
656
MODULE_DESCRIPTION("FMC-ADC-100MS-14b Linux Driver");
Federico Vaga's avatar
Federico Vaga committed
657
MODULE_LICENSE("GPL");
658
MODULE_VERSION(GIT_VERSION);
659

660
ADDITIONAL_VERSIONS;