···11+/*22+ * linux/arch/unicore32/include/asm/irqflags.h33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Copyright (C) 2001-2010 GUAN Xue-tao77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+#ifndef __UNICORE_IRQFLAGS_H__1313+#define __UNICORE_IRQFLAGS_H__1414+1515+#ifdef __KERNEL__1616+1717+#include <asm/ptrace.h>1818+1919+#define ARCH_IRQ_DISABLED (PRIV_MODE | PSR_I_BIT)2020+#define ARCH_IRQ_ENABLED (PRIV_MODE)2121+2222+/*2323+ * Save the current interrupt enable state.2424+ */2525+static inline unsigned long arch_local_save_flags(void)2626+{2727+ unsigned long temp;2828+2929+ asm volatile("mov %0, asr" : "=r" (temp) : : "memory", "cc");3030+3131+ return temp & PSR_c;3232+}3333+3434+/*3535+ * restore saved IRQ state3636+ */3737+static inline void arch_local_irq_restore(unsigned long flags)3838+{3939+ unsigned long temp;4040+4141+ asm volatile(4242+ "mov %0, asr\n"4343+ "mov.a asr, %1\n"4444+ "mov.f asr, %0"4545+ : "=&r" (temp)4646+ : "r" (flags)4747+ : "memory", "cc");4848+}4949+5050+#include <asm-generic/irqflags.h>5151+5252+#endif5353+#endif
+122
arch/unicore32/kernel/gpio.c
···11+/*22+ * linux/arch/unicore32/kernel/gpio.c33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>77+ * Copyright (C) 2001-2010 Guan Xuetao88+ *99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License version 2 as1111+ * published by the Free Software Foundation.1212+ */1313+/* in FPGA, no GPIO support */1414+1515+#include <linux/init.h>1616+#include <linux/module.h>1717+#include <linux/gpio.h>1818+#include <mach/hardware.h>1919+2020+#ifdef CONFIG_LEDS2121+#include <linux/leds.h>2222+#include <linux/platform_device.h>2323+2424+static const struct gpio_led puv3_gpio_leds[] = {2525+ { .name = "cpuhealth", .gpio = GPO_CPU_HEALTH, .active_low = 0,2626+ .default_trigger = "heartbeat", },2727+ { .name = "hdd_led", .gpio = GPO_HDD_LED, .active_low = 1,2828+ .default_trigger = "ide-disk", },2929+};3030+3131+static const struct gpio_led_platform_data puv3_gpio_led_data = {3232+ .num_leds = ARRAY_SIZE(puv3_gpio_leds),3333+ .leds = (void *) puv3_gpio_leds,3434+};3535+3636+static struct platform_device puv3_gpio_gpio_leds = {3737+ .name = "leds-gpio",3838+ .id = -1,3939+ .dev = {4040+ .platform_data = (void *) &puv3_gpio_led_data,4141+ }4242+};4343+4444+static int __init puv3_gpio_leds_init(void)4545+{4646+ platform_device_register(&puv3_gpio_gpio_leds);4747+ return 0;4848+}4949+5050+device_initcall(puv3_gpio_leds_init);5151+#endif5252+5353+static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)5454+{5555+ return GPIO_GPLR & GPIO_GPIO(offset);5656+}5757+5858+static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)5959+{6060+ if (value)6161+ GPIO_GPSR = GPIO_GPIO(offset);6262+ else6363+ GPIO_GPCR = GPIO_GPIO(offset);6464+}6565+6666+static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)6767+{6868+ unsigned long flags;6969+7070+ local_irq_save(flags);7171+ GPIO_GPDR &= ~GPIO_GPIO(offset);7272+ local_irq_restore(flags);7373+ return 0;7474+}7575+7676+static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,7777+ int value)7878+{7979+ unsigned long flags;8080+8181+ local_irq_save(flags);8282+ puv3_gpio_set(chip, offset, value);8383+ GPIO_GPDR |= GPIO_GPIO(offset);8484+ local_irq_restore(flags);8585+ return 0;8686+}8787+8888+static struct gpio_chip puv3_gpio_chip = {8989+ .label = "gpio",9090+ .direction_input = puv3_direction_input,9191+ .direction_output = puv3_direction_output,9292+ .set = puv3_gpio_set,9393+ .get = puv3_gpio_get,9494+ .base = 0,9595+ .ngpio = GPIO_MAX + 1,9696+};9797+9898+void __init puv3_init_gpio(void)9999+{100100+ GPIO_GPDR = GPIO_DIR;101101+#if defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919) \102102+ || defined(CONFIG_PUV3_DB0913)103103+ gpio_set_value(GPO_WIFI_EN, 1);104104+ gpio_set_value(GPO_HDD_LED, 1);105105+ gpio_set_value(GPO_VGA_EN, 1);106106+ gpio_set_value(GPO_LCD_EN, 1);107107+ gpio_set_value(GPO_CAM_PWR_EN, 0);108108+ gpio_set_value(GPO_LCD_VCC_EN, 1);109109+ gpio_set_value(GPO_SOFT_OFF, 1);110110+ gpio_set_value(GPO_BT_EN, 1);111111+ gpio_set_value(GPO_FAN_ON, 0);112112+ gpio_set_value(GPO_SPKR, 0);113113+ gpio_set_value(GPO_CPU_HEALTH, 1);114114+ gpio_set_value(GPO_LAN_SEL, 1);115115+/*116116+ * DO NOT modify the GPO_SET_V1 and GPO_SET_V2 in kernel117117+ * gpio_set_value(GPO_SET_V1, 1);118118+ * gpio_set_value(GPO_SET_V2, 1);119119+ */120120+#endif121121+ gpiochip_add(&puv3_gpio_chip);122122+}
+426
arch/unicore32/kernel/irq.c
···11+/*22+ * linux/arch/unicore32/kernel/irq.c33+ *44+ * Code specific to PKUnity SoC and UniCore ISA55+ *66+ * Copyright (C) 2001-2010 GUAN Xue-tao77+ *88+ * This program is free software; you can redistribute it and/or modify99+ * it under the terms of the GNU General Public License version 2 as1010+ * published by the Free Software Foundation.1111+ */1212+#include <linux/kernel_stat.h>1313+#include <linux/module.h>1414+#include <linux/signal.h>1515+#include <linux/ioport.h>1616+#include <linux/interrupt.h>1717+#include <linux/irq.h>1818+#include <linux/random.h>1919+#include <linux/smp.h>2020+#include <linux/init.h>2121+#include <linux/seq_file.h>2222+#include <linux/errno.h>2323+#include <linux/list.h>2424+#include <linux/kallsyms.h>2525+#include <linux/proc_fs.h>2626+#include <linux/sysdev.h>2727+#include <linux/gpio.h>2828+2929+#include <asm/system.h>3030+#include <mach/hardware.h>3131+3232+#include "setup.h"3333+3434+/*3535+ * PKUnity GPIO edge detection for IRQs:3636+ * IRQs are generated on Falling-Edge, Rising-Edge, or both.3737+ * Use this instead of directly setting GRER/GFER.3838+ */3939+static int GPIO_IRQ_rising_edge;4040+static int GPIO_IRQ_falling_edge;4141+static int GPIO_IRQ_mask = 0;4242+4343+#define GPIO_MASK(irq) (1 << (irq - IRQ_GPIO0))4444+4545+static int puv3_gpio_type(unsigned int irq, unsigned int type)4646+{4747+ unsigned int mask;4848+4949+ if (irq < IRQ_GPIOHIGH)5050+ mask = 1 << irq;5151+ else5252+ mask = GPIO_MASK(irq);5353+5454+ if (type == IRQ_TYPE_PROBE) {5555+ if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)5656+ return 0;5757+ type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;5858+ }5959+6060+ if (type & IRQ_TYPE_EDGE_RISING)6161+ GPIO_IRQ_rising_edge |= mask;6262+ else6363+ GPIO_IRQ_rising_edge &= ~mask;6464+ if (type & IRQ_TYPE_EDGE_FALLING)6565+ GPIO_IRQ_falling_edge |= mask;6666+ else6767+ GPIO_IRQ_falling_edge &= ~mask;6868+6969+ GPIO_GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;7070+ GPIO_GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;7171+7272+ return 0;7373+}7474+7575+/*7676+ * GPIO IRQs must be acknowledged. This is for IRQs from 0 to 7.7777+ */7878+static void puv3_low_gpio_ack(unsigned int irq)7979+{8080+ GPIO_GEDR = (1 << irq);8181+}8282+8383+static void puv3_low_gpio_mask(unsigned int irq)8484+{8585+ INTC_ICMR &= ~(1 << irq);8686+}8787+8888+static void puv3_low_gpio_unmask(unsigned int irq)8989+{9090+ INTC_ICMR |= 1 << irq;9191+}9292+9393+static int puv3_low_gpio_wake(unsigned int irq, unsigned int on)9494+{9595+ if (on)9696+ PM_PWER |= 1 << irq;9797+ else9898+ PM_PWER &= ~(1 << irq);9999+ return 0;100100+}101101+102102+static struct irq_chip puv3_low_gpio_chip = {103103+ .name = "GPIO-low",104104+ .ack = puv3_low_gpio_ack,105105+ .mask = puv3_low_gpio_mask,106106+ .unmask = puv3_low_gpio_unmask,107107+ .set_type = puv3_gpio_type,108108+ .set_wake = puv3_low_gpio_wake,109109+};110110+111111+/*112112+ * IRQ8 (GPIO0 through 27) handler. We enter here with the113113+ * irq_controller_lock held, and IRQs disabled. Decode the IRQ114114+ * and call the handler.115115+ */116116+static void117117+puv3_gpio_handler(unsigned int irq, struct irq_desc *desc)118118+{119119+ unsigned int mask;120120+121121+ mask = GPIO_GEDR;122122+ do {123123+ /*124124+ * clear down all currently active IRQ sources.125125+ * We will be processing them all.126126+ */127127+ GPIO_GEDR = mask;128128+129129+ irq = IRQ_GPIO0;130130+ do {131131+ if (mask & 1)132132+ generic_handle_irq(irq);133133+ mask >>= 1;134134+ irq++;135135+ } while (mask);136136+ mask = GPIO_GEDR;137137+ } while (mask);138138+}139139+140140+/*141141+ * GPIO0-27 edge IRQs need to be handled specially.142142+ * In addition, the IRQs are all collected up into one bit in the143143+ * interrupt controller registers.144144+ */145145+static void puv3_high_gpio_ack(unsigned int irq)146146+{147147+ unsigned int mask = GPIO_MASK(irq);148148+149149+ GPIO_GEDR = mask;150150+}151151+152152+static void puv3_high_gpio_mask(unsigned int irq)153153+{154154+ unsigned int mask = GPIO_MASK(irq);155155+156156+ GPIO_IRQ_mask &= ~mask;157157+158158+ GPIO_GRER &= ~mask;159159+ GPIO_GFER &= ~mask;160160+}161161+162162+static void puv3_high_gpio_unmask(unsigned int irq)163163+{164164+ unsigned int mask = GPIO_MASK(irq);165165+166166+ GPIO_IRQ_mask |= mask;167167+168168+ GPIO_GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;169169+ GPIO_GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;170170+}171171+172172+static int puv3_high_gpio_wake(unsigned int irq, unsigned int on)173173+{174174+ if (on)175175+ PM_PWER |= PM_PWER_GPIOHIGH;176176+ else177177+ PM_PWER &= ~PM_PWER_GPIOHIGH;178178+ return 0;179179+}180180+181181+static struct irq_chip puv3_high_gpio_chip = {182182+ .name = "GPIO-high",183183+ .ack = puv3_high_gpio_ack,184184+ .mask = puv3_high_gpio_mask,185185+ .unmask = puv3_high_gpio_unmask,186186+ .set_type = puv3_gpio_type,187187+ .set_wake = puv3_high_gpio_wake,188188+};189189+190190+/*191191+ * We don't need to ACK IRQs on the PKUnity unless they're GPIOs192192+ * this is for internal IRQs i.e. from 8 to 31.193193+ */194194+static void puv3_mask_irq(unsigned int irq)195195+{196196+ INTC_ICMR &= ~(1 << irq);197197+}198198+199199+static void puv3_unmask_irq(unsigned int irq)200200+{201201+ INTC_ICMR |= (1 << irq);202202+}203203+204204+/*205205+ * Apart form GPIOs, only the RTC alarm can be a wakeup event.206206+ */207207+static int puv3_set_wake(unsigned int irq, unsigned int on)208208+{209209+ if (irq == IRQ_RTCAlarm) {210210+ if (on)211211+ PM_PWER |= PM_PWER_RTC;212212+ else213213+ PM_PWER &= ~PM_PWER_RTC;214214+ return 0;215215+ }216216+ return -EINVAL;217217+}218218+219219+static struct irq_chip puv3_normal_chip = {220220+ .name = "PKUnity-v3",221221+ .ack = puv3_mask_irq,222222+ .mask = puv3_mask_irq,223223+ .unmask = puv3_unmask_irq,224224+ .set_wake = puv3_set_wake,225225+};226226+227227+static struct resource irq_resource = {228228+ .name = "irqs",229229+ .start = PKUNITY_INTC_BASE,230230+ .end = PKUNITY_INTC_BASE + 0xFFFFF,231231+};232232+233233+static struct puv3_irq_state {234234+ unsigned int saved;235235+ unsigned int icmr;236236+ unsigned int iclr;237237+ unsigned int iccr;238238+} puv3_irq_state;239239+240240+static int puv3_irq_suspend(struct sys_device *dev, pm_message_t state)241241+{242242+ struct puv3_irq_state *st = &puv3_irq_state;243243+244244+ st->saved = 1;245245+ st->icmr = INTC_ICMR;246246+ st->iclr = INTC_ICLR;247247+ st->iccr = INTC_ICCR;248248+249249+ /*250250+ * Disable all GPIO-based interrupts.251251+ */252252+ INTC_ICMR &= ~(0x1ff);253253+254254+ /*255255+ * Set the appropriate edges for wakeup.256256+ */257257+ GPIO_GRER = PM_PWER & GPIO_IRQ_rising_edge;258258+ GPIO_GFER = PM_PWER & GPIO_IRQ_falling_edge;259259+260260+ /*261261+ * Clear any pending GPIO interrupts.262262+ */263263+ GPIO_GEDR = GPIO_GEDR;264264+265265+ return 0;266266+}267267+268268+static int puv3_irq_resume(struct sys_device *dev)269269+{270270+ struct puv3_irq_state *st = &puv3_irq_state;271271+272272+ if (st->saved) {273273+ INTC_ICCR = st->iccr;274274+ INTC_ICLR = st->iclr;275275+276276+ GPIO_GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;277277+ GPIO_GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;278278+279279+ INTC_ICMR = st->icmr;280280+ }281281+ return 0;282282+}283283+284284+static struct sysdev_class puv3_irq_sysclass = {285285+ .name = "pkunity-irq",286286+ .suspend = puv3_irq_suspend,287287+ .resume = puv3_irq_resume,288288+};289289+290290+static struct sys_device puv3_irq_device = {291291+ .id = 0,292292+ .cls = &puv3_irq_sysclass,293293+};294294+295295+static int __init puv3_irq_init_devicefs(void)296296+{297297+ sysdev_class_register(&puv3_irq_sysclass);298298+ return sysdev_register(&puv3_irq_device);299299+}300300+301301+device_initcall(puv3_irq_init_devicefs);302302+303303+void __init init_IRQ(void)304304+{305305+ unsigned int irq;306306+307307+ request_resource(&iomem_resource, &irq_resource);308308+309309+ /* disable all IRQs */310310+ INTC_ICMR = 0;311311+312312+ /* all IRQs are IRQ, not REAL */313313+ INTC_ICLR = 0;314314+315315+ /* clear all GPIO edge detects */316316+ GPIO_GPIR = FMASK(8, 0) & ~FIELD(1, 1, GPI_SOFF_REQ);317317+ GPIO_GFER = 0;318318+ GPIO_GRER = 0;319319+ GPIO_GEDR = 0x0FFFFFFF;320320+321321+ INTC_ICCR = 1;322322+323323+ for (irq = 0; irq < IRQ_GPIOHIGH; irq++) {324324+ set_irq_chip(irq, &puv3_low_gpio_chip);325325+ set_irq_handler(irq, handle_edge_irq);326326+ irq_modify_status(irq,327327+ IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN,328328+ 0);329329+ }330330+331331+ for (irq = IRQ_GPIOHIGH + 1; irq < IRQ_GPIO0; irq++) {332332+ set_irq_chip(irq, &puv3_normal_chip);333333+ set_irq_handler(irq, handle_level_irq);334334+ irq_modify_status(irq,335335+ IRQ_NOREQUEST | IRQ_NOAUTOEN,336336+ IRQ_NOPROBE);337337+ }338338+339339+ for (irq = IRQ_GPIO0; irq <= IRQ_GPIO27; irq++) {340340+ set_irq_chip(irq, &puv3_high_gpio_chip);341341+ set_irq_handler(irq, handle_edge_irq);342342+ irq_modify_status(irq,343343+ IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN,344344+ 0);345345+ }346346+347347+ /*348348+ * Install handler for GPIO 0-27 edge detect interrupts349349+ */350350+ set_irq_chip(IRQ_GPIOHIGH, &puv3_normal_chip);351351+ set_irq_chained_handler(IRQ_GPIOHIGH, puv3_gpio_handler);352352+353353+#ifdef CONFIG_PUV3_GPIO354354+ puv3_init_gpio();355355+#endif356356+}357357+358358+int show_interrupts(struct seq_file *p, void *v)359359+{360360+ int i = *(loff_t *) v, cpu;361361+ struct irq_desc *desc;362362+ struct irqaction *action;363363+ unsigned long flags;364364+365365+ if (i == 0) {366366+ char cpuname[12];367367+368368+ seq_printf(p, " ");369369+ for_each_present_cpu(cpu) {370370+ sprintf(cpuname, "CPU%d", cpu);371371+ seq_printf(p, " %10s", cpuname);372372+ }373373+ seq_putc(p, '\n');374374+ }375375+376376+ if (i < nr_irqs) {377377+ desc = irq_to_desc(i);378378+ raw_spin_lock_irqsave(&desc->lock, flags);379379+ action = desc->action;380380+ if (!action)381381+ goto unlock;382382+383383+ seq_printf(p, "%3d: ", i);384384+ for_each_present_cpu(cpu)385385+ seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));386386+ seq_printf(p, " %10s", desc->chip->name ? : "-");387387+ seq_printf(p, " %s", action->name);388388+ for (action = action->next; action; action = action->next)389389+ seq_printf(p, ", %s", action->name);390390+391391+ seq_putc(p, '\n');392392+unlock:393393+ raw_spin_unlock_irqrestore(&desc->lock, flags);394394+ } else if (i == nr_irqs) {395395+ seq_printf(p, "Error in interrupt!\n");396396+ }397397+ return 0;398398+}399399+400400+/*401401+ * do_IRQ handles all hardware IRQ's. Decoded IRQs should not402402+ * come via this function. Instead, they should provide their403403+ * own 'handler'404404+ */405405+asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)406406+{407407+ struct pt_regs *old_regs = set_irq_regs(regs);408408+409409+ irq_enter();410410+411411+ /*412412+ * Some hardware gives randomly wrong interrupts. Rather413413+ * than crashing, do something sensible.414414+ */415415+ if (unlikely(irq >= nr_irqs)) {416416+ if (printk_ratelimit())417417+ printk(KERN_WARNING "Bad IRQ%u\n", irq);418418+ ack_bad_irq(irq);419419+ } else {420420+ generic_handle_irq(irq);421421+ }422422+423423+ irq_exit();424424+ set_irq_regs(old_regs);425425+}426426+