devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Marko <robert.marko@sartura.hr>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Lee Jones <lee.jones@linaro.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Luka Perkov <luka.perkov@sartura.hr>,
	jmp@epiphyte.org, Paul Menzel <pmenzel@molgen.mpg.de>,
	Donald Buczek <buczek@molgen.mpg.de>
Subject: Re: [PATCH v5 2/6] gpio: Add Delta TN48M CPLD GPIO driver
Date: Mon, 7 Jun 2021 14:23:00 +0200	[thread overview]
Message-ID: <CA+HBbNH9suWNFgFE8V4SLesF6aHkEOrxVGSRsL9XVU2eorwruQ@mail.gmail.com> (raw)
In-Reply-To: <CAHp75Vfkn-fSJrLFfswzLdZPJwe+x24rntCPO2VKK0RHfN0y=Q@mail.gmail.com>

On Mon, Jun 7, 2021 at 2:06 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Mon, Jun 7, 2021 at 1:51 PM Robert Marko <robert.marko@sartura.hr> wrote:
> >
> > Delta TN48M CPLD is used as a GPIO expander for the SFP GPIOs.
> >
> > It is a mix of input only and output only pins.
> >
> > Signed-off-by: Robert Marko <robert.marko@sartura.hr>
> > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> > Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>
> Couple of small issues below.
> Otherwise looks good!
>
> > ---
> > Changes in v2:
> > * Rewrite to use simple I2C MFD and GPIO regmap
> > * Drop DT bindings for pin numbering
> >
> >  drivers/gpio/Kconfig      | 12 ++++++
> >  drivers/gpio/Makefile     |  1 +
> >  drivers/gpio/gpio-tn48m.c | 89 +++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 102 insertions(+)
> >  create mode 100644 drivers/gpio/gpio-tn48m.c
> >
> > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> > index e3607ec4c2e8..472f7764508e 100644
> > --- a/drivers/gpio/Kconfig
> > +++ b/drivers/gpio/Kconfig
> > @@ -1310,6 +1310,18 @@ config GPIO_TIMBERDALE
> >         help
> >         Add support for the GPIO IP in the timberdale FPGA.
> >
> > +config GPIO_TN48M_CPLD
> > +       tristate "Delta Networks TN48M switch CPLD GPIO driver"
> > +       depends on MFD_TN48M_CPLD
> > +       select GPIO_REGMAP
> > +       help
> > +         This enables support for the GPIOs found on the Delta
> > +         Networks TN48M switch CPLD.
> > +         They are used for inputs and outputs on the SFP slots.
> > +
> > +         This driver can also be built as a module. If so, the
> > +         module will be called gpio-tn48m.
> > +
> >  config GPIO_TPS65086
> >         tristate "TI TPS65086 GPO"
> >         depends on MFD_TPS65086
> > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> > index c58a90a3c3b1..271fb806475e 100644
> > --- a/drivers/gpio/Makefile
> > +++ b/drivers/gpio/Makefile
> > @@ -145,6 +145,7 @@ obj-$(CONFIG_GPIO_TEGRA186)         += gpio-tegra186.o
> >  obj-$(CONFIG_GPIO_TEGRA)               += gpio-tegra.o
> >  obj-$(CONFIG_GPIO_THUNDERX)            += gpio-thunderx.o
> >  obj-$(CONFIG_GPIO_TIMBERDALE)          += gpio-timberdale.o
> > +obj-$(CONFIG_GPIO_TN48M_CPLD)          += gpio-tn48m.o
> >  obj-$(CONFIG_GPIO_TPIC2810)            += gpio-tpic2810.o
> >  obj-$(CONFIG_GPIO_TPS65086)            += gpio-tps65086.o
> >  obj-$(CONFIG_GPIO_TPS65218)            += gpio-tps65218.o
> > diff --git a/drivers/gpio/gpio-tn48m.c b/drivers/gpio/gpio-tn48m.c
> > new file mode 100644
> > index 000000000000..41484c002826
> > --- /dev/null
> > +++ b/drivers/gpio/gpio-tn48m.c
> > @@ -0,0 +1,89 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Delta TN48M CPLD GPIO driver
> > + *
> > + * Copyright 2021 Sartura Ltd
> > + *
> > + * Author: Robert Marko <robert.marko@sartura.hr>
> > + */
> > +
> > +#include <linux/device.h>
> > +#include <linux/gpio/driver.h>
> > +#include <linux/gpio/regmap.h>
>
> > +#include <linux/kernel.h>
>
> What is this header for?

Its not being actually used,
I will drop it.
>
> > +#include <linux/mod_devicetable.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +
> > +enum tn48m_gpio_type {
> > +       TN48M_SFP_TX_DISABLE = 1,
> > +       TN48M_SFP_PRESENT,
> > +       TN48M_SFP_LOS,
> > +};
> > +
> > +static int tn48m_gpio_probe(struct platform_device *pdev)
> > +{
> > +       struct gpio_regmap_config config = {0};
> > +       enum tn48m_gpio_type type;
> > +       struct regmap *regmap;
> > +       u32 base;
> > +       int ret;
> > +
> > +       if (!pdev->dev.parent)
> > +               return -ENODEV;
> > +
> > +       type = (uintptr_t)device_get_match_data(&pdev->dev);
> > +       if (!type)
> > +               return -ENODEV;
> > +
> > +       ret = device_property_read_u32(&pdev->dev, "reg", &base);
> > +       if (ret)
>
> > +               return -EINVAL;
>
> return ret;

Will fix this and send v6 in a couple of minutes.

Thanks,
Robert
>
> > +       regmap = dev_get_regmap(pdev->dev.parent, NULL);
> > +       if (!regmap)
> > +               return -ENODEV;
> > +
> > +       config.regmap = regmap;
> > +       config.parent = &pdev->dev;
> > +       config.ngpio = 4;
> > +
> > +       switch (type) {
> > +       case TN48M_SFP_TX_DISABLE:
> > +               config.reg_set_base = base;
> > +               break;
> > +       case TN48M_SFP_PRESENT:
> > +               config.reg_dat_base = base;
> > +               break;
> > +       case TN48M_SFP_LOS:
> > +               config.reg_dat_base = base;
> > +               break;
> > +       default:
> > +               dev_err(&pdev->dev, "unknown type %d\n", type);
> > +               return -ENODEV;
> > +       }
> > +
> > +       return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&pdev->dev, &config));
> > +}
> > +
> > +static const struct of_device_id tn48m_gpio_of_match[] = {
> > +       { .compatible = "delta,tn48m-gpio-sfp-tx-disable", .data = (void *)TN48M_SFP_TX_DISABLE },
> > +       { .compatible = "delta,tn48m-gpio-sfp-present", .data = (void *)TN48M_SFP_PRESENT },
> > +       { .compatible = "delta,tn48m-gpio-sfp-los", .data = (void *)TN48M_SFP_LOS },
> > +       { }
> > +};
> > +MODULE_DEVICE_TABLE(of, tn48m_gpio_of_match);
> > +
> > +static struct platform_driver tn48m_gpio_driver = {
> > +       .driver = {
> > +               .name = "delta-tn48m-gpio",
> > +               .of_match_table = tn48m_gpio_of_match,
> > +       },
> > +       .probe = tn48m_gpio_probe,
> > +};
> > +module_platform_driver(tn48m_gpio_driver);
> > +
> > +MODULE_AUTHOR("Robert Marko <robert.marko@sartura.hr>");
> > +MODULE_DESCRIPTION("Delta TN48M CPLD GPIO driver");
> > +MODULE_LICENSE("GPL");
> > --
> > 2.31.1
> >
>
>
> --
> With Best Regards,
> Andy Shevchenko



-- 
Robert Marko
Staff Embedded Linux Engineer
Sartura Ltd.
Lendavska ulica 16a
10000 Zagreb, Croatia
Email: robert.marko@sartura.hr
Web: www.sartura.hr

  reply	other threads:[~2021-06-07 12:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 10:51 [PATCH v5 1/6] mfd: simple-mfd-i2c: Add Delta TN48M CPLD support Robert Marko
2021-06-07 10:51 ` [PATCH v5 2/6] gpio: Add Delta TN48M CPLD GPIO driver Robert Marko
2021-06-07 12:06   ` Andy Shevchenko
2021-06-07 12:23     ` Robert Marko [this message]
2021-06-07 10:51 ` [PATCH v5 3/6] dt-bindings: reset: Add Delta TN48M Robert Marko
2021-06-07 10:51 ` [PATCH v5 4/6] reset: Add Delta TN48M CPLD reset controller Robert Marko
2021-06-07 10:51 ` [PATCH v5 5/6] dt-bindings: mfd: Add Delta TN48M CPLD drivers bindings Robert Marko
2021-06-07 10:51 ` [PATCH v5 6/6] MAINTAINERS: Add Delta Networks TN48M CPLD drivers Robert Marko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+HBbNH9suWNFgFE8V4SLesF6aHkEOrxVGSRsL9XVU2eorwruQ@mail.gmail.com \
    --to=robert.marko@sartura.hr \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=buczek@molgen.mpg.de \
    --cc=devicetree@vger.kernel.org \
    --cc=jmp@epiphyte.org \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luka.perkov@sartura.hr \
    --cc=p.zabel@pengutronix.de \
    --cc=pmenzel@molgen.mpg.de \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).