1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * SDK7786 FPGA USRGPIR Support.
4  *
5  * Copyright (C) 2010  Paul Mundt
6  */
7 #include <linux/init.h>
8 #include <linux/interrupt.h>
9 #include <linux/gpio/driver.h>
10 #include <linux/irq.h>
11 #include <linux/kernel.h>
12 #include <linux/spinlock.h>
13 #include <linux/io.h>
14 #include <mach/fpga.h>
15 
16 #define NR_FPGA_GPIOS	8
17 
18 static const char *usrgpir_gpio_names[NR_FPGA_GPIOS] = {
19 	"in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7",
20 };
21 
usrgpir_gpio_direction_input(struct gpio_chip * chip,unsigned gpio)22 static int usrgpir_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
23 {
24 	/* always in */
25 	return 0;
26 }
27 
usrgpir_gpio_get(struct gpio_chip * chip,unsigned gpio)28 static int usrgpir_gpio_get(struct gpio_chip *chip, unsigned gpio)
29 {
30 	return !!(fpga_read_reg(USRGPIR) & (1 << gpio));
31 }
32 
33 static struct gpio_chip usrgpir_gpio_chip = {
34 	.label			= "sdk7786-fpga",
35 	.names			= usrgpir_gpio_names,
36 	.direction_input	= usrgpir_gpio_direction_input,
37 	.get			= usrgpir_gpio_get,
38 	.base			= -1, /* don't care */
39 	.ngpio			= NR_FPGA_GPIOS,
40 };
41 
usrgpir_gpio_setup(void)42 static int __init usrgpir_gpio_setup(void)
43 {
44 	return gpiochip_add_data(&usrgpir_gpio_chip, NULL);
45 }
46 device_initcall(usrgpir_gpio_setup);
47