From patchwork Tue Mar 5 13:11:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amar X-Patchwork-Id: 15233 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A211C23E00 for ; Tue, 5 Mar 2013 12:55:01 +0000 (UTC) Received: from mail-vb0-f44.google.com (mail-vb0-f44.google.com [209.85.212.44]) by fiordland.canonical.com (Postfix) with ESMTP id 5451AA18864 for ; Tue, 5 Mar 2013 12:55:01 +0000 (UTC) Received: by mail-vb0-f44.google.com with SMTP id fr13so1254828vbb.31 for ; Tue, 05 Mar 2013 04:55:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-brightmail-tracker:x-brightmail-tracker :dlp-filter:x-mtr:x-cfilter-loop:x-gm-message-state; bh=KDeDNhUq1pQg4ZCtpKq3x7B5F5DYFNl5aOLBNB1XMkI=; b=lQbc1z5OCMrWR46mzy4jH11ZYPXccHL6ko9/nJr+rc4g7zqsPe7qyMt9ji9lPBC551 6WGufsAKZPfBys0VrCSqI7I8cMG0OlabXPUR2w8I3LgDxOhXqeskMSGEAb9ltkmK/bne XrLgncvsidypNf9UGgsi4Pu/DI5IcSTNMhFhruL3vrr0kW7SiomK+qpFp45ME65KBZEG KIanb9Zlt+fxJE1y3KFNcvZ7lDbK2knvbnPtd0LWMYZQPcP4WX8StAJ8Q2NVlJe5L7b1 H/1H4+IxxrrmtE2GYKNU5z8qXqkPrPpKld3HkUrC5LAshM3WPj0VKw/rTFsSo3Oq83z9 /uFA== X-Received: by 10.221.11.135 with SMTP id pe7mr9460886vcb.41.1362488100748; Tue, 05 Mar 2013 04:55:00 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp109880veb; Tue, 5 Mar 2013 04:55:00 -0800 (PST) X-Received: by 10.68.9.67 with SMTP id x3mr36995820pba.219.1362488099493; Tue, 05 Mar 2013 04:54:59 -0800 (PST) Received: from mailout2.samsung.com (mailout2.samsung.com. [203.254.224.25]) by mx.google.com with ESMTP id qf9si12624361pbb.334.2013.03.05.04.54.58; Tue, 05 Mar 2013 04:54:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.25 as permitted sender) client-ip=203.254.224.25; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.25 as permitted sender) smtp.mail=amarendra.xt@samsung.com Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MJ6002V8UJLMJ80@mailout2.samsung.com>; Tue, 05 Mar 2013 21:54:57 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.125]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 1B.44.02494.12BE5315; Tue, 05 Mar 2013 21:54:57 +0900 (KST) X-AuditID: cbfee68d-b7f636d0000009be-96-5135eb21d5db Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id D8.C9.03918.12BE5315; Tue, 05 Mar 2013 21:54:57 +0900 (KST) Received: from chrome-ubuntu.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MJ600GDUUCXH840@mmp1.samsung.com>; Tue, 05 Mar 2013 21:54:57 +0900 (KST) From: Amar To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org, afleming@gmail.com, jh80.chung@samsung.com Subject: [PATCH V7 04/10] EXYNOS5: DWMMC: Added FDT support for DWMMC Date: Tue, 05 Mar 2013 08:11:24 -0500 Message-id: <1362489090-7745-5-git-send-email-amarendra.xt@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1362489090-7745-1-git-send-email-amarendra.xt@samsung.com> References: <1362489090-7745-1-git-send-email-amarendra.xt@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsWyRsSkVlfxtWmgwaHFVhYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgy2rYeZi64YVPxY9dd5gbGfwZdjJwcEgImEhO+7GWC sMUkLtxbz9bFyMUhJLCUUeLJ/UmMMEULp59ih0gsYpToe36aCcLpZZLoO/gYqIqDg01AVeLX YnuQBhEBCYlf/VcZQWqYBToYJXZM3Aw2SVjAVWL//wvsIDYLUP3bV3tZQWxeAXeJO/t+sUBs k5P4sOcRWA2ngIfEos8LmUFsIaCaSz2LWECGSgg8ZpNY8+sbG8QgAYlvkw+xgBwhISArsekA M8QcSYmDK26wTGAUXsDIsIpRNLUguaA4Kb3IUK84Mbe4NC9dLzk/dxMjMCBP/3vWu4Px9gHr Q4zJQOMmMkuJJucDAzqvJN7Q2MTc1NjUzMjS0tKUNGElcV65SzKBQgLpiSWp2ampBalF8UWl OanFhxiZODilGhjnvKi/88j6q9LTM/nH5xb5VcxZPUUqcOv/XTzNH5S2ntELCzcuvbXnm5dr fOCCMzarqsJnsvwWn5Tw7M9sKfnFnNOVHz1Or1d9Pu/kXetLC1dt6/kSvk877bfmHtdrju63 nV0y9IQEuS++e/3mMLfb9QU3cj8czzDc3jGZIaiivumfSPbXTZ//KbEUZyQaajEXFScCAGTM +gpeAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRmVeSWpSXmKPExsVy+t9jAV3F16aBBpdvaFs8XH+TxWLK4S8s Dkwed67tYQtgjGpgtMlITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw1DW0tDBXUshLzE21VXLx CdB1y8wBmq2kUJaYUwoUCkgsLlbSt8M0ITTETdcCpjFC1zckCK7HyAANJKxhzGjbepi54IZN xY9dd5kbGP8ZdDFyckgImEgsnH6KHcIWk7hwbz1bFyMXh5DAIkaJvuenmSCcXiaJvoOPGbsY OTjYBFQlfi22B2kQEZCQ+NV/lRGkhlmgg1Fix8TNjCAJYQFXif3/L4BNZQGqf/tqLyuIzSvg LnFn3y8WiG1yEh/2PAKr4RTwkFj0eSEziC0EVHOpZxHLBEbeBYwMqxhFUwuSC4qT0nMN9YoT c4tL89L1kvNzNzGCw/2Z1A7GlQ0WhxgFOBiVeHgZjpoECrEmlhVX5h5ilOBgVhLh3fnUNFCI NyWxsiq1KD++qDQntfgQYzLQVROZpUST84GxmFcSb2hsYm5qbGppYmFiZkmasJI4L+OpJwFC AumJJanZqakFqUUwW5g4OKUaGFuZJ/kpsDZNWLlDXXjCEt5lTyblOM2VsM/5sWt54rTbk78V l3H8tbunbhHnqaVoZOMtc3RL6gmezP7MmulGwvqrgvrTj4by/WSZFq3aviOf8/s+xkML96Sl W70ruOXHqNr17uelJdbXDCbMY5m4NU/ya+2EY2rTlt74P+mOiNLmcK4v/yc5ZimxFGckGmox FxUnAgCw5revuwIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQnGAtEJUiNVFtCmVmwAtI99eUQhcMQmi8b8TBFD/SFf339MkL46fvEkdg5D1zyZePi7E9hE This patch adds FDT support for DWMMC, by reading the DWMMC node data from the device tree and initialising DWMMC channels as per data obtained from the node. Signed-off-by: Vivek Gautam Signed-off-by: Amar Acked-by: Simon Glass --- Changes since V1: 1)Updated code to have same signature for the function exynos_dwmci_init() for both FDT and non-FDT versions. 2)Updated code to pass device_id parameter to the function exynos5_mmc_set_clk_div() instead of index. 3)Updated code to decode the value of "samsung,width" from FDT. 4)Channel index is computed instead of getting from FDT. Changes since V2: 1)Updation of commit message and resubmition of proper patch set. Changes since V3: 1)Replaced the new function exynos5_mmc_set_clk_div() with the existing function set_mmc_clk(). set_mmc_clk() will do the purpose. 2)Computation of FSYS block clock divisor (pre-ratio) is added. Changes since V4: 1)Replaced "unsigned int exynos_dwmmc_init(int index, int bus_width)" with int exynos_dwmci_add_port(int, u32, inth, u32) i)exynos_dwmmc_add_port() will be used by non-FDT boards. ii)In FDT case, exynos_dwmmc_init(const void *blob) will use exynos_dwmmc_add_port() for every channel enabled in device node. 2)Changed the computation method of mmc clock divisor. 3)Updated exynos_dwmmc_init() to compute the 'clksel_val' within the function. Changes since V5: 1)Updated in response to review comments and changed the mmc clock value from 50MHz to 52MHz. Changes since V6: No change. arch/arm/include/asm/arch-exynos/dwmmc.h | 11 +-- drivers/mmc/exynos_dw_mmc.c | 127 ++++++++++++++++++++++++++++--- include/dwmmc.h | 3 + 3 files changed, 124 insertions(+), 17 deletions(-) diff --git a/arch/arm/include/asm/arch-exynos/dwmmc.h b/arch/arm/include/asm/arch-exynos/dwmmc.h index 8acdf9b..3b147b8 100644 --- a/arch/arm/include/asm/arch-exynos/dwmmc.h +++ b/arch/arm/include/asm/arch-exynos/dwmmc.h @@ -27,10 +27,7 @@ #define DWMCI_SET_DRV_CLK(x) ((x) << 16) #define DWMCI_SET_DIV_RATIO(x) ((x) << 24) -int exynos_dwmci_init(u32 regbase, int bus_width, int index); - -static inline unsigned int exynos_dwmmc_init(int index, int bus_width) -{ - unsigned int base = samsung_get_base_mmc() + (0x10000 * index); - return exynos_dwmci_init(base, bus_width, index); -} +#ifdef CONFIG_OF_CONTROL +int exynos_dwmmc_init(const void *blob); +#endif +int exynos_dwmci_add_port(int index, u32 regbase, int bus_width, u32 clksel); diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c index 72a31b7..4238dd9 100644 --- a/drivers/mmc/exynos_dw_mmc.c +++ b/drivers/mmc/exynos_dw_mmc.c @@ -19,39 +19,146 @@ */ #include -#include #include +#include +#include +#include #include #include +#include -static char *EXYNOS_NAME = "EXYNOS DWMMC"; +#define DWMMC_MAX_CH_NUM 4 +#define DWMMC_MAX_FREQ 52000000 +#define DWMMC_MIN_FREQ 400000 +#define DWMMC_MMC0_CLKSEL_VAL 0x03030001 +#define DWMMC_MMC2_CLKSEL_VAL 0x03020001 +/* + * Function used as callback function to initialise the + * CLKSEL register for every mmc channel. + */ static void exynos_dwmci_clksel(struct dwmci_host *host) { - u32 val; - val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) | - DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(0); + dwmci_writel(host, DWMCI_CLKSEL, host->clksel_val); +} - dwmci_writel(host, DWMCI_CLKSEL, val); +unsigned int exynos_dwmci_get_clk(int dev_index) +{ + return get_mmc_clk(dev_index); } -int exynos_dwmci_init(u32 regbase, int bus_width, int index) +/* + * This function adds the mmc channel to be registered with mmc core. + * index - mmc channel number. + * regbase - register base address of mmc channel specified in 'index'. + * bus_width - operating bus width of mmc channel specified in 'index'. + * clksel - value to be written into CLKSEL register in case of FDT. + * NULL in case od non-FDT. + */ +int exynos_dwmci_add_port(int index, u32 regbase, int bus_width, u32 clksel) { struct dwmci_host *host = NULL; + unsigned int div; + unsigned long freq, sclk; host = malloc(sizeof(struct dwmci_host)); if (!host) { printf("dwmci_host malloc fail!\n"); return 1; } + /* request mmc clock vlaue of 52MHz. */ + freq = 52000000; + sclk = get_mmc_clk(index); + div = DIV_ROUND_UP(sclk, freq); + /* set the clock divisor for mmc */ + set_mmc_clk(index, div); - host->name = EXYNOS_NAME; + host->name = "EXYNOS DWMMC"; host->ioaddr = (void *)regbase; host->buswidth = bus_width; + + if (clksel) { + host->clksel_val = clksel; + } else { + if (0 == index) + host->clksel_val = DWMMC_MMC0_CLKSEL_VAL; + if (2 == index) + host->clksel_val = DWMMC_MMC2_CLKSEL_VAL; + } + host->clksel = exynos_dwmci_clksel; host->dev_index = index; + host->mmc_clk = exynos_dwmci_get_clk; + /* Add the mmc channel to be registered with mmc core */ + if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) { + debug("dwmmc%d registration failed\n", index); + return -1; + } + return 0; +} + +#ifdef CONFIG_OF_CONTROL +int exynos_dwmmc_init(const void *blob) +{ + int index, bus_width; + int node_list[DWMMC_MAX_CH_NUM]; + int err = 0, dev_id, flag, count, i; + u32 clksel_val, base, timing[3]; + + count = fdtdec_find_aliases_for_id(blob, "mmc", + COMPAT_SAMSUNG_EXYNOS5_DWMMC, node_list, + DWMMC_MAX_CH_NUM); + + for (i = 0; i < count; i++) { + int node = node_list[i]; + + if (node <= 0) + continue; - add_dwmci(host, 52000000, 400000); + /* Extract device id for each mmc channel */ + dev_id = pinmux_decode_periph_id(blob, node); + /* Get the bus width from the device node */ + bus_width = fdtdec_get_int(blob, node, "samsung,bus-width", 0); + if (bus_width <= 0) { + debug("DWMMC: Can't get bus-width\n"); + return -1; + } + if (8 == bus_width) + flag = PINMUX_FLAG_8BIT_MODE; + else + flag = PINMUX_FLAG_NONE; + + /* config pinmux for each mmc channel */ + err = exynos_pinmux_config(dev_id, flag); + if (err) { + debug("DWMMC not configured\n"); + return err; + } + + index = dev_id - PERIPH_ID_SDMMC0; + + /* Get the base address from the device node */ + base = fdtdec_get_addr(blob, node, "reg"); + if (!base) { + debug("DWMMC: Can't get base address\n"); + return -1; + } + /* Extract the timing info from the node */ + err = fdtdec_get_int_array(blob, node, "samsung,timing", + timing, 3); + if (err) { + debug("Can't get sdr-timings for divider\n"); + return -1; + } + + clksel_val = (DWMCI_SET_SAMPLE_CLK(timing[0]) | + DWMCI_SET_DRV_CLK(timing[1]) | + DWMCI_SET_DIV_RATIO(timing[2])); + /* Initialise each mmc channel */ + err = exynos_dwmci_add_port(index, base, bus_width, clksel_val); + if (err) + debug("dwmmc Channel-%d init failed\n", index); + } return 0; } - +#endif diff --git a/include/dwmmc.h b/include/dwmmc.h index c8b1d40..e142f3e 100644 --- a/include/dwmmc.h +++ b/include/dwmmc.h @@ -123,6 +123,8 @@ #define MSIZE(x) ((x) << 28) #define RX_WMARK(x) ((x) << 16) #define TX_WMARK(x) (x) +#define RX_WMARK_SHIFT 16 +#define RX_WMARK_MASK (0xfff << RX_WMARK_SHIFT) #define DWMCI_IDMAC_OWN (1 << 31) #define DWMCI_IDMAC_CH (1 << 4) @@ -144,6 +146,7 @@ struct dwmci_host { unsigned int bus_hz; int dev_index; int buswidth; + u32 clksel_val; u32 fifoth_val; struct mmc *mmc;