0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/interrupt.h>
0009 #include <linux/kernel.h>
0010 #include <linux/mod_devicetable.h>
0011 #include <linux/module.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/property.h>
0014 #include <linux/regmap.h>
0015
0016 #define INTC_IE 0x00
0017 #define INTC_IP 0x01
0018
0019 static const struct regmap_irq sl28cpld_irqs[] = {
0020 REGMAP_IRQ_REG_LINE(0, 8),
0021 REGMAP_IRQ_REG_LINE(1, 8),
0022 REGMAP_IRQ_REG_LINE(2, 8),
0023 REGMAP_IRQ_REG_LINE(3, 8),
0024 REGMAP_IRQ_REG_LINE(4, 8),
0025 REGMAP_IRQ_REG_LINE(5, 8),
0026 REGMAP_IRQ_REG_LINE(6, 8),
0027 REGMAP_IRQ_REG_LINE(7, 8),
0028 };
0029
0030 struct sl28cpld_intc {
0031 struct regmap *regmap;
0032 struct regmap_irq_chip chip;
0033 struct regmap_irq_chip_data *irq_data;
0034 };
0035
0036 static int sl28cpld_intc_probe(struct platform_device *pdev)
0037 {
0038 struct device *dev = &pdev->dev;
0039 struct sl28cpld_intc *irqchip;
0040 int irq;
0041 u32 base;
0042 int ret;
0043
0044 if (!dev->parent)
0045 return -ENODEV;
0046
0047 irqchip = devm_kzalloc(dev, sizeof(*irqchip), GFP_KERNEL);
0048 if (!irqchip)
0049 return -ENOMEM;
0050
0051 irqchip->regmap = dev_get_regmap(dev->parent, NULL);
0052 if (!irqchip->regmap)
0053 return -ENODEV;
0054
0055 irq = platform_get_irq(pdev, 0);
0056 if (irq < 0)
0057 return irq;
0058
0059 ret = device_property_read_u32(&pdev->dev, "reg", &base);
0060 if (ret)
0061 return -EINVAL;
0062
0063 irqchip->chip.name = "sl28cpld-intc";
0064 irqchip->chip.irqs = sl28cpld_irqs;
0065 irqchip->chip.num_irqs = ARRAY_SIZE(sl28cpld_irqs);
0066 irqchip->chip.num_regs = 1;
0067 irqchip->chip.status_base = base + INTC_IP;
0068 irqchip->chip.mask_base = base + INTC_IE;
0069 irqchip->chip.mask_invert = true;
0070 irqchip->chip.ack_base = base + INTC_IP;
0071
0072 return devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev),
0073 irqchip->regmap, irq,
0074 IRQF_SHARED | IRQF_ONESHOT, 0,
0075 &irqchip->chip,
0076 &irqchip->irq_data);
0077 }
0078
0079 static const struct of_device_id sl28cpld_intc_of_match[] = {
0080 { .compatible = "kontron,sl28cpld-intc" },
0081 {}
0082 };
0083 MODULE_DEVICE_TABLE(of, sl28cpld_intc_of_match);
0084
0085 static struct platform_driver sl28cpld_intc_driver = {
0086 .probe = sl28cpld_intc_probe,
0087 .driver = {
0088 .name = "sl28cpld-intc",
0089 .of_match_table = sl28cpld_intc_of_match,
0090 }
0091 };
0092 module_platform_driver(sl28cpld_intc_driver);
0093
0094 MODULE_DESCRIPTION("sl28cpld Interrupt Controller Driver");
0095 MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
0096 MODULE_LICENSE("GPL");