Skip to content

Commit

Permalink
FMC: add a software mezzanine driver
Browse files Browse the repository at this point in the history
This simple do-nothing mezzanine driver shows how to write a mezzanine
driver, that can also handle interrupts reported by the carrier.

Signed-off-by: Alessandro Rubini <[email protected]>
Acked-by: Juan David Gonzalez Cobas <[email protected]>
Acked-by: Emilio G. Cota <[email protected]>
Acked-by: Samuel Iglesias Gonsalvez <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
rubini authored and gregkh committed Jun 18, 2013
1 parent 6c62a89 commit 056d83f
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Documentation/fmc/00-INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ identifiers.txt

fmc-fakedev.txt
- about drivers/fmc/fmc-fakedev.ko

fmc-trivial.txt
- about drivers/fmc/fmc-trivial.ko
17 changes: 17 additions & 0 deletions Documentation/fmc/fmc-trivial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fmc-trivial
===========

The simple module fmc-trivial is just a simple client that registers an
interrupt handler. I used it to verify the basic mechanism of the FMC
bus and how interrupts worked.

The module implements the generic FMC parameters, so it can program a
different gateware file in each card. The whole list of parameters it
accepts are:

`busid='
`gateware='
Generic parameters. See mezzanine.txt


This driver is worth reading, in my opinion.
7 changes: 7 additions & 0 deletions drivers/fmc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ config FMC_FAKEDEV
that can be rewritten at run time and usef for matching
mezzanines.

config FMC_TRIVIAL
tristate "FMC trivial mezzanine driver (software testing)"
help
This is a fake mezzanine driver, to show how FMC works and test it.
The driver also handles interrupts (we used it with a real carrier
before the mezzanines were produced)

endif # FMC
1 change: 1 addition & 0 deletions drivers/fmc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ fmc-y += fru-parse.o
fmc-y += fmc-dump.o

obj-$(CONFIG_FMC_FAKEDEV) += fmc-fakedev.o
obj-$(CONFIG_FMC_TRIVIAL) += fmc-trivial.o
107 changes: 107 additions & 0 deletions drivers/fmc/fmc-trivial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* The software is provided "as is"; the copyright holders disclaim
* all warranties and liabilities, to the extent permitted by
* applicable law.
*/

/* A trivial fmc driver that can load a gateware file and reports interrupts */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/fmc.h>

static struct fmc_driver t_drv; /* initialized later */

static irqreturn_t t_handler(int irq, void *dev_id)
{
struct fmc_device *fmc = dev_id;

fmc->op->irq_ack(fmc);
dev_info(&fmc->dev, "received irq %i\n", irq);
return IRQ_HANDLED;
}

static struct fmc_gpio t_gpio[] = {
{
.gpio = FMC_GPIO_IRQ(0),
.mode = GPIOF_DIR_IN,
.irqmode = IRQF_TRIGGER_RISING,
}, {
.gpio = FMC_GPIO_IRQ(1),
.mode = GPIOF_DIR_IN,
.irqmode = IRQF_TRIGGER_RISING,
}
};

static int t_probe(struct fmc_device *fmc)
{
int ret;
int index = 0;

if (fmc->op->validate)
index = fmc->op->validate(fmc, &t_drv);
if (index < 0)
return -EINVAL; /* not our device: invalid */

ret = fmc->op->irq_request(fmc, t_handler, "fmc-trivial", IRQF_SHARED);
if (ret < 0)
return ret;
/* ignore error code of call below, we really don't care */
fmc->op->gpio_config(fmc, t_gpio, ARRAY_SIZE(t_gpio));

/* Reprogram, if asked to. ESRCH == no filename specified */
ret = -ESRCH;
if (fmc->op->reprogram)
ret = fmc->op->reprogram(fmc, &t_drv, "");
if (ret == -ESRCH)
ret = 0;
if (ret < 0)
fmc->op->irq_free(fmc);

/* FIXME: reprogram LM32 too */
return ret;
}

static int t_remove(struct fmc_device *fmc)
{
fmc->op->irq_free(fmc);
return 0;
}

static struct fmc_driver t_drv = {
.version = FMC_VERSION,
.driver.name = KBUILD_MODNAME,
.probe = t_probe,
.remove = t_remove,
/* no table, as the current match just matches everything */
};

/* We accept the generic parameters */
FMC_PARAM_BUSID(t_drv);
FMC_PARAM_GATEWARE(t_drv);

static int t_init(void)
{
int ret;

ret = fmc_driver_register(&t_drv);
return ret;
}

static void t_exit(void)
{
fmc_driver_unregister(&t_drv);
}

module_init(t_init);
module_exit(t_exit);

MODULE_LICENSE("Dual BSD/GPL");

0 comments on commit 056d83f

Please sign in to comment.