blob: 7f89403b432f87155d95d8ef4618a8a5b18e1968 [file] [log] [blame]
Jaehoon Chung442d5562012-04-23 02:36:28 +00001/*
2 * (C) Copyright 2012 SAMSUNG Electronics
3 * Jaehoon Chung <jh80.chung@samsung.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Jaehoon Chung442d5562012-04-23 02:36:28 +00006 */
7
8#include <common.h>
9#include <malloc.h>
10#include <sdhci.h>
11#include <asm/arch/mmc.h>
Jaehoon Chungb09ed6e2012-08-30 16:24:11 +000012#include <asm/arch/clk.h>
Jaehoon Chung442d5562012-04-23 02:36:28 +000013
14static char *S5P_NAME = "SAMSUNG SDHCI";
15static void s5p_sdhci_set_control_reg(struct sdhci_host *host)
16{
17 unsigned long val, ctrl;
18 /*
19 * SELCLKPADDS[17:16]
20 * 00 = 2mA
21 * 01 = 4mA
22 * 10 = 7mA
23 * 11 = 9mA
24 */
25 sdhci_writel(host, SDHCI_CTRL4_DRIVE_MASK(0x3), SDHCI_CONTROL4);
26
27 val = sdhci_readl(host, SDHCI_CONTROL2);
28 val &= SDHCI_CTRL2_SELBASECLK_SHIFT;
29
30 val |= SDHCI_CTRL2_ENSTAASYNCCLR |
31 SDHCI_CTRL2_ENCMDCNFMSK |
32 SDHCI_CTRL2_ENFBCLKRX |
33 SDHCI_CTRL2_ENCLKOUTHOLD;
34
35 sdhci_writel(host, val, SDHCI_CONTROL2);
36
37 /*
38 * FCSEL3[31] FCSEL2[23] FCSEL1[15] FCSEL0[7]
39 * FCSel[1:0] : Rx Feedback Clock Delay Control
40 * Inverter delay means10ns delay if SDCLK 50MHz setting
41 * 01 = Delay1 (basic delay)
42 * 11 = Delay2 (basic delay + 2ns)
43 * 00 = Delay3 (inverter delay)
44 * 10 = Delay4 (inverter delay + 2ns)
45 */
Jaehoon Chungb2686602012-08-30 16:24:08 +000046 val = SDHCI_CTRL3_FCSEL0 | SDHCI_CTRL3_FCSEL1;
Jaehoon Chung442d5562012-04-23 02:36:28 +000047 sdhci_writel(host, val, SDHCI_CONTROL3);
48
49 /*
50 * SELBASECLK[5:4]
51 * 00/01 = HCLK
52 * 10 = EPLL
53 * 11 = XTI or XEXTCLK
54 */
55 ctrl = sdhci_readl(host, SDHCI_CONTROL2);
56 ctrl &= ~SDHCI_CTRL2_SELBASECLK_MASK(0x3);
57 ctrl |= SDHCI_CTRL2_SELBASECLK_MASK(0x2);
58 sdhci_writel(host, ctrl, SDHCI_CONTROL2);
59}
60
Jaehoon Chung8458e022012-08-30 16:24:10 +000061int s5p_sdhci_init(u32 regbase, int index, int bus_width)
Jaehoon Chung442d5562012-04-23 02:36:28 +000062{
63 struct sdhci_host *host = NULL;
64 host = (struct sdhci_host *)malloc(sizeof(struct sdhci_host));
65 if (!host) {
66 printf("sdhci__host malloc fail!\n");
67 return 1;
68 }
69
70 host->name = S5P_NAME;
71 host->ioaddr = (void *)regbase;
Jaehoon Chung442d5562012-04-23 02:36:28 +000072
Jaehoon Chungb2686602012-08-30 16:24:08 +000073 host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_BROKEN_VOLTAGE |
Tushar Behera13243f22012-09-20 20:31:57 +000074 SDHCI_QUIRK_BROKEN_R1B | SDHCI_QUIRK_32BIT_DMA_ADDR |
75 SDHCI_QUIRK_WAIT_SEND_CMD;
Jaehoon Chung442d5562012-04-23 02:36:28 +000076 host->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
Jaehoon Chungb2686602012-08-30 16:24:08 +000077 host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
Jaehoon Chung442d5562012-04-23 02:36:28 +000078
79 host->set_control_reg = &s5p_sdhci_set_control_reg;
Jaehoon Chungb09ed6e2012-08-30 16:24:11 +000080 host->set_clock = set_mmc_clk;
81 host->index = index;
Jaehoon Chung442d5562012-04-23 02:36:28 +000082
83 host->host_caps = MMC_MODE_HC;
84
Jaehoon Chunga68aac42012-12-13 20:07:12 +000085 return add_sdhci(host, 52000000, 400000);
Jaehoon Chung442d5562012-04-23 02:36:28 +000086}