Skip to contentSkip to conversation

gpio: zx: Add ZTE zx296702 GPIO support

PATCH In review Jun Nie 3 participants 3 messages Jun 24, 2015 GPIO

lore
Share & tools
lore

Jun Nie

author
#0 lore raw

PATCH v2 1/1 gpio: zx: Add ZTE zx296702 GPIO support

Add ZTE zx296702 GPIO controller support

---
 drivers/gpio/Kconfig         |   6 +
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-zx296702.c | 324 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)
 create mode 100644 drivers/gpio/gpio-zx296702.c
drivers/gpio/Kconfig +6 -0
index caefe80..aba5226 100644
@@ -970,6 +970,12 @@ config GPIO_MC33880
 	  SPI driver for Freescale MC33880 high-side/low-side switch.
 	  This provides GPIO interface supporting inputs and outputs.
 
+config GPIO_ZX296702
+	bool "ZTE ZX296702 GPIO support"
+	select GPIOLIB_IRQCHIP
+	help
+	  Say yes here to support the ZTE ZX296702 GPIO device
+
 endmenu
 
 menu "USB GPIO expanders"
drivers/gpio/Makefile +1 -0
index f71bb97..c26d81e 100644
@@ -112,3 +112,4 @@ obj-$(CONFIG_GPIO_XILINX)	+= gpio-xilinx.o
 obj-$(CONFIG_GPIO_XTENSA)	+= gpio-xtensa.o
 obj-$(CONFIG_GPIO_ZEVIO)	+= gpio-zevio.o
 obj-$(CONFIG_GPIO_ZYNQ)		+= gpio-zynq.o
+obj-$(CONFIG_GPIO_ZX296702)	+= gpio-zx296702.o
drivers/gpio/gpio-zx296702.c new file +324 -0

324 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

Hi Jun Nie,

Quoted 4 lines · Jun Nie

Add ZTE zx296702 GPIO controller support

---

(...)

drivers/gpio/gpio-zx296702.c line 247

Quoted 10 lines
drivers/gpio/gpio-zx296702.c new file +10 -0
+static int zx_gpio_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct zx_gpio *chip;
+	struct resource *res;
+	int irq, id, ret;
+
+	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+	if (chip == NULL)
+		return -ENOMEM;

We can simply check some thing like this:

	if (!chip)
		return -ENOMEM;
Quoted 25 lines
drivers/gpio/gpio-zx296702.c new file +25 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	chip->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(chip->base))
+		return PTR_ERR(chip->base);
+
+	spin_lock_init(&chip->lock);
+	if (of_property_read_bool(dev->of_node, "gpio-ranges"))
+		chip->uses_pinctrl = true;
+
+	id = of_alias_get_id(dev->of_node, "gpio");
+	chip->gc.request = zx_gpio_request;
+	chip->gc.free = zx_gpio_free;
+	chip->gc.direction_input = zx_direction_input;
+	chip->gc.direction_output = zx_direction_output;
+	chip->gc.get = zx_get_value;
+	chip->gc.set = zx_set_value;
+	chip->gc.base = ZX_GPIO_NR * id;
+	chip->gc.ngpio = ZX_GPIO_NR;
+	chip->gc.label = dev_name(dev);
+	chip->gc.dev = dev;
+	chip->gc.owner = THIS_MODULE;
+
+	ret = gpiochip_add(&chip->gc);
+	if (ret)

drivers/gpio/gpio-zx296702.c line 282

Quoted 10 lines
drivers/gpio/gpio-zx296702.c new file +10 -0
+		return ret;
+
+	/*
+	 * irq_chip support
+	 */
+	writew_relaxed(0xffff, chip->base + ZX_GPIO_IM);
+	writew_relaxed(0, chip->base + ZX_GPIO_IE);
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(dev, "invalid IRQ\n");

You added the gpiochio, but not removing on error here.

drivers/gpio/gpio-zx296702.c line 290

Quoted 8 lines
drivers/gpio/gpio-zx296702.c new file +8 -0
+		return -ENODEV;
+	}
+
+	ret = gpiochip_irqchip_add(&chip->gc, &zx_irqchip,
+				   0, handle_simple_irq,
+				   IRQ_TYPE_NONE);
+	if (ret) {
+		dev_info(dev, "could not add irqchip\n");

I think it should be dev_err().

Here also gpiochip_remove() ?

Quoted 11 lines
drivers/gpio/gpio-zx296702.c new file +11 -0
+		return ret;
+	}
+	gpiochip_set_chained_irqchip(&chip->gc, &zx_irqchip,
+				     irq, zx_irq_handler);
+
+	platform_set_drvdata(pdev, chip);
+	dev_info(dev, "ZX GPIO chip registered\n");
+
+	return 0;
+}
+

drivers/gpio/gpio-zx296702.c line 311

Quoted 10 lines
drivers/gpio/gpio-zx296702.c new file +10 -0
+#if defined(CONFIG_OF)
+static const struct of_device_id zx_gpio_match[] = {
+	{
+		.compatible = "zte,zx296702-gpio",
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, zx_gpio_match);
+#endif
+

This driver may be populated through OF.

Do you think this #if..#endif is required ?

Signature · 2 lines
Best regards,
Varka Bhadram.
#2 lore raw
In reply to Jun Nie

Jun,

A couple of comments below.

Quoted 16 lines · Jun Nie

Add ZTE zx296702 GPIO controller support

---
 drivers/gpio/Kconfig         |   6 +
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-zx296702.c | 324 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)
 create mode 100644 drivers/gpio/gpio-zx296702.c
drivers/gpio/Kconfig +0 -0
index caefe80..aba5226 100644

drivers/gpio/Kconfig config GPIO_MC33880 · line 978

Quoted 9 lines
drivers/gpio/Kconfig +6 -0
@@ -970,6 +970,12 @@ config GPIO_MC33880
          SPI driver for Freescale MC33880 high-side/low-side switch.
          This provides GPIO interface supporting inputs and outputs.
 
+config GPIO_ZX296702
+       bool "ZTE ZX296702 GPIO support"
+       select GPIOLIB_IRQCHIP
+       help
+         Say yes here to support the ZTE ZX296702 GPIO device
+

This GPIO block is available on ZTE ZX family SoCs, not only ZX296702. I suggest you name the option GPIO_ZX and the driver gpio-zx.

[...]

drivers/gpio/Kconfig config GPIO_MC33880

Quoted 6 lines
drivers/gpio/Kconfig +6 -0
+static int zx_direction_output(struct gpio_chip *gc, unsigned offset,
+               int value)
+{
+       struct zx_gpio *chip = to_zx(gc);
+       unsigned long flags;
+       unsigned char gpiodir;

It's a 8-bit variable. Is it what you want? I guess you need to use unsigned short to get a 16-bit variable.

Shawn

Quoted 17 lines
drivers/gpio/Kconfig +17 -0
+
+       if (offset >= gc->ngpio)
+               return -EINVAL;
+
+       spin_lock_irqsave(&chip->lock, flags);
+       gpiodir = readw_relaxed(chip->base + ZX_GPIO_DIR);
+       gpiodir |= BIT(offset);
+       writew_relaxed(gpiodir, chip->base + ZX_GPIO_DIR);
+
+       if (value)
+               writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO1);
+       else
+               writew_relaxed(BIT(offset), chip->base + ZX_GPIO_DO0);
+       spin_unlock_irqrestore(&chip->lock, flags);
+
+       return 0;
+}