summaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2018-12-05 09:49:11 +0100
committerJens Axboe <axboe@kernel.dk>2018-12-05 06:01:14 -0700
commit614c61a6514e05a4bb0cd8989159f986da132215 (patch)
treec1faf2f450332927360ddd1b77b7ebb5768d9f70 /drivers/ata
parentf43e4b007a943b00a7562025ed036a9c1ee2950f (diff)
downloadlinux-614c61a6514e05a4bb0cd8989159f986da132215.tar.bz2
ata: palmld: Introduce state container
This creates a state container struct for the Palm LifeDrive ATA controller, and puts the ATA host and the two GPIO descriptors into this container. This avoids using a singleton so potentially multiple PATA interfaces can be instantiated. Suggested-by: Marek Vasut <marek.vasut@gmail.com> Reviewed-by: Marek Vasut <marek.vasut@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/pata_palmld.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c
index e2933c324d41..26817fd91700 100644
--- a/drivers/ata/pata_palmld.c
+++ b/drivers/ata/pata_palmld.c
@@ -33,7 +33,11 @@
#define DRV_NAME "pata_palmld"
-static struct gpio_desc *palmld_pata_power;
+struct palmld_pata {
+ struct ata_host *host;
+ struct gpio_desc *power;
+ struct gpio_desc *reset;
+};
static struct scsi_host_template palmld_sht = {
ATA_PIO_SHT(DRV_NAME),
@@ -47,16 +51,19 @@ static struct ata_port_operations palmld_port_ops = {
static int palmld_pata_probe(struct platform_device *pdev)
{
- struct ata_host *host;
+ struct palmld_pata *lda;
struct ata_port *ap;
void __iomem *mem;
struct device *dev = &pdev->dev;
- struct gpio_desc *reset;
int ret;
+ lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL);
+ if (!lda)
+ return -ENOMEM;
+
/* allocate host */
- host = ata_host_alloc(dev, 1);
- if (!host)
+ lda->host = ata_host_alloc(dev, 1);
+ if (!lda->host)
return -ENOMEM;
/* remap drive's physical memory address */
@@ -65,23 +72,23 @@ static int palmld_pata_probe(struct platform_device *pdev)
return -ENOMEM;
/* request and activate power and reset GPIOs */
- palmld_pata_power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
- if (IS_ERR(palmld_pata_power))
- return PTR_ERR(palmld_pata_power);
- reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
- if (IS_ERR(reset)) {
- gpiod_set_value(palmld_pata_power, 0);
- return PTR_ERR(reset);
+ lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
+ if (IS_ERR(lda->power))
+ return PTR_ERR(lda->power);
+ lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(lda->reset)) {
+ gpiod_set_value(lda->power, 0);
+ return PTR_ERR(lda->reset);
}
/* Assert reset to reset the drive */
- gpiod_set_value(reset, 1);
+ gpiod_set_value(lda->reset, 1);
msleep(30);
- gpiod_set_value(reset, 0);
+ gpiod_set_value(lda->reset, 0);
msleep(30);
/* setup the ata port */
- ap = host->ports[0];
+ ap = lda->host->ports[0];
ap->ops = &palmld_port_ops;
ap->pio_mask = ATA_PIO4;
ap->flags |= ATA_FLAG_PIO_POLLING;
@@ -95,20 +102,26 @@ static int palmld_pata_probe(struct platform_device *pdev)
ata_sff_std_ports(&ap->ioaddr);
/* activate host */
- ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING,
- &palmld_sht);
+ ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING,
+ &palmld_sht);
/* power down on failure */
- if (ret)
- gpiod_set_value(palmld_pata_power, 0);
- return ret;
+ if (ret) {
+ gpiod_set_value(lda->power, 0);
+ return ret;
+ }
+
+ platform_set_drvdata(pdev, lda);
+ return 0;
}
-static int palmld_pata_remove(struct platform_device *dev)
+static int palmld_pata_remove(struct platform_device *pdev)
{
- ata_platform_remove_one(dev);
+ struct palmld_pata *lda = platform_get_drvdata(pdev);
+
+ ata_platform_remove_one(pdev);
/* power down the HDD */
- gpiod_set_value(palmld_pata_power, 0);
+ gpiod_set_value(lda->power, 0);
return 0;
}