mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] i2c: Add support for DesignWare controllers
Date: Mon, 2 Nov 2015 09:30:07 +0100	[thread overview]
Message-ID: <20151102083007.GC17132@pengutronix.de> (raw)
In-Reply-To: <1446352242-8053-1-git-send-email-andrew.smirnov@gmail.com>

On Sat, Oct 31, 2015 at 09:30:41PM -0700, Andrey Smirnov wrote:
> Add a driver for DesignWare I2C controller IP block found on several
> SoCs including Altera SoC products
> 
> Tested using Terrasic SoCKit board and GPIO expander board with I2C
> EEPROM on it
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---

Looks mostly fine. Two small nitpicks inside.


> +static int i2c_dw_probe(struct device_d *pdev)
> +{
> +	struct dw_i2c_dev *dw;
> +	struct i2c_platform_data *pdata;
> +	int ret, bitrate;
> +	uint32_t ic_con, ic_comp_type_value;
> +
> +	pdata = pdev->platform_data;
> +
> +	dw = kzalloc(sizeof(*dw), GFP_KERNEL);

kzalloc can fail. You should use xzalloc here which cannot fail.

> +
> +	if (IS_ENABLED(CONFIG_COMMON_CLK)) {
> +		dw->clk = clk_get(pdev, NULL);
> +		if (IS_ERR(dw->clk)) {
> +			ret = PTR_ERR(dw->clk);
> +			goto fail;
> +		}
> +	}
> +
> +	dw->adapter.master_xfer = i2c_dw_xfer;
> +	dw->adapter.nr = pdev->id;
> +	dw->adapter.dev.parent = pdev;
> +	dw->adapter.dev.device_node = pdev->device_node;
> +
> +	dw->base = dev_request_mem_region(pdev, 0);
> +	if (IS_ERR(dw->base)) {
> +		ret = PTR_ERR(dw->base);
> +		goto fail;
> +	}
> +
> +	ic_comp_type_value = readl(dw->base + DW_IC_COMP_TYPE);
> +	if (ic_comp_type_value != DW_IC_COMP_TYPE_VALUE) {
> +		dev_err(pdev,
> +			"unknown DesignWare IP block 0x%08x",
> +			ic_comp_type_value);
> +		ret = -ENODEV;
> +		goto fail;
> +	}
> +
> +	i2c_dw_enable(dw, false);
> +
> +	if (IS_ENABLED(CONFIG_COMMON_CLK))
> +		i2c_dw_setup_timings(dw);
> +
> +	bitrate = (pdata && pdata->bitrate) ? pdata->bitrate : DW_I2C_BIT_RATE;
> +
> +	/*
> +	 * We have to clear 'ic_10bitaddr_master' in 'ic_tar'
> +	 * register, otherwise 'ic_10bitaddr_master' in 'ic_con'
> +	 * wouldn't clear. We don't care about preserving the contents
> +	 * of that register so we set it to zero.
> +	 */
> +	writel(0, dw->base + DW_IC_TAR);
> +
> +	switch (bitrate) {
> +	case 400000:
> +		ic_con = DW_IC_CON_SPEED_FAST;
> +		break;
> +	default:
> +		dev_warn(pdev, "requested bitrate (%d) is not supported."
> +			 " Falling back to 100kHz", bitrate);
> +	case 100000:		/* FALLTHROUGH */
> +		ic_con = DW_IC_CON_SPEED_STD;
> +		break;
> +	}
> +
> +	ic_con |= DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE;
> +
> +	writel(ic_con, dw->base + DW_IC_CON);
> +
> +	/*
> +	 * Since we will be working in polling mode set both
> +	 * thresholds to their minimum
> +	 */
> +	writel(0, dw->base + DW_IC_RX_TL);
> +	writel(0, dw->base + DW_IC_TX_TL);
> +
> +	/* Disable and clear all interrrupts */
> +	writel(0, dw->base + DW_IC_INTR_MASK);
> +	readl(dw->base + DW_IC_CLR_INTR);
> +
> +	i2c_dw_enable(dw, true);
> +
> +	ret = i2c_add_numbered_adapter(&dw->adapter);
> +fail:
> +	if (ret < 0) {
> +		dev_err(pdev, "registration failed\n");

This message is unnecessary. The driver core will warn you when probe
fails anyway.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2015-11-02  8:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-01  4:30 Andrey Smirnov
2015-11-01  4:30 ` [PATCH] memtest: Fix reference to non-existing function Andrey Smirnov
2015-11-02  8:30 ` Sascha Hauer [this message]

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=20151102083007.GC17132@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.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