Re: [PATCH 6/7] iio: mlx90614: Add power management

2015-03-14 Thread Jonathan Cameron
On 09/03/15 16:43, Wolfram Sang wrote:
> On Mon, Mar 09, 2015 at 03:39:35PM +, Jonathan Cameron wrote:
>> On 25/02/15 15:55, Vianney le Clément de Saint-Marcq wrote:
>>> Add support for system sleep and runtime power management.
>>>
>>> To wake up the device, the SDA line should be held low for at least 33ms
>>> while SCL is high.  As this is not possible using the i2c API (and not
>>> supported by all i2c adapters), a GPIO connected to the SDA line is
>>> needed.  The GPIO is named "wakeup" and can be specified in a device
>>> tree with the "wakeup-gpios" binding.
>> Needs some i2c specialist input on this!  As you mentioned it is liable
>> to be controversial.  Wolfram, is this a one off special or do
>> any other devices do this sort of magic?
> 
> s/magic/insanity/ :)
> 
> I have never heard of something like this. Unsuprisingly, I can
> not recommend doing it this way. But we all know hardware...
> 
> And while we could think about reusing the bus_recovery_infrastructure,
> I don't think it is worth the hazzle. So, doing this GPIO fallback may
> well be the best we can do now.
> 
Fair enough.  Lets go with this approach then and hope this is the only bit
of hardware ever to do this (yeah right ;)

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/7] iio: mlx90614: Add power management

2015-03-09 Thread Wolfram Sang
On Mon, Mar 09, 2015 at 03:39:35PM +, Jonathan Cameron wrote:
> On 25/02/15 15:55, Vianney le Clément de Saint-Marcq wrote:
> > Add support for system sleep and runtime power management.
> > 
> > To wake up the device, the SDA line should be held low for at least 33ms
> > while SCL is high.  As this is not possible using the i2c API (and not
> > supported by all i2c adapters), a GPIO connected to the SDA line is
> > needed.  The GPIO is named "wakeup" and can be specified in a device
> > tree with the "wakeup-gpios" binding.
> Needs some i2c specialist input on this!  As you mentioned it is liable
> to be controversial.  Wolfram, is this a one off special or do
> any other devices do this sort of magic?

s/magic/insanity/ :)

I have never heard of something like this. Unsuprisingly, I can
not recommend doing it this way. But we all know hardware...

And while we could think about reusing the bus_recovery_infrastructure,
I don't think it is worth the hazzle. So, doing this GPIO fallback may
well be the best we can do now.



signature.asc
Description: Digital signature


Re: [PATCH 6/7] iio: mlx90614: Add power management

2015-03-09 Thread Jonathan Cameron
On 09/03/15 15:39, Jonathan Cameron wrote:
> On 25/02/15 15:55, Vianney le Clément de Saint-Marcq wrote:
>> Add support for system sleep and runtime power management.
>>
>> To wake up the device, the SDA line should be held low for at least 33ms
>> while SCL is high.  As this is not possible using the i2c API (and not
>> supported by all i2c adapters), a GPIO connected to the SDA line is
>> needed.  The GPIO is named "wakeup" and can be specified in a device
>> tree with the "wakeup-gpios" binding.
> Needs some i2c specialist input on this!  As you mentioned it is liable
> to be controversial.  Wolfram, is this a one off special or do
> any other devices do this sort of magic?
>>
>> If the wake-up GPIO is not given, disable power management for the
>> device.  Entering sleep requires an SMBus byte access, hence power
>> management is also disabled if byte access is not supported by the
>> adapter.
>>
>> Signed-off-by: Vianney le Clément de Saint-Marcq 
>> 
>> Cc: Arnout Vandecappelle (Essensium/Mind) 
Again, with a current address for Wolfram.
>>
>> ---
>>
>> The default autosleep delay (5s) is chosen arbitrarily, trying to take
>> into account the long startup time (250ms).  Feel free to change it to
>> another value if you think it is saner.
>> ---
>>  .../bindings/iio/temperature/mlx90614.txt  |  24 ++
>>  .../devicetree/bindings/vendor-prefixes.txt|   1 +
>>  drivers/iio/temperature/mlx90614.c | 244 
>> -
>>  3 files changed, 267 insertions(+), 2 deletions(-)
>>  create mode 100644 
>> Documentation/devicetree/bindings/iio/temperature/mlx90614.txt
>>
>> diff --git a/Documentation/devicetree/bindings/iio/temperature/mlx90614.txt 
>> b/Documentation/devicetree/bindings/iio/temperature/mlx90614.txt
>> new file mode 100644
>> index 000..9be57b0
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/iio/temperature/mlx90614.txt
>> @@ -0,0 +1,24 @@
>> +* Melexis MLX90614 contactless IR temperature sensor
>> +
>> +http://melexis.com/Infrared-Thermometer-Sensors/Infrared-Thermometer-Sensors/MLX90614-615.aspx
>> +
>> +Required properties:
>> +
>> +  - compatible: should be "melexis,mlx90614"
>> +  - reg: the I2C address of the sensor
>> +
>> +Optional properties:
>> +
>> +  - wakeup-gpios: device tree identifier of the GPIO connected to the SDA 
>> line
>> +  to hold low in order to wake up the device.  In normal operation, the
>> +  GPIO is set as input and will not interfere in I2C communication.  
>> There
>> +  is no need for a GPIO driving the SCL line.  If no GPIO is given, 
>> power
>> +  management is disabled.
>> +
>> +Example:
>> +
>> +mlx90614@5a {
>> +compatible = "melexis,mlx90614";
>> +reg = <0x5a>;
>> +wakeup-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
>> +};
>> diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
>> b/Documentation/devicetree/bindings/vendor-prefixes.txt
>> index 389ca13..ceacc40 100644
>> --- a/Documentation/devicetree/bindings/vendor-prefixes.txt
>> +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
>> @@ -108,6 +108,7 @@ lltc Linear Technology Corporation
>>  marvell Marvell Technology Group Ltd.
>>  maxim   Maxim Integrated Products
>>  mediatekMediaTek Inc.
>> +melexis Melexis N.V.
>>  merrii  Merrii Technology Co., Ltd.
>>  micrel  Micrel Inc.
>>  microchip   Microchip Technology Inc.
>> diff --git a/drivers/iio/temperature/mlx90614.c 
>> b/drivers/iio/temperature/mlx90614.c
>> index ab98fb6..49c517a 100644
>> --- a/drivers/iio/temperature/mlx90614.c
>> +++ b/drivers/iio/temperature/mlx90614.c
>> @@ -12,13 +12,22 @@
>>   *
>>   * (7-bit I2C slave address 0x5a, 100KHz bus speed only!)
>>   *
>> - * TODO: sleep mode
>> + * To wake up from sleep mode, the SDA line must be held low while SCL is 
>> high
>> + * for at least 33ms.  This is achieved with an extra GPIO that can be 
>> connected
>> + * directly to the SDA line.  In normal operation, the GPIO is set as input 
>> and
>> + * will not interfere in I2C communication.  While the GPIO is driven low, 
>> the
>> + * i2c adapter is locked since it cannot be used by other clients.  The SCL 
>> line
>> + * always has a pull-up so we do not need an extra GPIO to drive it high.  
>> If
>> + * the "wakeup" GPIO is not given, power management will be disabled.
>>   */
>>  
>>  #include 
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>> +#include 
>> +#include 
>>  
>>  #include 
>>  #include 
>> @@ -53,9 +62,13 @@
>>  #define MLX90614_TIMING_WAKEUP 34 /* time to hold SDA low for wake-up */
>>  #define MLX90614_TIMING_STARTUP 250 /* time before first data after wake-up 
>> */
>>  
>> +#define MLX90614_AUTOSLEEP_DELAY 5000 /* default autosleep delay */
>> +
>>  struct mlx90614_data {
>>  struct i2c_client *client;
>>  struct mutex lock; /* for EEPROM access only */
>> +struct gpio_desc *wakeup_gpio; /* NULL to disable sleep/wake-up */
>> +unsigned long ready_timestamp; /* in j

Re: [PATCH 6/7] iio: mlx90614: Add power management

2015-03-09 Thread Jonathan Cameron
On 25/02/15 15:55, Vianney le Clément de Saint-Marcq wrote:
> Add support for system sleep and runtime power management.
> 
> To wake up the device, the SDA line should be held low for at least 33ms
> while SCL is high.  As this is not possible using the i2c API (and not
> supported by all i2c adapters), a GPIO connected to the SDA line is
> needed.  The GPIO is named "wakeup" and can be specified in a device
> tree with the "wakeup-gpios" binding.
Needs some i2c specialist input on this!  As you mentioned it is liable
to be controversial.  Wolfram, is this a one off special or do
any other devices do this sort of magic?
> 
> If the wake-up GPIO is not given, disable power management for the
> device.  Entering sleep requires an SMBus byte access, hence power
> management is also disabled if byte access is not supported by the
> adapter.
> 
> Signed-off-by: Vianney le Clément de Saint-Marcq 
> 
> Cc: Arnout Vandecappelle (Essensium/Mind) 
> 
> ---
> 
> The default autosleep delay (5s) is chosen arbitrarily, trying to take
> into account the long startup time (250ms).  Feel free to change it to
> another value if you think it is saner.
> ---
>  .../bindings/iio/temperature/mlx90614.txt  |  24 ++
>  .../devicetree/bindings/vendor-prefixes.txt|   1 +
>  drivers/iio/temperature/mlx90614.c | 244 
> -
>  3 files changed, 267 insertions(+), 2 deletions(-)
>  create mode 100644 
> Documentation/devicetree/bindings/iio/temperature/mlx90614.txt
> 
> diff --git a/Documentation/devicetree/bindings/iio/temperature/mlx90614.txt 
> b/Documentation/devicetree/bindings/iio/temperature/mlx90614.txt
> new file mode 100644
> index 000..9be57b0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/temperature/mlx90614.txt
> @@ -0,0 +1,24 @@
> +* Melexis MLX90614 contactless IR temperature sensor
> +
> +http://melexis.com/Infrared-Thermometer-Sensors/Infrared-Thermometer-Sensors/MLX90614-615.aspx
> +
> +Required properties:
> +
> +  - compatible: should be "melexis,mlx90614"
> +  - reg: the I2C address of the sensor
> +
> +Optional properties:
> +
> +  - wakeup-gpios: device tree identifier of the GPIO connected to the SDA 
> line
> +  to hold low in order to wake up the device.  In normal operation, the
> +  GPIO is set as input and will not interfere in I2C communication.  
> There
> +  is no need for a GPIO driving the SCL line.  If no GPIO is given, power
> +  management is disabled.
> +
> +Example:
> +
> +mlx90614@5a {
> + compatible = "melexis,mlx90614";
> + reg = <0x5a>;
> + wakeup-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
> +};
> diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
> b/Documentation/devicetree/bindings/vendor-prefixes.txt
> index 389ca13..ceacc40 100644
> --- a/Documentation/devicetree/bindings/vendor-prefixes.txt
> +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
> @@ -108,6 +108,7 @@ lltc  Linear Technology Corporation
>  marvell  Marvell Technology Group Ltd.
>  maximMaxim Integrated Products
>  mediatek MediaTek Inc.
> +melexis  Melexis N.V.
>  merrii   Merrii Technology Co., Ltd.
>  micrel   Micrel Inc.
>  microchipMicrochip Technology Inc.
> diff --git a/drivers/iio/temperature/mlx90614.c 
> b/drivers/iio/temperature/mlx90614.c
> index ab98fb6..49c517a 100644
> --- a/drivers/iio/temperature/mlx90614.c
> +++ b/drivers/iio/temperature/mlx90614.c
> @@ -12,13 +12,22 @@
>   *
>   * (7-bit I2C slave address 0x5a, 100KHz bus speed only!)
>   *
> - * TODO: sleep mode
> + * To wake up from sleep mode, the SDA line must be held low while SCL is 
> high
> + * for at least 33ms.  This is achieved with an extra GPIO that can be 
> connected
> + * directly to the SDA line.  In normal operation, the GPIO is set as input 
> and
> + * will not interfere in I2C communication.  While the GPIO is driven low, 
> the
> + * i2c adapter is locked since it cannot be used by other clients.  The SCL 
> line
> + * always has a pull-up so we do not need an extra GPIO to drive it high.  If
> + * the "wakeup" GPIO is not given, power management will be disabled.
>   */
>  
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> +#include 
>  
>  #include 
>  #include 
> @@ -53,9 +62,13 @@
>  #define MLX90614_TIMING_WAKEUP 34 /* time to hold SDA low for wake-up */
>  #define MLX90614_TIMING_STARTUP 250 /* time before first data after wake-up 
> */
>  
> +#define MLX90614_AUTOSLEEP_DELAY 5000 /* default autosleep delay */
> +
>  struct mlx90614_data {
>   struct i2c_client *client;
>   struct mutex lock; /* for EEPROM access only */
> + struct gpio_desc *wakeup_gpio; /* NULL to disable sleep/wake-up */
> + unsigned long ready_timestamp; /* in jiffies */
>  };
>  
>  /*
> @@ -96,6 +109,52 @@ static s32 mlx90614_write_word(const struct i2c_client 
> *client, u8 command,
>   return ret;
>  }
>  
> +#ifdef CONFIG_PM
> +/*
> + * If @startup is t