Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-05-02 Thread Fabrice Gasnier
On 04/30/2017 07:07 PM, Jonathan Cameron wrote:
> On 28/04/17 15:52, Fabrice Gasnier wrote:
>> On 04/27/2017 07:49 AM, Jonathan Cameron wrote:
>>> On 26/04/17 09:55, Benjamin Gaignard wrote:
 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
> Add support for TRGO2 trigger that can be found on STM32F7.
> Add additional master modes supported by TRGO2.
>>> These additional modes would benefit from more information in the
>>> ABI docs.  Otherwise patch seems fine, though this may win
>>> the award for hardest hardware to come up with a generic
>>> interface for... 
> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
> Detect TRGO2 timer capability (master mode selection 2).
>
> Signed-off-by: Fabrice Gasnier 
> ---
>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
> ++---
>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>  include/linux/mfd/stm32-timers.h   |   2 +
>  4 files changed, 118 insertions(+), 14 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> index 230020e..47647b4 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> @@ -16,6 +16,21 @@ Description:
> - "OC2REF": OC2REF signal is used as trigger output.
> - "OC3REF": OC3REF signal is used as trigger output.
> - "OC4REF": OC4REF signal is used as trigger output.
> +   Additional modes (on TRGO2 only):
> +   - "OC5REF": OC5REF signal is used as trigger output.
> +   - "OC6REF": OC6REF signal is used as trigger output.
> +   - "compare_pulse_OC4REF":
> + OC4REF rising or falling edges generate pulses.
>>> I'd like this to be fairly understandable without resorting to reading the
>>> datasheet.  As I understand it you get a fixed term pulse on both edges
>>> of the waveform?  Perhaps this calls for some ascii art :)
>>
>> Hi Jonathan,
>>
>> If you feel like it needs more documentation, I'd rather prefer to add
>> reference or link to the datasheet... That will be more accurate,
>> up-to-date (e.g. like RM0385 pdf). Does this sound ok ? Or...
> Datasheet is good, but give it 10 years and chances are it will disappear
> into a black hole, whereas the hardware might still be in use by someone.
> Some of the hardware I use is at least that old. Frankly this laptop is
> getting close ;)
>>
>> Just in case, I prepared some ascii art, hope it clarify things.
>> I'm wondering if this is best place to put it ?
>> Shouldn't this be added in source code, instead of ABI Doc ?
> Could be either, but arguably the ABI docs should be all that a
> userspace developer should need to see.  This isn't an internal
> detail afterall.
>> Maybe I can skip 1st part of it, heading boxes? (only example is enough?
>> or not...)
>>
>> +---+   +-++-+
>> | Prescaler +-> | Counter |+-> | Master  | TRGO(2)
>> +---+   +--++-+|-> | Control +-->
>>||  ||  +-+
>> +--v+-+ OCxREF ||  +-+
>> | Chx compare +--> | Output  | ChX
>> +---+-+ |  | Control +-->
>>   . |   |  +-+
>>   . |   |.
>> +---v-+ OC6REF  |.
>> | Ch6 compare +-+>
>> +-+
>>
>> Example with: "compare_pulse_OC4REF_r_or_OC6REF_r":
>>
>> X
>>   X   X
>> X .   . X
>>   X   .   .   X
>> X .   . X
>> count X . .   . . X
>> . .   . .
>> . .   . .
>> +---+
>> OC4REF  | .   . |
>>   +-+ .   . +-+
>> . +---+ .
>> OC6REF  . |   | .
>>   +---+   +---+
>> +-+   +-+
>> TRGO2   | |   | |
>>   +-+ +---+ +-+
> This is good stuff so I'd put it in the ABI docs.
> 
Hi Jonathan,

Thanks, I just sent a v2 that includes this.

Best Regards,
Fabrice

> Jonathan
>>
>>
>> side note: this isn't my house ;-)
> :)
>>
>> Please advise,
>> Thanks,
>> Fabrice
>>
>>
> +   - "compare_pulse_OC6REF":
> + OC6REF rising or falling edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
> + OC4REF or OC6REF rising edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
> + OC4REF rising or 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-05-02 Thread Fabrice Gasnier
On 04/30/2017 07:07 PM, Jonathan Cameron wrote:
> On 28/04/17 15:52, Fabrice Gasnier wrote:
>> On 04/27/2017 07:49 AM, Jonathan Cameron wrote:
>>> On 26/04/17 09:55, Benjamin Gaignard wrote:
 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
> Add support for TRGO2 trigger that can be found on STM32F7.
> Add additional master modes supported by TRGO2.
>>> These additional modes would benefit from more information in the
>>> ABI docs.  Otherwise patch seems fine, though this may win
>>> the award for hardest hardware to come up with a generic
>>> interface for... 
> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
> Detect TRGO2 timer capability (master mode selection 2).
>
> Signed-off-by: Fabrice Gasnier 
> ---
>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
> ++---
>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>  include/linux/mfd/stm32-timers.h   |   2 +
>  4 files changed, 118 insertions(+), 14 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> index 230020e..47647b4 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> @@ -16,6 +16,21 @@ Description:
> - "OC2REF": OC2REF signal is used as trigger output.
> - "OC3REF": OC3REF signal is used as trigger output.
> - "OC4REF": OC4REF signal is used as trigger output.
> +   Additional modes (on TRGO2 only):
> +   - "OC5REF": OC5REF signal is used as trigger output.
> +   - "OC6REF": OC6REF signal is used as trigger output.
> +   - "compare_pulse_OC4REF":
> + OC4REF rising or falling edges generate pulses.
>>> I'd like this to be fairly understandable without resorting to reading the
>>> datasheet.  As I understand it you get a fixed term pulse on both edges
>>> of the waveform?  Perhaps this calls for some ascii art :)
>>
>> Hi Jonathan,
>>
>> If you feel like it needs more documentation, I'd rather prefer to add
>> reference or link to the datasheet... That will be more accurate,
>> up-to-date (e.g. like RM0385 pdf). Does this sound ok ? Or...
> Datasheet is good, but give it 10 years and chances are it will disappear
> into a black hole, whereas the hardware might still be in use by someone.
> Some of the hardware I use is at least that old. Frankly this laptop is
> getting close ;)
>>
>> Just in case, I prepared some ascii art, hope it clarify things.
>> I'm wondering if this is best place to put it ?
>> Shouldn't this be added in source code, instead of ABI Doc ?
> Could be either, but arguably the ABI docs should be all that a
> userspace developer should need to see.  This isn't an internal
> detail afterall.
>> Maybe I can skip 1st part of it, heading boxes? (only example is enough?
>> or not...)
>>
>> +---+   +-++-+
>> | Prescaler +-> | Counter |+-> | Master  | TRGO(2)
>> +---+   +--++-+|-> | Control +-->
>>||  ||  +-+
>> +--v+-+ OCxREF ||  +-+
>> | Chx compare +--> | Output  | ChX
>> +---+-+ |  | Control +-->
>>   . |   |  +-+
>>   . |   |.
>> +---v-+ OC6REF  |.
>> | Ch6 compare +-+>
>> +-+
>>
>> Example with: "compare_pulse_OC4REF_r_or_OC6REF_r":
>>
>> X
>>   X   X
>> X .   . X
>>   X   .   .   X
>> X .   . X
>> count X . .   . . X
>> . .   . .
>> . .   . .
>> +---+
>> OC4REF  | .   . |
>>   +-+ .   . +-+
>> . +---+ .
>> OC6REF  . |   | .
>>   +---+   +---+
>> +-+   +-+
>> TRGO2   | |   | |
>>   +-+ +---+ +-+
> This is good stuff so I'd put it in the ABI docs.
> 
Hi Jonathan,

Thanks, I just sent a v2 that includes this.

Best Regards,
Fabrice

> Jonathan
>>
>>
>> side note: this isn't my house ;-)
> :)
>>
>> Please advise,
>> Thanks,
>> Fabrice
>>
>>
> +   - "compare_pulse_OC6REF":
> + OC6REF rising or falling edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
> + OC4REF or OC6REF rising edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
> + OC4REF rising or OC6REF falling edges generate pulses.
> + 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-30 Thread Jonathan Cameron
On 28/04/17 15:52, Fabrice Gasnier wrote:
> On 04/27/2017 07:49 AM, Jonathan Cameron wrote:
>> On 26/04/17 09:55, Benjamin Gaignard wrote:
>>> 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
 Add support for TRGO2 trigger that can be found on STM32F7.
 Add additional master modes supported by TRGO2.
>> These additional modes would benefit from more information in the
>> ABI docs.  Otherwise patch seems fine, though this may win
>> the award for hardest hardware to come up with a generic
>> interface for... 
 Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
 Detect TRGO2 timer capability (master mode selection 2).

 Signed-off-by: Fabrice Gasnier 
 ---
  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
 ++---
  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
  include/linux/mfd/stm32-timers.h   |   2 +
  4 files changed, 118 insertions(+), 14 deletions(-)

 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
 b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
 index 230020e..47647b4 100644
 --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
 +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
 @@ -16,6 +16,21 @@ Description:
 - "OC2REF": OC2REF signal is used as trigger output.
 - "OC3REF": OC3REF signal is used as trigger output.
 - "OC4REF": OC4REF signal is used as trigger output.
 +   Additional modes (on TRGO2 only):
 +   - "OC5REF": OC5REF signal is used as trigger output.
 +   - "OC6REF": OC6REF signal is used as trigger output.
 +   - "compare_pulse_OC4REF":
 + OC4REF rising or falling edges generate pulses.
>> I'd like this to be fairly understandable without resorting to reading the
>> datasheet.  As I understand it you get a fixed term pulse on both edges
>> of the waveform?  Perhaps this calls for some ascii art :)
> 
> Hi Jonathan,
> 
> If you feel like it needs more documentation, I'd rather prefer to add
> reference or link to the datasheet... That will be more accurate,
> up-to-date (e.g. like RM0385 pdf). Does this sound ok ? Or...
Datasheet is good, but give it 10 years and chances are it will disappear
into a black hole, whereas the hardware might still be in use by someone.
Some of the hardware I use is at least that old. Frankly this laptop is
getting close ;)
> 
> Just in case, I prepared some ascii art, hope it clarify things.
> I'm wondering if this is best place to put it ?
> Shouldn't this be added in source code, instead of ABI Doc ?
Could be either, but arguably the ABI docs should be all that a
userspace developer should need to see.  This isn't an internal
detail afterall.
> Maybe I can skip 1st part of it, heading boxes? (only example is enough?
> or not...)
> 
> +---+   +-++-+
> | Prescaler +-> | Counter |+-> | Master  | TRGO(2)
> +---+   +--++-+|-> | Control +-->
>||  ||  +-+
> +--v+-+ OCxREF ||  +-+
> | Chx compare +--> | Output  | ChX
> +---+-+ |  | Control +-->
>   . |   |  +-+
>   . |   |.
> +---v-+ OC6REF  |.
> | Ch6 compare +-+>
> +-+
> 
> Example with: "compare_pulse_OC4REF_r_or_OC6REF_r":
> 
> X
>   X   X
> X .   . X
>   X   .   .   X
> X .   . X
> count X . .   . . X
> . .   . .
> . .   . .
> +---+
> OC4REF  | .   . |
>   +-+ .   . +-+
> . +---+ .
> OC6REF  . |   | .
>   +---+   +---+
> +-+   +-+
> TRGO2   | |   | |
>   +-+ +---+ +-+
This is good stuff so I'd put it in the ABI docs.

Jonathan
> 
> 
> side note: this isn't my house ;-)
:)
> 
> Please advise,
> Thanks,
> Fabrice
> 
> 
 +   - "compare_pulse_OC6REF":
 + OC6REF rising or falling edges generate pulses.
 +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
 + OC4REF or OC6REF rising edges generate pulses.
 +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
 + OC4REF rising or OC6REF falling edges generate pulses.
 +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
 + OC5REF or OC6REF rising edges generate pulses.
 +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
 +

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-30 Thread Jonathan Cameron
On 28/04/17 15:52, Fabrice Gasnier wrote:
> On 04/27/2017 07:49 AM, Jonathan Cameron wrote:
>> On 26/04/17 09:55, Benjamin Gaignard wrote:
>>> 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
 Add support for TRGO2 trigger that can be found on STM32F7.
 Add additional master modes supported by TRGO2.
>> These additional modes would benefit from more information in the
>> ABI docs.  Otherwise patch seems fine, though this may win
>> the award for hardest hardware to come up with a generic
>> interface for... 
 Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
 Detect TRGO2 timer capability (master mode selection 2).

 Signed-off-by: Fabrice Gasnier 
 ---
  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
 ++---
  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
  include/linux/mfd/stm32-timers.h   |   2 +
  4 files changed, 118 insertions(+), 14 deletions(-)

 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
 b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
 index 230020e..47647b4 100644
 --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
 +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
 @@ -16,6 +16,21 @@ Description:
 - "OC2REF": OC2REF signal is used as trigger output.
 - "OC3REF": OC3REF signal is used as trigger output.
 - "OC4REF": OC4REF signal is used as trigger output.
 +   Additional modes (on TRGO2 only):
 +   - "OC5REF": OC5REF signal is used as trigger output.
 +   - "OC6REF": OC6REF signal is used as trigger output.
 +   - "compare_pulse_OC4REF":
 + OC4REF rising or falling edges generate pulses.
>> I'd like this to be fairly understandable without resorting to reading the
>> datasheet.  As I understand it you get a fixed term pulse on both edges
>> of the waveform?  Perhaps this calls for some ascii art :)
> 
> Hi Jonathan,
> 
> If you feel like it needs more documentation, I'd rather prefer to add
> reference or link to the datasheet... That will be more accurate,
> up-to-date (e.g. like RM0385 pdf). Does this sound ok ? Or...
Datasheet is good, but give it 10 years and chances are it will disappear
into a black hole, whereas the hardware might still be in use by someone.
Some of the hardware I use is at least that old. Frankly this laptop is
getting close ;)
> 
> Just in case, I prepared some ascii art, hope it clarify things.
> I'm wondering if this is best place to put it ?
> Shouldn't this be added in source code, instead of ABI Doc ?
Could be either, but arguably the ABI docs should be all that a
userspace developer should need to see.  This isn't an internal
detail afterall.
> Maybe I can skip 1st part of it, heading boxes? (only example is enough?
> or not...)
> 
> +---+   +-++-+
> | Prescaler +-> | Counter |+-> | Master  | TRGO(2)
> +---+   +--++-+|-> | Control +-->
>||  ||  +-+
> +--v+-+ OCxREF ||  +-+
> | Chx compare +--> | Output  | ChX
> +---+-+ |  | Control +-->
>   . |   |  +-+
>   . |   |.
> +---v-+ OC6REF  |.
> | Ch6 compare +-+>
> +-+
> 
> Example with: "compare_pulse_OC4REF_r_or_OC6REF_r":
> 
> X
>   X   X
> X .   . X
>   X   .   .   X
> X .   . X
> count X . .   . . X
> . .   . .
> . .   . .
> +---+
> OC4REF  | .   . |
>   +-+ .   . +-+
> . +---+ .
> OC6REF  . |   | .
>   +---+   +---+
> +-+   +-+
> TRGO2   | |   | |
>   +-+ +---+ +-+
This is good stuff so I'd put it in the ABI docs.

Jonathan
> 
> 
> side note: this isn't my house ;-)
:)
> 
> Please advise,
> Thanks,
> Fabrice
> 
> 
 +   - "compare_pulse_OC6REF":
 + OC6REF rising or falling edges generate pulses.
 +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
 + OC4REF or OC6REF rising edges generate pulses.
 +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
 + OC4REF rising or OC6REF falling edges generate pulses.
 +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
 + OC5REF or OC6REF rising edges generate pulses.
 +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
 + OC5REF rising or OC6REF falling edges 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-28 Thread Fabrice Gasnier
On 04/27/2017 07:49 AM, Jonathan Cameron wrote:
> On 26/04/17 09:55, Benjamin Gaignard wrote:
>> 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
>>> Add support for TRGO2 trigger that can be found on STM32F7.
>>> Add additional master modes supported by TRGO2.
> These additional modes would benefit from more information in the
> ABI docs.  Otherwise patch seems fine, though this may win
> the award for hardest hardware to come up with a generic
> interface for... 
>>> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
>>> Detect TRGO2 timer capability (master mode selection 2).
>>>
>>> Signed-off-by: Fabrice Gasnier 
>>> ---
>>>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>>>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
>>> ++---
>>>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>>>  include/linux/mfd/stm32-timers.h   |   2 +
>>>  4 files changed, 118 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
>>> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>>> index 230020e..47647b4 100644
>>> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>>> @@ -16,6 +16,21 @@ Description:
>>> - "OC2REF": OC2REF signal is used as trigger output.
>>> - "OC3REF": OC3REF signal is used as trigger output.
>>> - "OC4REF": OC4REF signal is used as trigger output.
>>> +   Additional modes (on TRGO2 only):
>>> +   - "OC5REF": OC5REF signal is used as trigger output.
>>> +   - "OC6REF": OC6REF signal is used as trigger output.
>>> +   - "compare_pulse_OC4REF":
>>> + OC4REF rising or falling edges generate pulses.
> I'd like this to be fairly understandable without resorting to reading the
> datasheet.  As I understand it you get a fixed term pulse on both edges
> of the waveform?  Perhaps this calls for some ascii art :)

Hi Jonathan,

If you feel like it needs more documentation, I'd rather prefer to add
reference or link to the datasheet... That will be more accurate,
up-to-date (e.g. like RM0385 pdf). Does this sound ok ? Or...

Just in case, I prepared some ascii art, hope it clarify things.
I'm wondering if this is best place to put it ?
Shouldn't this be added in source code, instead of ABI Doc ?
Maybe I can skip 1st part of it, heading boxes? (only example is enough?
or not...)

+---+   +-++-+
| Prescaler +-> | Counter |+-> | Master  | TRGO(2)
+---+   +--++-+|-> | Control +-->
   ||  ||  +-+
+--v+-+ OCxREF ||  +-+
| Chx compare +--> | Output  | ChX
+---+-+ |  | Control +-->
  . |   |  +-+
  . |   |.
+---v-+ OC6REF  |.
| Ch6 compare +-+>
+-+

Example with: "compare_pulse_OC4REF_r_or_OC6REF_r":

X
  X   X
X .   . X
  X   .   .   X
X .   . X
count X . .   . . X
. .   . .
. .   . .
+---+
OC4REF  | .   . |
  +-+ .   . +-+
. +---+ .
OC6REF  . |   | .
  +---+   +---+
+-+   +-+
TRGO2   | |   | |
  +-+ +---+ +-+


side note: this isn't my house ;-)

Please advise,
Thanks,
Fabrice


>>> +   - "compare_pulse_OC6REF":
>>> + OC6REF rising or falling edges generate pulses.
>>> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
>>> + OC4REF or OC6REF rising edges generate pulses.
>>> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
>>> + OC4REF rising or OC6REF falling edges generate pulses.
>>> +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
>>> + OC5REF or OC6REF rising edges generate pulses.
>>> +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
>>> + OC5REF rising or OC6REF falling edges generate pulses.
>>>
>>>  What:  /sys/bus/iio/devices/triggerX/master_mode
>>>  KernelVersion: 4.11
>>> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
>>> b/drivers/iio/trigger/stm32-timer-trigger.c
>>> index 0f1a2cf..a0031b7 100644
>>> --- a/drivers/iio/trigger/stm32-timer-trigger.c
>>> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
>>> @@ -14,19 +14,19 @@
>>>  #include 
>>>  #include 
>>>
>>> -#define MAX_TRIGGERS 6
>>> +#define MAX_TRIGGERS 7
>>>  #define MAX_VALIDS 5
>>>
>>>  /* List the triggers created by each timer */
>>>  static const void 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-28 Thread Fabrice Gasnier
On 04/27/2017 07:49 AM, Jonathan Cameron wrote:
> On 26/04/17 09:55, Benjamin Gaignard wrote:
>> 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
>>> Add support for TRGO2 trigger that can be found on STM32F7.
>>> Add additional master modes supported by TRGO2.
> These additional modes would benefit from more information in the
> ABI docs.  Otherwise patch seems fine, though this may win
> the award for hardest hardware to come up with a generic
> interface for... 
>>> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
>>> Detect TRGO2 timer capability (master mode selection 2).
>>>
>>> Signed-off-by: Fabrice Gasnier 
>>> ---
>>>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>>>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
>>> ++---
>>>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>>>  include/linux/mfd/stm32-timers.h   |   2 +
>>>  4 files changed, 118 insertions(+), 14 deletions(-)
>>>
>>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
>>> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>>> index 230020e..47647b4 100644
>>> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>>> @@ -16,6 +16,21 @@ Description:
>>> - "OC2REF": OC2REF signal is used as trigger output.
>>> - "OC3REF": OC3REF signal is used as trigger output.
>>> - "OC4REF": OC4REF signal is used as trigger output.
>>> +   Additional modes (on TRGO2 only):
>>> +   - "OC5REF": OC5REF signal is used as trigger output.
>>> +   - "OC6REF": OC6REF signal is used as trigger output.
>>> +   - "compare_pulse_OC4REF":
>>> + OC4REF rising or falling edges generate pulses.
> I'd like this to be fairly understandable without resorting to reading the
> datasheet.  As I understand it you get a fixed term pulse on both edges
> of the waveform?  Perhaps this calls for some ascii art :)

Hi Jonathan,

If you feel like it needs more documentation, I'd rather prefer to add
reference or link to the datasheet... That will be more accurate,
up-to-date (e.g. like RM0385 pdf). Does this sound ok ? Or...

Just in case, I prepared some ascii art, hope it clarify things.
I'm wondering if this is best place to put it ?
Shouldn't this be added in source code, instead of ABI Doc ?
Maybe I can skip 1st part of it, heading boxes? (only example is enough?
or not...)

+---+   +-++-+
| Prescaler +-> | Counter |+-> | Master  | TRGO(2)
+---+   +--++-+|-> | Control +-->
   ||  ||  +-+
+--v+-+ OCxREF ||  +-+
| Chx compare +--> | Output  | ChX
+---+-+ |  | Control +-->
  . |   |  +-+
  . |   |.
+---v-+ OC6REF  |.
| Ch6 compare +-+>
+-+

Example with: "compare_pulse_OC4REF_r_or_OC6REF_r":

X
  X   X
X .   . X
  X   .   .   X
X .   . X
count X . .   . . X
. .   . .
. .   . .
+---+
OC4REF  | .   . |
  +-+ .   . +-+
. +---+ .
OC6REF  . |   | .
  +---+   +---+
+-+   +-+
TRGO2   | |   | |
  +-+ +---+ +-+


side note: this isn't my house ;-)

Please advise,
Thanks,
Fabrice


>>> +   - "compare_pulse_OC6REF":
>>> + OC6REF rising or falling edges generate pulses.
>>> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
>>> + OC4REF or OC6REF rising edges generate pulses.
>>> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
>>> + OC4REF rising or OC6REF falling edges generate pulses.
>>> +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
>>> + OC5REF or OC6REF rising edges generate pulses.
>>> +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
>>> + OC5REF rising or OC6REF falling edges generate pulses.
>>>
>>>  What:  /sys/bus/iio/devices/triggerX/master_mode
>>>  KernelVersion: 4.11
>>> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
>>> b/drivers/iio/trigger/stm32-timer-trigger.c
>>> index 0f1a2cf..a0031b7 100644
>>> --- a/drivers/iio/trigger/stm32-timer-trigger.c
>>> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
>>> @@ -14,19 +14,19 @@
>>>  #include 
>>>  #include 
>>>
>>> -#define MAX_TRIGGERS 6
>>> +#define MAX_TRIGGERS 7
>>>  #define MAX_VALIDS 5
>>>
>>>  /* List the triggers created by each timer */
>>>  static const void *triggers_table[][MAX_TRIGGERS] = {
>>> -   { TIM1_TRGO, TIM1_CH1, 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-26 Thread Jonathan Cameron
On 26/04/17 09:55, Benjamin Gaignard wrote:
> 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
>> Add support for TRGO2 trigger that can be found on STM32F7.
>> Add additional master modes supported by TRGO2.
These additional modes would benefit from more information in the
ABI docs.  Otherwise patch seems fine, though this may win
the award for hardest hardware to come up with a generic
interface for... 
>> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
>> Detect TRGO2 timer capability (master mode selection 2).
>>
>> Signed-off-by: Fabrice Gasnier 
>> ---
>>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
>> ++---
>>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>>  include/linux/mfd/stm32-timers.h   |   2 +
>>  4 files changed, 118 insertions(+), 14 deletions(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
>> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>> index 230020e..47647b4 100644
>> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>> @@ -16,6 +16,21 @@ Description:
>> - "OC2REF": OC2REF signal is used as trigger output.
>> - "OC3REF": OC3REF signal is used as trigger output.
>> - "OC4REF": OC4REF signal is used as trigger output.
>> +   Additional modes (on TRGO2 only):
>> +   - "OC5REF": OC5REF signal is used as trigger output.
>> +   - "OC6REF": OC6REF signal is used as trigger output.
>> +   - "compare_pulse_OC4REF":
>> + OC4REF rising or falling edges generate pulses.
I'd like this to be fairly understandable without resorting to reading the
datasheet.  As I understand it you get a fixed term pulse on both edges
of the waveform?  Perhaps this calls for some ascii art :)
>> +   - "compare_pulse_OC6REF":
>> + OC6REF rising or falling edges generate pulses.
>> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
>> + OC4REF or OC6REF rising edges generate pulses.
>> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
>> + OC4REF rising or OC6REF falling edges generate pulses.
>> +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
>> + OC5REF or OC6REF rising edges generate pulses.
>> +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
>> + OC5REF rising or OC6REF falling edges generate pulses.
>>
>>  What:  /sys/bus/iio/devices/triggerX/master_mode
>>  KernelVersion: 4.11
>> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
>> b/drivers/iio/trigger/stm32-timer-trigger.c
>> index 0f1a2cf..a0031b7 100644
>> --- a/drivers/iio/trigger/stm32-timer-trigger.c
>> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
>> @@ -14,19 +14,19 @@
>>  #include 
>>  #include 
>>
>> -#define MAX_TRIGGERS 6
>> +#define MAX_TRIGGERS 7
>>  #define MAX_VALIDS 5
>>
>>  /* List the triggers created by each timer */
>>  static const void *triggers_table[][MAX_TRIGGERS] = {
>> -   { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
>> +   { TIM1_TRGO, TIM1_TRGO2, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
>> { TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
>> { TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
>> { TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
>> { TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
>> { TIM6_TRGO,},
>> { TIM7_TRGO,},
>> -   { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
>> +   { TIM8_TRGO, TIM8_TRGO2, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
>> { TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
>> { }, /* timer 10 */
>> { }, /* timer 11 */
>> @@ -56,9 +56,16 @@ struct stm32_timer_trigger {
>> u32 max_arr;
>> const void *triggers;
>> const void *valids;
>> +   bool has_trgo2;
>>  };
>>
>> +static bool stm32_timer_is_trgo2_name(const char *name)
>> +{
>> +   return !!strstr(name, "trgo2");
>> +}
>> +
>>  static int stm32_timer_start(struct stm32_timer_trigger *priv,
>> +struct iio_trigger *trig,
>>  unsigned int frequency)
>>  {
>> unsigned long long prd, div;
>> @@ -102,7 +109,12 @@ static int stm32_timer_start(struct stm32_timer_trigger 
>> *priv,
>> regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 
>> TIM_CR1_ARPE);
>>
>> /* Force master mode to update mode */
>> -   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
>> +   if (stm32_timer_is_trgo2_name(trig->name))
>> +   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS2,
>> +  0x2 << TIM_CR2_MMS2_SHIFT);
>> +   else
>> + 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-26 Thread Jonathan Cameron
On 26/04/17 09:55, Benjamin Gaignard wrote:
> 2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
>> Add support for TRGO2 trigger that can be found on STM32F7.
>> Add additional master modes supported by TRGO2.
These additional modes would benefit from more information in the
ABI docs.  Otherwise patch seems fine, though this may win
the award for hardest hardware to come up with a generic
interface for... 
>> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
>> Detect TRGO2 timer capability (master mode selection 2).
>>
>> Signed-off-by: Fabrice Gasnier 
>> ---
>>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
>> ++---
>>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>>  include/linux/mfd/stm32-timers.h   |   2 +
>>  4 files changed, 118 insertions(+), 14 deletions(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
>> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>> index 230020e..47647b4 100644
>> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
>> @@ -16,6 +16,21 @@ Description:
>> - "OC2REF": OC2REF signal is used as trigger output.
>> - "OC3REF": OC3REF signal is used as trigger output.
>> - "OC4REF": OC4REF signal is used as trigger output.
>> +   Additional modes (on TRGO2 only):
>> +   - "OC5REF": OC5REF signal is used as trigger output.
>> +   - "OC6REF": OC6REF signal is used as trigger output.
>> +   - "compare_pulse_OC4REF":
>> + OC4REF rising or falling edges generate pulses.
I'd like this to be fairly understandable without resorting to reading the
datasheet.  As I understand it you get a fixed term pulse on both edges
of the waveform?  Perhaps this calls for some ascii art :)
>> +   - "compare_pulse_OC6REF":
>> + OC6REF rising or falling edges generate pulses.
>> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
>> + OC4REF or OC6REF rising edges generate pulses.
>> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
>> + OC4REF rising or OC6REF falling edges generate pulses.
>> +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
>> + OC5REF or OC6REF rising edges generate pulses.
>> +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
>> + OC5REF rising or OC6REF falling edges generate pulses.
>>
>>  What:  /sys/bus/iio/devices/triggerX/master_mode
>>  KernelVersion: 4.11
>> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
>> b/drivers/iio/trigger/stm32-timer-trigger.c
>> index 0f1a2cf..a0031b7 100644
>> --- a/drivers/iio/trigger/stm32-timer-trigger.c
>> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
>> @@ -14,19 +14,19 @@
>>  #include 
>>  #include 
>>
>> -#define MAX_TRIGGERS 6
>> +#define MAX_TRIGGERS 7
>>  #define MAX_VALIDS 5
>>
>>  /* List the triggers created by each timer */
>>  static const void *triggers_table[][MAX_TRIGGERS] = {
>> -   { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
>> +   { TIM1_TRGO, TIM1_TRGO2, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
>> { TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
>> { TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
>> { TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
>> { TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
>> { TIM6_TRGO,},
>> { TIM7_TRGO,},
>> -   { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
>> +   { TIM8_TRGO, TIM8_TRGO2, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
>> { TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
>> { }, /* timer 10 */
>> { }, /* timer 11 */
>> @@ -56,9 +56,16 @@ struct stm32_timer_trigger {
>> u32 max_arr;
>> const void *triggers;
>> const void *valids;
>> +   bool has_trgo2;
>>  };
>>
>> +static bool stm32_timer_is_trgo2_name(const char *name)
>> +{
>> +   return !!strstr(name, "trgo2");
>> +}
>> +
>>  static int stm32_timer_start(struct stm32_timer_trigger *priv,
>> +struct iio_trigger *trig,
>>  unsigned int frequency)
>>  {
>> unsigned long long prd, div;
>> @@ -102,7 +109,12 @@ static int stm32_timer_start(struct stm32_timer_trigger 
>> *priv,
>> regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 
>> TIM_CR1_ARPE);
>>
>> /* Force master mode to update mode */
>> -   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
>> +   if (stm32_timer_is_trgo2_name(trig->name))
>> +   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS2,
>> +  0x2 << TIM_CR2_MMS2_SHIFT);
>> +   else
>> +   regmap_update_bits(priv->regmap, 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-26 Thread Benjamin Gaignard
2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
> Add support for TRGO2 trigger that can be found on STM32F7.
> Add additional master modes supported by TRGO2.
> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
> Detect TRGO2 timer capability (master mode selection 2).
>
> Signed-off-by: Fabrice Gasnier 
> ---
>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
> ++---
>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>  include/linux/mfd/stm32-timers.h   |   2 +
>  4 files changed, 118 insertions(+), 14 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> index 230020e..47647b4 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> @@ -16,6 +16,21 @@ Description:
> - "OC2REF": OC2REF signal is used as trigger output.
> - "OC3REF": OC3REF signal is used as trigger output.
> - "OC4REF": OC4REF signal is used as trigger output.
> +   Additional modes (on TRGO2 only):
> +   - "OC5REF": OC5REF signal is used as trigger output.
> +   - "OC6REF": OC6REF signal is used as trigger output.
> +   - "compare_pulse_OC4REF":
> + OC4REF rising or falling edges generate pulses.
> +   - "compare_pulse_OC6REF":
> + OC6REF rising or falling edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
> + OC4REF or OC6REF rising edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
> + OC4REF rising or OC6REF falling edges generate pulses.
> +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
> + OC5REF or OC6REF rising edges generate pulses.
> +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
> + OC5REF rising or OC6REF falling edges generate pulses.
>
>  What:  /sys/bus/iio/devices/triggerX/master_mode
>  KernelVersion: 4.11
> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
> b/drivers/iio/trigger/stm32-timer-trigger.c
> index 0f1a2cf..a0031b7 100644
> --- a/drivers/iio/trigger/stm32-timer-trigger.c
> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
> @@ -14,19 +14,19 @@
>  #include 
>  #include 
>
> -#define MAX_TRIGGERS 6
> +#define MAX_TRIGGERS 7
>  #define MAX_VALIDS 5
>
>  /* List the triggers created by each timer */
>  static const void *triggers_table[][MAX_TRIGGERS] = {
> -   { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
> +   { TIM1_TRGO, TIM1_TRGO2, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
> { TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
> { TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
> { TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
> { TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
> { TIM6_TRGO,},
> { TIM7_TRGO,},
> -   { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
> +   { TIM8_TRGO, TIM8_TRGO2, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
> { TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
> { }, /* timer 10 */
> { }, /* timer 11 */
> @@ -56,9 +56,16 @@ struct stm32_timer_trigger {
> u32 max_arr;
> const void *triggers;
> const void *valids;
> +   bool has_trgo2;
>  };
>
> +static bool stm32_timer_is_trgo2_name(const char *name)
> +{
> +   return !!strstr(name, "trgo2");
> +}
> +
>  static int stm32_timer_start(struct stm32_timer_trigger *priv,
> +struct iio_trigger *trig,
>  unsigned int frequency)
>  {
> unsigned long long prd, div;
> @@ -102,7 +109,12 @@ static int stm32_timer_start(struct stm32_timer_trigger 
> *priv,
> regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
>
> /* Force master mode to update mode */
> -   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
> +   if (stm32_timer_is_trgo2_name(trig->name))
> +   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS2,
> +  0x2 << TIM_CR2_MMS2_SHIFT);
> +   else
> +   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS,
> +  0x2 << TIM_CR2_MMS_SHIFT);
>
> /* Make sure that registers are updated */
> regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
> @@ -150,7 +162,7 @@ static ssize_t stm32_tt_store_frequency(struct device 
> *dev,
> if (freq == 0) {
> stm32_timer_stop(priv);
> } else {
> -   ret = stm32_timer_start(priv, freq);
> +   ret = stm32_timer_start(priv, trig, 

Re: [PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-26 Thread Benjamin Gaignard
2017-04-26 10:17 GMT+02:00 Fabrice Gasnier :
> Add support for TRGO2 trigger that can be found on STM32F7.
> Add additional master modes supported by TRGO2.
> Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
> Detect TRGO2 timer capability (master mode selection 2).
>
> Signed-off-by: Fabrice Gasnier 
> ---
>  .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
>  drivers/iio/trigger/stm32-timer-trigger.c  | 113 
> ++---
>  include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
>  include/linux/mfd/stm32-timers.h   |   2 +
>  4 files changed, 118 insertions(+), 14 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
> b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> index 230020e..47647b4 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
> @@ -16,6 +16,21 @@ Description:
> - "OC2REF": OC2REF signal is used as trigger output.
> - "OC3REF": OC3REF signal is used as trigger output.
> - "OC4REF": OC4REF signal is used as trigger output.
> +   Additional modes (on TRGO2 only):
> +   - "OC5REF": OC5REF signal is used as trigger output.
> +   - "OC6REF": OC6REF signal is used as trigger output.
> +   - "compare_pulse_OC4REF":
> + OC4REF rising or falling edges generate pulses.
> +   - "compare_pulse_OC6REF":
> + OC6REF rising or falling edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_r":
> + OC4REF or OC6REF rising edges generate pulses.
> +   - "compare_pulse_OC4REF_r_or_OC6REF_f":
> + OC4REF rising or OC6REF falling edges generate pulses.
> +   - "compare_pulse_OC5REF_r_or_OC6REF_r":
> + OC5REF or OC6REF rising edges generate pulses.
> +   - "compare_pulse_OC5REF_r_or_OC6REF_f":
> + OC5REF rising or OC6REF falling edges generate pulses.
>
>  What:  /sys/bus/iio/devices/triggerX/master_mode
>  KernelVersion: 4.11
> diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
> b/drivers/iio/trigger/stm32-timer-trigger.c
> index 0f1a2cf..a0031b7 100644
> --- a/drivers/iio/trigger/stm32-timer-trigger.c
> +++ b/drivers/iio/trigger/stm32-timer-trigger.c
> @@ -14,19 +14,19 @@
>  #include 
>  #include 
>
> -#define MAX_TRIGGERS 6
> +#define MAX_TRIGGERS 7
>  #define MAX_VALIDS 5
>
>  /* List the triggers created by each timer */
>  static const void *triggers_table[][MAX_TRIGGERS] = {
> -   { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
> +   { TIM1_TRGO, TIM1_TRGO2, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
> { TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
> { TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
> { TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
> { TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
> { TIM6_TRGO,},
> { TIM7_TRGO,},
> -   { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
> +   { TIM8_TRGO, TIM8_TRGO2, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
> { TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
> { }, /* timer 10 */
> { }, /* timer 11 */
> @@ -56,9 +56,16 @@ struct stm32_timer_trigger {
> u32 max_arr;
> const void *triggers;
> const void *valids;
> +   bool has_trgo2;
>  };
>
> +static bool stm32_timer_is_trgo2_name(const char *name)
> +{
> +   return !!strstr(name, "trgo2");
> +}
> +
>  static int stm32_timer_start(struct stm32_timer_trigger *priv,
> +struct iio_trigger *trig,
>  unsigned int frequency)
>  {
> unsigned long long prd, div;
> @@ -102,7 +109,12 @@ static int stm32_timer_start(struct stm32_timer_trigger 
> *priv,
> regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
>
> /* Force master mode to update mode */
> -   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
> +   if (stm32_timer_is_trgo2_name(trig->name))
> +   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS2,
> +  0x2 << TIM_CR2_MMS2_SHIFT);
> +   else
> +   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS,
> +  0x2 << TIM_CR2_MMS_SHIFT);
>
> /* Make sure that registers are updated */
> regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
> @@ -150,7 +162,7 @@ static ssize_t stm32_tt_store_frequency(struct device 
> *dev,
> if (freq == 0) {
> stm32_timer_stop(priv);
> } else {
> -   ret = stm32_timer_start(priv, freq);
> +   ret = stm32_timer_start(priv, trig, freq);
> if (ret)
>   

[PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-26 Thread Fabrice Gasnier
Add support for TRGO2 trigger that can be found on STM32F7.
Add additional master modes supported by TRGO2.
Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
Detect TRGO2 timer capability (master mode selection 2).

Signed-off-by: Fabrice Gasnier 
---
 .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
 drivers/iio/trigger/stm32-timer-trigger.c  | 113 ++---
 include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
 include/linux/mfd/stm32-timers.h   |   2 +
 4 files changed, 118 insertions(+), 14 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
index 230020e..47647b4 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
+++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
@@ -16,6 +16,21 @@ Description:
- "OC2REF": OC2REF signal is used as trigger output.
- "OC3REF": OC3REF signal is used as trigger output.
- "OC4REF": OC4REF signal is used as trigger output.
+   Additional modes (on TRGO2 only):
+   - "OC5REF": OC5REF signal is used as trigger output.
+   - "OC6REF": OC6REF signal is used as trigger output.
+   - "compare_pulse_OC4REF":
+ OC4REF rising or falling edges generate pulses.
+   - "compare_pulse_OC6REF":
+ OC6REF rising or falling edges generate pulses.
+   - "compare_pulse_OC4REF_r_or_OC6REF_r":
+ OC4REF or OC6REF rising edges generate pulses.
+   - "compare_pulse_OC4REF_r_or_OC6REF_f":
+ OC4REF rising or OC6REF falling edges generate pulses.
+   - "compare_pulse_OC5REF_r_or_OC6REF_r":
+ OC5REF or OC6REF rising edges generate pulses.
+   - "compare_pulse_OC5REF_r_or_OC6REF_f":
+ OC5REF rising or OC6REF falling edges generate pulses.
 
 What:  /sys/bus/iio/devices/triggerX/master_mode
 KernelVersion: 4.11
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
b/drivers/iio/trigger/stm32-timer-trigger.c
index 0f1a2cf..a0031b7 100644
--- a/drivers/iio/trigger/stm32-timer-trigger.c
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -14,19 +14,19 @@
 #include 
 #include 
 
-#define MAX_TRIGGERS 6
+#define MAX_TRIGGERS 7
 #define MAX_VALIDS 5
 
 /* List the triggers created by each timer */
 static const void *triggers_table[][MAX_TRIGGERS] = {
-   { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
+   { TIM1_TRGO, TIM1_TRGO2, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
{ TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
{ TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
{ TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
{ TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
{ TIM6_TRGO,},
{ TIM7_TRGO,},
-   { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
+   { TIM8_TRGO, TIM8_TRGO2, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
{ TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
{ }, /* timer 10 */
{ }, /* timer 11 */
@@ -56,9 +56,16 @@ struct stm32_timer_trigger {
u32 max_arr;
const void *triggers;
const void *valids;
+   bool has_trgo2;
 };
 
+static bool stm32_timer_is_trgo2_name(const char *name)
+{
+   return !!strstr(name, "trgo2");
+}
+
 static int stm32_timer_start(struct stm32_timer_trigger *priv,
+struct iio_trigger *trig,
 unsigned int frequency)
 {
unsigned long long prd, div;
@@ -102,7 +109,12 @@ static int stm32_timer_start(struct stm32_timer_trigger 
*priv,
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
 
/* Force master mode to update mode */
-   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
+   if (stm32_timer_is_trgo2_name(trig->name))
+   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS2,
+  0x2 << TIM_CR2_MMS2_SHIFT);
+   else
+   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS,
+  0x2 << TIM_CR2_MMS_SHIFT);
 
/* Make sure that registers are updated */
regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
@@ -150,7 +162,7 @@ static ssize_t stm32_tt_store_frequency(struct device *dev,
if (freq == 0) {
stm32_timer_stop(priv);
} else {
-   ret = stm32_timer_start(priv, freq);
+   ret = stm32_timer_start(priv, trig, freq);
if (ret)
return ret;
}
@@ -183,6 +195,9 @@ static IIO_DEV_ATTR_SAMP_FREQ(0660,
  stm32_tt_read_frequency,
  stm32_tt_store_frequency);
 
+#define MASTER_MODE_MAX   

[PATCH] iio: stm32 trigger: Add support for TRGO2 triggers

2017-04-26 Thread Fabrice Gasnier
Add support for TRGO2 trigger that can be found on STM32F7.
Add additional master modes supported by TRGO2.
Register additional "tim[1/8]_trgo2" triggers for timer1 & timer8.
Detect TRGO2 timer capability (master mode selection 2).

Signed-off-by: Fabrice Gasnier 
---
 .../ABI/testing/sysfs-bus-iio-timer-stm32  |  15 +++
 drivers/iio/trigger/stm32-timer-trigger.c  | 113 ++---
 include/linux/iio/timer/stm32-timer-trigger.h  |   2 +
 include/linux/mfd/stm32-timers.h   |   2 +
 4 files changed, 118 insertions(+), 14 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 
b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
index 230020e..47647b4 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
+++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32
@@ -16,6 +16,21 @@ Description:
- "OC2REF": OC2REF signal is used as trigger output.
- "OC3REF": OC3REF signal is used as trigger output.
- "OC4REF": OC4REF signal is used as trigger output.
+   Additional modes (on TRGO2 only):
+   - "OC5REF": OC5REF signal is used as trigger output.
+   - "OC6REF": OC6REF signal is used as trigger output.
+   - "compare_pulse_OC4REF":
+ OC4REF rising or falling edges generate pulses.
+   - "compare_pulse_OC6REF":
+ OC6REF rising or falling edges generate pulses.
+   - "compare_pulse_OC4REF_r_or_OC6REF_r":
+ OC4REF or OC6REF rising edges generate pulses.
+   - "compare_pulse_OC4REF_r_or_OC6REF_f":
+ OC4REF rising or OC6REF falling edges generate pulses.
+   - "compare_pulse_OC5REF_r_or_OC6REF_r":
+ OC5REF or OC6REF rising edges generate pulses.
+   - "compare_pulse_OC5REF_r_or_OC6REF_f":
+ OC5REF rising or OC6REF falling edges generate pulses.
 
 What:  /sys/bus/iio/devices/triggerX/master_mode
 KernelVersion: 4.11
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c 
b/drivers/iio/trigger/stm32-timer-trigger.c
index 0f1a2cf..a0031b7 100644
--- a/drivers/iio/trigger/stm32-timer-trigger.c
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -14,19 +14,19 @@
 #include 
 #include 
 
-#define MAX_TRIGGERS 6
+#define MAX_TRIGGERS 7
 #define MAX_VALIDS 5
 
 /* List the triggers created by each timer */
 static const void *triggers_table[][MAX_TRIGGERS] = {
-   { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
+   { TIM1_TRGO, TIM1_TRGO2, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
{ TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
{ TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
{ TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
{ TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
{ TIM6_TRGO,},
{ TIM7_TRGO,},
-   { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
+   { TIM8_TRGO, TIM8_TRGO2, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
{ TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
{ }, /* timer 10 */
{ }, /* timer 11 */
@@ -56,9 +56,16 @@ struct stm32_timer_trigger {
u32 max_arr;
const void *triggers;
const void *valids;
+   bool has_trgo2;
 };
 
+static bool stm32_timer_is_trgo2_name(const char *name)
+{
+   return !!strstr(name, "trgo2");
+}
+
 static int stm32_timer_start(struct stm32_timer_trigger *priv,
+struct iio_trigger *trig,
 unsigned int frequency)
 {
unsigned long long prd, div;
@@ -102,7 +109,12 @@ static int stm32_timer_start(struct stm32_timer_trigger 
*priv,
regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
 
/* Force master mode to update mode */
-   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
+   if (stm32_timer_is_trgo2_name(trig->name))
+   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS2,
+  0x2 << TIM_CR2_MMS2_SHIFT);
+   else
+   regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS,
+  0x2 << TIM_CR2_MMS_SHIFT);
 
/* Make sure that registers are updated */
regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
@@ -150,7 +162,7 @@ static ssize_t stm32_tt_store_frequency(struct device *dev,
if (freq == 0) {
stm32_timer_stop(priv);
} else {
-   ret = stm32_timer_start(priv, freq);
+   ret = stm32_timer_start(priv, trig, freq);
if (ret)
return ret;
}
@@ -183,6 +195,9 @@ static IIO_DEV_ATTR_SAMP_FREQ(0660,
  stm32_tt_read_frequency,
  stm32_tt_store_frequency);
 
+#define MASTER_MODE_MAX7
+#define