From: Alessandro Rubini <rubini@gnudd.com>
To: linux-kernel@vger.kernel.org
Cc: Juan David Gonzalez Cobas <juan.david.gonzalez.cobas@cern.ch>,
"Emilio G. Cota" <cota@braap.org>,
Samuel Iglesias Gonsalvez <siglesias@igalia.com>,
gregkh@linuxfoundation.org, Rob Landley <rob@landley.net>,
linux-doc@vger.kernel.org
Subject: [PATCH 6/8] FMC: add a software mezzanine driver
Date: Wed, 12 Jun 2013 09:14:20 +0200 [thread overview]
Message-ID: <7be26b13f841e433176a5d77ca9de1dd964b153a.1371018406.git.rubini@gnudd.com> (raw)
In-Reply-To: <cover.1371018406.git.rubini@gnudd.com>
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 <rubini@gnudd.com>
Acked-by: Juan David Gonzalez Cobas <dcobas@cern.ch>
Acked-by: Emilio G. Cota <cota@braap.org>
Acked-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
---
Documentation/fmc/00-INDEX | 3 +
Documentation/fmc/fmc-trivial.txt | 17 ++++++
drivers/fmc/Kconfig | 7 +++
drivers/fmc/Makefile | 1 +
drivers/fmc/fmc-trivial.c | 101 +++++++++++++++++++++++++++++++++++++
5 files changed, 129 insertions(+), 0 deletions(-)
create mode 100644 Documentation/fmc/fmc-trivial.txt
create mode 100644 drivers/fmc/fmc-trivial.c
diff --git a/Documentation/fmc/00-INDEX b/Documentation/fmc/00-INDEX
index 34df5cf..c22d687 100644
--- a/Documentation/fmc/00-INDEX
+++ b/Documentation/fmc/00-INDEX
@@ -27,3 +27,6 @@ identifiers.txt
fmc-fakedev.txt
- about drivers/fmc/fmc-fakedev.ko
+
+fmc-trivial.txt
+ - about drivers/fmc/fmc-trivial.ko
diff --git a/Documentation/fmc/fmc-trivial.txt b/Documentation/fmc/fmc-trivial.txt
new file mode 100644
index 0000000..d1910bc
--- /dev/null
+++ b/Documentation/fmc/fmc-trivial.txt
@@ -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.
diff --git a/drivers/fmc/Kconfig b/drivers/fmc/Kconfig
index 505e96b..7eacef9 100644
--- a/drivers/fmc/Kconfig
+++ b/drivers/fmc/Kconfig
@@ -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
diff --git a/drivers/fmc/Makefile b/drivers/fmc/Makefile
index 9832b79..52624e6 100644
--- a/drivers/fmc/Makefile
+++ b/drivers/fmc/Makefile
@@ -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
diff --git a/drivers/fmc/fmc-trivial.c b/drivers/fmc/fmc-trivial.c
new file mode 100644
index 0000000..d91b28c
--- /dev/null
+++ b/drivers/fmc/fmc-trivial.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2012 CERN (www.cern.ch)
+ * Author: Alessandro Rubini <rubini@gnudd.com>
+ *
+ * Released to the public domain, as example to be reused
+ */
+
+/* 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("GPL and additional rights"); /* public domain */
--
1.7.7.2
next prev parent reply other threads:[~2013-06-12 7:15 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-12 7:13 [PATCH 0/8] Support for FMC carriers and mezzanines Alessandro Rubini
2013-06-12 7:13 ` [PATCH 1/8] FMC: create drivers/fmc and toplevel Kconfig question Alessandro Rubini
2013-06-17 23:17 ` Greg KH
2013-06-17 23:24 ` Alessandro Rubini
2013-06-17 23:35 ` Greg KH
2013-06-12 7:13 ` [PATCH 2/8] FMC: add needed headers Alessandro Rubini
2013-06-17 23:21 ` Greg KH
2013-06-17 23:29 ` Alessandro Rubini
2013-06-17 23:35 ` Greg KH
2013-06-19 10:49 ` Arnd Bergmann
2013-06-19 11:08 ` Alessandro Rubini
2013-06-12 7:13 ` [PATCH 3/8] FMC: add core bus driver Alessandro Rubini
2013-06-17 23:15 ` Greg KH
2013-06-17 23:16 ` Greg KH
2013-06-17 23:38 ` Alessandro Rubini
2013-06-18 8:36 ` Juan David Gonzalez Cobas
[not found] ` <CADDK0KdrVgmXN-TZw8E43JRNk5Wb_cfM6pUWaSxbJ49GU72cTg@mail.gmail.com>
2013-06-18 17:40 ` Greg KH
2013-06-18 19:52 ` Alessandro Rubini
2013-06-12 7:13 ` [PATCH 4/8] FMC: add documentation for the core Alessandro Rubini
2013-06-12 7:14 ` [PATCH 5/8] FMC: add a software carrier driver Alessandro Rubini
2013-06-17 23:19 ` Greg KH
2013-06-12 7:14 ` Alessandro Rubini [this message]
2013-06-17 23:20 ` [PATCH 6/8] FMC: add a software mezzanine driver Greg KH
2013-06-12 7:14 ` [PATCH 7/8] FMC: add a driver to write mezzanine EEPROM Alessandro Rubini
2013-06-12 7:14 ` [PATCH 8/8] FMC: add a char-device mezzanine driver Alessandro Rubini
-- strict thread matches above, loose matches on Subject: below --
2013-02-21 18:13 [PATCH RFC 0/8] drivers/fmc: bus support for ANSI-VITA 57.1 Alessandro Rubini
2013-02-21 18:14 ` [PATCH 6/8] FMC: add a software mezzanine driver Alessandro Rubini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7be26b13f841e433176a5d77ca9de1dd964b153a.1371018406.git.rubini@gnudd.com \
--to=rubini@gnudd.com \
--cc=cota@braap.org \
--cc=gregkh@linuxfoundation.org \
--cc=juan.david.gonzalez.cobas@cern.ch \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rob@landley.net \
--cc=siglesias@igalia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®