Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0679e29b authored by Alexander Aring's avatar Alexander Aring Committed by David S. Miller
Browse files

at86rf230: use devm_gpio_request_one



This patch replace the gpio_request functions with devm_gpio_request_one
functions. Then we don't need to take care about freeing gpios.

Signed-off-by: default avatarAlexander Aring <alex.aring@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 652355c5
Loading
Loading
Loading
Loading
+12 −41
Original line number Original line Diff line number Diff line
@@ -1074,27 +1074,17 @@ static int at86rf230_probe(struct spi_device *spi)
	}
	}


	if (gpio_is_valid(pdata->rstn)) {
	if (gpio_is_valid(pdata->rstn)) {
		rc = gpio_request(pdata->rstn, "rstn");
		rc = devm_gpio_request_one(&spi->dev, pdata->rstn,
					   GPIOF_OUT_INIT_HIGH, "rstn");
		if (rc)
		if (rc)
			return rc;
			return rc;
	}
	}


	if (gpio_is_valid(pdata->slp_tr)) {
	if (gpio_is_valid(pdata->slp_tr)) {
		rc = gpio_request(pdata->slp_tr, "slp_tr");
		rc = devm_gpio_request_one(&spi->dev, pdata->slp_tr,
					   GPIOF_OUT_INIT_LOW, "slp_tr");
		if (rc)
		if (rc)
			goto err_slp_tr;
			return rc;
	}

	if (gpio_is_valid(pdata->rstn)) {
		rc = gpio_direction_output(pdata->rstn, 1);
		if (rc)
			goto err_gpio_dir;
	}

	if (gpio_is_valid(pdata->slp_tr)) {
		rc = gpio_direction_output(pdata->slp_tr, 0);
		if (rc)
			goto err_gpio_dir;
	}
	}


	/* Reset */
	/* Reset */
@@ -1108,13 +1098,12 @@ static int at86rf230_probe(struct spi_device *spi)


	rc = __at86rf230_detect_device(spi, &man_id, &part, &version);
	rc = __at86rf230_detect_device(spi, &man_id, &part, &version);
	if (rc < 0)
	if (rc < 0)
		goto err_gpio_dir;
		return rc;


	if (man_id != 0x001f) {
	if (man_id != 0x001f) {
		dev_err(&spi->dev, "Non-Atmel dev found (MAN_ID %02x %02x)\n",
		dev_err(&spi->dev, "Non-Atmel dev found (MAN_ID %02x %02x)\n",
			man_id >> 8, man_id & 0xFF);
			man_id >> 8, man_id & 0xFF);
		rc = -EINVAL;
		return -EINVAL;
		goto err_gpio_dir;
	}
	}


	switch (part) {
	switch (part) {
@@ -1141,16 +1130,12 @@ static int at86rf230_probe(struct spi_device *spi)
	}
	}


	dev_info(&spi->dev, "Detected %s chip version %d\n", chip, version);
	dev_info(&spi->dev, "Detected %s chip version %d\n", chip, version);
	if (!ops) {
	if (!ops)
		rc = -ENOTSUPP;
		return -ENOTSUPP;
		goto err_gpio_dir;
	}


	dev = ieee802154_alloc_device(sizeof(*lp), ops);
	dev = ieee802154_alloc_device(sizeof(*lp), ops);
	if (!dev) {
	if (!dev)
		rc = -ENOMEM;
		return -ENOMEM;
		goto err_gpio_dir;
	}


	lp = dev->priv;
	lp = dev->priv;
	lp->dev = dev;
	lp->dev = dev;
@@ -1212,35 +1197,21 @@ static int at86rf230_probe(struct spi_device *spi)
	mutex_destroy(&lp->bmux);
	mutex_destroy(&lp->bmux);
	ieee802154_free_device(lp->dev);
	ieee802154_free_device(lp->dev);


err_gpio_dir:
	if (gpio_is_valid(pdata->slp_tr))
		gpio_free(pdata->slp_tr);
err_slp_tr:
	if (gpio_is_valid(pdata->rstn))
		gpio_free(pdata->rstn);
	return rc;
	return rc;
}
}


static int at86rf230_remove(struct spi_device *spi)
static int at86rf230_remove(struct spi_device *spi)
{
{
	struct at86rf230_local *lp = spi_get_drvdata(spi);
	struct at86rf230_local *lp = spi_get_drvdata(spi);
	struct at86rf230_platform_data *pdata = spi->dev.platform_data;


	/* mask all at86rf230 irq's */
	/* mask all at86rf230 irq's */
	at86rf230_write_subreg(lp, SR_IRQ_MASK, 0);
	at86rf230_write_subreg(lp, SR_IRQ_MASK, 0);
	ieee802154_unregister_device(lp->dev);
	ieee802154_unregister_device(lp->dev);

	flush_work(&lp->irqwork);
	flush_work(&lp->irqwork);

	if (gpio_is_valid(pdata->slp_tr))
		gpio_free(pdata->slp_tr);
	if (gpio_is_valid(pdata->rstn))
		gpio_free(pdata->rstn);

	mutex_destroy(&lp->bmux);
	mutex_destroy(&lp->bmux);
	ieee802154_free_device(lp->dev);
	ieee802154_free_device(lp->dev);

	dev_dbg(&spi->dev, "unregistered at86rf230\n");
	dev_dbg(&spi->dev, "unregistered at86rf230\n");

	return 0;
	return 0;
}
}