All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
@ 2016-02-29 14:00 Axel Lin
  2016-03-15  8:47 ` Linus Walleij
  2016-03-22 13:34 ` Linus Walleij
  0 siblings, 2 replies; 7+ messages in thread
From: Axel Lin @ 2016-02-29 14:00 UTC (permalink / raw)
  To: Linus Walleij; +Cc: YD Tseng, Alexandre Courbot, linux-gpio

Use gpio-generic to simplify this driver.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi YD,
I don't have this h/w for test.
I'd appreciate if you can help to review and test this patch.
Thanks.
 drivers/gpio/Kconfig      |   1 +
 drivers/gpio/gpio-amdpt.c | 122 ++++++----------------------------------------
 2 files changed, 15 insertions(+), 108 deletions(-)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 1118fef..32188f6 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -122,6 +122,7 @@ config GPIO_ALTERA
 config GPIO_AMDPT
 	tristate "AMD Promontory GPIO support"
 	depends on ACPI
+	select GPIO_GENERIC
 	help
 	  driver for GPIO functionality on Promontory IOHub
 	  Require ACPI ASL code to enumerate as a platform device.
diff --git a/drivers/gpio/gpio-amdpt.c b/drivers/gpio/gpio-amdpt.c
index c248404..569b424 100644
--- a/drivers/gpio/gpio-amdpt.c
+++ b/drivers/gpio/gpio-amdpt.c
@@ -28,7 +28,6 @@
 struct pt_gpio_chip {
 	struct gpio_chip         gc;
 	void __iomem             *reg_base;
-	spinlock_t               lock;
 };
 
 static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
@@ -39,19 +38,19 @@ static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
 
 	dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);
 
-	spin_lock_irqsave(&pt_gpio->lock, flags);
+	spin_lock_irqsave(&gc->bgpio_lock, flags);
 
 	using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
 	if (using_pins & BIT(offset)) {
 		dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
 			 offset);
-		spin_unlock_irqrestore(&pt_gpio->lock, flags);
+		spin_unlock_irqrestore(&gc->bgpio_lock, flags);
 		return -EINVAL;
 	}
 
 	writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG);
 
-	spin_unlock_irqrestore(&pt_gpio->lock, flags);
+	spin_unlock_irqrestore(&gc->bgpio_lock, flags);
 
 	return 0;
 }
@@ -62,111 +61,17 @@ static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
 	unsigned long flags;
 	u32 using_pins;
 
-	spin_lock_irqsave(&pt_gpio->lock, flags);
+	spin_lock_irqsave(&gc->bgpio_lock, flags);
 
 	using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
 	using_pins &= ~BIT(offset);
 	writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG);
 
-	spin_unlock_irqrestore(&pt_gpio->lock, flags);
+	spin_unlock_irqrestore(&gc->bgpio_lock, flags);
 
 	dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
 }
 
-static void pt_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
-{
-	struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
-	unsigned long flags;
-	u32 data;
-
-	dev_dbg(gc->parent, "pt_gpio_set_value offset=%x, value=%x\n",
-		offset, value);
-
-	spin_lock_irqsave(&pt_gpio->lock, flags);
-
-	data = readl(pt_gpio->reg_base + PT_OUTPUTDATA_REG);
-	data &= ~BIT(offset);
-	if (value)
-		data |= BIT(offset);
-	writel(data, pt_gpio->reg_base + PT_OUTPUTDATA_REG);
-
-	spin_unlock_irqrestore(&pt_gpio->lock, flags);
-}
-
-static int pt_gpio_get_value(struct gpio_chip *gc, unsigned offset)
-{
-	struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
-	unsigned long flags;
-	u32 data;
-
-	spin_lock_irqsave(&pt_gpio->lock, flags);
-
-	data = readl(pt_gpio->reg_base + PT_DIRECTION_REG);
-
-	/* configure as output */
-	if (data & BIT(offset))
-		data = readl(pt_gpio->reg_base + PT_OUTPUTDATA_REG);
-	else	/* configure as input */
-		data = readl(pt_gpio->reg_base + PT_INPUTDATA_REG);
-
-	spin_unlock_irqrestore(&pt_gpio->lock, flags);
-
-	data >>= offset;
-	data &= 1;
-
-	dev_dbg(gc->parent, "pt_gpio_get_value offset=%x, value=%x\n",
-		offset, data);
-
-	return data;
-}
-
-static int pt_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
-{
-	struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
-	unsigned long flags;
-	u32 data;
-
-	dev_dbg(gc->parent, "pt_gpio_dirction_input offset=%x\n", offset);
-
-	spin_lock_irqsave(&pt_gpio->lock, flags);
-
-	data = readl(pt_gpio->reg_base + PT_DIRECTION_REG);
-	data &= ~BIT(offset);
-	writel(data, pt_gpio->reg_base + PT_DIRECTION_REG);
-
-	spin_unlock_irqrestore(&pt_gpio->lock, flags);
-
-	return 0;
-}
-
-static int pt_gpio_direction_output(struct gpio_chip *gc,
-					unsigned offset, int value)
-{
-	struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
-	unsigned long flags;
-	u32 data;
-
-	dev_dbg(gc->parent, "pt_gpio_direction_output offset=%x, value=%x\n",
-		offset, value);
-
-	spin_lock_irqsave(&pt_gpio->lock, flags);
-
-	data = readl(pt_gpio->reg_base + PT_OUTPUTDATA_REG);
-	if (value)
-		data |= BIT(offset);
-	else
-		data &= ~BIT(offset);
-	writel(data, pt_gpio->reg_base + PT_OUTPUTDATA_REG);
-
-	data = readl(pt_gpio->reg_base + PT_DIRECTION_REG);
-	data |= BIT(offset);
-	writel(data, pt_gpio->reg_base + PT_DIRECTION_REG);
-
-	spin_unlock_irqrestore(&pt_gpio->lock, flags);
-
-	return 0;
-}
-
 static int pt_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -196,18 +101,19 @@ static int pt_gpio_probe(struct platform_device *pdev)
 		return PTR_ERR(pt_gpio->reg_base);
 	}
 
-	spin_lock_init(&pt_gpio->lock);
+	ret = bgpio_init(&pt_gpio->gc, dev, 4,
+			 pt_gpio->reg_base + PT_INPUTDATA_REG,
+			 pt_gpio->reg_base + PT_OUTPUTDATA_REG, NULL,
+			 pt_gpio->reg_base + PT_DIRECTION_REG, NULL,
+			 BGPIOF_READ_OUTPUT_REG_SET);
+	if (ret) {
+		dev_err(&pdev->dev, "bgpio_init failed\n");
+		return ret;
+	}
 
-	pt_gpio->gc.label            = pdev->name;
 	pt_gpio->gc.owner            = THIS_MODULE;
-	pt_gpio->gc.parent              = dev;
 	pt_gpio->gc.request          = pt_gpio_request;
 	pt_gpio->gc.free             = pt_gpio_free;
-	pt_gpio->gc.direction_input  = pt_gpio_direction_input;
-	pt_gpio->gc.direction_output = pt_gpio_direction_output;
-	pt_gpio->gc.get              = pt_gpio_get_value;
-	pt_gpio->gc.set              = pt_gpio_set_value;
-	pt_gpio->gc.base             = -1;
 	pt_gpio->gc.ngpio            = PT_TOTAL_GPIO;
 #if defined(CONFIG_OF_GPIO)
 	pt_gpio->gc.of_node          = pdev->dev.of_node;
-- 
2.1.4




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
  2016-02-29 14:00 [PATCH RFT] gpio: amdpt: Convert to use gpio-generic Axel Lin
@ 2016-03-15  8:47 ` Linus Walleij
  2016-03-22 13:34 ` Linus Walleij
  1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-03-15  8:47 UTC (permalink / raw)
  To: Axel Lin, YD Tseng, Varka Bhadram, Pramod Gurav,
	Dmitry Eremin-Solenikov, Ken Xue
  Cc: Alexandre Courbot, linux-gpio

On Mon, Feb 29, 2016 at 3:00 PM, Axel Lin <axel.lin@ingics.com> wrote:

> Use gpio-generic to simplify this driver.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> Hi YD,
> I don't have this h/w for test.
> I'd appreciate if you can help to review and test this patch.

Adding some random people working with AMD hardware to the
To: line.

If noone provides a test tag I will anyway merge this patch, they can
find out any problems the hard way if they are not reading their
mails.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
  2016-02-29 14:00 [PATCH RFT] gpio: amdpt: Convert to use gpio-generic Axel Lin
  2016-03-15  8:47 ` Linus Walleij
@ 2016-03-22 13:34 ` Linus Walleij
  1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-03-22 13:34 UTC (permalink / raw)
  To: Axel Lin; +Cc: YD Tseng, Alexandre Courbot, linux-gpio

On Mon, Feb 29, 2016 at 3:00 PM, Axel Lin <axel.lin@ingics.com> wrote:

> Use gpio-generic to simplify this driver.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

Patch applie for v4.7 with YD's Tested-by tag.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
@ 2016-03-18  9:49 YD Tseng
  0 siblings, 0 replies; 7+ messages in thread
From: YD Tseng @ 2016-03-18  9:49 UTC (permalink / raw)
  To: linus.walleij, axel.lin, varkab, pramod.gurav, dbaryshkov, Ken.Xue
  Cc: gnurou, linux-gpio, Yd_Tseng, TungYu_Lu

From: YD Tseng <Yd_Tseng@asmedia.com.tw>

>Use gpio-generic to simplify this driver.
>
>Signed-off-by: Axel Lin <axel.lin@ingics.com>
>---
>Hi YD,
>I don't have this h/w for test.
>I'd appreciate if you can help to review and test this patch.
>
>Thanks.

We confirm the new patch, it runs well with the AMD Promontory chip.

Regards,
YD Tseng


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
  2016-03-16  7:34 YD Tseng
@ 2016-03-16  8:29 ` Axel Lin
  0 siblings, 0 replies; 7+ messages in thread
From: Axel Lin @ 2016-03-16  8:29 UTC (permalink / raw)
  To: YD Tseng
  Cc: Linus Walleij, varkab, pramod.gurav, dbaryshkov, Ken.Xue,
	Alexandre Courbot, linux-gpio, Yd_Tseng, TungYu_Lu

2016-03-16 15:34 GMT+08:00 YD Tseng <ltyu101@gmail.com>:
> From: YD Tseng <Yd_Tseng@asmedia.com.tw>
>
> Sorry for reply late, please add the following emails in this thread.
> yd_tseng@asmedia.com.tw
> tungyu_lu@asmedia.com.tw
>
> We will confirm the new patch. And we also need to add a new ACPI HID, AMDIF030, in the pt_gpio_acpi_match.
> Which code base should we submit for the new ID?
If you patch is just adding new ACPI HID to pt_gpio_acpi_match, I
think it's fine for
use current tree or on top of this patch. It can be applied without
conflict anyway.

Regards,
Axel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
@ 2016-03-16  8:12 YD Tseng
  0 siblings, 0 replies; 7+ messages in thread
From: YD Tseng @ 2016-03-16  8:12 UTC (permalink / raw)
  To: linus.walleij, axel.lin, varkab, pramod.gurav, dbaryshkov, Ken.Xue
  Cc: gnurou, linux-gpio, Yd_Tseng, TungYu_Lu

From: YD Tseng <Yd_Tseng@asmedia.com.tw>

Sorry for reply late, please add the following emails in this thread.
yd_tseng@asmedia.com.tw
tungyu_lu@asmedia.com.tw

We will confirm the new patch. And we also need to add a new ACPI HID, AMDIF030, in the pt_gpio_acpi_match.
Which code base should we submit for the new ID?   

Thanks,
YD Tseng

>On Mon, Feb 29, 2016 at 3:00 PM, Axel Lin <axel.lin@ingics.com> wrote:
>
>> Use gpio-generic to simplify this driver.
>>
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>> ---
>> Hi YD,
>> I don't have this h/w for test.
>> I'd appreciate if you can help to review and test this patch.
>
>Adding some random people working with AMD hardware to the
>To: line.
>
>If noone provides a test tag I will anyway merge this patch, they can find out any problems the hard way if they are not reading their mails.
>
>Yours,
>Linus Walleij


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RFT] gpio: amdpt: Convert to use gpio-generic
@ 2016-03-16  7:34 YD Tseng
  2016-03-16  8:29 ` Axel Lin
  0 siblings, 1 reply; 7+ messages in thread
From: YD Tseng @ 2016-03-16  7:34 UTC (permalink / raw)
  To: linus.walleij, axel.lin, varkab, pramod.gurav, dbaryshkov, Ken.Xue
  Cc: gnurou, linux-gpio, Yd_Tseng, TungYu_Lu

From: YD Tseng <Yd_Tseng@asmedia.com.tw>

Sorry for reply late, please add the following emails in this thread.
yd_tseng@asmedia.com.tw
tungyu_lu@asmedia.com.tw

We will confirm the new patch. And we also need to add a new ACPI HID, AMDIF030, in the pt_gpio_acpi_match.
Which code base should we submit for the new ID?   

Thanks,
YD Tseng

>On Mon, Feb 29, 2016 at 3:00 PM, Axel Lin <axel.lin@ingics.com> wrote:
>
>> Use gpio-generic to simplify this driver.
>>
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>> ---
>> Hi YD,
>> I don't have this h/w for test.
>> I'd appreciate if you can help to review and test this patch.
>
>Adding some random people working with AMD hardware to the
>To: line.
>
>If noone provides a test tag I will anyway merge this patch, they can find out any problems the hard way if they are not reading their mails.
>
>Yours,
>Linus Walleij


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-03-22 13:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-29 14:00 [PATCH RFT] gpio: amdpt: Convert to use gpio-generic Axel Lin
2016-03-15  8:47 ` Linus Walleij
2016-03-22 13:34 ` Linus Walleij
2016-03-16  7:34 YD Tseng
2016-03-16  8:29 ` Axel Lin
2016-03-16  8:12 YD Tseng
2016-03-18  9:49 YD Tseng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.