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