Commit 257672f0 authored by Dimitris Lampridis's avatar Dimitris Lampridis

[sw][kernel] use modified struct gpio_chip in kernels 4.5 and newer

Signed-off-by: Dimitris Lampridis's avatarDimitris Lampridis <dimitris.lampridis@cern.ch>
parent 27670211
...@@ -77,12 +77,18 @@ static int gn412x_dbg_init(struct gn412x_gpio_dev *gn412x) ...@@ -77,12 +77,18 @@ static int gn412x_dbg_init(struct gn412x_gpio_dev *gn412x)
struct dentry *dir, *file; struct dentry *dir, *file;
int err; int err;
dir = debugfs_create_dir(dev_name(gn412x->gpiochip.dev), NULL); #if KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
struct device *dev = gn412x->gpiochip.dev;
#else
struct device *dev = gn412x->gpiochip.parent;
#endif
dir = debugfs_create_dir(dev_name(dev), NULL);
if (IS_ERR_OR_NULL(dir)) { if (IS_ERR_OR_NULL(dir)) {
err = PTR_ERR(dir); err = PTR_ERR(dir);
dev_warn(gn412x->gpiochip.dev, dev_warn(dev,
"Cannot create debugfs directory \"%s\" (%d)\n", "Cannot create debugfs directory \"%s\" (%d)\n",
dev_name(gn412x->gpiochip.dev), err); dev_name(dev), err);
goto err_dir; goto err_dir;
} }
...@@ -93,7 +99,7 @@ static int gn412x_dbg_init(struct gn412x_gpio_dev *gn412x) ...@@ -93,7 +99,7 @@ static int gn412x_dbg_init(struct gn412x_gpio_dev *gn412x)
dir, &gn412x->dbg_reg32); dir, &gn412x->dbg_reg32);
if (IS_ERR_OR_NULL(file)) { if (IS_ERR_OR_NULL(file)) {
err = PTR_ERR(file); err = PTR_ERR(file);
dev_warn(gn412x->gpiochip.dev, dev_warn(dev,
"Cannot create debugfs file \"%s\" (%d)\n", "Cannot create debugfs file \"%s\" (%d)\n",
GN412X_DBG_REG_NAME, err); GN412X_DBG_REG_NAME, err);
goto err_reg32; goto err_reg32;
...@@ -183,9 +189,15 @@ static int gn412x_gpio_request(struct gpio_chip *chip, unsigned int offset) ...@@ -183,9 +189,15 @@ static int gn412x_gpio_request(struct gpio_chip *chip, unsigned int offset)
{ {
int val; int val;
#if KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
struct device *dev = chip->dev;
#else
struct device *dev = chip->parent;
#endif
val = gn412x_gpio_reg_read(chip, GNGPIO_BYPASS_MODE, offset); val = gn412x_gpio_reg_read(chip, GNGPIO_BYPASS_MODE, offset);
if (val) { if (val) {
dev_err(chip->dev, "%s GPIO %d is in BYPASS mode\n", dev_err(dev, "%s GPIO %d is in BYPASS mode\n",
chip->label, offset); chip->label, offset);
return -EBUSY; return -EBUSY;
} }
...@@ -264,13 +276,19 @@ static int gn412x_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type) ...@@ -264,13 +276,19 @@ static int gn412x_gpio_irq_set_type(struct irq_data *d, unsigned int flow_type)
{ {
struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
#if KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
struct device *dev = gc->dev;
#else
struct device *dev = gc->parent;
#endif
/* /*
* detect errors: * detect errors:
* - level and edge together cannot work * - level and edge together cannot work
*/ */
if ((flow_type & IRQ_TYPE_LEVEL_MASK) && if ((flow_type & IRQ_TYPE_LEVEL_MASK) &&
(flow_type & IRQ_TYPE_EDGE_BOTH)) { (flow_type & IRQ_TYPE_EDGE_BOTH)) {
dev_err(gc->dev, dev_err(dev,
"Impossible to set GPIO IRQ %ld to both LEVEL and EDGE (0x%x)\n", "Impossible to set GPIO IRQ %ld to both LEVEL and EDGE (0x%x)\n",
d->hwirq, flow_type); d->hwirq, flow_type);
return -EINVAL; return -EINVAL;
...@@ -381,6 +399,12 @@ static irqreturn_t gn412x_gpio_irq_handler_t(int irq, void *arg) ...@@ -381,6 +399,12 @@ static irqreturn_t gn412x_gpio_irq_handler_t(int irq, void *arg)
irqreturn_t ret = IRQ_NONE; irqreturn_t ret = IRQ_NONE;
int i; int i;
#if KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
struct device *dev = gc->dev;
#else
struct device *dev = gc->parent;
#endif
gpio_int_status = gn412x_ioread32(gn412x, GNGPIO_INT_STATUS); gpio_int_status = gn412x_ioread32(gn412x, GNGPIO_INT_STATUS);
gpio_int_status &= ~gn412x_ioread32(gn412x, GNGPIO_INT_MASK); gpio_int_status &= ~gn412x_ioread32(gn412x, GNGPIO_INT_MASK);
if (!gpio_int_status) if (!gpio_int_status)
...@@ -500,7 +524,11 @@ static int gn412x_gpio_probe(struct platform_device *pdev) ...@@ -500,7 +524,11 @@ static int gn412x_gpio_probe(struct platform_device *pdev)
} }
gn412x_iowrite32(gn412x, 0, GNGPIO_BYPASS_MODE); gn412x_iowrite32(gn412x, 0, GNGPIO_BYPASS_MODE);
#if KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
gn412x->gpiochip.dev = &pdev->dev; gn412x->gpiochip.dev = &pdev->dev;
#else
gn412x->gpiochip.parent = &pdev->dev;
#endif
gn412x->gpiochip.label = "gn412x-gpio"; gn412x->gpiochip.label = "gn412x-gpio";
gn412x->gpiochip.owner = THIS_MODULE; gn412x->gpiochip.owner = THIS_MODULE;
gn412x->gpiochip.request = gn412x_gpio_request; gn412x->gpiochip.request = gn412x_gpio_request;
...@@ -529,6 +557,7 @@ static int gn412x_gpio_probe(struct platform_device *pdev) ...@@ -529,6 +557,7 @@ static int gn412x_gpio_probe(struct platform_device *pdev)
gn412x_gpio_irq_set_nested_thread_all(gn412x, true); gn412x_gpio_irq_set_nested_thread_all(gn412x, true);
#if KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
err = request_threaded_irq(platform_get_irq(pdev, 0), err = request_threaded_irq(platform_get_irq(pdev, 0),
gn412x_gpio_irq_handler_h, gn412x_gpio_irq_handler_h,
gn412x_gpio_irq_handler_t, gn412x_gpio_irq_handler_t,
...@@ -537,6 +566,16 @@ static int gn412x_gpio_probe(struct platform_device *pdev) ...@@ -537,6 +566,16 @@ static int gn412x_gpio_probe(struct platform_device *pdev)
gn412x); gn412x);
if (err) { if (err) {
dev_err(gn412x->gpiochip.dev, "Can't request IRQ %d (%d)\n", dev_err(gn412x->gpiochip.dev, "Can't request IRQ %d (%d)\n",
#else
err = request_threaded_irq(platform_get_irq(pdev, 0),
gn412x_gpio_irq_handler_h,
gn412x_gpio_irq_handler_t,
IRQF_SHARED,
dev_name(gn412x->gpiochip.parent),
gn412x);
if (err) {
dev_err(gn412x->gpiochip.parent, "Can't request IRQ %d (%d)\n",
#endif
platform_get_irq(pdev, 0), err); platform_get_irq(pdev, 0), err);
goto err_req; goto err_req;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment