Message ID | 74988d34ceae9bf239c138a558778cd999beb77c.1663835855.git.zhoubinbin@loongson.cn |
---|---|
State | New |
Headers | show |
Series | i2c: ls2x: Add support for the Loongson-2K/LS7A I2C | expand |
Hi Binbin, Thank you for the patch! Yet something to improve: [auto build test ERROR on wsa/i2c/for-next] [also build test ERROR on linus/master v6.0-rc6 next-20220921] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/i2c-ls2x-Add-support-for-the-Loongson-2K-LS7A-I2C/20220922-194252 base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next config: hexagon-randconfig-r045-20220922 (https://download.01.org/0day-ci/archive/20220923/202209230137.EmkAkBHm-lkp@intel.com/config) compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/90590b2a30c8afa5bb200812ffa52a3c5bb9da6a git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Binbin-Zhou/i2c-ls2x-Add-support-for-the-Loongson-2K-LS7A-I2C/20220922-194252 git checkout 90590b2a30c8afa5bb200812ffa52a3c5bb9da6a # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/i2c/busses/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): >> drivers/i2c/busses/i2c-gpio.c:472:12: error: call to undeclared function 'acpi_evaluate_integer'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] status = acpi_evaluate_integer(ACPI_HANDLE(dev), ^ drivers/i2c/busses/i2c-gpio.c:472:12: note: did you mean 'acpi_evaluate_object'? include/acpi/acpixf.h:550:8: note: 'acpi_evaluate_object' declared here acpi_evaluate_object(acpi_handle object, ^ include/acpi/platform/aclinux.h:93:21: note: expanded from macro 'ACPI_EXTERNAL_RETURN_STATUS' static ACPI_INLINE prototype {return(AE_NOT_CONFIGURED);} ^ 1 error generated. vim +/acpi_evaluate_integer +472 drivers/i2c/busses/i2c-gpio.c 375 376 static int i2c_gpio_probe(struct platform_device *pdev) 377 { 378 struct i2c_gpio_private_data *priv; 379 struct i2c_gpio_platform_data *pdata; 380 struct i2c_algo_bit_data *bit_data; 381 struct i2c_adapter *adap; 382 struct device *dev = &pdev->dev; 383 struct device_node *np = dev->of_node; 384 enum gpiod_flags gflags; 385 acpi_status status; 386 unsigned long long id; 387 int ret; 388 389 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 390 if (!priv) 391 return -ENOMEM; 392 393 adap = &priv->adap; 394 bit_data = &priv->bit_data; 395 pdata = &priv->pdata; 396 397 if (np) { 398 of_i2c_gpio_get_props(np, pdata); 399 } else if (ACPI_COMPANION(dev)) { 400 acpi_i2c_gpio_get_props(dev, pdata); 401 } else { 402 /* 403 * If all platform data settings are zero it is OK 404 * to not provide any platform data from the board. 405 */ 406 if (dev_get_platdata(dev)) 407 memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata)); 408 } 409 410 /* 411 * First get the GPIO pins; if it fails, we'll defer the probe. 412 * If the SCL/SDA lines are marked "open drain" by platform data or 413 * device tree then this means that something outside of our control is 414 * marking these lines to be handled as open drain, and we should just 415 * handle them as we handle any other output. Else we enforce open 416 * drain as this is required for an I2C bus. 417 */ 418 if (pdata->sda_is_open_drain) 419 gflags = GPIOD_OUT_HIGH; 420 else 421 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; 422 priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags); 423 if (IS_ERR(priv->sda)) 424 return PTR_ERR(priv->sda); 425 426 if (pdata->scl_is_open_drain) 427 gflags = GPIOD_OUT_HIGH; 428 else 429 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; 430 priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags); 431 if (IS_ERR(priv->scl)) 432 return PTR_ERR(priv->scl); 433 434 if (gpiod_cansleep(priv->sda) || gpiod_cansleep(priv->scl)) 435 dev_warn(dev, "Slow GPIO pins might wreak havoc into I2C/SMBus bus timing"); 436 else 437 bit_data->can_do_atomic = true; 438 439 bit_data->setsda = i2c_gpio_setsda_val; 440 bit_data->setscl = i2c_gpio_setscl_val; 441 442 if (!pdata->scl_is_output_only) 443 bit_data->getscl = i2c_gpio_getscl; 444 bit_data->getsda = i2c_gpio_getsda; 445 446 if (pdata->udelay) 447 bit_data->udelay = pdata->udelay; 448 else if (pdata->scl_is_output_only) 449 bit_data->udelay = 50; /* 10 kHz */ 450 else 451 bit_data->udelay = 5; /* 100 kHz */ 452 453 if (pdata->timeout) 454 bit_data->timeout = pdata->timeout; 455 else 456 bit_data->timeout = HZ / 10; /* 100 ms */ 457 458 bit_data->data = priv; 459 460 adap->owner = THIS_MODULE; 461 if (np) 462 strscpy(adap->name, dev_name(dev), sizeof(adap->name)); 463 else 464 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 465 466 adap->algo_data = bit_data; 467 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 468 adap->dev.parent = dev; 469 adap->dev.of_node = np; 470 471 if (ACPI_COMPANION(dev)) { > 472 status = acpi_evaluate_integer(ACPI_HANDLE(dev), 473 "_UID", NULL, &id); 474 if (ACPI_SUCCESS(status) && (id >= 0)) 475 adap->nr = id; 476 } else 477 adap->nr = pdev->id; 478 479 ret = i2c_bit_add_numbered_bus(adap); 480 if (ret) 481 return ret; 482 483 platform_set_drvdata(pdev, priv); 484 485 /* 486 * FIXME: using global GPIO numbers is not helpful. If/when we 487 * get accessors to get the actual name of the GPIO line, 488 * from the descriptor, then provide that instead. 489 */ 490 dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", 491 desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), 492 pdata->scl_is_output_only 493 ? ", no clock stretching" : ""); 494 495 i2c_gpio_fault_injector_init(pdev); 496 497 return 0; 498 } 499
On Fri, Sep 23, 2022 at 06:01:30PM +0800, Binbin Zhou wrote: > Hi Mika: > > 在 2022/9/22 20:26, Mika Westerberg 写道: > > Hi, > > > > On Thu, Sep 22, 2022 at 07:39:55PM +0800, Binbin Zhou wrote: > > > Add support for the ACPI-based device registration so that the driver > > > can be also enabled through ACPI table. > > > > > > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> > > > Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> > > > --- > > > drivers/i2c/busses/i2c-gpio.c | 41 ++++++++++++++++++++++++++++++++++- > > > 1 file changed, 40 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c > > > index b1985c1667e1..ccea37e755e6 100644 > > > --- a/drivers/i2c/busses/i2c-gpio.c > > > +++ b/drivers/i2c/busses/i2c-gpio.c > > > @@ -13,6 +13,7 @@ > > > #include <linux/init.h> > > > #include <linux/interrupt.h> > > > #include <linux/module.h> > > > +#include <linux/acpi.h> > > > #include <linux/of.h> > > > #include <linux/platform_data/i2c-gpio.h> > > > #include <linux/platform_device.h> > > > @@ -318,6 +319,24 @@ static void of_i2c_gpio_get_props(struct device_node *np, > > > of_property_read_bool(np, "i2c-gpio,scl-output-only"); > > > } > > > +static void acpi_i2c_gpio_get_props(struct device *dev, > > > + struct i2c_gpio_platform_data *pdata) > > > +{ > > > + u32 reg; > > > + > > > + device_property_read_u32(dev, "delay-us", &pdata->udelay); > > > + > > > + if (!device_property_read_u32(dev, "timeout-ms", ®)) > > > + pdata->timeout = msecs_to_jiffies(reg); > > > + > > > + pdata->sda_is_open_drain = > > > + device_property_read_bool(dev, "sda-open-drain"); > > > + pdata->scl_is_open_drain = > > > + device_property_read_bool(dev, "scl-open-drain"); > > > + pdata->scl_is_output_only = > > > + device_property_read_bool(dev, "scl-output-only"); > > > +} > > > > I think this would work with the DT description too as it is using > > device_property_xxx() so I wonder if you can just do: > > > > i2c_gpio_get_props(dev, pdata); > > > > instead of > > > > if (np) { > > of_i2c_gpio_get_props(np, pdata); > > } else if (ACPI_COMPANION(dev)) { > > acpi_i2c_gpio_get_props(dev, pdata); > > > Sorry, I don't quite understand how to do a unified api. > > We get the corresponding value by matching the propname, but obviously the > propnames related in the two ways are different. > > e.g. "delay-us"(ACPI) vs "i2c-gpio, delay-us"(FDT) Oh, we have different bindings for these? :( That's unfortunate - they should really have the same. That's the whole purpose of device properties API in the first place.
Hi Binbin,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on linus/master v6.0-rc7 next-20220923]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/i2c-ls2x-Add-support-for-the-Loongson-2K-LS7A-I2C/20220922-194252
base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
config: x86_64-randconfig-m001
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
smatch warnings:
drivers/i2c/busses/i2c-gpio.c:474 i2c_gpio_probe() warn: always true condition '(id >= 0) => (0-u64max >= 0)'
vim +474 drivers/i2c/busses/i2c-gpio.c
375
376 static int i2c_gpio_probe(struct platform_device *pdev)
377 {
378 struct i2c_gpio_private_data *priv;
379 struct i2c_gpio_platform_data *pdata;
380 struct i2c_algo_bit_data *bit_data;
381 struct i2c_adapter *adap;
382 struct device *dev = &pdev->dev;
383 struct device_node *np = dev->of_node;
384 enum gpiod_flags gflags;
385 acpi_status status;
386 unsigned long long id;
387 int ret;
388
389 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
390 if (!priv)
391 return -ENOMEM;
392
393 adap = &priv->adap;
394 bit_data = &priv->bit_data;
395 pdata = &priv->pdata;
396
397 if (np) {
398 of_i2c_gpio_get_props(np, pdata);
399 } else if (ACPI_COMPANION(dev)) {
400 acpi_i2c_gpio_get_props(dev, pdata);
401 } else {
402 /*
403 * If all platform data settings are zero it is OK
404 * to not provide any platform data from the board.
405 */
406 if (dev_get_platdata(dev))
407 memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata));
408 }
409
410 /*
411 * First get the GPIO pins; if it fails, we'll defer the probe.
412 * If the SCL/SDA lines are marked "open drain" by platform data or
413 * device tree then this means that something outside of our control is
414 * marking these lines to be handled as open drain, and we should just
415 * handle them as we handle any other output. Else we enforce open
416 * drain as this is required for an I2C bus.
417 */
418 if (pdata->sda_is_open_drain)
419 gflags = GPIOD_OUT_HIGH;
420 else
421 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN;
422 priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags);
423 if (IS_ERR(priv->sda))
424 return PTR_ERR(priv->sda);
425
426 if (pdata->scl_is_open_drain)
427 gflags = GPIOD_OUT_HIGH;
428 else
429 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN;
430 priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags);
431 if (IS_ERR(priv->scl))
432 return PTR_ERR(priv->scl);
433
434 if (gpiod_cansleep(priv->sda) || gpiod_cansleep(priv->scl))
435 dev_warn(dev, "Slow GPIO pins might wreak havoc into I2C/SMBus bus timing");
436 else
437 bit_data->can_do_atomic = true;
438
439 bit_data->setsda = i2c_gpio_setsda_val;
440 bit_data->setscl = i2c_gpio_setscl_val;
441
442 if (!pdata->scl_is_output_only)
443 bit_data->getscl = i2c_gpio_getscl;
444 bit_data->getsda = i2c_gpio_getsda;
445
446 if (pdata->udelay)
447 bit_data->udelay = pdata->udelay;
448 else if (pdata->scl_is_output_only)
449 bit_data->udelay = 50; /* 10 kHz */
450 else
451 bit_data->udelay = 5; /* 100 kHz */
452
453 if (pdata->timeout)
454 bit_data->timeout = pdata->timeout;
455 else
456 bit_data->timeout = HZ / 10; /* 100 ms */
457
458 bit_data->data = priv;
459
460 adap->owner = THIS_MODULE;
461 if (np)
462 strscpy(adap->name, dev_name(dev), sizeof(adap->name));
463 else
464 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
465
466 adap->algo_data = bit_data;
467 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
468 adap->dev.parent = dev;
469 adap->dev.of_node = np;
470
471 if (ACPI_COMPANION(dev)) {
472 status = acpi_evaluate_integer(ACPI_HANDLE(dev),
473 "_UID", NULL, &id);
> 474 if (ACPI_SUCCESS(status) && (id >= 0))
475 adap->nr = id;
476 } else
477 adap->nr = pdev->id;
478
479 ret = i2c_bit_add_numbered_bus(adap);
480 if (ret)
481 return ret;
482
483 platform_set_drvdata(pdev, priv);
484
485 /*
486 * FIXME: using global GPIO numbers is not helpful. If/when we
487 * get accessors to get the actual name of the GPIO line,
488 * from the descriptor, then provide that instead.
489 */
490 dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n",
491 desc_to_gpio(priv->sda), desc_to_gpio(priv->scl),
492 pdata->scl_is_output_only
493 ? ", no clock stretching" : "");
494
495 i2c_gpio_fault_injector_init(pdev);
496
497 return 0;
498 }
499
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index b1985c1667e1..ccea37e755e6 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -13,6 +13,7 @@ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> +#include <linux/acpi.h> #include <linux/of.h> #include <linux/platform_data/i2c-gpio.h> #include <linux/platform_device.h> @@ -318,6 +319,24 @@ static void of_i2c_gpio_get_props(struct device_node *np, of_property_read_bool(np, "i2c-gpio,scl-output-only"); } +static void acpi_i2c_gpio_get_props(struct device *dev, + struct i2c_gpio_platform_data *pdata) +{ + u32 reg; + + device_property_read_u32(dev, "delay-us", &pdata->udelay); + + if (!device_property_read_u32(dev, "timeout-ms", ®)) + pdata->timeout = msecs_to_jiffies(reg); + + pdata->sda_is_open_drain = + device_property_read_bool(dev, "sda-open-drain"); + pdata->scl_is_open_drain = + device_property_read_bool(dev, "scl-open-drain"); + pdata->scl_is_output_only = + device_property_read_bool(dev, "scl-output-only"); +} + static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, const char *con_id, unsigned int index, @@ -363,6 +382,8 @@ static int i2c_gpio_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; enum gpiod_flags gflags; + acpi_status status; + unsigned long long id; int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); @@ -375,6 +396,8 @@ static int i2c_gpio_probe(struct platform_device *pdev) if (np) { of_i2c_gpio_get_props(np, pdata); + } else if (ACPI_COMPANION(dev)) { + acpi_i2c_gpio_get_props(dev, pdata); } else { /* * If all platform data settings are zero it is OK @@ -445,7 +468,14 @@ static int i2c_gpio_probe(struct platform_device *pdev) adap->dev.parent = dev; adap->dev.of_node = np; - adap->nr = pdev->id; + if (ACPI_COMPANION(dev)) { + status = acpi_evaluate_integer(ACPI_HANDLE(dev), + "_UID", NULL, &id); + if (ACPI_SUCCESS(status) && (id >= 0)) + adap->nr = id; + } else + adap->nr = pdev->id; + ret = i2c_bit_add_numbered_bus(adap); if (ret) return ret; @@ -491,10 +521,19 @@ static const struct of_device_id i2c_gpio_dt_ids[] = { MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids); #endif +#ifdef CONFIG_ACPI +static const struct acpi_device_id i2c_gpio_acpi_match[] = { + {"LOON0005"}, + {} +}; +MODULE_DEVICE_TABLE(acpi, i2c_gpio_acpi_match); +#endif + static struct platform_driver i2c_gpio_driver = { .driver = { .name = "i2c-gpio", .of_match_table = of_match_ptr(i2c_gpio_dt_ids), + .acpi_match_table = ACPI_PTR(i2c_gpio_acpi_match), }, .probe = i2c_gpio_probe, .remove = i2c_gpio_remove,