All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
To: "Jon Arne Jørgensen" <jonarne@jonarne.no>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	hverkuil@xs4all.nl, elezegarcia@gmail.com
Subject: Re: [RFC V1 3/8] smi2021: Add smi2021_i2c.c
Date: Fri, 15 Mar 2013 09:27:54 -0300	[thread overview]
Message-ID: <20130315122753.GD2989@localhost> (raw)
In-Reply-To: <1363270024-12127-4-git-send-email-jonarne@jonarne.no>

On Thu, Mar 14, 2013 at 03:06:59PM +0100, Jon Arne Jørgensen wrote:
> This file is responsible for registering the device
> with the kernel i2c subsystem.
> v4l2 talks to the saa7113 chip of the device via i2c.
> 
> Signed-off-by: Jon Arne Jørgensen <jonarne@jonarne.no>
> ---
>  drivers/media/usb/smi2021/smi2021_i2c.c | 160 ++++++++++++++++++++++++++++++++
>  1 file changed, 160 insertions(+)
>  create mode 100644 drivers/media/usb/smi2021/smi2021_i2c.c
> 
> diff --git a/drivers/media/usb/smi2021/smi2021_i2c.c b/drivers/media/usb/smi2021/smi2021_i2c.c
> new file mode 100644
> index 0000000..5b6f3f5
> --- /dev/null
> +++ b/drivers/media/usb/smi2021/smi2021_i2c.c
> @@ -0,0 +1,160 @@
> +/*******************************************************************************
> + * smi2021_i2c.c                                                               *
> + *                                                                             *
> + * USB Driver for SMI2021 - EasyCAP                                            *
> + * USB ID 1c88:003c                                                            *
> + *                                                                             *
> + * *****************************************************************************
> + *
> + * Copyright 2011-2013 Jon Arne Jørgensen
> + * <jonjon.arnearne--a.t--gmail.com>
> + *
> + * Copyright 2011, 2012 Tony Brown, Michal Demin, Jeffry Johnston
> + *
> + * This file is part of SMI2021
> + * http://code.google.com/p/easycap-somagic-linux/
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, see <http://www.gnu.org/licenses/>.
> + *
> + * This driver is heavily influensed by the STK1160 driver.
> + * Copyright (C) 2012 Ezequiel Garcia
> + * <elezegarcia--a.t--gmail.com>
> + *
> + */
> +
> +#include "smi2021.h"
> +
> +/* The device will not return the chip_name on address 0x00.
> + * But the saa7115 i2c driver needs the chip id to match "f7113"
> + * if we want to use it,
> + * so we have to fake the return of this value
> + */

This comment style is wrong, check Documentation/CodingStyle.

BTW, Did you check the patches with checkpatch.pl?
(you can add checkpatch.pl as a git pre-commit hook, which I find very useful)

> +
> +static char chip_id[] = { 'x', 255, 55, 49, 49, 115, 0 };
> +static int id_ptr;
> +
> +static unsigned int i2c_debug;
> +module_param(i2c_debug, int, 0644);
> +MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
> +
> +#define dprint_i2c(fmt, args...)					\
> +do {									\
> +	if (i2c_debug)							\
> +		pr_debug("smi2021[i2c]::%s: " fmt, __func__, ##args);	\
> +} while (0)
> +
> +
> +static int i2c_xfer(struct i2c_adapter *i2c_adap,
> +				struct i2c_msg msgs[], int num)
> +{
> +	struct smi2021_dev *dev = i2c_adap->algo_data;
> +
> +	switch (num) {
> +	case 2: { /* Read reg */

Do you need a local scope in here?

> +		if (msgs[0].len != 1 || msgs[1].len != 1) {
> +			dprint_i2c("both messages must be 1 byte\n");
> +			goto err_out;
> +

I think you missed a closing } here. And an opening { below...

> +		if ((msgs[1].flags & I2C_M_RD) != I2C_M_RD)
> +			dprint_i2c("last message should have rd flag\n");
> +			goto err_out;
> +		}
> +
> +		if (msgs[0].buf[0] == 0) {
> +			msgs[1].buf[0] = chip_id[id_ptr];
> +			if (chip_id[id_ptr] != 0)
> +				id_ptr += 1;
> +		} else {
> +			smi2021_read_reg(dev, msgs[0].addr, msgs[0].buf[0],
> +						msgs[1].buf);
> +		}
> +		break;
> +	}
> +	case 1: { /* Write reg */
> +		if (msgs[0].len == 0) {
> +			break;
> +		} else if (msgs[0].len != 2) {
> +			dprint_i2c("unsupported len\n");
> +			goto err_out;
> +		}
> +		if (msgs[0].buf[0] == 0) {
> +			/* We don't handle writing to addr 0x00 */
> +			break;
> +		}
> +
> +		smi2021_write_reg(dev, msgs[0].addr, msgs[0].buf[0],
> +						msgs[0].buf[1]);
> +		break;
> +	}
> +	default: {
> +		dprint_i2c("driver can only handle 1 or 2 messages\n");
> +		goto err_out;
> +	}
> +	}
> +	return num;
> +
> +err_out:
> +	return -EOPNOTSUPP;
> +}
> +
> +static u32 functionality(struct i2c_adapter *adap)
> +{
> +	return I2C_FUNC_SMBUS_EMUL;
> +}
> +
> +static struct i2c_algorithm algo = {
> +	.master_xfer = i2c_xfer,
> +	.functionality = functionality,
> +};
> +
> +static struct i2c_adapter adap_template = {
> +	.owner = THIS_MODULE,
> +	.name = "smi2021_easycap_dc60",
> +	.algo = &algo,
> +};
> +
> +static struct i2c_client client_template = {
> +	.name = "smi2021 internal",
> +};
> +
> +int smi2021_i2c_register(struct smi2021_dev *dev)
> +{
> +	int rc;
> +
> +	id_ptr = 0;

You don't need to initialize id_ptr here.

> +
> +	dev->i2c_adap = adap_template;
> +	dev->i2c_adap.dev.parent = dev->dev;
> +	strcpy(dev->i2c_adap.name, "smi2021");
> +	dev->i2c_adap.algo_data = dev;
> +
> +	i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
> +
> +	rc = i2c_add_adapter(&dev->i2c_adap);
> +	if (rc < 0) {
> +		smi2021_err("can't add i2c adapter, errno: %d\n", rc);
> +		return rc;
> +	}
> +
> +	dev->i2c_client = client_template;
> +	dev->i2c_client.adapter = &dev->i2c_adap;
> +
> +	return 0;
> +}
> +
> +int smi2021_i2c_unregister(struct smi2021_dev *dev)
> +{
> +	i2c_del_adapter(&dev->i2c_adap);
> +	return 0;
> +}
> -- 
> 1.8.1.1
> 

-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

  reply	other threads:[~2013-03-15 12:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-14 14:06 [RFC V1 0/8] Add a driver for somagic smi2021 Jon Arne Jørgensen
2013-03-14 14:06 ` [RFC V1 1/8] smi2021: Add the header file Jon Arne Jørgensen
2013-03-15 12:13   ` Ezequiel Garcia
2013-03-17 20:16     ` Jon Arne Jørgensen
2013-03-14 14:06 ` [RFC V1 2/8] smi2021: Add smi2021_main.c Jon Arne Jørgensen
2013-03-15 12:20   ` Ezequiel Garcia
2013-03-17 20:14     ` Jon Arne Jørgensen
2013-03-18  7:58   ` Hans Verkuil
2013-03-20  9:30     ` Jon Arne Jørgensen
2013-03-18  8:30   ` Hans Verkuil
2013-03-20  9:31     ` Jon Arne Jørgensen
2013-03-14 14:06 ` [RFC V1 3/8] smi2021: Add smi2021_i2c.c Jon Arne Jørgensen
2013-03-15 12:27   ` Ezequiel Garcia [this message]
2013-03-17 19:59     ` Jon Arne Jørgensen
2013-03-18  8:04   ` Hans Verkuil
2013-03-20  9:32     ` Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 4/8] smi2021: Add smi2021_v4l2.c Jon Arne Jørgensen
2013-03-15 12:33   ` Ezequiel Garcia
2013-03-17 20:27     ` Jon Arne Jørgensen
2013-03-18  8:12   ` Hans Verkuil
2013-03-20  9:43     ` Jon Arne Jørgensen
2013-03-20 10:07       ` Hans Verkuil
2013-03-18  8:29   ` Hans Verkuil
2013-03-20  9:48     ` Jon Arne Jørgensen
2013-03-20 10:10       ` Hans Verkuil
2013-03-20 10:16         ` Jon Arne Jørgensen
2013-03-20 10:21           ` Hans Verkuil
2013-03-20 11:09             ` Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 5/8] smi2021: Add smi2021_video.c Jon Arne Jørgensen
2013-03-15 12:40   ` Ezequiel Garcia
2013-03-17 20:19     ` Jon Arne Jørgensen
2013-03-18  8:17   ` Hans Verkuil
2013-03-18  8:58     ` Bjørn Mork
2013-03-20 10:06       ` Jon Arne Jørgensen
2013-03-20 10:09         ` Hans Verkuil
2013-03-14 14:07 ` [RFC V1 6/8] smi2021: Add smi2021_audio.c Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 7/8] smi2021: Add smi2021_bl.c Jon Arne Jørgensen
2013-03-18  9:31   ` Bjørn Mork
2013-03-20  8:59     ` Jon Arne Jørgensen
2013-03-14 14:07 ` [RFC V1 8/8] smi2021: Add Kconfig and Makefiles Jon Arne Jørgensen
2013-03-15 12:08 ` [RFC V1 0/8] Add a driver for somagic smi2021 Ezequiel Garcia
2013-03-17 20:01   ` Jon Arne Jørgensen
2013-03-18  0:05     ` Ezequiel Garcia
2013-03-20 10:11       ` Jon Arne Jørgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130315122753.GD2989@localhost \
    --to=ezequiel.garcia@free-electrons.com \
    --cc=elezegarcia@gmail.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jonarne@jonarne.no \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.