diff mbox series

[v2,4/4] i2c: i2c-qcom-geni: Enable i2c controller sharing between two subsystems

Message ID 20240906191438.4104329-5-quic_msavaliy@quicinc.com
State Changes Requested
Delegated to: Andi Shyti
Headers show
Series Enable shared SE support over I2C | expand

Commit Message

Mukesh Kumar Savaliya Sept. 6, 2024, 7:14 p.m. UTC
Add support to share I2C SE by two Subsystems in a mutually exclusive way.
Use  "qcom,shared-se" flag in a particular i2c instance node if the
usecase requires i2c controller to be shared.

I2C driver just need to mark first_msg and last_msg flag to help indicate
GPI driver to  take lock and unlock TRE there by protecting from concurrent
access from other EE or Subsystem.

gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
Unlock TRE for the respective transfer operations.

Since the GPIOs are also shared for the i2c bus between two SS, do not
touch GPIO configuration during runtime suspend and only turn off the
clocks. This will allow other SS to continue to transfer the data
without any disturbance over the IO lines.

Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
---
 drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

Comments

Andi Shyti Sept. 7, 2024, 7:56 a.m. UTC | #1
Hi Mukesh,

On Sat, Sep 07, 2024 at 12:44:38AM GMT, Mukesh Kumar Savaliya wrote:
> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
> Use  "qcom,shared-se" flag in a particular i2c instance node if the
> usecase requires i2c controller to be shared.
> 
> I2C driver just need to mark first_msg and last_msg flag to help indicate
> GPI driver to  take lock and unlock TRE there by protecting from concurrent
> access from other EE or Subsystem.
> 
> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
> Unlock TRE for the respective transfer operations.
> 
> Since the GPIOs are also shared for the i2c bus between two SS, do not
> touch GPIO configuration during runtime suspend and only turn off the
> clocks. This will allow other SS to continue to transfer the data
> without any disturbance over the IO lines.

if I remember correctly, someone already commented on your
patches to explain and expand the achronyms you are using. Please
improve the commit log so that people who don't know this device
can understand.

...

> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>  		dma_async_issue_pending(gi2c->tx_c);
>  
>  		time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
> -		if (!time_left)
> +		if (!time_left) {
> +			dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n",
> +						gi2c->cur->flags, gi2c->cur->addr);

Please, don't print out here. The user doesn't really need to
know, let the upper levels decide what to do.

>  			gi2c->err = -ETIMEDOUT;
> +		}
>  
>  		if (gi2c->err) {
>  			ret = gi2c->err;
> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device *pdev)
>  		gi2c->clk_freq_out = KHZ(100);
>  	}
>  
> +	if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
> +		gi2c->is_shared = true;
> +		dev_dbg(&pdev->dev, "Shared SE Usecase\n");

Please, improve this debug message.

The rest looks good to me.

Thanks,
Andi
Neil Armstrong Sept. 9, 2024, 8:54 a.m. UTC | #2
Hi,

On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
> Use  "qcom,shared-se" flag in a particular i2c instance node if the
> usecase requires i2c controller to be shared.
> 
> I2C driver just need to mark first_msg and last_msg flag to help indicate
> GPI driver to  take lock and unlock TRE there by protecting from concurrent
> access from other EE or Subsystem.
> 
> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
> Unlock TRE for the respective transfer operations.
> 
> Since the GPIOs are also shared for the i2c bus between two SS, do not
> touch GPIO configuration during runtime suspend and only turn off the
> clocks. This will allow other SS to continue to transfer the data
> without any disturbance over the IO lines.

This doesn't answer my question about what would be the behavior if one
use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?

Because it seems to "fix" only the GPI DMA shared case.

Neil

> 
> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
> ---
>   drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
>   1 file changed, 22 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> index eebb0cbb6ca4..ee2e431601a6 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> @@ -1,5 +1,6 @@
>   // SPDX-License-Identifier: GPL-2.0
>   // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
>   
>   #include <linux/acpi.h>
>   #include <linux/clk.h>
> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>   	struct dma_chan *rx_c;
>   	bool gpi_mode;
>   	bool abort_done;
> +	bool is_shared;
>   };
>   
>   struct geni_i2c_desc {
> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>   	peripheral.clk_div = itr->clk_div;
>   	peripheral.set_config = 1;
>   	peripheral.multi_msg = false;
> +	peripheral.shared_se = gi2c->is_shared;
>   
>   	for (i = 0; i < num; i++) {
>   		gi2c->cur = &msgs[i];
> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>   		if (i < num - 1)
>   			peripheral.stretch = 1;
>   
> +		peripheral.first_msg = (i == 0);
> +		peripheral.last_msg = (i == num - 1);
>   		peripheral.addr = msgs[i].addr;
>   
>   		ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>   		dma_async_issue_pending(gi2c->tx_c);
>   
>   		time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
> -		if (!time_left)
> +		if (!time_left) {
> +			dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n",
> +						gi2c->cur->flags, gi2c->cur->addr);
>   			gi2c->err = -ETIMEDOUT;
> +		}
>   
>   		if (gi2c->err) {
>   			ret = gi2c->err;
> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device *pdev)
>   		gi2c->clk_freq_out = KHZ(100);
>   	}
>   
> +	if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
> +		gi2c->is_shared = true;
> +		dev_dbg(&pdev->dev, "Shared SE Usecase\n");
> +	}
> +
>   	if (has_acpi_companion(dev))
>   		ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>   
> @@ -962,14 +975,16 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev)
>   	struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>   
>   	disable_irq(gi2c->irq);
> -	ret = geni_se_resources_off(&gi2c->se);
> -	if (ret) {
> -		enable_irq(gi2c->irq);
> -		return ret;
> -
> +	if (gi2c->is_shared) {
> +		geni_se_clks_off(&gi2c->se);
>   	} else {
> -		gi2c->suspended = 1;
> +		ret = geni_se_resources_off(&gi2c->se);
> +		if (ret) {
> +			enable_irq(gi2c->irq);
> +			return ret;
> +		}
>   	}
> +	gi2c->suspended = 1;
>   
>   	clk_disable_unprepare(gi2c->core_clk);
>
Mukesh Kumar Savaliya Sept. 9, 2024, 9:18 a.m. UTC | #3
Hi Neil,

On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
> Hi,
> 
> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>> Add support to share I2C SE by two Subsystems in a mutually exclusive 
>> way.
>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>> usecase requires i2c controller to be shared.
>>
>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>> GPI driver to  take lock and unlock TRE there by protecting from 
>> concurrent
>> access from other EE or Subsystem.
>>
>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>> Unlock TRE for the respective transfer operations.
>>
>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>> touch GPIO configuration during runtime suspend and only turn off the
>> clocks. This will allow other SS to continue to transfer the data
>> without any disturbance over the IO lines.
> 
> This doesn't answer my question about what would be the behavior if one
> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
> 
Shared usecase is not supported for non GSI mode (FIFO and DMA), it 
should be static usecase. Dynamic sharing from two clients of two 
subsystems is only for GSI mode. Hope this helps ?
> Because it seems to "fix" only the GPI DMA shared case.
> 
> Neil
> 
>>
>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
>> ---
>>   drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
>>   1 file changed, 22 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
>> b/drivers/i2c/busses/i2c-qcom-geni.c
>> index eebb0cbb6ca4..ee2e431601a6 100644
>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>> @@ -1,5 +1,6 @@
>>   // SPDX-License-Identifier: GPL-2.0
>>   // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
>> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights 
>> reserved.
>>   #include <linux/acpi.h>
>>   #include <linux/clk.h>
>> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>>       struct dma_chan *rx_c;
>>       bool gpi_mode;
>>       bool abort_done;
>> +    bool is_shared;
>>   };
>>   struct geni_i2c_desc {
>> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>> *gi2c, struct i2c_msg msgs[], i
>>       peripheral.clk_div = itr->clk_div;
>>       peripheral.set_config = 1;
>>       peripheral.multi_msg = false;
>> +    peripheral.shared_se = gi2c->is_shared;
>>       for (i = 0; i < num; i++) {
>>           gi2c->cur = &msgs[i];
>> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>> *gi2c, struct i2c_msg msgs[], i
>>           if (i < num - 1)
>>               peripheral.stretch = 1;
>> +        peripheral.first_msg = (i == 0);
>> +        peripheral.last_msg = (i == num - 1);
>>           peripheral.addr = msgs[i].addr;
>>           ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>> *gi2c, struct i2c_msg msgs[], i
>>           dma_async_issue_pending(gi2c->tx_c);
>>           time_left = wait_for_completion_timeout(&gi2c->done, 
>> XFER_TIMEOUT);
>> -        if (!time_left)
>> +        if (!time_left) {
>> +            dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d 
>> addr:0x%x\n",
>> +                        gi2c->cur->flags, gi2c->cur->addr);
>>               gi2c->err = -ETIMEDOUT;
>> +        }
>>           if (gi2c->err) {
>>               ret = gi2c->err;
>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device 
>> *pdev)
>>           gi2c->clk_freq_out = KHZ(100);
>>       }
>> +    if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
>> +        gi2c->is_shared = true;
>> +        dev_dbg(&pdev->dev, "Shared SE Usecase\n");
>> +    }
>> +
>>       if (has_acpi_companion(dev))
>>           ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>> @@ -962,14 +975,16 @@ static int __maybe_unused 
>> geni_i2c_runtime_suspend(struct device *dev)
>>       struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>>       disable_irq(gi2c->irq);
>> -    ret = geni_se_resources_off(&gi2c->se);
>> -    if (ret) {
>> -        enable_irq(gi2c->irq);
>> -        return ret;
>> -
>> +    if (gi2c->is_shared) {
>> +        geni_se_clks_off(&gi2c->se);
>>       } else {
>> -        gi2c->suspended = 1;
>> +        ret = geni_se_resources_off(&gi2c->se);
>> +        if (ret) {
>> +            enable_irq(gi2c->irq);
>> +            return ret;
>> +        }
>>       }
>> +    gi2c->suspended = 1;
>>       clk_disable_unprepare(gi2c->core_clk);
> 
>
Konrad Dybcio Sept. 9, 2024, 11:37 a.m. UTC | #4
On 9.09.2024 11:18 AM, Mukesh Kumar Savaliya wrote:
> Hi Neil,
> 
> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>> Hi,
>>
>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
>>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>>> usecase requires i2c controller to be shared.
>>>
>>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
>>> access from other EE or Subsystem.
>>>
>>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>>> Unlock TRE for the respective transfer operations.
>>>
>>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>>> touch GPIO configuration during runtime suspend and only turn off the
>>> clocks. This will allow other SS to continue to transfer the data
>>> without any disturbance over the IO lines.
>>
>> This doesn't answer my question about what would be the behavior if one
>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
>>
> Shared usecase is not supported for non GSI mode (FIFO and DMA), it should be static usecase. Dynamic sharing from two clients of two subsystems is only for GSI mode. Hope this helps ?

This should very much be explained in commit message and perhaps in code

And since it can't work with FIFO mode, there should be checks in code
to disallow such invalid configurations

Konrad
Andi Shyti Sept. 9, 2024, 12:53 p.m. UTC | #5
Thank you guys for your reviews,

On Mon, Sep 09, 2024 at 01:37:00PM GMT, Konrad Dybcio wrote:
> On 9.09.2024 11:18 AM, Mukesh Kumar Savaliya wrote:
> > Hi Neil,
> > 
> > On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
> >> Hi,
> >>
> >> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
> >>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
> >>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
> >>> usecase requires i2c controller to be shared.
> >>>
> >>> I2C driver just need to mark first_msg and last_msg flag to help indicate
> >>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
> >>> access from other EE or Subsystem.
> >>>
> >>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
> >>> Unlock TRE for the respective transfer operations.
> >>>
> >>> Since the GPIOs are also shared for the i2c bus between two SS, do not
> >>> touch GPIO configuration during runtime suspend and only turn off the
> >>> clocks. This will allow other SS to continue to transfer the data
> >>> without any disturbance over the IO lines.
> >>
> >> This doesn't answer my question about what would be the behavior if one
> >> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
> >>
> > Shared usecase is not supported for non GSI mode (FIFO and DMA), it should be static usecase. Dynamic sharing from two clients of two subsystems is only for GSI mode. Hope this helps ?
> 
> This should very much be explained in commit message and perhaps in code
> 
> And since it can't work with FIFO mode, there should be checks in code
> to disallow such invalid configurations

it would be nice if, along with all these open questions and
clarifications on the commit message, we could add some good
comments to the code as well.

Thanks,
Andi
Neil Armstrong Sept. 9, 2024, 1:04 p.m. UTC | #6
On 09/09/2024 11:18, Mukesh Kumar Savaliya wrote:
> Hi Neil,
> 
> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>> Hi,
>>
>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
>>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>>> usecase requires i2c controller to be shared.
>>>
>>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
>>> access from other EE or Subsystem.
>>>
>>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>>> Unlock TRE for the respective transfer operations.
>>>
>>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>>> touch GPIO configuration during runtime suspend and only turn off the
>>> clocks. This will allow other SS to continue to transfer the data
>>> without any disturbance over the IO lines.
>>
>> This doesn't answer my question about what would be the behavior if one
>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
>>
> Shared usecase is not supported for non GSI mode (FIFO and DMA), it should be static usecase. Dynamic sharing from two clients of two subsystems is only for GSI mode. Hope this helps ?

Sure, this is why I proposed on v1 cover letter reply to add:
==============><=====================================================================
diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index ee2e431601a6..a15825ea56de 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -885,7 +885,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
          else
                  fifo_disable = readl_relaxed(gi2c->se.base + GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE;

-       if (fifo_disable) {
+       if (gi2c->is_shared || fifo_disable) {
                  /* FIFO is disabled, so we can only use GPI DMA */
                  gi2c->gpi_mode = true;
                  ret = setup_gpi_dma(gi2c);
==============><=====================================================================

Thanks,
Neil

>> Because it seems to "fix" only the GPI DMA shared case.
>>
>> Neil
>>
>>>
>>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
>>> ---
>>>   drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
>>>   1 file changed, 22 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
>>> index eebb0cbb6ca4..ee2e431601a6 100644
>>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>>> @@ -1,5 +1,6 @@
>>>   // SPDX-License-Identifier: GPL-2.0
>>>   // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
>>> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
>>>   #include <linux/acpi.h>
>>>   #include <linux/clk.h>
>>> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>>>       struct dma_chan *rx_c;
>>>       bool gpi_mode;
>>>       bool abort_done;
>>> +    bool is_shared;
>>>   };
>>>   struct geni_i2c_desc {
>>> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>       peripheral.clk_div = itr->clk_div;
>>>       peripheral.set_config = 1;
>>>       peripheral.multi_msg = false;
>>> +    peripheral.shared_se = gi2c->is_shared;
>>>       for (i = 0; i < num; i++) {
>>>           gi2c->cur = &msgs[i];
>>> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>           if (i < num - 1)
>>>               peripheral.stretch = 1;
>>> +        peripheral.first_msg = (i == 0);
>>> +        peripheral.last_msg = (i == num - 1);
>>>           peripheral.addr = msgs[i].addr;
>>>           ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
>>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>           dma_async_issue_pending(gi2c->tx_c);
>>>           time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
>>> -        if (!time_left)
>>> +        if (!time_left) {
>>> +            dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n",
>>> +                        gi2c->cur->flags, gi2c->cur->addr);
>>>               gi2c->err = -ETIMEDOUT;
>>> +        }
>>>           if (gi2c->err) {
>>>               ret = gi2c->err;
>>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device *pdev)
>>>           gi2c->clk_freq_out = KHZ(100);
>>>       }
>>> +    if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
>>> +        gi2c->is_shared = true;
>>> +        dev_dbg(&pdev->dev, "Shared SE Usecase\n");
>>> +    }
>>> +
>>>       if (has_acpi_companion(dev))
>>>           ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>>> @@ -962,14 +975,16 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev)
>>>       struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>>>       disable_irq(gi2c->irq);
>>> -    ret = geni_se_resources_off(&gi2c->se);
>>> -    if (ret) {
>>> -        enable_irq(gi2c->irq);
>>> -        return ret;
>>> -
>>> +    if (gi2c->is_shared) {
>>> +        geni_se_clks_off(&gi2c->se);
>>>       } else {
>>> -        gi2c->suspended = 1;
>>> +        ret = geni_se_resources_off(&gi2c->se);
>>> +        if (ret) {
>>> +            enable_irq(gi2c->irq);
>>> +            return ret;
>>> +        }
>>>       }
>>> +    gi2c->suspended = 1;
>>>       clk_disable_unprepare(gi2c->core_clk);
>>
>>
Mukesh Kumar Savaliya Sept. 10, 2024, 9:12 a.m. UTC | #7
Hi Neil,

On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
> Hi,
> 
> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>> Add support to share I2C SE by two Subsystems in a mutually exclusive 
>> way.
>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>> usecase requires i2c controller to be shared.
>>
>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>> GPI driver to  take lock and unlock TRE there by protecting from 
>> concurrent
>> access from other EE or Subsystem.
>>
>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>> Unlock TRE for the respective transfer operations.
>>
>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>> touch GPIO configuration during runtime suspend and only turn off the
>> clocks. This will allow other SS to continue to transfer the data
>> without any disturbance over the IO lines.
> 
> This doesn't answer my question about what would be the behavior if one
> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
> 
> Because it seems to "fix" only the GPI DMA shared case.
> 
This shared usecase is possible only GPI DMA mode, not for the FIFO OR 
SE DMA mode. Let me add conditional mask with GPI DMA mode only. Hope 
that would clarify ?
> Neil
> 
>>
>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
>> ---
>>   drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
>>   1 file changed, 22 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
>> b/drivers/i2c/busses/i2c-qcom-geni.c
>> index eebb0cbb6ca4..ee2e431601a6 100644
>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>> @@ -1,5 +1,6 @@
>>   // SPDX-License-Identifier: GPL-2.0
>>   // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
>> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights 
>> reserved.
>>   #include <linux/acpi.h>
>>   #include <linux/clk.h>
>> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>>       struct dma_chan *rx_c;
>>       bool gpi_mode;
>>       bool abort_done;
>> +    bool is_shared;
>>   };
>>   struct geni_i2c_desc {
>> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>> *gi2c, struct i2c_msg msgs[], i
>>       peripheral.clk_div = itr->clk_div;
>>       peripheral.set_config = 1;
>>       peripheral.multi_msg = false;
>> +    peripheral.shared_se = gi2c->is_shared;
>>       for (i = 0; i < num; i++) {
>>           gi2c->cur = &msgs[i];
>> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>> *gi2c, struct i2c_msg msgs[], i
>>           if (i < num - 1)
>>               peripheral.stretch = 1;
>> +        peripheral.first_msg = (i == 0);
>> +        peripheral.last_msg = (i == num - 1);
>>           peripheral.addr = msgs[i].addr;
>>           ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>> *gi2c, struct i2c_msg msgs[], i
>>           dma_async_issue_pending(gi2c->tx_c);
>>           time_left = wait_for_completion_timeout(&gi2c->done, 
>> XFER_TIMEOUT);
>> -        if (!time_left)
>> +        if (!time_left) {
>> +            dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d 
>> addr:0x%x\n",
>> +                        gi2c->cur->flags, gi2c->cur->addr);
>>               gi2c->err = -ETIMEDOUT;
>> +        }
>>           if (gi2c->err) {
>>               ret = gi2c->err;
>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device 
>> *pdev)
>>           gi2c->clk_freq_out = KHZ(100);
>>       }
>> +    if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
>> +        gi2c->is_shared = true;
>> +        dev_dbg(&pdev->dev, "Shared SE Usecase\n");
>> +    }
>> +
>>       if (has_acpi_companion(dev))
>>           ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>> @@ -962,14 +975,16 @@ static int __maybe_unused 
>> geni_i2c_runtime_suspend(struct device *dev)
>>       struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>>       disable_irq(gi2c->irq);
>> -    ret = geni_se_resources_off(&gi2c->se);
>> -    if (ret) {
>> -        enable_irq(gi2c->irq);
>> -        return ret;
>> -
>> +    if (gi2c->is_shared) {
>> +        geni_se_clks_off(&gi2c->se);
>>       } else {
>> -        gi2c->suspended = 1;
>> +        ret = geni_se_resources_off(&gi2c->se);
>> +        if (ret) {
>> +            enable_irq(gi2c->irq);
>> +            return ret;
>> +        }
>>       }
>> +    gi2c->suspended = 1;
>>       clk_disable_unprepare(gi2c->core_clk);
> 
>
Mukesh Kumar Savaliya Sept. 10, 2024, 9:12 a.m. UTC | #8
Thanks Konrad !

On 9/9/2024 5:07 PM, Konrad Dybcio wrote:
> On 9.09.2024 11:18 AM, Mukesh Kumar Savaliya wrote:
>> Hi Neil,
>>
>> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>>> Hi,
>>>
>>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
>>>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>>>> usecase requires i2c controller to be shared.
>>>>
>>>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>>>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
>>>> access from other EE or Subsystem.
>>>>
>>>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>>>> Unlock TRE for the respective transfer operations.
>>>>
>>>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>>>> touch GPIO configuration during runtime suspend and only turn off the
>>>> clocks. This will allow other SS to continue to transfer the data
>>>> without any disturbance over the IO lines.
>>>
>>> This doesn't answer my question about what would be the behavior if one
>>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
>>>
>> Shared usecase is not supported for non GSI mode (FIFO and DMA), it should be static usecase. Dynamic sharing from two clients of two subsystems is only for GSI mode. Hope this helps ?
> 
> This should very much be explained in commit message and perhaps in code
> 
Noted,  will add in commit message and cover letter.
> And since it can't work with FIFO mode, there should be checks in code
> to disallow such invalid configurations
> 
Agree, will add in next patch.
> Konrad
Mukesh Kumar Savaliya Sept. 10, 2024, 9:15 a.m. UTC | #9
Hi Neil,

On 9/9/2024 6:34 PM, neil.armstrong@linaro.org wrote:
> On 09/09/2024 11:18, Mukesh Kumar Savaliya wrote:
>> Hi Neil,
>>
>> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>>> Hi,
>>>
>>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>>> Add support to share I2C SE by two Subsystems in a mutually 
>>>> exclusive way.
>>>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>>>> usecase requires i2c controller to be shared.
>>>>
>>>> I2C driver just need to mark first_msg and last_msg flag to help 
>>>> indicate
>>>> GPI driver to  take lock and unlock TRE there by protecting from 
>>>> concurrent
>>>> access from other EE or Subsystem.
>>>>
>>>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock 
>>>> and
>>>> Unlock TRE for the respective transfer operations.
>>>>
>>>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>>>> touch GPIO configuration during runtime suspend and only turn off the
>>>> clocks. This will allow other SS to continue to transfer the data
>>>> without any disturbance over the IO lines.
>>>
>>> This doesn't answer my question about what would be the behavior if one
>>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE 
>>> DMA ?
>>>
>> Shared usecase is not supported for non GSI mode (FIFO and DMA), it 
>> should be static usecase. Dynamic sharing from two clients of two 
>> subsystems is only for GSI mode. Hope this helps ?
> 
> Sure, this is why I proposed on v1 cover letter reply to add:
Sure, i will add in cover letter and code check combining with 
fifo_disable check.
> ==============><=====================================================================
> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
> b/drivers/i2c/busses/i2c-qcom-geni.c
> index ee2e431601a6..a15825ea56de 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> @@ -885,7 +885,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
>           else
>                   fifo_disable = readl_relaxed(gi2c->se.base + 
> GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE;
> 
> -       if (fifo_disable) {
> +       if (gi2c->is_shared || fifo_disable) {
  Should be ANDING logically, as we need to combine both check. Shared
  usecase possible only for fifo_disable.

  if(gi2c->is_shared && fifo_disable) {
>                   /* FIFO is disabled, so we can only use GPI DMA */
>                   gi2c->gpi_mode = true;
>                   ret = setup_gpi_dma(gi2c);
> ==============><=====================================================================
> 
> Thanks,
> Neil
> 
>>> Because it seems to "fix" only the GPI DMA shared case.
>>>
>>> Neil
>>>
>>>>
>>>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
>>>> ---
>>>>   drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
>>>>   1 file changed, 22 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
>>>> b/drivers/i2c/busses/i2c-qcom-geni.c
>>>> index eebb0cbb6ca4..ee2e431601a6 100644
>>>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>>>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>>>> @@ -1,5 +1,6 @@
>>>>   // SPDX-License-Identifier: GPL-2.0
>>>>   // Copyright (c) 2017-2018, The Linux Foundation. All rights 
>>>> reserved.
>>>> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights 
>>>> reserved.
>>>>   #include <linux/acpi.h>
>>>>   #include <linux/clk.h>
>>>> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>>>>       struct dma_chan *rx_c;
>>>>       bool gpi_mode;
>>>>       bool abort_done;
>>>> +    bool is_shared;
>>>>   };
>>>>   struct geni_i2c_desc {
>>>> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>>>> *gi2c, struct i2c_msg msgs[], i
>>>>       peripheral.clk_div = itr->clk_div;
>>>>       peripheral.set_config = 1;
>>>>       peripheral.multi_msg = false;
>>>> +    peripheral.shared_se = gi2c->is_shared;
>>>>       for (i = 0; i < num; i++) {
>>>>           gi2c->cur = &msgs[i];
>>>> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev 
>>>> *gi2c, struct i2c_msg msgs[], i
>>>>           if (i < num - 1)
>>>>               peripheral.stretch = 1;
>>>> +        peripheral.first_msg = (i == 0);
>>>> +        peripheral.last_msg = (i == num - 1);
>>>>           peripheral.addr = msgs[i].addr;
>>>>           ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
>>>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct 
>>>> geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>           dma_async_issue_pending(gi2c->tx_c);
>>>>           time_left = wait_for_completion_timeout(&gi2c->done, 
>>>> XFER_TIMEOUT);
>>>> -        if (!time_left)
>>>> +        if (!time_left) {
>>>> +            dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d 
>>>> addr:0x%x\n",
>>>> +                        gi2c->cur->flags, gi2c->cur->addr);
>>>>               gi2c->err = -ETIMEDOUT;
>>>> +        }
>>>>           if (gi2c->err) {
>>>>               ret = gi2c->err;
>>>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct 
>>>> platform_device *pdev)
>>>>           gi2c->clk_freq_out = KHZ(100);
>>>>       }
>>>> +    if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
>>>> +        gi2c->is_shared = true;
>>>> +        dev_dbg(&pdev->dev, "Shared SE Usecase\n");
>>>> +    }
>>>> +
>>>>       if (has_acpi_companion(dev))
>>>>           ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>>>> @@ -962,14 +975,16 @@ static int __maybe_unused 
>>>> geni_i2c_runtime_suspend(struct device *dev)
>>>>       struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>>>>       disable_irq(gi2c->irq);
>>>> -    ret = geni_se_resources_off(&gi2c->se);
>>>> -    if (ret) {
>>>> -        enable_irq(gi2c->irq);
>>>> -        return ret;
>>>> -
>>>> +    if (gi2c->is_shared) {
>>>> +        geni_se_clks_off(&gi2c->se);
>>>>       } else {
>>>> -        gi2c->suspended = 1;
>>>> +        ret = geni_se_resources_off(&gi2c->se);
>>>> +        if (ret) {
>>>> +            enable_irq(gi2c->irq);
>>>> +            return ret;
>>>> +        }
>>>>       }
>>>> +    gi2c->suspended = 1;
>>>>       clk_disable_unprepare(gi2c->core_clk);
>>>
>>>
> 
>
Neil Armstrong Sept. 10, 2024, 9:52 a.m. UTC | #10
On 10/09/2024 11:15, Mukesh Kumar Savaliya wrote:
> Hi Neil,
> 
> On 9/9/2024 6:34 PM, neil.armstrong@linaro.org wrote:
>> On 09/09/2024 11:18, Mukesh Kumar Savaliya wrote:
>>> Hi Neil,
>>>
>>> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>>>> Hi,
>>>>
>>>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>>>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
>>>>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>>>>> usecase requires i2c controller to be shared.
>>>>>
>>>>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>>>>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
>>>>> access from other EE or Subsystem.
>>>>>
>>>>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>>>>> Unlock TRE for the respective transfer operations.
>>>>>
>>>>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>>>>> touch GPIO configuration during runtime suspend and only turn off the
>>>>> clocks. This will allow other SS to continue to transfer the data
>>>>> without any disturbance over the IO lines.
>>>>
>>>> This doesn't answer my question about what would be the behavior if one
>>>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
>>>>
>>> Shared usecase is not supported for non GSI mode (FIFO and DMA), it should be static usecase. Dynamic sharing from two clients of two subsystems is only for GSI mode. Hope this helps ?
>>
>> Sure, this is why I proposed on v1 cover letter reply to add:
> Sure, i will add in cover letter and code check combining with fifo_disable check.
>> ==============><=====================================================================
>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
>> index ee2e431601a6..a15825ea56de 100644
>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>> @@ -885,7 +885,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
>>           else
>>                   fifo_disable = readl_relaxed(gi2c->se.base + GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE;
>>
>> -       if (fifo_disable) {
>> +       if (gi2c->is_shared || fifo_disable) {
>   Should be ANDING logically, as we need to combine both check. Shared
>   usecase possible only for fifo_disable.

Could you elaborate on that ? GPI DMA is totally usable even if FIFO is enabled,
it's a decision took in the driver to _not_ use GPI when FIFO is enabled.

Neil

> 
>   if(gi2c->is_shared && fifo_disable) {
>>                   /* FIFO is disabled, so we can only use GPI DMA */
>>                   gi2c->gpi_mode = true;
>>                   ret = setup_gpi_dma(gi2c);
>> ==============><=====================================================================
>>
>> Thanks,
>> Neil
>>
>>>> Because it seems to "fix" only the GPI DMA shared case.
>>>>
>>>> Neil
>>>>
>>>>>
>>>>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
>>>>> ---
>>>>>   drivers/i2c/busses/i2c-qcom-geni.c | 29 ++++++++++++++++++++++-------
>>>>>   1 file changed, 22 insertions(+), 7 deletions(-)
>>>>>
>>>>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
>>>>> index eebb0cbb6ca4..ee2e431601a6 100644
>>>>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>>>>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>>>>> @@ -1,5 +1,6 @@
>>>>>   // SPDX-License-Identifier: GPL-2.0
>>>>>   // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
>>>>> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
>>>>>   #include <linux/acpi.h>
>>>>>   #include <linux/clk.h>
>>>>> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>>>>>       struct dma_chan *rx_c;
>>>>>       bool gpi_mode;
>>>>>       bool abort_done;
>>>>> +    bool is_shared;
>>>>>   };
>>>>>   struct geni_i2c_desc {
>>>>> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>>       peripheral.clk_div = itr->clk_div;
>>>>>       peripheral.set_config = 1;
>>>>>       peripheral.multi_msg = false;
>>>>> +    peripheral.shared_se = gi2c->is_shared;
>>>>>       for (i = 0; i < num; i++) {
>>>>>           gi2c->cur = &msgs[i];
>>>>> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>>           if (i < num - 1)
>>>>>               peripheral.stretch = 1;
>>>>> +        peripheral.first_msg = (i == 0);
>>>>> +        peripheral.last_msg = (i == num - 1);
>>>>>           peripheral.addr = msgs[i].addr;
>>>>>           ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
>>>>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>>           dma_async_issue_pending(gi2c->tx_c);
>>>>>           time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
>>>>> -        if (!time_left)
>>>>> +        if (!time_left) {
>>>>> +            dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n",
>>>>> +                        gi2c->cur->flags, gi2c->cur->addr);
>>>>>               gi2c->err = -ETIMEDOUT;
>>>>> +        }
>>>>>           if (gi2c->err) {
>>>>>               ret = gi2c->err;
>>>>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device *pdev)
>>>>>           gi2c->clk_freq_out = KHZ(100);
>>>>>       }
>>>>> +    if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
>>>>> +        gi2c->is_shared = true;
>>>>> +        dev_dbg(&pdev->dev, "Shared SE Usecase\n");
>>>>> +    }
>>>>> +
>>>>>       if (has_acpi_companion(dev))
>>>>>           ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>>>>> @@ -962,14 +975,16 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev)
>>>>>       struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>>>>>       disable_irq(gi2c->irq);
>>>>> -    ret = geni_se_resources_off(&gi2c->se);
>>>>> -    if (ret) {
>>>>> -        enable_irq(gi2c->irq);
>>>>> -        return ret;
>>>>> -
>>>>> +    if (gi2c->is_shared) {
>>>>> +        geni_se_clks_off(&gi2c->se);
>>>>>       } else {
>>>>> -        gi2c->suspended = 1;
>>>>> +        ret = geni_se_resources_off(&gi2c->se);
>>>>> +        if (ret) {
>>>>> +            enable_irq(gi2c->irq);
>>>>> +            return ret;
>>>>> +        }
>>>>>       }
>>>>> +    gi2c->suspended = 1;
>>>>>       clk_disable_unprepare(gi2c->core_clk);
>>>>
>>>>
>>
>>
Mukesh Kumar Savaliya Sept. 10, 2024, 1:39 p.m. UTC | #11
Hi Andi,

On 9/9/2024 6:23 PM, Andi Shyti wrote:
> Thank you guys for your reviews,
> 
> On Mon, Sep 09, 2024 at 01:37:00PM GMT, Konrad Dybcio wrote:
>> On 9.09.2024 11:18 AM, Mukesh Kumar Savaliya wrote:
>>> Hi Neil,
>>>
>>> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>>>> Hi,
>>>>
>>>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>>>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
>>>>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>>>>> usecase requires i2c controller to be shared.
>>>>>
>>>>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>>>>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
>>>>> access from other EE or Subsystem.
>>>>>
>>>>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>>>>> Unlock TRE for the respective transfer operations.
>>>>>
>>>>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>>>>> touch GPIO configuration during runtime suspend and only turn off the
>>>>> clocks. This will allow other SS to continue to transfer the data
>>>>> without any disturbance over the IO lines.
>>>>
>>>> This doesn't answer my question about what would be the behavior if one
>>>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or SE DMA ?
>>>>
>>> Shared usecase is not supported for non GSI mode (FIFO and DMA), it should be static usecase. Dynamic sharing from two clients of two subsystems is only for GSI mode. Hope this helps ?
>>
>> This should very much be explained in commit message and perhaps in code
>>
>> And since it can't work with FIFO mode, there should be checks in code
>> to disallow such invalid configurations
> 
> it would be nice if, along with all these open questions and
> clarifications on the commit message, we could add some good
> comments to the code as well.
> 
Agree, i realized it's good to add comment around code changes too.
In V3 i am incorporating all the suggestions and comments.
> Thanks,
> Andi
Mukesh Kumar Savaliya Sept. 10, 2024, 1:42 p.m. UTC | #12
Hi Andi, Sorry for late reply on this.

On 9/7/2024 1:26 PM, Andi Shyti wrote:
> Hi Mukesh,
> 
> On Sat, Sep 07, 2024 at 12:44:38AM GMT, Mukesh Kumar Savaliya wrote:
>> Add support to share I2C SE by two Subsystems in a mutually exclusive way.
>> Use  "qcom,shared-se" flag in a particular i2c instance node if the
>> usecase requires i2c controller to be shared.
>>
>> I2C driver just need to mark first_msg and last_msg flag to help indicate
>> GPI driver to  take lock and unlock TRE there by protecting from concurrent
>> access from other EE or Subsystem.
>>
>> gpi_create_i2c_tre() function at gpi.c will take care of adding Lock and
>> Unlock TRE for the respective transfer operations.
>>
>> Since the GPIOs are also shared for the i2c bus between two SS, do not
>> touch GPIO configuration during runtime suspend and only turn off the
>> clocks. This will allow other SS to continue to transfer the data
>> without any disturbance over the IO lines.
> 
> if I remember correctly, someone already commented on your
> patches to explain and expand the achronyms you are using. Please
> improve the commit log so that people who don't know this device
> can understand.
> 
Sure, Andi. Noted and addressed over comment. Will add full form for the 
acronyms.
> ...
> 
>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>   		dma_async_issue_pending(gi2c->tx_c);
>>   
>>   		time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
>> -		if (!time_left)
>> +		if (!time_left) {
>> +			dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n",
>> +						gi2c->cur->flags, gi2c->cur->addr);
> 
> Please, don't print out here. The user doesn't really need to
> know, let the upper levels decide what to do.
Sure, can remove this completely and user can handle , print it.

> 
>>   			gi2c->err = -ETIMEDOUT;
>> +		}
>>   
>>   		if (gi2c->err) {
>>   			ret = gi2c->err;
>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct platform_device *pdev)
>>   		gi2c->clk_freq_out = KHZ(100);
>>   	}
>>   
>> +	if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
>> +		gi2c->is_shared = true;
>> +		dev_dbg(&pdev->dev, "Shared SE Usecase\n");
> 
> Please, improve this debug message.
> 
"I2C is shared between subsystems" ?
> The rest looks good to me.
> 
> Thanks,
> Andi
Mukesh Kumar Savaliya Sept. 18, 2024, 12:20 p.m. UTC | #13
Thanks Neil for the review !

On 9/10/2024 3:22 PM, neil.armstrong@linaro.org wrote:
> On 10/09/2024 11:15, Mukesh Kumar Savaliya wrote:
>> Hi Neil,
>>
>> On 9/9/2024 6:34 PM, neil.armstrong@linaro.org wrote:
>>> On 09/09/2024 11:18, Mukesh Kumar Savaliya wrote:
>>>> Hi Neil,
>>>>
>>>> On 9/9/2024 2:24 PM, neil.armstrong@linaro.org wrote:
>>>>> Hi,
>>>>>
>>>>> On 06/09/2024 21:14, Mukesh Kumar Savaliya wrote:
>>>>>> Add support to share I2C SE by two Subsystems in a mutually 
>>>>>> exclusive way.
>>>>>> Use  "qcom,shared-se" flag in a particular i2c instance node ifthe
>>>>>> usecase requires i2c controller to be shared.
>>>>>>
>>>>>> I2C driver just need to mark first_msg and last_msg flag to help 
>>>>>> indicate
>>>>>> GPI driver to  take lock and unlock TRE there by protecting from 
>>>>>> concurrent
>>>>>> access from other EE or Subsystem.
>>>>>>
>>>>>> gpi_create_i2c_tre() function at gpi.c will take care of adding 
>>>>>> Lock and
>>>>>> Unlock TRE for the respective transfer operations.
>>>>>>
>>>>>> Since the GPIOs are also shared for the i2c bus between two SS, do 
>>>>>> not
>>>>>> touch GPIO configuration during runtime suspend and only turn off the
>>>>>> clocks. This will allow other SS to continue to transfer the data
>>>>>> without any disturbance over the IO lines.
>>>>>
>>>>> This doesn't answer my question about what would be the behavior if 
>>>>> one
>>>>> use uses, for example, GPI DMA, and the Linux kernel FIFO mode or 
>>>>> SE DMA ?
>>>>>
>>>> Shared usecase is not supported for non GSI mode (FIFO and DMA), it 
>>>> should be static usecase. Dynamic sharing from two clients of two 
>>>> subsystems is only for GSI mode. Hope this helps ?
>>>
>>> Sure, this is why I proposed on v1 cover letter reply to add:
>> Sure, i will add in cover letter and code check combining with 
>> fifo_disable check.
>>> ==============><=====================================================================
>>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
>>> b/drivers/i2c/busses/i2c-qcom-geni.c
>>> index ee2e431601a6..a15825ea56de 100644
>>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>>> @@ -885,7 +885,7 @@ static int geni_i2c_probe(struct platform_device 
>>> *pdev)
>>>           else
>>>                   fifo_disable = readl_relaxed(gi2c->se.base + 
>>> GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE;
>>>
>>> -       if (fifo_disable) {
>>> +       if (gi2c->is_shared || fifo_disable) {
>>   Should be ANDING logically, as we need to combine both check. Shared
>>   usecase possible only for fifo_disable.
> 
> Could you elaborate on that ? GPI DMA is totally usable even if FIFO is 
> enabled,
> it's a decision took in the driver to _not_ use GPI when FIFO is enabled.
> 
Yes, Neil, you are right. Its actually reverse condition from HW 
configuration.

if fifo_disable = true, then FIFO registers will not be accessible, 
meaning its GPI mode only. And SW should decide use GPI DMA mode only.

if fifo_disable = false, it can still use GPI DMA/CPU_DMA. we need to 
restrict from SW side.

Provided above, i suggest to keep conditional check with ANDING.
We want only GSI mode to be supported with shared SE. Because GSI mode 
only has GPII channel allocated to each EE. if not, then it will be 
misused between EEs and no way to prevent concurrency at HW level.(E.g. 
we use lock/unlock in GSI mode)

If so, hope you agree with the conditional check of ANDing both flags?
> Neil
> 
>>
>>   if(gi2c->is_shared && fifo_disable) {
>>>                   /* FIFO is disabled, so we can only use GPI DMA */
>>>                   gi2c->gpi_mode = true;
>>>                   ret = setup_gpi_dma(gi2c);
>>> ==============><=====================================================================
>>>
>>> Thanks,
>>> Neil
>>>
>>>>> Because it seems to "fix" only the GPI DMA shared case.
>>>>>
>>>>> Neil
>>>>>
>>>>>>
>>>>>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
>>>>>> ---
>>>>>>   drivers/i2c/busses/i2c-qcom-geni.c | 29 
>>>>>> ++++++++++++++++++++++-------
>>>>>>   1 file changed, 22 insertions(+), 7 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c 
>>>>>> b/drivers/i2c/busses/i2c-qcom-geni.c
>>>>>> index eebb0cbb6ca4..ee2e431601a6 100644
>>>>>> --- a/drivers/i2c/busses/i2c-qcom-geni.c
>>>>>> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
>>>>>> @@ -1,5 +1,6 @@
>>>>>>   // SPDX-License-Identifier: GPL-2.0
>>>>>>   // Copyright (c) 2017-2018, The Linux Foundation. All rights 
>>>>>> reserved.
>>>>>> +// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights 
>>>>>> reserved.
>>>>>>   #include <linux/acpi.h>
>>>>>>   #include <linux/clk.h>
>>>>>> @@ -99,6 +100,7 @@ struct geni_i2c_dev {
>>>>>>       struct dma_chan *rx_c;
>>>>>>       bool gpi_mode;
>>>>>>       bool abort_done;
>>>>>> +    bool is_shared;
>>>>>>   };
>>>>>>   struct geni_i2c_desc {
>>>>>> @@ -602,6 +604,7 @@ static int geni_i2c_gpi_xfer(struct 
>>>>>> geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>>>       peripheral.clk_div = itr->clk_div;
>>>>>>       peripheral.set_config = 1;
>>>>>>       peripheral.multi_msg = false;
>>>>>> +    peripheral.shared_se = gi2c->is_shared;
>>>>>>       for (i = 0; i < num; i++) {
>>>>>>           gi2c->cur =&msgs[i];
>>>>>> @@ -612,6 +615,8 @@ static int geni_i2c_gpi_xfer(struct 
>>>>>> geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>>>           if (i < num -1)
>>>>>>               peripheral.stretch = 1;
>>>>>> +        peripheral.first_msg =(i == 0);
>>>>>> +        peripheral.last_msg = (i == num - 1);
>>>>>>           peripheral.addr = msgs[i].addr;
>>>>>>           ret = geni_i2c_gpi(gi2c, &msgs[i], &config,
>>>>>> @@ -631,8 +636,11 @@ static int geni_i2c_gpi_xfer(struct 
>>>>>> geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
>>>>>>           dma_async_issue_pending(gi2c->tx_c);
>>>>>>           time_left =wait_for_completion_timeout(&gi2c->done, 
>>>>>> XFER_TIMEOUT);
>>>>>> -        if (!time_left)
>>>>>> +        if (!time_left) {
>>>>>> +            dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d 
>>>>>> addr:0x%x\n",
>>>>>> +                        gi2c->cur->flags, gi2c->cur->addr);
>>>>>>               gi2c->err = -ETIMEDOUT;
>>>>>> +        }
>>>>>>           if (gi2c->err) {
>>>>>>               ret = gi2c->err;
>>>>>> @@ -800,6 +808,11 @@ static int geni_i2c_probe(struct 
>>>>>> platform_device *pdev)
>>>>>>           gi2c->clk_freq_out = KHZ(100);
>>>>>>       }
>>>>>> +    if (of_property_read_bool(pdev->dev.of_node, 
>>>>>> "qcom,shared-se")) {
>>>>>> +        gi2c->is_shared = true;
>>>>>> +        dev_dbg(&pdev->dev, "Shared SE Usecase\n");
>>>>>> +    }
>>>>>> +
>>>>>>       if (has_acpi_companion(dev))
>>>>>>           ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
>>>>>> @@ -962,14 +975,16 @@ static int __maybe_unused 
>>>>>> geni_i2c_runtime_suspend(struct device *dev)
>>>>>>       struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
>>>>>>       disable_irq(gi2c->irq);
>>>>>> -    ret = geni_se_resources_off(&gi2c->se);
>>>>>> -    if (ret) {
>>>>>> -        enable_irq(gi2c->irq);
>>>>>> -        return ret;
>>>>>> -
>>>>>> +    if (gi2c->is_shared) {
>>>>>> +        geni_se_clks_off(&gi2c->se);
>>>>>>       } else {
>>>>>> -        gi2c->suspended = 1;
>>>>>> +        ret = geni_se_resources_off(&gi2c->se);
>>>>>> +        if (ret) {
>>>>>> +            enable_irq(gi2c->irq);
>>>>>> +            return ret;
>>>>>> +        }
>>>>>>       }
>>>>>> +    gi2c->suspended = 1;
>>>>>>       clk_disable_unprepare(gi2c->core_clk);
>>>>>
>>>>>
>>>
>>>
>
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index eebb0cbb6ca4..ee2e431601a6 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -1,5 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+// Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
 
 #include <linux/acpi.h>
 #include <linux/clk.h>
@@ -99,6 +100,7 @@  struct geni_i2c_dev {
 	struct dma_chan *rx_c;
 	bool gpi_mode;
 	bool abort_done;
+	bool is_shared;
 };
 
 struct geni_i2c_desc {
@@ -602,6 +604,7 @@  static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
 	peripheral.clk_div = itr->clk_div;
 	peripheral.set_config = 1;
 	peripheral.multi_msg = false;
+	peripheral.shared_se = gi2c->is_shared;
 
 	for (i = 0; i < num; i++) {
 		gi2c->cur = &msgs[i];
@@ -612,6 +615,8 @@  static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
 		if (i < num - 1)
 			peripheral.stretch = 1;
 
+		peripheral.first_msg = (i == 0);
+		peripheral.last_msg = (i == num - 1);
 		peripheral.addr = msgs[i].addr;
 
 		ret =  geni_i2c_gpi(gi2c, &msgs[i], &config,
@@ -631,8 +636,11 @@  static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i
 		dma_async_issue_pending(gi2c->tx_c);
 
 		time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
-		if (!time_left)
+		if (!time_left) {
+			dev_err(gi2c->se.dev, "I2C timeout gpi flags:%d addr:0x%x\n",
+						gi2c->cur->flags, gi2c->cur->addr);
 			gi2c->err = -ETIMEDOUT;
+		}
 
 		if (gi2c->err) {
 			ret = gi2c->err;
@@ -800,6 +808,11 @@  static int geni_i2c_probe(struct platform_device *pdev)
 		gi2c->clk_freq_out = KHZ(100);
 	}
 
+	if (of_property_read_bool(pdev->dev.of_node, "qcom,shared-se")) {
+		gi2c->is_shared = true;
+		dev_dbg(&pdev->dev, "Shared SE Usecase\n");
+	}
+
 	if (has_acpi_companion(dev))
 		ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
 
@@ -962,14 +975,16 @@  static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev)
 	struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
 
 	disable_irq(gi2c->irq);
-	ret = geni_se_resources_off(&gi2c->se);
-	if (ret) {
-		enable_irq(gi2c->irq);
-		return ret;
-
+	if (gi2c->is_shared) {
+		geni_se_clks_off(&gi2c->se);
 	} else {
-		gi2c->suspended = 1;
+		ret = geni_se_resources_off(&gi2c->se);
+		if (ret) {
+			enable_irq(gi2c->irq);
+			return ret;
+		}
 	}
+	gi2c->suspended = 1;
 
 	clk_disable_unprepare(gi2c->core_clk);