pata_scc.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. * Support for IDE interfaces on Celleb platform
  3. *
  4. * (C) Copyright 2006 TOSHIBA CORPORATION
  5. *
  6. * This code is based on drivers/ata/ata_piix.c:
  7. * Copyright 2003-2005 Red Hat Inc
  8. * Copyright 2003-2005 Jeff Garzik
  9. * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
  10. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  11. * Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
  12. *
  13. * and drivers/ata/ahci.c:
  14. * Copyright 2004-2005 Red Hat, Inc.
  15. *
  16. * and drivers/ata/libata-core.c:
  17. * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
  18. * Copyright 2003-2004 Jeff Garzik
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License along
  31. * with this program; if not, write to the Free Software Foundation, Inc.,
  32. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/pci.h>
  37. #include <linux/init.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/delay.h>
  40. #include <linux/device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <linux/libata.h>
  43. #define DRV_NAME "pata_scc"
  44. #define DRV_VERSION "0.2"
  45. #define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
  46. /* PCI BARs */
  47. #define SCC_CTRL_BAR 0
  48. #define SCC_BMID_BAR 1
  49. /* offset of CTRL registers */
  50. #define SCC_CTL_PIOSHT 0x000
  51. #define SCC_CTL_PIOCT 0x004
  52. #define SCC_CTL_MDMACT 0x008
  53. #define SCC_CTL_MCRCST 0x00C
  54. #define SCC_CTL_SDMACT 0x010
  55. #define SCC_CTL_SCRCST 0x014
  56. #define SCC_CTL_UDENVT 0x018
  57. #define SCC_CTL_TDVHSEL 0x020
  58. #define SCC_CTL_MODEREG 0x024
  59. #define SCC_CTL_ECMODE 0xF00
  60. #define SCC_CTL_MAEA0 0xF50
  61. #define SCC_CTL_MAEC0 0xF54
  62. #define SCC_CTL_CCKCTRL 0xFF0
  63. /* offset of BMID registers */
  64. #define SCC_DMA_CMD 0x000
  65. #define SCC_DMA_STATUS 0x004
  66. #define SCC_DMA_TABLE_OFS 0x008
  67. #define SCC_DMA_INTMASK 0x010
  68. #define SCC_DMA_INTST 0x014
  69. #define SCC_DMA_PTERADD 0x018
  70. #define SCC_REG_CMD_ADDR 0x020
  71. #define SCC_REG_DATA 0x000
  72. #define SCC_REG_ERR 0x004
  73. #define SCC_REG_FEATURE 0x004
  74. #define SCC_REG_NSECT 0x008
  75. #define SCC_REG_LBAL 0x00C
  76. #define SCC_REG_LBAM 0x010
  77. #define SCC_REG_LBAH 0x014
  78. #define SCC_REG_DEVICE 0x018
  79. #define SCC_REG_STATUS 0x01C
  80. #define SCC_REG_CMD 0x01C
  81. #define SCC_REG_ALTSTATUS 0x020
  82. /* register value */
  83. #define TDVHSEL_MASTER 0x00000001
  84. #define TDVHSEL_SLAVE 0x00000004
  85. #define MODE_JCUSFEN 0x00000080
  86. #define ECMODE_VALUE 0x01
  87. #define CCKCTRL_ATARESET 0x00040000
  88. #define CCKCTRL_BUFCNT 0x00020000
  89. #define CCKCTRL_CRST 0x00010000
  90. #define CCKCTRL_OCLKEN 0x00000100
  91. #define CCKCTRL_ATACLKOEN 0x00000002
  92. #define CCKCTRL_LCLKEN 0x00000001
  93. #define QCHCD_IOS_SS 0x00000001
  94. #define QCHSD_STPDIAG 0x00020000
  95. #define INTMASK_MSK 0xD1000012
  96. #define INTSTS_SERROR 0x80000000
  97. #define INTSTS_PRERR 0x40000000
  98. #define INTSTS_RERR 0x10000000
  99. #define INTSTS_ICERR 0x01000000
  100. #define INTSTS_BMSINT 0x00000010
  101. #define INTSTS_BMHE 0x00000008
  102. #define INTSTS_IOIRQS 0x00000004
  103. #define INTSTS_INTRQ 0x00000002
  104. #define INTSTS_ACTEINT 0x00000001
  105. /* PIO transfer mode table */
  106. /* JCHST */
  107. static const unsigned long JCHSTtbl[2][7] = {
  108. {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
  109. {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
  110. };
  111. /* JCHHT */
  112. static const unsigned long JCHHTtbl[2][7] = {
  113. {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
  114. {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
  115. };
  116. /* JCHCT */
  117. static const unsigned long JCHCTtbl[2][7] = {
  118. {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
  119. {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
  120. };
  121. /* DMA transfer mode table */
  122. /* JCHDCTM/JCHDCTS */
  123. static const unsigned long JCHDCTxtbl[2][7] = {
  124. {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
  125. {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
  126. };
  127. /* JCSTWTM/JCSTWTS */
  128. static const unsigned long JCSTWTxtbl[2][7] = {
  129. {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
  130. {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
  131. };
  132. /* JCTSS */
  133. static const unsigned long JCTSStbl[2][7] = {
  134. {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
  135. {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
  136. };
  137. /* JCENVT */
  138. static const unsigned long JCENVTtbl[2][7] = {
  139. {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
  140. {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
  141. };
  142. /* JCACTSELS/JCACTSELM */
  143. static const unsigned long JCACTSELtbl[2][7] = {
  144. {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
  145. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
  146. };
  147. static const struct pci_device_id scc_pci_tbl[] = {
  148. {PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA,
  149. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  150. { } /* terminate list */
  151. };
  152. /**
  153. * scc_set_piomode - Initialize host controller PATA PIO timings
  154. * @ap: Port whose timings we are configuring
  155. * @adev: um
  156. *
  157. * Set PIO mode for device.
  158. *
  159. * LOCKING:
  160. * None (inherited from caller).
  161. */
  162. static void scc_set_piomode (struct ata_port *ap, struct ata_device *adev)
  163. {
  164. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  165. void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
  166. void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
  167. void __iomem *piosht_port = ctrl_base + SCC_CTL_PIOSHT;
  168. void __iomem *pioct_port = ctrl_base + SCC_CTL_PIOCT;
  169. unsigned long reg;
  170. int offset;
  171. reg = in_be32(cckctrl_port);
  172. if (reg & CCKCTRL_ATACLKOEN)
  173. offset = 1; /* 133MHz */
  174. else
  175. offset = 0; /* 100MHz */
  176. reg = JCHSTtbl[offset][pio] << 16 | JCHHTtbl[offset][pio];
  177. out_be32(piosht_port, reg);
  178. reg = JCHCTtbl[offset][pio];
  179. out_be32(pioct_port, reg);
  180. }
  181. /**
  182. * scc_set_dmamode - Initialize host controller PATA DMA timings
  183. * @ap: Port whose timings we are configuring
  184. * @adev: um
  185. * @udma: udma mode, 0 - 6
  186. *
  187. * Set UDMA mode for device.
  188. *
  189. * LOCKING:
  190. * None (inherited from caller).
  191. */
  192. static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  193. {
  194. unsigned int udma = adev->dma_mode;
  195. unsigned int is_slave = (adev->devno != 0);
  196. u8 speed = udma;
  197. void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
  198. void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
  199. void __iomem *mdmact_port = ctrl_base + SCC_CTL_MDMACT;
  200. void __iomem *mcrcst_port = ctrl_base + SCC_CTL_MCRCST;
  201. void __iomem *sdmact_port = ctrl_base + SCC_CTL_SDMACT;
  202. void __iomem *scrcst_port = ctrl_base + SCC_CTL_SCRCST;
  203. void __iomem *udenvt_port = ctrl_base + SCC_CTL_UDENVT;
  204. void __iomem *tdvhsel_port = ctrl_base + SCC_CTL_TDVHSEL;
  205. int offset, idx;
  206. if (in_be32(cckctrl_port) & CCKCTRL_ATACLKOEN)
  207. offset = 1; /* 133MHz */
  208. else
  209. offset = 0; /* 100MHz */
  210. if (speed >= XFER_UDMA_0)
  211. idx = speed - XFER_UDMA_0;
  212. else
  213. return;
  214. if (is_slave) {
  215. out_be32(sdmact_port, JCHDCTxtbl[offset][idx]);
  216. out_be32(scrcst_port, JCSTWTxtbl[offset][idx]);
  217. out_be32(tdvhsel_port,
  218. (in_be32(tdvhsel_port) & ~TDVHSEL_SLAVE) | (JCACTSELtbl[offset][idx] << 2));
  219. } else {
  220. out_be32(mdmact_port, JCHDCTxtbl[offset][idx]);
  221. out_be32(mcrcst_port, JCSTWTxtbl[offset][idx]);
  222. out_be32(tdvhsel_port,
  223. (in_be32(tdvhsel_port) & ~TDVHSEL_MASTER) | JCACTSELtbl[offset][idx]);
  224. }
  225. out_be32(udenvt_port,
  226. JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]);
  227. }
  228. /**
  229. * scc_tf_load - send taskfile registers to host controller
  230. * @ap: Port to which output is sent
  231. * @tf: ATA taskfile register set
  232. *
  233. * Note: Original code is ata_tf_load().
  234. */
  235. static void scc_tf_load (struct ata_port *ap, const struct ata_taskfile *tf)
  236. {
  237. struct ata_ioports *ioaddr = &ap->ioaddr;
  238. unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
  239. if (tf->ctl != ap->last_ctl) {
  240. out_be32(ioaddr->ctl_addr, tf->ctl);
  241. ap->last_ctl = tf->ctl;
  242. ata_wait_idle(ap);
  243. }
  244. if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
  245. out_be32(ioaddr->feature_addr, tf->hob_feature);
  246. out_be32(ioaddr->nsect_addr, tf->hob_nsect);
  247. out_be32(ioaddr->lbal_addr, tf->hob_lbal);
  248. out_be32(ioaddr->lbam_addr, tf->hob_lbam);
  249. out_be32(ioaddr->lbah_addr, tf->hob_lbah);
  250. VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
  251. tf->hob_feature,
  252. tf->hob_nsect,
  253. tf->hob_lbal,
  254. tf->hob_lbam,
  255. tf->hob_lbah);
  256. }
  257. if (is_addr) {
  258. out_be32(ioaddr->feature_addr, tf->feature);
  259. out_be32(ioaddr->nsect_addr, tf->nsect);
  260. out_be32(ioaddr->lbal_addr, tf->lbal);
  261. out_be32(ioaddr->lbam_addr, tf->lbam);
  262. out_be32(ioaddr->lbah_addr, tf->lbah);
  263. VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
  264. tf->feature,
  265. tf->nsect,
  266. tf->lbal,
  267. tf->lbam,
  268. tf->lbah);
  269. }
  270. if (tf->flags & ATA_TFLAG_DEVICE) {
  271. out_be32(ioaddr->device_addr, tf->device);
  272. VPRINTK("device 0x%X\n", tf->device);
  273. }
  274. ata_wait_idle(ap);
  275. }
  276. /**
  277. * scc_check_status - Read device status reg & clear interrupt
  278. * @ap: port where the device is
  279. *
  280. * Note: Original code is ata_check_status().
  281. */
  282. static u8 scc_check_status (struct ata_port *ap)
  283. {
  284. return in_be32(ap->ioaddr.status_addr);
  285. }
  286. /**
  287. * scc_tf_read - input device's ATA taskfile shadow registers
  288. * @ap: Port from which input is read
  289. * @tf: ATA taskfile register set for storing input
  290. *
  291. * Note: Original code is ata_tf_read().
  292. */
  293. static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf)
  294. {
  295. struct ata_ioports *ioaddr = &ap->ioaddr;
  296. tf->command = scc_check_status(ap);
  297. tf->feature = in_be32(ioaddr->error_addr);
  298. tf->nsect = in_be32(ioaddr->nsect_addr);
  299. tf->lbal = in_be32(ioaddr->lbal_addr);
  300. tf->lbam = in_be32(ioaddr->lbam_addr);
  301. tf->lbah = in_be32(ioaddr->lbah_addr);
  302. tf->device = in_be32(ioaddr->device_addr);
  303. if (tf->flags & ATA_TFLAG_LBA48) {
  304. out_be32(ioaddr->ctl_addr, tf->ctl | ATA_HOB);
  305. tf->hob_feature = in_be32(ioaddr->error_addr);
  306. tf->hob_nsect = in_be32(ioaddr->nsect_addr);
  307. tf->hob_lbal = in_be32(ioaddr->lbal_addr);
  308. tf->hob_lbam = in_be32(ioaddr->lbam_addr);
  309. tf->hob_lbah = in_be32(ioaddr->lbah_addr);
  310. }
  311. }
  312. /**
  313. * scc_exec_command - issue ATA command to host controller
  314. * @ap: port to which command is being issued
  315. * @tf: ATA taskfile register set
  316. *
  317. * Note: Original code is ata_exec_command().
  318. */
  319. static void scc_exec_command (struct ata_port *ap,
  320. const struct ata_taskfile *tf)
  321. {
  322. DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
  323. out_be32(ap->ioaddr.command_addr, tf->command);
  324. ata_pause(ap);
  325. }
  326. /**
  327. * scc_check_altstatus - Read device alternate status reg
  328. * @ap: port where the device is
  329. */
  330. static u8 scc_check_altstatus (struct ata_port *ap)
  331. {
  332. return in_be32(ap->ioaddr.altstatus_addr);
  333. }
  334. /**
  335. * scc_std_dev_select - Select device 0/1 on ATA bus
  336. * @ap: ATA channel to manipulate
  337. * @device: ATA device (numbered from zero) to select
  338. *
  339. * Note: Original code is ata_std_dev_select().
  340. */
  341. static void scc_std_dev_select (struct ata_port *ap, unsigned int device)
  342. {
  343. u8 tmp;
  344. if (device == 0)
  345. tmp = ATA_DEVICE_OBS;
  346. else
  347. tmp = ATA_DEVICE_OBS | ATA_DEV1;
  348. out_be32(ap->ioaddr.device_addr, tmp);
  349. ata_pause(ap);
  350. }
  351. /**
  352. * scc_bmdma_setup - Set up PCI IDE BMDMA transaction
  353. * @qc: Info associated with this ATA transaction.
  354. *
  355. * Note: Original code is ata_bmdma_setup().
  356. */
  357. static void scc_bmdma_setup (struct ata_queued_cmd *qc)
  358. {
  359. struct ata_port *ap = qc->ap;
  360. unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
  361. u8 dmactl;
  362. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  363. /* load PRD table addr */
  364. out_be32(mmio + SCC_DMA_TABLE_OFS, ap->prd_dma);
  365. /* specify data direction, triple-check start bit is clear */
  366. dmactl = in_be32(mmio + SCC_DMA_CMD);
  367. dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
  368. if (!rw)
  369. dmactl |= ATA_DMA_WR;
  370. out_be32(mmio + SCC_DMA_CMD, dmactl);
  371. /* issue r/w command */
  372. ap->ops->exec_command(ap, &qc->tf);
  373. }
  374. /**
  375. * scc_bmdma_start - Start a PCI IDE BMDMA transaction
  376. * @qc: Info associated with this ATA transaction.
  377. *
  378. * Note: Original code is ata_bmdma_start().
  379. */
  380. static void scc_bmdma_start (struct ata_queued_cmd *qc)
  381. {
  382. struct ata_port *ap = qc->ap;
  383. u8 dmactl;
  384. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  385. /* start host DMA transaction */
  386. dmactl = in_be32(mmio + SCC_DMA_CMD);
  387. out_be32(mmio + SCC_DMA_CMD, dmactl | ATA_DMA_START);
  388. }
  389. /**
  390. * scc_devchk - PATA device presence detection
  391. * @ap: ATA channel to examine
  392. * @device: Device to examine (starting at zero)
  393. *
  394. * Note: Original code is ata_devchk().
  395. */
  396. static unsigned int scc_devchk (struct ata_port *ap,
  397. unsigned int device)
  398. {
  399. struct ata_ioports *ioaddr = &ap->ioaddr;
  400. u8 nsect, lbal;
  401. ap->ops->dev_select(ap, device);
  402. out_be32(ioaddr->nsect_addr, 0x55);
  403. out_be32(ioaddr->lbal_addr, 0xaa);
  404. out_be32(ioaddr->nsect_addr, 0xaa);
  405. out_be32(ioaddr->lbal_addr, 0x55);
  406. out_be32(ioaddr->nsect_addr, 0x55);
  407. out_be32(ioaddr->lbal_addr, 0xaa);
  408. nsect = in_be32(ioaddr->nsect_addr);
  409. lbal = in_be32(ioaddr->lbal_addr);
  410. if ((nsect == 0x55) && (lbal == 0xaa))
  411. return 1; /* we found a device */
  412. return 0; /* nothing found */
  413. }
  414. /**
  415. * scc_bus_post_reset - PATA device post reset
  416. *
  417. * Note: Original code is ata_bus_post_reset().
  418. */
  419. static int scc_bus_post_reset(struct ata_port *ap, unsigned int devmask,
  420. unsigned long deadline)
  421. {
  422. struct ata_ioports *ioaddr = &ap->ioaddr;
  423. unsigned int dev0 = devmask & (1 << 0);
  424. unsigned int dev1 = devmask & (1 << 1);
  425. int rc;
  426. /* if device 0 was found in ata_devchk, wait for its
  427. * BSY bit to clear
  428. */
  429. if (dev0) {
  430. rc = ata_wait_ready(ap, deadline);
  431. if (rc && rc != -ENODEV)
  432. return rc;
  433. }
  434. /* if device 1 was found in ata_devchk, wait for
  435. * register access, then wait for BSY to clear
  436. */
  437. while (dev1) {
  438. u8 nsect, lbal;
  439. ap->ops->dev_select(ap, 1);
  440. nsect = in_be32(ioaddr->nsect_addr);
  441. lbal = in_be32(ioaddr->lbal_addr);
  442. if ((nsect == 1) && (lbal == 1))
  443. break;
  444. if (time_after(jiffies, deadline))
  445. return -EBUSY;
  446. msleep(50); /* give drive a breather */
  447. }
  448. if (dev1) {
  449. rc = ata_wait_ready(ap, deadline);
  450. if (rc && rc != -ENODEV)
  451. return rc;
  452. }
  453. /* is all this really necessary? */
  454. ap->ops->dev_select(ap, 0);
  455. if (dev1)
  456. ap->ops->dev_select(ap, 1);
  457. if (dev0)
  458. ap->ops->dev_select(ap, 0);
  459. return 0;
  460. }
  461. /**
  462. * scc_bus_softreset - PATA device software reset
  463. *
  464. * Note: Original code is ata_bus_softreset().
  465. */
  466. static unsigned int scc_bus_softreset(struct ata_port *ap, unsigned int devmask,
  467. unsigned long deadline)
  468. {
  469. struct ata_ioports *ioaddr = &ap->ioaddr;
  470. DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
  471. /* software reset. causes dev0 to be selected */
  472. out_be32(ioaddr->ctl_addr, ap->ctl);
  473. udelay(20);
  474. out_be32(ioaddr->ctl_addr, ap->ctl | ATA_SRST);
  475. udelay(20);
  476. out_be32(ioaddr->ctl_addr, ap->ctl);
  477. /* spec mandates ">= 2ms" before checking status.
  478. * We wait 150ms, because that was the magic delay used for
  479. * ATAPI devices in Hale Landis's ATADRVR, for the period of time
  480. * between when the ATA command register is written, and then
  481. * status is checked. Because waiting for "a while" before
  482. * checking status is fine, post SRST, we perform this magic
  483. * delay here as well.
  484. *
  485. * Old drivers/ide uses the 2mS rule and then waits for ready
  486. */
  487. msleep(150);
  488. /* Before we perform post reset processing we want to see if
  489. * the bus shows 0xFF because the odd clown forgets the D7
  490. * pulldown resistor.
  491. */
  492. if (scc_check_status(ap) == 0xFF)
  493. return 0;
  494. scc_bus_post_reset(ap, devmask, deadline);
  495. return 0;
  496. }
  497. /**
  498. * scc_std_softreset - reset host port via ATA SRST
  499. * @ap: port to reset
  500. * @classes: resulting classes of attached devices
  501. * @deadline: deadline jiffies for the operation
  502. *
  503. * Note: Original code is ata_std_softreset().
  504. */
  505. static int scc_std_softreset (struct ata_port *ap, unsigned int *classes,
  506. unsigned long deadline)
  507. {
  508. unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
  509. unsigned int devmask = 0, err_mask;
  510. u8 err;
  511. DPRINTK("ENTER\n");
  512. if (ata_port_offline(ap)) {
  513. classes[0] = ATA_DEV_NONE;
  514. goto out;
  515. }
  516. /* determine if device 0/1 are present */
  517. if (scc_devchk(ap, 0))
  518. devmask |= (1 << 0);
  519. if (slave_possible && scc_devchk(ap, 1))
  520. devmask |= (1 << 1);
  521. /* select device 0 again */
  522. ap->ops->dev_select(ap, 0);
  523. /* issue bus reset */
  524. DPRINTK("about to softreset, devmask=%x\n", devmask);
  525. err_mask = scc_bus_softreset(ap, devmask, deadline);
  526. if (err_mask) {
  527. ata_port_printk(ap, KERN_ERR, "SRST failed (err_mask=0x%x)\n",
  528. err_mask);
  529. return -EIO;
  530. }
  531. /* determine by signature whether we have ATA or ATAPI devices */
  532. classes[0] = ata_dev_try_classify(ap, 0, &err);
  533. if (slave_possible && err != 0x81)
  534. classes[1] = ata_dev_try_classify(ap, 1, &err);
  535. out:
  536. DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
  537. return 0;
  538. }
  539. /**
  540. * scc_bmdma_stop - Stop PCI IDE BMDMA transfer
  541. * @qc: Command we are ending DMA for
  542. */
  543. static void scc_bmdma_stop (struct ata_queued_cmd *qc)
  544. {
  545. struct ata_port *ap = qc->ap;
  546. void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
  547. void __iomem *bmid_base = ap->host->iomap[SCC_BMID_BAR];
  548. u32 reg;
  549. while (1) {
  550. reg = in_be32(bmid_base + SCC_DMA_INTST);
  551. if (reg & INTSTS_SERROR) {
  552. printk(KERN_WARNING "%s: SERROR\n", DRV_NAME);
  553. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_SERROR|INTSTS_BMSINT);
  554. out_be32(bmid_base + SCC_DMA_CMD,
  555. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  556. continue;
  557. }
  558. if (reg & INTSTS_PRERR) {
  559. u32 maea0, maec0;
  560. maea0 = in_be32(ctrl_base + SCC_CTL_MAEA0);
  561. maec0 = in_be32(ctrl_base + SCC_CTL_MAEC0);
  562. printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", DRV_NAME, maea0, maec0);
  563. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_PRERR|INTSTS_BMSINT);
  564. out_be32(bmid_base + SCC_DMA_CMD,
  565. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  566. continue;
  567. }
  568. if (reg & INTSTS_RERR) {
  569. printk(KERN_WARNING "%s: Response Error\n", DRV_NAME);
  570. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_RERR|INTSTS_BMSINT);
  571. out_be32(bmid_base + SCC_DMA_CMD,
  572. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  573. continue;
  574. }
  575. if (reg & INTSTS_ICERR) {
  576. out_be32(bmid_base + SCC_DMA_CMD,
  577. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  578. printk(KERN_WARNING "%s: Illegal Configuration\n", DRV_NAME);
  579. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ICERR|INTSTS_BMSINT);
  580. continue;
  581. }
  582. if (reg & INTSTS_BMSINT) {
  583. unsigned int classes;
  584. unsigned long deadline = jiffies + ATA_TMOUT_BOOT;
  585. printk(KERN_WARNING "%s: Internal Bus Error\n", DRV_NAME);
  586. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMSINT);
  587. /* TBD: SW reset */
  588. scc_std_softreset(ap, &classes, deadline);
  589. continue;
  590. }
  591. if (reg & INTSTS_BMHE) {
  592. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMHE);
  593. continue;
  594. }
  595. if (reg & INTSTS_ACTEINT) {
  596. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ACTEINT);
  597. continue;
  598. }
  599. if (reg & INTSTS_IOIRQS) {
  600. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_IOIRQS);
  601. continue;
  602. }
  603. break;
  604. }
  605. /* clear start/stop bit */
  606. out_be32(bmid_base + SCC_DMA_CMD,
  607. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  608. /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
  609. ata_altstatus(ap); /* dummy read */
  610. }
  611. /**
  612. * scc_bmdma_status - Read PCI IDE BMDMA status
  613. * @ap: Port associated with this ATA transaction.
  614. */
  615. static u8 scc_bmdma_status (struct ata_port *ap)
  616. {
  617. u8 host_stat;
  618. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  619. host_stat = in_be32(mmio + SCC_DMA_STATUS);
  620. /* Workaround for PTERADD: emulate DMA_INTR when
  621. * - IDE_STATUS[ERR] = 1
  622. * - INT_STATUS[INTRQ] = 1
  623. * - DMA_STATUS[IORACTA] = 1
  624. */
  625. if (!(host_stat & ATA_DMA_INTR)) {
  626. u32 int_status = in_be32(mmio + SCC_DMA_INTST);
  627. if (ata_altstatus(ap) & ATA_ERR &&
  628. int_status & INTSTS_INTRQ &&
  629. host_stat & ATA_DMA_ACTIVE)
  630. host_stat |= ATA_DMA_INTR;
  631. }
  632. return host_stat;
  633. }
  634. /**
  635. * scc_data_xfer - Transfer data by PIO
  636. * @adev: device for this I/O
  637. * @buf: data buffer
  638. * @buflen: buffer length
  639. * @write_data: read/write
  640. *
  641. * Note: Original code is ata_data_xfer().
  642. */
  643. static void scc_data_xfer (struct ata_device *adev, unsigned char *buf,
  644. unsigned int buflen, int write_data)
  645. {
  646. struct ata_port *ap = adev->ap;
  647. unsigned int words = buflen >> 1;
  648. unsigned int i;
  649. u16 *buf16 = (u16 *) buf;
  650. void __iomem *mmio = ap->ioaddr.data_addr;
  651. /* Transfer multiple of 2 bytes */
  652. if (write_data) {
  653. for (i = 0; i < words; i++)
  654. out_be32(mmio, cpu_to_le16(buf16[i]));
  655. } else {
  656. for (i = 0; i < words; i++)
  657. buf16[i] = le16_to_cpu(in_be32(mmio));
  658. }
  659. /* Transfer trailing 1 byte, if any. */
  660. if (unlikely(buflen & 0x01)) {
  661. u16 align_buf[1] = { 0 };
  662. unsigned char *trailing_buf = buf + buflen - 1;
  663. if (write_data) {
  664. memcpy(align_buf, trailing_buf, 1);
  665. out_be32(mmio, cpu_to_le16(align_buf[0]));
  666. } else {
  667. align_buf[0] = le16_to_cpu(in_be32(mmio));
  668. memcpy(trailing_buf, align_buf, 1);
  669. }
  670. }
  671. }
  672. /**
  673. * scc_irq_on - Enable interrupts on a port.
  674. * @ap: Port on which interrupts are enabled.
  675. *
  676. * Note: Original code is ata_irq_on().
  677. */
  678. static u8 scc_irq_on (struct ata_port *ap)
  679. {
  680. struct ata_ioports *ioaddr = &ap->ioaddr;
  681. u8 tmp;
  682. ap->ctl &= ~ATA_NIEN;
  683. ap->last_ctl = ap->ctl;
  684. out_be32(ioaddr->ctl_addr, ap->ctl);
  685. tmp = ata_wait_idle(ap);
  686. ap->ops->irq_clear(ap);
  687. return tmp;
  688. }
  689. /**
  690. * scc_irq_ack - Acknowledge a device interrupt.
  691. * @ap: Port on which interrupts are enabled.
  692. *
  693. * Note: Original code is ata_irq_ack().
  694. */
  695. static u8 scc_irq_ack (struct ata_port *ap, unsigned int chk_drq)
  696. {
  697. unsigned int bits = chk_drq ? ATA_BUSY | ATA_DRQ : ATA_BUSY;
  698. u8 host_stat, post_stat, status;
  699. status = ata_busy_wait(ap, bits, 1000);
  700. if (status & bits)
  701. if (ata_msg_err(ap))
  702. printk(KERN_ERR "abnormal status 0x%X\n", status);
  703. /* get controller status; clear intr, err bits */
  704. host_stat = in_be32(ap->ioaddr.bmdma_addr + SCC_DMA_STATUS);
  705. out_be32(ap->ioaddr.bmdma_addr + SCC_DMA_STATUS,
  706. host_stat | ATA_DMA_INTR | ATA_DMA_ERR);
  707. post_stat = in_be32(ap->ioaddr.bmdma_addr + SCC_DMA_STATUS);
  708. if (ata_msg_intr(ap))
  709. printk(KERN_INFO "%s: irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n",
  710. __FUNCTION__,
  711. host_stat, post_stat, status);
  712. return status;
  713. }
  714. /**
  715. * scc_bmdma_freeze - Freeze BMDMA controller port
  716. * @ap: port to freeze
  717. *
  718. * Note: Original code is ata_bmdma_freeze().
  719. */
  720. static void scc_bmdma_freeze (struct ata_port *ap)
  721. {
  722. struct ata_ioports *ioaddr = &ap->ioaddr;
  723. ap->ctl |= ATA_NIEN;
  724. ap->last_ctl = ap->ctl;
  725. out_be32(ioaddr->ctl_addr, ap->ctl);
  726. /* Under certain circumstances, some controllers raise IRQ on
  727. * ATA_NIEN manipulation. Also, many controllers fail to mask
  728. * previously pending IRQ on ATA_NIEN assertion. Clear it.
  729. */
  730. ata_chk_status(ap);
  731. ap->ops->irq_clear(ap);
  732. }
  733. /**
  734. * scc_pata_prereset - prepare for reset
  735. * @ap: ATA port to be reset
  736. * @deadline: deadline jiffies for the operation
  737. */
  738. static int scc_pata_prereset(struct ata_port *ap, unsigned long deadline)
  739. {
  740. ap->cbl = ATA_CBL_PATA80;
  741. return ata_std_prereset(ap, deadline);
  742. }
  743. /**
  744. * scc_std_postreset - standard postreset callback
  745. * @ap: the target ata_port
  746. * @classes: classes of attached devices
  747. *
  748. * Note: Original code is ata_std_postreset().
  749. */
  750. static void scc_std_postreset (struct ata_port *ap, unsigned int *classes)
  751. {
  752. DPRINTK("ENTER\n");
  753. /* re-enable interrupts */
  754. if (!ap->ops->error_handler)
  755. ap->ops->irq_on(ap);
  756. /* is double-select really necessary? */
  757. if (classes[0] != ATA_DEV_NONE)
  758. ap->ops->dev_select(ap, 1);
  759. if (classes[1] != ATA_DEV_NONE)
  760. ap->ops->dev_select(ap, 0);
  761. /* bail out if no device is present */
  762. if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
  763. DPRINTK("EXIT, no device\n");
  764. return;
  765. }
  766. /* set up device control */
  767. if (ap->ioaddr.ctl_addr)
  768. out_be32(ap->ioaddr.ctl_addr, ap->ctl);
  769. DPRINTK("EXIT\n");
  770. }
  771. /**
  772. * scc_error_handler - Stock error handler for BMDMA controller
  773. * @ap: port to handle error for
  774. */
  775. static void scc_error_handler (struct ata_port *ap)
  776. {
  777. ata_bmdma_drive_eh(ap, scc_pata_prereset, scc_std_softreset, NULL,
  778. scc_std_postreset);
  779. }
  780. /**
  781. * scc_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
  782. * @ap: Port associated with this ATA transaction.
  783. *
  784. * Note: Original code is ata_bmdma_irq_clear().
  785. */
  786. static void scc_bmdma_irq_clear (struct ata_port *ap)
  787. {
  788. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  789. if (!mmio)
  790. return;
  791. out_be32(mmio + SCC_DMA_STATUS, in_be32(mmio + SCC_DMA_STATUS));
  792. }
  793. /**
  794. * scc_port_start - Set port up for dma.
  795. * @ap: Port to initialize
  796. *
  797. * Allocate space for PRD table using ata_port_start().
  798. * Set PRD table address for PTERADD. (PRD Transfer End Read)
  799. */
  800. static int scc_port_start (struct ata_port *ap)
  801. {
  802. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  803. int rc;
  804. rc = ata_port_start(ap);
  805. if (rc)
  806. return rc;
  807. out_be32(mmio + SCC_DMA_PTERADD, ap->prd_dma);
  808. return 0;
  809. }
  810. /**
  811. * scc_port_stop - Undo scc_port_start()
  812. * @ap: Port to shut down
  813. *
  814. * Reset PTERADD.
  815. */
  816. static void scc_port_stop (struct ata_port *ap)
  817. {
  818. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  819. out_be32(mmio + SCC_DMA_PTERADD, 0);
  820. }
  821. static struct scsi_host_template scc_sht = {
  822. .module = THIS_MODULE,
  823. .name = DRV_NAME,
  824. .ioctl = ata_scsi_ioctl,
  825. .queuecommand = ata_scsi_queuecmd,
  826. .can_queue = ATA_DEF_QUEUE,
  827. .this_id = ATA_SHT_THIS_ID,
  828. .sg_tablesize = LIBATA_MAX_PRD,
  829. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  830. .emulated = ATA_SHT_EMULATED,
  831. .use_clustering = ATA_SHT_USE_CLUSTERING,
  832. .proc_name = DRV_NAME,
  833. .dma_boundary = ATA_DMA_BOUNDARY,
  834. .slave_configure = ata_scsi_slave_config,
  835. .slave_destroy = ata_scsi_slave_destroy,
  836. .bios_param = ata_std_bios_param,
  837. };
  838. static const struct ata_port_operations scc_pata_ops = {
  839. .port_disable = ata_port_disable,
  840. .set_piomode = scc_set_piomode,
  841. .set_dmamode = scc_set_dmamode,
  842. .mode_filter = ata_pci_default_filter,
  843. .tf_load = scc_tf_load,
  844. .tf_read = scc_tf_read,
  845. .exec_command = scc_exec_command,
  846. .check_status = scc_check_status,
  847. .check_altstatus = scc_check_altstatus,
  848. .dev_select = scc_std_dev_select,
  849. .bmdma_setup = scc_bmdma_setup,
  850. .bmdma_start = scc_bmdma_start,
  851. .bmdma_stop = scc_bmdma_stop,
  852. .bmdma_status = scc_bmdma_status,
  853. .data_xfer = scc_data_xfer,
  854. .qc_prep = ata_qc_prep,
  855. .qc_issue = ata_qc_issue_prot,
  856. .freeze = scc_bmdma_freeze,
  857. .error_handler = scc_error_handler,
  858. .post_internal_cmd = scc_bmdma_stop,
  859. .irq_clear = scc_bmdma_irq_clear,
  860. .irq_on = scc_irq_on,
  861. .irq_ack = scc_irq_ack,
  862. .port_start = scc_port_start,
  863. .port_stop = scc_port_stop,
  864. };
  865. static struct ata_port_info scc_port_info[] = {
  866. {
  867. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY,
  868. .pio_mask = 0x1f, /* pio0-4 */
  869. .mwdma_mask = 0x00,
  870. .udma_mask = ATA_UDMA6,
  871. .port_ops = &scc_pata_ops,
  872. },
  873. };
  874. /**
  875. * scc_reset_controller - initialize SCC PATA controller.
  876. */
  877. static int scc_reset_controller(struct ata_host *host)
  878. {
  879. void __iomem *ctrl_base = host->iomap[SCC_CTRL_BAR];
  880. void __iomem *bmid_base = host->iomap[SCC_BMID_BAR];
  881. void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
  882. void __iomem *mode_port = ctrl_base + SCC_CTL_MODEREG;
  883. void __iomem *ecmode_port = ctrl_base + SCC_CTL_ECMODE;
  884. void __iomem *intmask_port = bmid_base + SCC_DMA_INTMASK;
  885. void __iomem *dmastatus_port = bmid_base + SCC_DMA_STATUS;
  886. u32 reg = 0;
  887. out_be32(cckctrl_port, reg);
  888. reg |= CCKCTRL_ATACLKOEN;
  889. out_be32(cckctrl_port, reg);
  890. reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
  891. out_be32(cckctrl_port, reg);
  892. reg |= CCKCTRL_CRST;
  893. out_be32(cckctrl_port, reg);
  894. for (;;) {
  895. reg = in_be32(cckctrl_port);
  896. if (reg & CCKCTRL_CRST)
  897. break;
  898. udelay(5000);
  899. }
  900. reg |= CCKCTRL_ATARESET;
  901. out_be32(cckctrl_port, reg);
  902. out_be32(ecmode_port, ECMODE_VALUE);
  903. out_be32(mode_port, MODE_JCUSFEN);
  904. out_be32(intmask_port, INTMASK_MSK);
  905. if (in_be32(dmastatus_port) & QCHSD_STPDIAG) {
  906. printk(KERN_WARNING "%s: failed to detect 80c cable. (PDIAG# is high)\n", DRV_NAME);
  907. return -EIO;
  908. }
  909. return 0;
  910. }
  911. /**
  912. * scc_setup_ports - initialize ioaddr with SCC PATA port offsets.
  913. * @ioaddr: IO address structure to be initialized
  914. * @base: base address of BMID region
  915. */
  916. static void scc_setup_ports (struct ata_ioports *ioaddr, void __iomem *base)
  917. {
  918. ioaddr->cmd_addr = base + SCC_REG_CMD_ADDR;
  919. ioaddr->altstatus_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
  920. ioaddr->ctl_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
  921. ioaddr->bmdma_addr = base;
  922. ioaddr->data_addr = ioaddr->cmd_addr + SCC_REG_DATA;
  923. ioaddr->error_addr = ioaddr->cmd_addr + SCC_REG_ERR;
  924. ioaddr->feature_addr = ioaddr->cmd_addr + SCC_REG_FEATURE;
  925. ioaddr->nsect_addr = ioaddr->cmd_addr + SCC_REG_NSECT;
  926. ioaddr->lbal_addr = ioaddr->cmd_addr + SCC_REG_LBAL;
  927. ioaddr->lbam_addr = ioaddr->cmd_addr + SCC_REG_LBAM;
  928. ioaddr->lbah_addr = ioaddr->cmd_addr + SCC_REG_LBAH;
  929. ioaddr->device_addr = ioaddr->cmd_addr + SCC_REG_DEVICE;
  930. ioaddr->status_addr = ioaddr->cmd_addr + SCC_REG_STATUS;
  931. ioaddr->command_addr = ioaddr->cmd_addr + SCC_REG_CMD;
  932. }
  933. static int scc_host_init(struct ata_host *host)
  934. {
  935. struct pci_dev *pdev = to_pci_dev(host->dev);
  936. int rc;
  937. rc = scc_reset_controller(host);
  938. if (rc)
  939. return rc;
  940. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  941. if (rc)
  942. return rc;
  943. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  944. if (rc)
  945. return rc;
  946. scc_setup_ports(&host->ports[0]->ioaddr, host->iomap[SCC_BMID_BAR]);
  947. pci_set_master(pdev);
  948. return 0;
  949. }
  950. /**
  951. * scc_init_one - Register SCC PATA device with kernel services
  952. * @pdev: PCI device to register
  953. * @ent: Entry in scc_pci_tbl matching with @pdev
  954. *
  955. * LOCKING:
  956. * Inherited from PCI layer (may sleep).
  957. *
  958. * RETURNS:
  959. * Zero on success, or -ERRNO value.
  960. */
  961. static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  962. {
  963. static int printed_version;
  964. unsigned int board_idx = (unsigned int) ent->driver_data;
  965. const struct ata_port_info *ppi[] = { &scc_port_info[board_idx], NULL };
  966. struct ata_host *host;
  967. int rc;
  968. if (!printed_version++)
  969. dev_printk(KERN_DEBUG, &pdev->dev,
  970. "version " DRV_VERSION "\n");
  971. host = ata_host_alloc_pinfo(&pdev->dev, ppi, 1);
  972. if (!host)
  973. return -ENOMEM;
  974. rc = pcim_enable_device(pdev);
  975. if (rc)
  976. return rc;
  977. rc = pcim_iomap_regions(pdev, (1 << SCC_CTRL_BAR) | (1 << SCC_BMID_BAR), DRV_NAME);
  978. if (rc == -EBUSY)
  979. pcim_pin_device(pdev);
  980. if (rc)
  981. return rc;
  982. host->iomap = pcim_iomap_table(pdev);
  983. rc = scc_host_init(host);
  984. if (rc)
  985. return rc;
  986. return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
  987. &scc_sht);
  988. }
  989. static struct pci_driver scc_pci_driver = {
  990. .name = DRV_NAME,
  991. .id_table = scc_pci_tbl,
  992. .probe = scc_init_one,
  993. .remove = ata_pci_remove_one,
  994. #ifdef CONFIG_PM
  995. .suspend = ata_pci_device_suspend,
  996. .resume = ata_pci_device_resume,
  997. #endif
  998. };
  999. static int __init scc_init (void)
  1000. {
  1001. int rc;
  1002. DPRINTK("pci_register_driver\n");
  1003. rc = pci_register_driver(&scc_pci_driver);
  1004. if (rc)
  1005. return rc;
  1006. DPRINTK("done\n");
  1007. return 0;
  1008. }
  1009. static void __exit scc_exit (void)
  1010. {
  1011. pci_unregister_driver(&scc_pci_driver);
  1012. }
  1013. module_init(scc_init);
  1014. module_exit(scc_exit);
  1015. MODULE_AUTHOR("Toshiba corp");
  1016. MODULE_DESCRIPTION("SCSI low-level driver for Toshiba SCC PATA controller");
  1017. MODULE_LICENSE("GPL");
  1018. MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
  1019. MODULE_VERSION(DRV_VERSION);