pata_scc.c 31 KB

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