2019-05-19 15:51:31 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
2008-07-05 10:02:59 +02:00
/*
* Copyright 2007 Freescale Semiconductor , Inc . All Rights Reserved .
* Copyright 2008 Juergen Beisert , kernel @ pengutronix . de
*/
/*
* i . MX27 specific CPU detection code
*/
# include <linux/io.h>
2020-09-16 21:41:15 -03:00
# include <linux/of_address.h>
2008-07-05 10:02:59 +02:00
# include <linux/module.h>
2012-09-14 14:14:45 +08:00
# include "hardware.h"
2008-07-05 10:02:59 +02:00
2011-08-26 13:35:20 +08:00
static int mx27_cpu_rev = - 1 ;
static int mx27_cpu_partnumber ;
2008-07-05 10:02:59 +02:00
2009-02-16 15:13:43 +01:00
# define SYS_CHIP_ID 0x00 /* The offset of CHIP ID register */
2020-09-16 21:41:15 -03:00
# define SYSCTRL_OFFSET 0x800 /* Offset from CCM base address */
2009-02-16 15:13:43 +01:00
2011-08-26 13:35:20 +08:00
static int mx27_read_cpu_rev ( void )
2008-07-05 10:02:59 +02:00
{
2020-09-16 21:41:15 -03:00
void __iomem * ccm_base ;
struct device_node * np ;
2008-07-05 10:02:59 +02:00
u32 val ;
2020-09-16 21:41:15 -03:00
np = of_find_compatible_node ( NULL , NULL , " fsl,imx27-ccm " ) ;
ccm_base = of_iomap ( np , 0 ) ;
BUG_ON ( ! ccm_base ) ;
2008-07-05 10:02:59 +02:00
/*
* now we have access to the IO registers . As we need
* the silicon revision very early we read it here to
* avoid any further hooks
*/
2020-09-16 21:41:15 -03:00
val = imx_readl ( ccm_base + SYSCTRL_OFFSET + SYS_CHIP_ID ) ;
2008-07-05 10:02:59 +02:00
2011-08-26 13:35:20 +08:00
mx27_cpu_partnumber = ( int ) ( ( val > > 12 ) & 0xFFFF ) ;
2010-11-15 11:30:01 -06:00
switch ( val > > 28 ) {
case 0 :
2011-08-26 13:35:20 +08:00
return IMX_CHIP_REVISION_1_0 ;
2010-11-15 11:30:01 -06:00
case 1 :
2011-08-26 13:35:20 +08:00
return IMX_CHIP_REVISION_2_0 ;
2010-11-15 11:30:01 -06:00
case 2 :
2011-08-26 13:35:20 +08:00
return IMX_CHIP_REVISION_2_1 ;
2010-11-15 11:30:01 -06:00
default :
2011-08-26 13:35:20 +08:00
return IMX_CHIP_REVISION_UNKNOWN ;
2010-11-15 11:30:01 -06:00
}
2008-07-05 10:02:59 +02:00
}
/*
* Returns :
* the silicon revision of the cpu
* - EINVAL - not a mx27
*/
int mx27_revision ( void )
{
2011-08-26 13:35:20 +08:00
if ( mx27_cpu_rev = = - 1 )
mx27_cpu_rev = mx27_read_cpu_rev ( ) ;
2008-07-05 10:02:59 +02:00
2011-08-26 13:35:20 +08:00
if ( mx27_cpu_partnumber ! = 0x8821 )
2008-07-05 10:02:59 +02:00
return - EINVAL ;
2011-08-26 13:35:20 +08:00
return mx27_cpu_rev ;
2008-07-05 10:02:59 +02:00
}
EXPORT_SYMBOL ( mx27_revision ) ;