162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * linux/arch/arm/boot/compressed/head-sharpsl.S
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2004-2005 Richard Purdie <rpurdie@rpsys.net>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Sharp's bootloader doesn't pass any kind of machine ID
862306a36Sopenharmony_ci * so we have to figure out the machine for ourselves...
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Support for Poodle, Corgi (SL-C700), Shepherd (SL-C750)
1162306a36Sopenharmony_ci * Husky (SL-C760), Tosa (SL-C6000), Spitz (SL-C3000),
1262306a36Sopenharmony_ci * Akita (SL-C1000) and Borzoi (SL-C3100).
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/linkage.h>
1762306a36Sopenharmony_ci#include <asm/mach-types.h>
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#ifndef CONFIG_PXA_SHARPSL
2062306a36Sopenharmony_ci#error What am I doing here...
2162306a36Sopenharmony_ci#endif
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci		.section        ".start", "ax"
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci__SharpSL_start:
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/* Check for TC6393 - if found we have a Tosa */
2862306a36Sopenharmony_ci	ldr	r7, .TOSAID
2962306a36Sopenharmony_ci	mov	r1, #0x10000000		@ Base address of TC6393 chip
3062306a36Sopenharmony_ci	mov 	r6, #0x03
3162306a36Sopenharmony_ci	ldrh	r3, [r1, #8]		@ Load TC6393XB Revison: This is 0x0003
3262306a36Sopenharmony_ci	cmp	r6, r3
3362306a36Sopenharmony_ci	beq	.SHARPEND		@ Success -> tosa
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/* Check for pxa270 - if found, branch */
3662306a36Sopenharmony_ci	mrc p15, 0, r4, c0, c0		@ Get Processor ID
3762306a36Sopenharmony_ci	and	r4, r4, #0xffffff00
3862306a36Sopenharmony_ci	ldr	r3, .PXA270ID
3962306a36Sopenharmony_ci	cmp	r4, r3
4062306a36Sopenharmony_ci	beq	.PXA270
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* Check for w100 - if not found we have a Poodle */
4362306a36Sopenharmony_ci	ldr	r1, .W100ADDR		@ Base address of w100 chip + regs offset
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci	mov r6, #0x31			@ Load Magic Init value
4662306a36Sopenharmony_ci	str	r6, [r1, #0x280]	@ to SCRATCH_UMSK
4762306a36Sopenharmony_ci	mov r5, #0x3000
4862306a36Sopenharmony_ci.W100LOOP:
4962306a36Sopenharmony_ci	subs r5, r5, #1
5062306a36Sopenharmony_ci	bne .W100LOOP
5162306a36Sopenharmony_ci	mov r6, #0x30			@ Load 2nd Magic Init value
5262306a36Sopenharmony_ci	str	r6, [r1, #0x280]	@ to SCRATCH_UMSK
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci	ldr	r6, [r1, #0]		@ Load Chip ID
5562306a36Sopenharmony_ci	ldr	r3, .W100ID
5662306a36Sopenharmony_ci	ldr	r7, .POODLEID
5762306a36Sopenharmony_ci	cmp	r6, r3
5862306a36Sopenharmony_ci	bne	.SHARPEND			@ We have no w100 - Poodle
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* Check for pxa250 - if found we have a Corgi */
6162306a36Sopenharmony_ci	ldr	r7, .CORGIID
6262306a36Sopenharmony_ci	ldr	r3, .PXA255ID
6362306a36Sopenharmony_ci	cmp	r4, r3
6462306a36Sopenharmony_ci	blo	.SHARPEND			@ We have a PXA250 - Corgi
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/* Check for 64MiB flash - if found we have a Shepherd */
6762306a36Sopenharmony_ci	bl	get_flash_ids
6862306a36Sopenharmony_ci	ldr	r7, .SHEPHERDID
6962306a36Sopenharmony_ci	cmp	r3, #0x76			@ 64MiB flash
7062306a36Sopenharmony_ci	beq	.SHARPEND			@ We have Shepherd
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Must be a Husky */
7362306a36Sopenharmony_ci	ldr	r7, .HUSKYID		@ Must be Husky
7462306a36Sopenharmony_ci	b .SHARPEND
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci.PXA270:
7762306a36Sopenharmony_ci/* Check for 16MiB flash - if found we have Spitz */
7862306a36Sopenharmony_ci	bl	get_flash_ids
7962306a36Sopenharmony_ci	ldr	r7, .SPITZID
8062306a36Sopenharmony_ci	cmp	r3, #0x73			@ 16MiB flash
8162306a36Sopenharmony_ci	beq	.SHARPEND			@ We have Spitz
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/* Check for a second SCOOP chip - if found we have Borzoi */
8462306a36Sopenharmony_ci	ldr	r1, .SCOOP2ADDR
8562306a36Sopenharmony_ci	ldr	r7, .BORZOIID
8662306a36Sopenharmony_ci	mov 	r6, #0x0140
8762306a36Sopenharmony_ci	strh	r6, [r1]
8862306a36Sopenharmony_ci	ldrh	r6, [r1]
8962306a36Sopenharmony_ci	cmp	r6, #0x0140
9062306a36Sopenharmony_ci	beq	.SHARPEND			@ We have Borzoi
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* Must be Akita */
9362306a36Sopenharmony_ci	ldr	r7, .AKITAID
9462306a36Sopenharmony_ci	b	.SHARPEND			@ We have Borzoi
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci.PXA255ID:
9762306a36Sopenharmony_ci	.word	0x69052d00		@ PXA255 Processor ID
9862306a36Sopenharmony_ci.PXA270ID:
9962306a36Sopenharmony_ci	.word	0x69054100		@ PXA270 Processor ID
10062306a36Sopenharmony_ci.W100ID:
10162306a36Sopenharmony_ci	.word	0x57411002		@ w100 Chip ID
10262306a36Sopenharmony_ci.W100ADDR:
10362306a36Sopenharmony_ci	.word 	0x08010000		@ w100 Chip ID Reg Address
10462306a36Sopenharmony_ci.SCOOP2ADDR:
10562306a36Sopenharmony_ci	.word	0x08800040
10662306a36Sopenharmony_ci.POODLEID:
10762306a36Sopenharmony_ci	.word	MACH_TYPE_POODLE
10862306a36Sopenharmony_ci.CORGIID:
10962306a36Sopenharmony_ci	.word	MACH_TYPE_CORGI
11062306a36Sopenharmony_ci.SHEPHERDID:
11162306a36Sopenharmony_ci	.word	MACH_TYPE_SHEPHERD
11262306a36Sopenharmony_ci.HUSKYID:
11362306a36Sopenharmony_ci	.word	MACH_TYPE_HUSKY
11462306a36Sopenharmony_ci.TOSAID:
11562306a36Sopenharmony_ci	.word	MACH_TYPE_TOSA
11662306a36Sopenharmony_ci.SPITZID:
11762306a36Sopenharmony_ci	.word	MACH_TYPE_SPITZ
11862306a36Sopenharmony_ci.AKITAID:
11962306a36Sopenharmony_ci	.word	MACH_TYPE_AKITA
12062306a36Sopenharmony_ci.BORZOIID:
12162306a36Sopenharmony_ci	.word	MACH_TYPE_BORZOI
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/*
12462306a36Sopenharmony_ci * Return: r2 - NAND Manufacturer ID
12562306a36Sopenharmony_ci *         r3 - NAND Chip ID
12662306a36Sopenharmony_ci * Corrupts: r1
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_ciget_flash_ids:
12962306a36Sopenharmony_ci	mov	r1, #0x0c000000		@ Base address of NAND chip
13062306a36Sopenharmony_ci	ldrb	r3, [r1, #24]		@ Load FLASHCTL
13162306a36Sopenharmony_ci	bic	r3, r3, #0x11		@ SET NCE
13262306a36Sopenharmony_ci	orr	r3, r3, #0x0a		@ SET CLR + FLWP
13362306a36Sopenharmony_ci	strb	r3, [r1, #24]		@ Save to FLASHCTL
13462306a36Sopenharmony_ci	mov 	r2, #0x90		@ Command "readid"
13562306a36Sopenharmony_ci	strb	r2, [r1, #20]		@ Save to FLASHIO
13662306a36Sopenharmony_ci	bic	r3, r3, #2		@ CLR CLE
13762306a36Sopenharmony_ci	orr	r3, r3, #4		@ SET ALE
13862306a36Sopenharmony_ci	strb	r3, [r1, #24]		@ Save to FLASHCTL
13962306a36Sopenharmony_ci	mov	r2, #0			@ Address 0x00
14062306a36Sopenharmony_ci	strb	r2, [r1, #20]		@ Save to FLASHIO
14162306a36Sopenharmony_ci	bic	r3, r3, #4		@ CLR ALE
14262306a36Sopenharmony_ci	strb	r3, [r1, #24]		@ Save to FLASHCTL
14362306a36Sopenharmony_ci.fids1:
14462306a36Sopenharmony_ci	ldrb	r3, [r1, #24]		@ Load FLASHCTL
14562306a36Sopenharmony_ci	tst	r3, #32			@ Is chip ready?
14662306a36Sopenharmony_ci	beq	.fids1
14762306a36Sopenharmony_ci	ldrb	r2, [r1, #20]		@ NAND Manufacturer ID
14862306a36Sopenharmony_ci	ldrb	r3, [r1, #20]		@ NAND Chip ID
14962306a36Sopenharmony_ci	mov	pc, lr
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci.SHARPEND:
152