From: Albert H. <he...@us...> - 2009-12-09 18:47:50
|
Update of /cvsroot/gc-linux/linux/arch/powerpc/platforms/embedded6xx In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv23815/arch/powerpc/platforms/embedded6xx Added Files: hlwd-gpio.c hlwd-pic.c hlwd-pic.h Log Message: Add new files for gc-linux-2.6.32. --- NEW FILE: hlwd-gpio.c --- /* * arch/powerpc/platforms/embedded6xx/hlwd-gpio.c * * Nintendo Wii (Hollywood) GPIO driver * Copyright (C) 2008-2009 The GameCube Linux Team * Copyright (C) 2008,2009 Albert Herranz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * */ #include <linux/io.h> #include <linux/kernel.h> #include <linux/of.h> #include <linux/of_gpio.h> #include <linux/of_platform.h> #define DRV_MODULE_NAME "hlwd-gpio" #define drv_printk(level, format, arg...) \ printk(level DRV_MODULE_NAME ": " format , ## arg) struct hlwd_gpio_chip { struct of_mm_gpio_chip mmchip; spinlock_t lock; }; struct hlwd_gpio_regs { __be32 out, dir, in; }; static inline struct hlwd_gpio_chip * to_hlwd_gpio_chip(struct of_mm_gpio_chip *mm_gc) { return container_of(mm_gc, struct hlwd_gpio_chip, mmchip); } static int hlwd_gpio_get(struct gpio_chip *gc, unsigned int gpio) { struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); struct hlwd_gpio_regs __iomem *regs = mm_gc->regs; u32 pin_mask = 1 << (31 - gpio); unsigned int val; val = !!(in_be32(®s->in) & pin_mask); pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val); return val; } static void hlwd_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) { struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); struct hlwd_gpio_chip *st_gc = to_hlwd_gpio_chip(mm_gc); struct hlwd_gpio_regs __iomem *regs = mm_gc->regs; u32 pin_mask = 1 << (31 - gpio); u32 data; unsigned long flags; spin_lock_irqsave(&st_gc->lock, flags); data = in_be32(®s->in) & ~pin_mask; if (val) data |= pin_mask; out_be32(®s->out, data); spin_unlock_irqrestore(&st_gc->lock, flags); pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val); } static int hlwd_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) { struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); struct hlwd_gpio_regs __iomem *regs = mm_gc->regs; u32 pin_mask = 1 << (31 - gpio); clrbits32(®s->dir, pin_mask); return 0; } static int hlwd_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) { struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); struct hlwd_gpio_regs __iomem *regs = mm_gc->regs; u32 pin_mask = 1 << (31 - gpio); setbits32(®s->dir, pin_mask); hlwd_gpio_set(gc, gpio, val); return 0; } int hlwd_gpio_add32(struct device_node *np) { struct of_mm_gpio_chip *mm_gc; struct of_gpio_chip *of_gc; struct gpio_chip *gc; struct hlwd_gpio_chip *st_gc; const unsigned long *prop; int error; st_gc = kzalloc(sizeof(*st_gc), GFP_KERNEL); if (!st_gc) return -ENOMEM; spin_lock_init(&st_gc->lock); mm_gc = &st_gc->mmchip; of_gc = &mm_gc->of_gc; gc = &of_gc->gc; prop = of_get_property(np, "#gpio-cells", NULL); if (prop && *prop >= 2) of_gc->gpio_cells = *prop; else of_gc->gpio_cells = 2; /* gpio pin number, flags */ gc->ngpio = 32; gc->direction_input = hlwd_gpio_dir_in; gc->direction_output = hlwd_gpio_dir_out; gc->get = hlwd_gpio_get; gc->set = hlwd_gpio_set; error = of_mm_gpiochip_add(np, mm_gc); if (!error) drv_printk(KERN_INFO, "%s: added %u gpios at %p\n", np->name, gc->ngpio, mm_gc->regs); return error; } static int hlwd_gpio_init(void) { struct device_node *np; int error; for_each_compatible_node(np, NULL, "nintendo,hollywood-gpio") { error = hlwd_gpio_add32(np); if (error < 0) drv_printk(KERN_ERR, "error %d adding gpios" " for %s\n", error, np->full_name); } return 0; /* whatever */ } arch_initcall(hlwd_gpio_init); --- NEW FILE: hlwd-pic.c --- /* * arch/powerpc/platforms/embedded6xx/hlwd-pic.c * * Nintendo Wii "Hollywood" interrupt controller support. * Copyright (C) 2009 The GameCube Linux Team * Copyright (C) 2009 Albert Herranz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * */ #define DRV_MODULE_NAME "hlwd-pic" #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt #include <linux/kernel.h> #include <linux/init.h> #include <linux/irq.h> #include <linux/of.h> #include <asm/io.h> #include "hlwd-pic.h" #define HLWD_NR_IRQS 32 /* * Each interrupt has a corresponding bit in both * the Interrupt Cause (ICR) and Interrupt Mask (IMR) registers. * * Enabling/disabling an interrupt line involves asserting/clearing * the corresponding bit in IMR. ACK'ing a request simply involves * asserting the corresponding bit in ICR. */ #define HW_BROADWAY_ICR 0x00 #define HW_BROADWAY_IMR 0x04 /* * IRQ chip hooks. * */ static void hlwd_pic_mask_and_ack(unsigned int virq) { int irq = virq_to_hw(virq); void __iomem *io_base = get_irq_chip_data(virq); clear_bit(irq, io_base + HW_BROADWAY_IMR); set_bit(irq, io_base + HW_BROADWAY_ICR); } static void hlwd_pic_ack(unsigned int virq) { int irq = virq_to_hw(virq); void __iomem *io_base = get_irq_chip_data(virq); set_bit(irq, io_base + HW_BROADWAY_ICR); } static void hlwd_pic_mask(unsigned int virq) { int irq = virq_to_hw(virq); void __iomem *io_base = get_irq_chip_data(virq); clear_bit(irq, io_base + HW_BROADWAY_IMR); } static void hlwd_pic_unmask(unsigned int virq) { int irq = virq_to_hw(virq); void __iomem *io_base = get_irq_chip_data(virq); set_bit(irq, io_base + HW_BROADWAY_IMR); } static struct irq_chip hlwd_pic = { .typename = "hlwd-pic", .ack = hlwd_pic_ack, .mask_ack = hlwd_pic_mask_and_ack, .mask = hlwd_pic_mask, .unmask = hlwd_pic_unmask, }; /* * IRQ host hooks. * */ static struct irq_host *hlwd_irq_host; static int hlwd_pic_map(struct irq_host *h, unsigned int virq, irq_hw_number_t hwirq) { set_irq_chip_data(virq, h->host_data); get_irq_desc(virq)->status |= IRQ_LEVEL; set_irq_chip_and_handler(virq, &hlwd_pic, handle_level_irq); return 0; } static void hlwd_pic_unmap(struct irq_host *h, unsigned int irq) { set_irq_chip_data(irq, NULL); set_irq_chip(irq, NULL); } static struct irq_host_ops hlwd_irq_host_ops = { .map = hlwd_pic_map, .unmap = hlwd_pic_unmap, }; static unsigned int __hlwd_pic_get_irq(struct irq_host *h) { void __iomem *io_base = h->host_data; int irq; u32 irq_status; irq_status = in_be32(io_base + HW_BROADWAY_ICR) & in_be32(io_base + HW_BROADWAY_IMR); if (irq_status == 0) return NO_IRQ_IGNORE; /* no more IRQs pending */ __asm__ __volatile__("cntlzw %0,%1" : "=r"(irq) : "r"(irq_status)); return irq_linear_revmap(h, 31 - irq); } static void hlwd_pic_irq_cascade(unsigned int cascade_virq, struct irq_desc *desc) { struct irq_host *irq_host = get_irq_data(cascade_virq); unsigned int virq; spin_lock(&desc->lock); desc->chip->mask(cascade_virq); /* IRQ_LEVEL */ spin_unlock(&desc->lock); virq = __hlwd_pic_get_irq(irq_host); if (virq != NO_IRQ_IGNORE) generic_handle_irq(virq); else pr_err("spurious interrupt!\n"); spin_lock(&desc->lock); desc->chip->ack(cascade_virq); /* IRQ_LEVEL */ if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask) desc->chip->unmask(cascade_virq); spin_unlock(&desc->lock); } /* * Platform hooks. * */ static void __hlwd_quiesce(void __iomem *io_base) { /* mask and ack all IRQs */ out_be32(io_base + HW_BROADWAY_IMR, 0); out_be32(io_base + HW_BROADWAY_ICR, ~0); } struct irq_host *hlwd_pic_init(struct device_node *np) { struct irq_host *irq_host; struct resource res; void __iomem *io_base; int retval; retval = of_address_to_resource(np, 0, &res); if (retval) { pr_err("no io memory range found\n"); return NULL; } io_base = ioremap(res.start, resource_size(&res)); if (!io_base) { pr_err("ioremap failed\n"); return NULL; } pr_info("controller at 0x%08x mapped to 0x%p\n", res.start, io_base); __hlwd_quiesce(io_base); irq_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, HLWD_NR_IRQS, &hlwd_irq_host_ops, NO_IRQ_IGNORE); if (!irq_host) { pr_err("failed to allocate irq_host\n"); return NULL; } irq_host->host_data = io_base; return irq_host; } unsigned int hlwd_pic_get_irq(void) { return __hlwd_pic_get_irq(hlwd_irq_host); } /* * Probe function. * */ void hlwd_pic_probe(void) { struct irq_host *host; struct device_node *np; const u32 *interrupts; int cascade_virq; for_each_compatible_node(np, NULL, "nintendo,hollywood-pic") { interrupts = of_get_property(np, "interrupts", NULL); if (interrupts) { host = hlwd_pic_init(np); BUG_ON(!host); cascade_virq = irq_of_parse_and_map(np, 0); set_irq_data(cascade_virq, host); set_irq_chained_handler(cascade_virq, hlwd_pic_irq_cascade); } } } /** * hlwd_quiesce() - quiesce hollywood irq controller * * Mask and ack all interrupt sources. * */ void hlwd_quiesce(void) { void __iomem *io_base = hlwd_irq_host->host_data; __hlwd_quiesce(io_base); } --- NEW FILE: hlwd-pic.h --- /* * arch/powerpc/platforms/embedded6xx/hlwd-pic.h * * Nintendo Wii "Hollywood" interrupt controller support. * Copyright (C) 2009 The GameCube Linux Team * Copyright (C) 2009 Albert Herranz * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * */ #ifndef __HLWD_PIC_H #define __HLWD_PIC_H extern unsigned int hlwd_pic_get_irq(void); extern void hlwd_pic_probe(void); extern void hlwd_quiesce(void); #endif |