Ignore:
Timestamp:
2012-11-19T16:07:27Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
68338c6
Parents:
bfc6e11
Message:

rootamdm37x: Begin DPLL initialization work.

Detect base system frequency. Add comments and TODOs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c

    rbfc6e11 r52e020b  
    5151#include "cm/clock_control.h"
    5252#include "cm/usbhost.h"
     53#include "prm/clock_control.h"
    5354
    5455#define NAME  "rootamdm37x"
     
    6263                usbhost_cm_regs_t *usbhost;
    6364        } cm;
     65        struct {
     66                clock_control_prm_regs_t *clocks;
     67        } prm;
    6468} amdm37x_t;
    6569
     
    8791        ret = pio_enable((void*)CLOCK_CONTROL_CM_BASE_ADDRESS,
    8892                    CLOCK_CONTROL_CM_SIZE, (void**)&device->cm.clocks);
     93        if (ret != EOK)
     94                return ret;
     95
     96        ret = pio_enable((void*)CLOCK_CONTROL_PRM_BASE_ADDRESS,
     97            CLOCK_CONTROL_PRM_SIZE, (void**)&device->prm.clocks);
    8998        if (ret != EOK)
    9099                return ret;
     
    106115                pio_trace_enable(device->cm.usbhost, USBHOST_CM_SIZE, log, (void*)USBHOST_CM_BASE_ADDRESS);
    107116                pio_trace_enable(device->uhh, AMDM37x_UHH_SIZE, log, (void*)AMDM37x_UHH_BASE_ADDRESS);
     117                pio_trace_enable(device->prm.clocks, CLOCK_CONTROL_PRM_SIZE, log, (void*)CLOCK_CONTROL_PRM_BASE_ADDRESS);
    108118        }
    109119        return EOK;
    110120}
    111121
    112 /** Set DPLL3,4,5 to autoidle
     122
     123
     124/** Set DPLLs 1,2,3,4,5 to ON (locked) and autoidle.
    113125 * @param device Register map.
    114  */
    115 static void dpll_autoidle(amdm37x_t *device)
     126 *
     127 * The idea is to get all DPLLs running and make hw control their power mode,
     128 * based on the module requirements (module ICLKs and FCLKs).
     129 */
     130static void dpll_on_autoidle(amdm37x_t *device)
    116131{
    117132        assert(device);
    118         /* Set DPLL3 to automatic */
     133        /* Get SYS_CLK value, it is used as reference clock by all DPLLs */
     134        const unsigned base_clk = pio_read_32(&device->prm.clocks->clksel)
     135            & CLOCK_CONTROL_PRM_CLKSEL_SYS_CLKIN_MASK;
     136        const unsigned base_freq = sys_clk_freq_kHz(base_clk);
     137        ddf_msg(LVL_DEBUG, "Base frequency: %d.%dMhz",
     138            base_freq / 1000, base_freq % 1000);
     139
     140
     141        /* DPLL1 provides MPU(CPU) clock.
     142         * It uses SYS_CLK as reference clock and core clock (DPLL3) as
     143         * high frequency bypass (MPU then runs on L3 interconnect freq).
     144         * It should be setup by fw or u-boot.*/
     145        // TODO: set to autoidle to save power.
     146        // TODO: compute current MPU frequency.
     147
     148        /* DPLL2 provides IVA(video acceleration) clock.
     149         * It uses SYS_CLK as reference clokc and core clock (DPLL3) as
     150         * high frequency bypass (IVA runs on L3 freq).
     151         */
     152        // TODO: We can probably turn this off entirely. IVA is left unused.
     153        // TODO: Set at least to autoidle to save power
     154
     155        /* DPLL3 provides tons of clocks:
     156         * CORE_CLK, COREX2_CLK, DSS_TV_CLK, 12M_CLK, 48M_CLK, 96M_CLK, L3_ICLK,
     157         * and L4_ICLK. It uses SYS_CLK as reference clock and low frequency
     158         * bypass. It should be setup by fw or u-boot as it controls critical
     159         * interconnects.
     160         */
     161
     162        /* Set DPLL3 to automatic to save power */
    119163        pio_change_32(&device->cm.clocks->autoidle_pll,
    120164            CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_CORE_DPLL_AUTOMATIC,
    121165            CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_CORE_DPLL_MASK, 5);
    122166
    123         /* Set DPLL4 to automatic */
     167        /* DPLL4 provides peripheral domain clocks:
     168         * CAM_MCLK, EMU_PER_ALWON_CLK, DSS1_ALWON_FCLK, and 96M_ALWON_FCLK.
     169         * It uses SYS_CLK as reference clock and low frequency bypass.
     170         * 96M clock is used by McBSP[1,5], MMC[1,2,3], I2C[1,2,3], so
     171         * we can probably turn this off entirely (DSS is still non-functional).
     172         */
     173        /* Set DPLL4 to automatic to save power*/
    124174        pio_change_32(&device->cm.clocks->autoidle_pll,
    125175            CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_PERIPH_DPLL_AUTOMATIC,
    126176            CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_PERIPH_DPLL_MASK, 5);
    127177
     178        /* DPLL5 provide peripheral domain clocks: 120M_FCLK.
     179         * It uses SYS_CLK as reference clock and low frequency bypass.
     180         * 120M clock is used by HS USB and USB TLL.
     181         */
     182        // TODO setup DPLL5
    128183        /* Set DPLL5 to automatic */
    129184        pio_change_32(&device->cm.clocks->autoidle2_pll,
     
    341396        }
    342397
    343         /* Set dplls to automatic */
    344         dpll_autoidle(device);
     398        /* Set dplls to ON and automatic */
     399        dpll_on_autoidle(device);
    345400
    346401        /* Enable function and interface clocks */
Note: See TracChangeset for help on using the changeset viewer.