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; |
| 19 | }; |
| 20 | |
| 21 | static const struct denali_dt_data denali_socfpga_data = { |
| 22 | .caps = DENALI_CAP_HW_ECC_FIXUP, |
| 23 | }; |
| 24 | |
| 25 | static const struct denali_dt_data denali_uniphier_v5a_data = { |
| 26 | .caps = DENALI_CAP_HW_ECC_FIXUP | |
| 27 | DENALI_CAP_DMA_64BIT, |
| 28 | }; |
| 29 | |
| 30 | static const struct denali_dt_data denali_uniphier_v5b_data = { |
| 31 | .revision = 0x0501, |
| 32 | .caps = DENALI_CAP_HW_ECC_FIXUP | |
| 33 | DENALI_CAP_DMA_64BIT, |
| 34 | }; |
| 35 | |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 36 | static const struct udevice_id denali_nand_dt_ids[] = { |
| 37 | { |
| 38 | .compatible = "altr,socfpga-denali-nand", |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 39 | .data = (unsigned long)&denali_socfpga_data, |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 40 | }, |
| 41 | { |
| 42 | .compatible = "socionext,uniphier-denali-nand-v5a", |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 43 | .data = (unsigned long)&denali_uniphier_v5a_data, |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 44 | }, |
| 45 | { |
| 46 | .compatible = "socionext,uniphier-denali-nand-v5b", |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 47 | .data = (unsigned long)&denali_uniphier_v5b_data, |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 48 | }, |
| 49 | { /* sentinel */ } |
| 50 | }; |
| 51 | |
| 52 | static int denali_dt_probe(struct udevice *dev) |
| 53 | { |
| 54 | struct denali_nand_info *denali = dev_get_priv(dev); |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 55 | const struct denali_dt_data *data; |
Masahiro Yamada | b1c7273 | 2017-10-14 02:21:18 +0900 | [diff] [blame^] | 56 | struct clk clk; |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 57 | struct resource res; |
| 58 | int ret; |
| 59 | |
Masahiro Yamada | 54fde8e | 2017-09-15 21:43:19 +0900 | [diff] [blame] | 60 | data = (void *)dev_get_driver_data(dev); |
| 61 | if (data) { |
| 62 | denali->revision = data->revision; |
| 63 | denali->caps = data->caps; |
| 64 | } |
| 65 | |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 66 | ret = dev_read_resource_byname(dev, "denali_reg", &res); |
| 67 | if (ret) |
| 68 | return ret; |
| 69 | |
| 70 | denali->flash_reg = devm_ioremap(dev, res.start, resource_size(&res)); |
| 71 | |
| 72 | ret = dev_read_resource_byname(dev, "nand_data", &res); |
| 73 | if (ret) |
| 74 | return ret; |
| 75 | |
| 76 | denali->flash_mem = devm_ioremap(dev, res.start, resource_size(&res)); |
| 77 | |
Masahiro Yamada | b1c7273 | 2017-10-14 02:21:18 +0900 | [diff] [blame^] | 78 | ret = clk_get_by_index(dev, 0, &clk); |
| 79 | if (ret) |
| 80 | return ret; |
| 81 | |
| 82 | ret = clk_enable(&clk); |
| 83 | if (ret) |
| 84 | return ret; |
| 85 | |
| 86 | denali->clk_x_rate = clk_get_rate(&clk); |
| 87 | |
Masahiro Yamada | 9c5a5dd | 2017-08-26 01:12:31 +0900 | [diff] [blame] | 88 | return denali_init(denali); |
| 89 | } |
| 90 | |
| 91 | U_BOOT_DRIVER(denali_nand_dt) = { |
| 92 | .name = "denali-nand-dt", |
| 93 | .id = UCLASS_MISC, |
| 94 | .of_match = denali_nand_dt_ids, |
| 95 | .probe = denali_dt_probe, |
| 96 | .priv_auto_alloc_size = sizeof(struct denali_nand_info), |
| 97 | }; |
| 98 | |
| 99 | void board_nand_init(void) |
| 100 | { |
| 101 | struct udevice *dev; |
| 102 | int ret; |
| 103 | |
| 104 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 105 | DM_GET_DRIVER(denali_nand_dt), |
| 106 | &dev); |
| 107 | if (ret && ret != -ENODEV) |
| 108 | printf("Failed to initialize Denali NAND controller. (error %d)\n", |
| 109 | ret); |
| 110 | } |