pata_scc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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.3"
  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. unsigned long scc_mode_filter(struct ata_device *adev, unsigned long mask)
  229. {
  230. /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */
  231. if (adev->class == ATA_DEV_ATAPI &&
  232. (mask & (0xE0 << ATA_SHIFT_UDMA))) {
  233. printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);
  234. mask &= ~(0xE0 << ATA_SHIFT_UDMA);
  235. }
  236. return ata_pci_default_filter(adev, mask);
  237. }
  238. /**
  239. * scc_tf_load - send taskfile registers to host controller
  240. * @ap: Port to which output is sent
  241. * @tf: ATA taskfile register set
  242. *
  243. * Note: Original code is ata_tf_load().
  244. */
  245. static void scc_tf_load (struct ata_port *ap, const struct ata_taskfile *tf)
  246. {
  247. struct ata_ioports *ioaddr = &ap->ioaddr;
  248. unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
  249. if (tf->ctl != ap->last_ctl) {
  250. out_be32(ioaddr->ctl_addr, tf->ctl);
  251. ap->last_ctl = tf->ctl;
  252. ata_wait_idle(ap);
  253. }
  254. if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
  255. out_be32(ioaddr->feature_addr, tf->hob_feature);
  256. out_be32(ioaddr->nsect_addr, tf->hob_nsect);
  257. out_be32(ioaddr->lbal_addr, tf->hob_lbal);
  258. out_be32(ioaddr->lbam_addr, tf->hob_lbam);
  259. out_be32(ioaddr->lbah_addr, tf->hob_lbah);
  260. VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
  261. tf->hob_feature,
  262. tf->hob_nsect,
  263. tf->hob_lbal,
  264. tf->hob_lbam,
  265. tf->hob_lbah);
  266. }
  267. if (is_addr) {
  268. out_be32(ioaddr->feature_addr, tf->feature);
  269. out_be32(ioaddr->nsect_addr, tf->nsect);
  270. out_be32(ioaddr->lbal_addr, tf->lbal);
  271. out_be32(ioaddr->lbam_addr, tf->lbam);
  272. out_be32(ioaddr->lbah_addr, tf->lbah);
  273. VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
  274. tf->feature,
  275. tf->nsect,
  276. tf->lbal,
  277. tf->lbam,
  278. tf->lbah);
  279. }
  280. if (tf->flags & ATA_TFLAG_DEVICE) {
  281. out_be32(ioaddr->device_addr, tf->device);
  282. VPRINTK("device 0x%X\n", tf->device);
  283. }
  284. ata_wait_idle(ap);
  285. }
  286. /**
  287. * scc_check_status - Read device status reg & clear interrupt
  288. * @ap: port where the device is
  289. *
  290. * Note: Original code is ata_check_status().
  291. */
  292. static u8 scc_check_status (struct ata_port *ap)
  293. {
  294. return in_be32(ap->ioaddr.status_addr);
  295. }
  296. /**
  297. * scc_tf_read - input device's ATA taskfile shadow registers
  298. * @ap: Port from which input is read
  299. * @tf: ATA taskfile register set for storing input
  300. *
  301. * Note: Original code is ata_tf_read().
  302. */
  303. static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf)
  304. {
  305. struct ata_ioports *ioaddr = &ap->ioaddr;
  306. tf->command = scc_check_status(ap);
  307. tf->feature = in_be32(ioaddr->error_addr);
  308. tf->nsect = in_be32(ioaddr->nsect_addr);
  309. tf->lbal = in_be32(ioaddr->lbal_addr);
  310. tf->lbam = in_be32(ioaddr->lbam_addr);
  311. tf->lbah = in_be32(ioaddr->lbah_addr);
  312. tf->device = in_be32(ioaddr->device_addr);
  313. if (tf->flags & ATA_TFLAG_LBA48) {
  314. out_be32(ioaddr->ctl_addr, tf->ctl | ATA_HOB);
  315. tf->hob_feature = in_be32(ioaddr->error_addr);
  316. tf->hob_nsect = in_be32(ioaddr->nsect_addr);
  317. tf->hob_lbal = in_be32(ioaddr->lbal_addr);
  318. tf->hob_lbam = in_be32(ioaddr->lbam_addr);
  319. tf->hob_lbah = in_be32(ioaddr->lbah_addr);
  320. out_be32(ioaddr->ctl_addr, tf->ctl);
  321. ap->last_ctl = tf->ctl;
  322. }
  323. }
  324. /**
  325. * scc_exec_command - issue ATA command to host controller
  326. * @ap: port to which command is being issued
  327. * @tf: ATA taskfile register set
  328. *
  329. * Note: Original code is ata_exec_command().
  330. */
  331. static void scc_exec_command (struct ata_port *ap,
  332. const struct ata_taskfile *tf)
  333. {
  334. DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
  335. out_be32(ap->ioaddr.command_addr, tf->command);
  336. ata_pause(ap);
  337. }
  338. /**
  339. * scc_check_altstatus - Read device alternate status reg
  340. * @ap: port where the device is
  341. */
  342. static u8 scc_check_altstatus (struct ata_port *ap)
  343. {
  344. return in_be32(ap->ioaddr.altstatus_addr);
  345. }
  346. /**
  347. * scc_std_dev_select - Select device 0/1 on ATA bus
  348. * @ap: ATA channel to manipulate
  349. * @device: ATA device (numbered from zero) to select
  350. *
  351. * Note: Original code is ata_std_dev_select().
  352. */
  353. static void scc_std_dev_select (struct ata_port *ap, unsigned int device)
  354. {
  355. u8 tmp;
  356. if (device == 0)
  357. tmp = ATA_DEVICE_OBS;
  358. else
  359. tmp = ATA_DEVICE_OBS | ATA_DEV1;
  360. out_be32(ap->ioaddr.device_addr, tmp);
  361. ata_pause(ap);
  362. }
  363. /**
  364. * scc_bmdma_setup - Set up PCI IDE BMDMA transaction
  365. * @qc: Info associated with this ATA transaction.
  366. *
  367. * Note: Original code is ata_bmdma_setup().
  368. */
  369. static void scc_bmdma_setup (struct ata_queued_cmd *qc)
  370. {
  371. struct ata_port *ap = qc->ap;
  372. unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
  373. u8 dmactl;
  374. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  375. /* load PRD table addr */
  376. out_be32(mmio + SCC_DMA_TABLE_OFS, ap->prd_dma);
  377. /* specify data direction, triple-check start bit is clear */
  378. dmactl = in_be32(mmio + SCC_DMA_CMD);
  379. dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
  380. if (!rw)
  381. dmactl |= ATA_DMA_WR;
  382. out_be32(mmio + SCC_DMA_CMD, dmactl);
  383. /* issue r/w command */
  384. ap->ops->exec_command(ap, &qc->tf);
  385. }
  386. /**
  387. * scc_bmdma_start - Start a PCI IDE BMDMA transaction
  388. * @qc: Info associated with this ATA transaction.
  389. *
  390. * Note: Original code is ata_bmdma_start().
  391. */
  392. static void scc_bmdma_start (struct ata_queued_cmd *qc)
  393. {
  394. struct ata_port *ap = qc->ap;
  395. u8 dmactl;
  396. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  397. /* start host DMA transaction */
  398. dmactl = in_be32(mmio + SCC_DMA_CMD);
  399. out_be32(mmio + SCC_DMA_CMD, dmactl | ATA_DMA_START);
  400. }
  401. /**
  402. * scc_devchk - PATA device presence detection
  403. * @ap: ATA channel to examine
  404. * @device: Device to examine (starting at zero)
  405. *
  406. * Note: Original code is ata_devchk().
  407. */
  408. static unsigned int scc_devchk (struct ata_port *ap,
  409. unsigned int device)
  410. {
  411. struct ata_ioports *ioaddr = &ap->ioaddr;
  412. u8 nsect, lbal;
  413. ap->ops->dev_select(ap, device);
  414. out_be32(ioaddr->nsect_addr, 0x55);
  415. out_be32(ioaddr->lbal_addr, 0xaa);
  416. out_be32(ioaddr->nsect_addr, 0xaa);
  417. out_be32(ioaddr->lbal_addr, 0x55);
  418. out_be32(ioaddr->nsect_addr, 0x55);
  419. out_be32(ioaddr->lbal_addr, 0xaa);
  420. nsect = in_be32(ioaddr->nsect_addr);
  421. lbal = in_be32(ioaddr->lbal_addr);
  422. if ((nsect == 0x55) && (lbal == 0xaa))
  423. return 1; /* we found a device */
  424. return 0; /* nothing found */
  425. }
  426. /**
  427. * scc_bus_post_reset - PATA device post reset
  428. *
  429. * Note: Original code is ata_bus_post_reset().
  430. */
  431. static int scc_bus_post_reset(struct ata_port *ap, unsigned int devmask,
  432. unsigned long deadline)
  433. {
  434. struct ata_ioports *ioaddr = &ap->ioaddr;
  435. unsigned int dev0 = devmask & (1 << 0);
  436. unsigned int dev1 = devmask & (1 << 1);
  437. int rc;
  438. /* if device 0 was found in ata_devchk, wait for its
  439. * BSY bit to clear
  440. */
  441. if (dev0) {
  442. rc = ata_wait_ready(ap, deadline);
  443. if (rc && rc != -ENODEV)
  444. return rc;
  445. }
  446. /* if device 1 was found in ata_devchk, wait for
  447. * register access, then wait for BSY to clear
  448. */
  449. while (dev1) {
  450. u8 nsect, lbal;
  451. ap->ops->dev_select(ap, 1);
  452. nsect = in_be32(ioaddr->nsect_addr);
  453. lbal = in_be32(ioaddr->lbal_addr);
  454. if ((nsect == 1) && (lbal == 1))
  455. break;
  456. if (time_after(jiffies, deadline))
  457. return -EBUSY;
  458. msleep(50); /* give drive a breather */
  459. }
  460. if (dev1) {
  461. rc = ata_wait_ready(ap, deadline);
  462. if (rc && rc != -ENODEV)
  463. return rc;
  464. }
  465. /* is all this really necessary? */
  466. ap->ops->dev_select(ap, 0);
  467. if (dev1)
  468. ap->ops->dev_select(ap, 1);
  469. if (dev0)
  470. ap->ops->dev_select(ap, 0);
  471. return 0;
  472. }
  473. /**
  474. * scc_bus_softreset - PATA device software reset
  475. *
  476. * Note: Original code is ata_bus_softreset().
  477. */
  478. static unsigned int scc_bus_softreset(struct ata_port *ap, unsigned int devmask,
  479. unsigned long deadline)
  480. {
  481. struct ata_ioports *ioaddr = &ap->ioaddr;
  482. DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
  483. /* software reset. causes dev0 to be selected */
  484. out_be32(ioaddr->ctl_addr, ap->ctl);
  485. udelay(20);
  486. out_be32(ioaddr->ctl_addr, ap->ctl | ATA_SRST);
  487. udelay(20);
  488. out_be32(ioaddr->ctl_addr, ap->ctl);
  489. /* wait a while before checking status */
  490. ata_wait_after_reset(ap, deadline);
  491. /* Before we perform post reset processing we want to see if
  492. * the bus shows 0xFF because the odd clown forgets the D7
  493. * pulldown resistor.
  494. */
  495. if (scc_check_status(ap) == 0xFF)
  496. return 0;
  497. scc_bus_post_reset(ap, devmask, deadline);
  498. return 0;
  499. }
  500. /**
  501. * scc_std_softreset - reset host port via ATA SRST
  502. * @ap: port to reset
  503. * @classes: resulting classes of attached devices
  504. * @deadline: deadline jiffies for the operation
  505. *
  506. * Note: Original code is ata_std_softreset().
  507. */
  508. static int scc_std_softreset(struct ata_link *link, unsigned int *classes,
  509. unsigned long deadline)
  510. {
  511. struct ata_port *ap = link->ap;
  512. unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
  513. unsigned int devmask = 0, err_mask;
  514. u8 err;
  515. DPRINTK("ENTER\n");
  516. if (ata_link_offline(link)) {
  517. classes[0] = ATA_DEV_NONE;
  518. goto out;
  519. }
  520. /* determine if device 0/1 are present */
  521. if (scc_devchk(ap, 0))
  522. devmask |= (1 << 0);
  523. if (slave_possible && scc_devchk(ap, 1))
  524. devmask |= (1 << 1);
  525. /* select device 0 again */
  526. ap->ops->dev_select(ap, 0);
  527. /* issue bus reset */
  528. DPRINTK("about to softreset, devmask=%x\n", devmask);
  529. err_mask = scc_bus_softreset(ap, devmask, deadline);
  530. if (err_mask) {
  531. ata_port_printk(ap, KERN_ERR, "SRST failed (err_mask=0x%x)\n",
  532. err_mask);
  533. return -EIO;
  534. }
  535. /* determine by signature whether we have ATA or ATAPI devices */
  536. classes[0] = ata_dev_try_classify(&ap->link.device[0],
  537. devmask & (1 << 0), &err);
  538. if (slave_possible && err != 0x81)
  539. classes[1] = ata_dev_try_classify(&ap->link.device[1],
  540. devmask & (1 << 1), &err);
  541. out:
  542. DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
  543. return 0;
  544. }
  545. /**
  546. * scc_bmdma_stop - Stop PCI IDE BMDMA transfer
  547. * @qc: Command we are ending DMA for
  548. */
  549. static void scc_bmdma_stop (struct ata_queued_cmd *qc)
  550. {
  551. struct ata_port *ap = qc->ap;
  552. void __iomem *ctrl_base = ap->host->iomap[SCC_CTRL_BAR];
  553. void __iomem *bmid_base = ap->host->iomap[SCC_BMID_BAR];
  554. u32 reg;
  555. while (1) {
  556. reg = in_be32(bmid_base + SCC_DMA_INTST);
  557. if (reg & INTSTS_SERROR) {
  558. printk(KERN_WARNING "%s: SERROR\n", DRV_NAME);
  559. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_SERROR|INTSTS_BMSINT);
  560. out_be32(bmid_base + SCC_DMA_CMD,
  561. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  562. continue;
  563. }
  564. if (reg & INTSTS_PRERR) {
  565. u32 maea0, maec0;
  566. maea0 = in_be32(ctrl_base + SCC_CTL_MAEA0);
  567. maec0 = in_be32(ctrl_base + SCC_CTL_MAEC0);
  568. printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", DRV_NAME, maea0, maec0);
  569. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_PRERR|INTSTS_BMSINT);
  570. out_be32(bmid_base + SCC_DMA_CMD,
  571. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  572. continue;
  573. }
  574. if (reg & INTSTS_RERR) {
  575. printk(KERN_WARNING "%s: Response Error\n", DRV_NAME);
  576. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_RERR|INTSTS_BMSINT);
  577. out_be32(bmid_base + SCC_DMA_CMD,
  578. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  579. continue;
  580. }
  581. if (reg & INTSTS_ICERR) {
  582. out_be32(bmid_base + SCC_DMA_CMD,
  583. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  584. printk(KERN_WARNING "%s: Illegal Configuration\n", DRV_NAME);
  585. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ICERR|INTSTS_BMSINT);
  586. continue;
  587. }
  588. if (reg & INTSTS_BMSINT) {
  589. unsigned int classes;
  590. unsigned long deadline = jiffies + ATA_TMOUT_BOOT;
  591. printk(KERN_WARNING "%s: Internal Bus Error\n", DRV_NAME);
  592. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMSINT);
  593. /* TBD: SW reset */
  594. scc_std_softreset(&ap->link, &classes, deadline);
  595. continue;
  596. }
  597. if (reg & INTSTS_BMHE) {
  598. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_BMHE);
  599. continue;
  600. }
  601. if (reg & INTSTS_ACTEINT) {
  602. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_ACTEINT);
  603. continue;
  604. }
  605. if (reg & INTSTS_IOIRQS) {
  606. out_be32(bmid_base + SCC_DMA_INTST, INTSTS_IOIRQS);
  607. continue;
  608. }
  609. break;
  610. }
  611. /* clear start/stop bit */
  612. out_be32(bmid_base + SCC_DMA_CMD,
  613. in_be32(bmid_base + SCC_DMA_CMD) & ~ATA_DMA_START);
  614. /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
  615. ata_altstatus(ap); /* dummy read */
  616. }
  617. /**
  618. * scc_bmdma_status - Read PCI IDE BMDMA status
  619. * @ap: Port associated with this ATA transaction.
  620. */
  621. static u8 scc_bmdma_status (struct ata_port *ap)
  622. {
  623. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  624. u8 host_stat = in_be32(mmio + SCC_DMA_STATUS);
  625. u32 int_status = in_be32(mmio + SCC_DMA_INTST);
  626. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
  627. static int retry = 0;
  628. /* return if IOS_SS is cleared */
  629. if (!(in_be32(mmio + SCC_DMA_CMD) & ATA_DMA_START))
  630. return host_stat;
  631. /* errata A252,A308 workaround: Step4 */
  632. if ((ata_altstatus(ap) & ATA_ERR) && (int_status & INTSTS_INTRQ))
  633. return (host_stat | ATA_DMA_INTR);
  634. /* errata A308 workaround Step5 */
  635. if (int_status & INTSTS_IOIRQS) {
  636. host_stat |= ATA_DMA_INTR;
  637. /* We don't check ATAPI DMA because it is limited to UDMA4 */
  638. if ((qc->tf.protocol == ATA_PROT_DMA &&
  639. qc->dev->xfer_mode > XFER_UDMA_4)) {
  640. if (!(int_status & INTSTS_ACTEINT)) {
  641. printk(KERN_WARNING "ata%u: operation failed (transfer data loss)\n",
  642. ap->print_id);
  643. host_stat |= ATA_DMA_ERR;
  644. if (retry++)
  645. ap->udma_mask &= ~(1 << qc->dev->xfer_mode);
  646. } else
  647. retry = 0;
  648. }
  649. }
  650. return host_stat;
  651. }
  652. /**
  653. * scc_data_xfer - Transfer data by PIO
  654. * @dev: device for this I/O
  655. * @buf: data buffer
  656. * @buflen: buffer length
  657. * @rw: read/write
  658. *
  659. * Note: Original code is ata_data_xfer().
  660. */
  661. static unsigned int scc_data_xfer (struct ata_device *dev, unsigned char *buf,
  662. unsigned int buflen, int rw)
  663. {
  664. struct ata_port *ap = dev->link->ap;
  665. unsigned int words = buflen >> 1;
  666. unsigned int i;
  667. u16 *buf16 = (u16 *) buf;
  668. void __iomem *mmio = ap->ioaddr.data_addr;
  669. /* Transfer multiple of 2 bytes */
  670. if (rw == READ)
  671. for (i = 0; i < words; i++)
  672. buf16[i] = le16_to_cpu(in_be32(mmio));
  673. else
  674. for (i = 0; i < words; i++)
  675. out_be32(mmio, cpu_to_le16(buf16[i]));
  676. /* Transfer trailing 1 byte, if any. */
  677. if (unlikely(buflen & 0x01)) {
  678. u16 align_buf[1] = { 0 };
  679. unsigned char *trailing_buf = buf + buflen - 1;
  680. if (rw == READ) {
  681. align_buf[0] = le16_to_cpu(in_be32(mmio));
  682. memcpy(trailing_buf, align_buf, 1);
  683. } else {
  684. memcpy(align_buf, trailing_buf, 1);
  685. out_be32(mmio, cpu_to_le16(align_buf[0]));
  686. }
  687. words++;
  688. }
  689. return words << 1;
  690. }
  691. /**
  692. * scc_irq_on - Enable interrupts on a port.
  693. * @ap: Port on which interrupts are enabled.
  694. *
  695. * Note: Original code is ata_irq_on().
  696. */
  697. static u8 scc_irq_on (struct ata_port *ap)
  698. {
  699. struct ata_ioports *ioaddr = &ap->ioaddr;
  700. u8 tmp;
  701. ap->ctl &= ~ATA_NIEN;
  702. ap->last_ctl = ap->ctl;
  703. out_be32(ioaddr->ctl_addr, ap->ctl);
  704. tmp = ata_wait_idle(ap);
  705. ap->ops->irq_clear(ap);
  706. return tmp;
  707. }
  708. /**
  709. * scc_bmdma_freeze - Freeze BMDMA controller port
  710. * @ap: port to freeze
  711. *
  712. * Note: Original code is ata_bmdma_freeze().
  713. */
  714. static void scc_bmdma_freeze (struct ata_port *ap)
  715. {
  716. struct ata_ioports *ioaddr = &ap->ioaddr;
  717. ap->ctl |= ATA_NIEN;
  718. ap->last_ctl = ap->ctl;
  719. out_be32(ioaddr->ctl_addr, ap->ctl);
  720. /* Under certain circumstances, some controllers raise IRQ on
  721. * ATA_NIEN manipulation. Also, many controllers fail to mask
  722. * previously pending IRQ on ATA_NIEN assertion. Clear it.
  723. */
  724. ata_chk_status(ap);
  725. ap->ops->irq_clear(ap);
  726. }
  727. /**
  728. * scc_pata_prereset - prepare for reset
  729. * @ap: ATA port to be reset
  730. * @deadline: deadline jiffies for the operation
  731. */
  732. static int scc_pata_prereset(struct ata_link *link, unsigned long deadline)
  733. {
  734. link->ap->cbl = ATA_CBL_PATA80;
  735. return ata_std_prereset(link, deadline);
  736. }
  737. /**
  738. * scc_std_postreset - standard postreset callback
  739. * @ap: the target ata_port
  740. * @classes: classes of attached devices
  741. *
  742. * Note: Original code is ata_std_postreset().
  743. */
  744. static void scc_std_postreset(struct ata_link *link, unsigned int *classes)
  745. {
  746. struct ata_port *ap = link->ap;
  747. DPRINTK("ENTER\n");
  748. /* is double-select really necessary? */
  749. if (classes[0] != ATA_DEV_NONE)
  750. ap->ops->dev_select(ap, 1);
  751. if (classes[1] != ATA_DEV_NONE)
  752. ap->ops->dev_select(ap, 0);
  753. /* bail out if no device is present */
  754. if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
  755. DPRINTK("EXIT, no device\n");
  756. return;
  757. }
  758. /* set up device control */
  759. if (ap->ioaddr.ctl_addr)
  760. out_be32(ap->ioaddr.ctl_addr, ap->ctl);
  761. DPRINTK("EXIT\n");
  762. }
  763. /**
  764. * scc_error_handler - Stock error handler for BMDMA controller
  765. * @ap: port to handle error for
  766. */
  767. static void scc_error_handler (struct ata_port *ap)
  768. {
  769. ata_bmdma_drive_eh(ap, scc_pata_prereset, scc_std_softreset, NULL,
  770. scc_std_postreset);
  771. }
  772. /**
  773. * scc_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
  774. * @ap: Port associated with this ATA transaction.
  775. *
  776. * Note: Original code is ata_bmdma_irq_clear().
  777. */
  778. static void scc_bmdma_irq_clear (struct ata_port *ap)
  779. {
  780. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  781. if (!mmio)
  782. return;
  783. out_be32(mmio + SCC_DMA_STATUS, in_be32(mmio + SCC_DMA_STATUS));
  784. }
  785. /**
  786. * scc_port_start - Set port up for dma.
  787. * @ap: Port to initialize
  788. *
  789. * Allocate space for PRD table using ata_port_start().
  790. * Set PRD table address for PTERADD. (PRD Transfer End Read)
  791. */
  792. static int scc_port_start (struct ata_port *ap)
  793. {
  794. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  795. int rc;
  796. rc = ata_port_start(ap);
  797. if (rc)
  798. return rc;
  799. out_be32(mmio + SCC_DMA_PTERADD, ap->prd_dma);
  800. return 0;
  801. }
  802. /**
  803. * scc_port_stop - Undo scc_port_start()
  804. * @ap: Port to shut down
  805. *
  806. * Reset PTERADD.
  807. */
  808. static void scc_port_stop (struct ata_port *ap)
  809. {
  810. void __iomem *mmio = ap->ioaddr.bmdma_addr;
  811. out_be32(mmio + SCC_DMA_PTERADD, 0);
  812. }
  813. static struct scsi_host_template scc_sht = {
  814. .module = THIS_MODULE,
  815. .name = DRV_NAME,
  816. .ioctl = ata_scsi_ioctl,
  817. .queuecommand = ata_scsi_queuecmd,
  818. .can_queue = ATA_DEF_QUEUE,
  819. .this_id = ATA_SHT_THIS_ID,
  820. .sg_tablesize = LIBATA_MAX_PRD,
  821. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  822. .emulated = ATA_SHT_EMULATED,
  823. .use_clustering = ATA_SHT_USE_CLUSTERING,
  824. .proc_name = DRV_NAME,
  825. .dma_boundary = ATA_DMA_BOUNDARY,
  826. .slave_configure = ata_scsi_slave_config,
  827. .slave_destroy = ata_scsi_slave_destroy,
  828. .bios_param = ata_std_bios_param,
  829. };
  830. static const struct ata_port_operations scc_pata_ops = {
  831. .set_piomode = scc_set_piomode,
  832. .set_dmamode = scc_set_dmamode,
  833. .mode_filter = scc_mode_filter,
  834. .tf_load = scc_tf_load,
  835. .tf_read = scc_tf_read,
  836. .exec_command = scc_exec_command,
  837. .check_status = scc_check_status,
  838. .check_altstatus = scc_check_altstatus,
  839. .dev_select = scc_std_dev_select,
  840. .bmdma_setup = scc_bmdma_setup,
  841. .bmdma_start = scc_bmdma_start,
  842. .bmdma_stop = scc_bmdma_stop,
  843. .bmdma_status = scc_bmdma_status,
  844. .data_xfer = scc_data_xfer,
  845. .qc_prep = ata_qc_prep,
  846. .qc_issue = ata_qc_issue_prot,
  847. .freeze = scc_bmdma_freeze,
  848. .error_handler = scc_error_handler,
  849. .post_internal_cmd = scc_bmdma_stop,
  850. .irq_clear = scc_bmdma_irq_clear,
  851. .irq_on = scc_irq_on,
  852. .port_start = scc_port_start,
  853. .port_stop = scc_port_stop,
  854. };
  855. static struct ata_port_info scc_port_info[] = {
  856. {
  857. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY,
  858. .pio_mask = 0x1f, /* pio0-4 */
  859. .mwdma_mask = 0x00,
  860. .udma_mask = ATA_UDMA6,
  861. .port_ops = &scc_pata_ops,
  862. },
  863. };
  864. /**
  865. * scc_reset_controller - initialize SCC PATA controller.
  866. */
  867. static int scc_reset_controller(struct ata_host *host)
  868. {
  869. void __iomem *ctrl_base = host->iomap[SCC_CTRL_BAR];
  870. void __iomem *bmid_base = host->iomap[SCC_BMID_BAR];
  871. void __iomem *cckctrl_port = ctrl_base + SCC_CTL_CCKCTRL;
  872. void __iomem *mode_port = ctrl_base + SCC_CTL_MODEREG;
  873. void __iomem *ecmode_port = ctrl_base + SCC_CTL_ECMODE;
  874. void __iomem *intmask_port = bmid_base + SCC_DMA_INTMASK;
  875. void __iomem *dmastatus_port = bmid_base + SCC_DMA_STATUS;
  876. u32 reg = 0;
  877. out_be32(cckctrl_port, reg);
  878. reg |= CCKCTRL_ATACLKOEN;
  879. out_be32(cckctrl_port, reg);
  880. reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
  881. out_be32(cckctrl_port, reg);
  882. reg |= CCKCTRL_CRST;
  883. out_be32(cckctrl_port, reg);
  884. for (;;) {
  885. reg = in_be32(cckctrl_port);
  886. if (reg & CCKCTRL_CRST)
  887. break;
  888. udelay(5000);
  889. }
  890. reg |= CCKCTRL_ATARESET;
  891. out_be32(cckctrl_port, reg);
  892. out_be32(ecmode_port, ECMODE_VALUE);
  893. out_be32(mode_port, MODE_JCUSFEN);
  894. out_be32(intmask_port, INTMASK_MSK);
  895. if (in_be32(dmastatus_port) & QCHSD_STPDIAG) {
  896. printk(KERN_WARNING "%s: failed to detect 80c cable. (PDIAG# is high)\n", DRV_NAME);
  897. return -EIO;
  898. }
  899. return 0;
  900. }
  901. /**
  902. * scc_setup_ports - initialize ioaddr with SCC PATA port offsets.
  903. * @ioaddr: IO address structure to be initialized
  904. * @base: base address of BMID region
  905. */
  906. static void scc_setup_ports (struct ata_ioports *ioaddr, void __iomem *base)
  907. {
  908. ioaddr->cmd_addr = base + SCC_REG_CMD_ADDR;
  909. ioaddr->altstatus_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
  910. ioaddr->ctl_addr = ioaddr->cmd_addr + SCC_REG_ALTSTATUS;
  911. ioaddr->bmdma_addr = base;
  912. ioaddr->data_addr = ioaddr->cmd_addr + SCC_REG_DATA;
  913. ioaddr->error_addr = ioaddr->cmd_addr + SCC_REG_ERR;
  914. ioaddr->feature_addr = ioaddr->cmd_addr + SCC_REG_FEATURE;
  915. ioaddr->nsect_addr = ioaddr->cmd_addr + SCC_REG_NSECT;
  916. ioaddr->lbal_addr = ioaddr->cmd_addr + SCC_REG_LBAL;
  917. ioaddr->lbam_addr = ioaddr->cmd_addr + SCC_REG_LBAM;
  918. ioaddr->lbah_addr = ioaddr->cmd_addr + SCC_REG_LBAH;
  919. ioaddr->device_addr = ioaddr->cmd_addr + SCC_REG_DEVICE;
  920. ioaddr->status_addr = ioaddr->cmd_addr + SCC_REG_STATUS;
  921. ioaddr->command_addr = ioaddr->cmd_addr + SCC_REG_CMD;
  922. }
  923. static int scc_host_init(struct ata_host *host)
  924. {
  925. struct pci_dev *pdev = to_pci_dev(host->dev);
  926. int rc;
  927. rc = scc_reset_controller(host);
  928. if (rc)
  929. return rc;
  930. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  931. if (rc)
  932. return rc;
  933. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  934. if (rc)
  935. return rc;
  936. scc_setup_ports(&host->ports[0]->ioaddr, host->iomap[SCC_BMID_BAR]);
  937. pci_set_master(pdev);
  938. return 0;
  939. }
  940. /**
  941. * scc_init_one - Register SCC PATA device with kernel services
  942. * @pdev: PCI device to register
  943. * @ent: Entry in scc_pci_tbl matching with @pdev
  944. *
  945. * LOCKING:
  946. * Inherited from PCI layer (may sleep).
  947. *
  948. * RETURNS:
  949. * Zero on success, or -ERRNO value.
  950. */
  951. static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  952. {
  953. static int printed_version;
  954. unsigned int board_idx = (unsigned int) ent->driver_data;
  955. const struct ata_port_info *ppi[] = { &scc_port_info[board_idx], NULL };
  956. struct ata_host *host;
  957. int rc;
  958. if (!printed_version++)
  959. dev_printk(KERN_DEBUG, &pdev->dev,
  960. "version " DRV_VERSION "\n");
  961. host = ata_host_alloc_pinfo(&pdev->dev, ppi, 1);
  962. if (!host)
  963. return -ENOMEM;
  964. rc = pcim_enable_device(pdev);
  965. if (rc)
  966. return rc;
  967. rc = pcim_iomap_regions(pdev, (1 << SCC_CTRL_BAR) | (1 << SCC_BMID_BAR), DRV_NAME);
  968. if (rc == -EBUSY)
  969. pcim_pin_device(pdev);
  970. if (rc)
  971. return rc;
  972. host->iomap = pcim_iomap_table(pdev);
  973. ata_port_pbar_desc(host->ports[0], SCC_CTRL_BAR, -1, "ctrl");
  974. ata_port_pbar_desc(host->ports[0], SCC_BMID_BAR, -1, "bmid");
  975. rc = scc_host_init(host);
  976. if (rc)
  977. return rc;
  978. return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
  979. &scc_sht);
  980. }
  981. static struct pci_driver scc_pci_driver = {
  982. .name = DRV_NAME,
  983. .id_table = scc_pci_tbl,
  984. .probe = scc_init_one,
  985. .remove = ata_pci_remove_one,
  986. #ifdef CONFIG_PM
  987. .suspend = ata_pci_device_suspend,
  988. .resume = ata_pci_device_resume,
  989. #endif
  990. };
  991. static int __init scc_init (void)
  992. {
  993. int rc;
  994. DPRINTK("pci_register_driver\n");
  995. rc = pci_register_driver(&scc_pci_driver);
  996. if (rc)
  997. return rc;
  998. DPRINTK("done\n");
  999. return 0;
  1000. }
  1001. static void __exit scc_exit (void)
  1002. {
  1003. pci_unregister_driver(&scc_pci_driver);
  1004. }
  1005. module_init(scc_init);
  1006. module_exit(scc_exit);
  1007. MODULE_AUTHOR("Toshiba corp");
  1008. MODULE_DESCRIPTION("SCSI low-level driver for Toshiba SCC PATA controller");
  1009. MODULE_LICENSE("GPL");
  1010. MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
  1011. MODULE_VERSION(DRV_VERSION);