LCOV - code coverage report
Current view: top level - drivers/clk/bcm - clk-bcm2835.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 243 446 54.5 %
Date: 2020-09-30 20:25:40 Functions: 22 42 52.4 %
Branches: 76 2206 3.4 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0+
       2                 :            : /*
       3                 :            :  * Copyright (C) 2010,2015 Broadcom
       4                 :            :  * Copyright (C) 2012 Stephen Warren
       5                 :            :  */
       6                 :            : 
       7                 :            : /**
       8                 :            :  * DOC: BCM2835 CPRMAN (clock manager for the "audio" domain)
       9                 :            :  *
      10                 :            :  * The clock tree on the 2835 has several levels.  There's a root
      11                 :            :  * oscillator running at 19.2Mhz.  After the oscillator there are 5
      12                 :            :  * PLLs, roughly divided as "camera", "ARM", "core", "DSI displays",
      13                 :            :  * and "HDMI displays".  Those 5 PLLs each can divide their output to
      14                 :            :  * produce up to 4 channels.  Finally, there is the level of clocks to
      15                 :            :  * be consumed by other hardware components (like "H264" or "HDMI
      16                 :            :  * state machine"), which divide off of some subset of the PLL
      17                 :            :  * channels.
      18                 :            :  *
      19                 :            :  * All of the clocks in the tree are exposed in the DT, because the DT
      20                 :            :  * may want to make assignments of the final layer of clocks to the
      21                 :            :  * PLL channels, and some components of the hardware will actually
      22                 :            :  * skip layers of the tree (for example, the pixel clock comes
      23                 :            :  * directly from the PLLH PIX channel without using a CM_*CTL clock
      24                 :            :  * generator).
      25                 :            :  */
      26                 :            : 
      27                 :            : #include <linux/clk-provider.h>
      28                 :            : #include <linux/clkdev.h>
      29                 :            : #include <linux/clk.h>
      30                 :            : #include <linux/debugfs.h>
      31                 :            : #include <linux/delay.h>
      32                 :            : #include <linux/io.h>
      33                 :            : #include <linux/module.h>
      34                 :            : #include <linux/of_device.h>
      35                 :            : #include <linux/platform_device.h>
      36                 :            : #include <linux/slab.h>
      37                 :            : #include <dt-bindings/clock/bcm2835.h>
      38                 :            : #include <soc/bcm2835/raspberrypi-firmware.h>
      39                 :            : 
      40                 :            : #define CM_PASSWORD             0x5a000000
      41                 :            : 
      42                 :            : #define CM_GNRICCTL             0x000
      43                 :            : #define CM_GNRICDIV             0x004
      44                 :            : # define CM_DIV_FRAC_BITS       12
      45                 :            : # define CM_DIV_FRAC_MASK       GENMASK(CM_DIV_FRAC_BITS - 1, 0)
      46                 :            : 
      47                 :            : #define CM_VPUCTL               0x008
      48                 :            : #define CM_VPUDIV               0x00c
      49                 :            : #define CM_SYSCTL               0x010
      50                 :            : #define CM_SYSDIV               0x014
      51                 :            : #define CM_PERIACTL             0x018
      52                 :            : #define CM_PERIADIV             0x01c
      53                 :            : #define CM_PERIICTL             0x020
      54                 :            : #define CM_PERIIDIV             0x024
      55                 :            : #define CM_H264CTL              0x028
      56                 :            : #define CM_H264DIV              0x02c
      57                 :            : #define CM_ISPCTL               0x030
      58                 :            : #define CM_ISPDIV               0x034
      59                 :            : #define CM_V3DCTL               0x038
      60                 :            : #define CM_V3DDIV               0x03c
      61                 :            : #define CM_CAM0CTL              0x040
      62                 :            : #define CM_CAM0DIV              0x044
      63                 :            : #define CM_CAM1CTL              0x048
      64                 :            : #define CM_CAM1DIV              0x04c
      65                 :            : #define CM_CCP2CTL              0x050
      66                 :            : #define CM_CCP2DIV              0x054
      67                 :            : #define CM_DSI0ECTL             0x058
      68                 :            : #define CM_DSI0EDIV             0x05c
      69                 :            : #define CM_DSI0PCTL             0x060
      70                 :            : #define CM_DSI0PDIV             0x064
      71                 :            : #define CM_DPICTL               0x068
      72                 :            : #define CM_DPIDIV               0x06c
      73                 :            : #define CM_GP0CTL               0x070
      74                 :            : #define CM_GP0DIV               0x074
      75                 :            : #define CM_GP1CTL               0x078
      76                 :            : #define CM_GP1DIV               0x07c
      77                 :            : #define CM_GP2CTL               0x080
      78                 :            : #define CM_GP2DIV               0x084
      79                 :            : #define CM_HSMCTL               0x088
      80                 :            : #define CM_HSMDIV               0x08c
      81                 :            : #define CM_OTPCTL               0x090
      82                 :            : #define CM_OTPDIV               0x094
      83                 :            : #define CM_PCMCTL               0x098
      84                 :            : #define CM_PCMDIV               0x09c
      85                 :            : #define CM_PWMCTL               0x0a0
      86                 :            : #define CM_PWMDIV               0x0a4
      87                 :            : #define CM_SLIMCTL              0x0a8
      88                 :            : #define CM_SLIMDIV              0x0ac
      89                 :            : #define CM_SMICTL               0x0b0
      90                 :            : #define CM_SMIDIV               0x0b4
      91                 :            : /* no definition for 0x0b8  and 0x0bc */
      92                 :            : #define CM_TCNTCTL              0x0c0
      93                 :            : # define CM_TCNT_SRC1_SHIFT             12
      94                 :            : #define CM_TCNTCNT              0x0c4
      95                 :            : #define CM_TECCTL               0x0c8
      96                 :            : #define CM_TECDIV               0x0cc
      97                 :            : #define CM_TD0CTL               0x0d0
      98                 :            : #define CM_TD0DIV               0x0d4
      99                 :            : #define CM_TD1CTL               0x0d8
     100                 :            : #define CM_TD1DIV               0x0dc
     101                 :            : #define CM_TSENSCTL             0x0e0
     102                 :            : #define CM_TSENSDIV             0x0e4
     103                 :            : #define CM_TIMERCTL             0x0e8
     104                 :            : #define CM_TIMERDIV             0x0ec
     105                 :            : #define CM_UARTCTL              0x0f0
     106                 :            : #define CM_UARTDIV              0x0f4
     107                 :            : #define CM_VECCTL               0x0f8
     108                 :            : #define CM_VECDIV               0x0fc
     109                 :            : #define CM_PULSECTL             0x190
     110                 :            : #define CM_PULSEDIV             0x194
     111                 :            : #define CM_SDCCTL               0x1a8
     112                 :            : #define CM_SDCDIV               0x1ac
     113                 :            : #define CM_ARMCTL               0x1b0
     114                 :            : #define CM_AVEOCTL              0x1b8
     115                 :            : #define CM_AVEODIV              0x1bc
     116                 :            : #define CM_EMMCCTL              0x1c0
     117                 :            : #define CM_EMMCDIV              0x1c4
     118                 :            : #define CM_EMMC2CTL             0x1d0
     119                 :            : #define CM_EMMC2DIV             0x1d4
     120                 :            : 
     121                 :            : /* General bits for the CM_*CTL regs */
     122                 :            : # define CM_ENABLE                      BIT(4)
     123                 :            : # define CM_KILL                        BIT(5)
     124                 :            : # define CM_GATE_BIT                    6
     125                 :            : # define CM_GATE                        BIT(CM_GATE_BIT)
     126                 :            : # define CM_BUSY                        BIT(7)
     127                 :            : # define CM_BUSYD                       BIT(8)
     128                 :            : # define CM_FRAC                        BIT(9)
     129                 :            : # define CM_SRC_SHIFT                   0
     130                 :            : # define CM_SRC_BITS                    4
     131                 :            : # define CM_SRC_MASK                    0xf
     132                 :            : # define CM_SRC_GND                     0
     133                 :            : # define CM_SRC_OSC                     1
     134                 :            : # define CM_SRC_TESTDEBUG0              2
     135                 :            : # define CM_SRC_TESTDEBUG1              3
     136                 :            : # define CM_SRC_PLLA_CORE               4
     137                 :            : # define CM_SRC_PLLA_PER                4
     138                 :            : # define CM_SRC_PLLC_CORE0              5
     139                 :            : # define CM_SRC_PLLC_PER                5
     140                 :            : # define CM_SRC_PLLC_CORE1              8
     141                 :            : # define CM_SRC_PLLD_CORE               6
     142                 :            : # define CM_SRC_PLLD_PER                6
     143                 :            : # define CM_SRC_PLLH_AUX                7
     144                 :            : # define CM_SRC_PLLC_CORE1              8
     145                 :            : # define CM_SRC_PLLC_CORE2              9
     146                 :            : 
     147                 :            : #define CM_OSCCOUNT             0x100
     148                 :            : 
     149                 :            : #define CM_PLLA                 0x104
     150                 :            : # define CM_PLL_ANARST                  BIT(8)
     151                 :            : # define CM_PLLA_HOLDPER                BIT(7)
     152                 :            : # define CM_PLLA_LOADPER                BIT(6)
     153                 :            : # define CM_PLLA_HOLDCORE               BIT(5)
     154                 :            : # define CM_PLLA_LOADCORE               BIT(4)
     155                 :            : # define CM_PLLA_HOLDCCP2               BIT(3)
     156                 :            : # define CM_PLLA_LOADCCP2               BIT(2)
     157                 :            : # define CM_PLLA_HOLDDSI0               BIT(1)
     158                 :            : # define CM_PLLA_LOADDSI0               BIT(0)
     159                 :            : 
     160                 :            : #define CM_PLLC                 0x108
     161                 :            : # define CM_PLLC_HOLDPER                BIT(7)
     162                 :            : # define CM_PLLC_LOADPER                BIT(6)
     163                 :            : # define CM_PLLC_HOLDCORE2              BIT(5)
     164                 :            : # define CM_PLLC_LOADCORE2              BIT(4)
     165                 :            : # define CM_PLLC_HOLDCORE1              BIT(3)
     166                 :            : # define CM_PLLC_LOADCORE1              BIT(2)
     167                 :            : # define CM_PLLC_HOLDCORE0              BIT(1)
     168                 :            : # define CM_PLLC_LOADCORE0              BIT(0)
     169                 :            : 
     170                 :            : #define CM_PLLD                 0x10c
     171                 :            : # define CM_PLLD_HOLDPER                BIT(7)
     172                 :            : # define CM_PLLD_LOADPER                BIT(6)
     173                 :            : # define CM_PLLD_HOLDCORE               BIT(5)
     174                 :            : # define CM_PLLD_LOADCORE               BIT(4)
     175                 :            : # define CM_PLLD_HOLDDSI1               BIT(3)
     176                 :            : # define CM_PLLD_LOADDSI1               BIT(2)
     177                 :            : # define CM_PLLD_HOLDDSI0               BIT(1)
     178                 :            : # define CM_PLLD_LOADDSI0               BIT(0)
     179                 :            : 
     180                 :            : #define CM_PLLH                 0x110
     181                 :            : # define CM_PLLH_LOADRCAL               BIT(2)
     182                 :            : # define CM_PLLH_LOADAUX                BIT(1)
     183                 :            : # define CM_PLLH_LOADPIX                BIT(0)
     184                 :            : 
     185                 :            : #define CM_LOCK                 0x114
     186                 :            : # define CM_LOCK_FLOCKH                 BIT(12)
     187                 :            : # define CM_LOCK_FLOCKD                 BIT(11)
     188                 :            : # define CM_LOCK_FLOCKC                 BIT(10)
     189                 :            : # define CM_LOCK_FLOCKB                 BIT(9)
     190                 :            : # define CM_LOCK_FLOCKA                 BIT(8)
     191                 :            : 
     192                 :            : #define CM_EVENT                0x118
     193                 :            : #define CM_DSI1ECTL             0x158
     194                 :            : #define CM_DSI1EDIV             0x15c
     195                 :            : #define CM_DSI1PCTL             0x160
     196                 :            : #define CM_DSI1PDIV             0x164
     197                 :            : #define CM_DFTCTL               0x168
     198                 :            : #define CM_DFTDIV               0x16c
     199                 :            : 
     200                 :            : #define CM_PLLB                 0x170
     201                 :            : # define CM_PLLB_HOLDARM                BIT(1)
     202                 :            : # define CM_PLLB_LOADARM                BIT(0)
     203                 :            : 
     204                 :            : #define A2W_PLLA_CTRL           0x1100
     205                 :            : #define A2W_PLLC_CTRL           0x1120
     206                 :            : #define A2W_PLLD_CTRL           0x1140
     207                 :            : #define A2W_PLLH_CTRL           0x1160
     208                 :            : #define A2W_PLLB_CTRL           0x11e0
     209                 :            : # define A2W_PLL_CTRL_PRST_DISABLE      BIT(17)
     210                 :            : # define A2W_PLL_CTRL_PWRDN             BIT(16)
     211                 :            : # define A2W_PLL_CTRL_PDIV_MASK         0x000007000
     212                 :            : # define A2W_PLL_CTRL_PDIV_SHIFT        12
     213                 :            : # define A2W_PLL_CTRL_NDIV_MASK         0x0000003ff
     214                 :            : # define A2W_PLL_CTRL_NDIV_SHIFT        0
     215                 :            : 
     216                 :            : #define A2W_PLLA_ANA0           0x1010
     217                 :            : #define A2W_PLLC_ANA0           0x1030
     218                 :            : #define A2W_PLLD_ANA0           0x1050
     219                 :            : #define A2W_PLLH_ANA0           0x1070
     220                 :            : #define A2W_PLLB_ANA0           0x10f0
     221                 :            : 
     222                 :            : #define A2W_PLL_KA_SHIFT        7
     223                 :            : #define A2W_PLL_KA_MASK         GENMASK(9, 7)
     224                 :            : #define A2W_PLL_KI_SHIFT        19
     225                 :            : #define A2W_PLL_KI_MASK         GENMASK(21, 19)
     226                 :            : #define A2W_PLL_KP_SHIFT        15
     227                 :            : #define A2W_PLL_KP_MASK         GENMASK(18, 15)
     228                 :            : 
     229                 :            : #define A2W_PLLH_KA_SHIFT       19
     230                 :            : #define A2W_PLLH_KA_MASK        GENMASK(21, 19)
     231                 :            : #define A2W_PLLH_KI_LOW_SHIFT   22
     232                 :            : #define A2W_PLLH_KI_LOW_MASK    GENMASK(23, 22)
     233                 :            : #define A2W_PLLH_KI_HIGH_SHIFT  0
     234                 :            : #define A2W_PLLH_KI_HIGH_MASK   GENMASK(0, 0)
     235                 :            : #define A2W_PLLH_KP_SHIFT       1
     236                 :            : #define A2W_PLLH_KP_MASK        GENMASK(4, 1)
     237                 :            : 
     238                 :            : #define A2W_XOSC_CTRL           0x1190
     239                 :            : # define A2W_XOSC_CTRL_PLLB_ENABLE      BIT(7)
     240                 :            : # define A2W_XOSC_CTRL_PLLA_ENABLE      BIT(6)
     241                 :            : # define A2W_XOSC_CTRL_PLLD_ENABLE      BIT(5)
     242                 :            : # define A2W_XOSC_CTRL_DDR_ENABLE       BIT(4)
     243                 :            : # define A2W_XOSC_CTRL_CPR1_ENABLE      BIT(3)
     244                 :            : # define A2W_XOSC_CTRL_USB_ENABLE       BIT(2)
     245                 :            : # define A2W_XOSC_CTRL_HDMI_ENABLE      BIT(1)
     246                 :            : # define A2W_XOSC_CTRL_PLLC_ENABLE      BIT(0)
     247                 :            : 
     248                 :            : #define A2W_PLLA_FRAC           0x1200
     249                 :            : #define A2W_PLLC_FRAC           0x1220
     250                 :            : #define A2W_PLLD_FRAC           0x1240
     251                 :            : #define A2W_PLLH_FRAC           0x1260
     252                 :            : #define A2W_PLLB_FRAC           0x12e0
     253                 :            : # define A2W_PLL_FRAC_MASK              ((1 << A2W_PLL_FRAC_BITS) - 1)
     254                 :            : # define A2W_PLL_FRAC_BITS              20
     255                 :            : 
     256                 :            : #define A2W_PLL_CHANNEL_DISABLE         BIT(8)
     257                 :            : #define A2W_PLL_DIV_BITS                8
     258                 :            : #define A2W_PLL_DIV_SHIFT               0
     259                 :            : 
     260                 :            : #define A2W_PLLA_DSI0           0x1300
     261                 :            : #define A2W_PLLA_CORE           0x1400
     262                 :            : #define A2W_PLLA_PER            0x1500
     263                 :            : #define A2W_PLLA_CCP2           0x1600
     264                 :            : 
     265                 :            : #define A2W_PLLC_CORE2          0x1320
     266                 :            : #define A2W_PLLC_CORE1          0x1420
     267                 :            : #define A2W_PLLC_PER            0x1520
     268                 :            : #define A2W_PLLC_CORE0          0x1620
     269                 :            : 
     270                 :            : #define A2W_PLLD_DSI0           0x1340
     271                 :            : #define A2W_PLLD_CORE           0x1440
     272                 :            : #define A2W_PLLD_PER            0x1540
     273                 :            : #define A2W_PLLD_DSI1           0x1640
     274                 :            : 
     275                 :            : #define A2W_PLLH_AUX            0x1360
     276                 :            : #define A2W_PLLH_RCAL           0x1460
     277                 :            : #define A2W_PLLH_PIX            0x1560
     278                 :            : #define A2W_PLLH_STS            0x1660
     279                 :            : 
     280                 :            : #define A2W_PLLH_CTRLR          0x1960
     281                 :            : #define A2W_PLLH_FRACR          0x1a60
     282                 :            : #define A2W_PLLH_AUXR           0x1b60
     283                 :            : #define A2W_PLLH_RCALR          0x1c60
     284                 :            : #define A2W_PLLH_PIXR           0x1d60
     285                 :            : #define A2W_PLLH_STSR           0x1e60
     286                 :            : 
     287                 :            : #define A2W_PLLB_ARM            0x13e0
     288                 :            : #define A2W_PLLB_SP0            0x14e0
     289                 :            : #define A2W_PLLB_SP1            0x15e0
     290                 :            : #define A2W_PLLB_SP2            0x16e0
     291                 :            : 
     292                 :            : #define LOCK_TIMEOUT_NS         100000000
     293                 :            : #define BCM2835_MAX_FB_RATE     1750000000u
     294                 :            : 
     295                 :            : #define SOC_BCM2835             BIT(0)
     296                 :            : #define SOC_BCM2711             BIT(1)
     297                 :            : #define SOC_ALL                 (SOC_BCM2835 | SOC_BCM2711)
     298                 :            : 
     299                 :            : #define VCMSG_ID_CORE_CLOCK     4
     300                 :            : 
     301                 :            : /*
     302                 :            :  * Names of clocks used within the driver that need to be replaced
     303                 :            :  * with an external parent's name.  This array is in the order that
     304                 :            :  * the clocks node in the DT references external clocks.
     305                 :            :  */
     306                 :            : static const char *const cprman_parent_names[] = {
     307                 :            :         "xosc",
     308                 :            :         "dsi0_byte",
     309                 :            :         "dsi0_ddr2",
     310                 :            :         "dsi0_ddr",
     311                 :            :         "dsi1_byte",
     312                 :            :         "dsi1_ddr2",
     313                 :            :         "dsi1_ddr",
     314                 :            : };
     315                 :            : 
     316                 :            : struct bcm2835_cprman {
     317                 :            :         struct device *dev;
     318                 :            :         void __iomem *regs;
     319                 :            :         struct rpi_firmware *fw;
     320                 :            :         spinlock_t regs_lock; /* spinlock for all clocks */
     321                 :            :         unsigned int soc;
     322                 :            : 
     323                 :            :         /*
     324                 :            :          * Real names of cprman clock parents looked up through
     325                 :            :          * of_clk_get_parent_name(), which will be used in the
     326                 :            :          * parent_names[] arrays for clock registration.
     327                 :            :          */
     328                 :            :         const char *real_parent_names[ARRAY_SIZE(cprman_parent_names)];
     329                 :            : 
     330                 :            :         /* Must be last */
     331                 :            :         struct clk_hw_onecell_data onecell;
     332                 :            : };
     333                 :            : 
     334                 :            : struct cprman_plat_data {
     335                 :            :         unsigned int soc;
     336                 :            : };
     337                 :            : 
     338                 :            : static inline void cprman_write(struct bcm2835_cprman *cprman, u32 reg, u32 val)
     339                 :            : {
     340                 :       6417 :         writel(CM_PASSWORD | val, cprman->regs + reg);
     341                 :            : }
     342                 :            : 
     343                 :            : static inline u32 cprman_read(struct bcm2835_cprman *cprman, u32 reg)
     344                 :            : {
     345                 :     164358 :         return readl(cprman->regs + reg);
     346                 :            : }
     347                 :            : 
     348                 :            : /* Does a cycle of measuring a clock through the TCNT clock, which may
     349                 :            :  * source from many other clocks in the system.
     350                 :            :  */
     351                 :            : static unsigned long bcm2835_measure_tcnt_mux(struct bcm2835_cprman *cprman,
     352                 :            :                                               u32 tcnt_mux)
     353                 :            : {
     354                 :            :         u32 osccount = 19200; /* 1ms */
     355                 :            :         u32 count;
     356                 :            :         ktime_t timeout;
     357                 :            : 
     358                 :            :         spin_lock(&cprman->regs_lock);
     359                 :            : 
     360                 :            :         cprman_write(cprman, CM_TCNTCTL, CM_KILL);
     361                 :            : 
     362                 :            :         cprman_write(cprman, CM_TCNTCTL,
     363                 :            :                      (tcnt_mux & CM_SRC_MASK) |
     364                 :            :                      (tcnt_mux >> CM_SRC_BITS) << CM_TCNT_SRC1_SHIFT);
     365                 :            : 
     366                 :            :         cprman_write(cprman, CM_OSCCOUNT, osccount);
     367                 :            : 
     368                 :            :         /* do a kind delay at the start */
     369                 :            :         mdelay(1);
     370                 :            : 
     371                 :            :         /* Finish off whatever is left of OSCCOUNT */
     372                 :            :         timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
     373                 :            :         while (cprman_read(cprman, CM_OSCCOUNT)) {
     374                 :            :                 if (ktime_after(ktime_get(), timeout)) {
     375                 :            :                         dev_err(cprman->dev, "timeout waiting for OSCCOUNT\n");
     376                 :            :                         count = 0;
     377                 :            :                         goto out;
     378                 :            :                 }
     379                 :            :                 cpu_relax();
     380                 :            :         }
     381                 :            : 
     382                 :            :         /* Wait for BUSY to clear. */
     383                 :            :         timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
     384                 :            :         while (cprman_read(cprman, CM_TCNTCTL) & CM_BUSY) {
     385                 :            :                 if (ktime_after(ktime_get(), timeout)) {
     386                 :            :                         dev_err(cprman->dev, "timeout waiting for !BUSY\n");
     387                 :            :                         count = 0;
     388                 :            :                         goto out;
     389                 :            :                 }
     390                 :            :                 cpu_relax();
     391                 :            :         }
     392                 :            : 
     393                 :            :         count = cprman_read(cprman, CM_TCNTCNT);
     394                 :            : 
     395                 :            :         cprman_write(cprman, CM_TCNTCTL, 0);
     396                 :            : 
     397                 :            : out:
     398                 :            :         spin_unlock(&cprman->regs_lock);
     399                 :            : 
     400                 :            :         return count * 1000;
     401                 :            : }
     402                 :            : 
     403                 :       9522 : static void bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base,
     404                 :            :                                   struct debugfs_reg32 *regs, size_t nregs,
     405                 :            :                                   struct dentry *dentry)
     406                 :            : {
     407                 :            :         struct debugfs_regset32 *regset;
     408                 :            : 
     409                 :       9522 :         regset = devm_kzalloc(cprman->dev, sizeof(*regset), GFP_KERNEL);
     410         [ +  - ]:       9522 :         if (!regset)
     411                 :       9522 :                 return;
     412                 :            : 
     413                 :       9522 :         regset->regs = regs;
     414                 :       9522 :         regset->nregs = nregs;
     415                 :       9522 :         regset->base = cprman->regs + base;
     416                 :            : 
     417                 :       9522 :         debugfs_create_regset32("regdump", S_IRUGO, dentry, regset);
     418                 :            : }
     419                 :            : 
     420                 :            : struct bcm2835_pll_data {
     421                 :            :         const char *name;
     422                 :            :         u32 cm_ctrl_reg;
     423                 :            :         u32 a2w_ctrl_reg;
     424                 :            :         u32 frac_reg;
     425                 :            :         u32 ana_reg_base;
     426                 :            :         u32 reference_enable_mask;
     427                 :            :         /* Bit in CM_LOCK to indicate when the PLL has locked. */
     428                 :            :         u32 lock_mask;
     429                 :            : 
     430                 :            :         const struct bcm2835_pll_ana_bits *ana;
     431                 :            : 
     432                 :            :         unsigned long min_rate;
     433                 :            :         unsigned long max_rate;
     434                 :            :         /*
     435                 :            :          * Highest rate for the VCO before we have to use the
     436                 :            :          * pre-divide-by-2.
     437                 :            :          */
     438                 :            :         unsigned long max_fb_rate;
     439                 :            : };
     440                 :            : 
     441                 :            : struct bcm2835_pll_ana_bits {
     442                 :            :         u32 mask0;
     443                 :            :         u32 set0;
     444                 :            :         u32 mask1;
     445                 :            :         u32 set1;
     446                 :            :         u32 mask3;
     447                 :            :         u32 set3;
     448                 :            :         u32 fb_prediv_mask;
     449                 :            : };
     450                 :            : 
     451                 :            : static const struct bcm2835_pll_ana_bits bcm2835_ana_default = {
     452                 :            :         .mask0 = 0,
     453                 :            :         .set0 = 0,
     454                 :            :         .mask1 = A2W_PLL_KI_MASK | A2W_PLL_KP_MASK,
     455                 :            :         .set1 = (2 << A2W_PLL_KI_SHIFT) | (8 << A2W_PLL_KP_SHIFT),
     456                 :            :         .mask3 = A2W_PLL_KA_MASK,
     457                 :            :         .set3 = (2 << A2W_PLL_KA_SHIFT),
     458                 :            :         .fb_prediv_mask = BIT(14),
     459                 :            : };
     460                 :            : 
     461                 :            : static const struct bcm2835_pll_ana_bits bcm2835_ana_pllh = {
     462                 :            :         .mask0 = A2W_PLLH_KA_MASK | A2W_PLLH_KI_LOW_MASK,
     463                 :            :         .set0 = (2 << A2W_PLLH_KA_SHIFT) | (2 << A2W_PLLH_KI_LOW_SHIFT),
     464                 :            :         .mask1 = A2W_PLLH_KI_HIGH_MASK | A2W_PLLH_KP_MASK,
     465                 :            :         .set1 = (6 << A2W_PLLH_KP_SHIFT),
     466                 :            :         .mask3 = 0,
     467                 :            :         .set3 = 0,
     468                 :            :         .fb_prediv_mask = BIT(11),
     469                 :            : };
     470                 :            : 
     471                 :            : struct bcm2835_pll_divider_data {
     472                 :            :         const char *name;
     473                 :            :         const char *source_pll;
     474                 :            : 
     475                 :            :         u32 cm_reg;
     476                 :            :         u32 a2w_reg;
     477                 :            : 
     478                 :            :         u32 load_mask;
     479                 :            :         u32 hold_mask;
     480                 :            :         u32 fixed_divider;
     481                 :            :         u32 flags;
     482                 :            : };
     483                 :            : 
     484                 :            : struct bcm2835_clock_data {
     485                 :            :         const char *name;
     486                 :            : 
     487                 :            :         const char *const *parents;
     488                 :            :         int num_mux_parents;
     489                 :            : 
     490                 :            :         /* Bitmap encoding which parents accept rate change propagation. */
     491                 :            :         unsigned int set_rate_parent;
     492                 :            : 
     493                 :            :         u32 ctl_reg;
     494                 :            :         u32 div_reg;
     495                 :            : 
     496                 :            :         /* Number of integer bits in the divider */
     497                 :            :         u32 int_bits;
     498                 :            :         /* Number of fractional bits in the divider */
     499                 :            :         u32 frac_bits;
     500                 :            : 
     501                 :            :         u32 flags;
     502                 :            : 
     503                 :            :         bool is_vpu_clock;
     504                 :            :         bool is_mash_clock;
     505                 :            :         bool low_jitter;
     506                 :            : 
     507                 :            :         u32 tcnt_mux;
     508                 :            : };
     509                 :            : 
     510                 :            : struct bcm2835_gate_data {
     511                 :            :         const char *name;
     512                 :            :         const char *parent;
     513                 :            : 
     514                 :            :         u32 ctl_reg;
     515                 :            : };
     516                 :            : 
     517                 :            : struct bcm2835_pll {
     518                 :            :         struct clk_hw hw;
     519                 :            :         struct bcm2835_cprman *cprman;
     520                 :            :         const struct bcm2835_pll_data *data;
     521                 :            : };
     522                 :            : 
     523                 :          0 : static int bcm2835_pll_is_on(struct clk_hw *hw)
     524                 :            : {
     525                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     526                 :          0 :         struct bcm2835_cprman *cprman = pll->cprman;
     527                 :          0 :         const struct bcm2835_pll_data *data = pll->data;
     528                 :            : 
     529                 :          0 :         return cprman_read(cprman, data->a2w_ctrl_reg) &
     530                 :            :                 A2W_PLL_CTRL_PRST_DISABLE;
     531                 :            : }
     532                 :            : 
     533                 :            : static u32 bcm2835_pll_get_prediv_mask(struct bcm2835_cprman *cprman,
     534                 :            :                                        const struct bcm2835_pll_data *data)
     535                 :            : {
     536                 :            :         /*
     537                 :            :          * On BCM2711 there isn't a pre-divisor available in the PLL feedback
     538                 :            :          * loop. Bits 13:14 of ANA1 (PLLA,PLLB,PLLC,PLLD) have been re-purposed
     539                 :            :          * for to for VCO RANGE bits.
     540                 :            :          */
     541   [ #  #  +  - ]:        828 :         if (cprman->soc & SOC_BCM2711)
     542                 :            :                 return 0;
     543                 :            : 
     544                 :        828 :         return data->ana->fb_prediv_mask;
     545                 :            : }
     546                 :            : 
     547                 :          0 : static void bcm2835_pll_choose_ndiv_and_fdiv(unsigned long rate,
     548                 :            :                                              unsigned long parent_rate,
     549                 :            :                                              u32 *ndiv, u32 *fdiv)
     550                 :            : {
     551                 :            :         u64 div;
     552                 :            : 
     553                 :          0 :         div = (u64)rate << A2W_PLL_FRAC_BITS;
     554   [ #  #  #  #  :          0 :         do_div(div, parent_rate);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     555                 :            : 
     556                 :          0 :         *ndiv = div >> A2W_PLL_FRAC_BITS;
     557                 :          0 :         *fdiv = div & ((1 << A2W_PLL_FRAC_BITS) - 1);
     558                 :          0 : }
     559                 :            : 
     560                 :        828 : static long bcm2835_pll_rate_from_divisors(unsigned long parent_rate,
     561                 :            :                                            u32 ndiv, u32 fdiv, u32 pdiv)
     562                 :            : {
     563                 :            :         u64 rate;
     564                 :            : 
     565         [ +  - ]:        828 :         if (pdiv == 0)
     566                 :            :                 return 0;
     567                 :            : 
     568                 :        828 :         rate = (u64)parent_rate * ((ndiv << A2W_PLL_FRAC_BITS) + fdiv);
     569   [ -  +  #  #  :        828 :         do_div(rate, pdiv);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   -  + ]
     570                 :        828 :         return rate >> A2W_PLL_FRAC_BITS;
     571                 :            : }
     572                 :            : 
     573                 :          0 : static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate,
     574                 :            :                                    unsigned long *parent_rate)
     575                 :            : {
     576                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     577                 :          0 :         const struct bcm2835_pll_data *data = pll->data;
     578                 :            :         u32 ndiv, fdiv;
     579                 :            : 
     580                 :          0 :         rate = clamp(rate, data->min_rate, data->max_rate);
     581                 :            : 
     582                 :          0 :         bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv);
     583                 :            : 
     584                 :          0 :         return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1);
     585                 :            : }
     586                 :            : 
     587                 :        828 : static unsigned long bcm2835_pll_get_rate(struct clk_hw *hw,
     588                 :            :                                           unsigned long parent_rate)
     589                 :            : {
     590                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     591                 :        828 :         struct bcm2835_cprman *cprman = pll->cprman;
     592                 :        828 :         const struct bcm2835_pll_data *data = pll->data;
     593                 :        828 :         u32 a2wctrl = cprman_read(cprman, data->a2w_ctrl_reg);
     594                 :            :         u32 ndiv, pdiv, fdiv;
     595                 :            :         bool using_prediv;
     596                 :            : 
     597         [ +  - ]:        828 :         if (parent_rate == 0)
     598                 :            :                 return 0;
     599                 :            : 
     600                 :       1656 :         fdiv = cprman_read(cprman, data->frac_reg) & A2W_PLL_FRAC_MASK;
     601                 :        828 :         ndiv = (a2wctrl & A2W_PLL_CTRL_NDIV_MASK) >> A2W_PLL_CTRL_NDIV_SHIFT;
     602                 :        828 :         pdiv = (a2wctrl & A2W_PLL_CTRL_PDIV_MASK) >> A2W_PLL_CTRL_PDIV_SHIFT;
     603                 :       1656 :         using_prediv = cprman_read(cprman, data->ana_reg_base + 4) &
     604                 :            :                        bcm2835_pll_get_prediv_mask(cprman, data);
     605                 :            : 
     606         [ +  + ]:        828 :         if (using_prediv) {
     607                 :        621 :                 ndiv *= 2;
     608                 :        621 :                 fdiv *= 2;
     609                 :            :         }
     610                 :            : 
     611                 :        828 :         return bcm2835_pll_rate_from_divisors(parent_rate, ndiv, fdiv, pdiv);
     612                 :            : }
     613                 :            : 
     614                 :          0 : static void bcm2835_pll_off(struct clk_hw *hw)
     615                 :            : {
     616                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     617                 :          0 :         struct bcm2835_cprman *cprman = pll->cprman;
     618                 :          0 :         const struct bcm2835_pll_data *data = pll->data;
     619                 :            : 
     620                 :            :         spin_lock(&cprman->regs_lock);
     621                 :          0 :         cprman_write(cprman, data->cm_ctrl_reg, CM_PLL_ANARST);
     622                 :            :         cprman_write(cprman, data->a2w_ctrl_reg,
     623                 :          0 :                      cprman_read(cprman, data->a2w_ctrl_reg) |
     624                 :            :                      A2W_PLL_CTRL_PWRDN);
     625                 :            :         spin_unlock(&cprman->regs_lock);
     626                 :          0 : }
     627                 :            : 
     628                 :        828 : static int bcm2835_pll_on(struct clk_hw *hw)
     629                 :            : {
     630                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     631                 :        828 :         struct bcm2835_cprman *cprman = pll->cprman;
     632                 :        828 :         const struct bcm2835_pll_data *data = pll->data;
     633                 :            :         ktime_t timeout;
     634                 :            : 
     635                 :        828 :         cprman_write(cprman, data->a2w_ctrl_reg,
     636                 :        828 :                      cprman_read(cprman, data->a2w_ctrl_reg) &
     637                 :            :                      ~A2W_PLL_CTRL_PWRDN);
     638                 :            : 
     639                 :            :         /* Take the PLL out of reset. */
     640                 :            :         spin_lock(&cprman->regs_lock);
     641                 :        828 :         cprman_write(cprman, data->cm_ctrl_reg,
     642                 :        828 :                      cprman_read(cprman, data->cm_ctrl_reg) & ~CM_PLL_ANARST);
     643                 :            :         spin_unlock(&cprman->regs_lock);
     644                 :            : 
     645                 :            :         /* Wait for the PLL to lock. */
     646         [ +  + ]:        828 :         if (strcmp(data->name, "pllh")) {
     647                 :        621 :                 timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
     648         [ -  + ]:       1242 :                 while (!(cprman_read(cprman, CM_LOCK) & data->lock_mask)) {
     649         [ #  # ]:          0 :                         if (ktime_after(ktime_get(), timeout)) {
     650                 :          0 :                                 dev_err(cprman->dev, "%s: couldn't lock PLL\n",
     651                 :            :                                         clk_hw_get_name(hw));
     652                 :          0 :                                 return -ETIMEDOUT;
     653                 :            :                         }
     654                 :            : 
     655                 :          0 :                         cpu_relax();
     656                 :            :                 }
     657                 :            :         }
     658                 :            : 
     659                 :            :         cprman_write(cprman, data->a2w_ctrl_reg,
     660                 :        828 :                      cprman_read(cprman, data->a2w_ctrl_reg) |
     661                 :            :                      A2W_PLL_CTRL_PRST_DISABLE);
     662                 :            : 
     663                 :        828 :         return 0;
     664                 :            : }
     665                 :            : 
     666                 :            : static void
     667                 :            : bcm2835_pll_write_ana(struct bcm2835_cprman *cprman, u32 ana_reg_base, u32 *ana)
     668                 :            : {
     669                 :            :         int i;
     670                 :            : 
     671                 :            :         /*
     672                 :            :          * ANA register setup is done as a series of writes to
     673                 :            :          * ANA3-ANA0, in that order.  This lets us write all 4
     674                 :            :          * registers as a single cycle of the serdes interface (taking
     675                 :            :          * 100 xosc clocks), whereas if we were to update ana0, 1, and
     676                 :            :          * 3 individually through their partial-write registers, each
     677                 :            :          * would be their own serdes cycle.
     678                 :            :          */
     679   [ #  #  #  # ]:          0 :         for (i = 3; i >= 0; i--)
     680                 :          0 :                 cprman_write(cprman, ana_reg_base + i * 4, ana[i]);
     681                 :            : }
     682                 :            : 
     683                 :          0 : static int bcm2835_pll_set_rate(struct clk_hw *hw,
     684                 :            :                                 unsigned long rate, unsigned long parent_rate)
     685                 :            : {
     686                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     687                 :          0 :         struct bcm2835_cprman *cprman = pll->cprman;
     688                 :          0 :         const struct bcm2835_pll_data *data = pll->data;
     689                 :            :         u32 prediv_mask = bcm2835_pll_get_prediv_mask(cprman, data);
     690                 :            :         bool was_using_prediv, use_fb_prediv, do_ana_setup_first;
     691                 :            :         u32 ndiv, fdiv, a2w_ctl;
     692                 :            :         u32 ana[4];
     693                 :            :         int i;
     694                 :            : 
     695         [ #  # ]:          0 :         if (rate > data->max_fb_rate) {
     696                 :            :                 use_fb_prediv = true;
     697                 :          0 :                 rate /= 2;
     698                 :            :         } else {
     699                 :            :                 use_fb_prediv = false;
     700                 :            :         }
     701                 :            : 
     702                 :          0 :         bcm2835_pll_choose_ndiv_and_fdiv(rate, parent_rate, &ndiv, &fdiv);
     703                 :            : 
     704         [ #  # ]:          0 :         for (i = 3; i >= 0; i--)
     705                 :          0 :                 ana[i] = cprman_read(cprman, data->ana_reg_base + i * 4);
     706                 :            : 
     707                 :          0 :         was_using_prediv = ana[1] & prediv_mask;
     708                 :            : 
     709                 :          0 :         ana[0] &= ~data->ana->mask0;
     710                 :          0 :         ana[0] |= data->ana->set0;
     711                 :          0 :         ana[1] &= ~data->ana->mask1;
     712                 :          0 :         ana[1] |= data->ana->set1;
     713                 :          0 :         ana[3] &= ~data->ana->mask3;
     714                 :          0 :         ana[3] |= data->ana->set3;
     715                 :            : 
     716         [ #  # ]:          0 :         if (was_using_prediv && !use_fb_prediv) {
     717                 :          0 :                 ana[1] &= ~prediv_mask;
     718                 :            :                 do_ana_setup_first = true;
     719         [ #  # ]:          0 :         } else if (!was_using_prediv && use_fb_prediv) {
     720                 :          0 :                 ana[1] |= prediv_mask;
     721                 :            :                 do_ana_setup_first = false;
     722                 :            :         } else {
     723                 :            :                 do_ana_setup_first = true;
     724                 :            :         }
     725                 :            : 
     726                 :            :         /* Unmask the reference clock from the oscillator. */
     727                 :            :         spin_lock(&cprman->regs_lock);
     728                 :          0 :         cprman_write(cprman, A2W_XOSC_CTRL,
     729                 :            :                      cprman_read(cprman, A2W_XOSC_CTRL) |
     730                 :          0 :                      data->reference_enable_mask);
     731                 :            :         spin_unlock(&cprman->regs_lock);
     732                 :            : 
     733         [ #  # ]:          0 :         if (do_ana_setup_first)
     734                 :          0 :                 bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
     735                 :            : 
     736                 :            :         /* Set the PLL multiplier from the oscillator. */
     737                 :          0 :         cprman_write(cprman, data->frac_reg, fdiv);
     738                 :            : 
     739                 :          0 :         a2w_ctl = cprman_read(cprman, data->a2w_ctrl_reg);
     740                 :          0 :         a2w_ctl &= ~A2W_PLL_CTRL_NDIV_MASK;
     741                 :          0 :         a2w_ctl |= ndiv << A2W_PLL_CTRL_NDIV_SHIFT;
     742                 :          0 :         a2w_ctl &= ~A2W_PLL_CTRL_PDIV_MASK;
     743                 :            :         a2w_ctl |= 1 << A2W_PLL_CTRL_PDIV_SHIFT;
     744                 :          0 :         cprman_write(cprman, data->a2w_ctrl_reg, a2w_ctl);
     745                 :            : 
     746         [ #  # ]:          0 :         if (!do_ana_setup_first)
     747                 :          0 :                 bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
     748                 :            : 
     749                 :          0 :         return 0;
     750                 :            : }
     751                 :            : 
     752                 :        828 : static void bcm2835_pll_debug_init(struct clk_hw *hw,
     753                 :            :                                   struct dentry *dentry)
     754                 :            : {
     755                 :            :         struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
     756                 :        828 :         struct bcm2835_cprman *cprman = pll->cprman;
     757                 :        828 :         const struct bcm2835_pll_data *data = pll->data;
     758                 :            :         struct debugfs_reg32 *regs;
     759                 :            : 
     760                 :        828 :         regs = devm_kcalloc(cprman->dev, 7, sizeof(*regs), GFP_KERNEL);
     761         [ +  - ]:        828 :         if (!regs)
     762                 :        828 :                 return;
     763                 :            : 
     764                 :        828 :         regs[0].name = "cm_ctrl";
     765                 :        828 :         regs[0].offset = data->cm_ctrl_reg;
     766                 :        828 :         regs[1].name = "a2w_ctrl";
     767                 :        828 :         regs[1].offset = data->a2w_ctrl_reg;
     768                 :        828 :         regs[2].name = "frac";
     769                 :        828 :         regs[2].offset = data->frac_reg;
     770                 :        828 :         regs[3].name = "ana0";
     771                 :        828 :         regs[3].offset = data->ana_reg_base + 0 * 4;
     772                 :        828 :         regs[4].name = "ana1";
     773                 :        828 :         regs[4].offset = data->ana_reg_base + 1 * 4;
     774                 :        828 :         regs[5].name = "ana2";
     775                 :        828 :         regs[5].offset = data->ana_reg_base + 2 * 4;
     776                 :        828 :         regs[6].name = "ana3";
     777                 :        828 :         regs[6].offset = data->ana_reg_base + 3 * 4;
     778                 :            : 
     779                 :        828 :         bcm2835_debugfs_regset(cprman, 0, regs, 7, dentry);
     780                 :            : }
     781                 :            : 
     782                 :            : static const struct clk_ops bcm2835_pll_clk_ops = {
     783                 :            :         .is_prepared = bcm2835_pll_is_on,
     784                 :            :         .prepare = bcm2835_pll_on,
     785                 :            :         .unprepare = bcm2835_pll_off,
     786                 :            :         .recalc_rate = bcm2835_pll_get_rate,
     787                 :            :         .set_rate = bcm2835_pll_set_rate,
     788                 :            :         .round_rate = bcm2835_pll_round_rate,
     789                 :            :         .debug_init = bcm2835_pll_debug_init,
     790                 :            : };
     791                 :            : 
     792                 :            : struct bcm2835_pll_divider {
     793                 :            :         struct clk_divider div;
     794                 :            :         struct bcm2835_cprman *cprman;
     795                 :            :         const struct bcm2835_pll_divider_data *data;
     796                 :            : };
     797                 :            : 
     798                 :            : static struct bcm2835_pll_divider *
     799                 :            : bcm2835_pll_divider_from_hw(struct clk_hw *hw)
     800                 :            : {
     801                 :            :         return container_of(hw, struct bcm2835_pll_divider, div.hw);
     802                 :            : }
     803                 :            : 
     804                 :          0 : static int bcm2835_pll_divider_is_on(struct clk_hw *hw)
     805                 :            : {
     806                 :            :         struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
     807                 :          0 :         struct bcm2835_cprman *cprman = divider->cprman;
     808                 :          0 :         const struct bcm2835_pll_divider_data *data = divider->data;
     809                 :            : 
     810                 :          0 :         return !(cprman_read(cprman, data->a2w_reg) & A2W_PLL_CHANNEL_DISABLE);
     811                 :            : }
     812                 :            : 
     813                 :          0 : static long bcm2835_pll_divider_round_rate(struct clk_hw *hw,
     814                 :            :                                            unsigned long rate,
     815                 :            :                                            unsigned long *parent_rate)
     816                 :            : {
     817                 :          0 :         return clk_divider_ops.round_rate(hw, rate, parent_rate);
     818                 :            : }
     819                 :            : 
     820                 :       2898 : static unsigned long bcm2835_pll_divider_get_rate(struct clk_hw *hw,
     821                 :            :                                                   unsigned long parent_rate)
     822                 :            : {
     823                 :       2898 :         return clk_divider_ops.recalc_rate(hw, parent_rate);
     824                 :            : }
     825                 :            : 
     826                 :          0 : static void bcm2835_pll_divider_off(struct clk_hw *hw)
     827                 :            : {
     828                 :            :         struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
     829                 :          0 :         struct bcm2835_cprman *cprman = divider->cprman;
     830                 :          0 :         const struct bcm2835_pll_divider_data *data = divider->data;
     831                 :            : 
     832                 :            :         spin_lock(&cprman->regs_lock);
     833                 :          0 :         cprman_write(cprman, data->cm_reg,
     834                 :          0 :                      (cprman_read(cprman, data->cm_reg) &
     835                 :          0 :                       ~data->load_mask) | data->hold_mask);
     836                 :            :         cprman_write(cprman, data->a2w_reg,
     837                 :          0 :                      cprman_read(cprman, data->a2w_reg) |
     838                 :            :                      A2W_PLL_CHANNEL_DISABLE);
     839                 :            :         spin_unlock(&cprman->regs_lock);
     840                 :          0 : }
     841                 :            : 
     842                 :       1656 : static int bcm2835_pll_divider_on(struct clk_hw *hw)
     843                 :            : {
     844                 :            :         struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
     845                 :       1656 :         struct bcm2835_cprman *cprman = divider->cprman;
     846                 :       1656 :         const struct bcm2835_pll_divider_data *data = divider->data;
     847                 :            : 
     848                 :            :         spin_lock(&cprman->regs_lock);
     849                 :       1656 :         cprman_write(cprman, data->a2w_reg,
     850                 :       1656 :                      cprman_read(cprman, data->a2w_reg) &
     851                 :            :                      ~A2W_PLL_CHANNEL_DISABLE);
     852                 :            : 
     853                 :       1656 :         cprman_write(cprman, data->cm_reg,
     854                 :       3312 :                      cprman_read(cprman, data->cm_reg) & ~data->hold_mask);
     855                 :            :         spin_unlock(&cprman->regs_lock);
     856                 :            : 
     857                 :       1656 :         return 0;
     858                 :            : }
     859                 :            : 
     860                 :          0 : static int bcm2835_pll_divider_set_rate(struct clk_hw *hw,
     861                 :            :                                         unsigned long rate,
     862                 :            :                                         unsigned long parent_rate)
     863                 :            : {
     864                 :            :         struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
     865                 :          0 :         struct bcm2835_cprman *cprman = divider->cprman;
     866                 :          0 :         const struct bcm2835_pll_divider_data *data = divider->data;
     867                 :            :         u32 cm, div, max_div = 1 << A2W_PLL_DIV_BITS;
     868                 :            : 
     869   [ #  #  #  #  :          0 :         div = DIV_ROUND_UP_ULL(parent_rate, rate);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     870                 :            : 
     871                 :          0 :         div = min(div, max_div);
     872         [ #  # ]:          0 :         if (div == max_div)
     873                 :            :                 div = 0;
     874                 :            : 
     875                 :          0 :         cprman_write(cprman, data->a2w_reg, div);
     876                 :          0 :         cm = cprman_read(cprman, data->cm_reg);
     877                 :          0 :         cprman_write(cprman, data->cm_reg, cm | data->load_mask);
     878                 :          0 :         cprman_write(cprman, data->cm_reg, cm & ~data->load_mask);
     879                 :            : 
     880                 :          0 :         return 0;
     881                 :            : }
     882                 :            : 
     883                 :       2898 : static void bcm2835_pll_divider_debug_init(struct clk_hw *hw,
     884                 :            :                                            struct dentry *dentry)
     885                 :            : {
     886                 :            :         struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
     887                 :       2898 :         struct bcm2835_cprman *cprman = divider->cprman;
     888                 :       2898 :         const struct bcm2835_pll_divider_data *data = divider->data;
     889                 :            :         struct debugfs_reg32 *regs;
     890                 :            : 
     891                 :       2898 :         regs = devm_kcalloc(cprman->dev, 7, sizeof(*regs), GFP_KERNEL);
     892         [ +  - ]:       2898 :         if (!regs)
     893                 :       2898 :                 return;
     894                 :            : 
     895                 :       2898 :         regs[0].name = "cm";
     896                 :       2898 :         regs[0].offset = data->cm_reg;
     897                 :       2898 :         regs[1].name = "a2w";
     898                 :       2898 :         regs[1].offset = data->a2w_reg;
     899                 :            : 
     900                 :       2898 :         bcm2835_debugfs_regset(cprman, 0, regs, 2, dentry);
     901                 :            : }
     902                 :            : 
     903                 :            : static const struct clk_ops bcm2835_pll_divider_clk_ops = {
     904                 :            :         .is_prepared = bcm2835_pll_divider_is_on,
     905                 :            :         .prepare = bcm2835_pll_divider_on,
     906                 :            :         .unprepare = bcm2835_pll_divider_off,
     907                 :            :         .recalc_rate = bcm2835_pll_divider_get_rate,
     908                 :            :         .set_rate = bcm2835_pll_divider_set_rate,
     909                 :            :         .round_rate = bcm2835_pll_divider_round_rate,
     910                 :            :         .debug_init = bcm2835_pll_divider_debug_init,
     911                 :            : };
     912                 :            : 
     913                 :            : /*
     914                 :            :  * The CM dividers do fixed-point division, so we can't use the
     915                 :            :  * generic integer divider code like the PLL dividers do (and we can't
     916                 :            :  * fake it by having some fixed shifts preceding it in the clock tree,
     917                 :            :  * because we'd run out of bits in a 32-bit unsigned long).
     918                 :            :  */
     919                 :            : struct bcm2835_clock {
     920                 :            :         struct clk_hw hw;
     921                 :            :         struct bcm2835_cprman *cprman;
     922                 :            :         const struct bcm2835_clock_data *data;
     923                 :            : };
     924                 :            : 
     925                 :            : static struct bcm2835_clock *bcm2835_clock_from_hw(struct clk_hw *hw)
     926                 :            : {
     927                 :            :         return container_of(hw, struct bcm2835_clock, hw);
     928                 :            : }
     929                 :            : 
     930                 :          0 : static int bcm2835_clock_is_on(struct clk_hw *hw)
     931                 :            : {
     932                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
     933                 :          0 :         struct bcm2835_cprman *cprman = clock->cprman;
     934                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
     935                 :            : 
     936                 :          0 :         return (cprman_read(cprman, data->ctl_reg) & CM_ENABLE) != 0;
     937                 :            : }
     938                 :            : 
     939                 :          0 : static u32 bcm2835_clock_choose_div(struct clk_hw *hw,
     940                 :            :                                     unsigned long rate,
     941                 :            :                                     unsigned long parent_rate,
     942                 :            :                                     bool round_up)
     943                 :            : {
     944                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
     945                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
     946                 :          0 :         u32 unused_frac_mask =
     947                 :          0 :                 GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0) >> 1;
     948                 :          0 :         u64 temp = (u64)parent_rate << CM_DIV_FRAC_BITS;
     949                 :            :         u64 rem;
     950                 :            :         u32 div, mindiv, maxdiv;
     951                 :            : 
     952   [ #  #  #  #  :          0 :         rem = do_div(temp, rate);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     953                 :          0 :         div = temp;
     954                 :            : 
     955                 :            :         /* Round up and mask off the unused bits */
     956   [ #  #  #  #  :          0 :         if (round_up && ((div & unused_frac_mask) != 0 || rem != 0))
                   #  # ]
     957                 :          0 :                 div += unused_frac_mask + 1;
     958                 :          0 :         div &= ~unused_frac_mask;
     959                 :            : 
     960                 :            :         /* different clamping limits apply for a mash clock */
     961         [ #  # ]:          0 :         if (data->is_mash_clock) {
     962                 :            :                 /* clamp to min divider of 2 */
     963                 :            :                 mindiv = 2 << CM_DIV_FRAC_BITS;
     964                 :            :                 /* clamp to the highest possible integer divider */
     965                 :          0 :                 maxdiv = (BIT(data->int_bits) - 1) << CM_DIV_FRAC_BITS;
     966                 :            :         } else {
     967                 :            :                 /* clamp to min divider of 1 */
     968                 :            :                 mindiv = 1 << CM_DIV_FRAC_BITS;
     969                 :            :                 /* clamp to the highest possible fractional divider */
     970                 :          0 :                 maxdiv = GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
     971                 :            :                                  CM_DIV_FRAC_BITS - data->frac_bits);
     972                 :            :         }
     973                 :            : 
     974                 :            :         /* apply the clamping  limits */
     975                 :          0 :         div = max_t(u32, div, mindiv);
     976                 :          0 :         div = min_t(u32, div, maxdiv);
     977                 :            : 
     978                 :          0 :         return div;
     979                 :            : }
     980                 :            : 
     981                 :       5175 : static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock,
     982                 :            :                                             unsigned long parent_rate,
     983                 :            :                                             u32 div)
     984                 :            : {
     985                 :       5175 :         const struct bcm2835_clock_data *data = clock->data;
     986                 :            :         u64 temp;
     987                 :            : 
     988   [ -  +  #  # ]:       5175 :         if (data->int_bits == 0 && data->frac_bits == 0)
     989                 :          0 :                 return parent_rate;
     990                 :            : 
     991                 :            :         /*
     992                 :            :          * The divisor is a 12.12 fixed point field, but only some of
     993                 :            :          * the bits are populated in any given clock.
     994                 :            :          */
     995                 :       5175 :         div >>= CM_DIV_FRAC_BITS - data->frac_bits;
     996                 :       5175 :         div &= (1 << (data->int_bits + data->frac_bits)) - 1;
     997                 :            : 
     998         [ +  + ]:       5175 :         if (div == 0)
     999                 :            :                 return 0;
    1000                 :            : 
    1001                 :       2277 :         temp = (u64)parent_rate << data->frac_bits;
    1002                 :            : 
    1003   [ -  +  #  #  :       2277 :         do_div(temp, div);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   +  + ]
    1004                 :            : 
    1005                 :       2277 :         return temp;
    1006                 :            : }
    1007                 :            : 
    1008                 :       5589 : static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw,
    1009                 :            :                                             unsigned long parent_rate)
    1010                 :            : {
    1011                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1012                 :       5589 :         struct bcm2835_cprman *cprman = clock->cprman;
    1013                 :       5589 :         const struct bcm2835_clock_data *data = clock->data;
    1014                 :            :         u32 div;
    1015                 :            : 
    1016   [ +  +  -  + ]:       5589 :         if (data->int_bits == 0 && data->frac_bits == 0)
    1017                 :            :                 return parent_rate;
    1018                 :            : 
    1019                 :       5175 :         div = cprman_read(cprman, data->div_reg);
    1020                 :            : 
    1021                 :       5175 :         return bcm2835_clock_rate_from_divisor(clock, parent_rate, div);
    1022                 :            : }
    1023                 :            : 
    1024                 :        207 : static unsigned long bcm2835_clock_get_rate_vpu(struct clk_hw *hw,
    1025                 :            :                                                 unsigned long parent_rate)
    1026                 :            : {
    1027                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1028                 :        207 :         struct bcm2835_cprman *cprman = clock->cprman;
    1029                 :            : 
    1030         [ +  - ]:        207 :         if (cprman->fw) {
    1031                 :            :                 struct {
    1032                 :            :                         u32 id;
    1033                 :            :                         u32 val;
    1034                 :            :                 } packet;
    1035                 :            : 
    1036                 :        207 :                 packet.id = VCMSG_ID_CORE_CLOCK;
    1037                 :        207 :                 packet.val = 0;
    1038                 :            : 
    1039         [ +  - ]:        207 :                 if (!rpi_firmware_property(cprman->fw,
    1040                 :            :                                            RPI_FIRMWARE_GET_MAX_CLOCK_RATE,
    1041                 :            :                                            &packet, sizeof(packet)))
    1042                 :        207 :                         return packet.val;
    1043                 :            :         }
    1044                 :            : 
    1045                 :          0 :         return bcm2835_clock_get_rate(hw, parent_rate);
    1046                 :            : }
    1047                 :            : 
    1048                 :          0 : static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock)
    1049                 :            : {
    1050                 :          0 :         struct bcm2835_cprman *cprman = clock->cprman;
    1051                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
    1052                 :          0 :         ktime_t timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
    1053                 :            : 
    1054         [ #  # ]:          0 :         while (cprman_read(cprman, data->ctl_reg) & CM_BUSY) {
    1055         [ #  # ]:          0 :                 if (ktime_after(ktime_get(), timeout)) {
    1056                 :          0 :                         dev_err(cprman->dev, "%s: couldn't lock PLL\n",
    1057                 :            :                                 clk_hw_get_name(&clock->hw));
    1058                 :          0 :                         return;
    1059                 :            :                 }
    1060                 :          0 :                 cpu_relax();
    1061                 :            :         }
    1062                 :            : }
    1063                 :            : 
    1064                 :          0 : static void bcm2835_clock_off(struct clk_hw *hw)
    1065                 :            : {
    1066                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1067                 :          0 :         struct bcm2835_cprman *cprman = clock->cprman;
    1068                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
    1069                 :            : 
    1070                 :            :         spin_lock(&cprman->regs_lock);
    1071                 :          0 :         cprman_write(cprman, data->ctl_reg,
    1072                 :          0 :                      cprman_read(cprman, data->ctl_reg) & ~CM_ENABLE);
    1073                 :            :         spin_unlock(&cprman->regs_lock);
    1074                 :            : 
    1075                 :            :         /* BUSY will remain high until the divider completes its cycle. */
    1076                 :          0 :         bcm2835_clock_wait_busy(clock);
    1077                 :          0 : }
    1078                 :            : 
    1079                 :        621 : static int bcm2835_clock_on(struct clk_hw *hw)
    1080                 :            : {
    1081                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1082                 :        621 :         struct bcm2835_cprman *cprman = clock->cprman;
    1083                 :        621 :         const struct bcm2835_clock_data *data = clock->data;
    1084                 :            : 
    1085                 :            :         spin_lock(&cprman->regs_lock);
    1086                 :            :         cprman_write(cprman, data->ctl_reg,
    1087                 :        621 :                      cprman_read(cprman, data->ctl_reg) |
    1088                 :            :                      CM_ENABLE |
    1089                 :            :                      CM_GATE);
    1090                 :            :         spin_unlock(&cprman->regs_lock);
    1091                 :            : 
    1092                 :            :         /* Debug code to measure the clock once it's turned on to see
    1093                 :            :          * if it's ticking at the rate we expect.
    1094                 :            :          */
    1095                 :            :         if (data->tcnt_mux && false) {
    1096                 :            :                 dev_info(cprman->dev,
    1097                 :            :                          "clk %s: rate %ld, measure %ld\n",
    1098                 :            :                          data->name,
    1099                 :            :                          clk_hw_get_rate(hw),
    1100                 :            :                          bcm2835_measure_tcnt_mux(cprman, data->tcnt_mux));
    1101                 :            :         }
    1102                 :            : 
    1103                 :        621 :         return 0;
    1104                 :            : }
    1105                 :            : 
    1106                 :          0 : static int bcm2835_clock_set_rate_and_parent(struct clk_hw *hw,
    1107                 :            :                                              unsigned long rate,
    1108                 :            :                                              unsigned long parent_rate,
    1109                 :            :                                              u8 parent)
    1110                 :            : {
    1111                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1112                 :          0 :         struct bcm2835_cprman *cprman = clock->cprman;
    1113                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
    1114                 :          0 :         u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate, false);
    1115                 :            :         u32 ctl;
    1116                 :            : 
    1117                 :            :         spin_lock(&cprman->regs_lock);
    1118                 :            : 
    1119                 :          0 :         ctl = cprman_read(cprman, data->ctl_reg);
    1120                 :            : 
    1121                 :            :         /* If the clock is running, we have to pause clock generation while
    1122                 :            :          * updating the control and div regs.  This is glitchless (no clock
    1123                 :            :          * signals generated faster than the rate) but each reg access is two
    1124                 :            :          * OSC cycles so the clock will slow down for a moment.
    1125                 :            :          */
    1126         [ #  # ]:          0 :         if (ctl & CM_ENABLE) {
    1127                 :          0 :                 cprman_write(cprman, data->ctl_reg, ctl & ~CM_ENABLE);
    1128                 :          0 :                 bcm2835_clock_wait_busy(clock);
    1129                 :            :         }
    1130                 :            : 
    1131         [ #  # ]:          0 :         if (parent != 0xff) {
    1132                 :          0 :                 ctl &= ~(CM_SRC_MASK << CM_SRC_SHIFT);
    1133                 :          0 :                 ctl |= parent << CM_SRC_SHIFT;
    1134                 :            :         }
    1135                 :            : 
    1136                 :          0 :         ctl &= ~CM_FRAC;
    1137         [ #  # ]:          0 :         ctl |= (div & CM_DIV_FRAC_MASK) ? CM_FRAC : 0;
    1138                 :          0 :         cprman_write(cprman, data->ctl_reg, ctl);
    1139                 :            : 
    1140                 :          0 :         cprman_write(cprman, data->div_reg, div);
    1141                 :            : 
    1142                 :            :         spin_unlock(&cprman->regs_lock);
    1143                 :            : 
    1144                 :          0 :         return 0;
    1145                 :            : }
    1146                 :            : 
    1147                 :          0 : static int bcm2835_clock_set_rate(struct clk_hw *hw,
    1148                 :            :                                   unsigned long rate, unsigned long parent_rate)
    1149                 :            : {
    1150                 :          0 :         return bcm2835_clock_set_rate_and_parent(hw, rate, parent_rate, 0xff);
    1151                 :            : }
    1152                 :            : 
    1153                 :            : static bool
    1154                 :          0 : bcm2835_clk_is_pllc(struct clk_hw *hw)
    1155                 :            : {
    1156         [ #  # ]:          0 :         if (!hw)
    1157                 :            :                 return false;
    1158                 :            : 
    1159                 :          0 :         return strncmp(clk_hw_get_name(hw), "pllc", 4) == 0;
    1160                 :            : }
    1161                 :            : 
    1162                 :          0 : static unsigned long bcm2835_clock_choose_div_and_prate(struct clk_hw *hw,
    1163                 :            :                                                         int parent_idx,
    1164                 :            :                                                         unsigned long rate,
    1165                 :            :                                                         u32 *div,
    1166                 :            :                                                         unsigned long *prate,
    1167                 :            :                                                         unsigned long *avgrate)
    1168                 :            : {
    1169                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1170                 :          0 :         struct bcm2835_cprman *cprman = clock->cprman;
    1171                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
    1172                 :            :         unsigned long best_rate = 0;
    1173                 :            :         u32 curdiv, mindiv, maxdiv;
    1174                 :            :         struct clk_hw *parent;
    1175                 :            : 
    1176                 :          0 :         parent = clk_hw_get_parent_by_index(hw, parent_idx);
    1177                 :            : 
    1178         [ #  # ]:          0 :         if (!(BIT(parent_idx) & data->set_rate_parent)) {
    1179                 :          0 :                 *prate = clk_hw_get_rate(parent);
    1180                 :          0 :                 *div = bcm2835_clock_choose_div(hw, rate, *prate, true);
    1181                 :            : 
    1182                 :          0 :                 *avgrate = bcm2835_clock_rate_from_divisor(clock, *prate, *div);
    1183                 :            : 
    1184   [ #  #  #  # ]:          0 :                 if (data->low_jitter && (*div & CM_DIV_FRAC_MASK)) {
    1185                 :            :                         unsigned long high, low;
    1186                 :          0 :                         u32 int_div = *div & ~CM_DIV_FRAC_MASK;
    1187                 :            : 
    1188                 :          0 :                         high = bcm2835_clock_rate_from_divisor(clock, *prate,
    1189                 :            :                                                                int_div);
    1190                 :          0 :                         int_div += CM_DIV_FRAC_MASK + 1;
    1191                 :          0 :                         low = bcm2835_clock_rate_from_divisor(clock, *prate,
    1192                 :            :                                                               int_div);
    1193                 :            : 
    1194                 :            :                         /*
    1195                 :            :                          * Return a value which is the maximum deviation
    1196                 :            :                          * below the ideal rate, for use as a metric.
    1197                 :            :                          */
    1198                 :          0 :                         return *avgrate - max(*avgrate - low, high - *avgrate);
    1199                 :            :                 }
    1200                 :            :                 return *avgrate;
    1201                 :            :         }
    1202                 :            : 
    1203         [ #  # ]:          0 :         if (data->frac_bits)
    1204                 :          0 :                 dev_warn(cprman->dev,
    1205                 :            :                         "frac bits are not used when propagating rate change");
    1206                 :            : 
    1207                 :            :         /* clamp to min divider of 2 if we're dealing with a mash clock */
    1208         [ #  # ]:          0 :         mindiv = data->is_mash_clock ? 2 : 1;
    1209                 :          0 :         maxdiv = BIT(data->int_bits) - 1;
    1210                 :            : 
    1211                 :            :         /* TODO: Be smart, and only test a subset of the available divisors. */
    1212         [ #  # ]:          0 :         for (curdiv = mindiv; curdiv <= maxdiv; curdiv++) {
    1213                 :            :                 unsigned long tmp_rate;
    1214                 :            : 
    1215                 :          0 :                 tmp_rate = clk_hw_round_rate(parent, rate * curdiv);
    1216                 :          0 :                 tmp_rate /= curdiv;
    1217   [ #  #  #  # ]:          0 :                 if (curdiv == mindiv ||
    1218                 :          0 :                     (tmp_rate > best_rate && tmp_rate <= rate))
    1219                 :            :                         best_rate = tmp_rate;
    1220                 :            : 
    1221         [ #  # ]:          0 :                 if (best_rate == rate)
    1222                 :            :                         break;
    1223                 :            :         }
    1224                 :            : 
    1225                 :          0 :         *div = curdiv << CM_DIV_FRAC_BITS;
    1226                 :          0 :         *prate = curdiv * best_rate;
    1227                 :          0 :         *avgrate = best_rate;
    1228                 :            : 
    1229                 :          0 :         return best_rate;
    1230                 :            : }
    1231                 :            : 
    1232                 :          0 : static int bcm2835_clock_determine_rate(struct clk_hw *hw,
    1233                 :            :                                         struct clk_rate_request *req)
    1234                 :            : {
    1235                 :            :         struct clk_hw *parent, *best_parent = NULL;
    1236                 :            :         bool current_parent_is_pllc;
    1237                 :            :         unsigned long rate, best_rate = 0;
    1238                 :            :         unsigned long prate, best_prate = 0;
    1239                 :            :         unsigned long avgrate, best_avgrate = 0;
    1240                 :            :         size_t i;
    1241                 :            :         u32 div;
    1242                 :            : 
    1243                 :          0 :         current_parent_is_pllc = bcm2835_clk_is_pllc(clk_hw_get_parent(hw));
    1244                 :            : 
    1245                 :            :         /*
    1246                 :            :          * Select parent clock that results in the closest but lower rate
    1247                 :            :          */
    1248         [ #  # ]:          0 :         for (i = 0; i < clk_hw_get_num_parents(hw); ++i) {
    1249                 :          0 :                 parent = clk_hw_get_parent_by_index(hw, i);
    1250         [ #  # ]:          0 :                 if (!parent)
    1251                 :          0 :                         continue;
    1252                 :            : 
    1253                 :            :                 /*
    1254                 :            :                  * Don't choose a PLLC-derived clock as our parent
    1255                 :            :                  * unless it had been manually set that way.  PLLC's
    1256                 :            :                  * frequency gets adjusted by the firmware due to
    1257                 :            :                  * over-temp or under-voltage conditions, without
    1258                 :            :                  * prior notification to our clock consumer.
    1259                 :            :                  */
    1260   [ #  #  #  # ]:          0 :                 if (bcm2835_clk_is_pllc(parent) && !current_parent_is_pllc)
    1261                 :          0 :                         continue;
    1262                 :            : 
    1263                 :          0 :                 rate = bcm2835_clock_choose_div_and_prate(hw, i, req->rate,
    1264                 :            :                                                           &div, &prate,
    1265                 :            :                                                           &avgrate);
    1266   [ #  #  #  # ]:          0 :                 if (rate > best_rate && rate <= req->rate) {
    1267                 :            :                         best_parent = parent;
    1268                 :          0 :                         best_prate = prate;
    1269                 :            :                         best_rate = rate;
    1270                 :          0 :                         best_avgrate = avgrate;
    1271                 :            :                 }
    1272                 :            :         }
    1273                 :            : 
    1274         [ #  # ]:          0 :         if (!best_parent)
    1275                 :            :                 return -EINVAL;
    1276                 :            : 
    1277                 :          0 :         req->best_parent_hw = best_parent;
    1278                 :          0 :         req->best_parent_rate = best_prate;
    1279                 :            : 
    1280                 :          0 :         req->rate = best_avgrate;
    1281                 :            : 
    1282                 :          0 :         return 0;
    1283                 :            : }
    1284                 :            : 
    1285                 :          0 : static int bcm2835_clock_set_parent(struct clk_hw *hw, u8 index)
    1286                 :            : {
    1287                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1288                 :          0 :         struct bcm2835_cprman *cprman = clock->cprman;
    1289                 :          0 :         const struct bcm2835_clock_data *data = clock->data;
    1290                 :          0 :         u8 src = (index << CM_SRC_SHIFT) & CM_SRC_MASK;
    1291                 :            : 
    1292                 :          0 :         cprman_write(cprman, data->ctl_reg, src);
    1293                 :          0 :         return 0;
    1294                 :            : }
    1295                 :            : 
    1296                 :      53199 : static u8 bcm2835_clock_get_parent(struct clk_hw *hw)
    1297                 :            : {
    1298                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1299                 :      53199 :         struct bcm2835_cprman *cprman = clock->cprman;
    1300                 :      53199 :         const struct bcm2835_clock_data *data = clock->data;
    1301                 :      53199 :         u32 src = cprman_read(cprman, data->ctl_reg);
    1302                 :            : 
    1303                 :      53199 :         return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
    1304                 :            : }
    1305                 :            : 
    1306                 :            : static struct debugfs_reg32 bcm2835_debugfs_clock_reg32[] = {
    1307                 :            :         {
    1308                 :            :                 .name = "ctl",
    1309                 :            :                 .offset = 0,
    1310                 :            :         },
    1311                 :            :         {
    1312                 :            :                 .name = "div",
    1313                 :            :                 .offset = 4,
    1314                 :            :         },
    1315                 :            : };
    1316                 :            : 
    1317                 :       5796 : static void bcm2835_clock_debug_init(struct clk_hw *hw,
    1318                 :            :                                     struct dentry *dentry)
    1319                 :            : {
    1320                 :            :         struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
    1321                 :       5796 :         struct bcm2835_cprman *cprman = clock->cprman;
    1322                 :       5796 :         const struct bcm2835_clock_data *data = clock->data;
    1323                 :            : 
    1324                 :       5796 :         bcm2835_debugfs_regset(cprman, data->ctl_reg,
    1325                 :            :                 bcm2835_debugfs_clock_reg32,
    1326                 :            :                 ARRAY_SIZE(bcm2835_debugfs_clock_reg32),
    1327                 :            :                 dentry);
    1328                 :       5796 : }
    1329                 :            : 
    1330                 :            : static const struct clk_ops bcm2835_clock_clk_ops = {
    1331                 :            :         .is_prepared = bcm2835_clock_is_on,
    1332                 :            :         .prepare = bcm2835_clock_on,
    1333                 :            :         .unprepare = bcm2835_clock_off,
    1334                 :            :         .recalc_rate = bcm2835_clock_get_rate,
    1335                 :            :         .set_rate = bcm2835_clock_set_rate,
    1336                 :            :         .set_rate_and_parent = bcm2835_clock_set_rate_and_parent,
    1337                 :            :         .determine_rate = bcm2835_clock_determine_rate,
    1338                 :            :         .set_parent = bcm2835_clock_set_parent,
    1339                 :            :         .get_parent = bcm2835_clock_get_parent,
    1340                 :            :         .debug_init = bcm2835_clock_debug_init,
    1341                 :            : };
    1342                 :            : 
    1343                 :          0 : static int bcm2835_vpu_clock_is_on(struct clk_hw *hw)
    1344                 :            : {
    1345                 :          0 :         return true;
    1346                 :            : }
    1347                 :            : 
    1348                 :            : /*
    1349                 :            :  * The VPU clock can never be disabled (it doesn't have an ENABLE
    1350                 :            :  * bit), so it gets its own set of clock ops.
    1351                 :            :  */
    1352                 :            : static const struct clk_ops bcm2835_vpu_clock_clk_ops = {
    1353                 :            :         .is_prepared = bcm2835_vpu_clock_is_on,
    1354                 :            :         .recalc_rate = bcm2835_clock_get_rate_vpu,
    1355                 :            :         .set_rate = bcm2835_clock_set_rate,
    1356                 :            :         .determine_rate = bcm2835_clock_determine_rate,
    1357                 :            :         .set_parent = bcm2835_clock_set_parent,
    1358                 :            :         .get_parent = bcm2835_clock_get_parent,
    1359                 :            :         .debug_init = bcm2835_clock_debug_init,
    1360                 :            : };
    1361                 :            : 
    1362                 :            : static bool bcm2835_clk_is_claimed(const char *name);
    1363                 :            : 
    1364                 :        828 : static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
    1365                 :            :                                            const struct bcm2835_pll_data *data)
    1366                 :            : {
    1367                 :            :         struct bcm2835_pll *pll;
    1368                 :            :         struct clk_init_data init;
    1369                 :            :         int ret;
    1370                 :            : 
    1371                 :        828 :         memset(&init, 0, sizeof(init));
    1372                 :            : 
    1373                 :            :         /* All of the PLLs derive from the external oscillator. */
    1374                 :        828 :         init.parent_names = &cprman->real_parent_names[0];
    1375                 :        828 :         init.num_parents = 1;
    1376                 :        828 :         init.name = data->name;
    1377                 :        828 :         init.ops = &bcm2835_pll_clk_ops;
    1378                 :        828 :         init.flags = CLK_IGNORE_UNUSED;
    1379                 :            : 
    1380         [ +  - ]:        828 :         if (!bcm2835_clk_is_claimed(data->name))
    1381                 :        828 :                 init.flags |= CLK_IS_CRITICAL;
    1382                 :            : 
    1383                 :        828 :         pll = kzalloc(sizeof(*pll), GFP_KERNEL);
    1384         [ +  - ]:        828 :         if (!pll)
    1385                 :            :                 return NULL;
    1386                 :            : 
    1387                 :        828 :         pll->cprman = cprman;
    1388                 :        828 :         pll->data = data;
    1389                 :        828 :         pll->hw.init = &init;
    1390                 :            : 
    1391                 :        828 :         ret = devm_clk_hw_register(cprman->dev, &pll->hw);
    1392         [ +  - ]:        828 :         if (ret)
    1393                 :            :                 return NULL;
    1394                 :        828 :         return &pll->hw;
    1395                 :            : }
    1396                 :            : 
    1397                 :            : static struct clk_hw *
    1398                 :       2898 : bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
    1399                 :            :                              const struct bcm2835_pll_divider_data *data)
    1400                 :            : {
    1401                 :            :         struct bcm2835_pll_divider *divider;
    1402                 :            :         struct clk_init_data init;
    1403                 :            :         const char *divider_name;
    1404                 :            :         int ret;
    1405                 :            : 
    1406         [ +  + ]:       2898 :         if (data->fixed_divider != 1) {
    1407                 :        414 :                 divider_name = devm_kasprintf(cprman->dev, GFP_KERNEL,
    1408                 :            :                                               "%s_prediv", data->name);
    1409         [ +  - ]:        414 :                 if (!divider_name)
    1410                 :            :                         return NULL;
    1411                 :            :         } else {
    1412                 :       2484 :                 divider_name = data->name;
    1413                 :            :         }
    1414                 :            : 
    1415                 :       2898 :         memset(&init, 0, sizeof(init));
    1416                 :            : 
    1417                 :       2898 :         init.parent_names = &data->source_pll;
    1418                 :       2898 :         init.num_parents = 1;
    1419                 :       2898 :         init.name = divider_name;
    1420                 :       2898 :         init.ops = &bcm2835_pll_divider_clk_ops;
    1421                 :       2898 :         init.flags = data->flags | CLK_IGNORE_UNUSED;
    1422                 :            : 
    1423                 :       2898 :         divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL);
    1424         [ +  - ]:       2898 :         if (!divider)
    1425                 :            :                 return NULL;
    1426                 :            : 
    1427                 :       2898 :         divider->div.reg = cprman->regs + data->a2w_reg;
    1428                 :       2898 :         divider->div.shift = A2W_PLL_DIV_SHIFT;
    1429                 :       2898 :         divider->div.width = A2W_PLL_DIV_BITS;
    1430                 :       2898 :         divider->div.flags = CLK_DIVIDER_MAX_AT_ZERO;
    1431                 :       2898 :         divider->div.lock = &cprman->regs_lock;
    1432                 :       2898 :         divider->div.hw.init = &init;
    1433                 :       2898 :         divider->div.table = NULL;
    1434                 :            : 
    1435         [ +  + ]:       5796 :         if (!(cprman_read(cprman, data->cm_reg) & data->hold_mask)) {
    1436         [ +  - ]:       1656 :                 if (!bcm2835_clk_is_claimed(data->source_pll))
    1437                 :       1656 :                         init.flags |= CLK_IS_CRITICAL;
    1438                 :            :                 if (!bcm2835_clk_is_claimed(data->name))
    1439                 :            :                         divider->div.flags |= CLK_IS_CRITICAL;
    1440                 :            :         }
    1441                 :            : 
    1442                 :       2898 :         divider->cprman = cprman;
    1443                 :       2898 :         divider->data = data;
    1444                 :            : 
    1445                 :       2898 :         ret = devm_clk_hw_register(cprman->dev, &divider->div.hw);
    1446         [ -  + ]:       2898 :         if (ret)
    1447                 :          0 :                 return ERR_PTR(ret);
    1448                 :            : 
    1449                 :            :         /*
    1450                 :            :          * PLLH's channels have a fixed divide by 10 afterwards, which
    1451                 :            :          * is what our consumers are actually using.
    1452                 :            :          */
    1453         [ +  + ]:       2898 :         if (data->fixed_divider != 1) {
    1454                 :        414 :                 return clk_hw_register_fixed_factor(cprman->dev, data->name,
    1455                 :            :                                                     divider_name,
    1456                 :            :                                                     CLK_SET_RATE_PARENT,
    1457                 :            :                                                     1,
    1458                 :            :                                                     data->fixed_divider);
    1459                 :            :         }
    1460                 :            : 
    1461                 :            :         return &divider->div.hw;
    1462                 :            : }
    1463                 :            : 
    1464                 :       5796 : static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
    1465                 :            :                                           const struct bcm2835_clock_data *data)
    1466                 :            : {
    1467                 :            :         struct bcm2835_clock *clock;
    1468                 :            :         struct clk_init_data init;
    1469                 :            :         const char *parents[1 << CM_SRC_BITS];
    1470                 :            :         size_t i;
    1471                 :            :         int ret;
    1472                 :            : 
    1473                 :            :         /*
    1474                 :            :          * Replace our strings referencing parent clocks with the
    1475                 :            :          * actual clock-output-name of the parent.
    1476                 :            :          */
    1477         [ +  + ]:      51336 :         for (i = 0; i < data->num_mux_parents; i++) {
    1478                 :      45540 :                 parents[i] = data->parents[i];
    1479                 :            : 
    1480                 :      45540 :                 ret = match_string(cprman_parent_names,
    1481                 :            :                                    ARRAY_SIZE(cprman_parent_names),
    1482                 :            :                                    parents[i]);
    1483         [ +  + ]:      45540 :                 if (ret >= 0)
    1484                 :       7038 :                         parents[i] = cprman->real_parent_names[ret];
    1485                 :            :         }
    1486                 :            : 
    1487                 :       5796 :         memset(&init, 0, sizeof(init));
    1488                 :       5796 :         init.parent_names = parents;
    1489                 :       5796 :         init.num_parents = data->num_mux_parents;
    1490                 :       5796 :         init.name = data->name;
    1491                 :       5796 :         init.flags = data->flags | CLK_IGNORE_UNUSED;
    1492                 :            : 
    1493                 :            :         /*
    1494                 :            :          * Some GPIO clocks for ethernet/wifi PLLs are marked as
    1495                 :            :          * critical (since some platforms use them), but if the
    1496                 :            :          * firmware didn't have them turned on then they clearly
    1497                 :            :          * aren't actually critical.
    1498                 :            :          */
    1499         [ +  + ]:      11592 :         if ((cprman_read(cprman, data->ctl_reg) & CM_ENABLE) == 0)
    1500                 :       4140 :                 init.flags &= ~CLK_IS_CRITICAL;
    1501                 :            : 
    1502                 :            :         /*
    1503                 :            :          * Pass the CLK_SET_RATE_PARENT flag if we are allowed to propagate
    1504                 :            :          * rate changes on at least of the parents.
    1505                 :            :          */
    1506         [ +  + ]:       5796 :         if (data->set_rate_parent)
    1507                 :        207 :                 init.flags |= CLK_SET_RATE_PARENT;
    1508                 :            : 
    1509         [ +  + ]:       5796 :         if (data->is_vpu_clock) {
    1510                 :        207 :                 init.ops = &bcm2835_vpu_clock_clk_ops;
    1511                 :            :         } else {
    1512                 :       5589 :                 init.ops = &bcm2835_clock_clk_ops;
    1513                 :            : 
    1514                 :            :                 /* If the clock wasn't actually enabled at boot, it's not
    1515                 :            :                  * critical.
    1516                 :            :                  */
    1517         [ +  + ]:      11178 :                 if (!(cprman_read(cprman, data->ctl_reg) & CM_ENABLE))
    1518                 :       3933 :                         init.flags &= ~CLK_IS_CRITICAL;
    1519                 :            :         }
    1520                 :            : 
    1521                 :       5796 :         clock = devm_kzalloc(cprman->dev, sizeof(*clock), GFP_KERNEL);
    1522         [ +  - ]:       5796 :         if (!clock)
    1523                 :            :                 return NULL;
    1524                 :            : 
    1525                 :       5796 :         clock->cprman = cprman;
    1526                 :       5796 :         clock->data = data;
    1527                 :       5796 :         clock->hw.init = &init;
    1528                 :            : 
    1529                 :       5796 :         ret = devm_clk_hw_register(cprman->dev, &clock->hw);
    1530         [ -  + ]:       5796 :         if (ret)
    1531                 :          0 :                 return ERR_PTR(ret);
    1532                 :            :         return &clock->hw;
    1533                 :            : }
    1534                 :            : 
    1535                 :        207 : static struct clk_hw *bcm2835_register_gate(struct bcm2835_cprman *cprman,
    1536                 :            :                                          const struct bcm2835_gate_data *data)
    1537                 :            : {
    1538                 :        414 :         return clk_hw_register_gate(cprman->dev, data->name, data->parent,
    1539                 :            :                                     CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
    1540                 :        207 :                                     cprman->regs + data->ctl_reg,
    1541                 :            :                                     CM_GATE_BIT, 0, &cprman->regs_lock);
    1542                 :            : }
    1543                 :            : 
    1544                 :            : typedef struct clk_hw *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman,
    1545                 :            :                                                const void *data);
    1546                 :            : struct bcm2835_clk_desc {
    1547                 :            :         bcm2835_clk_register clk_register;
    1548                 :            :         unsigned int supported;
    1549                 :            :         const void *data;
    1550                 :            : };
    1551                 :            : 
    1552                 :            : /* assignment helper macros for different clock types */
    1553                 :            : #define _REGISTER(f, s, ...) { .clk_register = (bcm2835_clk_register)f, \
    1554                 :            :                                .supported = s,                          \
    1555                 :            :                                .data = __VA_ARGS__ }
    1556                 :            : #define REGISTER_PLL(s, ...)    _REGISTER(&bcm2835_register_pll,    \
    1557                 :            :                                           s,                            \
    1558                 :            :                                           &(struct bcm2835_pll_data)        \
    1559                 :            :                                           {__VA_ARGS__})
    1560                 :            : #define REGISTER_PLL_DIV(s, ...) _REGISTER(&bcm2835_register_pll_divider, \
    1561                 :            :                                            s,                             \
    1562                 :            :                                            &(struct bcm2835_pll_divider_data) \
    1563                 :            :                                            {__VA_ARGS__})
    1564                 :            : #define REGISTER_CLK(s, ...)    _REGISTER(&bcm2835_register_clock,  \
    1565                 :            :                                           s,                            \
    1566                 :            :                                           &(struct bcm2835_clock_data)      \
    1567                 :            :                                           {__VA_ARGS__})
    1568                 :            : #define REGISTER_GATE(s, ...)   _REGISTER(&bcm2835_register_gate,   \
    1569                 :            :                                           s,                            \
    1570                 :            :                                           &(struct bcm2835_gate_data)       \
    1571                 :            :                                           {__VA_ARGS__})
    1572                 :            : 
    1573                 :            : /* parent mux arrays plus helper macros */
    1574                 :            : 
    1575                 :            : /* main oscillator parent mux */
    1576                 :            : static const char *const bcm2835_clock_osc_parents[] = {
    1577                 :            :         "gnd",
    1578                 :            :         "xosc",
    1579                 :            :         "testdebug0",
    1580                 :            :         "testdebug1"
    1581                 :            : };
    1582                 :            : 
    1583                 :            : #define REGISTER_OSC_CLK(s, ...)        REGISTER_CLK(                   \
    1584                 :            :         s,                                                              \
    1585                 :            :         .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents),       \
    1586                 :            :         .parents = bcm2835_clock_osc_parents,                           \
    1587                 :            :         __VA_ARGS__)
    1588                 :            : 
    1589                 :            : /* main peripherial parent mux */
    1590                 :            : static const char *const bcm2835_clock_per_parents[] = {
    1591                 :            :         "gnd",
    1592                 :            :         "xosc",
    1593                 :            :         "testdebug0",
    1594                 :            :         "testdebug1",
    1595                 :            :         "plla_per",
    1596                 :            :         "pllc_per",
    1597                 :            :         "plld_per",
    1598                 :            :         "pllh_aux",
    1599                 :            : };
    1600                 :            : 
    1601                 :            : #define REGISTER_PER_CLK(s, ...)        REGISTER_CLK(                   \
    1602                 :            :         s,                                                              \
    1603                 :            :         .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents),       \
    1604                 :            :         .parents = bcm2835_clock_per_parents,                           \
    1605                 :            :         __VA_ARGS__)
    1606                 :            : 
    1607                 :            : /*
    1608                 :            :  * Restrict clock sources for the PCM peripheral to the oscillator and
    1609                 :            :  * PLLD_PER because other source may have varying rates or be switched
    1610                 :            :  * off.
    1611                 :            :  *
    1612                 :            :  * Prevent other sources from being selected by replacing their names in
    1613                 :            :  * the list of potential parents with dummy entries (entry index is
    1614                 :            :  * significant).
    1615                 :            :  */
    1616                 :            : static const char *const bcm2835_pcm_per_parents[] = {
    1617                 :            :         "-",
    1618                 :            :         "xosc",
    1619                 :            :         "-",
    1620                 :            :         "-",
    1621                 :            :         "-",
    1622                 :            :         "-",
    1623                 :            :         "plld_per",
    1624                 :            :         "-",
    1625                 :            : };
    1626                 :            : 
    1627                 :            : #define REGISTER_PCM_CLK(s, ...)        REGISTER_CLK(                   \
    1628                 :            :         s,                                                              \
    1629                 :            :         .num_mux_parents = ARRAY_SIZE(bcm2835_pcm_per_parents),         \
    1630                 :            :         .parents = bcm2835_pcm_per_parents,                             \
    1631                 :            :         __VA_ARGS__)
    1632                 :            : 
    1633                 :            : /* main vpu parent mux */
    1634                 :            : static const char *const bcm2835_clock_vpu_parents[] = {
    1635                 :            :         "gnd",
    1636                 :            :         "xosc",
    1637                 :            :         "testdebug0",
    1638                 :            :         "testdebug1",
    1639                 :            :         "plla_core",
    1640                 :            :         "pllc_core0",
    1641                 :            :         "plld_core",
    1642                 :            :         "pllh_aux",
    1643                 :            :         "pllc_core1",
    1644                 :            :         "pllc_core2",
    1645                 :            : };
    1646                 :            : 
    1647                 :            : #define REGISTER_VPU_CLK(s, ...)        REGISTER_CLK(                   \
    1648                 :            :         s,                                                              \
    1649                 :            :         .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents),       \
    1650                 :            :         .parents = bcm2835_clock_vpu_parents,                           \
    1651                 :            :         __VA_ARGS__)
    1652                 :            : 
    1653                 :            : /*
    1654                 :            :  * DSI parent clocks.  The DSI byte/DDR/DDR2 clocks come from the DSI
    1655                 :            :  * analog PHY.  The _inv variants are generated internally to cprman,
    1656                 :            :  * but we don't use them so they aren't hooked up.
    1657                 :            :  */
    1658                 :            : static const char *const bcm2835_clock_dsi0_parents[] = {
    1659                 :            :         "gnd",
    1660                 :            :         "xosc",
    1661                 :            :         "testdebug0",
    1662                 :            :         "testdebug1",
    1663                 :            :         "dsi0_ddr",
    1664                 :            :         "dsi0_ddr_inv",
    1665                 :            :         "dsi0_ddr2",
    1666                 :            :         "dsi0_ddr2_inv",
    1667                 :            :         "dsi0_byte",
    1668                 :            :         "dsi0_byte_inv",
    1669                 :            : };
    1670                 :            : 
    1671                 :            : static const char *const bcm2835_clock_dsi1_parents[] = {
    1672                 :            :         "gnd",
    1673                 :            :         "xosc",
    1674                 :            :         "testdebug0",
    1675                 :            :         "testdebug1",
    1676                 :            :         "dsi1_ddr",
    1677                 :            :         "dsi1_ddr_inv",
    1678                 :            :         "dsi1_ddr2",
    1679                 :            :         "dsi1_ddr2_inv",
    1680                 :            :         "dsi1_byte",
    1681                 :            :         "dsi1_byte_inv",
    1682                 :            : };
    1683                 :            : 
    1684                 :            : #define REGISTER_DSI0_CLK(s, ...)       REGISTER_CLK(                   \
    1685                 :            :         s,                                                              \
    1686                 :            :         .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi0_parents),      \
    1687                 :            :         .parents = bcm2835_clock_dsi0_parents,                          \
    1688                 :            :         __VA_ARGS__)
    1689                 :            : 
    1690                 :            : #define REGISTER_DSI1_CLK(s, ...)       REGISTER_CLK(                   \
    1691                 :            :         s,                                                              \
    1692                 :            :         .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi1_parents),      \
    1693                 :            :         .parents = bcm2835_clock_dsi1_parents,                          \
    1694                 :            :         __VA_ARGS__)
    1695                 :            : 
    1696                 :            : /*
    1697                 :            :  * the real definition of all the pll, pll_dividers and clocks
    1698                 :            :  * these make use of the above REGISTER_* macros
    1699                 :            :  */
    1700                 :            : static const struct bcm2835_clk_desc clk_desc_array[] = {
    1701                 :            :         /* the PLL + PLL dividers */
    1702                 :            : 
    1703                 :            :         /*
    1704                 :            :          * PLLA is the auxiliary PLL, used to drive the CCP2
    1705                 :            :          * (Compact Camera Port 2) transmitter clock.
    1706                 :            :          *
    1707                 :            :          * It is in the PX LDO power domain, which is on when the
    1708                 :            :          * AUDIO domain is on.
    1709                 :            :          */
    1710                 :            :         [BCM2835_PLLA]          = REGISTER_PLL(
    1711                 :            :                 SOC_ALL,
    1712                 :            :                 .name = "plla",
    1713                 :            :                 .cm_ctrl_reg = CM_PLLA,
    1714                 :            :                 .a2w_ctrl_reg = A2W_PLLA_CTRL,
    1715                 :            :                 .frac_reg = A2W_PLLA_FRAC,
    1716                 :            :                 .ana_reg_base = A2W_PLLA_ANA0,
    1717                 :            :                 .reference_enable_mask = A2W_XOSC_CTRL_PLLA_ENABLE,
    1718                 :            :                 .lock_mask = CM_LOCK_FLOCKA,
    1719                 :            : 
    1720                 :            :                 .ana = &bcm2835_ana_default,
    1721                 :            : 
    1722                 :            :                 .min_rate = 600000000u,
    1723                 :            :                 .max_rate = 2400000000u,
    1724                 :            :                 .max_fb_rate = BCM2835_MAX_FB_RATE),
    1725                 :            :         [BCM2835_PLLA_CORE]     = REGISTER_PLL_DIV(
    1726                 :            :                 SOC_ALL,
    1727                 :            :                 .name = "plla_core",
    1728                 :            :                 .source_pll = "plla",
    1729                 :            :                 .cm_reg = CM_PLLA,
    1730                 :            :                 .a2w_reg = A2W_PLLA_CORE,
    1731                 :            :                 .load_mask = CM_PLLA_LOADCORE,
    1732                 :            :                 .hold_mask = CM_PLLA_HOLDCORE,
    1733                 :            :                 .fixed_divider = 1,
    1734                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1735                 :            : 
    1736                 :            :         /*
    1737                 :            :          * PLLA_PER is used for gpu clocks. Controlled by firmware, see
    1738                 :            :          * clk-raspberrypi.c.
    1739                 :            :          */
    1740                 :            : 
    1741                 :            :         [BCM2835_PLLA_DSI0]     = REGISTER_PLL_DIV(
    1742                 :            :                 SOC_ALL,
    1743                 :            :                 .name = "plla_dsi0",
    1744                 :            :                 .source_pll = "plla",
    1745                 :            :                 .cm_reg = CM_PLLA,
    1746                 :            :                 .a2w_reg = A2W_PLLA_DSI0,
    1747                 :            :                 .load_mask = CM_PLLA_LOADDSI0,
    1748                 :            :                 .hold_mask = CM_PLLA_HOLDDSI0,
    1749                 :            :                 .fixed_divider = 1),
    1750                 :            :         [BCM2835_PLLA_CCP2]     = REGISTER_PLL_DIV(
    1751                 :            :                 SOC_ALL,
    1752                 :            :                 .name = "plla_ccp2",
    1753                 :            :                 .source_pll = "plla",
    1754                 :            :                 .cm_reg = CM_PLLA,
    1755                 :            :                 .a2w_reg = A2W_PLLA_CCP2,
    1756                 :            :                 .load_mask = CM_PLLA_LOADCCP2,
    1757                 :            :                 .hold_mask = CM_PLLA_HOLDCCP2,
    1758                 :            :                 .fixed_divider = 1,
    1759                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1760                 :            : 
    1761                 :            :         /*
    1762                 :            :          * PLLB is used for the ARM's clock. Controlled by firmware, see
    1763                 :            :          * clk-raspberrypi.c.
    1764                 :            :          */
    1765                 :            : 
    1766                 :            :         /*
    1767                 :            :          * PLLC is the core PLL, used to drive the core VPU clock.
    1768                 :            :          *
    1769                 :            :          * It is in the PX LDO power domain, which is on when the
    1770                 :            :          * AUDIO domain is on.
    1771                 :            :          */
    1772                 :            :         [BCM2835_PLLC]          = REGISTER_PLL(
    1773                 :            :                 SOC_ALL,
    1774                 :            :                 .name = "pllc",
    1775                 :            :                 .cm_ctrl_reg = CM_PLLC,
    1776                 :            :                 .a2w_ctrl_reg = A2W_PLLC_CTRL,
    1777                 :            :                 .frac_reg = A2W_PLLC_FRAC,
    1778                 :            :                 .ana_reg_base = A2W_PLLC_ANA0,
    1779                 :            :                 .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
    1780                 :            :                 .lock_mask = CM_LOCK_FLOCKC,
    1781                 :            : 
    1782                 :            :                 .ana = &bcm2835_ana_default,
    1783                 :            : 
    1784                 :            :                 .min_rate = 600000000u,
    1785                 :            :                 .max_rate = 3000000000u,
    1786                 :            :                 .max_fb_rate = BCM2835_MAX_FB_RATE),
    1787                 :            :         [BCM2835_PLLC_CORE0]    = REGISTER_PLL_DIV(
    1788                 :            :                 SOC_ALL,
    1789                 :            :                 .name = "pllc_core0",
    1790                 :            :                 .source_pll = "pllc",
    1791                 :            :                 .cm_reg = CM_PLLC,
    1792                 :            :                 .a2w_reg = A2W_PLLC_CORE0,
    1793                 :            :                 .load_mask = CM_PLLC_LOADCORE0,
    1794                 :            :                 .hold_mask = CM_PLLC_HOLDCORE0,
    1795                 :            :                 .fixed_divider = 1,
    1796                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1797                 :            :         [BCM2835_PLLC_CORE1]    = REGISTER_PLL_DIV(
    1798                 :            :                 SOC_ALL,
    1799                 :            :                 .name = "pllc_core1",
    1800                 :            :                 .source_pll = "pllc",
    1801                 :            :                 .cm_reg = CM_PLLC,
    1802                 :            :                 .a2w_reg = A2W_PLLC_CORE1,
    1803                 :            :                 .load_mask = CM_PLLC_LOADCORE1,
    1804                 :            :                 .hold_mask = CM_PLLC_HOLDCORE1,
    1805                 :            :                 .fixed_divider = 1,
    1806                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1807                 :            :         [BCM2835_PLLC_CORE2]    = REGISTER_PLL_DIV(
    1808                 :            :                 SOC_ALL,
    1809                 :            :                 .name = "pllc_core2",
    1810                 :            :                 .source_pll = "pllc",
    1811                 :            :                 .cm_reg = CM_PLLC,
    1812                 :            :                 .a2w_reg = A2W_PLLC_CORE2,
    1813                 :            :                 .load_mask = CM_PLLC_LOADCORE2,
    1814                 :            :                 .hold_mask = CM_PLLC_HOLDCORE2,
    1815                 :            :                 .fixed_divider = 1,
    1816                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1817                 :            :         [BCM2835_PLLC_PER]      = REGISTER_PLL_DIV(
    1818                 :            :                 SOC_ALL,
    1819                 :            :                 .name = "pllc_per",
    1820                 :            :                 .source_pll = "pllc",
    1821                 :            :                 .cm_reg = CM_PLLC,
    1822                 :            :                 .a2w_reg = A2W_PLLC_PER,
    1823                 :            :                 .load_mask = CM_PLLC_LOADPER,
    1824                 :            :                 .hold_mask = CM_PLLC_HOLDPER,
    1825                 :            :                 .fixed_divider = 1,
    1826                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1827                 :            : 
    1828                 :            :         /*
    1829                 :            :          * PLLD is the display PLL, used to drive DSI display panels.
    1830                 :            :          *
    1831                 :            :          * It is in the PX LDO power domain, which is on when the
    1832                 :            :          * AUDIO domain is on.
    1833                 :            :          */
    1834                 :            :         [BCM2835_PLLD]          = REGISTER_PLL(
    1835                 :            :                 SOC_ALL,
    1836                 :            :                 .name = "plld",
    1837                 :            :                 .cm_ctrl_reg = CM_PLLD,
    1838                 :            :                 .a2w_ctrl_reg = A2W_PLLD_CTRL,
    1839                 :            :                 .frac_reg = A2W_PLLD_FRAC,
    1840                 :            :                 .ana_reg_base = A2W_PLLD_ANA0,
    1841                 :            :                 .reference_enable_mask = A2W_XOSC_CTRL_DDR_ENABLE,
    1842                 :            :                 .lock_mask = CM_LOCK_FLOCKD,
    1843                 :            : 
    1844                 :            :                 .ana = &bcm2835_ana_default,
    1845                 :            : 
    1846                 :            :                 .min_rate = 600000000u,
    1847                 :            :                 .max_rate = 2400000000u,
    1848                 :            :                 .max_fb_rate = BCM2835_MAX_FB_RATE),
    1849                 :            :         [BCM2835_PLLD_CORE]     = REGISTER_PLL_DIV(
    1850                 :            :                 SOC_ALL,
    1851                 :            :                 .name = "plld_core",
    1852                 :            :                 .source_pll = "plld",
    1853                 :            :                 .cm_reg = CM_PLLD,
    1854                 :            :                 .a2w_reg = A2W_PLLD_CORE,
    1855                 :            :                 .load_mask = CM_PLLD_LOADCORE,
    1856                 :            :                 .hold_mask = CM_PLLD_HOLDCORE,
    1857                 :            :                 .fixed_divider = 1,
    1858                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1859                 :            :         /*
    1860                 :            :          * VPU firmware assumes that PLLD_PER isn't disabled by the ARM core.
    1861                 :            :          * Otherwise this could cause firmware lookups. That's why we mark
    1862                 :            :          * it as critical.
    1863                 :            :          */
    1864                 :            :         [BCM2835_PLLD_PER]      = REGISTER_PLL_DIV(
    1865                 :            :                 SOC_ALL,
    1866                 :            :                 .name = "plld_per",
    1867                 :            :                 .source_pll = "plld",
    1868                 :            :                 .cm_reg = CM_PLLD,
    1869                 :            :                 .a2w_reg = A2W_PLLD_PER,
    1870                 :            :                 .load_mask = CM_PLLD_LOADPER,
    1871                 :            :                 .hold_mask = CM_PLLD_HOLDPER,
    1872                 :            :                 .fixed_divider = 1,
    1873                 :            :                 .flags = CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
    1874                 :            :         [BCM2835_PLLD_DSI0]     = REGISTER_PLL_DIV(
    1875                 :            :                 SOC_ALL,
    1876                 :            :                 .name = "plld_dsi0",
    1877                 :            :                 .source_pll = "plld",
    1878                 :            :                 .cm_reg = CM_PLLD,
    1879                 :            :                 .a2w_reg = A2W_PLLD_DSI0,
    1880                 :            :                 .load_mask = CM_PLLD_LOADDSI0,
    1881                 :            :                 .hold_mask = CM_PLLD_HOLDDSI0,
    1882                 :            :                 .fixed_divider = 1),
    1883                 :            :         [BCM2835_PLLD_DSI1]     = REGISTER_PLL_DIV(
    1884                 :            :                 SOC_ALL,
    1885                 :            :                 .name = "plld_dsi1",
    1886                 :            :                 .source_pll = "plld",
    1887                 :            :                 .cm_reg = CM_PLLD,
    1888                 :            :                 .a2w_reg = A2W_PLLD_DSI1,
    1889                 :            :                 .load_mask = CM_PLLD_LOADDSI1,
    1890                 :            :                 .hold_mask = CM_PLLD_HOLDDSI1,
    1891                 :            :                 .fixed_divider = 1),
    1892                 :            : 
    1893                 :            :         /*
    1894                 :            :          * PLLH is used to supply the pixel clock or the AUX clock for the
    1895                 :            :          * TV encoder.
    1896                 :            :          *
    1897                 :            :          * It is in the HDMI power domain.
    1898                 :            :          */
    1899                 :            :         [BCM2835_PLLH]          = REGISTER_PLL(
    1900                 :            :                 SOC_BCM2835,
    1901                 :            :                 "pllh",
    1902                 :            :                 .cm_ctrl_reg = CM_PLLH,
    1903                 :            :                 .a2w_ctrl_reg = A2W_PLLH_CTRL,
    1904                 :            :                 .frac_reg = A2W_PLLH_FRAC,
    1905                 :            :                 .ana_reg_base = A2W_PLLH_ANA0,
    1906                 :            :                 .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
    1907                 :            :                 .lock_mask = CM_LOCK_FLOCKH,
    1908                 :            : 
    1909                 :            :                 .ana = &bcm2835_ana_pllh,
    1910                 :            : 
    1911                 :            :                 .min_rate = 600000000u,
    1912                 :            :                 .max_rate = 3000000000u,
    1913                 :            :                 .max_fb_rate = BCM2835_MAX_FB_RATE),
    1914                 :            :         [BCM2835_PLLH_RCAL]     = REGISTER_PLL_DIV(
    1915                 :            :                 SOC_BCM2835,
    1916                 :            :                 .name = "pllh_rcal",
    1917                 :            :                 .source_pll = "pllh",
    1918                 :            :                 .cm_reg = CM_PLLH,
    1919                 :            :                 .a2w_reg = A2W_PLLH_RCAL,
    1920                 :            :                 .load_mask = CM_PLLH_LOADRCAL,
    1921                 :            :                 .hold_mask = 0,
    1922                 :            :                 .fixed_divider = 10,
    1923                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1924                 :            :         [BCM2835_PLLH_AUX]      = REGISTER_PLL_DIV(
    1925                 :            :                 SOC_BCM2835,
    1926                 :            :                 .name = "pllh_aux",
    1927                 :            :                 .source_pll = "pllh",
    1928                 :            :                 .cm_reg = CM_PLLH,
    1929                 :            :                 .a2w_reg = A2W_PLLH_AUX,
    1930                 :            :                 .load_mask = CM_PLLH_LOADAUX,
    1931                 :            :                 .hold_mask = 0,
    1932                 :            :                 .fixed_divider = 1,
    1933                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1934                 :            :         [BCM2835_PLLH_PIX]      = REGISTER_PLL_DIV(
    1935                 :            :                 SOC_BCM2835,
    1936                 :            :                 .name = "pllh_pix",
    1937                 :            :                 .source_pll = "pllh",
    1938                 :            :                 .cm_reg = CM_PLLH,
    1939                 :            :                 .a2w_reg = A2W_PLLH_PIX,
    1940                 :            :                 .load_mask = CM_PLLH_LOADPIX,
    1941                 :            :                 .hold_mask = 0,
    1942                 :            :                 .fixed_divider = 10,
    1943                 :            :                 .flags = CLK_SET_RATE_PARENT),
    1944                 :            : 
    1945                 :            :         /* the clocks */
    1946                 :            : 
    1947                 :            :         /* clocks with oscillator parent mux */
    1948                 :            : 
    1949                 :            :         /* One Time Programmable Memory clock.  Maximum 10Mhz. */
    1950                 :            :         [BCM2835_CLOCK_OTP]     = REGISTER_OSC_CLK(
    1951                 :            :                 SOC_ALL,
    1952                 :            :                 .name = "otp",
    1953                 :            :                 .ctl_reg = CM_OTPCTL,
    1954                 :            :                 .div_reg = CM_OTPDIV,
    1955                 :            :                 .int_bits = 4,
    1956                 :            :                 .frac_bits = 0,
    1957                 :            :                 .tcnt_mux = 6),
    1958                 :            :         /*
    1959                 :            :          * Used for a 1Mhz clock for the system clocksource, and also used
    1960                 :            :          * bythe watchdog timer and the camera pulse generator.
    1961                 :            :          */
    1962                 :            :         [BCM2835_CLOCK_TIMER]   = REGISTER_OSC_CLK(
    1963                 :            :                 SOC_ALL,
    1964                 :            :                 .name = "timer",
    1965                 :            :                 .ctl_reg = CM_TIMERCTL,
    1966                 :            :                 .div_reg = CM_TIMERDIV,
    1967                 :            :                 .int_bits = 6,
    1968                 :            :                 .frac_bits = 12),
    1969                 :            :         /*
    1970                 :            :          * Clock for the temperature sensor.
    1971                 :            :          * Generally run at 2Mhz, max 5Mhz.
    1972                 :            :          */
    1973                 :            :         [BCM2835_CLOCK_TSENS]   = REGISTER_OSC_CLK(
    1974                 :            :                 SOC_ALL,
    1975                 :            :                 .name = "tsens",
    1976                 :            :                 .ctl_reg = CM_TSENSCTL,
    1977                 :            :                 .div_reg = CM_TSENSDIV,
    1978                 :            :                 .int_bits = 5,
    1979                 :            :                 .frac_bits = 0),
    1980                 :            :         [BCM2835_CLOCK_TEC]     = REGISTER_OSC_CLK(
    1981                 :            :                 SOC_ALL,
    1982                 :            :                 .name = "tec",
    1983                 :            :                 .ctl_reg = CM_TECCTL,
    1984                 :            :                 .div_reg = CM_TECDIV,
    1985                 :            :                 .int_bits = 6,
    1986                 :            :                 .frac_bits = 0),
    1987                 :            : 
    1988                 :            :         /* clocks with vpu parent mux */
    1989                 :            :         [BCM2835_CLOCK_H264]    = REGISTER_VPU_CLK(
    1990                 :            :                 SOC_ALL,
    1991                 :            :                 .name = "h264",
    1992                 :            :                 .ctl_reg = CM_H264CTL,
    1993                 :            :                 .div_reg = CM_H264DIV,
    1994                 :            :                 .int_bits = 4,
    1995                 :            :                 .frac_bits = 8,
    1996                 :            :                 .tcnt_mux = 1),
    1997                 :            :         [BCM2835_CLOCK_ISP]     = REGISTER_VPU_CLK(
    1998                 :            :                 SOC_ALL,
    1999                 :            :                 .name = "isp",
    2000                 :            :                 .ctl_reg = CM_ISPCTL,
    2001                 :            :                 .div_reg = CM_ISPDIV,
    2002                 :            :                 .int_bits = 4,
    2003                 :            :                 .frac_bits = 8,
    2004                 :            :                 .tcnt_mux = 2),
    2005                 :            : 
    2006                 :            :         /*
    2007                 :            :          * Secondary SDRAM clock.  Used for low-voltage modes when the PLL
    2008                 :            :          * in the SDRAM controller can't be used.
    2009                 :            :          */
    2010                 :            :         [BCM2835_CLOCK_SDRAM]   = REGISTER_VPU_CLK(
    2011                 :            :                 SOC_ALL,
    2012                 :            :                 .name = "sdram",
    2013                 :            :                 .ctl_reg = CM_SDCCTL,
    2014                 :            :                 .div_reg = CM_SDCDIV,
    2015                 :            :                 .int_bits = 6,
    2016                 :            :                 .frac_bits = 0,
    2017                 :            :                 .tcnt_mux = 3),
    2018                 :            : 
    2019                 :            :         /*
    2020                 :            :          * CLOCK_V3D is used for v3d clock. Controlled by firmware, see
    2021                 :            :          * clk-raspberrypi.c.
    2022                 :            :          */
    2023                 :            : 
    2024                 :            :         /*
    2025                 :            :          * VPU clock.  This doesn't have an enable bit, since it drives
    2026                 :            :          * the bus for everything else, and is special so it doesn't need
    2027                 :            :          * to be gated for rate changes.  It is also known as "clk_audio"
    2028                 :            :          * in various hardware documentation.
    2029                 :            :          */
    2030                 :            :         [BCM2835_CLOCK_VPU]     = REGISTER_VPU_CLK(
    2031                 :            :                 SOC_ALL,
    2032                 :            :                 .name = "vpu",
    2033                 :            :                 .ctl_reg = CM_VPUCTL,
    2034                 :            :                 .div_reg = CM_VPUDIV,
    2035                 :            :                 .int_bits = 12,
    2036                 :            :                 .frac_bits = 8,
    2037                 :            :                 .flags = CLK_IS_CRITICAL,
    2038                 :            :                 .is_vpu_clock = true,
    2039                 :            :                 .tcnt_mux = 5),
    2040                 :            : 
    2041                 :            :         /* clocks with per parent mux */
    2042                 :            :         [BCM2835_CLOCK_AVEO]    = REGISTER_PER_CLK(
    2043                 :            :                 SOC_ALL,
    2044                 :            :                 .name = "aveo",
    2045                 :            :                 .ctl_reg = CM_AVEOCTL,
    2046                 :            :                 .div_reg = CM_AVEODIV,
    2047                 :            :                 .int_bits = 4,
    2048                 :            :                 .frac_bits = 0,
    2049                 :            :                 .tcnt_mux = 38),
    2050                 :            :         [BCM2835_CLOCK_CAM0]    = REGISTER_PER_CLK(
    2051                 :            :                 SOC_ALL,
    2052                 :            :                 .name = "cam0",
    2053                 :            :                 .ctl_reg = CM_CAM0CTL,
    2054                 :            :                 .div_reg = CM_CAM0DIV,
    2055                 :            :                 .int_bits = 4,
    2056                 :            :                 .frac_bits = 8,
    2057                 :            :                 .tcnt_mux = 14),
    2058                 :            :         [BCM2835_CLOCK_CAM1]    = REGISTER_PER_CLK(
    2059                 :            :                 SOC_ALL,
    2060                 :            :                 .name = "cam1",
    2061                 :            :                 .ctl_reg = CM_CAM1CTL,
    2062                 :            :                 .div_reg = CM_CAM1DIV,
    2063                 :            :                 .int_bits = 4,
    2064                 :            :                 .frac_bits = 8,
    2065                 :            :                 .tcnt_mux = 15),
    2066                 :            :         [BCM2835_CLOCK_DFT]     = REGISTER_PER_CLK(
    2067                 :            :                 SOC_ALL,
    2068                 :            :                 .name = "dft",
    2069                 :            :                 .ctl_reg = CM_DFTCTL,
    2070                 :            :                 .div_reg = CM_DFTDIV,
    2071                 :            :                 .int_bits = 5,
    2072                 :            :                 .frac_bits = 0),
    2073                 :            :         [BCM2835_CLOCK_DPI]     = REGISTER_PER_CLK(
    2074                 :            :                 SOC_ALL,
    2075                 :            :                 .name = "dpi",
    2076                 :            :                 .ctl_reg = CM_DPICTL,
    2077                 :            :                 .div_reg = CM_DPIDIV,
    2078                 :            :                 .int_bits = 4,
    2079                 :            :                 .frac_bits = 8,
    2080                 :            :                 .tcnt_mux = 17),
    2081                 :            : 
    2082                 :            :         /* Arasan EMMC clock */
    2083                 :            :         [BCM2835_CLOCK_EMMC]    = REGISTER_PER_CLK(
    2084                 :            :                 SOC_ALL,
    2085                 :            :                 .name = "emmc",
    2086                 :            :                 .ctl_reg = CM_EMMCCTL,
    2087                 :            :                 .div_reg = CM_EMMCDIV,
    2088                 :            :                 .int_bits = 4,
    2089                 :            :                 .frac_bits = 8,
    2090                 :            :                 .tcnt_mux = 39),
    2091                 :            : 
    2092                 :            :         /* EMMC2 clock (only available for BCM2711) */
    2093                 :            :         [BCM2711_CLOCK_EMMC2]   = REGISTER_PER_CLK(
    2094                 :            :                 SOC_BCM2711,
    2095                 :            :                 .name = "emmc2",
    2096                 :            :                 .ctl_reg = CM_EMMC2CTL,
    2097                 :            :                 .div_reg = CM_EMMC2DIV,
    2098                 :            :                 .int_bits = 4,
    2099                 :            :                 .frac_bits = 8,
    2100                 :            :                 .tcnt_mux = 42),
    2101                 :            : 
    2102                 :            :         /* General purpose (GPIO) clocks */
    2103                 :            :         [BCM2835_CLOCK_GP0]     = REGISTER_PER_CLK(
    2104                 :            :                 SOC_ALL,
    2105                 :            :                 .name = "gp0",
    2106                 :            :                 .ctl_reg = CM_GP0CTL,
    2107                 :            :                 .div_reg = CM_GP0DIV,
    2108                 :            :                 .int_bits = 12,
    2109                 :            :                 .frac_bits = 12,
    2110                 :            :                 .is_mash_clock = true,
    2111                 :            :                 .tcnt_mux = 20),
    2112                 :            :         [BCM2835_CLOCK_GP1]     = REGISTER_PER_CLK(
    2113                 :            :                 SOC_ALL,
    2114                 :            :                 .name = "gp1",
    2115                 :            :                 .ctl_reg = CM_GP1CTL,
    2116                 :            :                 .div_reg = CM_GP1DIV,
    2117                 :            :                 .int_bits = 12,
    2118                 :            :                 .frac_bits = 12,
    2119                 :            :                 .flags = CLK_IS_CRITICAL,
    2120                 :            :                 .is_mash_clock = true,
    2121                 :            :                 .tcnt_mux = 21),
    2122                 :            :         [BCM2835_CLOCK_GP2]     = REGISTER_PER_CLK(
    2123                 :            :                 SOC_ALL,
    2124                 :            :                 .name = "gp2",
    2125                 :            :                 .ctl_reg = CM_GP2CTL,
    2126                 :            :                 .div_reg = CM_GP2DIV,
    2127                 :            :                 .int_bits = 12,
    2128                 :            :                 .frac_bits = 12,
    2129                 :            :                 .flags = CLK_IS_CRITICAL),
    2130                 :            : 
    2131                 :            :         /* HDMI state machine */
    2132                 :            :         [BCM2835_CLOCK_HSM]     = REGISTER_PER_CLK(
    2133                 :            :                 SOC_ALL,
    2134                 :            :                 .name = "hsm",
    2135                 :            :                 .ctl_reg = CM_HSMCTL,
    2136                 :            :                 .div_reg = CM_HSMDIV,
    2137                 :            :                 .int_bits = 4,
    2138                 :            :                 .frac_bits = 8,
    2139                 :            :                 .tcnt_mux = 22),
    2140                 :            :         [BCM2835_CLOCK_PCM]     = REGISTER_PCM_CLK(
    2141                 :            :                 SOC_ALL,
    2142                 :            :                 .name = "pcm",
    2143                 :            :                 .ctl_reg = CM_PCMCTL,
    2144                 :            :                 .div_reg = CM_PCMDIV,
    2145                 :            :                 .int_bits = 12,
    2146                 :            :                 .frac_bits = 12,
    2147                 :            :                 .is_mash_clock = true,
    2148                 :            :                 .low_jitter = true,
    2149                 :            :                 .tcnt_mux = 23),
    2150                 :            :         [BCM2835_CLOCK_PWM]     = REGISTER_PER_CLK(
    2151                 :            :                 SOC_ALL,
    2152                 :            :                 .name = "pwm",
    2153                 :            :                 .ctl_reg = CM_PWMCTL,
    2154                 :            :                 .div_reg = CM_PWMDIV,
    2155                 :            :                 .int_bits = 12,
    2156                 :            :                 .frac_bits = 12,
    2157                 :            :                 .is_mash_clock = true,
    2158                 :            :                 .tcnt_mux = 24),
    2159                 :            :         [BCM2835_CLOCK_SLIM]    = REGISTER_PER_CLK(
    2160                 :            :                 SOC_ALL,
    2161                 :            :                 .name = "slim",
    2162                 :            :                 .ctl_reg = CM_SLIMCTL,
    2163                 :            :                 .div_reg = CM_SLIMDIV,
    2164                 :            :                 .int_bits = 12,
    2165                 :            :                 .frac_bits = 12,
    2166                 :            :                 .is_mash_clock = true,
    2167                 :            :                 .tcnt_mux = 25),
    2168                 :            :         [BCM2835_CLOCK_SMI]     = REGISTER_PER_CLK(
    2169                 :            :                 SOC_ALL,
    2170                 :            :                 .name = "smi",
    2171                 :            :                 .ctl_reg = CM_SMICTL,
    2172                 :            :                 .div_reg = CM_SMIDIV,
    2173                 :            :                 .int_bits = 4,
    2174                 :            :                 .frac_bits = 8,
    2175                 :            :                 .tcnt_mux = 27),
    2176                 :            :         [BCM2835_CLOCK_UART]    = REGISTER_PER_CLK(
    2177                 :            :                 SOC_ALL,
    2178                 :            :                 .name = "uart",
    2179                 :            :                 .ctl_reg = CM_UARTCTL,
    2180                 :            :                 .div_reg = CM_UARTDIV,
    2181                 :            :                 .int_bits = 10,
    2182                 :            :                 .frac_bits = 12,
    2183                 :            :                 .tcnt_mux = 28),
    2184                 :            : 
    2185                 :            :         /* TV encoder clock.  Only operating frequency is 108Mhz.  */
    2186                 :            :         [BCM2835_CLOCK_VEC]     = REGISTER_PER_CLK(
    2187                 :            :                 SOC_ALL,
    2188                 :            :                 .name = "vec",
    2189                 :            :                 .ctl_reg = CM_VECCTL,
    2190                 :            :                 .div_reg = CM_VECDIV,
    2191                 :            :                 .int_bits = 4,
    2192                 :            :                 .frac_bits = 0,
    2193                 :            :                 /*
    2194                 :            :                  * Allow rate change propagation only on PLLH_AUX which is
    2195                 :            :                  * assigned index 7 in the parent array.
    2196                 :            :                  */
    2197                 :            :                 .set_rate_parent = BIT(7),
    2198                 :            :                 .tcnt_mux = 29),
    2199                 :            : 
    2200                 :            :         /* dsi clocks */
    2201                 :            :         [BCM2835_CLOCK_DSI0E]   = REGISTER_PER_CLK(
    2202                 :            :                 SOC_ALL,
    2203                 :            :                 .name = "dsi0e",
    2204                 :            :                 .ctl_reg = CM_DSI0ECTL,
    2205                 :            :                 .div_reg = CM_DSI0EDIV,
    2206                 :            :                 .int_bits = 4,
    2207                 :            :                 .frac_bits = 8,
    2208                 :            :                 .tcnt_mux = 18),
    2209                 :            :         [BCM2835_CLOCK_DSI1E]   = REGISTER_PER_CLK(
    2210                 :            :                 SOC_ALL,
    2211                 :            :                 .name = "dsi1e",
    2212                 :            :                 .ctl_reg = CM_DSI1ECTL,
    2213                 :            :                 .div_reg = CM_DSI1EDIV,
    2214                 :            :                 .int_bits = 4,
    2215                 :            :                 .frac_bits = 8,
    2216                 :            :                 .tcnt_mux = 19),
    2217                 :            :         [BCM2835_CLOCK_DSI0P]   = REGISTER_DSI0_CLK(
    2218                 :            :                 SOC_ALL,
    2219                 :            :                 .name = "dsi0p",
    2220                 :            :                 .ctl_reg = CM_DSI0PCTL,
    2221                 :            :                 .div_reg = CM_DSI0PDIV,
    2222                 :            :                 .int_bits = 0,
    2223                 :            :                 .frac_bits = 0,
    2224                 :            :                 .tcnt_mux = 12),
    2225                 :            :         [BCM2835_CLOCK_DSI1P]   = REGISTER_DSI1_CLK(
    2226                 :            :                 SOC_ALL,
    2227                 :            :                 .name = "dsi1p",
    2228                 :            :                 .ctl_reg = CM_DSI1PCTL,
    2229                 :            :                 .div_reg = CM_DSI1PDIV,
    2230                 :            :                 .int_bits = 0,
    2231                 :            :                 .frac_bits = 0,
    2232                 :            :                 .tcnt_mux = 13),
    2233                 :            : 
    2234                 :            :         /* the gates */
    2235                 :            : 
    2236                 :            :         /*
    2237                 :            :          * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
    2238                 :            :          * you have the debug bit set in the power manager, which we
    2239                 :            :          * don't bother exposing) are individual gates off of the
    2240                 :            :          * non-stop vpu clock.
    2241                 :            :          */
    2242                 :            :         [BCM2835_CLOCK_PERI_IMAGE] = REGISTER_GATE(
    2243                 :            :                 SOC_ALL,
    2244                 :            :                 .name = "peri_image",
    2245                 :            :                 .parent = "vpu",
    2246                 :            :                 .ctl_reg = CM_PERIICTL),
    2247                 :            : };
    2248                 :            : 
    2249                 :            : static bool bcm2835_clk_claimed[ARRAY_SIZE(clk_desc_array)];
    2250                 :            : 
    2251                 :            : /*
    2252                 :            :  * Permanently take a reference on the parent of the SDRAM clock.
    2253                 :            :  *
    2254                 :            :  * While the SDRAM is being driven by its dedicated PLL most of the
    2255                 :            :  * time, there is a little loop running in the firmware that
    2256                 :            :  * periodically switches the SDRAM to using our CM clock to do PVT
    2257                 :            :  * recalibration, with the assumption that the previously configured
    2258                 :            :  * SDRAM parent is still enabled and running.
    2259                 :            :  */
    2260                 :        207 : static int bcm2835_mark_sdc_parent_critical(struct clk *sdc)
    2261                 :            : {
    2262                 :        207 :         struct clk *parent = clk_get_parent(sdc);
    2263                 :            : 
    2264         [ -  + ]:        207 :         if (IS_ERR(parent))
    2265                 :          0 :                 return PTR_ERR(parent);
    2266                 :            : 
    2267                 :        207 :         return clk_prepare_enable(parent);
    2268                 :            : }
    2269                 :            : 
    2270                 :       2484 : static bool bcm2835_clk_is_claimed(const char *name)
    2271                 :            : {
    2272                 :            :         int i;
    2273                 :            : 
    2274         [ +  - ]:       8901 :         for (i = 0; i < ARRAY_SIZE(clk_desc_array); i++) {
    2275         [ +  + ]:       8901 :                 if (clk_desc_array[i].data) {
    2276                 :       6831 :                         const char *clk_name = *(const char **)(clk_desc_array[i].data);
    2277         [ +  + ]:       6831 :                         if (!strcmp(name, clk_name))
    2278                 :       2484 :                                 return bcm2835_clk_claimed[i];
    2279                 :            :                 }
    2280                 :            :         }
    2281                 :            : 
    2282                 :            :         return false;
    2283                 :            : }
    2284                 :            : 
    2285                 :        414 : static int bcm2835_clk_probe(struct platform_device *pdev)
    2286                 :            : {
    2287                 :        414 :         struct device *dev = &pdev->dev;
    2288                 :            :         struct clk_hw **hws;
    2289                 :            :         struct bcm2835_cprman *cprman;
    2290                 :            :         struct resource *res;
    2291                 :            :         const struct bcm2835_clk_desc *desc;
    2292                 :            :         const size_t asize = ARRAY_SIZE(clk_desc_array);
    2293                 :            :         const struct cprman_plat_data *pdata;
    2294                 :            :         struct device_node *fw_node;
    2295                 :            :         size_t i;
    2296                 :            :         u32 clk_id;
    2297                 :            :         int ret;
    2298                 :            : 
    2299                 :        414 :         pdata = of_device_get_match_data(&pdev->dev);
    2300         [ +  - ]:        414 :         if (!pdata)
    2301                 :            :                 return -ENODEV;
    2302                 :            : 
    2303                 :        414 :         cprman = devm_kzalloc(dev,
    2304                 :            :                               struct_size(cprman, onecell.hws, asize),
    2305                 :            :                               GFP_KERNEL);
    2306         [ +  - ]:        414 :         if (!cprman)
    2307                 :            :                 return -ENOMEM;
    2308                 :            : 
    2309                 :        414 :         spin_lock_init(&cprman->regs_lock);
    2310                 :        414 :         cprman->dev = dev;
    2311                 :        414 :         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    2312                 :        414 :         cprman->regs = devm_ioremap_resource(dev, res);
    2313         [ -  + ]:        414 :         if (IS_ERR(cprman->regs))
    2314                 :          0 :                 return PTR_ERR(cprman->regs);
    2315                 :            : 
    2316                 :        414 :         fw_node = of_parse_phandle(dev->of_node, "firmware", 0);
    2317         [ +  - ]:        414 :         if (fw_node) {
    2318                 :        414 :                 struct rpi_firmware *fw = rpi_firmware_get(NULL);
    2319         [ +  + ]:        414 :                 if (!fw)
    2320                 :            :                         return -EPROBE_DEFER;
    2321                 :        207 :                 cprman->fw = fw;
    2322                 :            :         }
    2323                 :            : 
    2324                 :        207 :         memset(bcm2835_clk_claimed, 0, sizeof(bcm2835_clk_claimed));
    2325         [ -  + ]:        414 :         for (i = 0;
    2326                 :        207 :              !of_property_read_u32_index(pdev->dev.of_node, "claim-clocks",
    2327                 :            :                                          i, &clk_id);
    2328                 :          0 :              i++)
    2329                 :          0 :                 bcm2835_clk_claimed[clk_id]= true;
    2330                 :            : 
    2331                 :        207 :         memcpy(cprman->real_parent_names, cprman_parent_names,
    2332                 :            :                sizeof(cprman_parent_names));
    2333                 :        207 :         of_clk_parent_fill(dev->of_node, cprman->real_parent_names,
    2334                 :            :                            ARRAY_SIZE(cprman_parent_names));
    2335                 :            : 
    2336                 :            :         /*
    2337                 :            :          * Make sure the external oscillator has been registered.
    2338                 :            :          *
    2339                 :            :          * The other (DSI) clocks are not present on older device
    2340                 :            :          * trees, which we still need to support for backwards
    2341                 :            :          * compatibility.
    2342                 :            :          */
    2343         [ +  - ]:        207 :         if (!cprman->real_parent_names[0])
    2344                 :            :                 return -ENODEV;
    2345                 :            : 
    2346                 :            :         platform_set_drvdata(pdev, cprman);
    2347                 :            : 
    2348                 :        207 :         cprman->onecell.num = asize;
    2349                 :        207 :         cprman->soc = pdata->soc;
    2350                 :        207 :         hws = cprman->onecell.hws;
    2351                 :            : 
    2352         [ +  + ]:      10971 :         for (i = 0; i < asize; i++) {
    2353                 :            :                 desc = &clk_desc_array[i];
    2354   [ +  +  +  -  :      20700 :                 if (desc->clk_register && desc->data &&
                   +  + ]
    2355                 :       9936 :                     (desc->supported & pdata->soc)) {
    2356                 :       9729 :                         hws[i] = desc->clk_register(cprman, desc->data);
    2357                 :            :                 }
    2358                 :            :         }
    2359                 :            : 
    2360                 :        207 :         ret = bcm2835_mark_sdc_parent_critical(hws[BCM2835_CLOCK_SDRAM]->clk);
    2361         [ +  - ]:        207 :         if (ret)
    2362                 :            :                 return ret;
    2363                 :            : 
    2364                 :        414 :         ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
    2365                 :        207 :                                       &cprman->onecell);
    2366         [ -  + ]:        207 :         if (ret)
    2367                 :          0 :                 return ret;
    2368                 :            : 
    2369                 :            :         /* note that we have registered all the clocks */
    2370                 :            :         dev_dbg(dev, "registered %zd clocks\n", asize);
    2371                 :            : 
    2372                 :            :         return 0;
    2373                 :            : }
    2374                 :            : 
    2375                 :            : static const struct cprman_plat_data cprman_bcm2835_plat_data = {
    2376                 :            :         .soc = SOC_BCM2835,
    2377                 :            : };
    2378                 :            : 
    2379                 :            : static const struct cprman_plat_data cprman_bcm2711_plat_data = {
    2380                 :            :         .soc = SOC_BCM2711,
    2381                 :            : };
    2382                 :            : 
    2383                 :            : static const struct of_device_id bcm2835_clk_of_match[] = {
    2384                 :            :         { .compatible = "brcm,bcm2835-cprman", .data = &cprman_bcm2835_plat_data },
    2385                 :            :         { .compatible = "brcm,bcm2711-cprman", .data = &cprman_bcm2711_plat_data },
    2386                 :            :         {}
    2387                 :            : };
    2388                 :            : MODULE_DEVICE_TABLE(of, bcm2835_clk_of_match);
    2389                 :            : 
    2390                 :            : static struct platform_driver bcm2835_clk_driver = {
    2391                 :            :         .driver = {
    2392                 :            :                 .name = "bcm2835-clk",
    2393                 :            :                 .of_match_table = bcm2835_clk_of_match,
    2394                 :            :         },
    2395                 :            :         .probe          = bcm2835_clk_probe,
    2396                 :            : };
    2397                 :            : 
    2398                 :        207 : static int __init __bcm2835_clk_driver_init(void)
    2399                 :            : {
    2400                 :        207 :         return platform_driver_register(&bcm2835_clk_driver);
    2401                 :            : }
    2402                 :            : postcore_initcall(__bcm2835_clk_driver_init);
    2403                 :            : 
    2404                 :            : MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
    2405                 :            : MODULE_DESCRIPTION("BCM2835 clock driver");
    2406                 :            : MODULE_LICENSE("GPL");

Generated by: LCOV version 1.14