Blame view

drivers/ata/pata_marvell.c 4.43 KB
75742cb41   Alan Cox   [PATCH] pata_marv...
1
2
3
4
5
6
7
  /*
   *	Marvell PATA driver.
   *
   *	For the moment we drive the PATA port in legacy mode. That
   *	isn't making full use of the device functionality but it is
   *	easy to get working.
   *
ab7716300   Alan Cox   ata: Switch all m...
8
   *	(c) 2006 Red Hat
75742cb41   Alan Cox   [PATCH] pata_marv...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
   */
  
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/pci.h>
  #include <linux/init.h>
  #include <linux/blkdev.h>
  #include <linux/delay.h>
  #include <linux/device.h>
  #include <scsi/scsi_host.h>
  #include <linux/libata.h>
  #include <linux/ata.h>
  
  #define DRV_NAME	"pata_marvell"
5b66c829b   Alan Cox   ahci, pata_marvel...
23
  #define DRV_VERSION	"0.1.6"
75742cb41   Alan Cox   [PATCH] pata_marv...
24
25
  
  /**
5b66c829b   Alan Cox   ahci, pata_marvel...
26
27
   *	marvell_pata_active	-	check if PATA is active
   *	@pdev: PCI device
75742cb41   Alan Cox   [PATCH] pata_marv...
28
   *
5b66c829b   Alan Cox   ahci, pata_marvel...
29
30
   *	Returns 1 if the PATA port may be active. We know how to check this
   *	for the 6145 but not the other devices
75742cb41   Alan Cox   [PATCH] pata_marv...
31
   */
5b66c829b   Alan Cox   ahci, pata_marvel...
32
  static int marvell_pata_active(struct pci_dev *pdev)
75742cb41   Alan Cox   [PATCH] pata_marv...
33
  {
5b66c829b   Alan Cox   ahci, pata_marvel...
34
  	int i;
75742cb41   Alan Cox   [PATCH] pata_marv...
35
  	u32 devices;
75742cb41   Alan Cox   [PATCH] pata_marv...
36
  	void __iomem *barp;
75742cb41   Alan Cox   [PATCH] pata_marv...
37

5b66c829b   Alan Cox   ahci, pata_marvel...
38
39
  	/* We don't yet know how to do this for other devices */
  	if (pdev->device != 0x6145)
4fca377f7   Jeff Garzik   [libata] trivial:...
40
  		return 1;
75742cb41   Alan Cox   [PATCH] pata_marv...
41

6e9d8629b   Jeff Garzik   [libata] pata_mar...
42
  	barp = pci_iomap(pdev, 5, 0x10);
75742cb41   Alan Cox   [PATCH] pata_marv...
43
44
  	if (barp == NULL)
  		return -ENOMEM;
5b66c829b   Alan Cox   ahci, pata_marvel...
45

75742cb41   Alan Cox   [PATCH] pata_marv...
46
47
  	printk("BAR5:");
  	for(i = 0; i <= 0x0F; i++)
90925d305   Jiri Slaby   Ata: pata_marvell...
48
  		printk("%02X:%02X ", i, ioread8(barp + i));
75742cb41   Alan Cox   [PATCH] pata_marv...
49
50
  	printk("
  ");
f20b16ff7   Jeff Garzik   [libata] trim tra...
51

90925d305   Jiri Slaby   Ata: pata_marvell...
52
  	devices = ioread32(barp + 0x0C);
6e9d8629b   Jeff Garzik   [libata] pata_mar...
53
  	pci_iounmap(pdev, barp);
f20b16ff7   Jeff Garzik   [libata] trim tra...
54

5b66c829b   Alan Cox   ahci, pata_marvel...
55
56
57
58
59
60
  	if (devices & 0x10)
  		return 1;
  	return 0;
  }
  
  /**
2a2beac92   Bartlomiej Zolnierkiewicz   pata_marvell: fix...
61
   *	marvell_pre_reset	-	probe begin
5b66c829b   Alan Cox   ahci, pata_marvel...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
   *	@link: link
   *	@deadline: deadline jiffies for the operation
   *
   *	Perform the PATA port setup we need.
   */
  
  static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
  {
  	struct ata_port *ap = link->ap;
  	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  
  	if (pdev->device == 0x6145 && ap->port_no == 0 &&
  		!marvell_pata_active(pdev))	/* PATA enable ? */
  			return -ENOENT;
27c78b372   Jeff Garzik   [libata reset-seq...
76

9363c3825   Tejun Heo   libata: rename SF...
77
  	return ata_sff_prereset(link, deadline);
307c6054a   Alan Cox   pata_marvell: Cab...
78
  }
75742cb41   Alan Cox   [PATCH] pata_marv...
79

307c6054a   Alan Cox   pata_marvell: Cab...
80
81
  static int marvell_cable_detect(struct ata_port *ap)
  {
75742cb41   Alan Cox   [PATCH] pata_marv...
82
83
84
  	/* Cable type */
  	switch(ap->port_no)
  	{
6e9d8629b   Jeff Garzik   [libata] pata_mar...
85
  	case 0:
0d5ff5667   Tejun Heo   libata: convert t...
86
  		if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
307c6054a   Alan Cox   pata_marvell: Cab...
87
88
  			return ATA_CBL_PATA40;
  		return ATA_CBL_PATA80;
6e9d8629b   Jeff Garzik   [libata] pata_mar...
89
  	case 1: /* Legacy SATA port */
307c6054a   Alan Cox   pata_marvell: Cab...
90
  		return ATA_CBL_SATA;
75742cb41   Alan Cox   [PATCH] pata_marv...
91
  	}
d4b2bab4f   Tejun Heo   libata: add deadl...
92

307c6054a   Alan Cox   pata_marvell: Cab...
93
94
  	BUG();
  	return 0;	/* Our BUG macro needs the right markup */
75742cb41   Alan Cox   [PATCH] pata_marv...
95
  }
75742cb41   Alan Cox   [PATCH] pata_marv...
96
97
98
  /* No PIO or DMA methods needed for this device */
  
  static struct scsi_host_template marvell_sht = {
68d1d07b5   Tejun Heo   libata: implement...
99
  	ATA_BMDMA_SHT(DRV_NAME),
75742cb41   Alan Cox   [PATCH] pata_marv...
100
  };
029cfd6b7   Tejun Heo   libata: implement...
101
102
  static struct ata_port_operations marvell_ops = {
  	.inherits		= &ata_bmdma_port_ops,
307c6054a   Alan Cox   pata_marvell: Cab...
103
  	.cable_detect		= marvell_cable_detect,
887125e37   Tejun Heo   libata: stop over...
104
  	.prereset		= marvell_pre_reset,
75742cb41   Alan Cox   [PATCH] pata_marv...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  };
  
  
  /**
   *	marvell_init_one - Register Marvell ATA PCI device with kernel services
   *	@pdev: PCI device to register
   *	@ent: Entry in marvell_pci_tbl matching with @pdev
   *
   *	Called from kernel PCI layer.
   *
   *	LOCKING:
   *	Inherited from PCI layer (may sleep).
   *
   *	RETURNS:
   *	Zero on success, or -ERRNO value.
   */
  
  static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  {
1626aeb88   Tejun Heo   libata: clean up ...
124
  	static const struct ata_port_info info = {
1d2808fd3   Jeff Garzik   [libata] PATA dri...
125
  		.flags		= ATA_FLAG_SLAVE_POSS,
75742cb41   Alan Cox   [PATCH] pata_marv...
126

14bdef982   Erik Inge Bolsø   [libata] convert ...
127
128
  		.pio_mask	= ATA_PIO4,
  		.mwdma_mask	= ATA_MWDMA2,
bf6263a85   Jeff Garzik   [libata] Use ATA_...
129
  		.udma_mask 	= ATA_UDMA5,
75742cb41   Alan Cox   [PATCH] pata_marv...
130
131
132
  
  		.port_ops	= &marvell_ops,
  	};
1626aeb88   Tejun Heo   libata: clean up ...
133
  	static const struct ata_port_info info_sata = {
75742cb41   Alan Cox   [PATCH] pata_marv...
134
  		/* Slave possible as its magically mapped not real */
1d2808fd3   Jeff Garzik   [libata] PATA dri...
135
  		.flags		= ATA_FLAG_SLAVE_POSS,
75742cb41   Alan Cox   [PATCH] pata_marv...
136

14bdef982   Erik Inge Bolsø   [libata] convert ...
137
138
  		.pio_mask	= ATA_PIO4,
  		.mwdma_mask	= ATA_MWDMA2,
bf6263a85   Jeff Garzik   [libata] Use ATA_...
139
  		.udma_mask 	= ATA_UDMA6,
75742cb41   Alan Cox   [PATCH] pata_marv...
140
141
142
  
  		.port_ops	= &marvell_ops,
  	};
1626aeb88   Tejun Heo   libata: clean up ...
143
  	const struct ata_port_info *ppi[] = { &info, &info_sata };
6e9d8629b   Jeff Garzik   [libata] pata_mar...
144

75742cb41   Alan Cox   [PATCH] pata_marv...
145
  	if (pdev->device == 0x6101)
1626aeb88   Tejun Heo   libata: clean up ...
146
  		ppi[1] = &ata_dummy_port_info;
6e9d8629b   Jeff Garzik   [libata] pata_mar...
147

cb6643e1c   Christoph Egger   [libata] pata_mar...
148
  #if defined(CONFIG_SATA_AHCI) || defined(CONFIG_SATA_AHCI_MODULE)
5b66c829b   Alan Cox   ahci, pata_marvel...
149
150
151
152
153
154
  	if (!marvell_pata_active(pdev)) {
  		printk(KERN_INFO DRV_NAME ": PATA port not active, deferring to AHCI driver.
  ");
  		return -ENODEV;
  	}
  #endif
1c5afdf7a   Tejun Heo   libata-sff: separ...
155
  	return ata_pci_bmdma_init_one(pdev, ppi, &marvell_sht, NULL, 0);
75742cb41   Alan Cox   [PATCH] pata_marv...
156
157
158
159
  }
  
  static const struct pci_device_id marvell_pci_tbl[] = {
  	{ PCI_DEVICE(0x11AB, 0x6101), },
d36ee189f   Alan Cox   pata_marvell: Add...
160
161
  	{ PCI_DEVICE(0x11AB, 0x6121), },
  	{ PCI_DEVICE(0x11AB, 0x6123), },
75742cb41   Alan Cox   [PATCH] pata_marv...
162
  	{ PCI_DEVICE(0x11AB, 0x6145), },
f920fe1cb   Paweł Drewniak   pata_marvell: Add...
163
164
  	{ PCI_DEVICE(0x1B4B, 0x91A0), },
  	{ PCI_DEVICE(0x1B4B, 0x91A4), },
75742cb41   Alan Cox   [PATCH] pata_marv...
165
166
167
168
169
170
171
172
  	{ }	/* terminate list */
  };
  
  static struct pci_driver marvell_pci_driver = {
  	.name			= DRV_NAME,
  	.id_table		= marvell_pci_tbl,
  	.probe			= marvell_init_one,
  	.remove			= ata_pci_remove_one,
438ac6d5e   Tejun Heo   libata: add missi...
173
  #ifdef CONFIG_PM
30ced0f0d   Alan Cox   [PATCH] PATA liba...
174
175
  	.suspend		= ata_pci_device_suspend,
  	.resume			= ata_pci_device_resume,
438ac6d5e   Tejun Heo   libata: add missi...
176
  #endif
75742cb41   Alan Cox   [PATCH] pata_marv...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  };
  
  static int __init marvell_init(void)
  {
  	return pci_register_driver(&marvell_pci_driver);
  }
  
  static void __exit marvell_exit(void)
  {
  	pci_unregister_driver(&marvell_pci_driver);
  }
  
  module_init(marvell_init);
  module_exit(marvell_exit);
  
  MODULE_AUTHOR("Alan Cox");
  MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  MODULE_LICENSE("GPL");
  MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  MODULE_VERSION(DRV_VERSION);