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+
10191089static 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
11111189err_chip :
11121190 flctl_release_dma (flctl );
11131191 pm_runtime_disable (& pdev -> dev );
1192+ err_pdata :
11141193 free_irq (irq , flctl );
11151194err_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