Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 Socionext Inc. |
| 3 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Masahiro Yamada | b1c7273 | 2017-10-14 02:21:18 +0900 | [diff] [blame] | 9 | #include <clk.h> |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/ioport.h> |
| 13 | |
| 14 | #include "denali.h" |
| 15 | |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 16 | struct denali_dt_data { |
| 17 | unsigned int revision; |
| 18 | unsigned int caps; |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 19 | const struct nand_ecc_caps *ecc_caps; |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 20 | }; |
| 21 | |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 22 | NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes, |
| 23 | 512, 8, 15); |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 24 | static const struct denali_dt_data denali_socfpga_data = { |
| 25 | .caps = DENALI_CAP_HW_ECC_FIXUP, |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 26 | .ecc_caps = &denali_socfpga_ecc_caps, |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 27 | }; |
| 28 | |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 29 | NAND_ECC_CAPS_SINGLE(denali_uniphier_v5a_ecc_caps, denali_calc_ecc_bytes, |
| 30 | 1024, 8, 16, 24); |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 31 | static const struct denali_dt_data denali_uniphier_v5a_data = { |
| 32 | .caps = DENALI_CAP_HW_ECC_FIXUP | |
| 33 | DENALI_CAP_DMA_64BIT, |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 34 | .ecc_caps = &denali_uniphier_v5a_ecc_caps, |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 35 | }; |
| 36 | |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 37 | NAND_ECC_CAPS_SINGLE(denali_uniphier_v5b_ecc_caps, denali_calc_ecc_bytes, |
| 38 | 1024, 8, 16); |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 39 | static const struct denali_dt_data denali_uniphier_v5b_data = { |
| 40 | .revision = 0x0501, |
| 41 | .caps = DENALI_CAP_HW_ECC_FIXUP | |
| 42 | DENALI_CAP_DMA_64BIT, |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 43 | .ecc_caps = &denali_uniphier_v5b_ecc_caps, |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 44 | }; |
| 45 | |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 46 | static const struct udevice_id denali_nand_dt_ids[] = { |
| 47 | { |
| 48 | .compatible = "altr,socfpga-denali-nand", |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 49 | .data = (unsigned long)&denali_socfpga_data, |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 50 | }, |
| 51 | { |
| 52 | .compatible = "socionext,uniphier-denali-nand-v5a", |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 53 | .data = (unsigned long)&denali_uniphier_v5a_data, |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 54 | }, |
| 55 | { |
| 56 | .compatible = "socionext,uniphier-denali-nand-v5b", |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 57 | .data = (unsigned long)&denali_uniphier_v5b_data, |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 58 | }, |
| 59 | { /* sentinel */ } |
| 60 | }; |
| 61 | |
| 62 | static int denali_dt_probe(struct udevice *dev) |
| 63 | { |
| 64 | struct denali_nand_info *denali = dev_get_priv(dev); |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 65 | const struct denali_dt_data *data; |
Masahiro Yamada | b1c7273 | 2017-10-14 02:21:18 +0900 | [diff] [blame] | 66 | struct clk clk; |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 67 | struct resource res; |
| 68 | int ret; |
| 69 | |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 70 | data = (void *)dev_get_driver_data(dev); |
| 71 | if (data) { |
| 72 | denali->revision = data->revision; |
| 73 | denali->caps = data->caps; |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 74 | denali->ecc_caps = data->ecc_caps; |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 75 | } |
| 76 | |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 77 | denali->dev = dev; |
| 78 | |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 79 | ret = dev_read_resource_byname(dev, "denali_reg", &res); |
| 80 | if (ret) |
| 81 | return ret; |
| 82 | |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 83 | denali->reg = devm_ioremap(dev, res.start, resource_size(&res)); |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 84 | |
| 85 | ret = dev_read_resource_byname(dev, "nand_data", &res); |
| 86 | if (ret) |
| 87 | return ret; |
| 88 | |
Masahiro Yamada | 8b0c16f | 2017-11-22 02:38:32 +0900 | [diff] [blame^] | 89 | denali->host = devm_ioremap(dev, res.start, resource_size(&res)); |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 90 | |
Masahiro Yamada | b1c7273 | 2017-10-14 02:21:18 +0900 | [diff] [blame] | 91 | ret = clk_get_by_index(dev, 0, &clk); |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | |
| 95 | ret = clk_enable(&clk); |
| 96 | if (ret) |
| 97 | return ret; |
| 98 | |
| 99 | denali->clk_x_rate = clk_get_rate(&clk); |
| 100 | |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 101 | return denali_init(denali); |
| 102 | } |
| 103 | |
| 104 | U_BOOT_DRIVER(denali_nand_dt) = { |
| 105 | .name = "denali-nand-dt", |
| 106 | .id = UCLASS_MISC, |
| 107 | .of_match = denali_nand_dt_ids, |
| 108 | .probe = denali_dt_probe, |
| 109 | .priv_auto_alloc_size = sizeof(struct denali_nand_info), |
| 110 | }; |
| 111 | |
| 112 | void board_nand_init(void) |
| 113 | { |
| 114 | struct udevice *dev; |
| 115 | int ret; |
| 116 | |
| 117 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 118 | DM_GET_DRIVER(denali_nand_dt), |
| 119 | &dev); |
| 120 | if (ret && ret != -ENODEV) |
| 121 | printf("Failed to initialize Denali NAND controller. (error %d)\n", |
| 122 | ret); |
| 123 | } |