source: svn/trunk/newcon3bcm2_21bu/rockford/bsp/AVS/src/avs_start.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2008-2013, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: avs_start.c $
11 * $brcm_Revision: Hydra_Software_Devel/4 $
12 * $brcm_Date: 1/23/13 5:11p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /rockford/bsp/AVS/src/avs_start.c $
19 *
20 * Hydra_Software_Devel/4   1/23/13 5:11p rjlewis
21 * SWCFE-968: enable the call to check in the reset            the reset.
22 *
23 * Hydra_Software_Devel/3   1/22/13 4:47p rjlewis
24 * SWCFE-986: Enabled temperature over                over-temperature
25 * reset by default.  Enabled over-temperature reset detection and print
26 * (by default).
27 *
28 * Hydra_Software_Devel/2   8/2/12 1:13p garylin
29 * SWCFE-897: Update AVS to version 0.5.4
30 *
31***************************************************************************/
32
33#include <stdint.h>
34#include <stdbool.h>
35#include "avs_settings.h"
36#include "bchp_avs_hw_mntr.h"
37#include "bchp_aon_ctrl.h"
38
39#define SCALING_FACTOR 10000 /* make this larger to get more precision in the numbers (but be careful of overflow) */
40#define S1 SCALING_FACTOR    /* WARNING: DO NOT CHANGE THIS -- it MUST match the definition used to build the library */
41#define S2 SCALING_FACTOR
42#define INT(x) ((int32_t)((x)*S1)) /* this creates an integer from a float with the precision defined above */
43
44/* WARNING: the items below are values that were lab tested and should NOT be changed unless instructed to do so. */
45/* Changing these values can result in system failures (chip resets, memory read/write errors, hangs, etc.). */
46
47/* Margins added to the initial voltage setting to ensure adaquite voltage across all types of parts */
48#define VMARGINL            INT(.150) /*150mV*/
49#define VMARGINH            INT(.100) /*100mV*/
50
51/* Minimum/maximum voltage settings allowed when setting the initial voltage */
52#define VMIN_AVS            INT(.860) /*0.860V*/
53#define VMAX_AVS            INT(1.02) /*1.020V*/
54
55/* Maximum supported temperature if Temperature Threshold option is used */
56#define MAX_TEMPERATURE 130 /* note: 150C = register value of 0x1E2 which is the default for this register */
57
58/* Allow the values above to be over-ridden in the Makefile for test purposes (special builds) */
59#ifdef AVS_MARGIN_LOW
60#undef  VMARGINL
61#define VMARGINL            (INT(AVS_MARGIN_LOW))
62#endif
63#ifdef AVS_MARGIN_HIGH
64#undef  VMARGINH
65#define VMARGINH            (INT(AVS_MARGIN_HIGH))
66#endif
67#ifdef AVS_MIN_AVS
68#undef  VMIN_AVS
69#define VMIN_AVS            (INT(AVS_MIN_AVS))
70#endif
71#ifdef AVS_MAX_AVS
72#undef  VMAX_AVS
73#define VMAX_AVS            (INT(AVS_MAX_AVS))
74#endif
75
76#ifdef AVS_MAX_TEMPERATURE
77#undef MAX_TEMPERATURE
78#define MAX_TEMPERATURE AVS_MAX_TEMPERATURE
79#endif
80
81#ifdef AVS_NO_PRINTS
82#define QUIET 1 /* set to 1 for production release */
83#else
84#define QUIET 0 /* default is to print minimal data */
85#endif
86
87/* Some customer builds required added delay after changing the DAC (before reading the voltage) to allow regulator to settle */
88#ifdef AVS_EXTRA_DELAY
89#define EXTRA_DELAY AVS_EXTRA_DELAY
90#else
91#define EXTRA_DELAY 0
92#endif
93
94//#define AVS_DEBUG_STARTUP /* enable this to include debug code */
95
96#ifdef AVS_DEBUG_STARTUP
97#include "avs_debug.c"
98#endif
99
100#define BREG_Write32(addr,value) do { *(volatile uint32_t*)(addr+0xB0000000)=(value); } while(0)
101#define BREG_Read32(addr)            (*(volatile uint32_t*)(addr+0xB0000000))
102
103/*\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\*/
104
105#ifndef INCLUDE_TEMPERATURE_THRESHOLD
106#define INCLUDE_TEMPERATURE_THRESHOLD /* enable to set a temperature threshold to cause a reset for over-temp */
107#endif
108
109#ifdef INCLUDE_TEMPERATURE_THRESHOLD
110/* This enables a fail-safe temperature monitor.  If the temperature ever reaches this value the part will reset.
111** There This is really just a last ditch effort to save the part from burning up.
112** Note:
113**   reg = BREG_Read32(BCHP_AVS_RO_REGISTERS_0_PVT_TEMPERATURE_MNTR_STATUS);
114**   reg &= BCHP_AVS_RO_REGISTERS_0_PVT_TEMPERATURE_MNTR_STATUS_data_MASK;
115**   temperature = 418*1000 - (556 * reg);
116** Note that the part is guaranteed to run up to 125C so using 150C is just to catch run-away temperature situations.
117** The result of a reset due to over-temp can be read in "BCHP_AON_CTRL_RESET_HISTORY" with bit: AON_CTRL :: RESET_HISTORY :: overtemp_reset [13:13]
118*/
119static inline void AvsSetTempThreshold(void)
120{
121        uint32_t reg = (418 - MAX_TEMPERATURE) * 1000 / 556;
122        BREG_Write32(BCHP_AVS_HW_MNTR_TEMPERATURE_THRESHOLD, reg); 
123        BREG_Write32(BCHP_AVS_HW_MNTR_TEMPERATURE_RESET_ENABLE, 1);
124}
125
126#ifndef INCLUDE_TEMPERATURE_RESET_PRINT
127#define INCLUDE_TEMPERATURE_RESET_PRINT /* enable to print message when temperature reset occurred */
128#endif
129
130#ifdef INCLUDE_TEMPERATURE_RESET_PRINT
131/* This can be used to verify that reset occured due to over-temp */
132static inline void AvsCheckTempReset(void)
133{
134        uint32_t reg;
135        extern void print_char(char c);
136        extern void print_hex32(uint32_t val);
137
138        reg = BREG_Read32(BCHP_AON_CTRL_RESET_HISTORY);
139        //print_char('R');print_char('=');print_hex32(reg);print_char(0xa);print_char(0xd);
140
141        if (reg & BCHP_AON_CTRL_RESET_HISTORY_overtemp_reset_MASK) {
142                print_char('O');       
143                print_char('v');       
144                print_char('e');       
145                print_char('r');       
146                print_char('-');       
147                print_char('t');       
148                print_char('e');       
149                print_char('m');       
150                print_char('p');       
151                print_char(' ');       
152                print_char('R');       
153                print_char('e');       
154                print_char('s');       
155                print_char('e');       
156                print_char('t');       
157                print_char('!');       
158                print_char(0xa); print_char(0xd);
159
160                /* Clear the reset history for the next reboot */
161                BREG_Write32(BCHP_AON_CTRL_RESET_CTRL, 1);
162                BREG_Write32(BCHP_AON_CTRL_RESET_CTRL, 0);
163        }
164}
165#endif /*INCLUDE_TEMPERATURE_RESET_PRINT*/
166#endif /*INCLUDE_TEMPERATURE_THRESHOLD*/
167
168/*\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\*/
169
170/* This is the main entry point for AVS processing */
171
172void AvsStart(void)
173{
174        run_time_params params;
175
176        params.vmargin_low  = VMARGINL;
177        params.vmargin_high = VMARGINH;
178        params.voltage_min_avs = VMIN_AVS; 
179        params.voltage_max_avs = VMAX_AVS; 
180        params.extra_delay = EXTRA_DELAY;
181        params.quiet = QUIET; 
182
183#ifdef INCLUDE_TEMPERATURE_RESET_PRINT
184        AvsCheckTempReset();
185#endif
186
187        AvsLibraryStart(&params);
188
189#ifdef INCLUDE_TEMPERATURE_THRESHOLD
190        AvsSetTempThreshold();
191#endif
192}
193
194void AvsWarmStart(void)
195{ 
196#if BCHP_CHIP==7358
197        /* 7358 doesn't have AON registers so can't restore anything saved -- just handle it like startup */
198        /* This has to be handled here because binary doesn't know the defaults we're using for parameters */
199        AvsStart();
200#else
201        AvsLibraryWarmStart(EXTRA_DELAY);
202#endif
203}
Note: See TracBrowser for help on using the repository browser.