| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * drivers/ata/pata_palmld.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 13 | 14 | * ixp4xx PATA/Compact Flash driver |
|---|
| 14 | 15 | * Copyright (C) 2006-07 Tower Technologies |
|---|
| 15 | 16 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
|---|
| 16 | | - * |
|---|
| 17 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 18 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 19 | | - * published by the Free Software Foundation. |
|---|
| 20 | | - * |
|---|
| 21 | 17 | */ |
|---|
| 22 | 18 | |
|---|
| 23 | 19 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 26 | 22 | #include <linux/irq.h> |
|---|
| 27 | 23 | #include <linux/platform_device.h> |
|---|
| 28 | 24 | #include <linux/delay.h> |
|---|
| 29 | | -#include <linux/gpio.h> |
|---|
| 25 | +#include <linux/gpio/consumer.h> |
|---|
| 30 | 26 | |
|---|
| 31 | 27 | #include <scsi/scsi_host.h> |
|---|
| 32 | 28 | #include <mach/palmld.h> |
|---|
| 33 | 29 | |
|---|
| 34 | 30 | #define DRV_NAME "pata_palmld" |
|---|
| 35 | 31 | |
|---|
| 36 | | -static struct gpio palmld_hdd_gpios[] = { |
|---|
| 37 | | - { GPIO_NR_PALMLD_IDE_PWEN, GPIOF_INIT_HIGH, "HDD Power" }, |
|---|
| 38 | | - { GPIO_NR_PALMLD_IDE_RESET, GPIOF_INIT_LOW, "HDD Reset" }, |
|---|
| 32 | +struct palmld_pata { |
|---|
| 33 | + struct ata_host *host; |
|---|
| 34 | + struct gpio_desc *power; |
|---|
| 35 | + struct gpio_desc *reset; |
|---|
| 39 | 36 | }; |
|---|
| 40 | 37 | |
|---|
| 41 | 38 | static struct scsi_host_template palmld_sht = { |
|---|
| .. | .. |
|---|
| 50 | 47 | |
|---|
| 51 | 48 | static int palmld_pata_probe(struct platform_device *pdev) |
|---|
| 52 | 49 | { |
|---|
| 53 | | - struct ata_host *host; |
|---|
| 50 | + struct palmld_pata *lda; |
|---|
| 54 | 51 | struct ata_port *ap; |
|---|
| 55 | 52 | void __iomem *mem; |
|---|
| 53 | + struct device *dev = &pdev->dev; |
|---|
| 56 | 54 | int ret; |
|---|
| 57 | 55 | |
|---|
| 56 | + lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL); |
|---|
| 57 | + if (!lda) |
|---|
| 58 | + return -ENOMEM; |
|---|
| 59 | + |
|---|
| 58 | 60 | /* allocate host */ |
|---|
| 59 | | - host = ata_host_alloc(&pdev->dev, 1); |
|---|
| 60 | | - if (!host) { |
|---|
| 61 | | - ret = -ENOMEM; |
|---|
| 62 | | - goto err1; |
|---|
| 63 | | - } |
|---|
| 61 | + lda->host = ata_host_alloc(dev, 1); |
|---|
| 62 | + if (!lda->host) |
|---|
| 63 | + return -ENOMEM; |
|---|
| 64 | 64 | |
|---|
| 65 | 65 | /* remap drive's physical memory address */ |
|---|
| 66 | | - mem = devm_ioremap(&pdev->dev, PALMLD_IDE_PHYS, 0x1000); |
|---|
| 67 | | - if (!mem) { |
|---|
| 68 | | - ret = -ENOMEM; |
|---|
| 69 | | - goto err1; |
|---|
| 66 | + mem = devm_ioremap(dev, PALMLD_IDE_PHYS, 0x1000); |
|---|
| 67 | + if (!mem) |
|---|
| 68 | + return -ENOMEM; |
|---|
| 69 | + |
|---|
| 70 | + /* request and activate power and reset GPIOs */ |
|---|
| 71 | + lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); |
|---|
| 72 | + if (IS_ERR(lda->power)) |
|---|
| 73 | + return PTR_ERR(lda->power); |
|---|
| 74 | + lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); |
|---|
| 75 | + if (IS_ERR(lda->reset)) { |
|---|
| 76 | + gpiod_set_value(lda->power, 0); |
|---|
| 77 | + return PTR_ERR(lda->reset); |
|---|
| 70 | 78 | } |
|---|
| 71 | 79 | |
|---|
| 72 | | - /* request and activate power GPIO, IRQ GPIO */ |
|---|
| 73 | | - ret = gpio_request_array(palmld_hdd_gpios, |
|---|
| 74 | | - ARRAY_SIZE(palmld_hdd_gpios)); |
|---|
| 75 | | - if (ret) |
|---|
| 76 | | - goto err1; |
|---|
| 77 | | - |
|---|
| 78 | | - /* reset the drive */ |
|---|
| 79 | | - gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 0); |
|---|
| 80 | + /* Assert reset to reset the drive */ |
|---|
| 81 | + gpiod_set_value(lda->reset, 1); |
|---|
| 80 | 82 | msleep(30); |
|---|
| 81 | | - gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 1); |
|---|
| 83 | + gpiod_set_value(lda->reset, 0); |
|---|
| 82 | 84 | msleep(30); |
|---|
| 83 | 85 | |
|---|
| 84 | 86 | /* setup the ata port */ |
|---|
| 85 | | - ap = host->ports[0]; |
|---|
| 87 | + ap = lda->host->ports[0]; |
|---|
| 86 | 88 | ap->ops = &palmld_port_ops; |
|---|
| 87 | 89 | ap->pio_mask = ATA_PIO4; |
|---|
| 88 | 90 | ap->flags |= ATA_FLAG_PIO_POLLING; |
|---|
| .. | .. |
|---|
| 96 | 98 | ata_sff_std_ports(&ap->ioaddr); |
|---|
| 97 | 99 | |
|---|
| 98 | 100 | /* activate host */ |
|---|
| 99 | | - ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING, |
|---|
| 100 | | - &palmld_sht); |
|---|
| 101 | | - if (ret) |
|---|
| 102 | | - goto err2; |
|---|
| 101 | + ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING, |
|---|
| 102 | + &palmld_sht); |
|---|
| 103 | + /* power down on failure */ |
|---|
| 104 | + if (ret) { |
|---|
| 105 | + gpiod_set_value(lda->power, 0); |
|---|
| 106 | + return ret; |
|---|
| 107 | + } |
|---|
| 103 | 108 | |
|---|
| 104 | | - return ret; |
|---|
| 105 | | - |
|---|
| 106 | | -err2: |
|---|
| 107 | | - gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios)); |
|---|
| 108 | | -err1: |
|---|
| 109 | | - return ret; |
|---|
| 109 | + platform_set_drvdata(pdev, lda); |
|---|
| 110 | + return 0; |
|---|
| 110 | 111 | } |
|---|
| 111 | 112 | |
|---|
| 112 | | -static int palmld_pata_remove(struct platform_device *dev) |
|---|
| 113 | +static int palmld_pata_remove(struct platform_device *pdev) |
|---|
| 113 | 114 | { |
|---|
| 114 | | - ata_platform_remove_one(dev); |
|---|
| 115 | + struct palmld_pata *lda = platform_get_drvdata(pdev); |
|---|
| 116 | + |
|---|
| 117 | + ata_platform_remove_one(pdev); |
|---|
| 115 | 118 | |
|---|
| 116 | 119 | /* power down the HDD */ |
|---|
| 117 | | - gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0); |
|---|
| 118 | | - |
|---|
| 119 | | - gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios)); |
|---|
| 120 | + gpiod_set_value(lda->power, 0); |
|---|
| 120 | 121 | |
|---|
| 121 | 122 | return 0; |
|---|
| 122 | 123 | } |
|---|