@@ -1161,10 +1161,10 @@ static int nxp_fspi_probe(struct platform_device *pdev)
1161
1161
struct device_node * np = dev -> of_node ;
1162
1162
struct resource * res ;
1163
1163
struct nxp_fspi * f ;
1164
- int ret ;
1164
+ int ret , irq ;
1165
1165
u32 reg ;
1166
1166
1167
- ctlr = spi_alloc_host (& pdev -> dev , sizeof (* f ));
1167
+ ctlr = devm_spi_alloc_host (& pdev -> dev , sizeof (* f ));
1168
1168
if (!ctlr )
1169
1169
return - ENOMEM ;
1170
1170
@@ -1174,10 +1174,8 @@ static int nxp_fspi_probe(struct platform_device *pdev)
1174
1174
f = spi_controller_get_devdata (ctlr );
1175
1175
f -> dev = dev ;
1176
1176
f -> devtype_data = (struct nxp_fspi_devtype_data * )device_get_match_data (dev );
1177
- if (!f -> devtype_data ) {
1178
- ret = - ENODEV ;
1179
- goto err_put_ctrl ;
1180
- }
1177
+ if (!f -> devtype_data )
1178
+ return - ENODEV ;
1181
1179
1182
1180
platform_set_drvdata (pdev , f );
1183
1181
@@ -1186,23 +1184,17 @@ static int nxp_fspi_probe(struct platform_device *pdev)
1186
1184
f -> iobase = devm_platform_ioremap_resource (pdev , 0 );
1187
1185
else
1188
1186
f -> iobase = devm_platform_ioremap_resource_byname (pdev , "fspi_base" );
1189
-
1190
- if (IS_ERR (f -> iobase )) {
1191
- ret = PTR_ERR (f -> iobase );
1192
- goto err_put_ctrl ;
1193
- }
1187
+ if (IS_ERR (f -> iobase ))
1188
+ return PTR_ERR (f -> iobase );
1194
1189
1195
1190
/* find the resources - controller memory mapped space */
1196
1191
if (is_acpi_node (dev_fwnode (f -> dev )))
1197
1192
res = platform_get_resource (pdev , IORESOURCE_MEM , 1 );
1198
1193
else
1199
1194
res = platform_get_resource_byname (pdev ,
1200
1195
IORESOURCE_MEM , "fspi_mmap" );
1201
-
1202
- if (!res ) {
1203
- ret = - ENODEV ;
1204
- goto err_put_ctrl ;
1205
- }
1196
+ if (!res )
1197
+ return - ENODEV ;
1206
1198
1207
1199
/* assign memory mapped starting address and mapped size. */
1208
1200
f -> memmap_phy = res -> start ;
@@ -1211,69 +1203,46 @@ static int nxp_fspi_probe(struct platform_device *pdev)
1211
1203
/* find the clocks */
1212
1204
if (dev_of_node (& pdev -> dev )) {
1213
1205
f -> clk_en = devm_clk_get (dev , "fspi_en" );
1214
- if (IS_ERR (f -> clk_en )) {
1215
- ret = PTR_ERR (f -> clk_en );
1216
- goto err_put_ctrl ;
1217
- }
1206
+ if (IS_ERR (f -> clk_en ))
1207
+ return PTR_ERR (f -> clk_en );
1218
1208
1219
1209
f -> clk = devm_clk_get (dev , "fspi" );
1220
- if (IS_ERR (f -> clk )) {
1221
- ret = PTR_ERR (f -> clk );
1222
- goto err_put_ctrl ;
1223
- }
1224
-
1225
- ret = nxp_fspi_clk_prep_enable (f );
1226
- if (ret ) {
1227
- dev_err (dev , "can not enable the clock\n" );
1228
- goto err_put_ctrl ;
1229
- }
1210
+ if (IS_ERR (f -> clk ))
1211
+ return PTR_ERR (f -> clk );
1230
1212
}
1231
1213
1214
+ /* find the irq */
1215
+ irq = platform_get_irq (pdev , 0 );
1216
+ if (irq < 0 )
1217
+ return dev_err_probe (dev , irq , "Failed to get irq source" );
1218
+
1219
+ ret = nxp_fspi_clk_prep_enable (f );
1220
+ if (ret )
1221
+ return dev_err_probe (dev , ret , "Can't enable the clock\n" );
1222
+
1232
1223
/* Clear potential interrupts */
1233
1224
reg = fspi_readl (f , f -> iobase + FSPI_INTR );
1234
1225
if (reg )
1235
1226
fspi_writel (f , reg , f -> iobase + FSPI_INTR );
1236
1227
1237
- /* find the irq */
1238
- ret = platform_get_irq (pdev , 0 );
1239
- if (ret < 0 )
1240
- goto err_disable_clk ;
1228
+ nxp_fspi_default_setup (f );
1241
1229
1242
- ret = devm_request_irq (dev , ret ,
1230
+ ret = devm_request_irq (dev , irq ,
1243
1231
nxp_fspi_irq_handler , 0 , pdev -> name , f );
1244
1232
if (ret ) {
1245
- dev_err ( dev , "failed to request irq: %d\n" , ret );
1246
- goto err_disable_clk ;
1233
+ nxp_fspi_clk_disable_unprep ( f );
1234
+ return dev_err_probe ( dev , ret , "Failed to request irq\n" ) ;
1247
1235
}
1248
1236
1249
- mutex_init ( & f -> lock );
1237
+ devm_mutex_init ( dev , & f -> lock );
1250
1238
1251
1239
ctlr -> bus_num = -1 ;
1252
1240
ctlr -> num_chipselect = NXP_FSPI_MAX_CHIPSELECT ;
1253
1241
ctlr -> mem_ops = & nxp_fspi_mem_ops ;
1254
1242
ctlr -> mem_caps = & nxp_fspi_mem_caps ;
1255
-
1256
- nxp_fspi_default_setup (f );
1257
-
1258
1243
ctlr -> dev .of_node = np ;
1259
1244
1260
- ret = devm_spi_register_controller (& pdev -> dev , ctlr );
1261
- if (ret )
1262
- goto err_destroy_mutex ;
1263
-
1264
- return 0 ;
1265
-
1266
- err_destroy_mutex :
1267
- mutex_destroy (& f -> lock );
1268
-
1269
- err_disable_clk :
1270
- nxp_fspi_clk_disable_unprep (f );
1271
-
1272
- err_put_ctrl :
1273
- spi_controller_put (ctlr );
1274
-
1275
- dev_err (dev , "NXP FSPI probe failed\n" );
1276
- return ret ;
1245
+ return devm_spi_register_controller (& pdev -> dev , ctlr );
1277
1246
}
1278
1247
1279
1248
static void nxp_fspi_remove (struct platform_device * pdev )
@@ -1285,8 +1254,6 @@ static void nxp_fspi_remove(struct platform_device *pdev)
1285
1254
1286
1255
nxp_fspi_clk_disable_unprep (f );
1287
1256
1288
- mutex_destroy (& f -> lock );
1289
-
1290
1257
if (f -> ahb_addr )
1291
1258
iounmap (f -> ahb_addr );
1292
1259
}
0 commit comments