blob: 86ec550aaca92ac52d4aad4db3a4d1ee9d09dcfa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Minkyu Kang29325572009-10-01 17:20:40 +09002/*
3 * Copyright (C) 2008-2009 Samsung Electronics
4 * Kyungmin Park <kyungmin.park@samsung.com>
Minkyu Kang29325572009-10-01 17:20:40 +09005 */
6
Mike Frysinger11d1a092012-04-09 13:39:55 +00007#include <linux/compat.h>
Minkyu Kang29325572009-10-01 17:20:40 +09008#include <linux/mtd/mtd.h>
9#include <linux/mtd/onenand.h>
10#include <linux/mtd/samsung_onenand.h>
11
12#include <onenand_uboot.h>
13
14#include <asm/io.h>
15#include <asm/arch/clock.h>
16
Ladislav Michl11732712016-07-12 20:28:20 +020017int onenand_board_init(struct mtd_info *mtd)
Minkyu Kang29325572009-10-01 17:20:40 +090018{
19 struct onenand_chip *this = mtd->priv;
Minkyu Kangc8189842010-08-13 16:07:35 +090020 struct s5pc100_clock *clk =
21 (struct s5pc100_clock *)samsung_get_base_clock();
Minkyu Kang29325572009-10-01 17:20:40 +090022 struct samsung_onenand *onenand;
23 int value;
24
25 this->base = (void *)S5PC100_ONENAND_BASE;
26 onenand = (struct samsung_onenand *)this->base;
27
28 /* D0 Domain memory clock gating */
29 value = readl(&clk->gate_d01);
30 value &= ~(1 << 2); /* CLK_ONENANDC */
31 value |= (1 << 2);
32 writel(value, &clk->gate_d01);
33
34 value = readl(&clk->src0);
35 value &= ~(1 << 24); /* MUX_1nand: 0 from HCLKD0 */
36 value &= ~(1 << 20); /* MUX_HREF: 0 from FIN_27M */
37 writel(value, &clk->src0);
38
39 value = readl(&clk->div1);
40 value &= ~(3 << 16); /* PCLKD1_RATIO */
41 value |= (1 << 16);
42 writel(value, &clk->div1);
43
44 writel(ONENAND_MEM_RESET_COLD, &onenand->mem_reset);
45
46 while (!(readl(&onenand->int_err_stat) & RST_CMP))
47 continue;
48
49 writel(RST_CMP, &onenand->int_err_ack);
50
51 /*
52 * Access_Clock [2:0]
53 * 166 MHz, 134 Mhz : 3
54 * 100 Mhz, 60 Mhz : 2
55 */
56 writel(0x3, &onenand->acc_clock);
57
58 writel(INT_ERR_ALL, &onenand->int_err_mask);
59 writel(1 << 0, &onenand->int_pin_en); /* Enable */
60
61 value = readl(&onenand->int_err_mask);
62 value &= ~RDY_ACT;
63 writel(value, &onenand->int_err_mask);
64
65 s3c_onenand_init(mtd);
Ladislav Michl11732712016-07-12 20:28:20 +020066
67 return 0;
Minkyu Kang29325572009-10-01 17:20:40 +090068}