* [Patch v1 4/7] DA9055 GPIO driver
@ 2012-09-14 13:30 Ashish Jangam
2012-09-14 13:06 ` Laxman Dewangan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ashish Jangam @ 2012-09-14 13:30 UTC (permalink / raw)
To: Grant Likely, Linus Walleij; +Cc: Samuel Ortiz, linux-input, David Dajun Chen
This is the GPIO patch for the DA9055 PMIC. This patch has got
dependency on the DA9055 MFD core.
This patch is functionally tested on SMDK6410 board.
Signed-off-by: David Dajun Chen <dchen@diasemi.com>
Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com>
---
drivers/gpio/Kconfig | 11 +++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-da9055.c | 204 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 216 insertions(+), 0 deletions(-)
create mode 100644 drivers/gpio/gpio-da9055.c
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b16c8a7..0b0d884 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -86,6 +86,17 @@ config GPIO_DA9052
help
Say yes here to enable the GPIO driver for the DA9052 chip.
+config GPIO_DA9055
+ tristate "Dialog Semiconductor DA9055 GPIO"
+ depends on MFD_DA9055
+ help
+ Say yes here to enable the GPIO driver for the DA9055 chip.
+
+ The Dialog DA9055 PMIC chip has 3 GPIO pins that can be
+ be controller by this driver.
+
+ If driver is built as a module it will be called gpio-da9055.
+
config GPIO_MAX730X
tristate
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 153cace..23d9d13 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o
obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o
+obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o
obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o
obj-$(CONFIG_GPIO_EM) += gpio-em.o
obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
diff --git a/drivers/gpio/gpio-da9055.c b/drivers/gpio/gpio-da9055.c
new file mode 100644
index 0000000..55d83c7
--- /dev/null
+++ b/drivers/gpio/gpio-da9055.c
@@ -0,0 +1,204 @@
+/*
+ * GPIO Driver for Dialog DA9055 PMICs.
+ *
+ * Copyright(c) 2012 Dialog Semiconductor Ltd.
+ *
+ * Author: David Dajun Chen <dchen@diasemi.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ */
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include <linux/mfd/da9055/core.h>
+#include <linux/mfd/da9055/reg.h>
+#include <linux/mfd/da9055/pdata.h>
+
+#define DA9055_VDD_IO 0x0
+#define DA9055_PUSH_PULL 0x3
+#define DA9055_ACT_LOW 0x0
+#define DA9055_GPI 0x1
+#define DA9055_PORT_MASK 0x3
+#define DA9055_PORT_SHIFT(offset) (4 * (offset % 2))
+
+#define DA9055_INPUT DA9055_GPI
+#define DA9055_OUTPUT DA9055_PUSH_PULL
+#define DA9055_IRQ_GPI0 3
+
+struct da9055_gpio {
+ struct da9055 *da9055;
+ struct gpio_chip gp;
+};
+
+static inline struct da9055_gpio *to_da9055_gpio(struct gpio_chip *chip)
+{
+ return container_of(chip, struct da9055_gpio, gp);
+}
+
+static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset)
+{
+ struct da9055_gpio *gpio = to_da9055_gpio(gc);
+ int gpio_direction = 0;
+ int ret;
+
+ /* Get GPIO direction */
+ ret = da9055_reg_read(gpio->da9055, (offset >> 1) + DA9055_REG_GPIO0_1);
+ if (ret < 0)
+ return ret;
+
+ gpio_direction = ret & (DA9055_PORT_MASK) << DA9055_PORT_SHIFT(offset);
+ gpio_direction >>= DA9055_PORT_SHIFT(offset);
+ switch (gpio_direction) {
+ case DA9055_INPUT:
+ ret = da9055_reg_read(gpio->da9055, DA9055_REG_STATUS_B);
+ if (ret < 0)
+ return ret;
+ break;
+ case DA9055_OUTPUT:
+ ret = da9055_reg_read(gpio->da9055, DA9055_REG_GPIO_MODE0_2);
+ if (ret < 0)
+ return ret;
+ }
+
+ return ret & (1 << offset);
+
+}
+
+static void da9055_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
+{
+ struct da9055_gpio *gpio = to_da9055_gpio(gc);
+
+ da9055_reg_update(gpio->da9055,
+ DA9055_REG_GPIO_MODE0_2,
+ 1 << offset,
+ value << offset);
+}
+
+static int da9055_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
+{
+ struct da9055_gpio *gpio = to_da9055_gpio(gc);
+ unsigned char reg_byte;
+
+ reg_byte = (DA9055_ACT_LOW | DA9055_GPI)
+ << DA9055_PORT_SHIFT(offset);
+
+ return da9055_reg_update(gpio->da9055, (offset >> 1) +
+ DA9055_REG_GPIO0_1,
+ DA9055_PORT_MASK <<
+ DA9055_PORT_SHIFT(offset),
+ reg_byte);
+}
+
+static int da9055_gpio_direction_output(struct gpio_chip *gc,
+ unsigned offset, int value)
+{
+ struct da9055_gpio *gpio = to_da9055_gpio(gc);
+ unsigned char reg_byte;
+ int ret;
+
+ reg_byte = (DA9055_VDD_IO | DA9055_PUSH_PULL)
+ << DA9055_PORT_SHIFT(offset);
+
+ ret = da9055_reg_update(gpio->da9055, (offset >> 1) +
+ DA9055_REG_GPIO0_1,
+ DA9055_PORT_MASK <<
+ DA9055_PORT_SHIFT(offset),
+ reg_byte);
+ if (ret < 0)
+ return ret;
+
+ da9055_gpio_set(gc, offset, value);
+
+ return 0;
+}
+
+static int da9055_gpio_to_irq(struct gpio_chip *gc, u32 offset)
+{
+ struct da9055_gpio *gpio = to_da9055_gpio(gc);
+ struct da9055 *da9055 = gpio->da9055;
+
+ return regmap_irq_get_virq(da9055->irq_data,
+ DA9055_IRQ_GPI0 + offset);
+}
+
+static struct gpio_chip reference_gp __devinitdata = {
+ .label = "da9055-gpio",
+ .owner = THIS_MODULE,
+ .get = da9055_gpio_get,
+ .set = da9055_gpio_set,
+ .direction_input = da9055_gpio_direction_input,
+ .direction_output = da9055_gpio_direction_output,
+ .to_irq = da9055_gpio_to_irq,
+ .can_sleep = 1,
+ .ngpio = 3,
+ .base = -1,
+};
+
+static int __devinit da9055_gpio_probe(struct platform_device *pdev)
+{
+ struct da9055_gpio *gpio;
+ struct da9055_pdata *pdata;
+ int ret;
+
+ gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
+ if (gpio == NULL)
+ return -ENOMEM;
+
+ gpio->da9055 = dev_get_drvdata(pdev->dev.parent);
+ pdata = gpio->da9055->dev->platform_data;
+
+ gpio->gp = reference_gp;
+ if (pdata && pdata->gpio_base)
+ gpio->gp.base = pdata->gpio_base;
+
+ ret = gpiochip_add(&gpio->gp);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
+ goto err_mem;
+ }
+
+ platform_set_drvdata(pdev, gpio);
+
+ return 0;
+
+err_mem:
+ return ret;
+}
+
+static int __devexit da9055_gpio_remove(struct platform_device *pdev)
+{
+ struct da9055_gpio *gpio = platform_get_drvdata(pdev);
+
+ return gpiochip_remove(&gpio->gp);
+}
+
+static struct platform_driver da9055_gpio_driver = {
+ .probe = da9055_gpio_probe,
+ .remove = __devexit_p(da9055_gpio_remove),
+ .driver = {
+ .name = "da9055-gpio",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init da9055_gpio_init(void)
+{
+ return platform_driver_register(&da9055_gpio_driver);
+}
+subsys_initcall(da9055_gpio_init);
+
+static void __exit da9055_gpio_exit(void)
+{
+ platform_driver_unregister(&da9055_gpio_driver);
+}
+module_exit(da9055_gpio_exit);
+
+MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
+MODULE_DESCRIPTION("DA9055 GPIO Device Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:da9055-gpio");
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Patch v1 4/7] DA9055 GPIO driver
2012-09-14 13:30 [Patch v1 4/7] DA9055 GPIO driver Ashish Jangam
@ 2012-09-14 13:06 ` Laxman Dewangan
2012-09-14 14:13 ` Linus Walleij
2012-10-12 21:17 ` Linus Walleij
2 siblings, 0 replies; 6+ messages in thread
From: Laxman Dewangan @ 2012-09-14 13:06 UTC (permalink / raw)
To: Ashish Jangam
Cc: Grant Likely, Linus Walleij, Samuel Ortiz,
linux-input@vger.kernel.org, David Dajun Chen
On Friday 14 September 2012 07:00 PM, Ashish Jangam wrote:
> This is the GPIO patch for the DA9055 PMIC. This patch has got
> dependency on the DA9055 MFD core.
>
> This patch is functionally tested on SMDK6410 board.
>
> Signed-off-by: David Dajun Chen<dchen@diasemi.com>
> Signed-off-by: Ashish Jangam<ashish.jangam@kpitcummins.com>
> ---
>
> +struct da9055_gpio {
> + struct da9055 *da9055;
> + struct gpio_chip gp;
I suggest to make gp as first member so that offset of member will be 0
in container_of macro and avoid one ops.
> +static struct gpio_chip reference_gp __devinitdata = {
This is device int data and you used after device initailisation. I
think this can create issue.
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Patch v1 4/7] DA9055 GPIO driver
2012-09-14 13:30 [Patch v1 4/7] DA9055 GPIO driver Ashish Jangam
2012-09-14 13:06 ` Laxman Dewangan
@ 2012-09-14 14:13 ` Linus Walleij
2012-09-14 16:38 ` Mark Brown
2012-10-12 9:55 ` Ashish Jangam
2012-10-12 21:17 ` Linus Walleij
2 siblings, 2 replies; 6+ messages in thread
From: Linus Walleij @ 2012-09-14 14:13 UTC (permalink / raw)
To: Ashish Jangam, Mark Brown
Cc: Grant Likely, Samuel Ortiz, linux-input, David Dajun Chen
On Fri, Sep 14, 2012 at 3:30 PM, Ashish Jangam
<ashish.jangam@kpitcummins.com> wrote:
> This is the GPIO patch for the DA9055 PMIC. This patch has got
> dependency on the DA9055 MFD core.
>
> This patch is functionally tested on SMDK6410 board.
>
> Signed-off-by: David Dajun Chen <dchen@diasemi.com>
> Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com>
This looks OK
Acked-by: Linus Walleij <linus.walleij@linaro.org>
But I want Marks comment on this, for example:
> +static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset)
> +{
> + struct da9055_gpio *gpio = to_da9055_gpio(gc);
> + int gpio_direction = 0;
> + int ret;
> +
> + /* Get GPIO direction */
> + ret = da9055_reg_read(gpio->da9055, (offset >> 1) + DA9055_REG_GPIO0_1);
> + if (ret < 0)
> + return ret;
So unique functions to read/write registers (as I'm used to).
But the parent driver is using regmap, sand you seem not to use the
struct da9055
for anything else than passing reads/writes, so isn't it simpler to just pass
the struct regmap * and use update_bits etc directly and remove a layer of
indirection?
I'm very uncertain but Mark will know the proper design pattern.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Patch v1 4/7] DA9055 GPIO driver
2012-09-14 14:13 ` Linus Walleij
@ 2012-09-14 16:38 ` Mark Brown
2012-10-12 9:55 ` Ashish Jangam
1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2012-09-14 16:38 UTC (permalink / raw)
To: Linus Walleij
Cc: Ashish Jangam, Grant Likely, Samuel Ortiz, linux-input,
David Dajun Chen
On Fri, Sep 14, 2012 at 04:13:57PM +0200, Linus Walleij wrote:
> But the parent driver is using regmap, sand you seem not to use the
> struct da9055
> for anything else than passing reads/writes, so isn't it simpler to just pass
> the struct regmap * and use update_bits etc directly and remove a layer of
> indirection?
> I'm very uncertain but Mark will know the proper design pattern.
Either way is fine - usually the device specific functions end up being
static inlines in the header so the code is the same. It really depends
if it's useful to have the full device pointer around for other things.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Patch v1 4/7] DA9055 GPIO driver
2012-09-14 14:13 ` Linus Walleij
2012-09-14 16:38 ` Mark Brown
@ 2012-10-12 9:55 ` Ashish Jangam
1 sibling, 0 replies; 6+ messages in thread
From: Ashish Jangam @ 2012-10-12 9:55 UTC (permalink / raw)
To: Linus Walleij, Mark Brown
Cc: Grant Likely, Samuel Ortiz, linux-input@vger.kernel.org,
David Dajun Chen
> -----Original Message-----
> From: Linus Walleij [mailto:linus.walleij@linaro.org]
> Sent: Friday, September 14, 2012 7:44 PM
> To: Ashish Jangam; Mark Brown
> Cc: Grant Likely; Samuel Ortiz; linux-input@vger.kernel.org; David Dajun
> Chen
> Subject: Re: [Patch v1 4/7] DA9055 GPIO driver
>
> On Fri, Sep 14, 2012 at 3:30 PM, Ashish Jangam
> <ashish.jangam@kpitcummins.com> wrote:
>
> > This is the GPIO patch for the DA9055 PMIC. This patch has got
> > dependency on the DA9055 MFD core.
> >
> > This patch is functionally tested on SMDK6410 board.
> >
> > Signed-off-by: David Dajun Chen <dchen@diasemi.com>
> > Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com>
>
> This looks OK
> Acked-by: Linus Walleij <linus.walleij@linaro.org>
>
> But I want Marks comment on this, for example:
>
> > +static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset)
> > +{
> > + struct da9055_gpio *gpio = to_da9055_gpio(gc);
> > + int gpio_direction = 0;
> > + int ret;
> > +
> > + /* Get GPIO direction */
> > + ret = da9055_reg_read(gpio->da9055, (offset >> 1) +
> DA9055_REG_GPIO0_1);
> > + if (ret < 0)
> > + return ret;
>
> So unique functions to read/write registers (as I'm used to).
>
> But the parent driver is using regmap, sand you seem not to use the
> struct da9055
> for anything else than passing reads/writes, so isn't it simpler to just
> pass
> the struct regmap * and use update_bits etc directly and remove a layer of
> indirection?
>
> I'm very uncertain but Mark will know the proper design pattern.
>
As Mark was fine with this then will it be possible to upstream this patch?
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Patch v1 4/7] DA9055 GPIO driver
2012-09-14 13:30 [Patch v1 4/7] DA9055 GPIO driver Ashish Jangam
2012-09-14 13:06 ` Laxman Dewangan
2012-09-14 14:13 ` Linus Walleij
@ 2012-10-12 21:17 ` Linus Walleij
2 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2012-10-12 21:17 UTC (permalink / raw)
To: Ashish Jangam; +Cc: Grant Likely, Samuel Ortiz, linux-input, David Dajun Chen
On Fri, Sep 14, 2012 at 3:30 PM, Ashish Jangam
<ashish.jangam@kpitcummins.com> wrote:
> This is the GPIO patch for the DA9055 PMIC. This patch has got
> dependency on the DA9055 MFD core.
>
> This patch is functionally tested on SMDK6410 board.
>
> Signed-off-by: David Dajun Chen <dchen@diasemi.com>
> Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com>
Patch applied!
Thanks,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-10-12 21:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14 13:30 [Patch v1 4/7] DA9055 GPIO driver Ashish Jangam
2012-09-14 13:06 ` Laxman Dewangan
2012-09-14 14:13 ` Linus Walleij
2012-09-14 16:38 ` Mark Brown
2012-10-12 9:55 ` Ashish Jangam
2012-10-12 21:17 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).