Commit 614c61a6 authored by Linus Walleij's avatar Linus Walleij Committed by Jens Axboe

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: default avatarMarek Vasut <marek.vasut@gmail.com>
Reviewed-by: default avatarMarek Vasut <marek.vasut@gmail.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f43e4b00
...@@ -33,7 +33,11 @@ ...@@ -33,7 +33,11 @@
#define DRV_NAME "pata_palmld" #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 = { static struct scsi_host_template palmld_sht = {
ATA_PIO_SHT(DRV_NAME), ATA_PIO_SHT(DRV_NAME),
...@@ -47,16 +51,19 @@ static struct ata_port_operations palmld_port_ops = { ...@@ -47,16 +51,19 @@ static struct ata_port_operations palmld_port_ops = {
static int palmld_pata_probe(struct platform_device *pdev) static int palmld_pata_probe(struct platform_device *pdev)
{ {
struct ata_host *host; struct palmld_pata *lda;
struct ata_port *ap; struct ata_port *ap;
void __iomem *mem; void __iomem *mem;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct gpio_desc *reset;
int ret; int ret;
lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL);
if (!lda)
return -ENOMEM;
/* allocate host */ /* allocate host */
host = ata_host_alloc(dev, 1); lda->host = ata_host_alloc(dev, 1);
if (!host) if (!lda->host)
return -ENOMEM; return -ENOMEM;
/* remap drive's physical memory address */ /* remap drive's physical memory address */
...@@ -65,23 +72,23 @@ static int palmld_pata_probe(struct platform_device *pdev) ...@@ -65,23 +72,23 @@ static int palmld_pata_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
/* request and activate power and reset GPIOs */ /* request and activate power and reset GPIOs */
palmld_pata_power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
if (IS_ERR(palmld_pata_power)) if (IS_ERR(lda->power))
return PTR_ERR(palmld_pata_power); return PTR_ERR(lda->power);
reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(reset)) { if (IS_ERR(lda->reset)) {
gpiod_set_value(palmld_pata_power, 0); gpiod_set_value(lda->power, 0);
return PTR_ERR(reset); return PTR_ERR(lda->reset);
} }
/* Assert reset to reset the drive */ /* Assert reset to reset the drive */
gpiod_set_value(reset, 1); gpiod_set_value(lda->reset, 1);
msleep(30); msleep(30);
gpiod_set_value(reset, 0); gpiod_set_value(lda->reset, 0);
msleep(30); msleep(30);
/* setup the ata port */ /* setup the ata port */
ap = host->ports[0]; ap = lda->host->ports[0];
ap->ops = &palmld_port_ops; ap->ops = &palmld_port_ops;
ap->pio_mask = ATA_PIO4; ap->pio_mask = ATA_PIO4;
ap->flags |= ATA_FLAG_PIO_POLLING; ap->flags |= ATA_FLAG_PIO_POLLING;
...@@ -95,20 +102,26 @@ static int palmld_pata_probe(struct platform_device *pdev) ...@@ -95,20 +102,26 @@ static int palmld_pata_probe(struct platform_device *pdev)
ata_sff_std_ports(&ap->ioaddr); ata_sff_std_ports(&ap->ioaddr);
/* activate host */ /* activate host */
ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING, ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING,
&palmld_sht); &palmld_sht);
/* power down on failure */ /* power down on failure */
if (ret) if (ret) {
gpiod_set_value(palmld_pata_power, 0); gpiod_set_value(lda->power, 0);
return ret; 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 */ /* power down the HDD */
gpiod_set_value(palmld_pata_power, 0); gpiod_set_value(lda->power, 0);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment