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