uboot/board/ti/omap2420h4/sys_info.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2004
   3 * Texas Instruments, <www.ti.com>
   4 * Richard Woodruff <r-woodruff2@ti.com>
   5 *
   6 * This program is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU General Public License as
   8 * published by the Free Software Foundation; either version 2 of
   9 * the License, or (at your option) any later version.
  10 *
  11 * This program is distributed in the hope that it will be useful,
  12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE.  See the
  14 * GNU General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program; if not, write to the Free Software
  18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19 * MA 02111-1307 USA
  20 */
  21
  22#include <common.h>
  23#include <asm/arch/omap2420.h>
  24#include <asm/io.h>
  25#include <asm/arch/bits.h>
  26#include <asm/arch/mem.h>  /* get mem tables */
  27#include <asm/arch/sys_proto.h>
  28#include <asm/arch/sys_info.h>
  29#include <i2c.h>
  30
  31/**************************************************************************
  32 * get_prod_id() - get id info from chips
  33 ***************************************************************************/
  34static u32 get_prod_id(void)
  35{
  36        u32 p;
  37        p = __raw_readl(PRODUCTION_ID); /* get production ID */
  38        return((p & CPU_242X_PID_MASK) >> 16);
  39}
  40
  41/**************************************************************************
  42 * get_cpu_type() - low level get cpu type
  43 * - no C globals yet.
  44 * - just looking to say if this is a 2422 or 2420 or ...
  45 * - to start with we will look at switch settings..
  46 * - 2422 id's same as 2420 for ES1 will rely on H4 board characteristics
  47 *   (mux for 2420, non-mux for 2422).
  48 ***************************************************************************/
  49u32 get_cpu_type(void)
  50{
  51        u32 v;
  52
  53        switch(get_prod_id()){
  54                case 1:;/* 2420 */
  55                case 2: return(CPU_2420); break; /* 2420 pop */
  56                case 4: return(CPU_2422); break;
  57                case 8: return(CPU_2423); break;
  58                default: break;  /* early 2420/2422's unmarked */
  59        }
  60
  61        v = __raw_readl(TAP_IDCODE_REG);
  62        v &= CPU_24XX_ID_MASK;
  63        if (v == CPU_2420_CHIPID) {       /* currently 2420 and 2422 have same id */
  64                if (is_gpmc_muxed() == GPMC_MUXED)        /* if mux'ed */
  65                        return(CPU_2420);
  66                else
  67                        return(CPU_2422);
  68        } else
  69                return(CPU_2420); /* don't know, say 2420 */
  70}
  71
  72/******************************************
  73 * get_cpu_rev(void) - extract version info
  74 ******************************************/
  75u32 get_cpu_rev(void)
  76{
  77        u32 v;
  78        v = __raw_readl(TAP_IDCODE_REG);
  79        v = v >> 28;
  80        return(v+1);  /* currently 2422 and 2420 match up */
  81}
  82/****************************************************
  83 * is_mem_sdr() - return 1 if mem type in use is SDR
  84 ****************************************************/
  85u32 is_mem_sdr(void)
  86{
  87        volatile u32 *burst = (volatile u32 *)(SDRC_MR_0+SDRC_CS0_OSET);
  88        if(*burst == H4_2420_SDRC_MR_0_SDR)
  89                return(1);
  90        return(0);
  91}
  92
  93/***********************************************************
  94 * get_mem_type() - identify type of mDDR part used.
  95 * 2422 uses stacked DDR, 2 parts CS0/CS1.
  96 * 2420 may have 1 or 2, no good way to know...only init 1...
  97 * when eeprom data is up we can select 1 more.
  98 *************************************************************/
  99u32 get_mem_type(void)
 100{
 101        u32 cpu, sdr = is_mem_sdr();
 102
 103        cpu = get_cpu_type();
 104        if (cpu == CPU_2422 || cpu == CPU_2423)
 105                return(DDR_STACKED);
 106
 107        if(get_prod_id() == 0x2)
 108                return(XDR_POP);
 109
 110        if (get_board_type() == BOARD_H4_MENELAUS)
 111                if(sdr)
 112                        return(SDR_DISCRETE);
 113                else
 114                        return(DDR_COMBO);
 115        else
 116                if(sdr) /* SDP + SDR kit */
 117                        return(SDR_DISCRETE);
 118                else
 119                        return(DDR_DISCRETE); /* origional SDP */
 120}
 121
 122/***********************************************************************
 123 * get_cs0_size() - get size of chip select 0/1
 124 ************************************************************************/
 125u32 get_sdr_cs_size(u32 offset)
 126{
 127        u32 size;
 128        size = __raw_readl(SDRC_MCFG_0+offset) >> 8; /* get ram size field */
 129        size &= 0x2FF;   /* remove unwanted bits */
 130        size *= SZ_2M;   /* find size in MB */
 131        return(size);
 132}
 133
 134/***********************************************************************
 135 * get_board_type() - get board type based on current production stats.
 136 *  --- NOTE: 2 I2C EEPROMs will someday be populated with proper info.
 137 *      when they are available we can get info from there.  This should
 138 *      be correct of all known boards up until today.
 139 ************************************************************************/
 140u32 get_board_type(void)
 141{
 142        if (i2c_probe(I2C_MENELAUS) == 0)
 143                return(BOARD_H4_MENELAUS);
 144        else
 145                return(BOARD_H4_SDP);
 146}
 147
 148/******************************************************************
 149 * get_sysboot_value() - get init word settings (dip switch on h4)
 150 ******************************************************************/
 151inline u32 get_sysboot_value(void)
 152{
 153        return(0x00000FFF & __raw_readl(CONTROL_STATUS));
 154}
 155
 156/***************************************************************************
 157 *  get_gpmc0_base() - Return current address hardware will be
 158 *     fetching from. The below effectively gives what is correct, its a bit
 159 *   mis-leading compared to the TRM.  For the most general case the mask
 160 *   needs to be also taken into account this does work in practice.
 161 *   - for u-boot we currently map:
 162 *       -- 0 to nothing,
 163 *       -- 4 to flash
 164 *       -- 8 to enent
 165 *       -- c to wifi
 166 ****************************************************************************/
 167u32 get_gpmc0_base(void)
 168{
 169        u32 b;
 170
 171        b = __raw_readl(GPMC_CONFIG7_0);
 172        b &= 0x1F;       /* keep base [5:0] */
 173        b = b << 24; /* ret 0x0b000000 */
 174        return(b);
 175}
 176
 177/*****************************************************************
 178 *  is_gpmc_muxed() - tells if address/data lines are multiplexed
 179 *****************************************************************/
 180u32 is_gpmc_muxed(void)
 181{
 182        u32 mux;
 183        mux = get_sysboot_value();
 184        if ((mux & (BIT0 | BIT1 | BIT2 | BIT3)) == (BIT0 | BIT2 | BIT3))
 185                return(GPMC_MUXED); /* NAND Boot mode */
 186        if (mux & BIT1)    /* if mux'ed */
 187                return(GPMC_MUXED);
 188        else
 189                return(GPMC_NONMUXED);
 190}
 191
 192/************************************************************************
 193 *  get_gpmc0_type() - read sysboot lines to see type of memory attached
 194 ************************************************************************/
 195u32 get_gpmc0_type(void)
 196{
 197        u32 type;
 198        type = get_sysboot_value();
 199        if ((type & (BIT3|BIT2)) == (BIT3|BIT2))
 200                return(TYPE_NAND);
 201        else
 202                return(TYPE_NOR);
 203}
 204
 205/*******************************************************************
 206 * get_gpmc0_width() - See if bus is in x8 or x16 (mainly for nand)
 207 *******************************************************************/
 208u32 get_gpmc0_width(void)
 209{
 210        u32 width;
 211        width = get_sysboot_value();
 212        if ((width & 0xF) == (BIT3|BIT2))
 213                return(WIDTH_8BIT);
 214        else
 215                return(WIDTH_16BIT);
 216}
 217
 218/*********************************************************************
 219 * wait_on_value() - common routine to allow waiting for changes in
 220 *   volatile regs.
 221 *********************************************************************/
 222u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr, u32 bound)
 223{
 224        u32 i = 0, val;
 225        do {
 226                ++i;
 227                val = __raw_readl(read_addr) & read_bit_mask;
 228                if (val == match_value)
 229                        return(1);
 230                if (i==bound)
 231                        return(0);
 232        } while (1);
 233}
 234
 235/*********************************************************************
 236 *  display_board_info() - print banner with board info.
 237 *********************************************************************/
 238void display_board_info(u32 btype)
 239{
 240        char cpu_2420[] = "2420";   /* cpu type */
 241        char cpu_2422[] = "2422";
 242        char cpu_2423[] = "2423";
 243        char db_men[] = "Menelaus"; /* board type */
 244        char db_ip[] = "IP";
 245        char mem_sdr[] = "mSDR";    /* memory type */
 246        char mem_ddr[] = "mDDR";
 247        char t_tst[] = "TST";       /* security level */
 248        char t_emu[] = "EMU";
 249        char t_hs[] = "HS";
 250        char t_gp[] = "GP";
 251        char unk[] = "?";
 252
 253        char *cpu_s, *db_s, *mem_s, *sec_s;
 254        u32 cpu, rev, sec;
 255
 256        rev = get_cpu_rev();
 257        cpu = get_cpu_type();
 258        sec = get_device_type();
 259
 260        if(is_mem_sdr())
 261                mem_s = mem_sdr;
 262        else
 263                mem_s = mem_ddr;
 264
 265        if(cpu == CPU_2423)
 266                cpu_s = cpu_2423;
 267        else if (cpu == CPU_2422)
 268                cpu_s = cpu_2422;
 269        else
 270                cpu_s = cpu_2420;
 271
 272        if(btype ==  BOARD_H4_MENELAUS)
 273                db_s = db_men;
 274        else
 275                db_s = db_ip;
 276
 277        switch(sec){
 278                case TST_DEVICE: sec_s = t_tst; break;
 279                case EMU_DEVICE: sec_s = t_emu; break;
 280                case HS_DEVICE:  sec_s = t_hs; break;
 281                case GP_DEVICE:  sec_s = t_gp; break;
 282                default: sec_s = unk;
 283        }
 284
 285        printf("OMAP%s-%s revision %d\n", cpu_s, sec_s, rev-1);
 286        printf("TI H4 SDP Base Board + %s Daughter Board + %s \n", db_s, mem_s);
 287}
 288
 289/*************************************************************************
 290 * get_board_rev() - setup to pass kernel board revision information
 291 *          0 = 242x IP platform (first 2xx boards)
 292 *          1 = 242x Menelaus platfrom.
 293 *************************************************************************/
 294u32 get_board_rev(void)
 295{
 296        u32 rev = 0;
 297        u32 btype = get_board_type();
 298
 299        if (btype == BOARD_H4_MENELAUS){
 300                rev = 1;
 301        }
 302        return(rev);
 303}
 304
 305/********************************************************
 306 *  get_base(); get upper addr of current execution
 307 *******************************************************/
 308u32 get_base(void)
 309{
 310        u32  val;
 311        __asm__ __volatile__("mov %0, pc \n" : "=r" (val) : : "memory");
 312        val &= 0xF0000000;
 313        val >>= 28;
 314        return(val);
 315}
 316
 317/********************************************************
 318 *  get_base2(); get 2upper addr of current execution
 319 *******************************************************/
 320u32 get_base2(void)
 321{
 322        u32  val;
 323        __asm__ __volatile__("mov %0, pc \n" : "=r" (val) : : "memory");
 324        val &= 0xFF000000;
 325        val >>= 24;
 326        return(val);
 327}
 328
 329/********************************************************
 330 *  running_in_flash() - tell if currently running in
 331 *   flash.
 332 *******************************************************/
 333u32 running_in_flash(void)
 334{
 335        if (get_base() < 4)
 336                return(1);  /* in flash */
 337        return(0); /* running in SRAM or SDRAM */
 338}
 339
 340/********************************************************
 341 *  running_in_sram() - tell if currently running in
 342 *   sram.
 343 *******************************************************/
 344u32 running_in_sram(void)
 345{
 346        if (get_base() == 4)
 347                return(1);  /* in SRAM */
 348        return(0); /* running in FLASH or SDRAM */
 349}
 350/********************************************************
 351 *  running_in_sdram() - tell if currently running in
 352 *   flash.
 353 *******************************************************/
 354u32 running_in_sdram(void)
 355{
 356        if (get_base() > 4)
 357                return(1);  /* in sdram */
 358        return(0); /* running in SRAM or FLASH */
 359}
 360
 361/*************************************************************
 362 *  running_from_internal_boot() - am I a signed NOR image.
 363 *************************************************************/
 364u32 running_from_internal_boot(void)
 365{
 366        u32 v, base;
 367
 368        v = get_sysboot_value() & BIT3;
 369        base = get_base2();
 370        /* if running at mask rom flash address and
 371         * sysboot3 says this was an internal boot
 372         */
 373        if ((base == 0x08) && v)
 374                return(1);
 375        else
 376                return(0);
 377}
 378
 379/*************************************************************
 380 *  get_device_type(): tell if GP/HS/EMU/TST
 381 *************************************************************/
 382u32 get_device_type(void)
 383{
 384        int mode;
 385        mode = __raw_readl(CONTROL_STATUS) & (BIT10|BIT9|BIT8);
 386        return(mode >>= 8);
 387}
 388