From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/3] usb: lpc32xx: add host USB driver
Date: Sat, 18 Jul 2015 00:09:12 +0200 [thread overview]
Message-ID: <201507180009.12140.marex@denx.de> (raw)
In-Reply-To: <1437166134-21204-4-git-send-email-slemieux.tyco@gmail.com>
On Friday, July 17, 2015 at 10:48:54 PM, slemieux.tyco at gmail.com wrote:
> From: Sylvain Lemieux <slemieux@tycoint.com>
Hi!
> Incorporate DMA driver from legacy LPCLinux NXP BSP.
> The files taken from the legacy patch are:
> - lpc32xx USB driver
> - lpc3250 header file USB registers definition.
>
> Updated driver to integrate with the latest u-boot:
> 1) Fixed checkpatch script output in legacy code.
> 2) Use LPC32xx definition from "cpu.h" and "clk.h".
> 3) Incorporate USB specific register definition from "lpc3250.h" header
> file from legacy BSP patch from LPCLinux.
> 4) Use u-boot API for register access to remove the use of volatile in
> register definition taken from "lpc3250.h" header file.
> 5) Update driver for latest u-boot USB interface (board_usb init &
> board_usb_cleanup). 6) Use the peripheral clock to compute the I2C
> divider.
[...]
> +static int i2c_wait_reset(int timeout)
> +{
> + while (timeout > 0 && (readl(&otg->otg_i2c.otg_i2c_ctrl) & I2C_RESET)) {
> + udelay(1000);
> + timeout--;
> + }
> +
> + return timeout <= 0;
> +}
> +
> +static int isp1301_set_value(int reg, int value)
> +{
> + int n = 0;
> +
> + /* send isp1301 address */
> + writel((ISP1301_I2C_ADDR << 1) | I2C_START_BIT,
> + &otg->otg_i2c.otg_i2c_txrx);
> +
> + /* offset to write to */
> + writel((reg & 0xff) | I2C_WRITE, &otg->otg_i2c.otg_i2c_txrx);
> + /* value to write */
> + writel((value & 0xff) | I2C_STOP_BIT, &otg->otg_i2c.otg_i2c_txrx);
> +
> + /* wait for transmit done (TDI) */
> + while (((readl(&otg->otg_i2c.otg_i2c_stat) & I2C_TDI) != I2C_TDI) &&
> + n++ < 100000)
> + ;
Can you please rework the timeouts to use get_timer() ? It looks like this:
start = get_timer(0);
do {
if (readl(...) == FOO)
break;
udelay(1); /* Don't do tightloop and poke WDT */
} while (get_timer(start) < DELAY_IN_MSECS);
> + if (n >= 100000) {
> + printf("isp1301_set_value: ERROR TDI not set\n");
> + return -1;
> + }
> +
> + /* clear TDI */
> + setbits_le32(&otg->otg_i2c.otg_i2c_stat, I2C_TDI);
> +
> + return 0;
> +}
Don't you want to split this code out and make it into an actual i2c controller?
Then, the USB driver would use regular i2c_*() calls to configure the device on
the other end of the i2c bus. That'd be really cool and convenient.
[...]
> +int board_usb_init(int index, enum usb_init_type init)
> +{
> + /* Remove warning. */
> + (void)index;
> +
> + if (init != USB_INIT_HOST)
> + return -1;
> +
> + /* enable AHB slave USB clock */
> + setbits_le32(&clk_pwr->usb_ctrl,
> + CLK_USBCTRL_HCLK_EN | CLK_USBCTRL_BUS_KEEPER);
> +
> + /* enable I2C clock in OTG block if it isn't */
> + if ((readl(&otg->otg_clk_sts) & OTG_CLK_I2C_EN) != OTG_CLK_I2C_EN) {
> + writel(OTG_CLK_I2C_EN, &otg->otg_clk_ctrl);
> +
> + while (readl(&otg->otg_clk_sts) != OTG_CLK_I2C_EN)
> + ;
Ew..., such ugly infinite loops are a big no-no, please add a timeout here.
[...]
next prev parent reply other threads:[~2015-07-17 22:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-17 20:48 [U-Boot] [PATCH 3/3] usb: lpc32xx: add host USB driver slemieux.tyco at gmail.com
2015-07-17 22:09 ` Marek Vasut [this message]
2015-07-17 22:52 ` LEMIEUX, SYLVAIN
2015-07-18 3:27 ` Marek Vasut
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=201507180009.12140.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/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