blob: 17058e49faaa56353e08214334eb35e6701b901e [file] [log] [blame]
Dinesh Maniyam304fc3f2025-02-27 00:18:29 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2024 Intel Corporation <www.intel.com>
4 */
5
6#include <cadence-nand.h>
7#include <dm.h>
8#include <hang.h>
9#include <nand.h>
10#include <system-constants.h>
11
12/* Unselect after operation */
13void nand_deselect(void)
14{
15 struct mtd_info *mtd;
16 struct nand_chip *chip;
17
18 mtd = get_nand_dev_by_index(nand_curr_device);
19 if (!mtd)
20 hang();
21 chip = mtd_to_nand(mtd);
22
23 if (chip->select_chip)
24 chip->select_chip(mtd, -1);
25}
26
27static int nand_is_bad_block(int block)
28{
29 struct mtd_info *mtd;
30 struct nand_chip *chip;
31 loff_t ofs = block * CONFIG_SYS_NAND_BLOCK_SIZE;
32
33 mtd = get_nand_dev_by_index(nand_curr_device);
34 if (!mtd)
35 hang();
36 chip = mtd_to_nand(mtd);
37
38 return chip->block_bad(mtd, ofs);
39}
40
41static int nand_read_page(int block, int page, uchar *dst)
42{
43 struct mtd_info *mtd;
44 int page_addr = block * SYS_NAND_BLOCK_PAGES + page;
45 loff_t ofs = page_addr * CONFIG_SYS_NAND_PAGE_SIZE;
46 int ret;
47 size_t len = CONFIG_SYS_NAND_PAGE_SIZE;
48
49 mtd = get_nand_dev_by_index(nand_curr_device);
50 if (!mtd)
51 hang();
52
53 ret = nand_read(mtd, ofs, &len, dst);
54 if (ret)
55 printf("nand_read failed %d\n", ret);
56
57 return ret;
58}
59#include "nand_spl_loaders.c"