alim15x3.c 21 KB

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