22 #include <linux/module.h>
23 #include <linux/kernel.h>
27 #include <linux/pci.h>
30 #include <linux/slab.h>
44 static int rdc_gpio_get_value(
struct gpio_chip *
chip,
unsigned gpio)
53 spin_lock(&gpch->
lock);
54 pci_write_config_dword(gpch->
sb_pdev, reg,
56 pci_read_config_dword(gpch->
sb_pdev, reg, &value);
57 spin_unlock(&gpch->
lock);
59 return (1 << (gpio & 0x1f)) & value ? 1 : 0;
62 static void rdc_gpio_set_value_impl(
struct gpio_chip *chip,
63 unsigned gpio,
int value)
66 int reg = (gpio < 32) ? 0 : 1;
75 pci_write_config_dword(gpch->
sb_pdev,
81 static void rdc_gpio_set_value(
struct gpio_chip *chip,
82 unsigned gpio,
int value)
87 spin_lock(&gpch->
lock);
88 rdc_gpio_set_value_impl(chip, gpio, value);
89 spin_unlock(&gpch->
lock);
92 static int rdc_gpio_config(
struct gpio_chip *chip,
93 unsigned gpio,
int value)
101 spin_lock(&gpch->
lock);
102 err = pci_read_config_dword(gpch->
sb_pdev, gpio < 32 ?
107 reg |= 1 << (gpio & 0x1f);
109 err = pci_write_config_dword(gpch->
sb_pdev, gpio < 32 ?
114 rdc_gpio_set_value_impl(chip, gpio, value);
117 spin_unlock(&gpch->
lock);
123 static int rdc_gpio_direction_input(
struct gpio_chip *chip,
unsigned gpio)
125 return rdc_gpio_config(chip, gpio, 1);
138 pdata = pdev->
dev.platform_data;
140 dev_err(&pdev->
dev,
"no platform data supplied\n");
145 if (!rdc321x_gpio_dev) {
146 dev_err(&pdev->
dev,
"failed to allocate private data\n");
152 dev_err(&pdev->
dev,
"failed to get gpio-reg1 resource\n");
164 dev_err(&pdev->
dev,
"failed to get gpio-reg2 resource\n");
172 rdc321x_gpio_dev->
chip.label =
"rdc321x-gpio";
174 rdc321x_gpio_dev->
chip.direction_input = rdc_gpio_direction_input;
175 rdc321x_gpio_dev->
chip.direction_output = rdc_gpio_config;
176 rdc321x_gpio_dev->
chip.get = rdc_gpio_get_value;
177 rdc321x_gpio_dev->
chip.set = rdc_gpio_set_value;
178 rdc321x_gpio_dev->
chip.base = 0;
181 platform_set_drvdata(pdev, rdc321x_gpio_dev);
186 err = pci_read_config_dword(rdc321x_gpio_dev->
sb_pdev,
192 err = pci_read_config_dword(rdc321x_gpio_dev->
sb_pdev,
199 rdc321x_gpio_dev->
chip.ngpio);
203 platform_set_drvdata(pdev,
NULL);
205 kfree(rdc321x_gpio_dev);
212 struct rdc321x_gpio *rdc321x_gpio_dev = platform_get_drvdata(pdev);
216 dev_err(&pdev->
dev,
"failed to unregister chip\n");
218 kfree(rdc321x_gpio_dev);
219 platform_set_drvdata(pdev,
NULL);
225 .driver.name =
"rdc321x-gpio",
227 .probe = rdc321x_gpio_probe,