Skip to content

Commit a50895b

Browse files
bbrezillonmiquelraynal
authored andcommitted
mtd: rawnand: fsl_upm: Use gpio descriptors
The integer-based GPIO ids are now deprecated in favor of the GPIO desc API. The PPC platforms have already been converted to GPIOLIB, so let's use gpio descs in the NAND driver too. While at it, we use devm_gpiod_get_index_optional() so we can get rid of the manual gpio desc release done in the init error path and in the remove function. Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 58c5a0e commit a50895b

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

drivers/mtd/nand/raw/fsl_upm.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/mtd/partitions.h>
1616
#include <linux/mtd/mtd.h>
1717
#include <linux/of_platform.h>
18-
#include <linux/of_gpio.h>
1918
#include <linux/io.h>
2019
#include <linux/slab.h>
2120
#include <asm/fsl_lbc.h>
@@ -32,7 +31,7 @@ struct fsl_upm_nand {
3231
uint8_t upm_addr_offset;
3332
uint8_t upm_cmd_offset;
3433
void __iomem *io_base;
35-
int rnb_gpio[NAND_MAX_CHIPS];
34+
struct gpio_desc *rnb_gpio[NAND_MAX_CHIPS];
3635
uint32_t mchip_offsets[NAND_MAX_CHIPS];
3736
uint32_t mchip_count;
3837
uint32_t mchip_number;
@@ -50,7 +49,7 @@ static int fun_chip_ready(struct nand_chip *chip)
5049
{
5150
struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip));
5251

53-
if (gpio_get_value(fun->rnb_gpio[fun->mchip_number]))
52+
if (gpiod_get_value(fun->rnb_gpio[fun->mchip_number]))
5453
return 1;
5554

5655
dev_vdbg(fun->dev, "busy\n");
@@ -165,7 +164,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
165164
if (fun->mchip_count > 1)
166165
fun->chip.legacy.select_chip = fun_select_chip;
167166

168-
if (fun->rnb_gpio[0] >= 0)
167+
if (!fun->rnb_gpio[0])
169168
fun->chip.legacy.dev_ready = fun_chip_ready;
170169

171170
mtd->dev.parent = fun->dev;
@@ -198,7 +197,6 @@ static int fun_probe(struct platform_device *ofdev)
198197
struct fsl_upm_nand *fun;
199198
struct resource *io_res;
200199
const __be32 *prop;
201-
int rnb_gpio;
202200
int ret;
203201
int size;
204202
int i;
@@ -248,20 +246,12 @@ static int fun_probe(struct platform_device *ofdev)
248246
}
249247

250248
for (i = 0; i < fun->mchip_count; i++) {
251-
fun->rnb_gpio[i] = -1;
252-
rnb_gpio = of_get_gpio(ofdev->dev.of_node, i);
253-
if (rnb_gpio >= 0) {
254-
ret = gpio_request(rnb_gpio, dev_name(&ofdev->dev));
255-
if (ret) {
256-
dev_err(&ofdev->dev,
257-
"can't request RNB gpio #%d\n", i);
258-
goto err2;
259-
}
260-
gpio_direction_input(rnb_gpio);
261-
fun->rnb_gpio[i] = rnb_gpio;
262-
} else if (rnb_gpio == -EINVAL) {
249+
fun->rnb_gpio[i] = devm_gpiod_get_index_optional(&ofdev->dev,
250+
NULL, i,
251+
GPIOD_IN);
252+
if (IS_ERR(fun->rnb_gpio[i])) {
263253
dev_err(&ofdev->dev, "RNB gpio #%d is invalid\n", i);
264-
goto err2;
254+
return PTR_ERR(fun->rnb_gpio[i]);
265255
}
266256
}
267257

@@ -283,38 +273,24 @@ static int fun_probe(struct platform_device *ofdev)
283273

284274
ret = fun_chip_init(fun, ofdev->dev.of_node, io_res);
285275
if (ret)
286-
goto err2;
276+
return ret;
287277

288278
dev_set_drvdata(&ofdev->dev, fun);
289279

290280
return 0;
291-
err2:
292-
for (i = 0; i < fun->mchip_count; i++) {
293-
if (fun->rnb_gpio[i] < 0)
294-
break;
295-
gpio_free(fun->rnb_gpio[i]);
296-
}
297-
298-
return ret;
299281
}
300282

301283
static int fun_remove(struct platform_device *ofdev)
302284
{
303285
struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev);
304286
struct nand_chip *chip = &fun->chip;
305287
struct mtd_info *mtd = nand_to_mtd(chip);
306-
int ret, i;
288+
int ret;
307289

308290
ret = mtd_device_unregister(mtd);
309291
WARN_ON(ret);
310292
nand_cleanup(chip);
311293

312-
for (i = 0; i < fun->mchip_count; i++) {
313-
if (fun->rnb_gpio[i] < 0)
314-
break;
315-
gpio_free(fun->rnb_gpio[i]);
316-
}
317-
318294
return 0;
319295
}
320296

0 commit comments

Comments
 (0)