serverworks.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * linux/drivers/ide/pci/serverworks.c Version 0.8 25 Ebr 2003
  3. *
  4. * Copyright (C) 1998-2000 Michel Aubry
  5. * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
  6. * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  7. * Portions copyright (c) 2001 Sun Microsystems
  8. *
  9. *
  10. * RCC/ServerWorks IDE driver for Linux
  11. *
  12. * OSB4: `Open South Bridge' IDE Interface (fn 1)
  13. * supports UDMA mode 2 (33 MB/s)
  14. *
  15. * CSB5: `Champion South Bridge' IDE Interface (fn 1)
  16. * all revisions support UDMA mode 4 (66 MB/s)
  17. * revision A2.0 and up support UDMA mode 5 (100 MB/s)
  18. *
  19. * *** The CSB5 does not provide ANY register ***
  20. * *** to detect 80-conductor cable presence. ***
  21. *
  22. * CSB6: `Champion South Bridge' IDE Interface (optional: third channel)
  23. *
  24. * Documentation:
  25. * Available under NDA only. Errata info very hard to get.
  26. *
  27. */
  28. #include <linux/config.h>
  29. #include <linux/types.h>
  30. #include <linux/module.h>
  31. #include <linux/kernel.h>
  32. #include <linux/ioport.h>
  33. #include <linux/pci.h>
  34. #include <linux/hdreg.h>
  35. #include <linux/ide.h>
  36. #include <linux/init.h>
  37. #include <linux/delay.h>
  38. #include <asm/io.h>
  39. #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
  40. #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
  41. /* Seagate Barracuda ATA IV Family drives in UDMA mode 5
  42. * can overrun their FIFOs when used with the CSB5 */
  43. static const char *svwks_bad_ata100[] = {
  44. "ST320011A",
  45. "ST340016A",
  46. "ST360021A",
  47. "ST380021A",
  48. NULL
  49. };
  50. static u8 svwks_revision = 0;
  51. static struct pci_dev *isa_dev;
  52. static int check_in_drive_lists (ide_drive_t *drive, const char **list)
  53. {
  54. while (*list)
  55. if (!strcmp(*list++, drive->id->model))
  56. return 1;
  57. return 0;
  58. }
  59. static u8 svwks_ratemask (ide_drive_t *drive)
  60. {
  61. struct pci_dev *dev = HWIF(drive)->pci_dev;
  62. u8 mode;
  63. if (!svwks_revision)
  64. pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
  65. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  66. u32 reg = 0;
  67. if (isa_dev)
  68. pci_read_config_dword(isa_dev, 0x64, &reg);
  69. /*
  70. * Don't enable UDMA on disk devices for the moment
  71. */
  72. if(drive->media == ide_disk)
  73. return 0;
  74. /* Check the OSB4 DMA33 enable bit */
  75. return ((reg & 0x00004000) == 0x00004000) ? 1 : 0;
  76. } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
  77. return 1;
  78. } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
  79. u8 btr = 0;
  80. pci_read_config_byte(dev, 0x5A, &btr);
  81. mode = btr & 0x3;
  82. if (!eighty_ninty_three(drive))
  83. mode = min(mode, (u8)1);
  84. /* If someone decides to do UDMA133 on CSB5 the same
  85. issue will bite so be inclusive */
  86. if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
  87. mode = 2;
  88. }
  89. if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  90. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
  91. (!(PCI_FUNC(dev->devfn) & 1)))
  92. mode = 2;
  93. return mode;
  94. }
  95. static u8 svwks_csb_check (struct pci_dev *dev)
  96. {
  97. switch (dev->device) {
  98. case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE:
  99. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE:
  100. case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2:
  101. return 1;
  102. default:
  103. break;
  104. }
  105. return 0;
  106. }
  107. static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  108. {
  109. u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
  110. u8 dma_modes[] = { 0x77, 0x21, 0x20 };
  111. u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 };
  112. u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 };
  113. u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 };
  114. ide_hwif_t *hwif = HWIF(drive);
  115. struct pci_dev *dev = hwif->pci_dev;
  116. u8 speed;
  117. u8 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
  118. u8 unit = (drive->select.b.unit & 0x01);
  119. u8 csb5 = svwks_csb_check(dev);
  120. u8 ultra_enable = 0, ultra_timing = 0;
  121. u8 dma_timing = 0, pio_timing = 0;
  122. u16 csb5_pio = 0;
  123. if (xferspeed == 255) /* PIO auto-tuning */
  124. speed = XFER_PIO_0 + pio;
  125. else
  126. speed = ide_rate_filter(svwks_ratemask(drive), xferspeed);
  127. /* If we are about to put a disk into UDMA mode we screwed up.
  128. Our code assumes we never _ever_ do this on an OSB4 */
  129. if(dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4 &&
  130. drive->media == ide_disk && speed >= XFER_UDMA_0)
  131. BUG();
  132. pci_read_config_byte(dev, drive_pci[drive->dn], &pio_timing);
  133. pci_read_config_byte(dev, drive_pci2[drive->dn], &dma_timing);
  134. pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing);
  135. pci_read_config_word(dev, 0x4A, &csb5_pio);
  136. pci_read_config_byte(dev, 0x54, &ultra_enable);
  137. /* Per Specified Design by OEM, and ASIC Architect */
  138. if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  139. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
  140. if (!drive->init_speed) {
  141. u8 dma_stat = hwif->INB(hwif->dma_status);
  142. dma_pio:
  143. if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
  144. ((dma_stat & (1<<(5+unit))) == (1<<(5+unit)))) {
  145. drive->current_speed = drive->init_speed = XFER_UDMA_0 + udma_modes[(ultra_timing >> (4*unit)) & ~(0xF0)];
  146. return 0;
  147. } else if ((dma_timing) &&
  148. ((dma_stat&(1<<(5+unit)))==(1<<(5+unit)))) {
  149. u8 dmaspeed = dma_timing;
  150. dma_timing &= ~0xFF;
  151. if ((dmaspeed & 0x20) == 0x20)
  152. dmaspeed = XFER_MW_DMA_2;
  153. else if ((dmaspeed & 0x21) == 0x21)
  154. dmaspeed = XFER_MW_DMA_1;
  155. else if ((dmaspeed & 0x77) == 0x77)
  156. dmaspeed = XFER_MW_DMA_0;
  157. else
  158. goto dma_pio;
  159. drive->current_speed = drive->init_speed = dmaspeed;
  160. return 0;
  161. } else if (pio_timing) {
  162. u8 piospeed = pio_timing;
  163. pio_timing &= ~0xFF;
  164. if ((piospeed & 0x20) == 0x20)
  165. piospeed = XFER_PIO_4;
  166. else if ((piospeed & 0x22) == 0x22)
  167. piospeed = XFER_PIO_3;
  168. else if ((piospeed & 0x34) == 0x34)
  169. piospeed = XFER_PIO_2;
  170. else if ((piospeed & 0x47) == 0x47)
  171. piospeed = XFER_PIO_1;
  172. else if ((piospeed & 0x5d) == 0x5d)
  173. piospeed = XFER_PIO_0;
  174. else
  175. goto oem_setup_failed;
  176. drive->current_speed = drive->init_speed = piospeed;
  177. return 0;
  178. }
  179. }
  180. }
  181. oem_setup_failed:
  182. pio_timing &= ~0xFF;
  183. dma_timing &= ~0xFF;
  184. ultra_timing &= ~(0x0F << (4*unit));
  185. ultra_enable &= ~(0x01 << drive->dn);
  186. csb5_pio &= ~(0x0F << (4*drive->dn));
  187. switch(speed) {
  188. case XFER_PIO_4:
  189. case XFER_PIO_3:
  190. case XFER_PIO_2:
  191. case XFER_PIO_1:
  192. case XFER_PIO_0:
  193. pio_timing |= pio_modes[speed - XFER_PIO_0];
  194. csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn));
  195. break;
  196. case XFER_MW_DMA_2:
  197. case XFER_MW_DMA_1:
  198. case XFER_MW_DMA_0:
  199. pio_timing |= pio_modes[pio];
  200. csb5_pio |= (pio << (4*drive->dn));
  201. dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
  202. break;
  203. case XFER_UDMA_5:
  204. case XFER_UDMA_4:
  205. case XFER_UDMA_3:
  206. case XFER_UDMA_2:
  207. case XFER_UDMA_1:
  208. case XFER_UDMA_0:
  209. pio_timing |= pio_modes[pio];
  210. csb5_pio |= (pio << (4*drive->dn));
  211. dma_timing |= dma_modes[2];
  212. ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit));
  213. ultra_enable |= (0x01 << drive->dn);
  214. default:
  215. break;
  216. }
  217. pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing);
  218. if (csb5)
  219. pci_write_config_word(dev, 0x4A, csb5_pio);
  220. pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing);
  221. pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing);
  222. pci_write_config_byte(dev, 0x54, ultra_enable);
  223. return (ide_config_drive_speed(drive, speed));
  224. }
  225. static void config_chipset_for_pio (ide_drive_t *drive)
  226. {
  227. u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
  228. u16 xfer_pio = drive->id->eide_pio_modes;
  229. u8 timing, speed, pio;
  230. pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
  231. if (xfer_pio > 4)
  232. xfer_pio = 0;
  233. if (drive->id->eide_pio_iordy > 0)
  234. for (xfer_pio = 5;
  235. xfer_pio>0 &&
  236. drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
  237. xfer_pio--);
  238. else
  239. xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
  240. (drive->id->eide_pio_modes & 2) ? 0x04 :
  241. (drive->id->eide_pio_modes & 1) ? 0x03 :
  242. (drive->id->tPIO & 2) ? 0x02 :
  243. (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
  244. timing = (xfer_pio >= pio) ? xfer_pio : pio;
  245. switch(timing) {
  246. case 4: speed = XFER_PIO_4;break;
  247. case 3: speed = XFER_PIO_3;break;
  248. case 2: speed = XFER_PIO_2;break;
  249. case 1: speed = XFER_PIO_1;break;
  250. default:
  251. speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
  252. break;
  253. }
  254. (void) svwks_tune_chipset(drive, speed);
  255. drive->current_speed = speed;
  256. }
  257. static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
  258. {
  259. if(pio == 255)
  260. (void) svwks_tune_chipset(drive, 255);
  261. else
  262. (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio));
  263. }
  264. static int config_chipset_for_dma (ide_drive_t *drive)
  265. {
  266. u8 speed = ide_dma_speed(drive, svwks_ratemask(drive));
  267. if (!(speed))
  268. speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
  269. (void) svwks_tune_chipset(drive, speed);
  270. return ide_dma_enable(drive);
  271. }
  272. static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
  273. {
  274. ide_hwif_t *hwif = HWIF(drive);
  275. struct hd_driveid *id = drive->id;
  276. drive->init_speed = 0;
  277. if ((id->capability & 1) && drive->autodma) {
  278. if (ide_use_dma(drive)) {
  279. if (config_chipset_for_dma(drive))
  280. return hwif->ide_dma_on(drive);
  281. }
  282. goto fast_ata_pio;
  283. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  284. fast_ata_pio:
  285. config_chipset_for_pio(drive);
  286. // hwif->tuneproc(drive, 5);
  287. return hwif->ide_dma_off_quietly(drive);
  288. }
  289. /* IORDY not supported */
  290. return 0;
  291. }
  292. /* This can go soon */
  293. static int svwks_ide_dma_end (ide_drive_t *drive)
  294. {
  295. return __ide_dma_end(drive);
  296. }
  297. static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
  298. {
  299. unsigned int reg;
  300. u8 btr;
  301. /* save revision id to determine DMA capability */
  302. pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
  303. /* force Master Latency Timer value to 64 PCICLKs */
  304. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40);
  305. /* OSB4 : South Bridge and IDE */
  306. if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
  307. isa_dev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  308. PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL);
  309. if (isa_dev) {
  310. pci_read_config_dword(isa_dev, 0x64, &reg);
  311. reg &= ~0x00002000; /* disable 600ns interrupt mask */
  312. if(!(reg & 0x00004000))
  313. printk(KERN_DEBUG "%s: UDMA not BIOS enabled.\n", name);
  314. reg |= 0x00004000; /* enable UDMA/33 support */
  315. pci_write_config_dword(isa_dev, 0x64, reg);
  316. }
  317. }
  318. /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
  319. else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
  320. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  321. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
  322. /* Third Channel Test */
  323. if (!(PCI_FUNC(dev->devfn) & 1)) {
  324. struct pci_dev * findev = NULL;
  325. u32 reg4c = 0;
  326. findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  327. PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL);
  328. if (findev) {
  329. pci_read_config_dword(findev, 0x4C, &reg4c);
  330. reg4c &= ~0x000007FF;
  331. reg4c |= 0x00000040;
  332. reg4c |= 0x00000020;
  333. pci_write_config_dword(findev, 0x4C, reg4c);
  334. }
  335. outb_p(0x06, 0x0c00);
  336. dev->irq = inb_p(0x0c01);
  337. #if 0
  338. printk("%s: device class (0x%04x)\n",
  339. name, dev->class);
  340. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
  341. dev->class &= ~0x000F0F00;
  342. // dev->class |= ~0x00000400;
  343. dev->class |= ~0x00010100;
  344. /**/
  345. }
  346. #endif
  347. } else {
  348. struct pci_dev * findev = NULL;
  349. u8 reg41 = 0;
  350. findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS,
  351. PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL);
  352. if (findev) {
  353. pci_read_config_byte(findev, 0x41, &reg41);
  354. reg41 &= ~0x40;
  355. pci_write_config_byte(findev, 0x41, reg41);
  356. }
  357. /*
  358. * This is a device pin issue on CSB6.
  359. * Since there will be a future raid mode,
  360. * early versions of the chipset require the
  361. * interrupt pin to be set, and it is a compatibility
  362. * mode issue.
  363. */
  364. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  365. dev->irq = 0;
  366. }
  367. // pci_read_config_dword(dev, 0x40, &pioreg)
  368. // pci_write_config_dword(dev, 0x40, 0x99999999);
  369. // pci_read_config_dword(dev, 0x44, &dmareg);
  370. // pci_write_config_dword(dev, 0x44, 0xFFFFFFFF);
  371. /* setup the UDMA Control register
  372. *
  373. * 1. clear bit 6 to enable DMA
  374. * 2. enable DMA modes with bits 0-1
  375. * 00 : legacy
  376. * 01 : udma2
  377. * 10 : udma2/udma4
  378. * 11 : udma2/udma4/udma5
  379. */
  380. pci_read_config_byte(dev, 0x5A, &btr);
  381. btr &= ~0x40;
  382. if (!(PCI_FUNC(dev->devfn) & 1))
  383. btr |= 0x2;
  384. else
  385. btr |= (svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2;
  386. pci_write_config_byte(dev, 0x5A, btr);
  387. }
  388. return (dev->irq) ? dev->irq : 0;
  389. }
  390. static unsigned int __devinit ata66_svwks_svwks (ide_hwif_t *hwif)
  391. {
  392. return 1;
  393. }
  394. /* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits
  395. * of the subsystem device ID indicate presence of an 80-pin cable.
  396. * Bit 15 clear = secondary IDE channel does not have 80-pin cable.
  397. * Bit 15 set = secondary IDE channel has 80-pin cable.
  398. * Bit 14 clear = primary IDE channel does not have 80-pin cable.
  399. * Bit 14 set = primary IDE channel has 80-pin cable.
  400. */
  401. static unsigned int __devinit ata66_svwks_dell (ide_hwif_t *hwif)
  402. {
  403. struct pci_dev *dev = hwif->pci_dev;
  404. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
  405. dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  406. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE ||
  407. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE))
  408. return ((1 << (hwif->channel + 14)) &
  409. dev->subsystem_device) ? 1 : 0;
  410. return 0;
  411. }
  412. /* Sun Cobalt Alpine hardware avoids the 80-pin cable
  413. * detect issue by attaching the drives directly to the board.
  414. * This check follows the Dell precedent (how scary is that?!)
  415. *
  416. * WARNING: this only works on Alpine hardware!
  417. */
  418. static unsigned int __devinit ata66_svwks_cobalt (ide_hwif_t *hwif)
  419. {
  420. struct pci_dev *dev = hwif->pci_dev;
  421. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN &&
  422. dev->vendor == PCI_VENDOR_ID_SERVERWORKS &&
  423. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
  424. return ((1 << (hwif->channel + 14)) &
  425. dev->subsystem_device) ? 1 : 0;
  426. return 0;
  427. }
  428. static unsigned int __devinit ata66_svwks (ide_hwif_t *hwif)
  429. {
  430. struct pci_dev *dev = hwif->pci_dev;
  431. /* Per Specified Design by OEM, and ASIC Architect */
  432. if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  433. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2))
  434. return 1;
  435. /* Server Works */
  436. if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS)
  437. return ata66_svwks_svwks (hwif);
  438. /* Dell PowerEdge */
  439. if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL)
  440. return ata66_svwks_dell (hwif);
  441. /* Cobalt Alpine */
  442. if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN)
  443. return ata66_svwks_cobalt (hwif);
  444. return 0;
  445. }
  446. #undef CAN_SW_DMA
  447. static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
  448. {
  449. u8 dma_stat = 0;
  450. if (!hwif->irq)
  451. hwif->irq = hwif->channel ? 15 : 14;
  452. hwif->tuneproc = &svwks_tune_drive;
  453. hwif->speedproc = &svwks_tune_chipset;
  454. hwif->atapi_dma = 1;
  455. if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
  456. hwif->ultra_mask = 0x3f;
  457. hwif->mwdma_mask = 0x07;
  458. #ifdef CAN_SW_DMA
  459. hwif->swdma_mask = 0x07;
  460. #endif /* CAN_SW_DMA */
  461. hwif->autodma = 0;
  462. if (!hwif->dma_base) {
  463. hwif->drives[0].autotune = 1;
  464. hwif->drives[1].autotune = 1;
  465. return;
  466. }
  467. hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
  468. if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE)
  469. hwif->ide_dma_end = &svwks_ide_dma_end;
  470. else if (!(hwif->udma_four))
  471. hwif->udma_four = ata66_svwks(hwif);
  472. if (!noautodma)
  473. hwif->autodma = 1;
  474. dma_stat = hwif->INB(hwif->dma_status);
  475. hwif->drives[0].autodma = (dma_stat & 0x20);
  476. hwif->drives[1].autodma = (dma_stat & 0x40);
  477. hwif->drives[0].autotune = (!(dma_stat & 0x20));
  478. hwif->drives[1].autotune = (!(dma_stat & 0x40));
  479. // hwif->drives[0].autodma = hwif->autodma;
  480. // hwif->drives[1].autodma = hwif->autodma;
  481. }
  482. /*
  483. * We allow the BM-DMA driver to only work on enabled interfaces.
  484. */
  485. static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase)
  486. {
  487. struct pci_dev *dev = hwif->pci_dev;
  488. if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
  489. (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
  490. (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel))
  491. return;
  492. ide_setup_dma(hwif, dmabase, 8);
  493. }
  494. static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
  495. {
  496. return ide_setup_pci_device(dev, d);
  497. }
  498. static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d)
  499. {
  500. if (!(PCI_FUNC(dev->devfn) & 1)) {
  501. d->bootable = NEVER_BOARD;
  502. if (dev->resource[0].start == 0x01f1)
  503. d->bootable = ON_BOARD;
  504. }
  505. #if 0
  506. if ((IDE_PCI_DEVID_EQ(d->devid, DEVID_CSB6) &&
  507. (!(PCI_FUNC(dev->devfn) & 1)))
  508. d->autodma = AUTODMA;
  509. #endif
  510. d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE ||
  511. dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) &&
  512. (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2;
  513. return ide_setup_pci_device(dev, d);
  514. }
  515. static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
  516. { /* 0 */
  517. .name = "SvrWks OSB4",
  518. .init_setup = init_setup_svwks,
  519. .init_chipset = init_chipset_svwks,
  520. .init_hwif = init_hwif_svwks,
  521. .channels = 2,
  522. .autodma = AUTODMA,
  523. .bootable = ON_BOARD,
  524. },{ /* 1 */
  525. .name = "SvrWks CSB5",
  526. .init_setup = init_setup_svwks,
  527. .init_chipset = init_chipset_svwks,
  528. .init_hwif = init_hwif_svwks,
  529. .init_dma = init_dma_svwks,
  530. .channels = 2,
  531. .autodma = AUTODMA,
  532. .bootable = ON_BOARD,
  533. },{ /* 2 */
  534. .name = "SvrWks CSB6",
  535. .init_setup = init_setup_csb6,
  536. .init_chipset = init_chipset_svwks,
  537. .init_hwif = init_hwif_svwks,
  538. .init_dma = init_dma_svwks,
  539. .channels = 2,
  540. .autodma = AUTODMA,
  541. .bootable = ON_BOARD,
  542. },{ /* 3 */
  543. .name = "SvrWks CSB6",
  544. .init_setup = init_setup_csb6,
  545. .init_chipset = init_chipset_svwks,
  546. .init_hwif = init_hwif_svwks,
  547. .init_dma = init_dma_svwks,
  548. .channels = 1, /* 2 */
  549. .autodma = AUTODMA,
  550. .bootable = ON_BOARD,
  551. }
  552. };
  553. /**
  554. * svwks_init_one - called when a OSB/CSB is found
  555. * @dev: the svwks device
  556. * @id: the matching pci id
  557. *
  558. * Called when the PCI registration layer (or the IDE initialization)
  559. * finds a device matching our IDE device tables.
  560. */
  561. static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  562. {
  563. ide_pci_device_t *d = &serverworks_chipsets[id->driver_data];
  564. return d->init_setup(dev, d);
  565. }
  566. static struct pci_device_id svwks_pci_tbl[] = {
  567. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  568. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  569. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  570. { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  571. { 0, },
  572. };
  573. MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
  574. static struct pci_driver driver = {
  575. .name = "Serverworks_IDE",
  576. .id_table = svwks_pci_tbl,
  577. .probe = svwks_init_one,
  578. };
  579. static int svwks_ide_init(void)
  580. {
  581. return ide_pci_register_driver(&driver);
  582. }
  583. module_init(svwks_ide_init);
  584. MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick");
  585. MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE");
  586. MODULE_LICENSE("GPL");