Commit | Line | Data |
---|---|---|
5a9d2515 MV |
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> | |
f43e4b00 | 29 | #include <linux/gpio/consumer.h> |
5a9d2515 MV |
30 | |
31 | #include <scsi/scsi_host.h> | |
32 | #include <mach/palmld.h> | |
33 | ||
34 | #define DRV_NAME "pata_palmld" | |
35 | ||
f43e4b00 | 36 | static struct gpio_desc *palmld_pata_power; |
6b1e3fca | 37 | |
5a9d2515 MV |
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, | |
23ebda2f | 44 | .sff_data_xfer = ata_sff_data_xfer32, |
5a9d2515 MV |
45 | .cable_detect = ata_cable_40wire, |
46 | }; | |
47 | ||
0ec24914 | 48 | static int palmld_pata_probe(struct platform_device *pdev) |
5a9d2515 MV |
49 | { |
50 | struct ata_host *host; | |
51 | struct ata_port *ap; | |
52 | void __iomem *mem; | |
f43e4b00 LW |
53 | struct device *dev = &pdev->dev; |
54 | struct gpio_desc *reset; | |
5a9d2515 MV |
55 | int ret; |
56 | ||
57 | /* allocate host */ | |
f43e4b00 LW |
58 | host = ata_host_alloc(dev, 1); |
59 | if (!host) | |
60 | return -ENOMEM; | |
5a9d2515 MV |
61 | |
62 | /* remap drive's physical memory address */ | |
f43e4b00 LW |
63 | mem = devm_ioremap(dev, PALMLD_IDE_PHYS, 0x1000); |
64 | if (!mem) | |
65 | return -ENOMEM; | |
66 | ||
67 | /* request and activate power and reset GPIOs */ | |
68 | palmld_pata_power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH); | |
69 | if (IS_ERR(palmld_pata_power)) | |
70 | return PTR_ERR(palmld_pata_power); | |
71 | reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); | |
72 | if (IS_ERR(reset)) { | |
73 | gpiod_set_value(palmld_pata_power, 0); | |
74 | return PTR_ERR(reset); | |
6b1e3fca | 75 | } |
5a9d2515 | 76 | |
f43e4b00 LW |
77 | /* Assert reset to reset the drive */ |
78 | gpiod_set_value(reset, 1); | |
5a9d2515 | 79 | msleep(30); |
f43e4b00 | 80 | gpiod_set_value(reset, 0); |
5a9d2515 MV |
81 | msleep(30); |
82 | ||
83 | /* setup the ata port */ | |
84 | ap = host->ports[0]; | |
85 | ap->ops = &palmld_port_ops; | |
86 | ap->pio_mask = ATA_PIO4; | |
9cbe056f | 87 | ap->flags |= ATA_FLAG_PIO_POLLING; |
5a9d2515 MV |
88 | |
89 | /* memory mapping voodoo */ | |
90 | ap->ioaddr.cmd_addr = mem + 0x10; | |
91 | ap->ioaddr.altstatus_addr = mem + 0xe; | |
92 | ap->ioaddr.ctl_addr = mem + 0xe; | |
93 | ||
94 | /* start the port */ | |
95 | ata_sff_std_ports(&ap->ioaddr); | |
96 | ||
97 | /* activate host */ | |
6b1e3fca | 98 | ret = ata_host_activate(host, 0, NULL, IRQF_TRIGGER_RISING, |
5a9d2515 | 99 | &palmld_sht); |
f43e4b00 | 100 | /* power down on failure */ |
6b1e3fca | 101 | if (ret) |
f43e4b00 | 102 | gpiod_set_value(palmld_pata_power, 0); |
5a9d2515 MV |
103 | return ret; |
104 | } | |
105 | ||
0ec24914 | 106 | static int palmld_pata_remove(struct platform_device *dev) |
5a9d2515 | 107 | { |
56c1d3b7 | 108 | ata_platform_remove_one(dev); |
5a9d2515 MV |
109 | |
110 | /* power down the HDD */ | |
f43e4b00 | 111 | gpiod_set_value(palmld_pata_power, 0); |
5a9d2515 MV |
112 | |
113 | return 0; | |
114 | } | |
115 | ||
116 | static struct platform_driver palmld_pata_platform_driver = { | |
117 | .driver = { | |
118 | .name = DRV_NAME, | |
5a9d2515 MV |
119 | }, |
120 | .probe = palmld_pata_probe, | |
0ec24914 | 121 | .remove = palmld_pata_remove, |
5a9d2515 MV |
122 | }; |
123 | ||
99c8ea3e | 124 | module_platform_driver(palmld_pata_platform_driver); |
5a9d2515 MV |
125 | |
126 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); | |
127 | MODULE_DESCRIPTION("PalmLD PATA driver"); | |
128 | MODULE_LICENSE("GPL"); | |
129 | MODULE_ALIAS("platform:" DRV_NAME); |