Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * pata_triflex.c 	- Compaq PATA for new ATA layer
  4 *			  (C) 2005 Red Hat Inc
  5 *			  Alan Cox <alan@lxorguk.ukuu.org.uk>
  6 *
  7 * based upon
  8 *
  9 * triflex.c
 10 *
 11 * IDE Chipset driver for the Compaq TriFlex IDE controller.
 12 *
 13 * Known to work with the Compaq Workstation 5x00 series.
 14 *
 15 * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
 16 * Author: Torben Mathiasen <torben.mathiasen@hp.com>
 17 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 18 * Loosely based on the piix & svwks drivers.
 19 *
 20 * Documentation:
 21 *	Not publicly available.
 22 */
 23
 24#include <linux/kernel.h>
 25#include <linux/module.h>
 26#include <linux/pci.h>
 
 27#include <linux/blkdev.h>
 28#include <linux/delay.h>
 29#include <scsi/scsi_host.h>
 30#include <linux/libata.h>
 31
 32#define DRV_NAME "pata_triflex"
 33#define DRV_VERSION "0.2.8"
 34
 35/**
 36 *	triflex_prereset		-	probe begin
 37 *	@link: ATA link
 38 *	@deadline: deadline jiffies for the operation
 39 *
 40 *	Set up cable type and use generic probe init
 41 */
 42
 43static int triflex_prereset(struct ata_link *link, unsigned long deadline)
 44{
 45	static const struct pci_bits triflex_enable_bits[] = {
 46		{ 0x80, 1, 0x01, 0x01 },
 47		{ 0x80, 1, 0x02, 0x02 }
 48	};
 49
 50	struct ata_port *ap = link->ap;
 51	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 52
 53	if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
 54		return -ENOENT;
 55
 56	return ata_sff_prereset(link, deadline);
 57}
 58
 59
 60
 61/**
 62 *	triflex_load_timing		-	timing configuration
 63 *	@ap: ATA interface
 64 *	@adev: Device on the bus
 65 *	@speed: speed to configure
 66 *
 67 *	The Triflex has one set of timings per device per channel. This
 68 *	means we must do some switching. As the PIO and DMA timings don't
 69 *	match we have to do some reloading unlike PIIX devices where tuning
 70 *	tricks can avoid it.
 71 */
 72
 73static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
 74{
 75	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 76	u32 timing = 0;
 77	u32 triflex_timing, old_triflex_timing;
 78	int channel_offset = ap->port_no ? 0x74: 0x70;
 79	unsigned int is_slave	= (adev->devno != 0);
 80
 81
 82	pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
 83	triflex_timing = old_triflex_timing;
 84
 85	switch(speed)
 86	{
 87		case XFER_MW_DMA_2:
 88			timing = 0x0103;break;
 89		case XFER_MW_DMA_1:
 90			timing = 0x0203;break;
 91		case XFER_MW_DMA_0:
 92			timing = 0x0808;break;
 93		case XFER_SW_DMA_2:
 94		case XFER_SW_DMA_1:
 95		case XFER_SW_DMA_0:
 96			timing = 0x0F0F;break;
 97		case XFER_PIO_4:
 98			timing = 0x0202;break;
 99		case XFER_PIO_3:
100			timing = 0x0204;break;
101		case XFER_PIO_2:
102			timing = 0x0404;break;
103		case XFER_PIO_1:
104			timing = 0x0508;break;
105		case XFER_PIO_0:
106			timing = 0x0808;break;
107		default:
108			BUG();
109	}
110	triflex_timing &= ~ (0xFFFF << (16 * is_slave));
111	triflex_timing |= (timing << (16 * is_slave));
112
113	if (triflex_timing != old_triflex_timing)
114		pci_write_config_dword(pdev, channel_offset, triflex_timing);
115}
116
117/**
118 *	triflex_set_piomode	-	set initial PIO mode data
119 *	@ap: ATA interface
120 *	@adev: ATA device
121 *
122 *	Use the timing loader to set up the PIO mode. We have to do this
123 *	because DMA start/stop will only be called once DMA occurs. If there
124 *	has been no DMA then the PIO timings are still needed.
125 */
126static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
127{
128	triflex_load_timing(ap, adev, adev->pio_mode);
129}
130
131/**
132 *	triflex_bmdma_start	-	DMA start callback
133 *	@qc: Command in progress
134 *
135 *	Usually drivers set the DMA timing at the point the set_dmamode call
136 *	is made. Triflex however requires we load new timings on the
137 *	transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
138 *	We load the DMA timings just before starting DMA and then restore
139 *	the PIO timing when the DMA is finished.
140 */
141
142static void triflex_bmdma_start(struct ata_queued_cmd *qc)
143{
144	triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
145	ata_bmdma_start(qc);
146}
147
148/**
149 *	triflex_bmdma_stop	-	DMA stop callback
150 *	@qc: ATA command
 
151 *
152 *	We loaded new timings in dma_start, as a result we need to restore
153 *	the PIO timings in dma_stop so that the next command issue gets the
154 *	right clock values.
155 */
156
157static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
158{
159	ata_bmdma_stop(qc);
160	triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
161}
162
163static const struct scsi_host_template triflex_sht = {
164	ATA_BMDMA_SHT(DRV_NAME),
165};
166
167static struct ata_port_operations triflex_port_ops = {
168	.inherits	= &ata_bmdma_port_ops,
169	.bmdma_start 	= triflex_bmdma_start,
170	.bmdma_stop	= triflex_bmdma_stop,
171	.cable_detect	= ata_cable_40wire,
172	.set_piomode	= triflex_set_piomode,
173	.prereset	= triflex_prereset,
174};
175
176static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
177{
178	static const struct ata_port_info info = {
179		.flags = ATA_FLAG_SLAVE_POSS,
180		.pio_mask = ATA_PIO4,
181		.mwdma_mask = ATA_MWDMA2,
182		.port_ops = &triflex_port_ops
183	};
184	const struct ata_port_info *ppi[] = { &info, NULL };
185
186	ata_print_version_once(&dev->dev, DRV_VERSION);
187
188	return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0);
189}
190
191static const struct pci_device_id triflex[] = {
192	{ PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
193
194	{ },
195};
196
197#ifdef CONFIG_PM_SLEEP
198static int triflex_ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
199{
200	struct ata_host *host = pci_get_drvdata(pdev);
 
201
202	ata_host_suspend(host, mesg);
 
 
203
204	/*
205	 * We must not disable or powerdown the device.
206	 * APM bios refuses to suspend if IDE is not accessible.
207	 */
208	pci_save_state(pdev);
209
210	return 0;
211}
212
213#endif
214
215static struct pci_driver triflex_pci_driver = {
216	.name 		= DRV_NAME,
217	.id_table	= triflex,
218	.probe 		= triflex_init_one,
219	.remove		= ata_pci_remove_one,
220#ifdef CONFIG_PM_SLEEP
221	.suspend	= triflex_ata_pci_device_suspend,
222	.resume		= ata_pci_device_resume,
223#endif
224};
225
226module_pci_driver(triflex_pci_driver);
 
 
 
 
 
 
 
 
227
228MODULE_AUTHOR("Alan Cox");
229MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
230MODULE_LICENSE("GPL");
231MODULE_DEVICE_TABLE(pci, triflex);
232MODULE_VERSION(DRV_VERSION);
v3.1
 
  1/*
  2 * pata_triflex.c 	- Compaq PATA for new ATA layer
  3 *			  (C) 2005 Red Hat Inc
  4 *			  Alan Cox <alan@lxorguk.ukuu.org.uk>
  5 *
  6 * based upon
  7 *
  8 * triflex.c
  9 *
 10 * IDE Chipset driver for the Compaq TriFlex IDE controller.
 11 *
 12 * Known to work with the Compaq Workstation 5x00 series.
 13 *
 14 * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
 15 * Author: Torben Mathiasen <torben.mathiasen@hp.com>
 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 * This program is distributed in the hope that it will be useful,
 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 24 * GNU General Public License for more details.
 25 *
 26 * You should have received a copy of the GNU General Public License
 27 * along with this program; if not, write to the Free Software
 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 29 *
 30 * Loosely based on the piix & svwks drivers.
 31 *
 32 * Documentation:
 33 *	Not publicly available.
 34 */
 35
 36#include <linux/kernel.h>
 37#include <linux/module.h>
 38#include <linux/pci.h>
 39#include <linux/init.h>
 40#include <linux/blkdev.h>
 41#include <linux/delay.h>
 42#include <scsi/scsi_host.h>
 43#include <linux/libata.h>
 44
 45#define DRV_NAME "pata_triflex"
 46#define DRV_VERSION "0.2.8"
 47
 48/**
 49 *	triflex_prereset		-	probe begin
 50 *	@link: ATA link
 51 *	@deadline: deadline jiffies for the operation
 52 *
 53 *	Set up cable type and use generic probe init
 54 */
 55
 56static int triflex_prereset(struct ata_link *link, unsigned long deadline)
 57{
 58	static const struct pci_bits triflex_enable_bits[] = {
 59		{ 0x80, 1, 0x01, 0x01 },
 60		{ 0x80, 1, 0x02, 0x02 }
 61	};
 62
 63	struct ata_port *ap = link->ap;
 64	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 65
 66	if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
 67		return -ENOENT;
 68
 69	return ata_sff_prereset(link, deadline);
 70}
 71
 72
 73
 74/**
 75 *	triflex_load_timing		-	timing configuration
 76 *	@ap: ATA interface
 77 *	@adev: Device on the bus
 78 *	@speed: speed to configure
 79 *
 80 *	The Triflex has one set of timings per device per channel. This
 81 *	means we must do some switching. As the PIO and DMA timings don't
 82 *	match we have to do some reloading unlike PIIX devices where tuning
 83 *	tricks can avoid it.
 84 */
 85
 86static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
 87{
 88	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 89	u32 timing = 0;
 90	u32 triflex_timing, old_triflex_timing;
 91	int channel_offset = ap->port_no ? 0x74: 0x70;
 92	unsigned int is_slave	= (adev->devno != 0);
 93
 94
 95	pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
 96	triflex_timing = old_triflex_timing;
 97
 98	switch(speed)
 99	{
100		case XFER_MW_DMA_2:
101			timing = 0x0103;break;
102		case XFER_MW_DMA_1:
103			timing = 0x0203;break;
104		case XFER_MW_DMA_0:
105			timing = 0x0808;break;
106		case XFER_SW_DMA_2:
107		case XFER_SW_DMA_1:
108		case XFER_SW_DMA_0:
109			timing = 0x0F0F;break;
110		case XFER_PIO_4:
111			timing = 0x0202;break;
112		case XFER_PIO_3:
113			timing = 0x0204;break;
114		case XFER_PIO_2:
115			timing = 0x0404;break;
116		case XFER_PIO_1:
117			timing = 0x0508;break;
118		case XFER_PIO_0:
119			timing = 0x0808;break;
120		default:
121			BUG();
122	}
123	triflex_timing &= ~ (0xFFFF << (16 * is_slave));
124	triflex_timing |= (timing << (16 * is_slave));
125
126	if (triflex_timing != old_triflex_timing)
127		pci_write_config_dword(pdev, channel_offset, triflex_timing);
128}
129
130/**
131 *	triflex_set_piomode	-	set initial PIO mode data
132 *	@ap: ATA interface
133 *	@adev: ATA device
134 *
135 *	Use the timing loader to set up the PIO mode. We have to do this
136 *	because DMA start/stop will only be called once DMA occurs. If there
137 *	has been no DMA then the PIO timings are still needed.
138 */
139static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
140{
141	triflex_load_timing(ap, adev, adev->pio_mode);
142}
143
144/**
145 *	triflex_dma_start	-	DMA start callback
146 *	@qc: Command in progress
147 *
148 *	Usually drivers set the DMA timing at the point the set_dmamode call
149 *	is made. Triflex however requires we load new timings on the
150 *	transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
151 *	We load the DMA timings just before starting DMA and then restore
152 *	the PIO timing when the DMA is finished.
153 */
154
155static void triflex_bmdma_start(struct ata_queued_cmd *qc)
156{
157	triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
158	ata_bmdma_start(qc);
159}
160
161/**
162 *	triflex_dma_stop	-	DMA stop callback
163 *	@ap: ATA interface
164 *	@adev: ATA device
165 *
166 *	We loaded new timings in dma_start, as a result we need to restore
167 *	the PIO timings in dma_stop so that the next command issue gets the
168 *	right clock values.
169 */
170
171static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
172{
173	ata_bmdma_stop(qc);
174	triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
175}
176
177static struct scsi_host_template triflex_sht = {
178	ATA_BMDMA_SHT(DRV_NAME),
179};
180
181static struct ata_port_operations triflex_port_ops = {
182	.inherits	= &ata_bmdma_port_ops,
183	.bmdma_start 	= triflex_bmdma_start,
184	.bmdma_stop	= triflex_bmdma_stop,
185	.cable_detect	= ata_cable_40wire,
186	.set_piomode	= triflex_set_piomode,
187	.prereset	= triflex_prereset,
188};
189
190static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
191{
192	static const struct ata_port_info info = {
193		.flags = ATA_FLAG_SLAVE_POSS,
194		.pio_mask = ATA_PIO4,
195		.mwdma_mask = ATA_MWDMA2,
196		.port_ops = &triflex_port_ops
197	};
198	const struct ata_port_info *ppi[] = { &info, NULL };
199
200	ata_print_version_once(&dev->dev, DRV_VERSION);
201
202	return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0);
203}
204
205static const struct pci_device_id triflex[] = {
206	{ PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
207
208	{ },
209};
210
211#ifdef CONFIG_PM
212static int triflex_ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
213{
214	struct ata_host *host = dev_get_drvdata(&pdev->dev);
215	int rc = 0;
216
217	rc = ata_host_suspend(host, mesg);
218	if (rc)
219		return rc;
220
221	/*
222	 * We must not disable or powerdown the device.
223	 * APM bios refuses to suspend if IDE is not accessible.
224	 */
225	pci_save_state(pdev);
226
227	return 0;
228}
229
230#endif
231
232static struct pci_driver triflex_pci_driver = {
233	.name 		= DRV_NAME,
234	.id_table	= triflex,
235	.probe 		= triflex_init_one,
236	.remove		= ata_pci_remove_one,
237#ifdef CONFIG_PM
238	.suspend	= triflex_ata_pci_device_suspend,
239	.resume		= ata_pci_device_resume,
240#endif
241};
242
243static int __init triflex_init(void)
244{
245	return pci_register_driver(&triflex_pci_driver);
246}
247
248static void __exit triflex_exit(void)
249{
250	pci_unregister_driver(&triflex_pci_driver);
251}
252
253MODULE_AUTHOR("Alan Cox");
254MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
255MODULE_LICENSE("GPL");
256MODULE_DEVICE_TABLE(pci, triflex);
257MODULE_VERSION(DRV_VERSION);
258
259module_init(triflex_init);
260module_exit(triflex_exit);