Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 1 | /* |
| 2 | * NAND Flash Controller Device Driver for DT |
| 3 | * |
| 4 | * Copyright © 2011, Picochip. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | #include <linux/clk.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <linux/ioport.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/of_device.h> |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 24 | |
| 25 | #include "denali.h" |
| 26 | |
| 27 | struct denali_dt { |
| 28 | struct denali_nand_info denali; |
| 29 | struct clk *clk; |
| 30 | }; |
| 31 | |
Masahiro Yamada | be72a4a | 2017-03-23 05:07:07 +0900 | [diff] [blame] | 32 | struct denali_dt_data { |
| 33 | unsigned int caps; |
| 34 | }; |
| 35 | |
Masahiro Yamada | a56609c | 2017-03-30 15:45:53 +0900 | [diff] [blame^] | 36 | static const struct denali_dt_data denali_socfpga_data = { |
| 37 | .caps = DENALI_CAP_HW_ECC_FIXUP, |
| 38 | }; |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 39 | |
Masahiro Yamada | a56609c | 2017-03-30 15:45:53 +0900 | [diff] [blame^] | 40 | static const struct of_device_id denali_nand_dt_ids[] = { |
| 41 | { |
| 42 | .compatible = "altr,socfpga-denali-nand", |
| 43 | .data = &denali_socfpga_data, |
| 44 | }, |
| 45 | { /* sentinel */ } |
| 46 | }; |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 47 | MODULE_DEVICE_TABLE(of, denali_nand_dt_ids); |
| 48 | |
| 49 | static u64 denali_dma_mask; |
| 50 | |
Bill Pemberton | 06f2551 | 2012-11-19 13:23:07 -0500 | [diff] [blame] | 51 | static int denali_dt_probe(struct platform_device *ofdev) |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 52 | { |
| 53 | struct resource *denali_reg, *nand_data; |
| 54 | struct denali_dt *dt; |
Masahiro Yamada | be72a4a | 2017-03-23 05:07:07 +0900 | [diff] [blame] | 55 | const struct denali_dt_data *data; |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 56 | struct denali_nand_info *denali; |
| 57 | int ret; |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 58 | |
| 59 | dt = devm_kzalloc(&ofdev->dev, sizeof(*dt), GFP_KERNEL); |
| 60 | if (!dt) |
| 61 | return -ENOMEM; |
| 62 | denali = &dt->denali; |
| 63 | |
Masahiro Yamada | be72a4a | 2017-03-23 05:07:07 +0900 | [diff] [blame] | 64 | data = of_device_get_match_data(&ofdev->dev); |
| 65 | if (data) |
| 66 | denali->caps = data->caps; |
| 67 | |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 68 | denali->platform = DT; |
| 69 | denali->dev = &ofdev->dev; |
| 70 | denali->irq = platform_get_irq(ofdev, 0); |
| 71 | if (denali->irq < 0) { |
| 72 | dev_err(&ofdev->dev, "no irq defined\n"); |
Sachin Kamat | 2f2ff14 | 2013-03-18 15:11:13 +0530 | [diff] [blame] | 73 | return denali->irq; |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 74 | } |
| 75 | |
Jingoo Han | 7995204 | 2014-02-12 11:29:42 +0900 | [diff] [blame] | 76 | denali_reg = platform_get_resource_byname(ofdev, IORESOURCE_MEM, "denali_reg"); |
| 77 | denali->flash_reg = devm_ioremap_resource(&ofdev->dev, denali_reg); |
| 78 | if (IS_ERR(denali->flash_reg)) |
| 79 | return PTR_ERR(denali->flash_reg); |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 80 | |
Jingoo Han | 7995204 | 2014-02-12 11:29:42 +0900 | [diff] [blame] | 81 | nand_data = platform_get_resource_byname(ofdev, IORESOURCE_MEM, "nand_data"); |
| 82 | denali->flash_mem = devm_ioremap_resource(&ofdev->dev, nand_data); |
| 83 | if (IS_ERR(denali->flash_mem)) |
| 84 | return PTR_ERR(denali->flash_mem); |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 85 | |
| 86 | if (!of_property_read_u32(ofdev->dev.of_node, |
| 87 | "dma-mask", (u32 *)&denali_dma_mask)) { |
| 88 | denali->dev->dma_mask = &denali_dma_mask; |
| 89 | } else { |
| 90 | denali->dev->dma_mask = NULL; |
| 91 | } |
| 92 | |
Jingoo Han | 2281f7b6 | 2013-12-26 10:43:11 +0900 | [diff] [blame] | 93 | dt->clk = devm_clk_get(&ofdev->dev, NULL); |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 94 | if (IS_ERR(dt->clk)) { |
| 95 | dev_err(&ofdev->dev, "no clk available\n"); |
| 96 | return PTR_ERR(dt->clk); |
| 97 | } |
| 98 | clk_prepare_enable(dt->clk); |
| 99 | |
| 100 | ret = denali_init(denali); |
| 101 | if (ret) |
| 102 | goto out_disable_clk; |
| 103 | |
| 104 | platform_set_drvdata(ofdev, dt); |
| 105 | return 0; |
| 106 | |
| 107 | out_disable_clk: |
| 108 | clk_disable_unprepare(dt->clk); |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 109 | |
| 110 | return ret; |
| 111 | } |
| 112 | |
Bill Pemberton | 810b7e0 | 2012-11-19 13:26:04 -0500 | [diff] [blame] | 113 | static int denali_dt_remove(struct platform_device *ofdev) |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 114 | { |
| 115 | struct denali_dt *dt = platform_get_drvdata(ofdev); |
| 116 | |
| 117 | denali_remove(&dt->denali); |
Masahiro Yamada | a1a2617 | 2016-11-03 02:21:04 +0900 | [diff] [blame] | 118 | clk_disable_unprepare(dt->clk); |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static struct platform_driver denali_dt_driver = { |
| 124 | .probe = denali_dt_probe, |
Bill Pemberton | 5153b88 | 2012-11-19 13:21:24 -0500 | [diff] [blame] | 125 | .remove = denali_dt_remove, |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 126 | .driver = { |
| 127 | .name = "denali-nand-dt", |
Sachin Kamat | ef54f87 | 2013-03-18 15:11:14 +0530 | [diff] [blame] | 128 | .of_match_table = denali_nand_dt_ids, |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 129 | }, |
| 130 | }; |
| 131 | |
Sachin Kamat | 82fc812 | 2013-03-18 15:11:12 +0530 | [diff] [blame] | 132 | module_platform_driver(denali_dt_driver); |
Dinh Nguyen | 30f9f2f | 2012-09-27 10:58:06 -0600 | [diff] [blame] | 133 | |
| 134 | MODULE_LICENSE("GPL"); |
| 135 | MODULE_AUTHOR("Jamie Iles"); |
| 136 | MODULE_DESCRIPTION("DT driver for Denali NAND controller"); |