~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/mips/pic32/pic32mzda/early_clk.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Joshua Henderson <joshua.henderson@microchip.com>
  4  * Copyright (C) 2015 Microchip Technology Inc.  All rights reserved.
  5  */
  6 #include <asm/mach-pic32/pic32.h>
  7 
  8 #include "pic32mzda.h"
  9 
 10 /* Oscillators, PLL & clocks */
 11 #define ICLK_MASK       0x00000080
 12 #define PLLDIV_MASK     0x00000007
 13 #define CUROSC_MASK     0x00000007
 14 #define PLLMUL_MASK     0x0000007F
 15 #define PB_MASK         0x00000007
 16 #define FRC1            0
 17 #define FRC2            7
 18 #define SPLL            1
 19 #define POSC            2
 20 #define FRC_CLK         8000000
 21 
 22 #define PIC32_POSC_FREQ 24000000
 23 
 24 #define OSCCON          0x0000
 25 #define SPLLCON         0x0020
 26 #define PB1DIV          0x0140
 27 
 28 u32 pic32_get_sysclk(void)
 29 {
 30         u32 osc_freq = 0;
 31         u32 pllclk;
 32         u32 frcdivn;
 33         u32 osccon;
 34         u32 spllcon;
 35         int curr_osc;
 36 
 37         u32 plliclk;
 38         u32 pllidiv;
 39         u32 pllodiv;
 40         u32 pllmult;
 41         u32 frcdiv;
 42 
 43         void __iomem *osc_base = ioremap(PIC32_BASE_OSC, 0x200);
 44 
 45         osccon = __raw_readl(osc_base + OSCCON);
 46         spllcon = __raw_readl(osc_base + SPLLCON);
 47 
 48         plliclk = (spllcon & ICLK_MASK);
 49         pllidiv = ((spllcon >> 8) & PLLDIV_MASK) + 1;
 50         pllodiv = ((spllcon >> 24) & PLLDIV_MASK);
 51         pllmult = ((spllcon >> 16) & PLLMUL_MASK) + 1;
 52         frcdiv = ((osccon >> 24) & PLLDIV_MASK);
 53 
 54         pllclk = plliclk ? FRC_CLK : PIC32_POSC_FREQ;
 55         frcdivn = ((1 << frcdiv) + 1) + (128 * (frcdiv == 7));
 56 
 57         if (pllodiv < 2)
 58                 pllodiv = 2;
 59         else if (pllodiv < 5)
 60                 pllodiv = (1 << pllodiv);
 61         else
 62                 pllodiv = 32;
 63 
 64         curr_osc = (int)((osccon >> 12) & CUROSC_MASK);
 65 
 66         switch (curr_osc) {
 67         case FRC1:
 68         case FRC2:
 69                 osc_freq = FRC_CLK / frcdivn;
 70                 break;
 71         case SPLL:
 72                 osc_freq = ((pllclk / pllidiv) * pllmult) / pllodiv;
 73                 break;
 74         case POSC:
 75                 osc_freq = PIC32_POSC_FREQ;
 76                 break;
 77         default:
 78                 break;
 79         }
 80 
 81         iounmap(osc_base);
 82 
 83         return osc_freq;
 84 }
 85 
 86 u32 pic32_get_pbclk(int bus)
 87 {
 88         u32 clk_freq;
 89         void __iomem *osc_base = ioremap(PIC32_BASE_OSC, 0x200);
 90         u32 pbxdiv = PB1DIV + ((bus - 1) * 0x10);
 91         u32 pbdiv = (__raw_readl(osc_base + pbxdiv) & PB_MASK) + 1;
 92 
 93         iounmap(osc_base);
 94 
 95         clk_freq = pic32_get_sysclk();
 96 
 97         return clk_freq / pbdiv;
 98 }
 99 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php