xref: /openbmc/u-boot/drivers/mmc/atmel_sdhci.c (revision f1056910)
1 /*
2  * Copyright (C) 2015 Atmel Corporation
3  *		      Wenyou.Yang <wenyou.yang@atmel.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <malloc.h>
10 #include <sdhci.h>
11 #include <asm/arch/clk.h>
12 
13 #define ATMEL_SDHC_MIN_FREQ	400000
14 
15 int atmel_sdhci_init(void *regbase, u32 id)
16 {
17 	struct sdhci_host *host;
18 	u32 max_clk, min_clk = ATMEL_SDHC_MIN_FREQ;
19 
20 	host = (struct sdhci_host *)calloc(1, sizeof(struct sdhci_host));
21 	if (!host) {
22 		printf("%s: sdhci_host calloc failed\n", __func__);
23 		return -ENOMEM;
24 	}
25 
26 	host->name = "atmel_sdhci";
27 	host->ioaddr = regbase;
28 	host->quirks = 0;
29 	host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
30 	max_clk = at91_get_periph_generated_clk(id);
31 	if (!max_clk) {
32 		printf("%s: Failed to get the proper clock\n", __func__);
33 		free(host);
34 		return -ENODEV;
35 	}
36 
37 	add_sdhci(host, max_clk, min_clk);
38 
39 	return 0;
40 }
41