13 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/device.h>
20 #include <linux/ctype.h>
22 #include <linux/slab.h>
29 static struct pio2_card *gpio_to_pio2_card(
struct gpio_chip *
chip)
34 static int pio2_gpio_get(
struct gpio_chip *
chip,
unsigned int offset)
40 if ((card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
OUTPUT) |
41 (card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
NOFIT)) {
43 dev_err(&card->
vdev->dev,
"Channel not available as input\n");
48 PIO2_REGS_DATA[PIO2_CHANNEL_BANK[offset]]);
50 dev_err(&card->
vdev->dev,
"Unable to read from GPIO\n");
58 if (reg & PIO2_CHANNEL_BIT[offset]) {
59 if (card->
bank[PIO2_CHANNEL_BANK[offset]].config !=
BOTH)
64 if (card->
bank[PIO2_CHANNEL_BANK[offset]].config !=
BOTH)
71 static void pio2_gpio_set(
struct gpio_chip *chip,
unsigned int offset,
76 struct pio2_card *card = gpio_to_pio2_card(chip);
78 if ((card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
INPUT) |
79 (card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
NOFIT)) {
81 dev_err(&card->
vdev->dev,
"Channel not available as output\n");
86 reg = card->
bank[PIO2_CHANNEL_BANK[
offset]].value |
89 reg = card->
bank[PIO2_CHANNEL_BANK[
offset]].value &
93 PIO2_REGS_DATA[PIO2_CHANNEL_BANK[offset]]);
95 dev_err(&card->
vdev->dev,
"Unable to write to GPIO\n");
103 static int pio2_gpio_dir_in(
struct gpio_chip *chip,
unsigned offset)
106 struct pio2_card *card = gpio_to_pio2_card(chip);
108 if ((card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
OUTPUT) |
109 (card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
NOFIT)) {
111 "Channel directionality not configurable at runtine\n");
122 static int pio2_gpio_dir_out(
struct gpio_chip *chip,
unsigned offset,
int value)
125 struct pio2_card *card = gpio_to_pio2_card(chip);
127 if ((card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
INPUT) |
128 (card->
bank[PIO2_CHANNEL_BANK[offset]].config ==
NOFIT)) {
130 "Channel directionality not configurable at runtine\n");
152 for (i = 0; i < 4; i++) {
157 card->
bank[
i].value = 0;
161 for (i = 0; i < 4; i++) {
163 PIO2_REGS_INT_MASK[i * 2]);
168 PIO2_REGS_INT_MASK[(i * 2) + 1]);
172 for (j = 0; j < 8; j++)
177 for (i = 0; i < 4; i++) {
180 PIO2_REGS_INT_STAT[i]);
196 dev_err(&card->
vdev->dev,
"Unable to allocate GPIO label\n");
207 card->
gc.direction_input = pio2_gpio_dir_in;
208 card->
gc.direction_output = pio2_gpio_dir_out;
209 card->
gc.get = pio2_gpio_get;
210 card->
gc.set = pio2_gpio_set;
215 dev_err(&card->
vdev->dev,
"Unable to register GPIO\n");
224 const char *
label = card->
gc.label;
227 dev_err(&card->
vdev->dev,
"Failed to remove GPIO");