From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Subject: Re: [PATCH V1 1/1] iio: Added Capella cm3232 ambient light sensor driver. Date: Mon, 05 Jan 2015 05:09:56 -0800 Message-ID: <1420463396.2652.8.camel@perches.com> References: <1420071030-888-1-git-send-email-ktsai@capellamicro.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Daniel Baluta Cc: Kevin Tsai , Wolfram Sang , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Mauro Carvalho Chehab , Antti Palosaari , Archana Patni , linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , Linux Kernel Mailing List List-Id: linux-i2c@vger.kernel.org On Mon, 2015-01-05 at 12:51 +0200, Daniel Baluta wrote: > On Thu, Jan 1, 2015 at 2:10 AM, Kevin Tsai wrote: > > CM3232 is an advanced ambient light sensor with I2C protocol interface. > > The I2C slave address is internally hardwired as 0x10 (7-bit). Writing > > to configure register is byte mode, but reading ALS register requests to > > use word mode for 16-bit resolution. > > This looks good to me. Few comments inline. [] > > diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c [] > > +/** > > + * cm3232_reg_init() - Initialize CM3232 registers > > + * @chip: pointer of struct cm3232. > > + * > > + * Initialize CM3232 ambient light sensor register to default values. > > + * > > + Return: 0 for success; otherwise for error code. > > + */ > > +static int cm3232_reg_init(struct cm3232_chip *chip) > > +{ > > + struct i2c_client *client = chip->client; > > + struct cm3232_als_info *als_info; > > + s32 ret; > > + > > + /* Identify device */ > > + ret = i2c_smbus_read_word_data(client, CM3232_REG_ADDR_ID); > > + if (ret < 0) > > + return ret; > > + if ((ret & 0xFF) != 0x32) > > + return -ENODEV; > > + > > + /* Disable and reset device */ > > + chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET; > > + ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD, > > + chip->regs_cmd); > > + if (ret < 0) > > + return ret; > > + > > + /* Initialization */ > > + als_info = chip->als_info = &cm3232_als_info_default; > > + chip->regs_cmd = CM3232_CMD_DEFAULT; > > + > > + /* Configure register */ > > + ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD, > > + chip->regs_cmd); > > You could directly return i2c_smbus_write_byte_data(..). Sometimes it's better to return a specific value for the error instead of depending on correctness of all the indirect functions in the call chain. In this case, all the smbus_xfer functions must return 0 on success. Do they? Inspecting the codebase for correctness or not depending on that correctness is sometimes better to avoid doing. > > + if (ret < 0) > > + return ret; > > + > > + return 0; > > +} -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Message-ID: <1420463396.2652.8.camel@perches.com> Subject: Re: [PATCH V1 1/1] iio: Added Capella cm3232 ambient light sensor driver. From: Joe Perches To: Daniel Baluta Cc: Kevin Tsai , Wolfram Sang , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Mauro Carvalho Chehab , Antti Palosaari , Archana Patni , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, "linux-iio@vger.kernel.org" , Linux Kernel Mailing List Date: Mon, 05 Jan 2015 05:09:56 -0800 In-Reply-To: References: <1420071030-888-1-git-send-email-ktsai@capellamicro.com> Content-Type: text/plain; charset="ISO-8859-1" Mime-Version: 1.0 List-ID: On Mon, 2015-01-05 at 12:51 +0200, Daniel Baluta wrote: > On Thu, Jan 1, 2015 at 2:10 AM, Kevin Tsai wrote: > > CM3232 is an advanced ambient light sensor with I2C protocol interface. > > The I2C slave address is internally hardwired as 0x10 (7-bit). Writing > > to configure register is byte mode, but reading ALS register requests to > > use word mode for 16-bit resolution. > > This looks good to me. Few comments inline. [] > > diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c [] > > +/** > > + * cm3232_reg_init() - Initialize CM3232 registers > > + * @chip: pointer of struct cm3232. > > + * > > + * Initialize CM3232 ambient light sensor register to default values. > > + * > > + Return: 0 for success; otherwise for error code. > > + */ > > +static int cm3232_reg_init(struct cm3232_chip *chip) > > +{ > > + struct i2c_client *client = chip->client; > > + struct cm3232_als_info *als_info; > > + s32 ret; > > + > > + /* Identify device */ > > + ret = i2c_smbus_read_word_data(client, CM3232_REG_ADDR_ID); > > + if (ret < 0) > > + return ret; > > + if ((ret & 0xFF) != 0x32) > > + return -ENODEV; > > + > > + /* Disable and reset device */ > > + chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET; > > + ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD, > > + chip->regs_cmd); > > + if (ret < 0) > > + return ret; > > + > > + /* Initialization */ > > + als_info = chip->als_info = &cm3232_als_info_default; > > + chip->regs_cmd = CM3232_CMD_DEFAULT; > > + > > + /* Configure register */ > > + ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD, > > + chip->regs_cmd); > > You could directly return i2c_smbus_write_byte_data(..). Sometimes it's better to return a specific value for the error instead of depending on correctness of all the indirect functions in the call chain. In this case, all the smbus_xfer functions must return 0 on success. Do they? Inspecting the codebase for correctness or not depending on that correctness is sometimes better to avoid doing. > > + if (ret < 0) > > + return ret; > > + > > + return 0; > > +}