blob: 9b955c1bd678eb70475b0a4002ed8457b1ec462a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stelian Popd1aea1c2008-01-30 21:15:54 +00002/*
3 * (C) Copyright 2006
Stelian Popf9e848b2008-05-08 22:52:09 +02004 * DENX Software Engineering <mk@denx.de>
Stelian Popd1aea1c2008-01-30 21:15:54 +00005 */
6
7#include <common.h>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +02008#include <asm/arch/clk.h>
Stelian Popd1aea1c2008-01-30 21:15:54 +00009
10int usb_cpu_init(void)
11{
Bo Shen4a985df2013-10-21 16:14:00 +080012#ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
Wenyou Yangcb88cd82016-02-03 10:20:44 +080013 if (at91_pllb_clk_enable(get_pllb_init()))
14 return -1;
15
Bo Shen8ed87832013-10-21 16:13:59 +080016#ifdef CONFIG_AT91SAM9N12
Wenyou Yang2f7be642016-02-02 11:11:53 +080017 at91_usb_clk_init(AT91_PMC_USBS_USB_PLLB | AT91_PMC_USB_DIV_2);
Bo Shen8ed87832013-10-21 16:13:59 +080018#endif
Bo Shen4a985df2013-10-21 16:14:00 +080019#elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
Wenyou Yang2f7be642016-02-02 11:11:53 +080020 if (at91_upll_clk_enable())
21 return -1;
Sergey Matyukevichd25010d2010-06-09 23:09:06 +040022
Wenyou Yang2f7be642016-02-02 11:11:53 +080023 at91_usb_clk_init(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10);
Stelian Pope9fe2cf2008-11-09 00:14:46 +010024#endif
25
Bo Shencf905632014-08-06 17:24:56 +080026 at91_periph_clk_enable(ATMEL_ID_UHP);
Bo Shen72979a32013-05-12 22:40:53 +000027
Wenyou Yangfbd4ac12016-02-03 10:16:51 +080028 at91_system_clk_enable(ATMEL_PMC_UHP);
Bo Shenbed082f2013-04-17 00:09:51 +000029#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
Wenyou Yangfbd4ac12016-02-03 10:16:51 +080030 at91_system_clk_enable(AT91_PMC_HCK0);
Stelian Pop61e69d72008-05-08 20:52:22 +020031#endif
Stelian Popd1aea1c2008-01-30 21:15:54 +000032
33 return 0;
34}
35
36int usb_cpu_stop(void)
37{
Bo Shencf905632014-08-06 17:24:56 +080038 at91_periph_clk_disable(ATMEL_ID_UHP);
Bo Shen72979a32013-05-12 22:40:53 +000039
Wenyou Yangfbd4ac12016-02-03 10:16:51 +080040 at91_system_clk_disable(ATMEL_PMC_UHP);
Bo Shenbed082f2013-04-17 00:09:51 +000041#if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
Wenyou Yangfbd4ac12016-02-03 10:16:51 +080042 at91_system_clk_disable(AT91_PMC_HCK0);
Stelian Pop61e69d72008-05-08 20:52:22 +020043#endif
Stelian Pope9fe2cf2008-11-09 00:14:46 +010044
Bo Shen4a985df2013-10-21 16:14:00 +080045#ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB
Bo Shen8ed87832013-10-21 16:13:59 +080046#ifdef CONFIG_AT91SAM9N12
Wenyou Yang2f7be642016-02-02 11:11:53 +080047 at91_usb_clk_init(0);
Bo Shen8ed87832013-10-21 16:13:59 +080048#endif
Wenyou Yangcb88cd82016-02-03 10:20:44 +080049
50 if (at91_pllb_clk_disable())
51 return -1;
52
Bo Shen4a985df2013-10-21 16:14:00 +080053#elif defined(CONFIG_USB_ATMEL_CLK_SEL_UPLL)
Wenyou Yang2f7be642016-02-02 11:11:53 +080054 if (at91_upll_clk_disable())
55 return -1;
Stelian Pope9fe2cf2008-11-09 00:14:46 +010056#endif
57
Stelian Popd1aea1c2008-01-30 21:15:54 +000058 return 0;
59}
60
61int usb_cpu_init_fail(void)
62{
63 return usb_cpu_stop();
64}