2 * Copyright (C) 2012 CERN (www.cern.ch)
3 * Author: Alessandro Rubini <rubini@gnudd.com>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * The software is provided "as is"; the copyright holders disclaim
10 * all warranties and liabilities, to the extent permitted by
14 /* A trivial fmc driver that can load a gateware file and reports interrupts */
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/gpio.h>
19 #include <linux/fmc.h>
21 static struct fmc_driver t_drv
; /* initialized later */
23 static irqreturn_t
t_handler(int irq
, void *dev_id
)
25 struct fmc_device
*fmc
= dev_id
;
27 fmc
->op
->irq_ack(fmc
);
28 dev_info(&fmc
->dev
, "received irq %i\n", irq
);
32 static struct fmc_gpio t_gpio
[] = {
34 .gpio
= FMC_GPIO_IRQ(0),
36 .irqmode
= IRQF_TRIGGER_RISING
,
38 .gpio
= FMC_GPIO_IRQ(1),
40 .irqmode
= IRQF_TRIGGER_RISING
,
44 static int t_probe(struct fmc_device
*fmc
)
49 if (fmc
->op
->validate
)
50 index
= fmc
->op
->validate(fmc
, &t_drv
);
52 return -EINVAL
; /* not our device: invalid */
54 ret
= fmc
->op
->irq_request(fmc
, t_handler
, "fmc-trivial", IRQF_SHARED
);
57 /* ignore error code of call below, we really don't care */
58 fmc
->op
->gpio_config(fmc
, t_gpio
, ARRAY_SIZE(t_gpio
));
60 /* Reprogram, if asked to. ESRCH == no filename specified */
62 if (fmc
->op
->reprogram
)
63 ret
= fmc
->op
->reprogram(fmc
, &t_drv
, "");
67 fmc
->op
->irq_free(fmc
);
69 /* FIXME: reprogram LM32 too */
73 static int t_remove(struct fmc_device
*fmc
)
75 fmc
->op
->irq_free(fmc
);
79 static struct fmc_driver t_drv
= {
80 .version
= FMC_VERSION
,
81 .driver
.name
= KBUILD_MODNAME
,
84 /* no table, as the current match just matches everything */
87 /* We accept the generic parameters */
88 FMC_PARAM_BUSID(t_drv
);
89 FMC_PARAM_GATEWARE(t_drv
);
91 static int t_init(void)
95 ret
= fmc_driver_register(&t_drv
);
99 static void t_exit(void)
101 fmc_driver_unregister(&t_drv
);
107 MODULE_LICENSE("Dual BSD/GPL");