Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 2 | /* |
| 3 | * drivers/ata/pata_palmld.c |
| 4 | * |
| 5 | * Driver for IDE channel in Palm LifeDrive |
| 6 | * |
| 7 | * Based on research of: |
| 8 | * Alex Osborne <ato@meshy.org> |
| 9 | * |
| 10 | * Rewrite for mainline: |
| 11 | * Marek Vasut <marek.vasut@gmail.com> |
| 12 | * |
| 13 | * Rewritten version based on pata_ixp4xx_cf.c: |
| 14 | * ixp4xx PATA/Compact Flash driver |
| 15 | * Copyright (C) 2006-07 Tower Technologies |
| 16 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/libata.h> |
| 22 | #include <linux/irq.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/delay.h> |
Linus Walleij | f43e4b0 | 2018-11-13 14:01:02 +0100 | [diff] [blame] | 25 | #include <linux/gpio/consumer.h> |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 26 | |
| 27 | #include <scsi/scsi_host.h> |
| 28 | #include <mach/palmld.h> |
| 29 | |
| 30 | #define DRV_NAME "pata_palmld" |
| 31 | |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 32 | struct palmld_pata { |
| 33 | struct ata_host *host; |
| 34 | struct gpio_desc *power; |
| 35 | struct gpio_desc *reset; |
| 36 | }; |
Marek Vasut | 6b1e3fc | 2011-01-15 19:19:05 +0100 | [diff] [blame] | 37 | |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 38 | static struct scsi_host_template palmld_sht = { |
| 39 | ATA_PIO_SHT(DRV_NAME), |
| 40 | }; |
| 41 | |
| 42 | static struct ata_port_operations palmld_port_ops = { |
| 43 | .inherits = &ata_sff_port_ops, |
Sebastian Andrzej Siewior | 23ebda2 | 2018-07-11 17:21:05 +0200 | [diff] [blame] | 44 | .sff_data_xfer = ata_sff_data_xfer32, |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 45 | .cable_detect = ata_cable_40wire, |
| 46 | }; |
| 47 | |
Greg Kroah-Hartman | 0ec2491 | 2012-12-21 13:19:58 -0800 | [diff] [blame] | 48 | static int palmld_pata_probe(struct platform_device *pdev) |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 49 | { |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 50 | struct palmld_pata *lda; |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 51 | struct ata_port *ap; |
| 52 | void __iomem *mem; |
Linus Walleij | f43e4b0 | 2018-11-13 14:01:02 +0100 | [diff] [blame] | 53 | struct device *dev = &pdev->dev; |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 54 | int ret; |
| 55 | |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 56 | lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL); |
| 57 | if (!lda) |
| 58 | return -ENOMEM; |
| 59 | |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 60 | /* allocate host */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 61 | lda->host = ata_host_alloc(dev, 1); |
| 62 | if (!lda->host) |
Linus Walleij | f43e4b0 | 2018-11-13 14:01:02 +0100 | [diff] [blame] | 63 | return -ENOMEM; |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 64 | |
| 65 | /* remap drive's physical memory address */ |
Linus Walleij | f43e4b0 | 2018-11-13 14:01:02 +0100 | [diff] [blame] | 66 | mem = devm_ioremap(dev, PALMLD_IDE_PHYS, 0x1000); |
| 67 | if (!mem) |
| 68 | return -ENOMEM; |
| 69 | |
| 70 | /* request and activate power and reset GPIOs */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 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); |
Marek Vasut | 6b1e3fc | 2011-01-15 19:19:05 +0100 | [diff] [blame] | 78 | } |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 79 | |
Linus Walleij | f43e4b0 | 2018-11-13 14:01:02 +0100 | [diff] [blame] | 80 | /* Assert reset to reset the drive */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 81 | gpiod_set_value(lda->reset, 1); |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 82 | msleep(30); |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 83 | gpiod_set_value(lda->reset, 0); |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 84 | msleep(30); |
| 85 | |
| 86 | /* setup the ata port */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 87 | ap = lda->host->ports[0]; |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 88 | ap->ops = &palmld_port_ops; |
| 89 | ap->pio_mask = ATA_PIO4; |
Sergei Shtylyov | 9cbe056 | 2011-02-04 22:05:48 +0300 | [diff] [blame] | 90 | ap->flags |= ATA_FLAG_PIO_POLLING; |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 91 | |
| 92 | /* memory mapping voodoo */ |
| 93 | ap->ioaddr.cmd_addr = mem + 0x10; |
| 94 | ap->ioaddr.altstatus_addr = mem + 0xe; |
| 95 | ap->ioaddr.ctl_addr = mem + 0xe; |
| 96 | |
| 97 | /* start the port */ |
| 98 | ata_sff_std_ports(&ap->ioaddr); |
| 99 | |
| 100 | /* activate host */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 101 | ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING, |
| 102 | &palmld_sht); |
Linus Walleij | f43e4b0 | 2018-11-13 14:01:02 +0100 | [diff] [blame] | 103 | /* power down on failure */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 104 | if (ret) { |
| 105 | gpiod_set_value(lda->power, 0); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | platform_set_drvdata(pdev, lda); |
| 110 | return 0; |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 113 | static int palmld_pata_remove(struct platform_device *pdev) |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 114 | { |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 115 | struct palmld_pata *lda = platform_get_drvdata(pdev); |
| 116 | |
| 117 | ata_platform_remove_one(pdev); |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 118 | |
| 119 | /* power down the HDD */ |
Linus Walleij | 614c61a | 2018-12-05 09:49:11 +0100 | [diff] [blame] | 120 | gpiod_set_value(lda->power, 0); |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static struct platform_driver palmld_pata_platform_driver = { |
| 126 | .driver = { |
| 127 | .name = DRV_NAME, |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 128 | }, |
| 129 | .probe = palmld_pata_probe, |
Greg Kroah-Hartman | 0ec2491 | 2012-12-21 13:19:58 -0800 | [diff] [blame] | 130 | .remove = palmld_pata_remove, |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 131 | }; |
| 132 | |
Axel Lin | 99c8ea3 | 2011-11-27 14:44:26 +0800 | [diff] [blame] | 133 | module_platform_driver(palmld_pata_platform_driver); |
Marek Vašut | 5a9d251 | 2009-05-21 13:11:05 +0100 | [diff] [blame] | 134 | |
| 135 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); |
| 136 | MODULE_DESCRIPTION("PalmLD PATA driver"); |
| 137 | MODULE_LICENSE("GPL"); |
| 138 | MODULE_ALIAS("platform:" DRV_NAME); |