public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 02/22] ARM: sunxi: MMC driver
Date: Sun, 25 Nov 2012 19:09:02 +0100	[thread overview]
Message-ID: <201211251909.02478.marex@denx.de> (raw)
In-Reply-To: <1353843479.17518.14.camel@home.hno.se>

Dear Henrik Nordstr?m,

> This adds a basic MMC driver for Allwinner sun4i/sun5i family of SoC
> this driver is limited to a single MMC channel.
> 
> Signed-off-by: Tom Cubie <tangliang@allwinnertech.com>
> Signed-off-by: Henrik Nodstrom <henrik@henriknordstrom.net>
> Signed-off-by: Stefan Roese <sr@denx.de>
> ---
[...]

> +#undef SUNXI_MMCDBG

debug_cond() won't work for you ?
[...]

> +	case 0:
> +		/* D1-PF0, D0-PF1, CLK-PF2, CMD-PF3, D3-PF4, D4-PF5 */

Magic goo below?

> +		writel(0x222222, &gpio_f->cfg[0]);
> +		writel(0x555, &gpio_f->pull[0]);
> +		writel(0xaaa, &gpio_f->drv[0]);
> +		break;
> +
> +	case 1:
> +#if CONFIG_MMC1_PG
> +		/* PG0-CMD, PG1-CLK, PG2~5-D0~3 : 4 */
> +		writel(0x444444, &gpio_g->cfg[0]);
> +		writel(0x555, &gpio_g->pull[0]);
> +		writel(0xaaa, &gpio_g->drv[0]);
> +#else
> +		/* PH22-CMD, PH23-CLK, PH24~27-D0~D3 : 5 */
> +		writel(0x55 << 24, &gpio_h->cfg[2]);
> +		writel(0x5555, &gpio_h->cfg[3]);
> +		writel(0x555 << 12, &gpio_h->pull[1]);
> +		writel(0xaaa << 12, &gpio_h->drv[1]);
> +#endif
> +		break;
> +
> +	case 2:
> +		/* CMD-PC6, CLK-PC7, D0-PC8, D1-PC9, D2-PC10, D3-PC11 */
> +		writel(0x33 << 24, &gpio_c->cfg[0]);
> +		writel(0x3333, &gpio_c->cfg[1]);
> +		writel(0x555 << 12, &gpio_c->pull[0]);
> +		writel(0xaaa << 12, &gpio_c->drv[0]);
> +		break;
> +
> +	case 3:
> +		/* PI4-CMD, PI5-CLK, PI6~9-D0~D3 : 2 */
> +		writel(0x2222 << 16, &gpio_i->cfg[0]);
> +		writel(0x22, &gpio_i->cfg[1]);
> +		writel(0x555 << 8, &gpio_i->pull[0]);
> +		writel(0x555 << 8, &gpio_i->drv[0]);
> +		break;
> +
> +	default:
> +		return -1;
> +	}
> +
> +	/* config ahb clock */
> +	rval = readl(&ccm->ahb_gate0);
> +	rval |= (1 << (8 + sdc_no));
> +	writel(rval, &ccm->ahb_gate0);
> +
> +	/* config mod clock */
> +	pll5_clk = clock_get_pll5();
> +	if (pll5_clk > 400000000)
> +		divider = 4;
> +	else
> +		divider = 3;
> +	writel((1U << 31) | (2U << 24) | divider, mmchost->mclkreg);
> +	mmchost->mod_clk = pll5_clk / (divider + 1);
> +
> +	dumphex32("ccmu", (char *)SUNXI_CCM_BASE, 0x100);
> +	dumphex32("gpio", (char *)SUNXI_PIO_BASE, 0x100);
> +	dumphex32("mmc", (char *)mmchost->reg, 0x100);
> +
> +	return 0;
> +}
> +
> +static int mmc_update_clk(struct mmc *mmc)
> +{
> +	struct sunxi_mmc_host *mmchost = (struct sunxi_mmc_host *)mmc->priv;
> +	unsigned int cmd;
> +	unsigned timeout = 0xfffff;
> +
> +	cmd = (1U << 31) | (1 << 21) | (1 << 13);
> +	writel(cmd, &mmchost->reg->cmd);
> +	while ((readl(&mmchost->reg->cmd) & 0x80000000) && timeout--)
> +		;
> +	if (!timeout)
> +		return -1;
> +
> +	writel(readl(&mmchost->reg->rint), &mmchost->reg->rint);
> +
> +	return 0;
> +}
> +
> +static int mmc_config_clock(struct mmc *mmc, unsigned div)
> +{
> +	struct sunxi_mmc_host *mmchost = (struct sunxi_mmc_host *)mmc->priv;
> +	unsigned rval = readl(&mmchost->reg->clkcr);
> +
> +	/*
> +	 * CLKCREG[7:0]: divider
> +	 * CLKCREG[16]:  on/off
> +	 * CLKCREG[17]:  power save
> +	 */
> +	/* Disable Clock */
> +	rval &= ~(1 << 16);
> +	writel(rval, &mmchost->reg->clkcr);
> +	if (mmc_update_clk(mmc))
> +		return -1;
> +
> +	/* Change Divider Factor */
> +	rval &= ~(0xFF);
> +	rval |= div;
> +	writel(rval, &mmchost->reg->clkcr);
> +	if (mmc_update_clk(mmc))
> +		return -1;
> +	/* Re-enable Clock */
> +	rval |= (1 << 16);
> +	writel(rval, &mmchost->reg->clkcr);
> +
> +	if (mmc_update_clk(mmc))
> +		return -1;
> +
> +	return 0;
> +}
> +
> +static void mmc_set_ios(struct mmc *mmc)
> +{
> +	struct sunxi_mmc_host *mmchost = (struct sunxi_mmc_host *)mmc->priv;
> +	unsigned int clkdiv = 0;
> +
> +	MMCDBG("set ios: bus_width: %x, clock: %d, mod_clk\n", mmc->bus_width,
> +	       mmc->clock, mmchost->mod_clk);
> +
> +	/* Change clock first */
> +	clkdiv = (mmchost->mod_clk + (mmc->clock >> 1)) / mmc->clock / 2;
> +	if (mmc->clock)
> +		if (mmc_config_clock(mmc, clkdiv)) {
> +			mmchost->fatal_err = 1;
> +			return;
> +		}
> +
> +	/* Change bus width */
> +	if (mmc->bus_width == 8)
> +		writel(2, &mmchost->reg->width);
> +	else if (mmc->bus_width == 4)
> +		writel(1, &mmchost->reg->width);
> +	else
> +		writel(0, &mmchost->reg->width);
> +}
> +
> +static int mmc_core_init(struct mmc *mmc)
> +{
> +	struct sunxi_mmc_host *mmchost = (struct sunxi_mmc_host *)mmc->priv;
> +
> +	/* Reset controller */
> +	writel(0x7, &mmchost->reg->gctrl);
> +
> +	return 0;
> +}
> +
> +static int mmc_trans_data_by_cpu(struct mmc *mmc, struct mmc_data *data)
> +{
> +	struct sunxi_mmc_host *mmchost = (struct sunxi_mmc_host *)mmc->priv;
> +	unsigned i;
> +	unsigned byte_cnt = data->blocksize * data->blocks;
> +	unsigned *buff;
> +	unsigned timeout = 0xfffff;
> +
> +	if (data->flags & MMC_DATA_READ) {
> +		buff = (unsigned int *)data->dest;
> +		for (i = 0; i < (byte_cnt >> 2); i++) {
> +			while (--timeout
> +			       && (readl(&mmchost->reg->status) & (1 << 2)))

More magic.

> +				;
> +			if (timeout <= 0)
> +				goto out;
> +			buff[i] = readl(mmchost->database);
> +			timeout = 0xfffff;
> +		}
> +	} else {
> +		buff = (unsigned int *)data->src;
> +		for (i = 0; i < (byte_cnt >> 2); i++) {
> +			while (--timeout
> +			       && (readl(&mmchost->reg->status) & (1 << 3)))
> +				;
> +			if (timeout <= 0)
> +				goto out;
> +			writel(buff[i], mmchost->database);
> +			timeout = 0xfffff;
> +		}
> +	}
> +
> +out:
> +	if (timeout <= 0)
> +		return -1;
> +
> +	return 0;
> +}
> +
[...]

  parent reply	other threads:[~2012-11-25 18:09 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1353842684.git.henrik@henriknordstrom.net>
2012-11-25 11:37 ` [U-Boot] [PATCH 01/22] ARM: sunxi: Basic Allwinner A10/A13 (sun4i/sun5i) support Henrik Nordström
2012-11-25 12:23   ` Luka Perkov
2012-11-25 13:08     ` Henrik Nordström
2012-11-25 19:55       ` Wolfgang Denk
2012-11-26  1:05         ` [U-Boot] [PATCH 01/22] Re: Copyright on board makefiles Henrik Nordström
2012-11-26  5:54           ` Wolfgang Denk
2012-11-25 19:52     ` [U-Boot] [PATCH 01/22] ARM: sunxi: Basic Allwinner A10/A13 (sun4i/sun5i) support Wolfgang Denk
2012-11-25 18:06   ` Marek Vasut
2012-11-26  0:21     ` Henrik Nordström
2012-11-26  0:33       ` Marek Vasut
2012-11-26  5:52       ` Wolfgang Denk
2012-11-25 19:33   ` Wolfgang Denk
2012-11-25 23:53     ` Henrik Nordström
2012-11-26  8:00       ` Stefan Roese
2012-11-25 19:40   ` Wolfgang Denk
2012-11-25 11:37 ` [U-Boot] [PATCH 02/22] ARM: sunxi: MMC driver Henrik Nordström
2012-11-25 14:33   ` Luka Perkov
2012-11-25 15:39     ` Henrik Nordström
2012-11-25 17:07       ` Luka Perkov
2012-11-25 19:58       ` Wolfgang Denk
2012-11-25 19:56     ` Wolfgang Denk
2012-11-25 18:09   ` Marek Vasut [this message]
2012-11-25 19:44   ` Wolfgang Denk
2012-11-25 11:38 ` [U-Boot] [PATCH 03/22] ARM sunxi: I2C driver Henrik Nordström
2012-11-25 14:41   ` Luka Perkov
2012-11-25 15:47     ` Henrik Nordström
2012-11-25 18:11   ` Marek Vasut
2012-11-25 19:47   ` Wolfgang Denk
2012-11-26 11:13   ` Heiko Schocher
2012-11-26 13:39     ` Henrik Nordström
2012-11-25 11:39 ` [U-Boot] [PATCH 05/22] power: Add AXP209 Power Management controller (I2C) Henrik Nordström
2012-11-25 14:44   ` Luka Perkov
2012-11-25 18:13   ` Marek Vasut
2012-11-25 19:48   ` Wolfgang Denk
2012-11-25 11:40 ` [U-Boot] [PATCH 06/22] ARM sunxi: Basic GPIO driver Henrik Nordström
2012-11-25 14:52   ` Luka Perkov
2012-11-25 18:14   ` Marek Vasut
2012-11-25 19:50   ` Wolfgang Denk
2012-11-25 21:47     ` Marek Vasut
2012-11-25 23:41     ` Henrik Nordström
2012-11-25 11:40 ` [U-Boot] [PATCH 07/22] tools: mksunixboot adding a Allwinner boot header Henrik Nordström
2012-11-25 15:01   ` Luka Perkov
2012-11-25 17:47   ` Wolfgang Denk
2012-11-25 11:41 ` [U-Boot] [PATCH 08/22] net: Add sunxi (Allwinner) wemac driver Henrik Nordström
2013-07-08 15:43   ` Joe Hershberger
2013-07-08 16:16     ` Tom Rini
2013-07-08 16:29       ` Joe Hershberger
2013-07-08 19:03         ` Tom Rini
2012-11-25 11:42 ` [U-Boot] [PATCH 09/22] ARM: sun4i: Enable ethernet support (wemac) on A10 boards Henrik Nordström
2012-11-25 15:05   ` Luka Perkov
2012-11-25 11:43 ` [U-Boot] [PATCH 10/22] sunxi: Add more network commands and netconsole support Henrik Nordström
2012-11-25 15:07   ` Luka Perkov
2012-11-25 11:44 ` [U-Boot] [PATCH 11/22] ARM: sunxi: U-Boot SPL capable of booting directly from MMC Henrik Nordström
2012-11-25 15:11   ` Luka Perkov
2012-11-25 11:44 ` [U-Boot] [PATCH 12/22] ARM sunxi: SPL support for Olimex A13-OLinuXino board Henrik Nordström
2012-11-25 15:17   ` Luka Perkov
2012-11-25 11:44 ` [U-Boot] [PATCH 13/22] ARM sunxi: SPL support for Mele A1000 board Henrik Nordström
2012-11-25 11:45 ` [U-Boot] [PATCH 14/22] ARM sunxi: SPL support for Cubieboard board Henrik Nordström
2012-11-25 11:45 ` [U-Boot] [PATCH 15/22] ARM sunxi: SPL support for Hackberry 1GB board Henrik Nordström
2012-11-25 11:45 ` [U-Boot] [PATCH 16/22] ARM sunxi: SPL support for a13_mid board Henrik Nordström
2012-11-25 11:45 ` [U-Boot] [PATCH 17/22] ARM sunxi: SPL support for Mini-X board Henrik Nordström
2012-11-25 11:46 ` [U-Boot] [PATCH 18/22] ARM sunxi: SPL support for hyundai A7HD board Henrik Nordström
2012-11-25 11:46 ` [U-Boot] [PATCH 19/22] ARM sunxi: SPL support for MK802 board Henrik Nordström
2012-11-25 11:46 ` [U-Boot] [PATCH 20/22] ARM sunxi: SPL support for Rikomagic MK802II board Henrik Nordström
2012-11-25 11:46 ` [U-Boot] [PATCH 21/22] ARM sunxi: SPL support for Mele A3700 board Henrik Nordström
2012-11-25 11:46 ` [U-Boot] [PATCH 22/22] ARM sunxi: SPL support for Olinuxino A13 Micro Henrik Nordström
2012-11-25 11:47 ` [U-Boot] [PATCH 04/22] ARM: sunxi: watchdog support Henrik Nordström
2013-02-02 23:55   ` Albert ARIBAUD

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=201211251909.02478.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