All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH v2] MAX6642: Better detection schema
@ 2011-05-26 13:08 Per Dalén
  2011-05-26 13:52 ` Guenter Roeck
  2011-05-26 19:39 ` Jean Delvare
  0 siblings, 2 replies; 3+ messages in thread
From: Per Dalén @ 2011-05-26 13:08 UTC (permalink / raw)
  To: lm-sensors

Changed according to the suggestions from Guenter Roeck:

* Check the manufacturer ID directly. Fastens the test if it's not a
Maxim chip.
* Read the other non-existing registers after the manufacturer ID.

---
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..565b507 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,7 +134,7 @@ 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_reg;

 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return -ENODEV;
@@ -136,6 +144,19 @@ static int max6642_detect(struct i2c_client *client,
 	if (man_id != 0x4D)
 		return -ENODEV;

+	/* sanity check */
+	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_1);
+	if (dummy_reg != 0x4D)
+		return -ENODEV;
+
+	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_2);
+	if (dummy_reg != 0x4D)
+		return -ENODEV;
+
+	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_3);
+	if (dummy_reg != 0x4D)
+		return -ENODEV;
+
 	/*
 	 * We read the config and status register, the 4 lower bits in the
 	 * config register should be zero and bit 5, 3, 1 and 0 should be

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

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

* Re: [lm-sensors] [PATCH v2] MAX6642: Better detection schema
  2011-05-26 13:08 [lm-sensors] [PATCH v2] MAX6642: Better detection schema Per Dalén
@ 2011-05-26 13:52 ` Guenter Roeck
  2011-05-26 19:39 ` Jean Delvare
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2011-05-26 13:52 UTC (permalink / raw)
  To: lm-sensors

On Thu, May 26, 2011 at 09:08:53AM -0400, Per Dalén wrote:
> Changed according to the suggestions from Guenter Roeck:
> 
> * Check the manufacturer ID directly. Fastens the test if it's not a
> Maxim chip.
> * Read the other non-existing registers after the manufacturer ID.
> 
> ---
> 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>

Applied, with a couple of spelling errors fixed.

> ---

On a side note, your comments from above should go here. As written, the comments
end up in the commit log, but the description and your signature don't.

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] 3+ messages in thread

* Re: [lm-sensors] [PATCH v2] MAX6642: Better detection schema
  2011-05-26 13:08 [lm-sensors] [PATCH v2] MAX6642: Better detection schema Per Dalén
  2011-05-26 13:52 ` Guenter Roeck
@ 2011-05-26 19:39 ` Jean Delvare
  1 sibling, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2011-05-26 19:39 UTC (permalink / raw)
  To: lm-sensors

On Thu, 26 May 2011 15:08:53 +0200, Per Dalén wrote:
> Changed according to the suggestions from Guenter Roeck:
> 
> * Check the manufacturer ID directly. Fastens the test if it's not a
> Maxim chip.
> * Read the other non-existing registers after the manufacturer ID.
> 
> ---
> 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..565b507 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

I don't even think you want defines for these. They don't exist! The
comment would be better placed right before the relevant piece of code.

> +
> +/*
>   * Conversions
>   */
> 
> @@ -126,7 +134,7 @@ 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_reg;
> 
>  	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
>  		return -ENODEV;
> @@ -136,6 +144,19 @@ static int max6642_detect(struct i2c_client *client,
>  	if (man_id != 0x4D)
>  		return -ENODEV;
> 
> +	/* sanity check */
> +	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_1);
> +	if (dummy_reg != 0x4D)
> +		return -ENODEV;
> +
> +	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_2);
> +	if (dummy_reg != 0x4D)
> +		return -ENODEV;
> +
> +	dummy_reg = i2c_smbus_read_byte_data(client, MAX6642_REG_R_DUMMY_3);
> +	if (dummy_reg != 0x4D)
> +		return -ENODEV;
> +

Same as for sensors-detect, please do a second round of checks after
reading the config or status register. You may want to move the checks
to a small function to avoid repeating the code.

>  	/*
>  	 * We read the config and status register, the 4 lower bits in the
>  	 * config register should be zero and bit 5, 3, 1 and 0 should be
> 


-- 
Jean Delvare

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

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

end of thread, other threads:[~2011-05-26 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-26 13:08 [lm-sensors] [PATCH v2] MAX6642: Better detection schema Per Dalén
2011-05-26 13:52 ` Guenter Roeck
2011-05-26 19:39 ` Jean Delvare

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.