public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: Tim Kryger <tim.kryger@linaro.org>
Cc: Christian Daudt <bcm@fixthebug.org>,
	Rob Herring <rob.herring@calxeda.com>,
	Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Rob Landley <rob@landley.net>,
	Grant Likely <grant.likely@linaro.org>,
	devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [RESEND PATCH 1/4] i2c: i2c-bcm-kona: Introduce Broadcom I2C Driver
Date: Fri, 1 Nov 2013 13:49:58 +0100	[thread overview]
Message-ID: <20131101124958.GB6734@katana> (raw)
In-Reply-To: <1381960909-1735-2-git-send-email-tim.kryger@linaro.org>

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

On Wed, Oct 16, 2013 at 03:01:46PM -0700, Tim Kryger wrote:
> Introduce support for Broadcom Serial Controller (BSC) I2C bus found
> in the Kona family of Mobile SoCs.  FIFO hardware is utilized but only
> standard mode (100kHz), fast mode (400kHz), and fast mode plus (1MHz)
> bus speeds are supported.
> 
> Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
> Reviewed-by: Matt Porter <matt.porter@linaro.org>
> Reviewed-by: Markus Mayer <markus.mayer@linaro.org>

Looks mostly good, some remarks:

> +struct bcm_kona_i2c_dev {
> +	/* Pointer to linux device struct */
> +	struct device *device;
> +
> +	/* Virtual address where registers are mapped */
> +	void __iomem *base;
> +
> +	/* Interrupt */
> +	int irq;
> +
> +	/* Standard Speed configuration */
> +	const struct bus_speed_cfg *std_cfg;
> +
> +	/* Linux I2C adapter struct */
> +	struct i2c_adapter adapter;
> +
> +	/* Lock for the I2C device */
> +	struct mutex i2c_bcm_lock;
> +
> +	/* Completion to signal an operation finished */
> +	struct completion done;
> +
> +	/* Handle for external clock */
> +	struct clk *external_clk;
> +};

IMO most of the comments could go. Kind of stating the obvious :)


> +/* Read any amount of data using the RX FIFO from the i2c bus */
> +static int bcm_kona_i2c_read_fifo(struct bcm_kona_i2c_dev *dev,
> +				  struct i2c_msg *msg)
> +{
> +	unsigned int bytes_to_read = MAX_RX_FIFO_SIZE;
> +	unsigned int last_byte_nak = 0;
> +	unsigned int bytes_read = 0;
> +	unsigned int rc;

Should be signed.

> +/* Write any amount of data using TX FIFO to the i2c bus */
> +static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
> +				   struct i2c_msg *msg)
> +{
> +	unsigned int bytes_to_write = MAX_TX_FIFO_SIZE;
> +	unsigned int bytes_written = 0;
> +	unsigned int rc;

Ditto signed.

> +/* Master transfer function */
> +static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
> +			     struct i2c_msg msgs[], int num)
> +{
> +	struct bcm_kona_i2c_dev *dev = i2c_get_adapdata(adapter);
> +	struct i2c_msg *pmsg;
> +	int rc = 0;
> +	int i;
> +
> +	mutex_lock(&dev->i2c_bcm_lock);

Huh? Why do you need that? The core has locks per bus.

> +static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
> +{
> +	unsigned int bus_speed;
> +	int ret = of_property_read_u32(dev->device->of_node, "clock-frequency",
> +				       &bus_speed);
> +	if (ret < 0) {
> +		dev_err(dev->device, "missing clock-frequency property\n");
> +		return -ENODEV;
> +	}
> +
> +	switch (bus_speed) {
> +	case 100000:
> +		dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
> +		break;
> +	case 400000:
> +		dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
> +		break;
> +	case 1000000:
> +		dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
> +		break;
> +	default:
> +		pr_err("%d hz bus speed not supported\n", bus_speed);
> +		return -EINVAL;
> +	};

Unneeded semicolon.

> +
> +	return 0;
> +}
> +
> +static int bcm_kona_i2c_probe(struct platform_device *pdev)
> +{
> +	int rc = 0;
> +	struct bcm_kona_i2c_dev *dev;
> +	struct i2c_adapter *adap;
> +	struct resource *iomem;
> +
> +	/* Allocate memory for private data structure */
> +	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
> +	if (!dev) {
> +		rc = -ENOMEM;
> +		goto probe_return;

I'd prefer simply return -Esomething. The printout at probe_return is
also available via driver core.

...

> +	/* Add the i2c adapter */
> +	adap = &dev->adapter;
> +	i2c_set_adapdata(adap, dev);
> +	adap->owner = THIS_MODULE;
> +	adap->class = UINT_MAX;	/* can be used by any I2C device */

Why do you need class based instantiation. It will most likely cost
boot-time and you have devicetree means for doing instantiation.


> +	strlcpy(adap->name, "Broadcom I2C adapter", sizeof(adap->name));
> +	adap->algo = &bcm_algo;
> +	adap->dev.parent = &pdev->dev;
> +	adap->nr = pdev->id;
> +	adap->dev.of_node = pdev->dev.of_node;
> +
> +	rc = i2c_add_numbered_adapter(adap);

Maybe you want simply i2c_add_adapter here since the core has no
built-in support for of aliases?

> +
> +MODULE_AUTHOR("Broadcom");

Some email address please.

> +MODULE_DESCRIPTION("Broadcom Kona I2C Driver");
> +MODULE_LICENSE("GPL v2");

Thanks,

   Wolfram


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2013-11-01 12:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16 22:01 [RESEND PATCH 0/4] Add-Broadcom-Kona-I2C-Support Tim Kryger
2013-10-16 22:01 ` [RESEND PATCH 1/4] i2c: i2c-bcm-kona: Introduce Broadcom I2C Driver Tim Kryger
2013-11-01 12:49   ` Wolfram Sang [this message]
2013-11-02  0:32     ` Tim Kryger
2013-10-16 22:01 ` [RESEND PATCH 2/4] i2c: i2c-bcm-kona: Add support for high-speed mode Tim Kryger
2013-11-01 13:08   ` Wolfram Sang
2013-11-07 19:57     ` Tim Kryger
2013-11-07 20:13       ` Wolfram Sang
2013-11-07 20:16         ` Tim Kryger
2013-10-16 22:01 ` [RESEND PATCH 3/4] ARM: dts: bcm281xx: Add i2c busses Tim Kryger
2013-10-17  4:32   ` Christian Daudt
2013-10-17 12:14     ` Matt Porter
2013-10-16 22:01 ` [RESEND PATCH 4/4] ARM: dts: bcm28155-ap: Enable all the " Tim Kryger

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=20131101124958.GB6734@katana \
    --to=wsa@the-dreams.de \
    --cc=bcm@fixthebug.org \
    --cc=devicetree@vger.kernel.org \
    --cc=grant.likely@linaro.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=swarren@wwwdotorg.org \
    --cc=tim.kryger@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox