2018-05-07 06:58:06 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-08-26 01:12:31 +09:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Socionext Inc.
|
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
*/
|
|
|
|
|
2017-10-14 02:21:18 +09:00
|
|
|
#include <clk.h>
|
2017-08-26 01:12:31 +09:00
|
|
|
#include <dm.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/ioport.h>
|
2017-11-30 13:45:26 +09:00
|
|
|
#include <linux/printk.h>
|
2020-01-22 04:03:11 +09:00
|
|
|
#include <reset.h>
|
2017-08-26 01:12:31 +09:00
|
|
|
|
|
|
|
#include "denali.h"
|
|
|
|
|
2017-09-15 21:43:19 +09:00
|
|
|
struct denali_dt_data {
|
|
|
|
unsigned int revision;
|
|
|
|
unsigned int caps;
|
2020-01-30 00:55:55 +09:00
|
|
|
unsigned int oob_skip_bytes;
|
2017-11-22 02:38:32 +09:00
|
|
|
const struct nand_ecc_caps *ecc_caps;
|
2017-09-15 21:43:19 +09:00
|
|
|
};
|
|
|
|
|
2017-11-22 02:38:32 +09:00
|
|
|
NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes,
|
|
|
|
512, 8, 15);
|
2017-09-15 21:43:19 +09:00
|
|
|
static const struct denali_dt_data denali_socfpga_data = {
|
|
|
|
.caps = DENALI_CAP_HW_ECC_FIXUP,
|
2020-01-30 00:55:55 +09:00
|
|
|
.oob_skip_bytes = 2,
|
2017-11-22 02:38:32 +09:00
|
|
|
.ecc_caps = &denali_socfpga_ecc_caps,
|
2017-09-15 21:43:19 +09:00
|
|
|
};
|
|
|
|
|
2017-11-22 02:38:32 +09:00
|
|
|
NAND_ECC_CAPS_SINGLE(denali_uniphier_v5a_ecc_caps, denali_calc_ecc_bytes,
|
|
|
|
1024, 8, 16, 24);
|
2017-09-15 21:43:19 +09:00
|
|
|
static const struct denali_dt_data denali_uniphier_v5a_data = {
|
|
|
|
.caps = DENALI_CAP_HW_ECC_FIXUP |
|
|
|
|
DENALI_CAP_DMA_64BIT,
|
2020-01-30 00:55:55 +09:00
|
|
|
.oob_skip_bytes = 8,
|
2017-11-22 02:38:32 +09:00
|
|
|
.ecc_caps = &denali_uniphier_v5a_ecc_caps,
|
2017-09-15 21:43:19 +09:00
|
|
|
};
|
|
|
|
|
2017-11-22 02:38:32 +09:00
|
|
|
NAND_ECC_CAPS_SINGLE(denali_uniphier_v5b_ecc_caps, denali_calc_ecc_bytes,
|
|
|
|
1024, 8, 16);
|
2017-09-15 21:43:19 +09:00
|
|
|
static const struct denali_dt_data denali_uniphier_v5b_data = {
|
|
|
|
.revision = 0x0501,
|
|
|
|
.caps = DENALI_CAP_HW_ECC_FIXUP |
|
|
|
|
DENALI_CAP_DMA_64BIT,
|
2020-01-30 00:55:55 +09:00
|
|
|
.oob_skip_bytes = 8,
|
2017-11-22 02:38:32 +09:00
|
|
|
.ecc_caps = &denali_uniphier_v5b_ecc_caps,
|
2017-09-15 21:43:19 +09:00
|
|
|
};
|
|
|
|
|
2017-08-26 01:12:31 +09:00
|
|
|
static const struct udevice_id denali_nand_dt_ids[] = {
|
|
|
|
{
|
|
|
|
.compatible = "altr,socfpga-denali-nand",
|
2017-09-15 21:43:19 +09:00
|
|
|
.data = (unsigned long)&denali_socfpga_data,
|
2017-08-26 01:12:31 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "socionext,uniphier-denali-nand-v5a",
|
2017-09-15 21:43:19 +09:00
|
|
|
.data = (unsigned long)&denali_uniphier_v5a_data,
|
2017-08-26 01:12:31 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "socionext,uniphier-denali-nand-v5b",
|
2017-09-15 21:43:19 +09:00
|
|
|
.data = (unsigned long)&denali_uniphier_v5b_data,
|
2017-08-26 01:12:31 +09:00
|
|
|
},
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int denali_dt_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct denali_nand_info *denali = dev_get_priv(dev);
|
2017-09-15 21:43:19 +09:00
|
|
|
const struct denali_dt_data *data;
|
2018-12-19 20:03:17 +09:00
|
|
|
struct clk clk, clk_x, clk_ecc;
|
2020-01-22 04:03:11 +09:00
|
|
|
struct reset_ctl_bulk resets;
|
2017-08-26 01:12:31 +09:00
|
|
|
struct resource res;
|
|
|
|
int ret;
|
|
|
|
|
2017-09-15 21:43:19 +09:00
|
|
|
data = (void *)dev_get_driver_data(dev);
|
2020-01-30 00:55:55 +09:00
|
|
|
if (WARN_ON(!data))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
denali->revision = data->revision;
|
|
|
|
denali->caps = data->caps;
|
|
|
|
denali->oob_skip_bytes = data->oob_skip_bytes;
|
|
|
|
denali->ecc_caps = data->ecc_caps;
|
2017-09-15 21:43:19 +09:00
|
|
|
|
2017-11-22 02:38:32 +09:00
|
|
|
denali->dev = dev;
|
|
|
|
|
2017-08-26 01:12:31 +09:00
|
|
|
ret = dev_read_resource_byname(dev, "denali_reg", &res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-11-22 02:38:32 +09:00
|
|
|
denali->reg = devm_ioremap(dev, res.start, resource_size(&res));
|
2017-08-26 01:12:31 +09:00
|
|
|
|
|
|
|
ret = dev_read_resource_byname(dev, "nand_data", &res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-11-22 02:38:32 +09:00
|
|
|
denali->host = devm_ioremap(dev, res.start, resource_size(&res));
|
2017-08-26 01:12:31 +09:00
|
|
|
|
2018-12-19 20:03:17 +09:00
|
|
|
ret = clk_get_by_name(dev, "nand", &clk);
|
|
|
|
if (ret)
|
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
2017-10-14 02:21:18 +09:00
|
|
|
if (ret)
|
2020-01-22 04:03:10 +09:00
|
|
|
clk.dev = NULL;
|
2017-10-14 02:21:18 +09:00
|
|
|
|
2018-12-19 20:03:17 +09:00
|
|
|
ret = clk_get_by_name(dev, "nand_x", &clk_x);
|
|
|
|
if (ret)
|
|
|
|
clk_x.dev = NULL;
|
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "ecc", &clk_ecc);
|
|
|
|
if (ret)
|
|
|
|
clk_ecc.dev = NULL;
|
|
|
|
|
2020-01-22 04:03:10 +09:00
|
|
|
if (clk.dev) {
|
|
|
|
ret = clk_enable(&clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2017-10-14 02:21:18 +09:00
|
|
|
|
2018-12-19 20:03:17 +09:00
|
|
|
if (clk_x.dev) {
|
|
|
|
ret = clk_enable(&clk_x);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clk_ecc.dev) {
|
|
|
|
ret = clk_enable(&clk_ecc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clk_x.dev) {
|
2018-12-19 20:03:18 +09:00
|
|
|
denali->clk_rate = clk_get_rate(&clk);
|
2018-12-19 20:03:17 +09:00
|
|
|
denali->clk_x_rate = clk_get_rate(&clk_x);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Hardcode the clock rates for the backward compatibility.
|
|
|
|
* This works for both SOCFPGA and UniPhier.
|
|
|
|
*/
|
|
|
|
dev_notice(dev,
|
|
|
|
"necessary clock is missing. default clock rates are used.\n");
|
2018-12-19 20:03:18 +09:00
|
|
|
denali->clk_rate = 50000000;
|
2018-12-19 20:03:17 +09:00
|
|
|
denali->clk_x_rate = 200000000;
|
|
|
|
}
|
2017-10-14 02:21:18 +09:00
|
|
|
|
2020-01-22 04:03:11 +09:00
|
|
|
ret = reset_get_bulk(dev, &resets);
|
2020-01-30 00:55:54 +09:00
|
|
|
if (ret) {
|
2019-03-02 04:12:34 +09:00
|
|
|
dev_warn(dev, "Can't get reset: %d\n", ret);
|
2020-01-30 00:55:54 +09:00
|
|
|
} else {
|
2020-01-22 04:03:11 +09:00
|
|
|
reset_deassert_bulk(&resets);
|
2019-03-02 04:12:34 +09:00
|
|
|
|
2020-01-30 00:55:54 +09:00
|
|
|
/*
|
|
|
|
* When the reset is deasserted, the initialization sequence is
|
|
|
|
* kicked (bootstrap process). The driver must wait until it is
|
|
|
|
* finished. Otherwise, it will result in unpredictable behavior.
|
|
|
|
*/
|
|
|
|
udelay(200);
|
|
|
|
}
|
|
|
|
|
2017-08-26 01:12:31 +09:00
|
|
|
return denali_init(denali);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(denali_nand_dt) = {
|
|
|
|
.name = "denali-nand-dt",
|
2020-01-30 22:07:59 +09:00
|
|
|
.id = UCLASS_MTD,
|
2017-08-26 01:12:31 +09:00
|
|
|
.of_match = denali_nand_dt_ids,
|
|
|
|
.probe = denali_dt_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct denali_nand_info),
|
|
|
|
};
|
|
|
|
|
|
|
|
void board_nand_init(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
2020-01-30 22:07:59 +09:00
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MTD,
|
2017-08-26 01:12:31 +09:00
|
|
|
DM_GET_DRIVER(denali_nand_dt),
|
|
|
|
&dev);
|
|
|
|
if (ret && ret != -ENODEV)
|
2017-11-30 13:45:26 +09:00
|
|
|
pr_err("Failed to initialize Denali NAND controller. (error %d)\n",
|
2017-08-26 01:12:31 +09:00
|
|
|
ret);
|
|
|
|
}
|