17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/pci.h>
25 #define IOH_EDGE_FALLING 0
26 #define IOH_EDGE_RISING BIT(0)
27 #define IOH_LEVEL_L BIT(1)
28 #define IOH_LEVEL_H (BIT(0) | BIT(1))
29 #define IOH_EDGE_BOTH BIT(2)
30 #define IOH_IM_MASK (BIT(0) | BIT(1) | BIT(2))
32 #define IOH_IRQ_BASE 0
34 #define PCI_VENDOR_ID_ROHM 0x10DB
104 static const int num_ports[] = {6, 12, 16, 16, 15, 16, 16, 12};
106 static void ioh_gpio_set(
struct gpio_chip *
gpio,
unsigned nr,
int val)
115 reg_val |= (1 <<
nr);
117 reg_val &= ~(1 <<
nr);
120 spin_unlock_irqrestore(&chip->
spinlock, flags);
123 static int ioh_gpio_get(
struct gpio_chip *gpio,
unsigned nr)
130 static int ioh_gpio_direction_output(
struct gpio_chip *gpio,
unsigned nr,
140 ((1 << num_ports[chip->
ch]) - 1);
146 reg_val |= (1 <<
nr);
148 reg_val &= ~(1 <<
nr);
151 spin_unlock_irqrestore(&chip->
spinlock, flags);
156 static int ioh_gpio_direction_input(
struct gpio_chip *gpio,
unsigned nr)
164 ((1 << num_ports[chip->
ch]) - 1);
167 spin_unlock_irqrestore(&chip->
spinlock, flags);
176 static void ioh_gpio_save_reg_conf(
struct ioh_gpio *chip)
180 for (i = 0; i < 8; i ++, chip++) {
202 static void ioh_gpio_restore_reg_conf(
struct ioh_gpio *chip)
206 for (i = 0; i < 8; i ++, chip++) {
208 &chip->
reg->regs[chip->
ch].po);
210 &chip->
reg->regs[chip->
ch].pm);
212 &chip->
reg->regs[chip->
ch].ien);
214 &chip->
reg->regs[chip->
ch].imask);
216 &chip->
reg->regs[chip->
ch].im_0);
218 &chip->
reg->regs[chip->
ch].im_1);
221 &chip->
reg->ioh_sel_reg[i]);
226 static int ioh_gpio_to_irq(
struct gpio_chip *gpio,
unsigned offset)
232 static void ioh_gpio_setup(
struct ioh_gpio *chip,
int num_port)
234 struct gpio_chip *gpio = &chip->
gpio;
236 gpio->label = dev_name(chip->
dev);
238 gpio->direction_input = ioh_gpio_direction_input;
239 gpio->get = ioh_gpio_get;
240 gpio->direction_output = ioh_gpio_direction_output;
241 gpio->set = ioh_gpio_set;
242 gpio->dbg_show =
NULL;
244 gpio->ngpio = num_port;
246 gpio->to_irq = ioh_gpio_to_irq;
249 static int ioh_irq_type(
struct irq_data *
d,
unsigned int type)
259 struct irq_chip_generic *
gc = irq_data_get_irq_chip_data(d);
260 struct ioh_gpio *chip = gc->private;
264 im_reg = &chip->
reg->regs[chip->
ch].im_0;
267 im_reg = &chip->
reg->regs[chip->
ch].im_1;
270 dev_dbg(chip->
dev,
"%s:irq=%d type=%d ch=%d pos=%d type=%d\n",
271 __func__, irq, type, ch, im_pos, type);
301 iowrite32(im | (val << (im_pos * 4)), im_reg);
313 spin_unlock_irqrestore(&chip->
spinlock, flags);
318 static void ioh_irq_unmask(
struct irq_data *d)
320 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
321 struct ioh_gpio *chip = gc->private;
324 &chip->
reg->regs[chip->
ch].imaskclr);
327 static void ioh_irq_mask(
struct irq_data *d)
329 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
330 struct ioh_gpio *chip = gc->private;
333 &chip->
reg->regs[chip->
ch].imask);
336 static void ioh_irq_disable(
struct irq_data *d)
338 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
339 struct ioh_gpio *chip = gc->private;
347 spin_unlock_irqrestore(&chip->
spinlock, flags);
350 static void ioh_irq_enable(
struct irq_data *d)
352 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
353 struct ioh_gpio *chip = gc->private;
361 spin_unlock_irqrestore(&chip->
spinlock, flags);
371 for (i = 0; i < 8; i++, chip++) {
373 for (j = 0; j < num_ports[
i]; j++) {
374 if (reg_val &
BIT(j)) {
376 "%s:[%d]:irq=%d status=0x%x\n",
377 __func__, j, irq, reg_val);
379 &chip->
reg->regs[chip->
ch].iclr);
389 unsigned int irq_start,
unsigned int num)
391 struct irq_chip_generic *gc;
392 struct irq_chip_type *
ct;
399 ct->chip.irq_mask = ioh_irq_mask;
400 ct->chip.irq_unmask = ioh_irq_unmask;
401 ct->chip.irq_set_type = ioh_irq_type;
402 ct->chip.irq_disable = ioh_irq_disable;
403 ct->chip.irq_enable = ioh_irq_enable;
421 dev_err(&pdev->
dev,
"%s : pci_enable_device failed", __func__);
427 dev_err(&pdev->
dev,
"pci_request_regions failed-%d", ret);
428 goto err_request_regions;
431 base = pci_iomap(pdev, 1, 0);
433 dev_err(&pdev->
dev,
"%s : pci_iomap failed", __func__);
438 chip_save = kzalloc(
sizeof(*chip) * 8,
GFP_KERNEL);
439 if (chip_save ==
NULL) {
440 dev_err(&pdev->
dev,
"%s : kzalloc failed", __func__);
446 for (i = 0; i < 8; i++, chip++) {
452 ioh_gpio_setup(chip, num_ports[i]);
455 dev_err(&pdev->
dev,
"IOH gpio: Failed to register GPIO\n");
456 goto err_gpiochip_add;
461 for (j = 0; j < 8; j++, chip++) {
462 irq_base = irq_alloc_descs(-1,
IOH_IRQ_BASE, num_ports[j],
466 "ml_ioh_gpio: Failed to get IRQ base num\n");
468 goto err_irq_alloc_descs;
471 ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]);
479 "%s request_irq failed\n", __func__);
480 goto err_request_irq;
483 pci_set_drvdata(pdev, chip);
501 dev_err(&pdev->
dev,
"Failed gpiochip_remove(%d)\n", i);
516 dev_err(&pdev->
dev,
"%s Failed returns %d\n", __func__, ret);
524 struct ioh_gpio *chip = pci_get_drvdata(pdev);
531 for (i = 0; i < 8; i++, chip++) {
535 dev_err(&pdev->
dev,
"Failed gpiochip_remove\n");
549 struct ioh_gpio *chip = pci_get_drvdata(pdev);
553 ioh_gpio_save_reg_conf(chip);
554 spin_unlock_irqrestore(&chip->
spinlock, flags);
558 dev_err(&pdev->
dev,
"pci_save_state Failed-%d\n", ret);
563 ret = pci_enable_wake(pdev,
PCI_D0, 1);
565 dev_err(&pdev->
dev,
"pci_enable_wake Failed -%d\n", ret);
573 struct ioh_gpio *chip = pci_get_drvdata(pdev);
576 ret = pci_enable_wake(pdev,
PCI_D0, 0);
581 dev_err(&pdev->
dev,
"pci_enable_device Failed-%d ", ret);
589 ioh_gpio_restore_reg_conf(chip);
590 spin_unlock_irqrestore(&chip->
spinlock, flags);
595 #define ioh_gpio_suspend NULL
596 #define ioh_gpio_resume NULL
606 .name =
"ml_ioh_gpio",
607 .id_table = ioh_gpio_pcidev_id,
608 .probe = ioh_gpio_probe,