blob: df2bb7504fc8e073650c271dd147d4d75cbf26a5 [file] [log] [blame]
Marek Vašut5a9d2512009-05-21 13:11:05 +01001/*
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>
29#include <linux/gpio.h>
30
31#include <scsi/scsi_host.h>
32#include <mach/palmld.h>
33
34#define DRV_NAME "pata_palmld"
35
Marek Vasut6b1e3fc2011-01-15 19:19:05 +010036static 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" },
39};
40
Marek Vašut5a9d2512009-05-21 13:11:05 +010041static struct scsi_host_template palmld_sht = {
42 ATA_PIO_SHT(DRV_NAME),
43};
44
45static struct ata_port_operations palmld_port_ops = {
46 .inherits = &ata_sff_port_ops,
47 .sff_data_xfer = ata_sff_data_xfer_noirq,
48 .cable_detect = ata_cable_40wire,
49};
50
Greg Kroah-Hartman0ec24912012-12-21 13:19:58 -080051static int palmld_pata_probe(struct platform_device *pdev)
Marek Vašut5a9d2512009-05-21 13:11:05 +010052{
53 struct ata_host *host;
54 struct ata_port *ap;
55 void __iomem *mem;
56 int ret;
57
58 /* allocate host */
59 host = ata_host_alloc(&pdev->dev, 1);
Marek Vasut6b1e3fc2011-01-15 19:19:05 +010060 if (!host) {
61 ret = -ENOMEM;
62 goto err1;
63 }
Marek Vašut5a9d2512009-05-21 13:11:05 +010064
65 /* remap drive's physical memory address */
66 mem = devm_ioremap(&pdev->dev, PALMLD_IDE_PHYS, 0x1000);
Marek Vasut6b1e3fc2011-01-15 19:19:05 +010067 if (!mem) {
68 ret = -ENOMEM;
69 goto err1;
70 }
Marek Vašut5a9d2512009-05-21 13:11:05 +010071
72 /* request and activate power GPIO, IRQ GPIO */
Marek Vasut6b1e3fc2011-01-15 19:19:05 +010073 ret = gpio_request_array(palmld_hdd_gpios,
74 ARRAY_SIZE(palmld_hdd_gpios));
Marek Vašut5a9d2512009-05-21 13:11:05 +010075 if (ret)
76 goto err1;
Marek Vašut5a9d2512009-05-21 13:11:05 +010077
78 /* reset the drive */
79 gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 0);
80 msleep(30);
81 gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 1);
82 msleep(30);
83
84 /* setup the ata port */
85 ap = host->ports[0];
86 ap->ops = &palmld_port_ops;
87 ap->pio_mask = ATA_PIO4;
Sergei Shtylyov9cbe0562011-02-04 22:05:48 +030088 ap->flags |= ATA_FLAG_PIO_POLLING;
Marek Vašut5a9d2512009-05-21 13:11:05 +010089
90 /* memory mapping voodoo */
91 ap->ioaddr.cmd_addr = mem + 0x10;
92 ap->ioaddr.altstatus_addr = mem + 0xe;
93 ap->ioaddr.ctl_addr = mem + 0xe;
94
95 /* start the port */
96 ata_sff_std_ports(&ap->ioaddr);
97
98 /* activate host */
Marek Vasut6b1e3fc2011-01-15 19:19:05 +010099 ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING,
Marek Vašut5a9d2512009-05-21 13:11:05 +0100100 &palmld_sht);
Marek Vasut6b1e3fc2011-01-15 19:19:05 +0100101 if (ret)
102 goto err2;
Marek Vašut5a9d2512009-05-21 13:11:05 +0100103
Marek Vasut6b1e3fc2011-01-15 19:19:05 +0100104 return ret;
105
Marek Vašut5a9d2512009-05-21 13:11:05 +0100106err2:
Marek Vasut6b1e3fc2011-01-15 19:19:05 +0100107 gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
Marek Vašut5a9d2512009-05-21 13:11:05 +0100108err1:
109 return ret;
110}
111
Greg Kroah-Hartman0ec24912012-12-21 13:19:58 -0800112static int palmld_pata_remove(struct platform_device *dev)
Marek Vašut5a9d2512009-05-21 13:11:05 +0100113{
Brian Norris56c1d3b2012-11-02 00:46:25 -0700114 ata_platform_remove_one(dev);
Marek Vašut5a9d2512009-05-21 13:11:05 +0100115
116 /* power down the HDD */
117 gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0);
118
Marek Vasut6b1e3fc2011-01-15 19:19:05 +0100119 gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
Marek Vašut5a9d2512009-05-21 13:11:05 +0100120
121 return 0;
122}
123
124static struct platform_driver palmld_pata_platform_driver = {
125 .driver = {
126 .name = DRV_NAME,
127 .owner = THIS_MODULE,
128 },
129 .probe = palmld_pata_probe,
Greg Kroah-Hartman0ec24912012-12-21 13:19:58 -0800130 .remove = palmld_pata_remove,
Marek Vašut5a9d2512009-05-21 13:11:05 +0100131};
132
Axel Lin99c8ea32011-11-27 14:44:26 +0800133module_platform_driver(palmld_pata_platform_driver);
Marek Vašut5a9d2512009-05-21 13:11:05 +0100134
135MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
136MODULE_DESCRIPTION("PalmLD PATA driver");
137MODULE_LICENSE("GPL");
138MODULE_ALIAS("platform:" DRV_NAME);