drivers: at91: clean up peripheral clock code
authorWenyou Yang <wenyou.yang@atmel.com>
Wed, 3 Feb 2016 02:16:51 +0000 (10:16 +0800)
committerAndreas Bießmann <andreas.devel@googlemail.com>
Thu, 18 Feb 2016 20:34:40 +0000 (21:34 +0100)
Due to introducing the new peripheral clock handle functions,
use these functions to reduce the duplicated code.

Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Tested-by: Heiko Schocher <hs@denx.de>
[fixup for missing clk.h in at91_emac.c]
Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
drivers/net/at91_emac.c
drivers/usb/host/ehci-atmel.c
drivers/usb/host/ohci-at91.c

index 2659592..9151600 100644 (file)
@@ -12,7 +12,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/at91_emac.h>
-#include <asm/arch/at91_pmc.h>
+#include <asm/arch/clk.h>
 #include <asm/arch/at91_pio.h>
 #include <net.h>
 #include <netdev.h>
@@ -321,7 +321,6 @@ static int at91emac_init(struct eth_device *netdev, bd_t *bd)
        emac_device *dev;
        at91_emac_t *emac;
        at91_pio_t *pio = (at91_pio_t *) ATMEL_BASE_PIO;
-       at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
 
        emac = (at91_emac_t *) netdev->iobase;
        dev = (emac_device *) netdev->priv;
@@ -347,7 +346,8 @@ static int at91emac_init(struct eth_device *netdev, bd_t *bd)
        writel(value, &pio->piob.pdr);
        writel(value, &pio->piob.bsr);
 
-       writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
+       at91_periph_clk_enable(ATMEL_ID_EMAC);
+
        writel(readl(&emac->ctl) | AT91_EMAC_CTL_CSR, &emac->ctl);
 
        /* Init Ethernet buffers */
@@ -452,10 +452,10 @@ static int at91emac_recv(struct eth_device *netdev)
 static int at91emac_write_hwaddr(struct eth_device *netdev)
 {
        at91_emac_t *emac;
-       at91_pmc_t *pmc = (at91_pmc_t *) ATMEL_BASE_PMC;
        emac = (at91_emac_t *) netdev->iobase;
 
-       writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
+       at91_periph_clk_enable(ATMEL_ID_EMAC);
+
        debug_cond(DEBUG_AT91EMAC,
                "init MAC-ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
                netdev->enetaddr[5], netdev->enetaddr[4], netdev->enetaddr[3],
index 9a8f004..a33fb49 100644 (file)
@@ -40,11 +40,7 @@ int ehci_hcd_init(int index, enum usb_init_type init,
        }
 
        /* Enable USB Host clock */
-#ifdef CPU_HAS_PCR
        at91_periph_clk_enable(ATMEL_ID_UHPHS);
-#else
-       writel(1 << ATMEL_ID_UHPHS, &pmc->pcer);
-#endif
 
        *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
        *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -59,11 +55,7 @@ int ehci_hcd_stop(int index)
        ulong start_time, tmp_time;
 
        /* Disable USB Host Clock */
-#ifdef CPU_HAS_PCR
        at91_periph_clk_disable(ATMEL_ID_UHPHS);
-#else
-       writel(1 << ATMEL_ID_UHPHS, &pmc->pcdr);
-#endif
 
        start_time = get_timer(0);
        /* Disable UTMI PLL */
index 820e2e5..da85111 100644 (file)
@@ -37,17 +37,11 @@ int usb_cpu_init(void)
        writel(AT91_PMC_USBS_USB_UPLL | AT91_PMC_USBDIV_10, &pmc->usb);
 #endif
 
-       /* Enable USB host clock. */
-#ifdef CPU_HAS_PCR
        at91_periph_clk_enable(ATMEL_ID_UHP);
-#else
-       writel(1 << ATMEL_ID_UHP, &pmc->pcer);
-#endif
 
+       at91_system_clk_enable(ATMEL_PMC_UHP);
 #if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
-       writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scer);
-#else
-       writel(ATMEL_PMC_UHP, &pmc->scer);
+       at91_system_clk_enable(AT91_PMC_HCK0);
 #endif
 
        return 0;
@@ -57,17 +51,11 @@ int usb_cpu_stop(void)
 {
        at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
 
-       /* Disable USB host clock. */
-#ifdef CPU_HAS_PCR
        at91_periph_clk_disable(ATMEL_ID_UHP);
-#else
-       writel(1 << ATMEL_ID_UHP, &pmc->pcdr);
-#endif
 
+       at91_system_clk_disable(ATMEL_PMC_UHP);
 #if defined(CONFIG_AT91SAM9261) || defined(CONFIG_AT91SAM9G10)
-       writel(ATMEL_PMC_UHP | AT91_PMC_HCK0, &pmc->scdr);
-#else
-       writel(ATMEL_PMC_UHP, &pmc->scdr);
+       at91_system_clk_disable(AT91_PMC_HCK0);
 #endif
 
 #ifdef CONFIG_USB_ATMEL_CLK_SEL_PLLB