[PATCH 1/3] mtd: atmel_nand: request and configure pio via gpiolib

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Dec 28 11:46:29 EST 2012


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 drivers/mtd/nand/atmel_nand.c |   53 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 7e0de51..2a57dbb 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -1114,8 +1114,42 @@ static int __init atmel_nand_probe(struct device_d *dev)
 	nand_chip->IO_ADDR_W = host->io_base;
 	nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
 
-	if (gpio_is_valid(host->board->rdy_pin))
+	if (gpio_is_valid(host->board->rdy_pin)) {
+		res = gpio_request(host->board->rdy_pin, "nand_rdy");
+		if (res < 0) {
+			dev_err(dev, "can't request rdy gpio %d\n",
+				host->board->rdy_pin);
+			goto err_no_card;
+		}
+
+		res = gpio_direction_input(host->board->rdy_pin);
+		if (res < 0) {
+			dev_err(dev,
+				"can't request input direction rdy gpio %d\n",
+				host->board->rdy_pin);
+			goto err_no_card;
+		}
+
 		nand_chip->dev_ready = atmel_nand_device_ready;
+	}
+
+	if (gpio_is_valid(host->board->enable_pin)) {
+		res = gpio_request(host->board->enable_pin, "nand_enable");
+		if (res < 0) {
+			dev_err(dev,
+				"can't request enable gpio %d\n",
+				host->board->enable_pin);
+			goto err_no_card;
+		}
+
+		res = gpio_direction_output(host->board->enable_pin, 1);
+		if (res < 0) {
+			dev_err(dev,
+				"can't request output direction enable gpio %d\n",
+				host->board->enable_pin);
+			goto err_no_card;
+		}
+	}
 
 	nand_chip->ecc.mode = NAND_ECC_SOFT;
 
@@ -1138,9 +1172,24 @@ static int __init atmel_nand_probe(struct device_d *dev)
 	atmel_nand_enable(host);
 
 	if (gpio_is_valid(host->board->det_pin)) {
+		res = gpio_request(host->board->det_pin, "nand_det");
+		if (res < 0) {
+			dev_err(dev, "can't request det gpio %d\n",
+				host->board->det_pin);
+			goto err_no_card;
+		}
+
+		res = gpio_direction_input(host->board->det_pin);
+		if (res < 0) {
+			dev_err(dev,
+				"can't request input direction det gpio %d\n",
+				host->board->det_pin);
+			goto err_no_card;
+		}
+
 		if (gpio_get_value(host->board->det_pin)) {
 			printk("No SmartMedia card inserted.\n");
-			res = ENXIO;
+			res = -ENXIO;
 			goto err_no_card;
 		}
 	}
-- 
1.7.10.4




More information about the barebox mailing list