]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_clk.c
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / common / cmd_clk.c
1 /*
2  * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
3  * Terry Lv
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <linux/types.h>
25 #include <command.h>
26 #include <common.h>
27 #include <asm/clock.h>
28
29 int do_clkops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
30 {
31         int rc = 0;
32         int freq = 0;
33
34         switch (argc) {
35         case 1:
36                 clk_info(ALL_CLK);
37                 break;
38         case 2:
39                 if ((strcmp(argv[1], "core") == 0) ||
40                         (strcmp(argv[1], "cpu") == 0))
41                         clk_info(CPU_CLK);
42                 else if (strcmp(argv[1], "periph") == 0)
43                         clk_info(PERIPH_CLK);
44                 else if (strcmp(argv[1], "ddr") == 0)
45                         clk_info(DDR_CLK);
46                 else if (strcmp(argv[1], "nfc") == 0)
47                         clk_info(NFC_CLK);
48                 else
49                         printf("Unsupported clock type!\n");
50                 break;
51         case 3:
52                 freq = simple_strtoul(argv[2], NULL, 10);
53                 if ((strcmp(argv[1], "core") == 0) ||
54                         (strcmp(argv[1], "cpu") == 0))
55                         clk_config(CONFIG_REF_CLK_FREQ, freq, CPU_CLK);
56                 else if (strcmp(argv[1], "periph") == 0)
57                         clk_config(CONFIG_REF_CLK_FREQ, freq, PERIPH_CLK);
58                 else if (strcmp(argv[1], "ddr") == 0)
59                         clk_config(CONFIG_REF_CLK_FREQ, freq, DDR_CLK);
60                 else if (strcmp(argv[1], "nfc") == 0)
61                         clk_config(CONFIG_REF_CLK_FREQ, freq, NFC_CLK);
62                 else
63                         printf("Unsupported clock type!\n");
64                 break;
65         default:
66                 rc = 1;
67                 printf("Too many parameters.\n");
68                 printf("Usage:\n%s\n", cmdtp->usage);
69                 break;
70         }
71
72         return rc;
73 }
74
75 U_BOOT_CMD(
76         clk, 3, 1, do_clkops,
77         "Clock sub system",
78         "Setup/Display clock\n"
79         "clk - Display all clocks\n"
80         "clk core <core clock in MHz> - Setup/Display core clock\n"
81         "clk periph <peripheral clock in MHz> -"
82         "Setup/Display peripheral clock\n"
83         "clk ddr <DDR clock in MHz> - Setup/Display DDR clock\n"
84         "clk nfc <NFC clk in MHz> - Setup/Display NFC clock\n"
85         "Example:\n"
86         "clk - Show various clocks\n"
87         "clk core 665 - Set core clock to 665MHz\n"
88         "clk periph 600 - Set peripheral clock to 600MHz\n"
89         "clk ddr 166 - Set DDR clock to 166MHz");
90