* [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200
@ 2009-03-06 21:12 Grant Likely
2009-03-06 21:13 ` [RFC 2/2] powerpc/5200: add LocalPlus bus FIFO device driver Grant Likely
2009-03-06 21:29 ` [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Jon Smirl
0 siblings, 2 replies; 4+ messages in thread
From: Grant Likely @ 2009-03-06 21:12 UTC (permalink / raw)
To: linuxppc-dev
From: Grant Likely <grant.likely@secretlab.ca>
This patch adds an interface for controlling the timer function of the
MPC5200 GPT devices.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
This probably isn't complete, but I wanted to get it out there and reviewed
before I commit to the design. Comments appreciated.
g.
arch/powerpc/include/asm/mpc52xx.h | 7 ++
arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 132 +++++++++++++++++++++++++++--
2 files changed, 129 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/include/asm/mpc52xx.h b/arch/powerpc/include/asm/mpc52xx.h
index 81a2393..8273357 100644
--- a/arch/powerpc/include/asm/mpc52xx.h
+++ b/arch/powerpc/include/asm/mpc52xx.h
@@ -275,6 +275,13 @@ extern void mpc52xx_map_common_devices(void);
extern int mpc52xx_set_psc_clkdiv(int psc_id, int clkdiv);
extern void mpc52xx_restart(char *cmd);
+/* mpc52xx_gpt.c */
+struct mpc52xx_gpt_priv;
+extern struct mpc52xx_gpt_priv *mpc52xx_gpt_from_irq(int irq);
+extern int mpc52xx_gpt_start_timer(struct mpc52xx_gpt_priv *gpt, int period,
+ int continuous);
+extern void mpc52xx_gpt_stop_timer(struct mpc52xx_gpt_priv *gpt);
+
/* mpc52xx_pic.c */
extern void mpc52xx_init_irq(void);
extern unsigned int mpc52xx_get_irq(void);
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
index bfbcd41..e9e040f 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
@@ -46,9 +46,12 @@
* the output mode. This driver does not change the output mode setting.
*/
+#include <linux/device.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
@@ -68,16 +71,21 @@ MODULE_LICENSE("GPL");
* @irqhost: Pointer to irq_host instance; used when IRQ mode is supported
*/
struct mpc52xx_gpt_priv {
+ struct list_head list; /* List of all GPT devices */
struct device *dev;
struct mpc52xx_gpt __iomem *regs;
spinlock_t lock;
struct irq_host *irqhost;
+ u32 ipb_freq;
#if defined(CONFIG_GPIOLIB)
struct of_gpio_chip of_gc;
#endif
};
+LIST_HEAD(mpc52xx_gpt_list);
+DEFINE_MUTEX(mpc52xx_gpt_list_mutex);
+
#define MPC52xx_GPT_MODE_MS_MASK (0x07)
#define MPC52xx_GPT_MODE_MS_IC (0x01)
#define MPC52xx_GPT_MODE_MS_OC (0x02)
@@ -88,6 +96,9 @@ struct mpc52xx_gpt_priv {
#define MPC52xx_GPT_MODE_GPIO_OUT_LOW (0x20)
#define MPC52xx_GPT_MODE_GPIO_OUT_HIGH (0x30)
+#define MPC52xx_GPT_MODE_COUNTER_ENABLE (0x1000)
+#define MPC52xx_GPT_MODE_CONTINUOUS (0x0400)
+#define MPC52xx_GPT_MODE_OPEN_DRAIN (0x0200)
#define MPC52xx_GPT_MODE_IRQ_EN (0x0100)
#define MPC52xx_GPT_MODE_ICT_MASK (0x030000)
@@ -190,7 +201,7 @@ static int mpc52xx_gpt_irq_xlate(struct irq_host *h, struct device_node *ct,
dev_dbg(gpt->dev, "%s: flags=%i\n", __func__, intspec[0]);
- if ((intsize < 1) || (intspec[0] < 1) || (intspec[0] > 3)) {
+ if ((intsize < 1) || (intspec[0] > 3)) {
dev_err(gpt->dev, "bad irq specifier in %s\n", ct->full_name);
return -EINVAL;
}
@@ -211,13 +222,11 @@ mpc52xx_gpt_irq_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)
{
int cascade_virq;
unsigned long flags;
-
- /* Only setup cascaded IRQ if device tree claims the GPT is
- * an interrupt controller */
- if (!of_find_property(node, "interrupt-controller", NULL))
- return;
+ u32 mode;
cascade_virq = irq_of_parse_and_map(node, 0);
+ if (!cascade_virq)
+ return;
gpt->irqhost = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR, 1,
&mpc52xx_gpt_irq_ops, -1);
@@ -227,14 +236,16 @@ mpc52xx_gpt_irq_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)
}
gpt->irqhost->host_data = gpt;
-
set_irq_data(cascade_virq, gpt);
set_irq_chained_handler(cascade_virq, mpc52xx_gpt_irq_cascade);
- /* Set to Input Capture mode */
+ /* If the GPT is currently disabled, then change it to be in Input
+ * Capture mode. If the mode is non-zero, then the pin could be
+ * already in use for something. */
spin_lock_irqsave(&gpt->lock, flags);
- clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK,
- MPC52xx_GPT_MODE_MS_IC);
+ mode = in_be32(&gpt->regs->mode);
+ if ((mode & MPC52xx_GPT_MODE_MS_MASK) == 0)
+ out_be32(&gpt->regs->mode, mode | MPC52xx_GPT_MODE_MS_IC);
spin_unlock_irqrestore(&gpt->lock, flags);
dev_dbg(gpt->dev, "%s() complete. virq=%i\n", __func__, cascade_virq);
@@ -335,6 +346,102 @@ static void
mpc52xx_gpt_gpio_setup(struct mpc52xx_gpt_priv *p, struct device_node *np) { }
#endif /* defined(CONFIG_GPIOLIB) */
+/***********************************************************************
+ * Timer API
+ */
+
+/**
+ * mpc52xx_gpt_from_irq - Return the GPT device associated with an IRQ number
+ * @irq: irq of timer.
+ */
+struct mpc52xx_gpt_priv *mpc52xx_gpt_from_irq(int irq)
+{
+ struct mpc52xx_gpt_priv *gpt;
+ struct list_head *pos;
+
+ /* Iterate over the list of timers looking for a matching device */
+ mutex_lock(&mpc52xx_gpt_list_mutex);
+ list_for_each(pos, &mpc52xx_gpt_list) {
+ gpt = container_of(pos, struct mpc52xx_gpt_priv, list);
+ if (gpt->irqhost && irq == irq_linear_revmap(gpt->irqhost, 0)) {
+ mutex_unlock(&mpc52xx_gpt_list_mutex);
+ return gpt;
+ }
+ }
+ mutex_unlock(&mpc52xx_gpt_list_mutex);
+
+ return NULL;
+}
+EXPORT_SYMBOL(mpc52xx_gpt_from_irq);
+
+/**
+ * mpc52xx_gpt_start_timer - Set and enable the GPT timer
+ * @gpt: Pointer to gpt private data structure
+ * @period: period of timer
+ * @continuous: set to 1 to make timer continuous free running
+ *
+ * An interrupt will be generated every time the timer fires
+ */
+int mpc52xx_gpt_start_timer(struct mpc52xx_gpt_priv *gpt, int period,
+ int continuous)
+{
+ u32 clear, set;
+ //u64 clocks;
+ u32 clocks;
+ u32 count, prescale;
+ unsigned long flags;
+
+ clear = MPC52xx_GPT_MODE_MS_MASK | MPC52xx_GPT_MODE_CONTINUOUS;
+ set = MPC52xx_GPT_MODE_MS_GPIO | MPC52xx_GPT_MODE_COUNTER_ENABLE;
+ if (continuous)
+ set |= MPC52xx_GPT_MODE_CONTINUOUS;
+
+ /* Determine the number of clocks in the requested period. 64 bit
+ * arithmatic is done here to preserve the precision until the value
+ * is scaled back down into the u32 range. Period is in 'ns', bus
+ * frequency is in Hz. */
+ //clocks = (u64)period * (u64)gpt->ipb_freq;
+ //clocks = clocks / 1000000000; /* Scale it down to ns range */
+ clocks = (period / 1000) * (gpt->ipb_freq / 1000000);
+
+ /* This device cannot handle a clock count greater than 32 bits */
+ if (clocks > 0xffffffff)
+ return -EINVAL;
+
+ /* Calculate the prescaler and count values from the clocks value.
+ * 'clocks' is the number of clock ticks in the period. The timer
+ * has 16 bit precision and a 16 bit prescaler. Prescaler is
+ * calculated by integer dividing the clocks by 0x10000 (shifting
+ * down 16 bits) to obtain the smallest possible divisor for clocks
+ * to get a 16 bit count value.
+ *
+ * Note: the prescale register is '1' based, not '0' based. ie. a
+ * value of '1' means divide the clock by one. 0xffff divides the
+ * clock by 0xffff. '0x0000' does not divide by zero, but wraps
+ * around and divides by 0x10000. That is why prescale must be
+ * a u32 variable, not a u16, for this calculation. */
+ prescale = (clocks >> 16) + 1;
+ count = clocks / prescale;
+ if (count > 0xffff)
+ pr_err("calculation error; count:%x prescale:%x clocks:%x\n",
+ count, prescale, clocks);
+
+ /* Set and enable the timer */
+ spin_lock_irqsave(&gpt->lock, flags);
+ out_be32(&gpt->regs->count, prescale << 16 | count);
+ clrsetbits_be32(&gpt->regs->mode, clear, set);
+ spin_unlock_irqrestore(&gpt->lock, flags);
+
+ return 0;
+}
+EXPORT_SYMBOL(mpc52xx_gpt_start_timer);
+
+void mpc52xx_gpt_stop_timer(struct mpc52xx_gpt_priv *gpt)
+{
+ clrbits32(&gpt->regs->mode, MPC52xx_GPT_MODE_COUNTER_ENABLE);
+}
+EXPORT_SYMBOL(mpc52xx_gpt_stop_timer);
+
/* ---------------------------------------------------------------------
* of_platform bus binding code
*/
@@ -349,6 +456,7 @@ static int __devinit mpc52xx_gpt_probe(struct of_device *ofdev,
spin_lock_init(&gpt->lock);
gpt->dev = &ofdev->dev;
+ gpt->ipb_freq = mpc52xx_find_ipb_freq(ofdev->node);
gpt->regs = of_iomap(ofdev->node, 0);
if (!gpt->regs) {
kfree(gpt);
@@ -360,6 +468,10 @@ static int __devinit mpc52xx_gpt_probe(struct of_device *ofdev,
mpc52xx_gpt_gpio_setup(gpt, ofdev->node);
mpc52xx_gpt_irq_setup(gpt, ofdev->node);
+ mutex_lock(&mpc52xx_gpt_list_mutex);
+ list_add(&gpt->list, &mpc52xx_gpt_list);
+ mutex_unlock(&mpc52xx_gpt_list_mutex);
+
return 0;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC 2/2] powerpc/5200: add LocalPlus bus FIFO device driver
2009-03-06 21:12 [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Grant Likely
@ 2009-03-06 21:13 ` Grant Likely
2009-03-06 21:29 ` [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Jon Smirl
1 sibling, 0 replies; 4+ messages in thread
From: Grant Likely @ 2009-03-06 21:13 UTC (permalink / raw)
To: linuxppc-dev
From: Grant Likely <grant.likely@secretlab.ca>
This is a driver for the LocalPlus bus FIFO device
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
This also isn't complete, but I wanted to get it out there and reviewed
before I commit to the design. Comments appreciated.
g.
arch/powerpc/include/asm/mpc52xx.h | 11 +
arch/powerpc/platforms/52xx/Kconfig | 4
arch/powerpc/platforms/52xx/Makefile | 1
arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c | 282 +++++++++++++++++++++++++
4 files changed, 298 insertions(+), 0 deletions(-)
create mode 100644 arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
diff --git a/arch/powerpc/include/asm/mpc52xx.h b/arch/powerpc/include/asm/mpc52xx.h
index 8273357..7ec34ea 100644
--- a/arch/powerpc/include/asm/mpc52xx.h
+++ b/arch/powerpc/include/asm/mpc52xx.h
@@ -282,6 +282,17 @@ extern int mpc52xx_gpt_start_timer(struct mpc52xx_gpt_priv *gpt, int period,
int continuous);
extern void mpc52xx_gpt_stop_timer(struct mpc52xx_gpt_priv *gpt);
+/* mpc52xx_lpbfifo.c */
+extern int mpc52xx_lpbfifo_write(void *src, unsigned int cs,
+ size_t offset, size_t size, int flags,
+ void (*callback)(void *, size_t, int),
+ void *callback_data);
+extern int mpc52xx_lpbfifo_read(void *dest, unsigned int cs,
+ size_t offset, size_t size, int flags,
+ void (*callback)(void *, size_t, int),
+ void *callback_data);
+extern void mpc52xx_lpbfifo_abort(void *callback_data);
+
/* mpc52xx_pic.c */
extern void mpc52xx_init_irq(void);
extern unsigned int mpc52xx_get_irq(void);
diff --git a/arch/powerpc/platforms/52xx/Kconfig b/arch/powerpc/platforms/52xx/Kconfig
index 0465e5b..f117e23 100644
--- a/arch/powerpc/platforms/52xx/Kconfig
+++ b/arch/powerpc/platforms/52xx/Kconfig
@@ -61,3 +61,7 @@ config PPC_MPC5200_GPIO
select GENERIC_GPIO
help
Enable gpiolib support for mpc5200 based boards
+
+config PPC_MPC5200_LPBFIFO
+ tristate "MPC5200 LocalPlus bus FIFO driver"
+ depends on PPC_MPC52xx
diff --git a/arch/powerpc/platforms/52xx/Makefile b/arch/powerpc/platforms/52xx/Makefile
index bfd4f52..2bc8cd0 100644
--- a/arch/powerpc/platforms/52xx/Makefile
+++ b/arch/powerpc/platforms/52xx/Makefile
@@ -15,3 +15,4 @@ ifeq ($(CONFIG_PPC_LITE5200),y)
endif
obj-$(CONFIG_PPC_MPC5200_GPIO) += mpc52xx_gpio.o
+obj-$(CONFIG_PPC_MPC5200_LPBFIFO) += mpc52xx_lpbfifo.o
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c b/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
new file mode 100644
index 0000000..b00d763
--- /dev/null
+++ b/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
@@ -0,0 +1,282 @@
+/*
+ * LocalPlus Bus FIFO driver for the Freescale MPC52xx.
+ *
+ * Copyright (C) 2009 Secret Lab Technologies Ltd.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ */
+
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/spinlock.h>
+#include <asm/io.h>
+#include <asm/prom.h>
+#include <asm/mpc52xx.h>
+
+MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
+MODULE_DESCRIPTION("MPC5200 LocalPlus FIFO device driver");
+MODULE_LICENSE("GPL");
+
+#define LPBFIFO_REG_PACKET_SIZE (0x00)
+#define LPBFIFO_REG_START_ADDRESS (0x04)
+#define LPBFIFO_REG_CONTROL (0x08)
+#define LPBFIFO_REG_ENABLE (0x0C)
+#define LPBFIFO_REG_BYTES_DONE_STATUS (0x14)
+#define LPBFIFO_REG_FIFO_DATA (0x40)
+#define LPBFIFO_REG_FIFO_STATUS (0x44)
+#define LPBFIFO_REG_FIFO_CONTROL (0x48)
+#define LPBFIFO_REG_FIFO_ALARM (0x4C)
+
+struct mpc52xx_lpbfifo {
+ struct device *dev;
+ void __iomem *regs;
+ int irq;
+ spinlock_t lock;
+
+ /* Current transfer data */
+ void *data;
+ int cs;
+ size_t offset;
+ size_t size;
+ size_t remaining;
+ void (*callback)(void *, size_t, int);
+ void *callback_data;
+};
+
+/* The MPC5200 has only one fifo, so only need one instance structure */
+static struct mpc52xx_lpbfifo lpbfifo;
+
+/**
+ * mpc52xx_lpbfifo_kick - Trigger the next block of data to be transfered
+ */
+static void mpc52xx_lpbfifo_kick(void)
+{
+ size_t transfer_size = lpbfifo.remaining;
+
+ /* While the FIFO can be setup for transfer sizes as large as 16M-1,
+ * the FIFO itself is only 512 bytes deep and it does not generate
+ * interrupts for FIFO full events (only transfer complete will
+ * raise an IRQ). Therefore when not using Bestcomm to drive the
+ * FIFO it needs to either be polled, or transfers need to constrained
+ * to the size of the fifo.
+ *
+ * Here we choose to restrict the size of the transfer
+ */
+ if (transfer_size > 512)
+ transfer_size = 512;
+
+ /* Set and clear the reset bits; is good practice in User Manual */
+ out_be32(lpbfifo.regs + LPBFIFO_REG_ENABLE, 0x01010000);
+ out_be32(lpbfifo.regs + LPBFIFO_REG_ENABLE, 0x00000301);
+
+ /* Set transfer size, width, chip select and READ mode */
+ out_be32(lpbfifo.regs + LPBFIFO_REG_PACKET_SIZE, transfer_size);
+ out_be32(lpbfifo.regs + LPBFIFO_REG_CONTROL,
+ lpbfifo.cs << 24 | 0x00010008);
+
+ /* Kick it off */
+ out_8(lpbfifo.regs + LPBFIFO_REG_PACKET_SIZE, 0x01);
+}
+
+/**
+ * mpc52xx_lpbfifo_irq - IRQ handler for LPB FIFO
+ */
+static irqreturn_t mpc52xx_lpbfifo_irq(int irq, void *dev_id)
+{
+ u8 status = in_8(lpbfifo.regs + LPBFIFO_REG_BYTES_DONE_STATUS);
+ u32 *data;
+ int count, i;
+ void (*callback)(void *, size_t, int);
+ void *callback_data;
+
+ spin_lock(&lpbfifo.lock);
+
+ if (status & 0x10) { /* check abort bit */
+ out_be32(lpbfifo.regs + LPBFIFO_REG_ENABLE, 0x01010000);
+ } else if (status & 0x01) { /* check transaction done bit */
+ /* Read result from hardware */
+ count = in_be32(lpbfifo.regs + LPBFIFO_REG_BYTES_DONE_STATUS);
+ count &= 0x00ffffff;
+
+ data = lpbfifo.data;
+ for (i = 0; i < count; i += 4)
+ *data++ = in_be32(lpbfifo.regs + LPBFIFO_REG_FIFO_DATA);
+
+ /* Update transfer position and count */
+ lpbfifo.remaining -= count;
+ lpbfifo.offset += count;
+ lpbfifo.data += count;
+
+ /* Clear the IRQ */
+ out_8(lpbfifo.regs + LPBFIFO_REG_BYTES_DONE_STATUS, 0x01);
+
+ if (lpbfifo.remaining) {
+ /* More work to do. Kick of the next block and exit */
+ mpc52xx_lpbfifo_kick();
+ spin_unlock(&lpbfifo.lock);
+ return IRQ_HANDLED;
+ }
+ }
+
+ /* Mark the FIFO as idle */
+ lpbfifo.data = NULL;
+ callback = lpbfifo.callback;
+ callback_data = lpbfifo.callback_data;
+ count = lpbfifo.size - lpbfifo.remaining;
+
+ /* Release the lock before calling out to the callback. */
+ spin_unlock(&lpbfifo.lock);
+
+ /* If control reaches this point then the transfer is finished,
+ * either normal completion or due to abort */
+ callback(callback_data, count, (status & 0x10) != 0);
+
+ return IRQ_HANDLED;
+}
+
+/**
+ * mpc52xx_lpbfifo_read - Initiate an LPB fifo READ transaction
+ * @data: location to copy data into
+ * @cs: LocalPlus bus chip select number for transfer
+ * @offset: Location of data to read as an offset from the CS base address
+ * @size: Size of transfer in bytes
+ * @callback: Callback function for FIFO events. Will be called when the
+ * FIFO high watermark is reached, when the transfer finishes,
+ * and if a FIFO error occurs.
+ * @data: Private data pointer to be passed to callback function.
+ */
+int mpc52xx_lpbfifo_read(void *dest, unsigned int cs,
+ size_t offset, size_t size, int mode_flags,
+ void (*callback)(void *, size_t, int),
+ void *callback_data)
+{
+ int rc = -EBUSY;
+ unsigned long flags;
+
+ if (!lpbfifo.regs)
+ return -ENODEV;
+
+ spin_lock_irqsave(&lpbfifo.lock, flags);
+ /* If the data pointer is already set then a transfer is in progress */
+ if (lpbfifo.data)
+ goto out;
+
+ /* Setup the transfer */
+ lpbfifo.data = dest;
+ lpbfifo.cs = cs;
+ lpbfifo.offset = offset;
+ lpbfifo.remaining = lpbfifo.size = size;
+ lpbfifo.callback = callback;
+ lpbfifo.callback_data = callback_data;
+
+ mpc52xx_lpbfifo_kick();
+ rc = 0;
+
+ out:
+ spin_unlock_irqrestore(&lpbfifo.lock, flags);
+ return rc;
+}
+EXPORT_SYMBOL(mpc52xx_lpbfifo_read);
+
+void mpc52xx_lpbfifo_abort(void *callback_data)
+{
+ unsigned long flags;
+
+ if (lpbfifo.callback_data != callback_data)
+ return;
+
+ spin_lock_irqsave(&lpbfifo.lock, flags);
+ /* Put it into reset and clear the state */
+ out_be32(lpbfifo.regs + LPBFIFO_REG_ENABLE, 0x01010000);
+ lpbfifo.data = NULL;
+ spin_unlock_irqrestore(&lpbfifo.lock, flags);
+}
+EXPORT_SYMBOL(mpc52xx_lpbfifo_abort);
+
+static int __devinit
+mpc52xx_lpbfifo_probe(struct of_device *op, const struct of_device_id *match)
+{
+ int rc;
+
+ if (lpbfifo.dev != NULL)
+ return -ENOSPC;
+
+ lpbfifo.regs = of_iomap(op->node, 0);
+ if (!lpbfifo.regs)
+ return -ENOMEM;
+
+ lpbfifo.irq = irq_of_parse_and_map(op->node, 0);
+ if (!lpbfifo.irq) {
+ lpbfifo.regs = NULL;
+ iounmap(lpbfifo.regs);
+ return -ENOMEM;
+ }
+
+ spin_lock_init(&lpbfifo.lock);
+
+ /* Put FIFO into reset */
+ out_be32(lpbfifo.regs + LPBFIFO_REG_ENABLE, 0x01010000);
+
+ /* Register the interrupt handler */
+ rc = request_irq(lpbfifo.irq, mpc52xx_lpbfifo_irq, 0,
+ "mpc52xx-lpbfifo", &lpbfifo);
+ if (rc) {
+ pr_err("request_irq() failed. rc=%i\n", rc);
+ lpbfifo.regs = NULL;
+ free_irq(lpbfifo.irq, &lpbfifo);
+ iounmap(lpbfifo.regs);
+ }
+
+ lpbfifo.dev = &op->dev;
+ pr_info("LPB FIFO ready; regs=%p irq=%i\n", lpbfifo.regs, lpbfifo.irq);
+ return 0;
+}
+
+
+static int __devexit mpc52xx_lpbfifo_remove(struct of_device *op)
+{
+ if (lpbfifo.dev == &op->dev) {
+ /* Put FIFO in reset */
+ out_be32(lpbfifo.regs + LPBFIFO_REG_ENABLE, 0x01010000);
+ lpbfifo.regs = NULL;
+ free_irq(lpbfifo.irq, &lpbfifo);
+ iounmap(lpbfifo.regs);
+ lpbfifo.dev = NULL;
+ }
+ return 0;
+}
+
+static struct of_device_id mpc52xx_lpbfifo_match[] __devinitdata = {
+ { .compatible = "fsl,mpc5200-lpbfifo", },
+ {},
+};
+
+static struct of_platform_driver mpc52xx_lpbfifo_driver = {
+ .owner = THIS_MODULE,
+ .name = "mpc52xx-lpbfifo",
+ .match_table = mpc52xx_lpbfifo_match,
+ .probe = mpc52xx_lpbfifo_probe,
+ .remove = __devexit_p(mpc52xx_lpbfifo_remove),
+};
+
+/***********************************************************************
+ * Module init/exit
+ */
+static int __init mpc52xx_lpbfifo_init(void)
+{
+ pr_debug("Registering LocalPlus bus FIFO driver\n");
+ return of_register_platform_driver(&mpc52xx_lpbfifo_driver);
+}
+module_init(mpc52xx_lpbfifo_init);
+
+static void __exit mpc52xx_lpbfifo_exit(void)
+{
+ pr_debug("Unregistering LocalPlus bus FIFO driver\n");
+ of_unregister_platform_driver(&mpc52xx_lpbfifo_driver);
+}
+module_exit(mpc52xx_lpbfifo_exit);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200
2009-03-06 21:12 [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Grant Likely
2009-03-06 21:13 ` [RFC 2/2] powerpc/5200: add LocalPlus bus FIFO device driver Grant Likely
@ 2009-03-06 21:29 ` Jon Smirl
2009-03-06 21:39 ` Grant Likely
1 sibling, 1 reply; 4+ messages in thread
From: Jon Smirl @ 2009-03-06 21:29 UTC (permalink / raw)
To: Grant Likely, linuxppc-dev, w.sang
[-- Attachment #1: Type: text/plain, Size: 748 bytes --]
I'm using a GPT pin in input capture mode to implement IR. I attached
my GPT driver code. I can convert to your API. That's a really cheap
way to do IR, just IR sensor, resistor and a cap.
I also have an in-kernel IR system but Christoph (lirc maintainer)
won't consider it. He is a microkernel type - he wants everything in
user space. My in-kernel version is tiny, less than 10K. It turns IR
events into keystrokes on a virtual keyboard device.
This is my old device tree, what should the new one look like?
ir0@670 { /* General Purpose Timer 6 in Input mode */
compatible = "gpt-ir";
cell-index = <7>;
reg = <0x670 0x10>;
interrupts = <0x1 0x10 0x0>;
interrupt-parent = <&mpc5200_pic>;
};
--
Jon Smirl
jonsmirl@gmail.com
[-- Attachment #2: jds-lirc-gpt --]
[-- Type: application/octet-stream, Size: 5699 bytes --]
GPT driver for in-kernel IR support.
From: Jon Smirl <jonsmirl@gmail.com>
GPT is a GPIO pin that is cable able of measuring the lenght of pulses.
GPTs are common on embedded systems
---
drivers/input/ir/Kconfig | 6 +
drivers/input/ir/Makefile | 3 +
drivers/input/ir/ir-gpt.c | 184 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 193 insertions(+), 0 deletions(-)
create mode 100644 drivers/input/ir/ir-gpt.c
diff --git a/drivers/input/ir/Kconfig b/drivers/input/ir/Kconfig
index a6f3f25..172c0c6 100644
--- a/drivers/input/ir/Kconfig
+++ b/drivers/input/ir/Kconfig
@@ -12,4 +12,10 @@ menuconfig INPUT_IR
if INPUT_IR
+config IR_GPT
+ tristate "GPT Based IR Receiver"
+ default m
+ help
+ Driver for GPT-based IR receiver found on Digispeaker
+
endif
diff --git a/drivers/input/ir/Makefile b/drivers/input/ir/Makefile
index 2ccdda3..ab0da3f 100644
--- a/drivers/input/ir/Makefile
+++ b/drivers/input/ir/Makefile
@@ -6,3 +6,6 @@
obj-$(CONFIG_INPUT_IR) += ir.o
ir-objs := ir-core.o ir-configfs.o
+
+obj-$(CONFIG_IR_GPT) += ir-gpt.o
+
diff --git a/drivers/input/ir/ir-gpt.c b/drivers/input/ir/ir-gpt.c
new file mode 100644
index 0000000..41d2fa6
--- /dev/null
+++ b/drivers/input/ir/ir-gpt.c
@@ -0,0 +1,184 @@
+/*
+ * GPT timer based IR device
+ *
+ * Copyright (C) 2008 Jon Smirl <jonsmirl@gmail.com>
+ */
+
+#define DEBUG
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/input.h>
+#include <asm/io.h>
+#include <asm/mpc52xx.h>
+
+struct ir_gpt {
+ struct input_dev *input;
+ int irq, previous;
+ struct mpc52xx_gpt __iomem *regs;
+};
+
+/*
+ * Interrupt handlers
+ */
+static irqreturn_t dpeak_ir_irq(int irq, void *_ir)
+{
+ struct ir_gpt *ir_gpt = _ir;
+ int sample, count, delta, bit, wrap;
+
+ sample = in_be32(&ir_gpt->regs->status);
+ out_be32(&ir_gpt->regs->status, 0xF);
+
+ count = sample >> 16;
+ wrap = (sample >> 12) & 7;
+ bit = (sample >> 8) & 1;
+
+ delta = count - ir_gpt->previous;
+ delta += wrap * 0x10000;
+
+ ir_gpt->previous = count;
+
+ if (bit)
+ delta = -delta;
+
+ input_ir_queue(ir_gpt->input, delta);
+
+ return IRQ_HANDLED;
+}
+
+
+/* ---------------------------------------------------------------------
+ * OF platform bus binding code:
+ * - Probe/remove operations
+ * - OF device match table
+ */
+static int __devinit ir_gpt_of_probe(struct of_device *op,
+ const struct of_device_id *match)
+{
+ struct ir_gpt *ir_gpt;
+ struct resource res;
+ int ret, rc;
+
+ dev_dbg(&op->dev, "ir_gpt_of_probe\n");
+
+ /* Allocate and initialize the driver private data */
+ ir_gpt = kzalloc(sizeof *ir_gpt, GFP_KERNEL);
+ if (!ir_gpt)
+ return -ENOMEM;
+
+ ir_gpt->input = input_allocate_device();
+ if (!ir_gpt->input) {
+ ret = -ENOMEM;
+ goto free_mem;
+ }
+ ret = input_ir_create(ir_gpt->input, ir_gpt, NULL);
+ if (ret)
+ goto free_input;
+
+ ir_gpt->input->id.bustype = BUS_HOST;
+ ir_gpt->input->name = "GPT IR Receiver";
+
+ ir_gpt->input->irbit[0] |= BIT_MASK(IR_CAP_RECEIVE_36K);
+ ir_gpt->input->irbit[0] |= BIT_MASK(IR_CAP_RECEIVE_38K);
+ ir_gpt->input->irbit[0] |= BIT_MASK(IR_CAP_RECEIVE_40K);
+ ir_gpt->input->irbit[0] |= BIT_MASK(IR_CAP_RECEIVE_RAW);
+
+ ret = input_register_device(ir_gpt->input);
+ if (ret)
+ goto free_input;
+ ret = input_ir_register(ir_gpt->input);
+ if (ret)
+ goto free_input;
+
+ /* Fetch the registers and IRQ of the GPT */
+ if (of_address_to_resource(op->node, 0, &res)) {
+ dev_err(&op->dev, "Missing reg property\n");
+ ret = -ENODEV;
+ goto free_input;
+ }
+ ir_gpt->regs = ioremap(res.start, 1 + res.end - res.start);
+ if (!ir_gpt->regs) {
+ dev_err(&op->dev, "Could not map registers\n");
+ ret = -ENODEV;
+ goto free_input;
+ }
+ ir_gpt->irq = irq_of_parse_and_map(op->node, 0);
+ if (ir_gpt->irq == NO_IRQ) {
+ ret = -ENODEV;
+ goto free_input;
+ }
+ dev_dbg(&op->dev, "ir_gpt_of_probe irq=%d\n", ir_gpt->irq);
+
+ rc = request_irq(ir_gpt->irq, &dpeak_ir_irq, IRQF_SHARED,
+ "gpt-ir", ir_gpt);
+ dev_dbg(&op->dev, "ir_gpt_of_probe request irq rc=%d\n", rc);
+
+ /* set prescale to ? */
+ out_be32(&ir_gpt->regs->count, 0x00870000);
+
+ /* Select input capture, enable the counter, and interrupt */
+ out_be32(&ir_gpt->regs->mode, 0x0);
+ out_be32(&ir_gpt->regs->mode, 0x00000501);
+
+ /* Save what we've done so it can be found again later */
+ dev_set_drvdata(&op->dev, ir_gpt);
+
+ printk("GPT IR Receiver driver\n");
+
+ return 0;
+
+free_input:
+ input_free_device(ir_gpt->input);
+free_mem:
+ kfree(ir_gpt);
+ return ret;
+}
+
+static int __devexit ir_gpt_of_remove(struct of_device *op)
+{
+ struct ir_gpt *ir_gpt = dev_get_drvdata(&op->dev);
+
+ dev_dbg(&op->dev, "ir_gpt_remove()\n");
+
+ input_unregister_device(ir_gpt->input);
+ kfree(ir_gpt);
+ dev_set_drvdata(&op->dev, NULL);
+
+ return 0;
+}
+
+/* Match table for of_platform binding */
+static struct of_device_id ir_gpt_match[] __devinitdata = {
+ { .compatible = "gpt-ir", },
+ {}
+};
+MODULE_DEVICE_TABLE(of, ir_gpt_match);
+
+static struct of_platform_driver ir_gpt_driver = {
+ .match_table = ir_gpt_match,
+ .probe = ir_gpt_of_probe,
+ .remove = __devexit_p(ir_gpt_of_remove),
+ .driver = {
+ .name = "ir-gpt",
+ .owner = THIS_MODULE,
+ },
+};
+
+/* ---------------------------------------------------------------------
+ * Module setup and teardown; simply register the of_platform driver
+ */
+static int __init ir_gpt_init(void)
+{
+ return of_register_platform_driver(&ir_gpt_driver);
+}
+module_init(ir_gpt_init);
+
+static void __exit ir_gpt_exit(void)
+{
+ of_unregister_platform_driver(&ir_gpt_driver);
+}
+module_exit(ir_gpt_exit);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200
2009-03-06 21:29 ` [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Jon Smirl
@ 2009-03-06 21:39 ` Grant Likely
0 siblings, 0 replies; 4+ messages in thread
From: Grant Likely @ 2009-03-06 21:39 UTC (permalink / raw)
To: Jon Smirl; +Cc: linuxppc-dev
On Fri, Mar 6, 2009 at 2:29 PM, Jon Smirl <jonsmirl@gmail.com> wrote:
> I'm using a GPT pin in input capture mode to implement IR. I attached
> my GPT driver code. I can convert to your API. That's a really cheap
> way to do IR, just IR sensor, resistor and a cap.
The driver I posted can't do input capture mode yet, but it shouldn't
be too difficult to add. Just another api function for setting the
mode I think. I don't have a use for that yet, so I haven't thought
much about it. Feel free to suggest what you think the API should
look like.
> This is my old device tree, what should the new one look like?
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ir0@670 { /* General Purpose Timer 6 in In=
put mode */
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0compatible =3D "gpt-ir";
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cell-index =3D <7>;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0reg =3D <0x670 0x10>;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0interrupts =3D <0x1 0x10 0=
x0>;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0interrupt-parent =3D <&mpc=
5200_pic>;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0};
You'd want a node for the IR device which uses the GPT node as its
interrupt controller.
so:
gpt7: gpt@670 {
compatible =3D "fsl,mpc5200b-gpt"
reg =3D <0x670 0x10>;
interrupt =3D <1 16 0>;
interrupt-controller;
#interrupt-cells =3D <1>;
};
Then elsewhere:
ir {
compatible =3D "digispeaker,ir"; // or whatever best matches your =
board
interrupt-parent =3D <&gpt>;
interrupts =3D <0>; // IIRC, '0' means irq on both edges for
the GPT irq controller
};
g.
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-06 21:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-06 21:12 [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Grant Likely
2009-03-06 21:13 ` [RFC 2/2] powerpc/5200: add LocalPlus bus FIFO device driver Grant Likely
2009-03-06 21:29 ` [RFC 1/2] powerpc/5200: add general purpose timer API for the MPC5200 Jon Smirl
2009-03-06 21:39 ` Grant Likely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).