serverworks.c 19 KB

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