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>
This commit is contained in:
Linus Walleij 2018-12-05 09:49:11 +01:00 committed by Jens Axboe
parent f43e4b007a
commit 614c61a651

View File

@ -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;
}