mbox series

[0/5] i2c: ls2x: Add support for the Loongson-2K/LS7A I2C

Message ID cover.1663835855.git.zhoubinbin@loongson.cn
Headers show
Series i2c: ls2x: Add support for the Loongson-2K/LS7A I2C | expand

Message

Binbin Zhou Sept. 22, 2022, 11:39 a.m. UTC
Hi all:

This patch series adds support for the I2C module found on various
Loongson systems with the Loongson-2K SoC or the Loongson LS7A bridge chip.

For now, the I2C driver is suitable for DT-based or ACPI-based systems.

BTW:
I have only tested on the Loongson-3A5000+LS7A1000/LS7A2000 under LoongArch
architecture.

Thanks.

Binbin Zhou (5):
  i2c: core: Pick i2c bus number from ACPI if present
  i2c: gpio: Add support on ACPI-based system
  dt-bindings: i2c: add bindings for Loongson LS2X I2C
  i2c: Add driver for Loongson-2K/LS7A I2C controller
  LoongArch: Enable LS2X I2C in loongson3_defconfig

 .../bindings/i2c/loongson,ls2x-i2c.yaml       |  48 +++
 arch/loongarch/configs/loongson3_defconfig    |   1 +
 drivers/i2c/busses/Kconfig                    |   7 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-gpio.c                 |  41 +-
 drivers/i2c/busses/i2c-ls2x.c                 | 364 ++++++++++++++++++
 drivers/i2c/i2c-core-base.c                   |  10 +-
 7 files changed, 470 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml
 create mode 100644 drivers/i2c/busses/i2c-ls2x.c

Comments

Mika Westerberg Sept. 22, 2022, 12:23 p.m. UTC | #1
Hi,

On Thu, Sep 22, 2022 at 07:39:54PM +0800, Binbin Zhou wrote:
> Under LoongARCH based on ACPI(such as Loongson-3A + LS7A), the ls2x i2c
> driver obtains the i2c bus number from ACPI table.

Why this is needed? The I2CSerialBusV2() resource should be enough to
identify the adapter, and I don't see why static number would be needed
for anything?
Jinyang He Sept. 22, 2022, 12:29 p.m. UTC | #2
On 2022/9/22 下午7:39, Binbin Zhou wrote:

> Under LoongARCH based on ACPI(such as Loongson-3A + LS7A), the ls2x i2c
> driver obtains the i2c bus number from ACPI table.
>
> Similar to the DT-base system, this is also a static bus number.
>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
>   drivers/i2c/i2c-core-base.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 91007558bcb2..ffab4cc2c6ba 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1559,7 +1559,8 @@ static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
>   int i2c_add_adapter(struct i2c_adapter *adapter)
>   {
>   	struct device *dev = &adapter->dev;
> -	int id;
> +	acpi_status status;
> +	unsigned long long id;
>   
>   	if (dev->of_node) {
>   		id = of_alias_get_id(dev->of_node, "i2c");
> @@ -1567,6 +1568,13 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
>   			adapter->nr = id;
>   			return __i2c_add_numbered_adapter(adapter);
>   		}
> +	} else if (dev->parent->fwnode) {
> +		status = acpi_evaluate_integer(ACPI_HANDLE(dev->parent),
> +						"_UID", NULL, &id);
> +		if (ACPI_SUCCESS(status) && (id >= 0)) {

Hi, Binbin,


Emm, the id is unsigned and it always return true if (id>=0). And I think

you should check the other patches.


Jinyang


> +			adapter->nr = id;
> +			return __i2c_add_numbered_adapter(adapter);
> +		}
>   	}
>   
>   	mutex_lock(&core_lock);
Mika Westerberg Sept. 23, 2022, 8:55 a.m. UTC | #3
Hi,

On Fri, Sep 23, 2022 at 03:16:03PM +0800, Huacai Chen wrote:
> Hi, Mika,
> 
> On Thu, Sep 22, 2022 at 8:23 PM Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> >
> > Hi,
> >
> > On Thu, Sep 22, 2022 at 07:39:54PM +0800, Binbin Zhou wrote:
> > > Under LoongARCH based on ACPI(such as Loongson-3A + LS7A), the ls2x i2c
> > > driver obtains the i2c bus number from ACPI table.
> >
> > Why this is needed? The I2CSerialBusV2() resource should be enough to
> > identify the adapter, and I don't see why static number would be needed
> > for anything?
> >
> In later patches we will add LS7A i2c driver, this driver is shared by
> MIPS-based Loongson-3A4000 system (use FDT) and LoongArch-based
> Loongson-3A5000 system (use ACPI).
> 
> FDT systems support static bus numbers, so we want to do the same
> thing on ACPI systems. I think keep this consistency can make user
> feel better

I don't think the user cares to be honest. As long as all the devices
work as expected ;-) And this saves a couple of lines of code too so if
not really needed, I would just drop that part.