mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 5/7] i2c: add stm32f7 I2C adapter driver
Date: Fri, 12 Jul 2019 07:09:31 +0200	[thread overview]
Message-ID: <20190712050931.5icq2vgdd5uobvzw@pengutronix.de> (raw)
In-Reply-To: <20190710201112.9086-5-a.fatoum@pengutronix.de>

On Wed, Jul 10, 2019 at 10:11:10PM +0200, Ahmad Fatoum wrote:
> +
> +static int stm32_i2c_check_end_of_message(struct stm32_i2c *i2c_priv)
> +{
> +	struct stm32_i2c_regs *regs = i2c_priv->regs;
> +	u32 mask = STM32_I2C_ISR_ERRORS | STM32_I2C_ISR_NACKF |
> +		   STM32_I2C_ISR_STOPF;
> +	u32 status;
> +	int ret;
> +
> +	ret = stm32_i2c_wait_flags(i2c_priv, mask, &status);
> +	if (ret)
> +		return ret;
> +
> +	if (status & STM32_I2C_ISR_BERR) {
> +		debug("%s: Bus error\n", __func__);

Please replace with dev_dbg and friends.

> +
> +static int stm32_i2c_message_xfer(struct stm32_i2c *i2c_priv,
> +				  struct i2c_msg *msg, bool stop)
> +{
> +	struct stm32_i2c_regs *regs = i2c_priv->regs;
> +	u32 status;
> +	u32 mask = msg->flags & I2C_M_RD ? STM32_I2C_ISR_RXNE :
> +		   STM32_I2C_ISR_TXIS | STM32_I2C_ISR_NACKF;
> +	int bytes_to_rw = msg->len > STM32_I2C_MAX_LEN ?
> +			  STM32_I2C_MAX_LEN : msg->len;
> +	int ret = 0;
> +
> +	/* Add errors */
> +	mask |= STM32_I2C_ISR_ERRORS;
> +
> +	stm32_i2c_message_start(i2c_priv, msg, stop);
> +
> +	while (msg->len) {
> +		/*
> +		 * Wait until TXIS/NACKF/BERR/ARLO flags or
> +		 * RXNE/BERR/ARLO flags are set
> +		 */
> +		ret = stm32_i2c_wait_flags(i2c_priv, mask, &status);
> +		if (ret)
> +			break;
> +
> +		if (status & (STM32_I2C_ISR_NACKF | STM32_I2C_ISR_ERRORS))
> +			break;
> +
> +		if (status & STM32_I2C_ISR_RXNE) {
> +			*msg->buf++ = readb(&regs->rxdr);
> +			msg->len--;

The driver shouldn't modify the message. Please create local variables
for the length counter and buf pointer.

> +
> +static int __init stm32_i2c_probe(struct device_d *dev)
> +{
> +	struct device_node *np = dev->device_node;
> +	struct resource *iores;
> +	struct stm32_i2c *stm32_i2c;
> +	struct i2c_platform_data *pdata;
> +	struct reset_control *rst;
> +	const struct stm32_i2c_setup *setup;
> +	int bitrate;
> +	int ret;
> +
> +	pdata = dev->platform_data;
> +
> +	stm32_i2c = xzalloc(sizeof(*stm32_i2c));
> +
> +	stm32_i2c->clk = clk_get(dev, NULL);
> +	if (IS_ERR(stm32_i2c->clk))
> +		return PTR_ERR(stm32_i2c->clk);
> +	clk_enable(stm32_i2c->clk);
> +
> +	rst = reset_control_get(dev, NULL);
> +	if (IS_ERR(rst))
> +		return PTR_ERR(rst);
> +
> +	reset_control_assert(rst);
> +	udelay(2);
> +	reset_control_deassert(rst);
> +
> +	ret = dev_get_drvdata(dev, (const void **)&setup);
> +	if (ret)
> +		return ret;
> +
> +	stm32_i2c->setup = *setup;
> +
> +	of_property_read_u32(np, "i2c-scl-rising-time-ns",
> +				   &stm32_i2c->setup.rise_time);
> +	of_property_read_u32(np, "i2c-scl-falling-time-ns",
> +				   &stm32_i2c->setup.fall_time);

The Kernel has a helper function for reading these generic properties.
Can we have a similar function?

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

  reply	other threads:[~2019-07-12  5:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 20:11 [PATCH 1/7] gpio: allow for arch-specific ARCH_NR_GPIOS > 256 Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 2/7] ARM: stm32mp: set CONFIG_ARCH_NR_GPIO = (26 * 16) Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 3/7] ARM: dts: stm32mp157c: correct gpioz id Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 4/7] reset: add reset controller driver for STM32 RCC Ahmad Fatoum
2019-07-10 21:28   ` [PATCH] fixup! " Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 5/7] i2c: add stm32f7 I2C adapter driver Ahmad Fatoum
2019-07-12  5:09   ` Sascha Hauer [this message]
2019-07-10 20:11 ` [PATCH 6/7] mfd: add support for STPMIC1 Ahmad Fatoum
2019-07-10 20:11 ` [PATCH 7/7] watchdog: add support for STPMIC1 integrated watchdog Ahmad Fatoum
2019-07-15  6:42 ` [PATCH 1/7] gpio: allow for arch-specific ARCH_NR_GPIOS > 256 Sascha Hauer

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=20190712050931.5icq2vgdd5uobvzw@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --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