Message ID | 20230222111213.2241633-4-keguang.zhang@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Devicetree support for Loongson-1 GPIO | expand |
Wed, Feb 22, 2023 at 07:12:12PM +0800, Keguang Zhang kirjoitti: > This patch adds DT support for Loongson-1 GPIO driver, > including the following changes. > - Add the of_match_table > - Parse the ngpios property > - Parse the alias id Split! ... > + if (of_property_read_u32(dn, "ngpios", &ngpios)) { > + dev_err(dev, "Missing ngpios OF property\n"); > + return -ENODEV; > + } Why?! GPIO library has this already. ... > + id = of_alias_get_id(dn, "gpio"); > + if (id < 0) { > + dev_err(dev, "Couldn't get OF id\n"); > + return id; > + } What is this for? ... > + ls1x_gc->gc.base = pdev->id * BITS_PER_LONG; > - ls1x_gc->gc.base = pdev->id * 32; No way. This is change makes me thing that initially it's simply wrong. Please, just use -1 for the base. ... > +static const struct of_device_id ls1x_gpio_dt_ids[] = { > + { .compatible = "loongson,ls1x-gpio", }, Inner comma is not needed. > + { /* sentinel */ } > +}; You missed MODULE_DEVICE_TABLE().
On Wed, Feb 22, 2023 at 8:21 PM <andy.shevchenko@gmail.com> wrote: > > Wed, Feb 22, 2023 at 07:12:12PM +0800, Keguang Zhang kirjoitti: > > This patch adds DT support for Loongson-1 GPIO driver, > > including the following changes. > > - Add the of_match_table > > - Parse the ngpios property > > - Parse the alias id > > Split! > > ... > > > + if (of_property_read_u32(dn, "ngpios", &ngpios)) { > > + dev_err(dev, "Missing ngpios OF property\n"); > > + return -ENODEV; > > + } > > Why?! GPIO library has this already. > Will make use of gpiolib and remove this part. > ... > > > + id = of_alias_get_id(dn, "gpio"); > > + if (id < 0) { > > + dev_err(dev, "Couldn't get OF id\n"); > > + return id; > > + } > > What is this for? > Will remove this part. > ... > > > + ls1x_gc->gc.base = pdev->id * BITS_PER_LONG; > > - ls1x_gc->gc.base = pdev->id * 32; > > No way. This is change makes me thing that initially it's simply wrong. Please, > just use -1 for the base. > Sure. And this is already done by bgpio_init(). So I will simply remove this line. > ... > > > +static const struct of_device_id ls1x_gpio_dt_ids[] = { > > + { .compatible = "loongson,ls1x-gpio", }, > > Inner comma is not needed. > Will do. > > + { /* sentinel */ } > > +}; > > You missed MODULE_DEVICE_TABLE(). > Will add MODULE_DEVICE_TABLE(). > -- > With Best Regards, > Andy Shevchenko > >
diff --git a/drivers/gpio/gpio-loongson1.c b/drivers/gpio/gpio-loongson1.c index b950bcfd78ce..92ad31f61bf0 100644 --- a/drivers/gpio/gpio-loongson1.c +++ b/drivers/gpio/gpio-loongson1.c @@ -48,7 +48,10 @@ static void ls1x_gpio_free(struct gpio_chip *gc, unsigned int offset) static int ls1x_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct device_node *dn = pdev->dev.of_node; struct ls1x_gpio_chip *ls1x_gc; + unsigned int ngpios; + int id; int ret; ls1x_gc = devm_kzalloc(dev, sizeof(*ls1x_gc), GFP_KERNEL); @@ -59,34 +62,56 @@ static int ls1x_gpio_probe(struct platform_device *pdev) if (IS_ERR(ls1x_gc->reg_base)) return PTR_ERR(ls1x_gc->reg_base); + if (of_property_read_u32(dn, "ngpios", &ngpios)) { + dev_err(dev, "Missing ngpios OF property\n"); + return -ENODEV; + } + + id = of_alias_get_id(dn, "gpio"); + if (id < 0) { + dev_err(dev, "Couldn't get OF id\n"); + return id; + } + ret = bgpio_init(&ls1x_gc->gc, dev, 4, ls1x_gc->reg_base + GPIO_DATA, ls1x_gc->reg_base + GPIO_OUTPUT, NULL, NULL, ls1x_gc->reg_base + GPIO_DIR, 0); if (ret) goto err; + ls1x_gc->gc.label = dev_name(&pdev->dev); + ls1x_gc->gc.ngpio = ngpios; ls1x_gc->gc.owner = THIS_MODULE; + ls1x_gc->gc.parent = dev; + ls1x_gc->gc.base = pdev->id * BITS_PER_LONG; ls1x_gc->gc.request = ls1x_gpio_request; ls1x_gc->gc.free = ls1x_gpio_free; - ls1x_gc->gc.base = pdev->id * 32; ret = devm_gpiochip_add_data(dev, &ls1x_gc->gc, ls1x_gc); if (ret) goto err; platform_set_drvdata(pdev, ls1x_gc); - dev_info(dev, "Loongson1 GPIO driver registered\n"); + + dev_info(dev, "GPIO controller %d registered with %d pins\n", id, + ngpios); return 0; err: - dev_err(dev, "failed to register GPIO device\n"); + dev_err(dev, "failed to register GPIO controller\n"); return ret; } +static const struct of_device_id ls1x_gpio_dt_ids[] = { + { .compatible = "loongson,ls1x-gpio", }, + { /* sentinel */ } +}; + static struct platform_driver ls1x_gpio_driver = { .probe = ls1x_gpio_probe, .driver = { .name = "ls1x-gpio", + .of_match_table = ls1x_gpio_dt_ids, }, };
This patch adds DT support for Loongson-1 GPIO driver, including the following changes. - Add the of_match_table - Parse the ngpios property - Parse the alias id Signed-off-by: Keguang Zhang <keguang.zhang@gmail.com> --- drivers/gpio/gpio-loongson1.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)