1447da58bSPeter Griffin /*
2447da58bSPeter Griffin * (C) Copyright 2015 Linaro
3447da58bSPeter Griffin * peter.griffin <peter.griffin@linaro.org>
4447da58bSPeter Griffin *
5447da58bSPeter Griffin * SPDX-License-Identifier: GPL-2.0+
6447da58bSPeter Griffin */
7447da58bSPeter Griffin
8447da58bSPeter Griffin #include <common.h>
9447da58bSPeter Griffin #include <dwmmc.h>
10447da58bSPeter Griffin #include <malloc.h>
115d97dff0SMasahiro Yamada #include <linux/errno.h>
12447da58bSPeter Griffin
13447da58bSPeter Griffin #define DWMMC_MAX_CH_NUM 4
14447da58bSPeter Griffin
15447da58bSPeter Griffin #define DWMMC_MAX_FREQ 50000000
16447da58bSPeter Griffin #define DWMMC_MIN_FREQ 400000
17447da58bSPeter Griffin
18447da58bSPeter Griffin /* Source clock is configured to 100MHz by ATF bl1*/
19447da58bSPeter Griffin #define MMC0_DEFAULT_FREQ 100000000
20447da58bSPeter Griffin
hi6220_dwmci_core_init(struct dwmci_host * host,int index)21447da58bSPeter Griffin static int hi6220_dwmci_core_init(struct dwmci_host *host, int index)
22447da58bSPeter Griffin {
23fc50a6cbSJorge Ramirez-Ortiz host->name = "Hisilicon DWMMC";
24447da58bSPeter Griffin
25447da58bSPeter Griffin host->dev_index = index;
26447da58bSPeter Griffin
27447da58bSPeter Griffin /* Add the mmc channel to be registered with mmc core */
28447da58bSPeter Griffin if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) {
29447da58bSPeter Griffin printf("DWMMC%d registration failed\n", index);
30447da58bSPeter Griffin return -1;
31447da58bSPeter Griffin }
32447da58bSPeter Griffin return 0;
33447da58bSPeter Griffin }
34447da58bSPeter Griffin
35447da58bSPeter Griffin /*
36447da58bSPeter Griffin * This function adds the mmc channel to be registered with mmc core.
37447da58bSPeter Griffin * index - mmc channel number.
38447da58bSPeter Griffin * regbase - register base address of mmc channel specified in 'index'.
39447da58bSPeter Griffin * bus_width - operating bus width of mmc channel specified in 'index'.
40447da58bSPeter Griffin */
hi6220_dwmci_add_port(int index,u32 regbase,int bus_width)41447da58bSPeter Griffin int hi6220_dwmci_add_port(int index, u32 regbase, int bus_width)
42447da58bSPeter Griffin {
43447da58bSPeter Griffin struct dwmci_host *host = NULL;
44447da58bSPeter Griffin
45447da58bSPeter Griffin host = calloc(1, sizeof(struct dwmci_host));
46447da58bSPeter Griffin if (!host) {
47*90aa625cSMasahiro Yamada pr_err("dwmci_host calloc failed!\n");
48447da58bSPeter Griffin return -ENOMEM;
49447da58bSPeter Griffin }
50447da58bSPeter Griffin
5141f7be3cSPrabhakar Kushwaha host->ioaddr = (void *)(ulong)regbase;
52447da58bSPeter Griffin host->buswidth = bus_width;
53447da58bSPeter Griffin host->bus_hz = MMC0_DEFAULT_FREQ;
54447da58bSPeter Griffin
55447da58bSPeter Griffin return hi6220_dwmci_core_init(host, index);
56447da58bSPeter Griffin }
57