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 <gxt@mprc.pku.edu.cn>
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
24static 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
31static 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
36static 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
44static int __init puv3_gpio_leds_init(void)
45{
46	platform_device_register(&puv3_gpio_gpio_leds);
47	return 0;
48}
49
50device_initcall(puv3_gpio_leds_init);
51#endif
52
53static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
54{
55	return readl(GPIO_GPLR) & GPIO_GPIO(offset);
56}
57
58static 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
66static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
67{
68	unsigned long flags;
69
70	local_irq_save(flags);
71	writel(readl(GPIO_GPDR) & ~GPIO_GPIO(offset), GPIO_GPDR);
72	local_irq_restore(flags);
73	return 0;
74}
75
76static 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);
83	writel(readl(GPIO_GPDR) | GPIO_GPIO(offset), GPIO_GPDR);
84	local_irq_restore(flags);
85	return 0;
86}
87
88static 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
98void __init puv3_init_gpio(void)
99{
100	writel(GPIO_DIR, GPIO_GPDR);
101#if	defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919)	\
102	|| defined(CONFIG_PUV3_DB0913)
103	gpio_set_value(GPO_WIFI_EN, 1);
104	gpio_set_value(GPO_HDD_LED, 1);
105	gpio_set_value(GPO_VGA_EN, 1);
106	gpio_set_value(GPO_LCD_EN, 1);
107	gpio_set_value(GPO_CAM_PWR_EN, 0);
108	gpio_set_value(GPO_LCD_VCC_EN, 1);
109	gpio_set_value(GPO_SOFT_OFF, 1);
110	gpio_set_value(GPO_BT_EN, 1);
111	gpio_set_value(GPO_FAN_ON, 0);
112	gpio_set_value(GPO_SPKR, 0);
113	gpio_set_value(GPO_CPU_HEALTH, 1);
114	gpio_set_value(GPO_LAN_SEL, 1);
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}
123