scc_pata.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /*
  2. * Support for IDE interfaces on Celleb platform
  3. *
  4. * (C) Copyright 2006 TOSHIBA CORPORATION
  5. *
  6. * This code is based on drivers/ide/pci/siimage.c:
  7. * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
  8. * Copyright (C) 2003 Red Hat <alan@redhat.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. */
  24. #include <linux/types.h>
  25. #include <linux/module.h>
  26. #include <linux/pci.h>
  27. #include <linux/delay.h>
  28. #include <linux/hdreg.h>
  29. #include <linux/ide.h>
  30. #include <linux/init.h>
  31. #define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
  32. #define SCC_PATA_NAME "scc IDE"
  33. #define TDVHSEL_MASTER 0x00000001
  34. #define TDVHSEL_SLAVE 0x00000004
  35. #define MODE_JCUSFEN 0x00000080
  36. #define CCKCTRL_ATARESET 0x00040000
  37. #define CCKCTRL_BUFCNT 0x00020000
  38. #define CCKCTRL_CRST 0x00010000
  39. #define CCKCTRL_OCLKEN 0x00000100
  40. #define CCKCTRL_ATACLKOEN 0x00000002
  41. #define CCKCTRL_LCLKEN 0x00000001
  42. #define QCHCD_IOS_SS 0x00000001
  43. #define QCHSD_STPDIAG 0x00020000
  44. #define INTMASK_MSK 0xD1000012
  45. #define INTSTS_SERROR 0x80000000
  46. #define INTSTS_PRERR 0x40000000
  47. #define INTSTS_RERR 0x10000000
  48. #define INTSTS_ICERR 0x01000000
  49. #define INTSTS_BMSINT 0x00000010
  50. #define INTSTS_BMHE 0x00000008
  51. #define INTSTS_IOIRQS 0x00000004
  52. #define INTSTS_INTRQ 0x00000002
  53. #define INTSTS_ACTEINT 0x00000001
  54. #define ECMODE_VALUE 0x01
  55. static struct scc_ports {
  56. unsigned long ctl, dma;
  57. unsigned char hwif_id; /* for removing hwif from system */
  58. } scc_ports[MAX_HWIFS];
  59. /* PIO transfer mode table */
  60. /* JCHST */
  61. static unsigned long JCHSTtbl[2][7] = {
  62. {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
  63. {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
  64. };
  65. /* JCHHT */
  66. static unsigned long JCHHTtbl[2][7] = {
  67. {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
  68. {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
  69. };
  70. /* JCHCT */
  71. static unsigned long JCHCTtbl[2][7] = {
  72. {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
  73. {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
  74. };
  75. /* DMA transfer mode table */
  76. /* JCHDCTM/JCHDCTS */
  77. static unsigned long JCHDCTxtbl[2][7] = {
  78. {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
  79. {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
  80. };
  81. /* JCSTWTM/JCSTWTS */
  82. static unsigned long JCSTWTxtbl[2][7] = {
  83. {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
  84. {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
  85. };
  86. /* JCTSS */
  87. static unsigned long JCTSStbl[2][7] = {
  88. {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
  89. {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
  90. };
  91. /* JCENVT */
  92. static unsigned long JCENVTtbl[2][7] = {
  93. {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
  94. {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
  95. };
  96. /* JCACTSELS/JCACTSELM */
  97. static unsigned long JCACTSELtbl[2][7] = {
  98. {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
  99. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
  100. };
  101. static u8 scc_ide_inb(unsigned long port)
  102. {
  103. u32 data = in_be32((void*)port);
  104. return (u8)data;
  105. }
  106. static u16 scc_ide_inw(unsigned long port)
  107. {
  108. u32 data = in_be32((void*)port);
  109. return (u16)data;
  110. }
  111. static void scc_ide_insw(unsigned long port, void *addr, u32 count)
  112. {
  113. u16 *ptr = (u16 *)addr;
  114. while (count--) {
  115. *ptr++ = le16_to_cpu(in_be32((void*)port));
  116. }
  117. }
  118. static void scc_ide_insl(unsigned long port, void *addr, u32 count)
  119. {
  120. u16 *ptr = (u16 *)addr;
  121. while (count--) {
  122. *ptr++ = le16_to_cpu(in_be32((void*)port));
  123. *ptr++ = le16_to_cpu(in_be32((void*)port));
  124. }
  125. }
  126. static void scc_ide_outb(u8 addr, unsigned long port)
  127. {
  128. out_be32((void*)port, addr);
  129. }
  130. static void scc_ide_outw(u16 addr, unsigned long port)
  131. {
  132. out_be32((void*)port, addr);
  133. }
  134. static void
  135. scc_ide_outbsync(ide_drive_t * drive, u8 addr, unsigned long port)
  136. {
  137. ide_hwif_t *hwif = HWIF(drive);
  138. out_be32((void*)port, addr);
  139. __asm__ __volatile__("eieio":::"memory");
  140. in_be32((void*)(hwif->dma_base + 0x01c));
  141. __asm__ __volatile__("eieio":::"memory");
  142. }
  143. static void
  144. scc_ide_outsw(unsigned long port, void *addr, u32 count)
  145. {
  146. u16 *ptr = (u16 *)addr;
  147. while (count--) {
  148. out_be32((void*)port, cpu_to_le16(*ptr++));
  149. }
  150. }
  151. static void
  152. scc_ide_outsl(unsigned long port, void *addr, u32 count)
  153. {
  154. u16 *ptr = (u16 *)addr;
  155. while (count--) {
  156. out_be32((void*)port, cpu_to_le16(*ptr++));
  157. out_be32((void*)port, cpu_to_le16(*ptr++));
  158. }
  159. }
  160. /**
  161. * scc_tuneproc - tune a drive PIO mode
  162. * @drive: drive to tune
  163. * @mode_wanted: the target operating mode
  164. *
  165. * Load the timing settings for this device mode into the
  166. * controller.
  167. */
  168. static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted)
  169. {
  170. ide_hwif_t *hwif = HWIF(drive);
  171. struct scc_ports *ports = ide_get_hwifdata(hwif);
  172. unsigned long ctl_base = ports->ctl;
  173. unsigned long cckctrl_port = ctl_base + 0xff0;
  174. unsigned long piosht_port = ctl_base + 0x000;
  175. unsigned long pioct_port = ctl_base + 0x004;
  176. unsigned long reg;
  177. unsigned char speed = XFER_PIO_0;
  178. int offset;
  179. mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4, NULL);
  180. switch (mode_wanted) {
  181. case 4:
  182. speed = XFER_PIO_4;
  183. break;
  184. case 3:
  185. speed = XFER_PIO_3;
  186. break;
  187. case 2:
  188. speed = XFER_PIO_2;
  189. break;
  190. case 1:
  191. speed = XFER_PIO_1;
  192. break;
  193. case 0:
  194. default:
  195. speed = XFER_PIO_0;
  196. break;
  197. }
  198. reg = in_be32((void __iomem *)cckctrl_port);
  199. if (reg & CCKCTRL_ATACLKOEN) {
  200. offset = 1; /* 133MHz */
  201. } else {
  202. offset = 0; /* 100MHz */
  203. }
  204. reg = JCHSTtbl[offset][mode_wanted] << 16 | JCHHTtbl[offset][mode_wanted];
  205. out_be32((void __iomem *)piosht_port, reg);
  206. reg = JCHCTtbl[offset][mode_wanted];
  207. out_be32((void __iomem *)pioct_port, reg);
  208. ide_config_drive_speed(drive, speed);
  209. }
  210. /**
  211. * scc_tune_chipset - tune a drive DMA mode
  212. * @drive: Drive to set up
  213. * @xferspeed: speed we want to achieve
  214. *
  215. * Load the timing settings for this device mode into the
  216. * controller.
  217. */
  218. static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
  219. {
  220. ide_hwif_t *hwif = HWIF(drive);
  221. u8 speed = ide_rate_filter(drive, xferspeed);
  222. struct scc_ports *ports = ide_get_hwifdata(hwif);
  223. unsigned long ctl_base = ports->ctl;
  224. unsigned long cckctrl_port = ctl_base + 0xff0;
  225. unsigned long mdmact_port = ctl_base + 0x008;
  226. unsigned long mcrcst_port = ctl_base + 0x00c;
  227. unsigned long sdmact_port = ctl_base + 0x010;
  228. unsigned long scrcst_port = ctl_base + 0x014;
  229. unsigned long udenvt_port = ctl_base + 0x018;
  230. unsigned long tdvhsel_port = ctl_base + 0x020;
  231. int is_slave = (&hwif->drives[1] == drive);
  232. int offset, idx;
  233. unsigned long reg;
  234. unsigned long jcactsel;
  235. reg = in_be32((void __iomem *)cckctrl_port);
  236. if (reg & CCKCTRL_ATACLKOEN) {
  237. offset = 1; /* 133MHz */
  238. } else {
  239. offset = 0; /* 100MHz */
  240. }
  241. switch (speed) {
  242. case XFER_UDMA_6:
  243. idx = 6;
  244. break;
  245. case XFER_UDMA_5:
  246. idx = 5;
  247. break;
  248. case XFER_UDMA_4:
  249. idx = 4;
  250. break;
  251. case XFER_UDMA_3:
  252. idx = 3;
  253. break;
  254. case XFER_UDMA_2:
  255. idx = 2;
  256. break;
  257. case XFER_UDMA_1:
  258. idx = 1;
  259. break;
  260. case XFER_UDMA_0:
  261. idx = 0;
  262. break;
  263. default:
  264. return 1;
  265. }
  266. jcactsel = JCACTSELtbl[offset][idx];
  267. if (is_slave) {
  268. out_be32((void __iomem *)sdmact_port, JCHDCTxtbl[offset][idx]);
  269. out_be32((void __iomem *)scrcst_port, JCSTWTxtbl[offset][idx]);
  270. jcactsel = jcactsel << 2;
  271. out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_SLAVE) | jcactsel);
  272. } else {
  273. out_be32((void __iomem *)mdmact_port, JCHDCTxtbl[offset][idx]);
  274. out_be32((void __iomem *)mcrcst_port, JCSTWTxtbl[offset][idx]);
  275. out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_MASTER) | jcactsel);
  276. }
  277. reg = JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx];
  278. out_be32((void __iomem *)udenvt_port, reg);
  279. return ide_config_drive_speed(drive, speed);
  280. }
  281. /**
  282. * scc_config_chipset_for_dma - configure for DMA
  283. * @drive: drive to configure
  284. *
  285. * Called by scc_config_drive_for_dma().
  286. */
  287. static int scc_config_chipset_for_dma(ide_drive_t *drive)
  288. {
  289. u8 speed = ide_max_dma_mode(drive);
  290. if (!speed)
  291. return 0;
  292. if (scc_tune_chipset(drive, speed))
  293. return 0;
  294. return ide_dma_enable(drive);
  295. }
  296. /**
  297. * scc_configure_drive_for_dma - set up for DMA transfers
  298. * @drive: drive we are going to set up
  299. *
  300. * Set up the drive for DMA, tune the controller and drive as
  301. * required.
  302. * If the drive isn't suitable for DMA or we hit other problems
  303. * then we will drop down to PIO and set up PIO appropriately.
  304. * (return 1)
  305. */
  306. static int scc_config_drive_for_dma(ide_drive_t *drive)
  307. {
  308. if (ide_use_dma(drive) && scc_config_chipset_for_dma(drive))
  309. return 0;
  310. if (ide_use_fast_pio(drive))
  311. scc_tuneproc(drive, 4);
  312. return -1;
  313. }
  314. /**
  315. * scc_ide_dma_setup - begin a DMA phase
  316. * @drive: target device
  317. *
  318. * Build an IDE DMA PRD (IDE speak for scatter gather table)
  319. * and then set up the DMA transfer registers.
  320. *
  321. * Returns 0 on success. If a PIO fallback is required then 1
  322. * is returned.
  323. */
  324. static int scc_dma_setup(ide_drive_t *drive)
  325. {
  326. ide_hwif_t *hwif = drive->hwif;
  327. struct request *rq = HWGROUP(drive)->rq;
  328. unsigned int reading;
  329. u8 dma_stat;
  330. if (rq_data_dir(rq))
  331. reading = 0;
  332. else
  333. reading = 1 << 3;
  334. /* fall back to pio! */
  335. if (!ide_build_dmatable(drive, rq)) {
  336. ide_map_sg(drive, rq);
  337. return 1;
  338. }
  339. /* PRD table */
  340. out_be32((void __iomem *)hwif->dma_prdtable, hwif->dmatable_dma);
  341. /* specify r/w */
  342. out_be32((void __iomem *)hwif->dma_command, reading);
  343. /* read dma_status for INTR & ERROR flags */
  344. dma_stat = in_be32((void __iomem *)hwif->dma_status);
  345. /* clear INTR & ERROR flags */
  346. out_be32((void __iomem *)hwif->dma_status, dma_stat|6);
  347. drive->waiting_for_dma = 1;
  348. return 0;
  349. }
  350. /**
  351. * scc_ide_dma_end - Stop DMA
  352. * @drive: IDE drive
  353. *
  354. * Check and clear INT Status register.
  355. * Then call __ide_dma_end().
  356. */
  357. static int scc_ide_dma_end(ide_drive_t * drive)
  358. {
  359. ide_hwif_t *hwif = HWIF(drive);
  360. unsigned long intsts_port = hwif->dma_base + 0x014;
  361. u32 reg;
  362. while (1) {
  363. reg = in_be32((void __iomem *)intsts_port);
  364. if (reg & INTSTS_SERROR) {
  365. printk(KERN_WARNING "%s: SERROR\n", SCC_PATA_NAME);
  366. out_be32((void __iomem *)intsts_port, INTSTS_SERROR|INTSTS_BMSINT);
  367. out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
  368. continue;
  369. }
  370. if (reg & INTSTS_PRERR) {
  371. u32 maea0, maec0;
  372. unsigned long ctl_base = hwif->config_data;
  373. maea0 = in_be32((void __iomem *)(ctl_base + 0xF50));
  374. maec0 = in_be32((void __iomem *)(ctl_base + 0xF54));
  375. printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", SCC_PATA_NAME, maea0, maec0);
  376. out_be32((void __iomem *)intsts_port, INTSTS_PRERR|INTSTS_BMSINT);
  377. out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
  378. continue;
  379. }
  380. if (reg & INTSTS_RERR) {
  381. printk(KERN_WARNING "%s: Response Error\n", SCC_PATA_NAME);
  382. out_be32((void __iomem *)intsts_port, INTSTS_RERR|INTSTS_BMSINT);
  383. out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
  384. continue;
  385. }
  386. if (reg & INTSTS_ICERR) {
  387. out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
  388. printk(KERN_WARNING "%s: Illegal Configuration\n", SCC_PATA_NAME);
  389. out_be32((void __iomem *)intsts_port, INTSTS_ICERR|INTSTS_BMSINT);
  390. continue;
  391. }
  392. if (reg & INTSTS_BMSINT) {
  393. printk(KERN_WARNING "%s: Internal Bus Error\n", SCC_PATA_NAME);
  394. out_be32((void __iomem *)intsts_port, INTSTS_BMSINT);
  395. ide_do_reset(drive);
  396. continue;
  397. }
  398. if (reg & INTSTS_BMHE) {
  399. out_be32((void __iomem *)intsts_port, INTSTS_BMHE);
  400. continue;
  401. }
  402. if (reg & INTSTS_ACTEINT) {
  403. out_be32((void __iomem *)intsts_port, INTSTS_ACTEINT);
  404. continue;
  405. }
  406. if (reg & INTSTS_IOIRQS) {
  407. out_be32((void __iomem *)intsts_port, INTSTS_IOIRQS);
  408. continue;
  409. }
  410. break;
  411. }
  412. return __ide_dma_end(drive);
  413. }
  414. /* returns 1 if dma irq issued, 0 otherwise */
  415. static int scc_dma_test_irq(ide_drive_t *drive)
  416. {
  417. ide_hwif_t *hwif = HWIF(drive);
  418. u8 dma_stat = hwif->INB(hwif->dma_status);
  419. /* return 1 if INTR asserted */
  420. if ((dma_stat & 4) == 4)
  421. return 1;
  422. /* Workaround for PTERADD: emulate DMA_INTR when
  423. * - IDE_STATUS[ERR] = 1
  424. * - INT_STATUS[INTRQ] = 1
  425. * - DMA_STATUS[IORACTA] = 1
  426. */
  427. if (in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT &&
  428. in_be32((void __iomem *)(hwif->dma_base + 0x014)) & INTSTS_INTRQ &&
  429. dma_stat & 1)
  430. return 1;
  431. if (!drive->waiting_for_dma)
  432. printk(KERN_WARNING "%s: (%s) called while not waiting\n",
  433. drive->name, __FUNCTION__);
  434. return 0;
  435. }
  436. /**
  437. * setup_mmio_scc - map CTRL/BMID region
  438. * @dev: PCI device we are configuring
  439. * @name: device name
  440. *
  441. */
  442. static int setup_mmio_scc (struct pci_dev *dev, const char *name)
  443. {
  444. unsigned long ctl_base = pci_resource_start(dev, 0);
  445. unsigned long dma_base = pci_resource_start(dev, 1);
  446. unsigned long ctl_size = pci_resource_len(dev, 0);
  447. unsigned long dma_size = pci_resource_len(dev, 1);
  448. void *ctl_addr;
  449. void *dma_addr;
  450. int i;
  451. for (i = 0; i < MAX_HWIFS; i++) {
  452. if (scc_ports[i].ctl == 0)
  453. break;
  454. }
  455. if (i >= MAX_HWIFS)
  456. return -ENOMEM;
  457. if (!request_mem_region(ctl_base, ctl_size, name)) {
  458. printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
  459. goto fail_0;
  460. }
  461. if (!request_mem_region(dma_base, dma_size, name)) {
  462. printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
  463. goto fail_1;
  464. }
  465. if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL)
  466. goto fail_2;
  467. if ((dma_addr = ioremap(dma_base, dma_size)) == NULL)
  468. goto fail_3;
  469. pci_set_master(dev);
  470. scc_ports[i].ctl = (unsigned long)ctl_addr;
  471. scc_ports[i].dma = (unsigned long)dma_addr;
  472. pci_set_drvdata(dev, (void *) &scc_ports[i]);
  473. return 1;
  474. fail_3:
  475. iounmap(ctl_addr);
  476. fail_2:
  477. release_mem_region(dma_base, dma_size);
  478. fail_1:
  479. release_mem_region(ctl_base, ctl_size);
  480. fail_0:
  481. return -ENOMEM;
  482. }
  483. /**
  484. * init_setup_scc - set up an SCC PATA Controller
  485. * @dev: PCI device
  486. * @d: IDE PCI device
  487. *
  488. * Perform the initial set up for this device.
  489. */
  490. static int __devinit init_setup_scc(struct pci_dev *dev, ide_pci_device_t *d)
  491. {
  492. unsigned long ctl_base;
  493. unsigned long dma_base;
  494. unsigned long cckctrl_port;
  495. unsigned long intmask_port;
  496. unsigned long mode_port;
  497. unsigned long ecmode_port;
  498. unsigned long dma_status_port;
  499. u32 reg = 0;
  500. struct scc_ports *ports;
  501. int rc;
  502. rc = setup_mmio_scc(dev, d->name);
  503. if (rc < 0) {
  504. return rc;
  505. }
  506. ports = pci_get_drvdata(dev);
  507. ctl_base = ports->ctl;
  508. dma_base = ports->dma;
  509. cckctrl_port = ctl_base + 0xff0;
  510. intmask_port = dma_base + 0x010;
  511. mode_port = ctl_base + 0x024;
  512. ecmode_port = ctl_base + 0xf00;
  513. dma_status_port = dma_base + 0x004;
  514. /* controller initialization */
  515. reg = 0;
  516. out_be32((void*)cckctrl_port, reg);
  517. reg |= CCKCTRL_ATACLKOEN;
  518. out_be32((void*)cckctrl_port, reg);
  519. reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
  520. out_be32((void*)cckctrl_port, reg);
  521. reg |= CCKCTRL_CRST;
  522. out_be32((void*)cckctrl_port, reg);
  523. for (;;) {
  524. reg = in_be32((void*)cckctrl_port);
  525. if (reg & CCKCTRL_CRST)
  526. break;
  527. udelay(5000);
  528. }
  529. reg |= CCKCTRL_ATARESET;
  530. out_be32((void*)cckctrl_port, reg);
  531. out_be32((void*)ecmode_port, ECMODE_VALUE);
  532. out_be32((void*)mode_port, MODE_JCUSFEN);
  533. out_be32((void*)intmask_port, INTMASK_MSK);
  534. return ide_setup_pci_device(dev, d);
  535. }
  536. /**
  537. * init_mmio_iops_scc - set up the iops for MMIO
  538. * @hwif: interface to set up
  539. *
  540. */
  541. static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif)
  542. {
  543. struct pci_dev *dev = hwif->pci_dev;
  544. struct scc_ports *ports = pci_get_drvdata(dev);
  545. unsigned long dma_base = ports->dma;
  546. ide_set_hwifdata(hwif, ports);
  547. hwif->INB = scc_ide_inb;
  548. hwif->INW = scc_ide_inw;
  549. hwif->INSW = scc_ide_insw;
  550. hwif->INSL = scc_ide_insl;
  551. hwif->OUTB = scc_ide_outb;
  552. hwif->OUTBSYNC = scc_ide_outbsync;
  553. hwif->OUTW = scc_ide_outw;
  554. hwif->OUTSW = scc_ide_outsw;
  555. hwif->OUTSL = scc_ide_outsl;
  556. hwif->io_ports[IDE_DATA_OFFSET] = dma_base + 0x20;
  557. hwif->io_ports[IDE_ERROR_OFFSET] = dma_base + 0x24;
  558. hwif->io_ports[IDE_NSECTOR_OFFSET] = dma_base + 0x28;
  559. hwif->io_ports[IDE_SECTOR_OFFSET] = dma_base + 0x2c;
  560. hwif->io_ports[IDE_LCYL_OFFSET] = dma_base + 0x30;
  561. hwif->io_ports[IDE_HCYL_OFFSET] = dma_base + 0x34;
  562. hwif->io_ports[IDE_SELECT_OFFSET] = dma_base + 0x38;
  563. hwif->io_ports[IDE_STATUS_OFFSET] = dma_base + 0x3c;
  564. hwif->io_ports[IDE_CONTROL_OFFSET] = dma_base + 0x40;
  565. hwif->irq = hwif->pci_dev->irq;
  566. hwif->dma_base = dma_base;
  567. hwif->config_data = ports->ctl;
  568. hwif->mmio = 1;
  569. }
  570. /**
  571. * init_iops_scc - set up iops
  572. * @hwif: interface to set up
  573. *
  574. * Do the basic setup for the SCC hardware interface
  575. * and then do the MMIO setup.
  576. */
  577. static void __devinit init_iops_scc(ide_hwif_t *hwif)
  578. {
  579. struct pci_dev *dev = hwif->pci_dev;
  580. hwif->hwif_data = NULL;
  581. if (pci_get_drvdata(dev) == NULL)
  582. return;
  583. init_mmio_iops_scc(hwif);
  584. }
  585. /**
  586. * init_hwif_scc - set up hwif
  587. * @hwif: interface to set up
  588. *
  589. * We do the basic set up of the interface structure. The SCC
  590. * requires several custom handlers so we override the default
  591. * ide DMA handlers appropriately.
  592. */
  593. static void __devinit init_hwif_scc(ide_hwif_t *hwif)
  594. {
  595. struct scc_ports *ports = ide_get_hwifdata(hwif);
  596. ports->hwif_id = hwif->index;
  597. hwif->dma_command = hwif->dma_base;
  598. hwif->dma_status = hwif->dma_base + 0x04;
  599. hwif->dma_prdtable = hwif->dma_base + 0x08;
  600. /* PTERADD */
  601. out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma);
  602. hwif->dma_setup = scc_dma_setup;
  603. hwif->ide_dma_end = scc_ide_dma_end;
  604. hwif->speedproc = scc_tune_chipset;
  605. hwif->tuneproc = scc_tuneproc;
  606. hwif->ide_dma_check = scc_config_drive_for_dma;
  607. hwif->ide_dma_test_irq = scc_dma_test_irq;
  608. hwif->drives[0].autotune = IDE_TUNE_AUTO;
  609. hwif->drives[1].autotune = IDE_TUNE_AUTO;
  610. if (in_be32((void __iomem *)(hwif->config_data + 0xff0)) & CCKCTRL_ATACLKOEN) {
  611. hwif->ultra_mask = 0x7f; /* 133MHz */
  612. } else {
  613. hwif->ultra_mask = 0x3f; /* 100MHz */
  614. }
  615. hwif->mwdma_mask = 0x00;
  616. hwif->swdma_mask = 0x00;
  617. hwif->atapi_dma = 1;
  618. /* we support 80c cable only. */
  619. hwif->udma_four = 1;
  620. hwif->autodma = 0;
  621. if (!noautodma)
  622. hwif->autodma = 1;
  623. hwif->drives[0].autodma = hwif->autodma;
  624. hwif->drives[1].autodma = hwif->autodma;
  625. }
  626. #define DECLARE_SCC_DEV(name_str) \
  627. { \
  628. .name = name_str, \
  629. .init_setup = init_setup_scc, \
  630. .init_iops = init_iops_scc, \
  631. .init_hwif = init_hwif_scc, \
  632. .channels = 1, \
  633. .autodma = AUTODMA, \
  634. .bootable = ON_BOARD, \
  635. }
  636. static ide_pci_device_t scc_chipsets[] __devinitdata = {
  637. /* 0 */ DECLARE_SCC_DEV("sccIDE"),
  638. };
  639. /**
  640. * scc_init_one - pci layer discovery entry
  641. * @dev: PCI device
  642. * @id: ident table entry
  643. *
  644. * Called by the PCI code when it finds an SCC PATA controller.
  645. * We then use the IDE PCI generic helper to do most of the work.
  646. */
  647. static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  648. {
  649. ide_pci_device_t *d = &scc_chipsets[id->driver_data];
  650. return d->init_setup(dev, d);
  651. }
  652. /**
  653. * scc_remove - pci layer remove entry
  654. * @dev: PCI device
  655. *
  656. * Called by the PCI code when it removes an SCC PATA controller.
  657. */
  658. static void __devexit scc_remove(struct pci_dev *dev)
  659. {
  660. struct scc_ports *ports = pci_get_drvdata(dev);
  661. ide_hwif_t *hwif = &ide_hwifs[ports->hwif_id];
  662. unsigned long ctl_base = pci_resource_start(dev, 0);
  663. unsigned long dma_base = pci_resource_start(dev, 1);
  664. unsigned long ctl_size = pci_resource_len(dev, 0);
  665. unsigned long dma_size = pci_resource_len(dev, 1);
  666. if (hwif->dmatable_cpu) {
  667. pci_free_consistent(hwif->pci_dev,
  668. PRD_ENTRIES * PRD_BYTES,
  669. hwif->dmatable_cpu,
  670. hwif->dmatable_dma);
  671. hwif->dmatable_cpu = NULL;
  672. }
  673. ide_unregister(hwif->index);
  674. hwif->chipset = ide_unknown;
  675. iounmap((void*)ports->dma);
  676. iounmap((void*)ports->ctl);
  677. release_mem_region(dma_base, dma_size);
  678. release_mem_region(ctl_base, ctl_size);
  679. memset(ports, 0, sizeof(*ports));
  680. }
  681. static struct pci_device_id scc_pci_tbl[] = {
  682. { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  683. { 0, },
  684. };
  685. MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
  686. static struct pci_driver driver = {
  687. .name = "SCC IDE",
  688. .id_table = scc_pci_tbl,
  689. .probe = scc_init_one,
  690. .remove = scc_remove,
  691. };
  692. static int scc_ide_init(void)
  693. {
  694. return ide_pci_register_driver(&driver);
  695. }
  696. module_init(scc_ide_init);
  697. /* -- No exit code?
  698. static void scc_ide_exit(void)
  699. {
  700. ide_pci_unregister_driver(&driver);
  701. }
  702. module_exit(scc_ide_exit);
  703. */
  704. MODULE_DESCRIPTION("PCI driver module for Toshiba SCC IDE");
  705. MODULE_LICENSE("GPL");