Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gpio.c
Go to the documentation of this file.
1 /*
2  * linux/arch/unicore32/kernel/gpio.c
3  *
4  * Code specific to PKUnity SoC and UniCore ISA
5  *
6  * Maintained by GUAN Xue-tao <[email protected]>
7  * Copyright (C) 2001-2010 Guan Xuetao
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 /* in FPGA, no GPIO support */
14 
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/gpio.h>
18 #include <mach/hardware.h>
19 
20 #ifdef CONFIG_LEDS
21 #include <linux/leds.h>
22 #include <linux/platform_device.h>
23 
24 static const struct gpio_led puv3_gpio_leds[] = {
25  { .name = "cpuhealth", .gpio = GPO_CPU_HEALTH, .active_low = 0,
26  .default_trigger = "heartbeat", },
27  { .name = "hdd_led", .gpio = GPO_HDD_LED, .active_low = 1,
28  .default_trigger = "ide-disk", },
29 };
30 
31 static const struct gpio_led_platform_data puv3_gpio_led_data = {
32  .num_leds = ARRAY_SIZE(puv3_gpio_leds),
33  .leds = (void *) puv3_gpio_leds,
34 };
35 
36 static struct platform_device puv3_gpio_gpio_leds = {
37  .name = "leds-gpio",
38  .id = -1,
39  .dev = {
40  .platform_data = (void *) &puv3_gpio_led_data,
41  }
42 };
43 
44 static int __init puv3_gpio_leds_init(void)
45 {
46  platform_device_register(&puv3_gpio_gpio_leds);
47  return 0;
48 }
49 
50 device_initcall(puv3_gpio_leds_init);
51 #endif
52 
53 static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
54 {
55  return readl(GPIO_GPLR) & GPIO_GPIO(offset);
56 }
57 
58 static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
59 {
60  if (value)
61  writel(GPIO_GPIO(offset), GPIO_GPSR);
62  else
63  writel(GPIO_GPIO(offset), GPIO_GPCR);
64 }
65 
66 static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
67 {
68  unsigned long flags;
69 
70  local_irq_save(flags);
72  local_irq_restore(flags);
73  return 0;
74 }
75 
76 static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,
77  int value)
78 {
79  unsigned long flags;
80 
81  local_irq_save(flags);
82  puv3_gpio_set(chip, offset, value);
84  local_irq_restore(flags);
85  return 0;
86 }
87 
88 static struct gpio_chip puv3_gpio_chip = {
89  .label = "gpio",
90  .direction_input = puv3_direction_input,
91  .direction_output = puv3_direction_output,
92  .set = puv3_gpio_set,
93  .get = puv3_gpio_get,
94  .base = 0,
95  .ngpio = GPIO_MAX + 1,
96 };
97 
99 {
101 #if defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919) \
102  || defined(CONFIG_PUV3_DB0913)
115 /*
116  * DO NOT modify the GPO_SET_V1 and GPO_SET_V2 in kernel
117  * gpio_set_value(GPO_SET_V1, 1);
118  * gpio_set_value(GPO_SET_V2, 1);
119  */
120 #endif
121  gpiochip_add(&puv3_gpio_chip);
122 }