26 #include <linux/module.h>
27 #include <linux/pci.h>
29 #include <linux/kernel.h>
31 #include <linux/stddef.h>
37 #include <linux/slab.h>
78 unsigned nreg = chip->ngpio / 32;
90 unsigned nreg = chip->ngpio / 32;
98 static int lnw_gpio_request(
struct gpio_chip *chip,
unsigned offset)
100 void __iomem *gafr = gpio_reg_2bit(chip, offset,
GAFR);
102 int shift = (offset % 16) << 1, af = (value >> shift) & 3;
105 value &= ~(3 << shift);
111 static int lnw_gpio_get(
struct gpio_chip *chip,
unsigned offset)
115 return readl(gplr) &
BIT(offset % 32);
118 static void lnw_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
123 gpsr = gpio_reg(chip, offset,
GPSR);
126 gpcr = gpio_reg(chip, offset,
GPCR);
131 static int lnw_gpio_direction_input(
struct gpio_chip *chip,
unsigned offset)
139 pm_runtime_get(&lnw->
pdev->dev);
143 value &= ~
BIT(offset % 32);
145 spin_unlock_irqrestore(&lnw->
lock, flags);
148 pm_runtime_put(&lnw->
pdev->dev);
153 static int lnw_gpio_direction_output(
struct gpio_chip *chip,
154 unsigned offset,
int value)
160 lnw_gpio_set(chip, offset, value);
163 pm_runtime_get(&lnw->
pdev->dev);
167 value |=
BIT(offset % 32);
169 spin_unlock_irqrestore(&lnw->
lock, flags);
172 pm_runtime_put(&lnw->
pdev->dev);
177 static int lnw_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
185 struct lnw_gpio *lnw = irq_data_get_irq_chip_data(d);
192 if (gpio >= lnw->
chip.ngpio)
196 pm_runtime_get(&lnw->
pdev->dev);
200 value =
readl(grer) |
BIT(gpio % 32);
202 value =
readl(grer) & (~
BIT(gpio % 32));
206 value =
readl(gfer) |
BIT(gpio % 32);
208 value =
readl(gfer) & (~
BIT(gpio % 32));
210 spin_unlock_irqrestore(&lnw->
lock, flags);
213 pm_runtime_put(&lnw->
pdev->dev);
218 static void lnw_irq_unmask(
struct irq_data *d)
222 static void lnw_irq_mask(
struct irq_data *d)
226 static struct irq_chip lnw_irqchip = {
228 .irq_mask = lnw_irq_mask,
229 .irq_unmask = lnw_irq_unmask,
230 .irq_set_type = lnw_irq_type,
241 static void lnw_irq_handler(
unsigned irq,
struct irq_desc *
desc)
244 struct lnw_gpio *lnw = irq_data_get_irq_handler_data(data);
245 struct irq_chip *chip = irq_data_get_irq_chip(data);
247 unsigned long pending;
251 for (base = 0; base < lnw->
chip.ngpio; base += 32) {
252 gedr = gpio_reg(&lnw->
chip, base,
GEDR);
253 while ((pending =
readl(gedr))) {
254 gpio =
__ffs(pending);
266 static void lnw_irq_init_hw(
struct lnw_gpio *lnw)
271 for (base = 0; base < lnw->
chip.ngpio; base += 32) {
273 reg = gpio_reg(&lnw->
chip, base,
GRER);
276 reg = gpio_reg(&lnw->
chip, base,
GFER);
279 reg = gpio_reg(&lnw->
chip, base,
GEDR);
284 static int lnw_gpio_irq_map(
struct irq_domain *d,
unsigned int virq,
298 .map = lnw_gpio_irq_map,
324 #define lnw_gpio_runtime_suspend NULL
325 #define lnw_gpio_runtime_resume NULL
326 #define lnw_gpio_runtime_idle NULL
329 static const struct dev_pm_ops lnw_gpio_pm_ops = {
343 int ngpio =
id->driver_data;
351 dev_err(&pdev->
dev,
"error requesting resources\n");
363 gpio_base = *((
u32 *)base + 1);
378 dev_err(&pdev->
dev,
"can't allocate langwell_gpio chip data\n");
384 &lnw_gpio_irq_ops, lnw);
391 lnw->
chip.label = dev_name(&pdev->
dev);
392 lnw->
chip.request = lnw_gpio_request;
393 lnw->
chip.direction_input = lnw_gpio_direction_input;
394 lnw->
chip.direction_output = lnw_gpio_direction_output;
395 lnw->
chip.get = lnw_gpio_get;
396 lnw->
chip.set = lnw_gpio_set;
397 lnw->
chip.to_irq = lnw_gpio_to_irq;
399 lnw->
chip.ngpio = ngpio;
400 lnw->
chip.can_sleep = 0;
402 pci_set_drvdata(pdev, lnw);
405 dev_err(&pdev->
dev,
"langwell gpiochip_add error %d\n", retval);
409 lnw_irq_init_hw(lnw);
412 irq_set_chained_handler(pdev->
irq, lnw_irq_handler);
416 pm_runtime_put_noidle(&pdev->
dev);
429 .name =
"langwell_gpio",
430 .id_table = lnw_gpio_ids,
431 .probe = lnw_gpio_probe,
433 .pm = &lnw_gpio_pm_ops,
441 struct gpio_chip *
gc;
452 "can't allocate whitneypoint_gpio chip data\n");
462 gc->label = dev_name(&pdev->
dev);
464 gc->direction_input = lnw_gpio_direction_input;
465 gc->direction_output = lnw_gpio_direction_output;
466 gc->get = lnw_gpio_get;
467 gc->set = lnw_gpio_set;
474 dev_err(&pdev->
dev,
"whitneypoint gpiochip_add error %d\n",
478 platform_set_drvdata(pdev, lnw);
489 struct lnw_gpio *lnw = platform_get_drvdata(pdev);
493 dev_err(&pdev->
dev,
"failed to remove gpio_chip.\n");
496 platform_set_drvdata(pdev,
NULL);
501 .probe = wp_gpio_probe,
509 static int __init lnw_gpio_init(
void)
512 ret = pci_register_driver(&lnw_gpio_driver);