]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/armv7/bcm281xx/clk-sdio.c
49badcbaa71486c502cea8157c72cd9def2c5e57
[people/ms/u-boot.git] / arch / arm / cpu / armv7 / bcm281xx / clk-sdio.c
1 /*
2 * Copyright 2013 Broadcom Corporation.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/errno.h>
10 #include <asm/arch/sysmap.h>
11 #include <asm/kona-common/clk.h>
12 #include "clk-core.h"
13
14 /* Enable appropriate clocks for an SDIO port */
15 int clk_sdio_enable(void *base, u32 rate, u32 *actual_ratep)
16 {
17 int ret;
18 struct clk *c;
19
20 char *clkstr;
21 char *slpstr;
22 char *ahbstr;
23
24 switch ((u32) base) {
25 case CONFIG_SYS_SDIO_BASE0:
26 clkstr = CONFIG_SYS_SDIO0 "_clk";
27 ahbstr = CONFIG_SYS_SDIO0 "_ahb_clk";
28 slpstr = CONFIG_SYS_SDIO0 "_sleep_clk";
29 break;
30 case CONFIG_SYS_SDIO_BASE1:
31 clkstr = CONFIG_SYS_SDIO1 "_clk";
32 ahbstr = CONFIG_SYS_SDIO1 "_ahb_clk";
33 slpstr = CONFIG_SYS_SDIO1 "_sleep_clk";
34 break;
35 case CONFIG_SYS_SDIO_BASE2:
36 clkstr = CONFIG_SYS_SDIO2 "_clk";
37 ahbstr = CONFIG_SYS_SDIO2 "_ahb_clk";
38 slpstr = CONFIG_SYS_SDIO2 "_sleep_clk";
39 break;
40 case CONFIG_SYS_SDIO_BASE3:
41 clkstr = CONFIG_SYS_SDIO3 "_clk";
42 ahbstr = CONFIG_SYS_SDIO3 "_ahb_clk";
43 slpstr = CONFIG_SYS_SDIO3 "_sleep_clk";
44 break;
45 default:
46 printf("%s: base 0x%p not found\n", __func__, base);
47 return -EINVAL;
48 }
49
50 ret = clk_get_and_enable(ahbstr);
51 if (ret)
52 return ret;
53
54 ret = clk_get_and_enable(slpstr);
55 if (ret)
56 return ret;
57
58 c = clk_get(clkstr);
59 if (c) {
60 ret = clk_set_rate(c, rate);
61 if (ret)
62 return ret;
63
64 ret = clk_enable(c);
65 if (ret)
66 return ret;
67 } else {
68 printf("%s: Couldn't find %s\n", __func__, clkstr);
69 return -EINVAL;
70 }
71 *actual_ratep = rate;
72 return 0;
73 }