Skip to content

Commit 7c8f680

Browse files
Bastian Hechtdedekind
authored andcommitted
mtd: sh_flctl: Add device tree support
The flctl can now be probed via device tree setup in addition to the existing platform data way. SoC specific setup data is set in the .data member of the OF match, so kept within the driver itself, while board/user specific setup - like partitioning - is taken from the device tree. Actual configuration is added for the SoC sh7372. Signed-off-by: Bastian Hecht <hechtb@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent 83738d8 commit 7c8f680

2 files changed

Lines changed: 136 additions & 7 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FLCTL NAND controller
2+
3+
Required properties:
4+
- compatible : "renesas,shmobile-flctl-sh7372"
5+
- reg : Address range of the FLCTL
6+
- interrupts : flste IRQ number
7+
- nand-bus-width : bus width to NAND chip
8+
9+
Optional properties:
10+
- dmas: DMA specifier(s)
11+
- dma-names: name for each DMA specifier. Valid names are
12+
"data_tx", "data_rx", "ecc_tx", "ecc_rx"
13+
14+
The DMA fields are not used yet in the driver but are listed here for
15+
completing the bindings.
16+
17+
The device tree may optionally contain sub-nodes describing partitions of the
18+
address space. See partition.txt for more detail.
19+
20+
Example:
21+
22+
flctl@e6a30000 {
23+
#address-cells = <1>;
24+
#size-cells = <1>;
25+
compatible = "renesas,shmobile-flctl-sh7372";
26+
reg = <0xe6a30000 0x100>;
27+
interrupts = <0x0d80>;
28+
29+
nand-bus-width = <16>;
30+
31+
dmas = <&dmac 1 /* data_tx */
32+
&dmac 2;> /* data_rx */
33+
dma-names = "data_tx", "data_rx";
34+
35+
system@0 {
36+
label = "system";
37+
reg = <0x0 0x8000000>;
38+
};
39+
40+
userdata@8000000 {
41+
label = "userdata";
42+
reg = <0x8000000 0x10000000>;
43+
};
44+
45+
cache@18000000 {
46+
label = "cache";
47+
reg = <0x18000000 0x8000000>;
48+
};
49+
};

‎drivers/mtd/nand/sh_flctl.c‎

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <linux/dma-mapping.h>
3030
#include <linux/interrupt.h>
3131
#include <linux/io.h>
32+
#include <linux/of.h>
33+
#include <linux/of_device.h>
34+
#include <linux/of_mtd.h>
3235
#include <linux/platform_device.h>
3336
#include <linux/pm_runtime.h>
3437
#include <linux/sh_dma.h>
@@ -1016,6 +1019,73 @@ static irqreturn_t flctl_handle_flste(int irq, void *dev_id)
10161019
return IRQ_HANDLED;
10171020
}
10181021

1022+
#ifdef CONFIG_OF
1023+
struct flctl_soc_config {
1024+
unsigned long flcmncr_val;
1025+
unsigned has_hwecc:1;
1026+
unsigned use_holden:1;
1027+
};
1028+
1029+
static struct flctl_soc_config flctl_sh7372_config = {
1030+
.flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET | SHBUSSEL,
1031+
.has_hwecc = 1,
1032+
.use_holden = 1,
1033+
};
1034+
1035+
static const struct of_device_id of_flctl_match[] = {
1036+
{ .compatible = "renesas,shmobile-flctl-sh7372",
1037+
.data = &flctl_sh7372_config },
1038+
{},
1039+
};
1040+
MODULE_DEVICE_TABLE(of, of_flctl_match);
1041+
1042+
static struct sh_flctl_platform_data *flctl_parse_dt(struct device *dev)
1043+
{
1044+
const struct of_device_id *match;
1045+
struct flctl_soc_config *config;
1046+
struct sh_flctl_platform_data *pdata;
1047+
struct device_node *dn = dev->of_node;
1048+
int ret;
1049+
1050+
match = of_match_device(of_flctl_match, dev);
1051+
if (match)
1052+
config = (struct flctl_soc_config *)match->data;
1053+
else {
1054+
dev_err(dev, "%s: no OF configuration attached\n", __func__);
1055+
return NULL;
1056+
}
1057+
1058+
pdata = devm_kzalloc(dev, sizeof(struct sh_flctl_platform_data),
1059+
GFP_KERNEL);
1060+
if (!pdata) {
1061+
dev_err(dev, "%s: failed to allocate config data\n", __func__);
1062+
return NULL;
1063+
}
1064+
1065+
/* set SoC specific options */
1066+
pdata->flcmncr_val = config->flcmncr_val;
1067+
pdata->has_hwecc = config->has_hwecc;
1068+
pdata->use_holden = config->use_holden;
1069+
1070+
/* parse user defined options */
1071+
ret = of_get_nand_bus_width(dn);
1072+
if (ret == 16)
1073+
pdata->flcmncr_val |= SEL_16BIT;
1074+
else if (ret != 8) {
1075+
dev_err(dev, "%s: invalid bus width\n", __func__);
1076+
return NULL;
1077+
}
1078+
1079+
return pdata;
1080+
}
1081+
#else /* CONFIG_OF */
1082+
#define of_flctl_match NULL
1083+
static struct sh_flctl_platform_data *flctl_parse_dt(struct device *dev)
1084+
{
1085+
return NULL;
1086+
}
1087+
#endif /* CONFIG_OF */
1088+
10191089
static int __devinit flctl_probe(struct platform_device *pdev)
10201090
{
10211091
struct resource *res;
@@ -1025,12 +1095,7 @@ static int __devinit flctl_probe(struct platform_device *pdev)
10251095
struct sh_flctl_platform_data *pdata;
10261096
int ret = -ENXIO;
10271097
int irq;
1028-
1029-
pdata = pdev->dev.platform_data;
1030-
if (pdata == NULL) {
1031-
dev_err(&pdev->dev, "no platform data defined\n");
1032-
return -EINVAL;
1033-
}
1098+
struct mtd_part_parser_data ppdata = {};
10341099

10351100
flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL);
10361101
if (!flctl) {
@@ -1062,6 +1127,17 @@ static int __devinit flctl_probe(struct platform_device *pdev)
10621127
goto err_flste;
10631128
}
10641129

1130+
if (pdev->dev.of_node)
1131+
pdata = flctl_parse_dt(&pdev->dev);
1132+
else
1133+
pdata = pdev->dev.platform_data;
1134+
1135+
if (!pdata) {
1136+
dev_err(&pdev->dev, "no setup data defined\n");
1137+
ret = -EINVAL;
1138+
goto err_pdata;
1139+
}
1140+
10651141
platform_set_drvdata(pdev, flctl);
10661142
flctl_mtd = &flctl->mtd;
10671143
nand = &flctl->chip;
@@ -1104,13 +1180,16 @@ static int __devinit flctl_probe(struct platform_device *pdev)
11041180
if (ret)
11051181
goto err_chip;
11061182

1107-
mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
1183+
ppdata.of_node = pdev->dev.of_node;
1184+
ret = mtd_device_parse_register(flctl_mtd, NULL, &ppdata, pdata->parts,
1185+
pdata->nr_parts);
11081186

11091187
return 0;
11101188

11111189
err_chip:
11121190
flctl_release_dma(flctl);
11131191
pm_runtime_disable(&pdev->dev);
1192+
err_pdata:
11141193
free_irq(irq, flctl);
11151194
err_flste:
11161195
iounmap(flctl->reg);
@@ -1138,6 +1217,7 @@ static struct platform_driver flctl_driver = {
11381217
.driver = {
11391218
.name = "sh_flctl",
11401219
.owner = THIS_MODULE,
1220+
.of_match_table = of_flctl_match,
11411221
},
11421222
};
11431223

0 commit comments

Comments
 (0)