linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel()
@ 2019-12-17 10:52 Peter Ujfalusi
  2019-12-20  8:54 ` Fabrice Gasnier
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Ujfalusi @ 2019-12-17 10:52 UTC (permalink / raw)
  To: fabrice.gasnier, lee.jones, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-stm32, linux-arm-kernel, linux-kernel

dma_request_slave_channel() is a wrapper on top of dma_request_chan()
eating up the error code.

By using dma_request_chan() directly the driver can support deferred
probing against DMA.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 drivers/mfd/stm32-timers.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
index efcd4b980c94..34747e8a4a40 100644
--- a/drivers/mfd/stm32-timers.c
+++ b/drivers/mfd/stm32-timers.c
@@ -167,10 +167,11 @@ static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
 	regmap_write(ddata->regmap, TIM_ARR, 0x0);
 }
 
-static void stm32_timers_dma_probe(struct device *dev,
+static int stm32_timers_dma_probe(struct device *dev,
 				   struct stm32_timers *ddata)
 {
 	int i;
+	int ret = 0;
 	char name[4];
 
 	init_completion(&ddata->dma.completion);
@@ -179,14 +180,22 @@ static void stm32_timers_dma_probe(struct device *dev,
 	/* Optional DMA support: get valid DMA channel(s) or NULL */
 	for (i = STM32_TIMERS_DMA_CH1; i <= STM32_TIMERS_DMA_CH4; i++) {
 		snprintf(name, ARRAY_SIZE(name), "ch%1d", i + 1);
-		ddata->dma.chans[i] = dma_request_slave_channel(dev, name);
+		ddata->dma.chans[i] = dma_request_chan(dev, name);
 	}
-	ddata->dma.chans[STM32_TIMERS_DMA_UP] =
-		dma_request_slave_channel(dev, "up");
-	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] =
-		dma_request_slave_channel(dev, "trig");
-	ddata->dma.chans[STM32_TIMERS_DMA_COM] =
-		dma_request_slave_channel(dev, "com");
+	ddata->dma.chans[STM32_TIMERS_DMA_UP] = dma_request_chan(dev, "up");
+	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] = dma_request_chan(dev, "trig");
+	ddata->dma.chans[STM32_TIMERS_DMA_COM] = dma_request_chan(dev, "com");
+
+	for (i = STM32_TIMERS_DMA_CH1; i < STM32_TIMERS_MAX_DMAS; i++) {
+		if (IS_ERR(ddata->dma.chans[i])) {
+			if (PTR_ERR(ddata->dma.chans[i]) == -EPROBE_DEFER)
+				ret = -EPROBE_DEFER;
+
+			ddata->dma.chans[i] = NULL;
+		}
+	}
+
+	return ret;
 }
 
 static void stm32_timers_dma_remove(struct device *dev,
@@ -230,7 +239,11 @@ static int stm32_timers_probe(struct platform_device *pdev)
 
 	stm32_timers_get_arr_size(ddata);
 
-	stm32_timers_dma_probe(dev, ddata);
+	ret = stm32_timers_dma_probe(dev, ddata);
+	if (ret) {
+		stm32_timers_dma_remove(dev, ddata);
+		return ret;
+	}
 
 	platform_set_drvdata(pdev, ddata);
 
-- 
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel()
  2019-12-17 10:52 [PATCH] mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
@ 2019-12-20  8:54 ` Fabrice Gasnier
  2019-12-20 11:36   ` Peter Ujfalusi
  0 siblings, 1 reply; 4+ messages in thread
From: Fabrice Gasnier @ 2019-12-20  8:54 UTC (permalink / raw)
  To: Peter Ujfalusi, lee.jones, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-stm32, linux-arm-kernel, linux-kernel, Benjamin GAIGNARD

On 12/17/19 11:52 AM, Peter Ujfalusi wrote:
> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
> eating up the error code.
> 
> By using dma_request_chan() directly the driver can support deferred
> probing against DMA.
> 
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> ---
>  drivers/mfd/stm32-timers.c | 31 ++++++++++++++++++++++---------
>  1 file changed, 22 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
> index efcd4b980c94..34747e8a4a40 100644
> --- a/drivers/mfd/stm32-timers.c
> +++ b/drivers/mfd/stm32-timers.c
> @@ -167,10 +167,11 @@ static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
>  	regmap_write(ddata->regmap, TIM_ARR, 0x0);
>  }
>  
> -static void stm32_timers_dma_probe(struct device *dev,
> +static int stm32_timers_dma_probe(struct device *dev,
>  				   struct stm32_timers *ddata)
>  {
>  	int i;
> +	int ret = 0;
>  	char name[4];
>  
>  	init_completion(&ddata->dma.completion);
> @@ -179,14 +180,22 @@ static void stm32_timers_dma_probe(struct device *dev,
>  	/* Optional DMA support: get valid DMA channel(s) or NULL */
>  	for (i = STM32_TIMERS_DMA_CH1; i <= STM32_TIMERS_DMA_CH4; i++) {
>  		snprintf(name, ARRAY_SIZE(name), "ch%1d", i + 1);
> -		ddata->dma.chans[i] = dma_request_slave_channel(dev, name);
> +		ddata->dma.chans[i] = dma_request_chan(dev, name);
>  	}
> -	ddata->dma.chans[STM32_TIMERS_DMA_UP] =
> -		dma_request_slave_channel(dev, "up");
> -	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] =
> -		dma_request_slave_channel(dev, "trig");
> -	ddata->dma.chans[STM32_TIMERS_DMA_COM] =
> -		dma_request_slave_channel(dev, "com");
> +	ddata->dma.chans[STM32_TIMERS_DMA_UP] = dma_request_chan(dev, "up");
> +	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] = dma_request_chan(dev, "trig");
> +	ddata->dma.chans[STM32_TIMERS_DMA_COM] = dma_request_chan(dev, "com");
> +
> +	for (i = STM32_TIMERS_DMA_CH1; i < STM32_TIMERS_MAX_DMAS; i++) {
> +		if (IS_ERR(ddata->dma.chans[i])) {
> +			if (PTR_ERR(ddata->dma.chans[i]) == -EPROBE_DEFER)> +				ret = -EPROBE_DEFER;

Hi Peter,

Thanks for the patch,

As the DMA is optional, I'd rather prefer to check explicitly there's no
device, and return any other error case, basically:

			if (PTR_ERR(ddata->dma.chans[i]) != -ENODEV)
				return PTR_ERR(ddata->dma.chans[i]);

> +
> +			ddata->dma.chans[i] = NULL;
> +		}
> +	}
> +
> +	return ret;

With that, return 0 here.

>  }
>  
>  static void stm32_timers_dma_remove(struct device *dev,
> @@ -230,7 +239,11 @@ static int stm32_timers_probe(struct platform_device *pdev)
>  
>  	stm32_timers_get_arr_size(ddata);
>  
> -	stm32_timers_dma_probe(dev, ddata);
> +	ret = stm32_timers_dma_probe(dev, ddata);
> +	if (ret) {
> +		stm32_timers_dma_remove(dev, ddata);

With that, stm32_timers_dma_remove() likely need to be updated:

-		if (ddata->dma.chans[i])
+		if (!IS_ERR_OR_NULL(ddata->dma.chans[i]))
			dma_release_channel(ddata->dma.chans[i]);

Best regards,
Fabrice

> +		return ret;
> +	}
>  
>  	platform_set_drvdata(pdev, ddata);
>  
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel()
  2019-12-20  8:54 ` Fabrice Gasnier
@ 2019-12-20 11:36   ` Peter Ujfalusi
  2020-01-06 14:57     ` Fabrice Gasnier
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Ujfalusi @ 2019-12-20 11:36 UTC (permalink / raw)
  To: Fabrice Gasnier, lee.jones, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-stm32, linux-arm-kernel, linux-kernel, Benjamin GAIGNARD

Hi Fabrice,

On 20/12/2019 10.54, Fabrice Gasnier wrote:
> On 12/17/19 11:52 AM, Peter Ujfalusi wrote:
>> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
>> eating up the error code.
>>
>> By using dma_request_chan() directly the driver can support deferred
>> probing against DMA.
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>> ---
>>  drivers/mfd/stm32-timers.c | 31 ++++++++++++++++++++++---------
>>  1 file changed, 22 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
>> index efcd4b980c94..34747e8a4a40 100644
>> --- a/drivers/mfd/stm32-timers.c
>> +++ b/drivers/mfd/stm32-timers.c
>> @@ -167,10 +167,11 @@ static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
>>  	regmap_write(ddata->regmap, TIM_ARR, 0x0);
>>  }
>>  
>> -static void stm32_timers_dma_probe(struct device *dev,
>> +static int stm32_timers_dma_probe(struct device *dev,
>>  				   struct stm32_timers *ddata)
>>  {
>>  	int i;
>> +	int ret = 0;
>>  	char name[4];
>>  
>>  	init_completion(&ddata->dma.completion);
>> @@ -179,14 +180,22 @@ static void stm32_timers_dma_probe(struct device *dev,
>>  	/* Optional DMA support: get valid DMA channel(s) or NULL */
>>  	for (i = STM32_TIMERS_DMA_CH1; i <= STM32_TIMERS_DMA_CH4; i++) {
>>  		snprintf(name, ARRAY_SIZE(name), "ch%1d", i + 1);
>> -		ddata->dma.chans[i] = dma_request_slave_channel(dev, name);
>> +		ddata->dma.chans[i] = dma_request_chan(dev, name);
>>  	}
>> -	ddata->dma.chans[STM32_TIMERS_DMA_UP] =
>> -		dma_request_slave_channel(dev, "up");
>> -	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] =
>> -		dma_request_slave_channel(dev, "trig");
>> -	ddata->dma.chans[STM32_TIMERS_DMA_COM] =
>> -		dma_request_slave_channel(dev, "com");
>> +	ddata->dma.chans[STM32_TIMERS_DMA_UP] = dma_request_chan(dev, "up");
>> +	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] = dma_request_chan(dev, "trig");
>> +	ddata->dma.chans[STM32_TIMERS_DMA_COM] = dma_request_chan(dev, "com");
>> +
>> +	for (i = STM32_TIMERS_DMA_CH1; i < STM32_TIMERS_MAX_DMAS; i++) {
>> +		if (IS_ERR(ddata->dma.chans[i])) {
>> +			if (PTR_ERR(ddata->dma.chans[i]) == -EPROBE_DEFER)> +				ret = -EPROBE_DEFER;
> 
> Hi Peter,
> 
> Thanks for the patch,
> 
> As the DMA is optional, I'd rather prefer to check explicitly there's no
> device, and return any other error case, basically:
> 
> 			if (PTR_ERR(ddata->dma.chans[i]) != -ENODEV)
> 				return PTR_ERR(ddata->dma.chans[i]);

My intention was to specifically pick and handle EPROBE_DEFER while not
changing how the driver handles other errors, whether it because there
is no DMA channel specified or there is a failure to get the channel.

But if you prefer to ignore only ENODEV and report other errors then I
can send v2.
It could expose otherwise ignored configuration error (from DT?) and the
change in the driver will be blamed for the regression.

Would it make sense to add the change you suggested as an iteration on
top of this patch?

> 
>> +
>> +			ddata->dma.chans[i] = NULL;
>> +		}
>> +	}
>> +
>> +	return ret;
> 
> With that, return 0 here.
> 
>>  }
>>  
>>  static void stm32_timers_dma_remove(struct device *dev,
>> @@ -230,7 +239,11 @@ static int stm32_timers_probe(struct platform_device *pdev)
>>  
>>  	stm32_timers_get_arr_size(ddata);
>>  
>> -	stm32_timers_dma_probe(dev, ddata);
>> +	ret = stm32_timers_dma_probe(dev, ddata);
>> +	if (ret) {
>> +		stm32_timers_dma_remove(dev, ddata);
> 
> With that, stm32_timers_dma_remove() likely need to be updated:
> 
> -		if (ddata->dma.chans[i])
> +		if (!IS_ERR_OR_NULL(ddata->dma.chans[i]))
> 			dma_release_channel(ddata->dma.chans[i]);
> 
> Best regards,
> Fabrice
> 
>> +		return ret;
>> +	}
>>  
>>  	platform_set_drvdata(pdev, ddata);
>>  
>>

Kind regards,
- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel()
  2019-12-20 11:36   ` Peter Ujfalusi
@ 2020-01-06 14:57     ` Fabrice Gasnier
  0 siblings, 0 replies; 4+ messages in thread
From: Fabrice Gasnier @ 2020-01-06 14:57 UTC (permalink / raw)
  To: Peter Ujfalusi, lee.jones, mcoquelin.stm32, alexandre.torgue
  Cc: vkoul, linux-stm32, linux-arm-kernel, linux-kernel, Benjamin GAIGNARD

On 12/20/19 12:36 PM, Peter Ujfalusi wrote:
> Hi Fabrice,
> 
> On 20/12/2019 10.54, Fabrice Gasnier wrote:
>> On 12/17/19 11:52 AM, Peter Ujfalusi wrote:
>>> dma_request_slave_channel() is a wrapper on top of dma_request_chan()
>>> eating up the error code.
>>>
>>> By using dma_request_chan() directly the driver can support deferred
>>> probing against DMA.
>>>
>>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
>>> ---
>>>  drivers/mfd/stm32-timers.c | 31 ++++++++++++++++++++++---------
>>>  1 file changed, 22 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
>>> index efcd4b980c94..34747e8a4a40 100644
>>> --- a/drivers/mfd/stm32-timers.c
>>> +++ b/drivers/mfd/stm32-timers.c
>>> @@ -167,10 +167,11 @@ static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
>>>  	regmap_write(ddata->regmap, TIM_ARR, 0x0);
>>>  }
>>>  
>>> -static void stm32_timers_dma_probe(struct device *dev,
>>> +static int stm32_timers_dma_probe(struct device *dev,
>>>  				   struct stm32_timers *ddata)
>>>  {
>>>  	int i;
>>> +	int ret = 0;
>>>  	char name[4];
>>>  
>>>  	init_completion(&ddata->dma.completion);
>>> @@ -179,14 +180,22 @@ static void stm32_timers_dma_probe(struct device *dev,
>>>  	/* Optional DMA support: get valid DMA channel(s) or NULL */
>>>  	for (i = STM32_TIMERS_DMA_CH1; i <= STM32_TIMERS_DMA_CH4; i++) {
>>>  		snprintf(name, ARRAY_SIZE(name), "ch%1d", i + 1);
>>> -		ddata->dma.chans[i] = dma_request_slave_channel(dev, name);
>>> +		ddata->dma.chans[i] = dma_request_chan(dev, name);
>>>  	}
>>> -	ddata->dma.chans[STM32_TIMERS_DMA_UP] =
>>> -		dma_request_slave_channel(dev, "up");
>>> -	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] =
>>> -		dma_request_slave_channel(dev, "trig");
>>> -	ddata->dma.chans[STM32_TIMERS_DMA_COM] =
>>> -		dma_request_slave_channel(dev, "com");
>>> +	ddata->dma.chans[STM32_TIMERS_DMA_UP] = dma_request_chan(dev, "up");
>>> +	ddata->dma.chans[STM32_TIMERS_DMA_TRIG] = dma_request_chan(dev, "trig");
>>> +	ddata->dma.chans[STM32_TIMERS_DMA_COM] = dma_request_chan(dev, "com");
>>> +
>>> +	for (i = STM32_TIMERS_DMA_CH1; i < STM32_TIMERS_MAX_DMAS; i++) {
>>> +		if (IS_ERR(ddata->dma.chans[i])) {
>>> +			if (PTR_ERR(ddata->dma.chans[i]) == -EPROBE_DEFER)> +				ret = -EPROBE_DEFER;
>>
>> Hi Peter,
>>
>> Thanks for the patch,
>>
>> As the DMA is optional, I'd rather prefer to check explicitly there's no
>> device, and return any other error case, basically:
>>
>> 			if (PTR_ERR(ddata->dma.chans[i]) != -ENODEV)
>> 				return PTR_ERR(ddata->dma.chans[i]);
> 
> My intention was to specifically pick and handle EPROBE_DEFER while not
> changing how the driver handles other errors, whether it because there
> is no DMA channel specified or there is a failure to get the channel.
> 
> But if you prefer to ignore only ENODEV and report other errors then I
> can send v2.

Hi Peter,

Sorry for the late answer.

Yes, I'd prefer this please, not to hide other error case (as detailed
in other thread: https://lkml.org/lkml/2020/1/6/209). The only expected
"normal" error here is -ENODEV, as the DMA is optional.

> It could expose otherwise ignored configuration error (from DT?) and the
> change in the driver will be blamed for the regression.

I can do some testing at my end if needed, but I don't expect regression
here.

Thanks,
Fabrice

> 
> Would it make sense to add the change you suggested as an iteration on
> top of this patch?
> 
>>
>>> +
>>> +			ddata->dma.chans[i] = NULL;
>>> +		}
>>> +	}
>>> +
>>> +	return ret;
>>
>> With that, return 0 here.
>>
>>>  }
>>>  
>>>  static void stm32_timers_dma_remove(struct device *dev,
>>> @@ -230,7 +239,11 @@ static int stm32_timers_probe(struct platform_device *pdev)
>>>  
>>>  	stm32_timers_get_arr_size(ddata);
>>>  
>>> -	stm32_timers_dma_probe(dev, ddata);
>>> +	ret = stm32_timers_dma_probe(dev, ddata);
>>> +	if (ret) {
>>> +		stm32_timers_dma_remove(dev, ddata);
>>
>> With that, stm32_timers_dma_remove() likely need to be updated:
>>
>> -		if (ddata->dma.chans[i])
>> +		if (!IS_ERR_OR_NULL(ddata->dma.chans[i]))
>> 			dma_release_channel(ddata->dma.chans[i]);
>>
>> Best regards,
>> Fabrice
>>
>>> +		return ret;
>>> +	}
>>>  
>>>  	platform_set_drvdata(pdev, ddata);
>>>  
>>>
> 
> Kind regards,
> - Péter
> 
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-06 14:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17 10:52 [PATCH] mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel() Peter Ujfalusi
2019-12-20  8:54 ` Fabrice Gasnier
2019-12-20 11:36   ` Peter Ujfalusi
2020-01-06 14:57     ` Fabrice Gasnier

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).