Skip to content

Commit 26a48c4

Browse files
Thor Thayerlinusw
authored andcommitted
gpio: altera-a10sr: Add A10 System Resource Chip GPIO support.
Add the GPIO functionality for the Altera Arria10 MAX5 System Resource Chip. The A10 MAX5 has 12 bits of GPIO assigned to switches, buttons, and LEDs as a GPIO extender on the SPI bus. Signed-off-by: Thor Thayer <tthayer@opensource.altera.com> Acked-by: Linus Walleij <linus.walleij@linaro.org>i Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent e78ade0 commit 26a48c4

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

drivers/gpio/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,14 @@ config GPIO_ADP5520
818818
This option enables support for on-chip GPIO found
819819
on Analog Devices ADP5520 PMICs.
820820

821+
config GPIO_ALTERA_A10SR
822+
tristate "Altera Arria10 System Resource GPIO"
823+
depends on MFD_ALTERA_A10SR
824+
help
825+
Driver for Arria10 Development Kit GPIO expansion which
826+
includes reads of pushbuttons and DIP switches as well
827+
as writes to LEDs.
828+
821829
config GPIO_ARIZONA
822830
tristate "Wolfson Microelectronics Arizona class devices"
823831
depends on MFD_ARIZONA

drivers/gpio/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
2424
obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
2525
obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
2626
obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o
27+
obj-$(CONFIG_GPIO_ALTERA_A10SR) += gpio-altera-a10sr.o
2728
obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
2829
obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o
2930
obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o

drivers/gpio/gpio-altera-a10sr.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright Intel Corporation (C) 2014-2016. All Rights Reserved
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*
16+
* GPIO driver for Altera Arria10 MAX5 System Resource Chip
17+
*
18+
* Adapted from gpio-tps65910.c
19+
*/
20+
21+
#include <linux/gpio/driver.h>
22+
#include <linux/mfd/altera-a10sr.h>
23+
#include <linux/module.h>
24+
25+
/**
26+
* struct altr_a10sr_gpio - Altera Max5 GPIO device private data structure
27+
* @gp: : instance of the gpio_chip
28+
* @regmap: the regmap from the parent device.
29+
*/
30+
struct altr_a10sr_gpio {
31+
struct gpio_chip gp;
32+
struct regmap *regmap;
33+
};
34+
35+
static int altr_a10sr_gpio_get(struct gpio_chip *chip, unsigned int offset)
36+
{
37+
struct altr_a10sr_gpio *gpio = gpiochip_get_data(chip);
38+
int ret, val;
39+
40+
ret = regmap_read(gpio->regmap, ALTR_A10SR_PBDSW_REG, &val);
41+
if (ret < 0)
42+
return ret;
43+
44+
return !!(val & BIT(offset - ALTR_A10SR_LED_VALID_SHIFT));
45+
}
46+
47+
static void altr_a10sr_gpio_set(struct gpio_chip *chip, unsigned int offset,
48+
int value)
49+
{
50+
struct altr_a10sr_gpio *gpio = gpiochip_get_data(chip);
51+
52+
regmap_update_bits(gpio->regmap, ALTR_A10SR_LED_REG,
53+
BIT(ALTR_A10SR_LED_VALID_SHIFT + offset),
54+
value ? BIT(ALTR_A10SR_LED_VALID_SHIFT + offset)
55+
: 0);
56+
}
57+
58+
static int altr_a10sr_gpio_direction_input(struct gpio_chip *gc,
59+
unsigned int nr)
60+
{
61+
if (nr >= (ALTR_A10SR_IN_VALID_RANGE_LO - ALTR_A10SR_LED_VALID_SHIFT))
62+
return 0;
63+
return -EINVAL;
64+
}
65+
66+
static int altr_a10sr_gpio_direction_output(struct gpio_chip *gc,
67+
unsigned int nr, int value)
68+
{
69+
if (nr <= (ALTR_A10SR_OUT_VALID_RANGE_HI - ALTR_A10SR_LED_VALID_SHIFT))
70+
return 0;
71+
return -EINVAL;
72+
}
73+
74+
static struct gpio_chip altr_a10sr_gc = {
75+
.label = "altr_a10sr_gpio",
76+
.owner = THIS_MODULE,
77+
.get = altr_a10sr_gpio_get,
78+
.set = altr_a10sr_gpio_set,
79+
.direction_input = altr_a10sr_gpio_direction_input,
80+
.direction_output = altr_a10sr_gpio_direction_output,
81+
.can_sleep = true,
82+
.ngpio = 12,
83+
.base = -1,
84+
};
85+
86+
static int altr_a10sr_gpio_probe(struct platform_device *pdev)
87+
{
88+
struct altr_a10sr_gpio *gpio;
89+
int ret;
90+
struct altr_a10sr *a10sr = dev_get_drvdata(pdev->dev.parent);
91+
92+
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
93+
if (!gpio)
94+
return -ENOMEM;
95+
96+
gpio->regmap = a10sr->regmap;
97+
98+
gpio->gp = altr_a10sr_gc;
99+
100+
gpio->gp.of_node = pdev->dev.of_node;
101+
102+
ret = devm_gpiochip_add_data(&pdev->dev, &gpio->gp, gpio);
103+
if (ret < 0) {
104+
dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
105+
return ret;
106+
}
107+
108+
platform_set_drvdata(pdev, gpio);
109+
110+
return 0;
111+
}
112+
113+
static int altr_a10sr_gpio_remove(struct platform_device *pdev)
114+
{
115+
struct altr_a10sr_gpio *gpio = platform_get_drvdata(pdev);
116+
117+
gpiochip_remove(&gpio->gp);
118+
119+
return 0;
120+
}
121+
122+
static const struct of_device_id altr_a10sr_gpio_of_match[] = {
123+
{ .compatible = "altr,a10sr-gpio" },
124+
{ },
125+
};
126+
MODULE_DEVICE_TABLE(of, altr_a10sr_gpio_of_match);
127+
128+
static struct platform_driver altr_a10sr_gpio_driver = {
129+
.probe = altr_a10sr_gpio_probe,
130+
.remove = altr_a10sr_gpio_remove,
131+
.driver = {
132+
.name = "altr_a10sr_gpio",
133+
.of_match_table = of_match_ptr(altr_a10sr_gpio_of_match),
134+
},
135+
};
136+
module_platform_driver(altr_a10sr_gpio_driver);
137+
138+
MODULE_LICENSE("GPL v2");
139+
MODULE_AUTHOR("Thor Thayer <tthayer@opensource.altera.com>");
140+
MODULE_DESCRIPTION("Altera Arria10 System Resource Chip GPIO");

0 commit comments

Comments
 (0)