All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] MAX6642: Better detection schema
@ 2011-05-25 17:48 Per Dalén
  2011-05-25 18:55 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Per Dalén @ 2011-05-25 17:48 UTC (permalink / raw)
  To: lm-sensors

Made the improvement for the detection schema suggested by Guenter Roeck.
---
Check for non-existing registers, registers 0x04, 0x06 and 0xff, which
are supported by other Maxim chips. Reading such registers returns the
previously read value.

Signed-off-by: Per Dalen <per.dalen@appeartv.com>
---

diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c
index 0f9fc40..69c7f9e 100644
--- a/drivers/hwmon/max6642.c
+++ b/drivers/hwmon/max6642.c
@@ -64,6 +64,14 @@ static const unsigned short normal_i2c[] = {
 #define MAX6642_REG_W_REMOTE_HIGH	0x0D

 /*
+ * Registers for detection tests, these registers isn't pressent and
+ * will only show the last valid register read.
+ */
+#define MAX6642_REG_R_DUMMY_1          0x04
+#define MAX6642_REG_R_DUMMY_2          0x06
+#define MAX6642_REG_R_DUMMY_3          0xFF
+
+/*
  * Conversions
  */

@@ -126,14 +134,16 @@ static int max6642_detect(struct i2c_client *client,
 			  struct i2c_board_info *info)
 {
 	struct i2c_adapter *adapter = client->adapter;
-	u8 reg_config, reg_status, man_id;
+	u8 reg_config, reg_status, man_id, dummy_reg1, dummy_reg2;

 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return -ENODEV;

 	/* identification */
 	man_id = i2c_smbus_read_byte_data(client, MAX6642_REG_R_MAN_ID);
-	if (man_id != 0x4D)
+	dummy_reg1 = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_1);
+	if ((man_id != 0x4D) &&
+	    (man_id != dummy_reg1))
 		return -ENODEV;

 	/*
@@ -142,9 +152,13 @@ static int max6642_detect(struct i2c_client *client,
 	 * zero in the status register.
 	 */
 	reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG);
+	dummy_reg1 = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_2);
 	reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS);
-	if (((reg_config & 0x0f) != 0x00) ||
-	    ((reg_status & 0x2b) != 0x00))
+	dummy_reg2 = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_3);
+	if ((reg_config & 0x0f) != 0x00 ||
+	    (reg_status & 0x2b) != 0x00 ||
+	    reg_config != dummy_reg1 ||
+	    reg_status != dummy_reg2)
 		return -ENODEV;

 	strlcpy(info->type, "max6642", I2C_NAME_SIZE);

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

* Re: [lm-sensors] [PATCH] MAX6642: Better detection schema
  2011-05-25 17:48 [lm-sensors] [PATCH] MAX6642: Better detection schema Per Dalén
@ 2011-05-25 18:55 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2011-05-25 18:55 UTC (permalink / raw)
  To: lm-sensors

Hi Per,

On Wed, 2011-05-25 at 13:48 -0400, Per Dalén wrote:
> Made the improvement for the detection schema suggested by Guenter Roeck.
> ---
> Check for non-existing registers, registers 0x04, 0x06 and 0xff, which
> are supported by other Maxim chips. Reading such registers returns the
> previously read value.
> 
> Signed-off-by: Per Dalen <per.dalen@appeartv.com>
> ---
> 
> diff --git a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c
> index 0f9fc40..69c7f9e 100644
> --- a/drivers/hwmon/max6642.c
> +++ b/drivers/hwmon/max6642.c
> @@ -64,6 +64,14 @@ static const unsigned short normal_i2c[] = {
>  #define MAX6642_REG_W_REMOTE_HIGH	0x0D
> 
>  /*
> + * Registers for detection tests, these registers isn't pressent and
> + * will only show the last valid register read.
> + */
> +#define MAX6642_REG_R_DUMMY_1          0x04
> +#define MAX6642_REG_R_DUMMY_2          0x06
> +#define MAX6642_REG_R_DUMMY_3          0xFF
> +
> +/*
>   * Conversions
>   */
> 
> @@ -126,14 +134,16 @@ static int max6642_detect(struct i2c_client *client,
>  			  struct i2c_board_info *info)
>  {
>  	struct i2c_adapter *adapter = client->adapter;
> -	u8 reg_config, reg_status, man_id;
> +	u8 reg_config, reg_status, man_id, dummy_reg1, dummy_reg2;
> 
>  	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
>  		return -ENODEV;
> 
>  	/* identification */
>  	man_id = i2c_smbus_read_byte_data(client, MAX6642_REG_R_MAN_ID);
> -	if (man_id != 0x4D)
> +	dummy_reg1 = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_1);
> +	if ((man_id != 0x4D) &&
> +	    (man_id != dummy_reg1))

Please drop all the unnecessary () and the unnecessary line break. Also,
I think the logic is wrong. It should be

	if (man_id != 0x4d || man_id != dummy_reg1)

>  		return -ENODEV;
> 
>  	/*
> @@ -142,9 +152,13 @@ static int max6642_detect(struct i2c_client *client,
>  	 * zero in the status register.
>  	 */
>  	reg_config = i2c_smbus_read_byte_data(client, MAX6642_REG_R_CONFIG);
> +	dummy_reg1 = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_2);
>  	reg_status = i2c_smbus_read_byte_data(client, MAX6642_REG_R_STATUS);
> -	if (((reg_config & 0x0f) != 0x00) ||
> -	    ((reg_status & 0x2b) != 0x00))
> +	dummy_reg2 = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_3);
> +	if ((reg_config & 0x0f) != 0x00 ||
> +	    (reg_status & 0x2b) != 0x00 ||
> +	    reg_config != dummy_reg1 ||
> +	    reg_status != dummy_reg2)

Please remove unnecessary line breaks.

I think it is better to read all dummy registers right after reading
man_id. This way we know for sure that the MAX6642 will return 0x4d when
reading those registers, and you can check each of the registers against
man_id in the first if statement above.

Thanks,
Guenter



_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

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

end of thread, other threads:[~2011-05-25 18:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-25 17:48 [lm-sensors] [PATCH] MAX6642: Better detection schema Per Dalén
2011-05-25 18:55 ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.