linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] input: mma8450: Add chip ID check in probe
@ 2024-12-13 22:23 Frank Li
  2024-12-13 23:02 ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2024-12-13 22:23 UTC (permalink / raw)
  To: Dmitry Torokhov, Luwei Zhou, Vipul Kumar, Dong Aisheng,
	Uwe Kleine-König,
	open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list
  Cc: imx

From: Luwei Zhou <b45643@freescale.com>

Prevent continuous polling error logs by adding a chip ID check in the
probe  function. This ensures the driver only proceeds when the mma8450 is
present, avoiding issues in scenarios like missing add-on cards.

Signed-off-by: Luwei Zhou <b45643@freescale.com>
Signed-off-by: Fugang Duan <B38611@freescale.com>
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/input/misc/mma8450.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
index 08412239b8e69..da941748ed29b 100644
--- a/drivers/input/misc/mma8450.c
+++ b/drivers/input/misc/mma8450.c
@@ -38,6 +38,8 @@
 
 #define MMA8450_CTRL_REG1	0x38
 #define MMA8450_CTRL_REG2	0x39
+#define MMA8450_ID		0xc6
+#define MMA8450_WHO_AM_I	0x0f
 
 static int mma8450_read(struct i2c_client *c, unsigned int off)
 {
@@ -148,8 +150,20 @@ static void mma8450_close(struct input_dev *input)
  */
 static int mma8450_probe(struct i2c_client *c)
 {
+	struct i2c_adapter *adapter = to_i2c_adapter(c->dev.parent);
 	struct input_dev *input;
-	int err;
+	int err, client_id;
+
+	err = i2c_check_functionality(adapter,
+				      I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA);
+	if (!err)
+		return err;
+
+	client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
+	if (client_id != MMA8450_ID)
+		return dev_err_probe(&c->dev, -EINVAL,
+				     "read chip ID 0x%x is not equal to 0x%x!\n",
+				     client_id, MMA8450_ID);
 
 	input = devm_input_allocate_device(&c->dev);
 	if (!input)
-- 
2.34.1


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

* Re: [PATCH 1/1] input: mma8450: Add chip ID check in probe
  2024-12-13 22:23 [PATCH 1/1] input: mma8450: Add chip ID check in probe Frank Li
@ 2024-12-13 23:02 ` Uwe Kleine-König
  2024-12-16 16:30   ` Frank Li
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2024-12-13 23:02 UTC (permalink / raw)
  To: Frank Li
  Cc: Dmitry Torokhov, Luwei Zhou, Vipul Kumar, Dong Aisheng,
	open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, imx

[-- Attachment #1: Type: text/plain, Size: 2093 bytes --]

Hello Frank,

On Fri, Dec 13, 2024 at 05:23:09PM -0500, Frank Li wrote:
> From: Luwei Zhou <b45643@freescale.com>
> 
> Prevent continuous polling error logs by adding a chip ID check in the
> probe  function. This ensures the driver only proceeds when the mma8450 is
> present, avoiding issues in scenarios like missing add-on cards.
> 
> Signed-off-by: Luwei Zhou <b45643@freescale.com>
> Signed-off-by: Fugang Duan <B38611@freescale.com>
> Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
>  drivers/input/misc/mma8450.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> index 08412239b8e69..da941748ed29b 100644
> --- a/drivers/input/misc/mma8450.c
> +++ b/drivers/input/misc/mma8450.c
> @@ -38,6 +38,8 @@
>  
>  #define MMA8450_CTRL_REG1	0x38
>  #define MMA8450_CTRL_REG2	0x39
> +#define MMA8450_ID		0xc6
> +#define MMA8450_WHO_AM_I	0x0f
>  
>  static int mma8450_read(struct i2c_client *c, unsigned int off)
>  {
> @@ -148,8 +150,20 @@ static void mma8450_close(struct input_dev *input)
>   */
>  static int mma8450_probe(struct i2c_client *c)
>  {
> +	struct i2c_adapter *adapter = to_i2c_adapter(c->dev.parent);

+	struct i2c_adapter *adapter = c->adapter;

>  	struct input_dev *input;
> -	int err;
> +	int err, client_id;
> +
> +	err = i2c_check_functionality(adapter,
> +				      I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA);
> +	if (!err)
> +		return err;

How unusual. I would have expected no ! here.

> +	client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
> +	if (client_id != MMA8450_ID)
> +		return dev_err_probe(&c->dev, -EINVAL,
> +				     "read chip ID 0x%x is not equal to 0x%x!\n",
> +				     client_id, MMA8450_ID);

Given that here you emit an error message, maybe add an error message
above, too?

>  	input = devm_input_allocate_device(&c->dev);
>  	if (!input)

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 1/1] input: mma8450: Add chip ID check in probe
  2024-12-13 23:02 ` Uwe Kleine-König
@ 2024-12-16 16:30   ` Frank Li
  2024-12-16 17:14     ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2024-12-16 16:30 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Dmitry Torokhov, Luwei Zhou, Vipul Kumar, Dong Aisheng,
	open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, imx

On Sat, Dec 14, 2024 at 12:02:56AM +0100, Uwe Kleine-König wrote:
> Hello Frank,
>
> On Fri, Dec 13, 2024 at 05:23:09PM -0500, Frank Li wrote:
> > From: Luwei Zhou <b45643@freescale.com>
> >
> > Prevent continuous polling error logs by adding a chip ID check in the
> > probe  function. This ensures the driver only proceeds when the mma8450 is
> > present, avoiding issues in scenarios like missing add-on cards.
> >
> > Signed-off-by: Luwei Zhou <b45643@freescale.com>
> > Signed-off-by: Fugang Duan <B38611@freescale.com>
> > Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
> > Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> >  drivers/input/misc/mma8450.c | 16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> > index 08412239b8e69..da941748ed29b 100644
> > --- a/drivers/input/misc/mma8450.c
> > +++ b/drivers/input/misc/mma8450.c
> > @@ -38,6 +38,8 @@
> >
> >  #define MMA8450_CTRL_REG1	0x38
> >  #define MMA8450_CTRL_REG2	0x39
> > +#define MMA8450_ID		0xc6
> > +#define MMA8450_WHO_AM_I	0x0f
> >
> >  static int mma8450_read(struct i2c_client *c, unsigned int off)
> >  {
> > @@ -148,8 +150,20 @@ static void mma8450_close(struct input_dev *input)
> >   */
> >  static int mma8450_probe(struct i2c_client *c)
> >  {
> > +	struct i2c_adapter *adapter = to_i2c_adapter(c->dev.parent);
>
> +	struct i2c_adapter *adapter = c->adapter;
>
> >  	struct input_dev *input;
> > -	int err;
> > +	int err, client_id;
> > +
> > +	err = i2c_check_functionality(adapter,
> > +				      I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA);
> > +	if (!err)
> > +		return err;
>
> How unusual. I would have expected no ! here.

yes, it should be better

	if (!i2c_check_functionality())
		....

i2c_check_functionality() return 1 if adapter supports everything we need.

Frank

>
> > +	client_id = i2c_smbus_read_byte_data(c, MMA8450_WHO_AM_I);
> > +	if (client_id != MMA8450_ID)
> > +		return dev_err_probe(&c->dev, -EINVAL,
> > +				     "read chip ID 0x%x is not equal to 0x%x!\n",
> > +				     client_id, MMA8450_ID);
>
> Given that here you emit an error message, maybe add an error message
> above, too?
>
> >  	input = devm_input_allocate_device(&c->dev);
> >  	if (!input)
>
> Best regards
> Uwe



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

* Re: [PATCH 1/1] input: mma8450: Add chip ID check in probe
  2024-12-16 16:30   ` Frank Li
@ 2024-12-16 17:14     ` Dmitry Torokhov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2024-12-16 17:14 UTC (permalink / raw)
  To: Frank Li
  Cc: Uwe Kleine-König, Luwei Zhou, Vipul Kumar, Dong Aisheng,
	open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, imx

On Mon, Dec 16, 2024 at 11:30:15AM -0500, Frank Li wrote:
> On Sat, Dec 14, 2024 at 12:02:56AM +0100, Uwe Kleine-König wrote:
> > Hello Frank,
> >
> > On Fri, Dec 13, 2024 at 05:23:09PM -0500, Frank Li wrote:
> > > From: Luwei Zhou <b45643@freescale.com>
> > >
> > > Prevent continuous polling error logs by adding a chip ID check in the
> > > probe  function. This ensures the driver only proceeds when the mma8450 is
> > > present, avoiding issues in scenarios like missing add-on cards.
> > >
> > > Signed-off-by: Luwei Zhou <b45643@freescale.com>
> > > Signed-off-by: Fugang Duan <B38611@freescale.com>
> > > Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
> > > Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> > > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > > ---
> > >  drivers/input/misc/mma8450.c | 16 +++++++++++++++-
> > >  1 file changed, 15 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c
> > > index 08412239b8e69..da941748ed29b 100644
> > > --- a/drivers/input/misc/mma8450.c
> > > +++ b/drivers/input/misc/mma8450.c
> > > @@ -38,6 +38,8 @@
> > >
> > >  #define MMA8450_CTRL_REG1	0x38
> > >  #define MMA8450_CTRL_REG2	0x39
> > > +#define MMA8450_ID		0xc6
> > > +#define MMA8450_WHO_AM_I	0x0f
> > >
> > >  static int mma8450_read(struct i2c_client *c, unsigned int off)
> > >  {
> > > @@ -148,8 +150,20 @@ static void mma8450_close(struct input_dev *input)
> > >   */
> > >  static int mma8450_probe(struct i2c_client *c)
> > >  {
> > > +	struct i2c_adapter *adapter = to_i2c_adapter(c->dev.parent);
> >
> > +	struct i2c_adapter *adapter = c->adapter;
> >
> > >  	struct input_dev *input;
> > > -	int err;
> > > +	int err, client_id;
> > > +
> > > +	err = i2c_check_functionality(adapter,
> > > +				      I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA);
> > > +	if (!err)
> > > +		return err;
> >
> > How unusual. I would have expected no ! here.
> 
> yes, it should be better
> 
> 	if (!i2c_check_functionality())
> 		....
> 
> i2c_check_functionality() return 1 if adapter supports everything we need.

Yes, it would be much better, otherwise in the case when an adapter does
not support the required functionality your code returns 0 which signals
successful probing.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2024-12-16 17:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-13 22:23 [PATCH 1/1] input: mma8450: Add chip ID check in probe Frank Li
2024-12-13 23:02 ` Uwe Kleine-König
2024-12-16 16:30   ` Frank Li
2024-12-16 17:14     ` Dmitry Torokhov

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