alim15x3.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * linux/drivers/ide/pci/alim15x3.c Version 0.25 Jun 9 2007
  3. *
  4. * Copyright (C) 1998-2000 Michel Aubry, Maintainer
  5. * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
  6. * Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer
  7. *
  8. * Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org)
  9. * May be copied or modified under the terms of the GNU General Public License
  10. * Copyright (C) 2002 Alan Cox <alan@redhat.com>
  11. * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw>
  12. * Copyright (C) 2007 MontaVista Software, Inc. <source@mvista.com>
  13. * Copyright (C) 2007 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
  14. *
  15. * (U)DMA capable version of ali 1533/1543(C), 1535(D)
  16. *
  17. **********************************************************************
  18. * 9/7/99 --Parts from the above author are included and need to be
  19. * converted into standard interface, once I finish the thought.
  20. *
  21. * Recent changes
  22. * Don't use LBA48 mode on ALi <= 0xC4
  23. * Don't poke 0x79 with a non ALi northbridge
  24. * Don't flip undefined bits on newer chipsets (fix Fujitsu laptop hang)
  25. * Allow UDMA6 on revisions > 0xC4
  26. *
  27. * Documentation
  28. * Chipset documentation available under NDA only
  29. *
  30. */
  31. #include <linux/module.h>
  32. #include <linux/types.h>
  33. #include <linux/kernel.h>
  34. #include <linux/pci.h>
  35. #include <linux/delay.h>
  36. #include <linux/hdreg.h>
  37. #include <linux/ide.h>
  38. #include <linux/init.h>
  39. #include <linux/dmi.h>
  40. #include <asm/io.h>
  41. #define DISPLAY_ALI_TIMINGS
  42. /*
  43. * ALi devices are not plug in. Otherwise these static values would
  44. * need to go. They ought to go away anyway
  45. */
  46. static u8 m5229_revision;
  47. static u8 chip_is_1543c_e;
  48. static struct pci_dev *isa_dev;
  49. #if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
  50. #include <linux/stat.h>
  51. #include <linux/proc_fs.h>
  52. static u8 ali_proc = 0;
  53. static struct pci_dev *bmide_dev;
  54. static char *fifo[4] = {
  55. "FIFO Off",
  56. "FIFO On ",
  57. "DMA mode",
  58. "PIO mode" };
  59. static char *udmaT[8] = {
  60. "1.5T",
  61. " 2T",
  62. "2.5T",
  63. " 3T",
  64. "3.5T",
  65. " 4T",
  66. " 6T",
  67. " 8T"
  68. };
  69. static char *channel_status[8] = {
  70. "OK ",
  71. "busy ",
  72. "DRQ ",
  73. "DRQ busy ",
  74. "error ",
  75. "error busy ",
  76. "error DRQ ",
  77. "error DRQ busy"
  78. };
  79. /**
  80. * ali_get_info - generate proc file for ALi IDE
  81. * @buffer: buffer to fill
  82. * @addr: address of user start in buffer
  83. * @offset: offset into 'file'
  84. * @count: buffer count
  85. *
  86. * Walks the Ali devices and outputs summary data on the tuning and
  87. * anything else that will help with debugging
  88. */
  89. static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
  90. {
  91. unsigned long bibma;
  92. u8 reg53h, reg5xh, reg5yh, reg5xh1, reg5yh1, c0, c1, rev, tmp;
  93. char *q, *p = buffer;
  94. /* fetch rev. */
  95. pci_read_config_byte(bmide_dev, 0x08, &rev);
  96. if (rev >= 0xc1) /* M1543C or newer */
  97. udmaT[7] = " ???";
  98. else
  99. fifo[3] = " ??? ";
  100. /* first fetch bibma: */
  101. bibma = pci_resource_start(bmide_dev, 4);
  102. /*
  103. * at that point bibma+0x2 et bibma+0xa are byte
  104. * registers to investigate:
  105. */
  106. c0 = inb(bibma + 0x02);
  107. c1 = inb(bibma + 0x0a);
  108. p += sprintf(p,
  109. "\n Ali M15x3 Chipset.\n");
  110. p += sprintf(p,
  111. " ------------------\n");
  112. pci_read_config_byte(bmide_dev, 0x78, &reg53h);
  113. p += sprintf(p, "PCI Clock: %d.\n", reg53h);
  114. pci_read_config_byte(bmide_dev, 0x53, &reg53h);
  115. p += sprintf(p,
  116. "CD_ROM FIFO:%s, CD_ROM DMA:%s\n",
  117. (reg53h & 0x02) ? "Yes" : "No ",
  118. (reg53h & 0x01) ? "Yes" : "No " );
  119. pci_read_config_byte(bmide_dev, 0x74, &reg53h);
  120. p += sprintf(p,
  121. "FIFO Status: contains %d Words, runs%s%s\n\n",
  122. (reg53h & 0x3f),
  123. (reg53h & 0x40) ? " OVERWR" : "",
  124. (reg53h & 0x80) ? " OVERRD." : "." );
  125. p += sprintf(p,
  126. "-------------------primary channel"
  127. "-------------------secondary channel"
  128. "---------\n\n");
  129. pci_read_config_byte(bmide_dev, 0x09, &reg53h);
  130. p += sprintf(p,
  131. "channel status: %s"
  132. " %s\n",
  133. (reg53h & 0x20) ? "On " : "Off",
  134. (reg53h & 0x10) ? "On " : "Off" );
  135. p += sprintf(p,
  136. "both channels togth: %s"
  137. " %s\n",
  138. (c0&0x80) ? "No " : "Yes",
  139. (c1&0x80) ? "No " : "Yes" );
  140. pci_read_config_byte(bmide_dev, 0x76, &reg53h);
  141. p += sprintf(p,
  142. "Channel state: %s %s\n",
  143. channel_status[reg53h & 0x07],
  144. channel_status[(reg53h & 0x70) >> 4] );
  145. pci_read_config_byte(bmide_dev, 0x58, &reg5xh);
  146. pci_read_config_byte(bmide_dev, 0x5c, &reg5yh);
  147. p += sprintf(p,
  148. "Add. Setup Timing: %dT"
  149. " %dT\n",
  150. (reg5xh & 0x07) ? (reg5xh & 0x07) : 8,
  151. (reg5yh & 0x07) ? (reg5yh & 0x07) : 8 );
  152. pci_read_config_byte(bmide_dev, 0x59, &reg5xh);
  153. pci_read_config_byte(bmide_dev, 0x5d, &reg5yh);
  154. p += sprintf(p,
  155. "Command Act. Count: %dT"
  156. " %dT\n"
  157. "Command Rec. Count: %dT"
  158. " %dT\n\n",
  159. (reg5xh & 0x70) ? ((reg5xh & 0x70) >> 4) : 8,
  160. (reg5yh & 0x70) ? ((reg5yh & 0x70) >> 4) : 8,
  161. (reg5xh & 0x0f) ? (reg5xh & 0x0f) : 16,
  162. (reg5yh & 0x0f) ? (reg5yh & 0x0f) : 16 );
  163. p += sprintf(p,
  164. "----------------drive0-----------drive1"
  165. "------------drive0-----------drive1------\n\n");
  166. p += sprintf(p,
  167. "DMA enabled: %s %s"
  168. " %s %s\n",
  169. (c0&0x20) ? "Yes" : "No ",
  170. (c0&0x40) ? "Yes" : "No ",
  171. (c1&0x20) ? "Yes" : "No ",
  172. (c1&0x40) ? "Yes" : "No " );
  173. pci_read_config_byte(bmide_dev, 0x54, &reg5xh);
  174. pci_read_config_byte(bmide_dev, 0x55, &reg5yh);
  175. q = "FIFO threshold: %2d Words %2d Words"
  176. " %2d Words %2d Words\n";
  177. if (rev < 0xc1) {
  178. if ((rev == 0x20) &&
  179. (pci_read_config_byte(bmide_dev, 0x4f, &tmp), (tmp &= 0x20))) {
  180. p += sprintf(p, q, 8, 8, 8, 8);
  181. } else {
  182. p += sprintf(p, q,
  183. (reg5xh & 0x03) + 12,
  184. ((reg5xh & 0x30)>>4) + 12,
  185. (reg5yh & 0x03) + 12,
  186. ((reg5yh & 0x30)>>4) + 12 );
  187. }
  188. } else {
  189. int t1 = (tmp = (reg5xh & 0x03)) ? (tmp << 3) : 4;
  190. int t2 = (tmp = ((reg5xh & 0x30)>>4)) ? (tmp << 3) : 4;
  191. int t3 = (tmp = (reg5yh & 0x03)) ? (tmp << 3) : 4;
  192. int t4 = (tmp = ((reg5yh & 0x30)>>4)) ? (tmp << 3) : 4;
  193. p += sprintf(p, q, t1, t2, t3, t4);
  194. }
  195. #if 0
  196. p += sprintf(p,
  197. "FIFO threshold: %2d Words %2d Words"
  198. " %2d Words %2d Words\n",
  199. (reg5xh & 0x03) + 12,
  200. ((reg5xh & 0x30)>>4) + 12,
  201. (reg5yh & 0x03) + 12,
  202. ((reg5yh & 0x30)>>4) + 12 );
  203. #endif
  204. p += sprintf(p,
  205. "FIFO mode: %s %s %s %s\n",
  206. fifo[((reg5xh & 0x0c) >> 2)],
  207. fifo[((reg5xh & 0xc0) >> 6)],
  208. fifo[((reg5yh & 0x0c) >> 2)],
  209. fifo[((reg5yh & 0xc0) >> 6)] );
  210. pci_read_config_byte(bmide_dev, 0x5a, &reg5xh);
  211. pci_read_config_byte(bmide_dev, 0x5b, &reg5xh1);
  212. pci_read_config_byte(bmide_dev, 0x5e, &reg5yh);
  213. pci_read_config_byte(bmide_dev, 0x5f, &reg5yh1);
  214. p += sprintf(p,/*
  215. "------------------drive0-----------drive1"
  216. "------------drive0-----------drive1------\n")*/
  217. "Dt RW act. Cnt %2dT %2dT"
  218. " %2dT %2dT\n"
  219. "Dt RW rec. Cnt %2dT %2dT"
  220. " %2dT %2dT\n\n",
  221. (reg5xh & 0x70) ? ((reg5xh & 0x70) >> 4) : 8,
  222. (reg5xh1 & 0x70) ? ((reg5xh1 & 0x70) >> 4) : 8,
  223. (reg5yh & 0x70) ? ((reg5yh & 0x70) >> 4) : 8,
  224. (reg5yh1 & 0x70) ? ((reg5yh1 & 0x70) >> 4) : 8,
  225. (reg5xh & 0x0f) ? (reg5xh & 0x0f) : 16,
  226. (reg5xh1 & 0x0f) ? (reg5xh1 & 0x0f) : 16,
  227. (reg5yh & 0x0f) ? (reg5yh & 0x0f) : 16,
  228. (reg5yh1 & 0x0f) ? (reg5yh1 & 0x0f) : 16 );
  229. p += sprintf(p,
  230. "-----------------------------------UDMA Timings"
  231. "--------------------------------\n\n");
  232. pci_read_config_byte(bmide_dev, 0x56, &reg5xh);
  233. pci_read_config_byte(bmide_dev, 0x57, &reg5yh);
  234. p += sprintf(p,
  235. "UDMA: %s %s"
  236. " %s %s\n"
  237. "UDMA timings: %s %s"
  238. " %s %s\n\n",
  239. (reg5xh & 0x08) ? "OK" : "No",
  240. (reg5xh & 0x80) ? "OK" : "No",
  241. (reg5yh & 0x08) ? "OK" : "No",
  242. (reg5yh & 0x80) ? "OK" : "No",
  243. udmaT[(reg5xh & 0x07)],
  244. udmaT[(reg5xh & 0x70) >> 4],
  245. udmaT[reg5yh & 0x07],
  246. udmaT[(reg5yh & 0x70) >> 4] );
  247. return p-buffer; /* => must be less than 4k! */
  248. }
  249. #endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
  250. /**
  251. * ali15x3_tune_pio - set up chipset for PIO mode
  252. * @drive: drive to tune
  253. * @pio: desired mode
  254. *
  255. * Select the best PIO mode for the drive in question.
  256. * Then program the controller for this mode.
  257. *
  258. * Returns the PIO mode programmed.
  259. */
  260. static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio)
  261. {
  262. ide_pio_data_t d;
  263. ide_hwif_t *hwif = HWIF(drive);
  264. struct pci_dev *dev = hwif->pci_dev;
  265. int s_time, a_time, c_time;
  266. u8 s_clc, a_clc, r_clc;
  267. unsigned long flags;
  268. int bus_speed = system_bus_clock();
  269. int port = hwif->channel ? 0x5c : 0x58;
  270. int portFIFO = hwif->channel ? 0x55 : 0x54;
  271. u8 cd_dma_fifo = 0;
  272. int unit = drive->select.b.unit & 1;
  273. pio = ide_get_best_pio_mode(drive, pio, 5, &d);
  274. s_time = ide_pio_timings[pio].setup_time;
  275. a_time = ide_pio_timings[pio].active_time;
  276. if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
  277. s_clc = 0;
  278. if ((a_clc = (a_time * bus_speed + 999) / 1000) >= 8)
  279. a_clc = 0;
  280. c_time = ide_pio_timings[pio].cycle_time;
  281. #if 0
  282. if ((r_clc = ((c_time - s_time - a_time) * bus_speed + 999) / 1000) >= 16)
  283. r_clc = 0;
  284. #endif
  285. if (!(r_clc = (c_time * bus_speed + 999) / 1000 - a_clc - s_clc)) {
  286. r_clc = 1;
  287. } else {
  288. if (r_clc >= 16)
  289. r_clc = 0;
  290. }
  291. local_irq_save(flags);
  292. /*
  293. * PIO mode => ATA FIFO on, ATAPI FIFO off
  294. */
  295. pci_read_config_byte(dev, portFIFO, &cd_dma_fifo);
  296. if (drive->media==ide_disk) {
  297. if (unit) {
  298. pci_write_config_byte(dev, portFIFO, (cd_dma_fifo & 0x0F) | 0x50);
  299. } else {
  300. pci_write_config_byte(dev, portFIFO, (cd_dma_fifo & 0xF0) | 0x05);
  301. }
  302. } else {
  303. if (unit) {
  304. pci_write_config_byte(dev, portFIFO, cd_dma_fifo & 0x0F);
  305. } else {
  306. pci_write_config_byte(dev, portFIFO, cd_dma_fifo & 0xF0);
  307. }
  308. }
  309. pci_write_config_byte(dev, port, s_clc);
  310. pci_write_config_byte(dev, port+drive->select.b.unit+2, (a_clc << 4) | r_clc);
  311. local_irq_restore(flags);
  312. /*
  313. * setup active rec
  314. * { 70, 165, 365 }, PIO Mode 0
  315. * { 50, 125, 208 }, PIO Mode 1
  316. * { 30, 100, 110 }, PIO Mode 2
  317. * { 30, 80, 70 }, PIO Mode 3 with IORDY
  318. * { 25, 70, 25 }, PIO Mode 4 with IORDY ns
  319. * { 20, 50, 30 } PIO Mode 5 with IORDY (nonstandard)
  320. */
  321. return pio;
  322. }
  323. /**
  324. * ali15x3_tune_drive - set up drive for PIO mode
  325. * @drive: drive to tune
  326. * @pio: desired mode
  327. *
  328. * Program the controller with the best PIO timing for the given drive.
  329. * Then set up the drive itself.
  330. */
  331. static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio)
  332. {
  333. pio = ali15x3_tune_pio(drive, pio);
  334. (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
  335. }
  336. /**
  337. * ali_udma_filter - compute UDMA mask
  338. * @drive: IDE device
  339. *
  340. * Return available UDMA modes.
  341. *
  342. * The actual rules for the ALi are:
  343. * No UDMA on revisions <= 0x20
  344. * Disk only for revisions < 0xC2
  345. * Not WDC drives for revisions < 0xC2
  346. *
  347. * FIXME: WDC ifdef needs to die
  348. */
  349. static u8 ali_udma_filter(ide_drive_t *drive)
  350. {
  351. if (m5229_revision > 0x20 && m5229_revision < 0xC2) {
  352. if (drive->media != ide_disk)
  353. return 0;
  354. #ifndef CONFIG_WDC_ALI15X3
  355. if (chip_is_1543c_e && strstr(drive->id->model, "WDC "))
  356. return 0;
  357. #endif
  358. }
  359. return drive->hwif->ultra_mask;
  360. }
  361. /**
  362. * ali15x3_tune_chipset - set up chipset/drive for new speed
  363. * @drive: drive to configure for
  364. * @xferspeed: desired speed
  365. *
  366. * Configure the hardware for the desired IDE transfer mode.
  367. * We also do the needed drive configuration through helpers
  368. */
  369. static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  370. {
  371. ide_hwif_t *hwif = HWIF(drive);
  372. struct pci_dev *dev = hwif->pci_dev;
  373. u8 speed = ide_rate_filter(drive, xferspeed);
  374. u8 speed1 = speed;
  375. u8 unit = (drive->select.b.unit & 0x01);
  376. u8 tmpbyte = 0x00;
  377. int m5229_udma = (hwif->channel) ? 0x57 : 0x56;
  378. if (speed == XFER_UDMA_6)
  379. speed1 = 0x47;
  380. if (speed < XFER_UDMA_0) {
  381. u8 ultra_enable = (unit) ? 0x7f : 0xf7;
  382. /*
  383. * clear "ultra enable" bit
  384. */
  385. pci_read_config_byte(dev, m5229_udma, &tmpbyte);
  386. tmpbyte &= ultra_enable;
  387. pci_write_config_byte(dev, m5229_udma, tmpbyte);
  388. if (speed < XFER_SW_DMA_0)
  389. (void) ali15x3_tune_pio(drive, speed - XFER_PIO_0);
  390. } else {
  391. pci_read_config_byte(dev, m5229_udma, &tmpbyte);
  392. tmpbyte &= (0x0f << ((1-unit) << 2));
  393. /*
  394. * enable ultra dma and set timing
  395. */
  396. tmpbyte |= ((0x08 | ((4-speed1)&0x07)) << (unit << 2));
  397. pci_write_config_byte(dev, m5229_udma, tmpbyte);
  398. if (speed >= XFER_UDMA_3) {
  399. pci_read_config_byte(dev, 0x4b, &tmpbyte);
  400. tmpbyte |= 1;
  401. pci_write_config_byte(dev, 0x4b, tmpbyte);
  402. }
  403. }
  404. return (ide_config_drive_speed(drive, speed));
  405. }
  406. /**
  407. * ali15x3_config_drive_for_dma - configure for DMA
  408. * @drive: drive to configure
  409. *
  410. * Configure a drive for DMA operation. If DMA is not possible we
  411. * drop the drive into PIO mode instead.
  412. */
  413. static int ali15x3_config_drive_for_dma(ide_drive_t *drive)
  414. {
  415. drive->init_speed = 0;
  416. if (ide_tune_dma(drive))
  417. return 0;
  418. ali15x3_tune_drive(drive, 255);
  419. return -1;
  420. }
  421. /**
  422. * ali15x3_dma_setup - begin a DMA phase
  423. * @drive: target device
  424. *
  425. * Returns 1 if the DMA cannot be performed, zero on success.
  426. */
  427. static int ali15x3_dma_setup(ide_drive_t *drive)
  428. {
  429. if (m5229_revision < 0xC2 && drive->media != ide_disk) {
  430. if (rq_data_dir(drive->hwif->hwgroup->rq))
  431. return 1; /* try PIO instead of DMA */
  432. }
  433. return ide_dma_setup(drive);
  434. }
  435. /**
  436. * init_chipset_ali15x3 - Initialise an ALi IDE controller
  437. * @dev: PCI device
  438. * @name: Name of the controller
  439. *
  440. * This function initializes the ALI IDE controller and where
  441. * appropriate also sets up the 1533 southbridge.
  442. */
  443. static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const char *name)
  444. {
  445. unsigned long flags;
  446. u8 tmpbyte;
  447. struct pci_dev *north = pci_get_slot(dev->bus, PCI_DEVFN(0,0));
  448. m5229_revision = dev->revision;
  449. isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  450. #if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
  451. if (!ali_proc) {
  452. ali_proc = 1;
  453. bmide_dev = dev;
  454. ide_pci_create_host_proc("ali", ali_get_info);
  455. }
  456. #endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
  457. local_irq_save(flags);
  458. if (m5229_revision < 0xC2) {
  459. /*
  460. * revision 0x20 (1543-E, 1543-F)
  461. * revision 0xC0, 0xC1 (1543C-C, 1543C-D, 1543C-E)
  462. * clear CD-ROM DMA write bit, m5229, 0x4b, bit 7
  463. */
  464. pci_read_config_byte(dev, 0x4b, &tmpbyte);
  465. /*
  466. * clear bit 7
  467. */
  468. pci_write_config_byte(dev, 0x4b, tmpbyte & 0x7F);
  469. goto out;
  470. }
  471. /*
  472. * 1543C-B?, 1535, 1535D, 1553
  473. * Note 1: not all "motherboard" support this detection
  474. * Note 2: if no udma 66 device, the detection may "error".
  475. * but in this case, we will not set the device to
  476. * ultra 66, the detection result is not important
  477. */
  478. /*
  479. * enable "Cable Detection", m5229, 0x4b, bit3
  480. */
  481. pci_read_config_byte(dev, 0x4b, &tmpbyte);
  482. pci_write_config_byte(dev, 0x4b, tmpbyte | 0x08);
  483. /*
  484. * We should only tune the 1533 enable if we are using an ALi
  485. * North bridge. We might have no north found on some zany
  486. * box without a device at 0:0.0. The ALi bridge will be at
  487. * 0:0.0 so if we didn't find one we know what is cooking.
  488. */
  489. if (north && north->vendor != PCI_VENDOR_ID_AL)
  490. goto out;
  491. if (m5229_revision < 0xC5 && isa_dev)
  492. {
  493. /*
  494. * set south-bridge's enable bit, m1533, 0x79
  495. */
  496. pci_read_config_byte(isa_dev, 0x79, &tmpbyte);
  497. if (m5229_revision == 0xC2) {
  498. /*
  499. * 1543C-B0 (m1533, 0x79, bit 2)
  500. */
  501. pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x04);
  502. } else if (m5229_revision >= 0xC3) {
  503. /*
  504. * 1553/1535 (m1533, 0x79, bit 1)
  505. */
  506. pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x02);
  507. }
  508. }
  509. out:
  510. pci_dev_put(north);
  511. pci_dev_put(isa_dev);
  512. local_irq_restore(flags);
  513. return 0;
  514. }
  515. /*
  516. * Cable special cases
  517. */
  518. static struct dmi_system_id cable_dmi_table[] = {
  519. {
  520. .ident = "HP Pavilion N5430",
  521. .matches = {
  522. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  523. DMI_MATCH(DMI_BOARD_NAME, "OmniBook N32N-736"),
  524. },
  525. },
  526. { }
  527. };
  528. static int ali_cable_override(struct pci_dev *pdev)
  529. {
  530. /* Fujitsu P2000 */
  531. if (pdev->subsystem_vendor == 0x10CF &&
  532. pdev->subsystem_device == 0x10AF)
  533. return 1;
  534. /* Systems by DMI */
  535. if (dmi_check_system(cable_dmi_table))
  536. return 1;
  537. return 0;
  538. }
  539. /**
  540. * ata66_ali15x3 - check for UDMA 66 support
  541. * @hwif: IDE interface
  542. *
  543. * This checks if the controller and the cable are capable
  544. * of UDMA66 transfers. It doesn't check the drives.
  545. * But see note 2 below!
  546. *
  547. * FIXME: frobs bits that are not defined on newer ALi devicea
  548. */
  549. static u8 __devinit ata66_ali15x3(ide_hwif_t *hwif)
  550. {
  551. struct pci_dev *dev = hwif->pci_dev;
  552. unsigned long flags;
  553. u8 cbl = ATA_CBL_PATA40, tmpbyte;
  554. local_irq_save(flags);
  555. if (m5229_revision >= 0xC2) {
  556. /*
  557. * m5229 80-pin cable detection (from Host View)
  558. *
  559. * 0x4a bit0 is 0 => primary channel has 80-pin
  560. * 0x4a bit1 is 0 => secondary channel has 80-pin
  561. *
  562. * Certain laptops use short but suitable cables
  563. * and don't implement the detect logic.
  564. */
  565. if (ali_cable_override(dev))
  566. cbl = ATA_CBL_PATA40_SHORT;
  567. else {
  568. pci_read_config_byte(dev, 0x4a, &tmpbyte);
  569. if ((tmpbyte & (1 << hwif->channel)) == 0)
  570. cbl = ATA_CBL_PATA80;
  571. }
  572. } else {
  573. /*
  574. * check m1533, 0x5e, bit 1~4 == 1001 => & 00011110 = 00010010
  575. */
  576. pci_read_config_byte(isa_dev, 0x5e, &tmpbyte);
  577. chip_is_1543c_e = ((tmpbyte & 0x1e) == 0x12) ? 1: 0;
  578. }
  579. /*
  580. * CD_ROM DMA on (m5229, 0x53, bit0)
  581. * Enable this bit even if we want to use PIO
  582. * PIO FIFO off (m5229, 0x53, bit1)
  583. * The hardware will use 0x54h and 0x55h to control PIO FIFO
  584. * (Not on later devices it seems)
  585. *
  586. * 0x53 changes meaning on later revs - we must no touch
  587. * bit 1 on them. Need to check if 0x20 is the right break
  588. */
  589. pci_read_config_byte(dev, 0x53, &tmpbyte);
  590. if(m5229_revision <= 0x20)
  591. tmpbyte = (tmpbyte & (~0x02)) | 0x01;
  592. else if (m5229_revision == 0xc7 || m5229_revision == 0xc8)
  593. tmpbyte |= 0x03;
  594. else
  595. tmpbyte |= 0x01;
  596. pci_write_config_byte(dev, 0x53, tmpbyte);
  597. local_irq_restore(flags);
  598. return cbl;
  599. }
  600. /**
  601. * init_hwif_common_ali15x3 - Set up ALI IDE hardware
  602. * @hwif: IDE interface
  603. *
  604. * Initialize the IDE structure side of the ALi 15x3 driver.
  605. */
  606. static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
  607. {
  608. hwif->autodma = 0;
  609. hwif->tuneproc = &ali15x3_tune_drive;
  610. hwif->speedproc = &ali15x3_tune_chipset;
  611. hwif->udma_filter = &ali_udma_filter;
  612. /* don't use LBA48 DMA on ALi devices before rev 0xC5 */
  613. hwif->no_lba48_dma = (m5229_revision <= 0xC4) ? 1 : 0;
  614. if (!hwif->dma_base) {
  615. hwif->drives[0].autotune = 1;
  616. hwif->drives[1].autotune = 1;
  617. return;
  618. }
  619. if (m5229_revision > 0x20)
  620. hwif->atapi_dma = 1;
  621. if (m5229_revision <= 0x20)
  622. hwif->ultra_mask = 0x00; /* no udma */
  623. else if (m5229_revision < 0xC2)
  624. hwif->ultra_mask = 0x07; /* udma0-2 */
  625. else if (m5229_revision == 0xC2 || m5229_revision == 0xC3)
  626. hwif->ultra_mask = 0x1f; /* udma0-4 */
  627. else if (m5229_revision == 0xC4)
  628. hwif->ultra_mask = 0x3f; /* udma0-5 */
  629. else
  630. hwif->ultra_mask = 0x7f; /* udma0-6 */
  631. hwif->mwdma_mask = 0x07;
  632. hwif->swdma_mask = 0x07;
  633. if (m5229_revision >= 0x20) {
  634. /*
  635. * M1543C or newer for DMAing
  636. */
  637. hwif->ide_dma_check = &ali15x3_config_drive_for_dma;
  638. hwif->dma_setup = &ali15x3_dma_setup;
  639. if (!noautodma)
  640. hwif->autodma = 1;
  641. if (hwif->cbl != ATA_CBL_PATA40_SHORT)
  642. hwif->cbl = ata66_ali15x3(hwif);
  643. }
  644. hwif->drives[0].autodma = hwif->autodma;
  645. hwif->drives[1].autodma = hwif->autodma;
  646. }
  647. /**
  648. * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff
  649. * @hwif: interface to configure
  650. *
  651. * Obtain the IRQ tables for an ALi based IDE solution on the PC
  652. * class platforms. This part of the code isn't applicable to the
  653. * Sparc systems
  654. */
  655. static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
  656. {
  657. u8 ideic, inmir;
  658. s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6,
  659. 1, 11, 0, 12, 0, 14, 0, 15 };
  660. int irq = -1;
  661. if (hwif->pci_dev->device == PCI_DEVICE_ID_AL_M5229)
  662. hwif->irq = hwif->channel ? 15 : 14;
  663. if (isa_dev) {
  664. /*
  665. * read IDE interface control
  666. */
  667. pci_read_config_byte(isa_dev, 0x58, &ideic);
  668. /* bit0, bit1 */
  669. ideic = ideic & 0x03;
  670. /* get IRQ for IDE Controller */
  671. if ((hwif->channel && ideic == 0x03) ||
  672. (!hwif->channel && !ideic)) {
  673. /*
  674. * get SIRQ1 routing table
  675. */
  676. pci_read_config_byte(isa_dev, 0x44, &inmir);
  677. inmir = inmir & 0x0f;
  678. irq = irq_routing_table[inmir];
  679. } else if (hwif->channel && !(ideic & 0x01)) {
  680. /*
  681. * get SIRQ2 routing table
  682. */
  683. pci_read_config_byte(isa_dev, 0x75, &inmir);
  684. inmir = inmir & 0x0f;
  685. irq = irq_routing_table[inmir];
  686. }
  687. if(irq >= 0)
  688. hwif->irq = irq;
  689. }
  690. init_hwif_common_ali15x3(hwif);
  691. }
  692. /**
  693. * init_dma_ali15x3 - set up DMA on ALi15x3
  694. * @hwif: IDE interface
  695. * @dmabase: DMA interface base PCI address
  696. *
  697. * Set up the DMA functionality on the ALi 15x3. For the ALi
  698. * controllers this is generic so we can let the generic code do
  699. * the actual work.
  700. */
  701. static void __devinit init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase)
  702. {
  703. if (m5229_revision < 0x20)
  704. return;
  705. if (!hwif->channel)
  706. outb(inb(dmabase + 2) & 0x60, dmabase + 2);
  707. ide_setup_dma(hwif, dmabase, 8);
  708. }
  709. static ide_pci_device_t ali15x3_chipset __devinitdata = {
  710. .name = "ALI15X3",
  711. .init_chipset = init_chipset_ali15x3,
  712. .init_hwif = init_hwif_ali15x3,
  713. .init_dma = init_dma_ali15x3,
  714. .channels = 2,
  715. .autodma = AUTODMA,
  716. .bootable = ON_BOARD,
  717. };
  718. /**
  719. * alim15x3_init_one - set up an ALi15x3 IDE controller
  720. * @dev: PCI device to set up
  721. *
  722. * Perform the actual set up for an ALi15x3 that has been found by the
  723. * hot plug layer.
  724. */
  725. static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  726. {
  727. static struct pci_device_id ati_rs100[] = {
  728. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100) },
  729. { },
  730. };
  731. ide_pci_device_t *d = &ali15x3_chipset;
  732. if (pci_dev_present(ati_rs100))
  733. printk(KERN_WARNING "alim15x3: ATI Radeon IGP Northbridge is not yet fully tested.\n");
  734. #if defined(CONFIG_SPARC64)
  735. d->init_hwif = init_hwif_common_ali15x3;
  736. #endif /* CONFIG_SPARC64 */
  737. return ide_setup_pci_device(dev, d);
  738. }
  739. static struct pci_device_id alim15x3_pci_tbl[] = {
  740. { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  741. { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5228, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  742. { 0, },
  743. };
  744. MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
  745. static struct pci_driver driver = {
  746. .name = "ALI15x3_IDE",
  747. .id_table = alim15x3_pci_tbl,
  748. .probe = alim15x3_init_one,
  749. };
  750. static int __init ali15x3_ide_init(void)
  751. {
  752. return ide_pci_register_driver(&driver);
  753. }
  754. module_init(ali15x3_ide_init);
  755. MODULE_AUTHOR("Michael Aubry, Andrzej Krzysztofowicz, CJ, Andre Hedrick, Alan Cox");
  756. MODULE_DESCRIPTION("PCI driver module for ALi 15x3 IDE");
  757. MODULE_LICENSE("GPL");