xref: /openbmc/linux/drivers/ata/pata_atp867x.c (revision 25df73d9)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2d15d6e6cSJohn(Jung-Ik) Lee /*
3d15d6e6cSJohn(Jung-Ik) Lee  * pata_atp867x.c - ARTOP 867X 64bit 4-channel UDMA133 ATA controller driver
4d15d6e6cSJohn(Jung-Ik) Lee  *
5d15d6e6cSJohn(Jung-Ik) Lee  *	(C) 2009 Google Inc. John(Jung-Ik) Lee <jilee@google.com>
6d15d6e6cSJohn(Jung-Ik) Lee  *
7d15d6e6cSJohn(Jung-Ik) Lee  * Per Atp867 data sheet rev 1.2, Acard.
8d15d6e6cSJohn(Jung-Ik) Lee  * Based in part on early ide code from
9d15d6e6cSJohn(Jung-Ik) Lee  *	2003-2004 by Eric Uhrhane, Google, Inc.
10d15d6e6cSJohn(Jung-Ik) Lee  *
11d15d6e6cSJohn(Jung-Ik) Lee  * TODO:
12d15d6e6cSJohn(Jung-Ik) Lee  *   1. RAID features [comparison, XOR, striping, mirroring, etc.]
13d15d6e6cSJohn(Jung-Ik) Lee  */
14d15d6e6cSJohn(Jung-Ik) Lee 
15d15d6e6cSJohn(Jung-Ik) Lee #include <linux/kernel.h>
16d15d6e6cSJohn(Jung-Ik) Lee #include <linux/module.h>
17d15d6e6cSJohn(Jung-Ik) Lee #include <linux/pci.h>
18d15d6e6cSJohn(Jung-Ik) Lee #include <linux/blkdev.h>
19d15d6e6cSJohn(Jung-Ik) Lee #include <linux/delay.h>
20d15d6e6cSJohn(Jung-Ik) Lee #include <linux/device.h>
215a0e3ad6STejun Heo #include <linux/gfp.h>
22d15d6e6cSJohn(Jung-Ik) Lee #include <scsi/scsi_host.h>
23d15d6e6cSJohn(Jung-Ik) Lee #include <linux/libata.h>
24d15d6e6cSJohn(Jung-Ik) Lee 
25d15d6e6cSJohn(Jung-Ik) Lee #define	DRV_NAME	"pata_atp867x"
26d15d6e6cSJohn(Jung-Ik) Lee #define	DRV_VERSION	"0.7.5"
27d15d6e6cSJohn(Jung-Ik) Lee 
28d15d6e6cSJohn(Jung-Ik) Lee /*
29d15d6e6cSJohn(Jung-Ik) Lee  * IO Registers
30d15d6e6cSJohn(Jung-Ik) Lee  * Note that all runtime hot priv ports are cached in ap private_data
31d15d6e6cSJohn(Jung-Ik) Lee  */
32d15d6e6cSJohn(Jung-Ik) Lee 
33d15d6e6cSJohn(Jung-Ik) Lee enum {
34d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_CHANNEL_OFFSET	= 0x10,
35d15d6e6cSJohn(Jung-Ik) Lee 
36d15d6e6cSJohn(Jung-Ik) Lee 	/*
37d15d6e6cSJohn(Jung-Ik) Lee 	 * IO Register Bitfields
38d15d6e6cSJohn(Jung-Ik) Lee 	 */
39d15d6e6cSJohn(Jung-Ik) Lee 
40d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_PIOSPD_ACTIVE_SHIFT	= 4,
41d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_PIOSPD_RECOVER_SHIFT	= 0,
42d15d6e6cSJohn(Jung-Ik) Lee 
43d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_MSTR_SHIFT	= 0,
44d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_MSTR_MASK	= 0x07,
45d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_SLAVE_SHIFT	= 4,
46d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_SLAVE_MASK	= 0x70,
47d15d6e6cSJohn(Jung-Ik) Lee 
48d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_6	= 0x07,
49d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_5	= 0x06,
50d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_4	= 0x05,
51d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_3	= 0x04,
52d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_2	= 0x03,
53d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_1	= 0x02,
54d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_UDMA_0	= 0x01,
55d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_DMAMODE_DISABLE	= 0x00,
56d15d6e6cSJohn(Jung-Ik) Lee 
57d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_SYS_INFO_66MHZ	= 0x04,
58d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_SYS_INFO_SLOW_UDMA5	= 0x02,
59d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_SYS_MASK_RESERVED	= (~0xf1),
60d15d6e6cSJohn(Jung-Ik) Lee 
61d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_IO_PORTSPD_VAL		= 0x1143,
62d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_PREREAD_VAL		= 0x0200,
63d15d6e6cSJohn(Jung-Ik) Lee 
64d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_NUM_PORTS		= 4,
65d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_BAR_IOBASE		= 0,
66d15d6e6cSJohn(Jung-Ik) Lee 	ATP867X_BAR_ROMBASE		= 6,
67d15d6e6cSJohn(Jung-Ik) Lee };
68d15d6e6cSJohn(Jung-Ik) Lee 
69d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IOBASE(ap)		((ap)->host->iomap[0])
70d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_SYS_INFO(ap)		(0x3F + ATP867X_IOBASE(ap))
71d15d6e6cSJohn(Jung-Ik) Lee 
72d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_PORTBASE(ap, port)	(0x00 + ATP867X_IOBASE(ap) + \
73d15d6e6cSJohn(Jung-Ik) Lee 					(port) * ATP867X_IO_CHANNEL_OFFSET)
74d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_DMABASE(ap, port)	(0x40 + \
75d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_PORTBASE((ap), (port)))
76d15d6e6cSJohn(Jung-Ik) Lee 
77d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_STATUS(ap, port)	(0x07 + \
78d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_PORTBASE((ap), (port)))
79d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_ALTSTATUS(ap, port)	(0x0E + \
80d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_PORTBASE((ap), (port)))
81d15d6e6cSJohn(Jung-Ik) Lee 
82d15d6e6cSJohn(Jung-Ik) Lee /*
83d15d6e6cSJohn(Jung-Ik) Lee  * hot priv ports
84d15d6e6cSJohn(Jung-Ik) Lee  */
85d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_MSTRPIOSPD(ap, port)	(0x08 + \
86d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_DMABASE((ap), (port)))
87d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_SLAVPIOSPD(ap, port)	(0x09 + \
88d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_DMABASE((ap), (port)))
89d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_8BPIOSPD(ap, port)	(0x0A + \
90d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_DMABASE((ap), (port)))
91d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_DMAMODE(ap, port)	(0x0B + \
92d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_DMABASE((ap), (port)))
93d15d6e6cSJohn(Jung-Ik) Lee 
94d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_PORTSPD(ap, port)	(0x4A + \
95d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_PORTBASE((ap), (port)))
96d15d6e6cSJohn(Jung-Ik) Lee #define ATP867X_IO_PREREAD(ap, port)	(0x4C + \
97d15d6e6cSJohn(Jung-Ik) Lee 					ATP867X_IO_PORTBASE((ap), (port)))
98d15d6e6cSJohn(Jung-Ik) Lee 
99d15d6e6cSJohn(Jung-Ik) Lee struct atp867x_priv {
100d15d6e6cSJohn(Jung-Ik) Lee 	void __iomem *dma_mode;
101d15d6e6cSJohn(Jung-Ik) Lee 	void __iomem *mstr_piospd;
102d15d6e6cSJohn(Jung-Ik) Lee 	void __iomem *slave_piospd;
103d15d6e6cSJohn(Jung-Ik) Lee 	void __iomem *eightb_piospd;
104d15d6e6cSJohn(Jung-Ik) Lee 	int		pci66mhz;
105d15d6e6cSJohn(Jung-Ik) Lee };
106d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_set_dmamode(struct ata_port * ap,struct ata_device * adev)107d15d6e6cSJohn(Jung-Ik) Lee static void atp867x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
108d15d6e6cSJohn(Jung-Ik) Lee {
109d15d6e6cSJohn(Jung-Ik) Lee 	struct pci_dev *pdev	= to_pci_dev(ap->host->dev);
110d15d6e6cSJohn(Jung-Ik) Lee 	struct atp867x_priv *dp = ap->private_data;
111d15d6e6cSJohn(Jung-Ik) Lee 	u8 speed = adev->dma_mode;
112d15d6e6cSJohn(Jung-Ik) Lee 	u8 b;
113566b54c8SBartlomiej Zolnierkiewicz 	u8 mode = speed - XFER_UDMA_0 + 1;
114d15d6e6cSJohn(Jung-Ik) Lee 
115d15d6e6cSJohn(Jung-Ik) Lee 	/*
116d15d6e6cSJohn(Jung-Ik) Lee 	 * Doc 6.6.9: decrease the udma mode value by 1 for safer UDMA speed
117d15d6e6cSJohn(Jung-Ik) Lee 	 * on 66MHz bus
118d15d6e6cSJohn(Jung-Ik) Lee 	 *   rev-A: UDMA_1~4 (5, 6 no change)
119d15d6e6cSJohn(Jung-Ik) Lee 	 *   rev-B: all UDMA modes
120d15d6e6cSJohn(Jung-Ik) Lee 	 *   UDMA_0 stays not to disable UDMA
121d15d6e6cSJohn(Jung-Ik) Lee 	 */
122d15d6e6cSJohn(Jung-Ik) Lee 	if (dp->pci66mhz && mode > ATP867X_IO_DMAMODE_UDMA_0  &&
123d15d6e6cSJohn(Jung-Ik) Lee 	   (pdev->device == PCI_DEVICE_ID_ARTOP_ATP867B ||
124d15d6e6cSJohn(Jung-Ik) Lee 	    mode < ATP867X_IO_DMAMODE_UDMA_5))
125d15d6e6cSJohn(Jung-Ik) Lee 		mode--;
126d15d6e6cSJohn(Jung-Ik) Lee 
127d15d6e6cSJohn(Jung-Ik) Lee 	b = ioread8(dp->dma_mode);
128d15d6e6cSJohn(Jung-Ik) Lee 	if (adev->devno & 1) {
129d15d6e6cSJohn(Jung-Ik) Lee 		b = (b & ~ATP867X_IO_DMAMODE_SLAVE_MASK) |
130d15d6e6cSJohn(Jung-Ik) Lee 			(mode << ATP867X_IO_DMAMODE_SLAVE_SHIFT);
131d15d6e6cSJohn(Jung-Ik) Lee 	} else {
132d15d6e6cSJohn(Jung-Ik) Lee 		b = (b & ~ATP867X_IO_DMAMODE_MSTR_MASK) |
133d15d6e6cSJohn(Jung-Ik) Lee 			(mode << ATP867X_IO_DMAMODE_MSTR_SHIFT);
134d15d6e6cSJohn(Jung-Ik) Lee 	}
135d15d6e6cSJohn(Jung-Ik) Lee 	iowrite8(b, dp->dma_mode);
136d15d6e6cSJohn(Jung-Ik) Lee }
137d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_get_active_clocks_shifted(struct ata_port * ap,unsigned int clk)13864207f59SJohn(Jung-Ik) Lee static int atp867x_get_active_clocks_shifted(struct ata_port *ap,
13964207f59SJohn(Jung-Ik) Lee 	unsigned int clk)
140d15d6e6cSJohn(Jung-Ik) Lee {
14164207f59SJohn(Jung-Ik) Lee 	struct atp867x_priv *dp = ap->private_data;
142d15d6e6cSJohn(Jung-Ik) Lee 	unsigned char clocks = clk;
143d15d6e6cSJohn(Jung-Ik) Lee 
14464207f59SJohn(Jung-Ik) Lee 	/*
14564207f59SJohn(Jung-Ik) Lee 	 * Doc 6.6.9: increase the clock value by 1 for safer PIO speed
14664207f59SJohn(Jung-Ik) Lee 	 * on 66MHz bus
14764207f59SJohn(Jung-Ik) Lee 	 */
148c59bcc37SBartlomiej Zolnierkiewicz 	if (dp->pci66mhz)
14964207f59SJohn(Jung-Ik) Lee 		clocks++;
15064207f59SJohn(Jung-Ik) Lee 
151c59bcc37SBartlomiej Zolnierkiewicz 	switch (clocks) {
152c59bcc37SBartlomiej Zolnierkiewicz 	case 0:
153c59bcc37SBartlomiej Zolnierkiewicz 		clocks = 1;
154c59bcc37SBartlomiej Zolnierkiewicz 		break;
155c59bcc37SBartlomiej Zolnierkiewicz 	case 1 ... 6:
156c59bcc37SBartlomiej Zolnierkiewicz 		break;
157c59bcc37SBartlomiej Zolnierkiewicz 	default:
158f2f01a52SHannes Reinecke 		ata_port_warn(ap, "ATP867X: active %dclk is invalid. "
159c59bcc37SBartlomiej Zolnierkiewicz 			"Using 12clk.\n", clk);
160df561f66SGustavo A. R. Silva 		fallthrough;
161c59bcc37SBartlomiej Zolnierkiewicz 	case 9 ... 12:
162c59bcc37SBartlomiej Zolnierkiewicz 		clocks = 7;	/* 12 clk */
163c59bcc37SBartlomiej Zolnierkiewicz 		break;
164c59bcc37SBartlomiej Zolnierkiewicz 	case 7:
165c59bcc37SBartlomiej Zolnierkiewicz 	case 8:	/* default 8 clk */
166c59bcc37SBartlomiej Zolnierkiewicz 		clocks = 0;
167c59bcc37SBartlomiej Zolnierkiewicz 		goto active_clock_shift_done;
168c59bcc37SBartlomiej Zolnierkiewicz 	}
169c59bcc37SBartlomiej Zolnierkiewicz 
17064207f59SJohn(Jung-Ik) Lee active_clock_shift_done:
171d15d6e6cSJohn(Jung-Ik) Lee 	return clocks << ATP867X_IO_PIOSPD_ACTIVE_SHIFT;
172d15d6e6cSJohn(Jung-Ik) Lee }
173d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_get_recover_clocks_shifted(struct ata_port * ap,unsigned int clk)174f2f01a52SHannes Reinecke static int atp867x_get_recover_clocks_shifted(struct ata_port *ap,
175f2f01a52SHannes Reinecke 					      unsigned int clk)
176d15d6e6cSJohn(Jung-Ik) Lee {
177d15d6e6cSJohn(Jung-Ik) Lee 	unsigned char clocks = clk;
178d15d6e6cSJohn(Jung-Ik) Lee 
179d15d6e6cSJohn(Jung-Ik) Lee 	switch (clocks) {
180d15d6e6cSJohn(Jung-Ik) Lee 	case 0:
181d15d6e6cSJohn(Jung-Ik) Lee 		clocks = 1;
182d15d6e6cSJohn(Jung-Ik) Lee 		break;
183d15d6e6cSJohn(Jung-Ik) Lee 	case 1 ... 11:
184d15d6e6cSJohn(Jung-Ik) Lee 		break;
185c59bcc37SBartlomiej Zolnierkiewicz 	case 13:
186c59bcc37SBartlomiej Zolnierkiewicz 	case 14:
18764207f59SJohn(Jung-Ik) Lee 		--clocks;	/* by the spec */
188d15d6e6cSJohn(Jung-Ik) Lee 		break;
189d15d6e6cSJohn(Jung-Ik) Lee 	case 15:
190d15d6e6cSJohn(Jung-Ik) Lee 		break;
191d15d6e6cSJohn(Jung-Ik) Lee 	default:
192f2f01a52SHannes Reinecke 		ata_port_warn(ap, "ATP867X: recover %dclk is invalid. "
19364207f59SJohn(Jung-Ik) Lee 			"Using default 12clk.\n", clk);
194df561f66SGustavo A. R. Silva 		fallthrough;
19564207f59SJohn(Jung-Ik) Lee 	case 12:	/* default 12 clk */
19664207f59SJohn(Jung-Ik) Lee 		clocks = 0;
197d15d6e6cSJohn(Jung-Ik) Lee 		break;
198d15d6e6cSJohn(Jung-Ik) Lee 	}
19964207f59SJohn(Jung-Ik) Lee 
200d15d6e6cSJohn(Jung-Ik) Lee 	return clocks << ATP867X_IO_PIOSPD_RECOVER_SHIFT;
201d15d6e6cSJohn(Jung-Ik) Lee }
202d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_set_piomode(struct ata_port * ap,struct ata_device * adev)203d15d6e6cSJohn(Jung-Ik) Lee static void atp867x_set_piomode(struct ata_port *ap, struct ata_device *adev)
204d15d6e6cSJohn(Jung-Ik) Lee {
205d15d6e6cSJohn(Jung-Ik) Lee 	struct ata_device *peer = ata_dev_pair(adev);
206d15d6e6cSJohn(Jung-Ik) Lee 	struct atp867x_priv *dp = ap->private_data;
207d15d6e6cSJohn(Jung-Ik) Lee 	u8 speed = adev->pio_mode;
208d15d6e6cSJohn(Jung-Ik) Lee 	struct ata_timing t, p;
209d15d6e6cSJohn(Jung-Ik) Lee 	int T, UT;
210d15d6e6cSJohn(Jung-Ik) Lee 	u8 b;
211d15d6e6cSJohn(Jung-Ik) Lee 
212d15d6e6cSJohn(Jung-Ik) Lee 	T = 1000000000 / 33333;
213d15d6e6cSJohn(Jung-Ik) Lee 	UT = T / 4;
214d15d6e6cSJohn(Jung-Ik) Lee 
215d15d6e6cSJohn(Jung-Ik) Lee 	ata_timing_compute(adev, speed, &t, T, UT);
216d15d6e6cSJohn(Jung-Ik) Lee 	if (peer && peer->pio_mode) {
217d15d6e6cSJohn(Jung-Ik) Lee 		ata_timing_compute(peer, peer->pio_mode, &p, T, UT);
218d15d6e6cSJohn(Jung-Ik) Lee 		ata_timing_merge(&p, &t, &t, ATA_TIMING_8BIT);
219d15d6e6cSJohn(Jung-Ik) Lee 	}
220d15d6e6cSJohn(Jung-Ik) Lee 
221d15d6e6cSJohn(Jung-Ik) Lee 	b = ioread8(dp->dma_mode);
222d15d6e6cSJohn(Jung-Ik) Lee 	if (adev->devno & 1)
223d15d6e6cSJohn(Jung-Ik) Lee 		b = (b & ~ATP867X_IO_DMAMODE_SLAVE_MASK);
224d15d6e6cSJohn(Jung-Ik) Lee 	else
225d15d6e6cSJohn(Jung-Ik) Lee 		b = (b & ~ATP867X_IO_DMAMODE_MSTR_MASK);
226d15d6e6cSJohn(Jung-Ik) Lee 	iowrite8(b, dp->dma_mode);
227d15d6e6cSJohn(Jung-Ik) Lee 
22864207f59SJohn(Jung-Ik) Lee 	b = atp867x_get_active_clocks_shifted(ap, t.active) |
229f2f01a52SHannes Reinecke 		atp867x_get_recover_clocks_shifted(ap, t.recover);
230d15d6e6cSJohn(Jung-Ik) Lee 
231d15d6e6cSJohn(Jung-Ik) Lee 	if (adev->devno & 1)
232d15d6e6cSJohn(Jung-Ik) Lee 		iowrite8(b, dp->slave_piospd);
233d15d6e6cSJohn(Jung-Ik) Lee 	else
234d15d6e6cSJohn(Jung-Ik) Lee 		iowrite8(b, dp->mstr_piospd);
235d15d6e6cSJohn(Jung-Ik) Lee 
236c59bcc37SBartlomiej Zolnierkiewicz 	b = atp867x_get_active_clocks_shifted(ap, t.act8b) |
237f2f01a52SHannes Reinecke 		atp867x_get_recover_clocks_shifted(ap, t.rec8b);
238c59bcc37SBartlomiej Zolnierkiewicz 
239d15d6e6cSJohn(Jung-Ik) Lee 	iowrite8(b, dp->eightb_piospd);
240d15d6e6cSJohn(Jung-Ik) Lee }
241d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_cable_override(struct pci_dev * pdev)24264207f59SJohn(Jung-Ik) Lee static int atp867x_cable_override(struct pci_dev *pdev)
24364207f59SJohn(Jung-Ik) Lee {
24464207f59SJohn(Jung-Ik) Lee 	if (pdev->subsystem_vendor == PCI_VENDOR_ID_ARTOP &&
24564207f59SJohn(Jung-Ik) Lee 		(pdev->subsystem_device == PCI_DEVICE_ID_ARTOP_ATP867A ||
24664207f59SJohn(Jung-Ik) Lee 		 pdev->subsystem_device == PCI_DEVICE_ID_ARTOP_ATP867B)) {
24764207f59SJohn(Jung-Ik) Lee 		return 1;
24864207f59SJohn(Jung-Ik) Lee 	}
24964207f59SJohn(Jung-Ik) Lee 	return 0;
25064207f59SJohn(Jung-Ik) Lee }
25164207f59SJohn(Jung-Ik) Lee 
atp867x_cable_detect(struct ata_port * ap)252d15d6e6cSJohn(Jung-Ik) Lee static int atp867x_cable_detect(struct ata_port *ap)
253d15d6e6cSJohn(Jung-Ik) Lee {
25464207f59SJohn(Jung-Ik) Lee 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
25564207f59SJohn(Jung-Ik) Lee 
25664207f59SJohn(Jung-Ik) Lee 	if (atp867x_cable_override(pdev))
257d15d6e6cSJohn(Jung-Ik) Lee 		return ATA_CBL_PATA40_SHORT;
25864207f59SJohn(Jung-Ik) Lee 
25964207f59SJohn(Jung-Ik) Lee 	return ATA_CBL_PATA_UNK;
260d15d6e6cSJohn(Jung-Ik) Lee }
261d15d6e6cSJohn(Jung-Ik) Lee 
262*25df73d9SBart Van Assche static const struct scsi_host_template atp867x_sht = {
263d15d6e6cSJohn(Jung-Ik) Lee 	ATA_BMDMA_SHT(DRV_NAME),
264d15d6e6cSJohn(Jung-Ik) Lee };
265d15d6e6cSJohn(Jung-Ik) Lee 
266d15d6e6cSJohn(Jung-Ik) Lee static struct ata_port_operations atp867x_ops = {
267d15d6e6cSJohn(Jung-Ik) Lee 	.inherits		= &ata_bmdma_port_ops,
268d15d6e6cSJohn(Jung-Ik) Lee 	.cable_detect		= atp867x_cable_detect,
269d15d6e6cSJohn(Jung-Ik) Lee 	.set_piomode		= atp867x_set_piomode,
270d15d6e6cSJohn(Jung-Ik) Lee 	.set_dmamode		= atp867x_set_dmamode,
271d15d6e6cSJohn(Jung-Ik) Lee };
272d15d6e6cSJohn(Jung-Ik) Lee 
273d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_check_res(struct pci_dev * pdev)274d15d6e6cSJohn(Jung-Ik) Lee static void atp867x_check_res(struct pci_dev *pdev)
275d15d6e6cSJohn(Jung-Ik) Lee {
276d15d6e6cSJohn(Jung-Ik) Lee 	int i;
277d15d6e6cSJohn(Jung-Ik) Lee 	unsigned long start, len;
278d15d6e6cSJohn(Jung-Ik) Lee 
279d15d6e6cSJohn(Jung-Ik) Lee 	/* Check the PCI resources for this channel are enabled */
280d15d6e6cSJohn(Jung-Ik) Lee 	for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
281d15d6e6cSJohn(Jung-Ik) Lee 		start = pci_resource_start(pdev, i);
282d15d6e6cSJohn(Jung-Ik) Lee 		len   = pci_resource_len(pdev, i);
283f2f01a52SHannes Reinecke 		dev_dbg(&pdev->dev, "ATP867X: resource start:len=%lx:%lx\n",
284d15d6e6cSJohn(Jung-Ik) Lee 			start, len);
285d15d6e6cSJohn(Jung-Ik) Lee 	}
286d15d6e6cSJohn(Jung-Ik) Lee }
287d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_check_ports(struct ata_port * ap,int port)288d15d6e6cSJohn(Jung-Ik) Lee static void atp867x_check_ports(struct ata_port *ap, int port)
289d15d6e6cSJohn(Jung-Ik) Lee {
290d15d6e6cSJohn(Jung-Ik) Lee 	struct ata_ioports *ioaddr = &ap->ioaddr;
291d15d6e6cSJohn(Jung-Ik) Lee 	struct atp867x_priv *dp = ap->private_data;
292d15d6e6cSJohn(Jung-Ik) Lee 
293f2f01a52SHannes Reinecke 	ata_port_dbg(ap, "ATP867X: port[%d] addresses\n"
294f2f01a52SHannes Reinecke 		"  cmd_addr	=0x%lx, 0x%lx\n"
295f2f01a52SHannes Reinecke 		"  ctl_addr	=0x%lx, 0x%lx\n"
296f2f01a52SHannes Reinecke 		"  bmdma_addr	=0x%lx, 0x%lx\n"
297f2f01a52SHannes Reinecke 		"  data_addr	=0x%lx\n"
298f2f01a52SHannes Reinecke 		"  error_addr	=0x%lx\n"
299f2f01a52SHannes Reinecke 		"  feature_addr	=0x%lx\n"
300f2f01a52SHannes Reinecke 		"  nsect_addr	=0x%lx\n"
301f2f01a52SHannes Reinecke 		"  lbal_addr	=0x%lx\n"
302f2f01a52SHannes Reinecke 		"  lbam_addr	=0x%lx\n"
303f2f01a52SHannes Reinecke 		"  lbah_addr	=0x%lx\n"
304f2f01a52SHannes Reinecke 		"  device_addr	=0x%lx\n"
305f2f01a52SHannes Reinecke 		"  status_addr	=0x%lx\n"
306f2f01a52SHannes Reinecke 		"  command_addr	=0x%lx\n"
307f2f01a52SHannes Reinecke 		"  dp->dma_mode	=0x%lx\n"
308f2f01a52SHannes Reinecke 		"  dp->mstr_piospd	=0x%lx\n"
309f2f01a52SHannes Reinecke 		"  dp->slave_piospd	=0x%lx\n"
310f2f01a52SHannes Reinecke 		"  dp->eightb_piospd	=0x%lx\n"
311d15d6e6cSJohn(Jung-Ik) Lee 		"  dp->pci66mhz		=0x%lx\n",
312d15d6e6cSJohn(Jung-Ik) Lee 		port,
313f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->cmd_addr,
314f2f01a52SHannes Reinecke 		(unsigned long)ATP867X_IO_PORTBASE(ap, port),
315f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->ctl_addr,
316f2f01a52SHannes Reinecke 		(unsigned long)ATP867X_IO_ALTSTATUS(ap, port),
317f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->bmdma_addr,
318f2f01a52SHannes Reinecke 		(unsigned long)ATP867X_IO_DMABASE(ap, port),
319f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->data_addr,
320f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->error_addr,
321f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->feature_addr,
322f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->nsect_addr,
323f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->lbal_addr,
324f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->lbam_addr,
325f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->lbah_addr,
326f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->device_addr,
327f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->status_addr,
328f2f01a52SHannes Reinecke 		(unsigned long)ioaddr->command_addr,
329f2f01a52SHannes Reinecke 		(unsigned long)dp->dma_mode,
330f2f01a52SHannes Reinecke 		(unsigned long)dp->mstr_piospd,
331f2f01a52SHannes Reinecke 		(unsigned long)dp->slave_piospd,
332f2f01a52SHannes Reinecke 		(unsigned long)dp->eightb_piospd,
333d15d6e6cSJohn(Jung-Ik) Lee 		(unsigned long)dp->pci66mhz);
334d15d6e6cSJohn(Jung-Ik) Lee }
335d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_set_priv(struct ata_port * ap)336d15d6e6cSJohn(Jung-Ik) Lee static int atp867x_set_priv(struct ata_port *ap)
337d15d6e6cSJohn(Jung-Ik) Lee {
338d15d6e6cSJohn(Jung-Ik) Lee 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
339d15d6e6cSJohn(Jung-Ik) Lee 	struct atp867x_priv *dp;
340d15d6e6cSJohn(Jung-Ik) Lee 	int port = ap->port_no;
341d15d6e6cSJohn(Jung-Ik) Lee 
342d15d6e6cSJohn(Jung-Ik) Lee 	dp = ap->private_data =
343d15d6e6cSJohn(Jung-Ik) Lee 		devm_kzalloc(&pdev->dev, sizeof(*dp), GFP_KERNEL);
344d15d6e6cSJohn(Jung-Ik) Lee 	if (dp == NULL)
345d15d6e6cSJohn(Jung-Ik) Lee 		return -ENOMEM;
346d15d6e6cSJohn(Jung-Ik) Lee 
347d15d6e6cSJohn(Jung-Ik) Lee 	dp->dma_mode	 = ATP867X_IO_DMAMODE(ap, port);
348d15d6e6cSJohn(Jung-Ik) Lee 	dp->mstr_piospd	 = ATP867X_IO_MSTRPIOSPD(ap, port);
349d15d6e6cSJohn(Jung-Ik) Lee 	dp->slave_piospd = ATP867X_IO_SLAVPIOSPD(ap, port);
350d15d6e6cSJohn(Jung-Ik) Lee 	dp->eightb_piospd = ATP867X_IO_8BPIOSPD(ap, port);
351d15d6e6cSJohn(Jung-Ik) Lee 
352d15d6e6cSJohn(Jung-Ik) Lee 	dp->pci66mhz =
353d15d6e6cSJohn(Jung-Ik) Lee 		ioread8(ATP867X_SYS_INFO(ap)) & ATP867X_IO_SYS_INFO_66MHZ;
354d15d6e6cSJohn(Jung-Ik) Lee 
355d15d6e6cSJohn(Jung-Ik) Lee 	return 0;
356d15d6e6cSJohn(Jung-Ik) Lee }
357d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_fixup(struct ata_host * host)358d15d6e6cSJohn(Jung-Ik) Lee static void atp867x_fixup(struct ata_host *host)
359d15d6e6cSJohn(Jung-Ik) Lee {
360d15d6e6cSJohn(Jung-Ik) Lee 	struct pci_dev *pdev = to_pci_dev(host->dev);
361d15d6e6cSJohn(Jung-Ik) Lee 	struct ata_port *ap = host->ports[0];
362d15d6e6cSJohn(Jung-Ik) Lee 	int i;
363d15d6e6cSJohn(Jung-Ik) Lee 	u8 v;
364d15d6e6cSJohn(Jung-Ik) Lee 
365d15d6e6cSJohn(Jung-Ik) Lee 	/*
366d15d6e6cSJohn(Jung-Ik) Lee 	 * Broken BIOS might not set latency high enough
367d15d6e6cSJohn(Jung-Ik) Lee 	 */
368d15d6e6cSJohn(Jung-Ik) Lee 	pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &v);
369d15d6e6cSJohn(Jung-Ik) Lee 	if (v < 0x80) {
370d15d6e6cSJohn(Jung-Ik) Lee 		v = 0x80;
371d15d6e6cSJohn(Jung-Ik) Lee 		pci_write_config_byte(pdev, PCI_LATENCY_TIMER, v);
372f2f01a52SHannes Reinecke 		dev_dbg(&pdev->dev, "ATP867X: set latency timer to %d\n", v);
373d15d6e6cSJohn(Jung-Ik) Lee 	}
374d15d6e6cSJohn(Jung-Ik) Lee 
375d15d6e6cSJohn(Jung-Ik) Lee 	/*
376d15d6e6cSJohn(Jung-Ik) Lee 	 * init 8bit io ports speed(0aaarrrr) to 43h and
377d15d6e6cSJohn(Jung-Ik) Lee 	 * init udma modes of master/slave to 0/0(11h)
378d15d6e6cSJohn(Jung-Ik) Lee 	 */
379d15d6e6cSJohn(Jung-Ik) Lee 	for (i = 0; i < ATP867X_NUM_PORTS; i++)
380d15d6e6cSJohn(Jung-Ik) Lee 		iowrite16(ATP867X_IO_PORTSPD_VAL, ATP867X_IO_PORTSPD(ap, i));
381d15d6e6cSJohn(Jung-Ik) Lee 
382d15d6e6cSJohn(Jung-Ik) Lee 	/*
383d15d6e6cSJohn(Jung-Ik) Lee 	 * init PreREAD counts
384d15d6e6cSJohn(Jung-Ik) Lee 	 */
385d15d6e6cSJohn(Jung-Ik) Lee 	for (i = 0; i < ATP867X_NUM_PORTS; i++)
386d15d6e6cSJohn(Jung-Ik) Lee 		iowrite16(ATP867X_PREREAD_VAL, ATP867X_IO_PREREAD(ap, i));
387d15d6e6cSJohn(Jung-Ik) Lee 
388d15d6e6cSJohn(Jung-Ik) Lee 	v = ioread8(ATP867X_IOBASE(ap) + 0x28);
389d15d6e6cSJohn(Jung-Ik) Lee 	v &= 0xcf;	/* Enable INTA#: bit4=0 means enable */
390d15d6e6cSJohn(Jung-Ik) Lee 	v |= 0xc0;	/* Enable PCI burst, MRM & not immediate interrupts */
391d15d6e6cSJohn(Jung-Ik) Lee 	iowrite8(v, ATP867X_IOBASE(ap) + 0x28);
392d15d6e6cSJohn(Jung-Ik) Lee 
393d15d6e6cSJohn(Jung-Ik) Lee 	/*
394d15d6e6cSJohn(Jung-Ik) Lee 	 * Turn off the over clocked udma5 mode, only for Rev-B
395d15d6e6cSJohn(Jung-Ik) Lee 	 */
396d15d6e6cSJohn(Jung-Ik) Lee 	v = ioread8(ATP867X_SYS_INFO(ap));
397d15d6e6cSJohn(Jung-Ik) Lee 	v &= ATP867X_IO_SYS_MASK_RESERVED;
398d15d6e6cSJohn(Jung-Ik) Lee 	if (pdev->device == PCI_DEVICE_ID_ARTOP_ATP867B)
399d15d6e6cSJohn(Jung-Ik) Lee 		v |= ATP867X_IO_SYS_INFO_SLOW_UDMA5;
400d15d6e6cSJohn(Jung-Ik) Lee 	iowrite8(v, ATP867X_SYS_INFO(ap));
401d15d6e6cSJohn(Jung-Ik) Lee }
402d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_ata_pci_sff_init_host(struct ata_host * host)403d15d6e6cSJohn(Jung-Ik) Lee static int atp867x_ata_pci_sff_init_host(struct ata_host *host)
404d15d6e6cSJohn(Jung-Ik) Lee {
405d15d6e6cSJohn(Jung-Ik) Lee 	struct device *gdev = host->dev;
406d15d6e6cSJohn(Jung-Ik) Lee 	struct pci_dev *pdev = to_pci_dev(gdev);
407d15d6e6cSJohn(Jung-Ik) Lee 	unsigned int mask = 0;
408d15d6e6cSJohn(Jung-Ik) Lee 	int i, rc;
409d15d6e6cSJohn(Jung-Ik) Lee 
410d15d6e6cSJohn(Jung-Ik) Lee 	/*
411d15d6e6cSJohn(Jung-Ik) Lee 	 * do not map rombase
412d15d6e6cSJohn(Jung-Ik) Lee 	 */
413d15d6e6cSJohn(Jung-Ik) Lee 	rc = pcim_iomap_regions(pdev, 1 << ATP867X_BAR_IOBASE, DRV_NAME);
414d15d6e6cSJohn(Jung-Ik) Lee 	if (rc == -EBUSY)
415d15d6e6cSJohn(Jung-Ik) Lee 		pcim_pin_device(pdev);
416d15d6e6cSJohn(Jung-Ik) Lee 	if (rc)
417d15d6e6cSJohn(Jung-Ik) Lee 		return rc;
418d15d6e6cSJohn(Jung-Ik) Lee 	host->iomap = pcim_iomap_table(pdev);
419d15d6e6cSJohn(Jung-Ik) Lee 
420d15d6e6cSJohn(Jung-Ik) Lee 	atp867x_check_res(pdev);
421d15d6e6cSJohn(Jung-Ik) Lee 
422c9c13ba4SDenis Efremov 	for (i = 0; i < PCI_STD_NUM_BARS; i++)
423f2f01a52SHannes Reinecke 		dev_dbg(gdev, "ATP867X: iomap[%d]=0x%p\n", i,
424f2f01a52SHannes Reinecke 			host->iomap[i]);
425d15d6e6cSJohn(Jung-Ik) Lee 
426d15d6e6cSJohn(Jung-Ik) Lee 	/*
427d15d6e6cSJohn(Jung-Ik) Lee 	 * request, iomap BARs and init port addresses accordingly
428d15d6e6cSJohn(Jung-Ik) Lee 	 */
429d15d6e6cSJohn(Jung-Ik) Lee 	for (i = 0; i < host->n_ports; i++) {
430d15d6e6cSJohn(Jung-Ik) Lee 		struct ata_port *ap = host->ports[i];
431d15d6e6cSJohn(Jung-Ik) Lee 		struct ata_ioports *ioaddr = &ap->ioaddr;
432d15d6e6cSJohn(Jung-Ik) Lee 
433d15d6e6cSJohn(Jung-Ik) Lee 		ioaddr->cmd_addr = ATP867X_IO_PORTBASE(ap, i);
434d15d6e6cSJohn(Jung-Ik) Lee 		ioaddr->ctl_addr = ioaddr->altstatus_addr
435d15d6e6cSJohn(Jung-Ik) Lee 				 = ATP867X_IO_ALTSTATUS(ap, i);
436d15d6e6cSJohn(Jung-Ik) Lee 		ioaddr->bmdma_addr = ATP867X_IO_DMABASE(ap, i);
437d15d6e6cSJohn(Jung-Ik) Lee 
438d15d6e6cSJohn(Jung-Ik) Lee 		ata_sff_std_ports(ioaddr);
439d15d6e6cSJohn(Jung-Ik) Lee 		rc = atp867x_set_priv(ap);
440d15d6e6cSJohn(Jung-Ik) Lee 		if (rc)
441d15d6e6cSJohn(Jung-Ik) Lee 			return rc;
442d15d6e6cSJohn(Jung-Ik) Lee 
443d15d6e6cSJohn(Jung-Ik) Lee 		atp867x_check_ports(ap, i);
444f2f01a52SHannes Reinecke 
445d15d6e6cSJohn(Jung-Ik) Lee 		ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx",
446d15d6e6cSJohn(Jung-Ik) Lee 			(unsigned long)ioaddr->cmd_addr,
447d15d6e6cSJohn(Jung-Ik) Lee 			(unsigned long)ioaddr->ctl_addr);
448d15d6e6cSJohn(Jung-Ik) Lee 		ata_port_desc(ap, "bmdma 0x%lx",
449d15d6e6cSJohn(Jung-Ik) Lee 			(unsigned long)ioaddr->bmdma_addr);
450d15d6e6cSJohn(Jung-Ik) Lee 
451d15d6e6cSJohn(Jung-Ik) Lee 		mask |= 1 << i;
452d15d6e6cSJohn(Jung-Ik) Lee 	}
453d15d6e6cSJohn(Jung-Ik) Lee 
454d15d6e6cSJohn(Jung-Ik) Lee 	if (!mask) {
455a44fec1fSJoe Perches 		dev_err(gdev, "no available native port\n");
456d15d6e6cSJohn(Jung-Ik) Lee 		return -ENODEV;
457d15d6e6cSJohn(Jung-Ik) Lee 	}
458d15d6e6cSJohn(Jung-Ik) Lee 
459d15d6e6cSJohn(Jung-Ik) Lee 	atp867x_fixup(host);
460d15d6e6cSJohn(Jung-Ik) Lee 
461b5e55556SChristoph Hellwig 	return dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK);
462d15d6e6cSJohn(Jung-Ik) Lee }
463d15d6e6cSJohn(Jung-Ik) Lee 
atp867x_init_one(struct pci_dev * pdev,const struct pci_device_id * id)464d15d6e6cSJohn(Jung-Ik) Lee static int atp867x_init_one(struct pci_dev *pdev,
465d15d6e6cSJohn(Jung-Ik) Lee 	const struct pci_device_id *id)
466d15d6e6cSJohn(Jung-Ik) Lee {
467d15d6e6cSJohn(Jung-Ik) Lee 	static const struct ata_port_info info_867x = {
468d15d6e6cSJohn(Jung-Ik) Lee 		.flags		= ATA_FLAG_SLAVE_POSS,
469d15d6e6cSJohn(Jung-Ik) Lee 		.pio_mask	= ATA_PIO4,
470d15d6e6cSJohn(Jung-Ik) Lee 		.udma_mask 	= ATA_UDMA6,
471d15d6e6cSJohn(Jung-Ik) Lee 		.port_ops	= &atp867x_ops,
472d15d6e6cSJohn(Jung-Ik) Lee 	};
473d15d6e6cSJohn(Jung-Ik) Lee 
474d15d6e6cSJohn(Jung-Ik) Lee 	struct ata_host *host;
475d15d6e6cSJohn(Jung-Ik) Lee 	const struct ata_port_info *ppi[] = { &info_867x, NULL };
476d15d6e6cSJohn(Jung-Ik) Lee 	int rc;
477d15d6e6cSJohn(Jung-Ik) Lee 
47806296a1eSJoe Perches 	ata_print_version_once(&pdev->dev, DRV_VERSION);
479d15d6e6cSJohn(Jung-Ik) Lee 
480d15d6e6cSJohn(Jung-Ik) Lee 	rc = pcim_enable_device(pdev);
481d15d6e6cSJohn(Jung-Ik) Lee 	if (rc)
482d15d6e6cSJohn(Jung-Ik) Lee 		return rc;
483d15d6e6cSJohn(Jung-Ik) Lee 
484f2f01a52SHannes Reinecke 	dev_info(&pdev->dev, "ATP867X: ATP867 ATA UDMA133 controller (rev %02X)",
485d15d6e6cSJohn(Jung-Ik) Lee 		pdev->device);
486d15d6e6cSJohn(Jung-Ik) Lee 
487d15d6e6cSJohn(Jung-Ik) Lee 	host = ata_host_alloc_pinfo(&pdev->dev, ppi, ATP867X_NUM_PORTS);
488d15d6e6cSJohn(Jung-Ik) Lee 	if (!host) {
489a44fec1fSJoe Perches 		dev_err(&pdev->dev, "failed to allocate ATA host\n");
490d15d6e6cSJohn(Jung-Ik) Lee 		rc = -ENOMEM;
491d15d6e6cSJohn(Jung-Ik) Lee 		goto err_out;
492d15d6e6cSJohn(Jung-Ik) Lee 	}
493d15d6e6cSJohn(Jung-Ik) Lee 
494d15d6e6cSJohn(Jung-Ik) Lee 	rc = atp867x_ata_pci_sff_init_host(host);
495d15d6e6cSJohn(Jung-Ik) Lee 	if (rc) {
496a44fec1fSJoe Perches 		dev_err(&pdev->dev, "failed to init host\n");
497d15d6e6cSJohn(Jung-Ik) Lee 		goto err_out;
498d15d6e6cSJohn(Jung-Ik) Lee 	}
499d15d6e6cSJohn(Jung-Ik) Lee 
500d15d6e6cSJohn(Jung-Ik) Lee 	pci_set_master(pdev);
501d15d6e6cSJohn(Jung-Ik) Lee 
502c3b28894STejun Heo 	rc = ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
503d15d6e6cSJohn(Jung-Ik) Lee 				IRQF_SHARED, &atp867x_sht);
504d15d6e6cSJohn(Jung-Ik) Lee 	if (rc)
505a44fec1fSJoe Perches 		dev_err(&pdev->dev, "failed to activate host\n");
506d15d6e6cSJohn(Jung-Ik) Lee 
507d15d6e6cSJohn(Jung-Ik) Lee err_out:
508d15d6e6cSJohn(Jung-Ik) Lee 	return rc;
509d15d6e6cSJohn(Jung-Ik) Lee }
510d15d6e6cSJohn(Jung-Ik) Lee 
51158eb8cd5SBartlomiej Zolnierkiewicz #ifdef CONFIG_PM_SLEEP
atp867x_reinit_one(struct pci_dev * pdev)5127affb32aSBartlomiej Zolnierkiewicz static int atp867x_reinit_one(struct pci_dev *pdev)
5137affb32aSBartlomiej Zolnierkiewicz {
5140a86e1c8SJingoo Han 	struct ata_host *host = pci_get_drvdata(pdev);
5157affb32aSBartlomiej Zolnierkiewicz 	int rc;
5167affb32aSBartlomiej Zolnierkiewicz 
5177affb32aSBartlomiej Zolnierkiewicz 	rc = ata_pci_device_do_resume(pdev);
5187affb32aSBartlomiej Zolnierkiewicz 	if (rc)
5197affb32aSBartlomiej Zolnierkiewicz 		return rc;
5207affb32aSBartlomiej Zolnierkiewicz 
5217affb32aSBartlomiej Zolnierkiewicz 	atp867x_fixup(host);
5227affb32aSBartlomiej Zolnierkiewicz 
5237affb32aSBartlomiej Zolnierkiewicz 	ata_host_resume(host);
5247affb32aSBartlomiej Zolnierkiewicz 	return 0;
5257affb32aSBartlomiej Zolnierkiewicz }
5267affb32aSBartlomiej Zolnierkiewicz #endif
5277affb32aSBartlomiej Zolnierkiewicz 
528d15d6e6cSJohn(Jung-Ik) Lee static struct pci_device_id atp867x_pci_tbl[] = {
529d15d6e6cSJohn(Jung-Ik) Lee 	{ PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP867A),	0 },
530d15d6e6cSJohn(Jung-Ik) Lee 	{ PCI_VDEVICE(ARTOP, PCI_DEVICE_ID_ARTOP_ATP867B),	0 },
531d15d6e6cSJohn(Jung-Ik) Lee 	{ },
532d15d6e6cSJohn(Jung-Ik) Lee };
533d15d6e6cSJohn(Jung-Ik) Lee 
534d15d6e6cSJohn(Jung-Ik) Lee static struct pci_driver atp867x_driver = {
535d15d6e6cSJohn(Jung-Ik) Lee 	.name 		= DRV_NAME,
536d15d6e6cSJohn(Jung-Ik) Lee 	.id_table 	= atp867x_pci_tbl,
537d15d6e6cSJohn(Jung-Ik) Lee 	.probe 		= atp867x_init_one,
538d15d6e6cSJohn(Jung-Ik) Lee 	.remove		= ata_pci_remove_one,
53958eb8cd5SBartlomiej Zolnierkiewicz #ifdef CONFIG_PM_SLEEP
5407affb32aSBartlomiej Zolnierkiewicz 	.suspend	= ata_pci_device_suspend,
5417affb32aSBartlomiej Zolnierkiewicz 	.resume		= atp867x_reinit_one,
5427affb32aSBartlomiej Zolnierkiewicz #endif
543d15d6e6cSJohn(Jung-Ik) Lee };
544d15d6e6cSJohn(Jung-Ik) Lee 
5452fc75da0SAxel Lin module_pci_driver(atp867x_driver);
546d15d6e6cSJohn(Jung-Ik) Lee 
547d15d6e6cSJohn(Jung-Ik) Lee MODULE_AUTHOR("John(Jung-Ik) Lee, Google Inc.");
548d15d6e6cSJohn(Jung-Ik) Lee MODULE_DESCRIPTION("low level driver for Artop/Acard 867x ATA controller");
549d15d6e6cSJohn(Jung-Ik) Lee MODULE_LICENSE("GPL");
550d15d6e6cSJohn(Jung-Ik) Lee MODULE_DEVICE_TABLE(pci, atp867x_pci_tbl);
551d15d6e6cSJohn(Jung-Ik) Lee MODULE_VERSION(DRV_VERSION);
552