aec62xx.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * linux/drivers/ide/pci/aec62xx.c Version 0.11 March 27, 2002
  3. *
  4. * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
  5. *
  6. */
  7. #include <linux/module.h>
  8. #include <linux/config.h>
  9. #include <linux/types.h>
  10. #include <linux/pci.h>
  11. #include <linux/delay.h>
  12. #include <linux/hdreg.h>
  13. #include <linux/ide.h>
  14. #include <linux/init.h>
  15. #include <asm/io.h>
  16. struct chipset_bus_clock_list_entry {
  17. u8 xfer_speed;
  18. u8 chipset_settings;
  19. u8 ultra_settings;
  20. };
  21. static struct chipset_bus_clock_list_entry aec6xxx_33_base [] = {
  22. { XFER_UDMA_6, 0x31, 0x07 },
  23. { XFER_UDMA_5, 0x31, 0x06 },
  24. { XFER_UDMA_4, 0x31, 0x05 },
  25. { XFER_UDMA_3, 0x31, 0x04 },
  26. { XFER_UDMA_2, 0x31, 0x03 },
  27. { XFER_UDMA_1, 0x31, 0x02 },
  28. { XFER_UDMA_0, 0x31, 0x01 },
  29. { XFER_MW_DMA_2, 0x31, 0x00 },
  30. { XFER_MW_DMA_1, 0x31, 0x00 },
  31. { XFER_MW_DMA_0, 0x0a, 0x00 },
  32. { XFER_PIO_4, 0x31, 0x00 },
  33. { XFER_PIO_3, 0x33, 0x00 },
  34. { XFER_PIO_2, 0x08, 0x00 },
  35. { XFER_PIO_1, 0x0a, 0x00 },
  36. { XFER_PIO_0, 0x00, 0x00 },
  37. { 0, 0x00, 0x00 }
  38. };
  39. static struct chipset_bus_clock_list_entry aec6xxx_34_base [] = {
  40. { XFER_UDMA_6, 0x41, 0x06 },
  41. { XFER_UDMA_5, 0x41, 0x05 },
  42. { XFER_UDMA_4, 0x41, 0x04 },
  43. { XFER_UDMA_3, 0x41, 0x03 },
  44. { XFER_UDMA_2, 0x41, 0x02 },
  45. { XFER_UDMA_1, 0x41, 0x01 },
  46. { XFER_UDMA_0, 0x41, 0x01 },
  47. { XFER_MW_DMA_2, 0x41, 0x00 },
  48. { XFER_MW_DMA_1, 0x42, 0x00 },
  49. { XFER_MW_DMA_0, 0x7a, 0x00 },
  50. { XFER_PIO_4, 0x41, 0x00 },
  51. { XFER_PIO_3, 0x43, 0x00 },
  52. { XFER_PIO_2, 0x78, 0x00 },
  53. { XFER_PIO_1, 0x7a, 0x00 },
  54. { XFER_PIO_0, 0x70, 0x00 },
  55. { 0, 0x00, 0x00 }
  56. };
  57. #define BUSCLOCK(D) \
  58. ((struct chipset_bus_clock_list_entry *) pci_get_drvdata((D)))
  59. #if 0
  60. if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
  61. (void) pci_read_config_byte(dev, 0x54, &art);
  62. p += sprintf(p, "DMA Mode: %s(%s)",
  63. (c0&0x20)?((art&0x03)?"UDMA":" DMA"):" PIO",
  64. (art&0x02)?"2":(art&0x01)?"1":"0");
  65. p += sprintf(p, " %s(%s)",
  66. (c0&0x40)?((art&0x0c)?"UDMA":" DMA"):" PIO",
  67. (art&0x08)?"2":(art&0x04)?"1":"0");
  68. p += sprintf(p, " %s(%s)",
  69. (c1&0x20)?((art&0x30)?"UDMA":" DMA"):" PIO",
  70. (art&0x20)?"2":(art&0x10)?"1":"0");
  71. p += sprintf(p, " %s(%s)\n",
  72. (c1&0x40)?((art&0xc0)?"UDMA":" DMA"):" PIO",
  73. (art&0x80)?"2":(art&0x40)?"1":"0");
  74. } else {
  75. #endif
  76. /*
  77. * TO DO: active tuning and correction of cards without a bios.
  78. */
  79. static u8 pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
  80. {
  81. for ( ; chipset_table->xfer_speed ; chipset_table++)
  82. if (chipset_table->xfer_speed == speed) {
  83. return chipset_table->chipset_settings;
  84. }
  85. return chipset_table->chipset_settings;
  86. }
  87. static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
  88. {
  89. for ( ; chipset_table->xfer_speed ; chipset_table++)
  90. if (chipset_table->xfer_speed == speed) {
  91. return chipset_table->ultra_settings;
  92. }
  93. return chipset_table->ultra_settings;
  94. }
  95. static u8 aec62xx_ratemask (ide_drive_t *drive)
  96. {
  97. ide_hwif_t *hwif = HWIF(drive);
  98. u8 mode;
  99. switch(hwif->pci_dev->device) {
  100. case PCI_DEVICE_ID_ARTOP_ATP865:
  101. case PCI_DEVICE_ID_ARTOP_ATP865R:
  102. #if 0
  103. mode = (hwif->INB(hwif->dma_master) & 0x10) ? 4 : 3;
  104. #else
  105. mode = (hwif->INB(((hwif->channel) ?
  106. hwif->mate->dma_status :
  107. hwif->dma_status)) & 0x10) ? 4 : 3;
  108. #endif
  109. break;
  110. case PCI_DEVICE_ID_ARTOP_ATP860:
  111. case PCI_DEVICE_ID_ARTOP_ATP860R:
  112. mode = 2;
  113. break;
  114. case PCI_DEVICE_ID_ARTOP_ATP850UF:
  115. default:
  116. return 1;
  117. }
  118. if (!eighty_ninty_three(drive))
  119. mode = min(mode, (u8)1);
  120. return mode;
  121. }
  122. static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  123. {
  124. ide_hwif_t *hwif = HWIF(drive);
  125. struct pci_dev *dev = hwif->pci_dev;
  126. u16 d_conf = 0;
  127. u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed);
  128. u8 ultra = 0, ultra_conf = 0;
  129. u8 tmp0 = 0, tmp1 = 0, tmp2 = 0;
  130. unsigned long flags;
  131. local_irq_save(flags);
  132. /* 0x40|(2*drive->dn): Active, 0x41|(2*drive->dn): Recovery */
  133. pci_read_config_word(dev, 0x40|(2*drive->dn), &d_conf);
  134. tmp0 = pci_bus_clock_list(speed, BUSCLOCK(dev));
  135. d_conf = ((tmp0 & 0xf0) << 4) | (tmp0 & 0xf);
  136. pci_write_config_word(dev, 0x40|(2*drive->dn), d_conf);
  137. tmp1 = 0x00;
  138. tmp2 = 0x00;
  139. pci_read_config_byte(dev, 0x54, &ultra);
  140. tmp1 = ((0x00 << (2*drive->dn)) | (ultra & ~(3 << (2*drive->dn))));
  141. ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev));
  142. tmp2 = ((ultra_conf << (2*drive->dn)) | (tmp1 & ~(3 << (2*drive->dn))));
  143. pci_write_config_byte(dev, 0x54, tmp2);
  144. local_irq_restore(flags);
  145. return(ide_config_drive_speed(drive, speed));
  146. }
  147. static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed)
  148. {
  149. ide_hwif_t *hwif = HWIF(drive);
  150. struct pci_dev *dev = hwif->pci_dev;
  151. u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed);
  152. u8 unit = (drive->select.b.unit & 0x01);
  153. u8 tmp1 = 0, tmp2 = 0;
  154. u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
  155. unsigned long flags;
  156. local_irq_save(flags);
  157. /* high 4-bits: Active, low 4-bits: Recovery */
  158. pci_read_config_byte(dev, 0x40|drive->dn, &drive_conf);
  159. drive_conf = pci_bus_clock_list(speed, BUSCLOCK(dev));
  160. pci_write_config_byte(dev, 0x40|drive->dn, drive_conf);
  161. pci_read_config_byte(dev, (0x44|hwif->channel), &ultra);
  162. tmp1 = ((0x00 << (4*unit)) | (ultra & ~(7 << (4*unit))));
  163. ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev));
  164. tmp2 = ((ultra_conf << (4*unit)) | (tmp1 & ~(7 << (4*unit))));
  165. pci_write_config_byte(dev, (0x44|hwif->channel), tmp2);
  166. local_irq_restore(flags);
  167. return(ide_config_drive_speed(drive, speed));
  168. }
  169. static int aec62xx_tune_chipset (ide_drive_t *drive, u8 speed)
  170. {
  171. switch (HWIF(drive)->pci_dev->device) {
  172. case PCI_DEVICE_ID_ARTOP_ATP865:
  173. case PCI_DEVICE_ID_ARTOP_ATP865R:
  174. case PCI_DEVICE_ID_ARTOP_ATP860:
  175. case PCI_DEVICE_ID_ARTOP_ATP860R:
  176. return ((int) aec6260_tune_chipset(drive, speed));
  177. case PCI_DEVICE_ID_ARTOP_ATP850UF:
  178. return ((int) aec6210_tune_chipset(drive, speed));
  179. default:
  180. return -1;
  181. }
  182. }
  183. static int config_chipset_for_dma (ide_drive_t *drive)
  184. {
  185. u8 speed = ide_dma_speed(drive, aec62xx_ratemask(drive));
  186. if (!(speed))
  187. return 0;
  188. (void) aec62xx_tune_chipset(drive, speed);
  189. return ide_dma_enable(drive);
  190. }
  191. static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
  192. {
  193. u8 speed = 0;
  194. u8 new_pio = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
  195. switch(pio) {
  196. case 5: speed = new_pio; break;
  197. case 4: speed = XFER_PIO_4; break;
  198. case 3: speed = XFER_PIO_3; break;
  199. case 2: speed = XFER_PIO_2; break;
  200. case 1: speed = XFER_PIO_1; break;
  201. default: speed = XFER_PIO_0; break;
  202. }
  203. (void) aec62xx_tune_chipset(drive, speed);
  204. }
  205. static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
  206. {
  207. ide_hwif_t *hwif = HWIF(drive);
  208. struct hd_driveid *id = drive->id;
  209. if ((id->capability & 1) && drive->autodma) {
  210. if (ide_use_dma(drive)) {
  211. if (config_chipset_for_dma(drive))
  212. return hwif->ide_dma_on(drive);
  213. }
  214. goto fast_ata_pio;
  215. } else if ((id->capability & 8) || (id->field_valid & 2)) {
  216. fast_ata_pio:
  217. aec62xx_tune_drive(drive, 5);
  218. return hwif->ide_dma_off_quietly(drive);
  219. }
  220. /* IORDY not supported */
  221. return 0;
  222. }
  223. static int aec62xx_irq_timeout (ide_drive_t *drive)
  224. {
  225. ide_hwif_t *hwif = HWIF(drive);
  226. struct pci_dev *dev = hwif->pci_dev;
  227. switch(dev->device) {
  228. case PCI_DEVICE_ID_ARTOP_ATP860:
  229. case PCI_DEVICE_ID_ARTOP_ATP860R:
  230. case PCI_DEVICE_ID_ARTOP_ATP865:
  231. case PCI_DEVICE_ID_ARTOP_ATP865R:
  232. printk(" AEC62XX time out ");
  233. #if 0
  234. {
  235. int i = 0;
  236. u8 reg49h = 0;
  237. pci_read_config_byte(HWIF(drive)->pci_dev, 0x49, &reg49h);
  238. for (i=0;i<256;i++)
  239. pci_write_config_byte(HWIF(drive)->pci_dev, 0x49, reg49h|0x10);
  240. pci_write_config_byte(HWIF(drive)->pci_dev, 0x49, reg49h & ~0x10);
  241. }
  242. return 0;
  243. #endif
  244. default:
  245. break;
  246. }
  247. #if 0
  248. {
  249. ide_hwif_t *hwif = HWIF(drive);
  250. struct pci_dev *dev = hwif->pci_dev;
  251. u8 tmp1 = 0, tmp2 = 0, mode6 = 0;
  252. pci_read_config_byte(dev, 0x44, &tmp1);
  253. pci_read_config_byte(dev, 0x45, &tmp2);
  254. printk(" AEC6280 r44=%x r45=%x ",tmp1,tmp2);
  255. mode6 = HWIF(drive)->INB(((hwif->channel) ?
  256. hwif->mate->dma_status :
  257. hwif->dma_status));
  258. printk(" AEC6280 133=%x ", (mode6 & 0x10));
  259. }
  260. #endif
  261. return 0;
  262. }
  263. static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const char *name)
  264. {
  265. int bus_speed = system_bus_clock();
  266. if (dev->resource[PCI_ROM_RESOURCE].start) {
  267. pci_write_config_dword(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
  268. printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, dev->resource[PCI_ROM_RESOURCE].start);
  269. }
  270. if (bus_speed <= 33)
  271. pci_set_drvdata(dev, (void *) aec6xxx_33_base);
  272. else
  273. pci_set_drvdata(dev, (void *) aec6xxx_34_base);
  274. return dev->irq;
  275. }
  276. static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
  277. {
  278. hwif->autodma = 0;
  279. hwif->tuneproc = &aec62xx_tune_drive;
  280. hwif->speedproc = &aec62xx_tune_chipset;
  281. if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
  282. hwif->serialized = hwif->channel;
  283. hwif->no_dsc = 1;
  284. }
  285. if (hwif->mate)
  286. hwif->mate->serialized = hwif->serialized;
  287. if (!hwif->dma_base) {
  288. hwif->drives[0].autotune = 1;
  289. hwif->drives[1].autotune = 1;
  290. return;
  291. }
  292. hwif->ultra_mask = 0x7f;
  293. hwif->mwdma_mask = 0x07;
  294. hwif->swdma_mask = 0x07;
  295. hwif->ide_dma_check = &aec62xx_config_drive_xfer_rate;
  296. hwif->ide_dma_lostirq = &aec62xx_irq_timeout;
  297. hwif->ide_dma_timeout = &aec62xx_irq_timeout;
  298. if (!noautodma)
  299. hwif->autodma = 1;
  300. hwif->drives[0].autodma = hwif->autodma;
  301. hwif->drives[1].autodma = hwif->autodma;
  302. }
  303. static void __devinit init_dma_aec62xx(ide_hwif_t *hwif, unsigned long dmabase)
  304. {
  305. struct pci_dev *dev = hwif->pci_dev;
  306. if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) {
  307. u8 reg54h = 0;
  308. unsigned long flags;
  309. spin_lock_irqsave(&ide_lock, flags);
  310. pci_read_config_byte(dev, 0x54, &reg54h);
  311. pci_write_config_byte(dev, 0x54, reg54h & ~(hwif->channel ? 0xF0 : 0x0F));
  312. spin_unlock_irqrestore(&ide_lock, flags);
  313. } else {
  314. u8 ata66 = 0;
  315. pci_read_config_byte(hwif->pci_dev, 0x49, &ata66);
  316. if (!(hwif->udma_four))
  317. hwif->udma_four = (ata66&(hwif->channel?0x02:0x01))?0:1;
  318. }
  319. ide_setup_dma(hwif, dmabase, 8);
  320. }
  321. static int __devinit init_setup_aec62xx(struct pci_dev *dev, ide_pci_device_t *d)
  322. {
  323. return ide_setup_pci_device(dev, d);
  324. }
  325. static int __devinit init_setup_aec6x80(struct pci_dev *dev, ide_pci_device_t *d)
  326. {
  327. unsigned long bar4reg = pci_resource_start(dev, 4);
  328. if (inb(bar4reg+2) & 0x10) {
  329. strcpy(d->name, "AEC6880");
  330. if (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R)
  331. strcpy(d->name, "AEC6880R");
  332. } else {
  333. strcpy(d->name, "AEC6280");
  334. if (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R)
  335. strcpy(d->name, "AEC6280R");
  336. }
  337. return ide_setup_pci_device(dev, d);
  338. }
  339. static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
  340. { /* 0 */
  341. .name = "AEC6210",
  342. .init_setup = init_setup_aec62xx,
  343. .init_chipset = init_chipset_aec62xx,
  344. .init_hwif = init_hwif_aec62xx,
  345. .init_dma = init_dma_aec62xx,
  346. .channels = 2,
  347. .autodma = AUTODMA,
  348. .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
  349. .bootable = OFF_BOARD,
  350. },{ /* 1 */
  351. .name = "AEC6260",
  352. .init_setup = init_setup_aec62xx,
  353. .init_chipset = init_chipset_aec62xx,
  354. .init_hwif = init_hwif_aec62xx,
  355. .init_dma = init_dma_aec62xx,
  356. .channels = 2,
  357. .autodma = NOAUTODMA,
  358. .bootable = OFF_BOARD,
  359. },{ /* 2 */
  360. .name = "AEC6260R",
  361. .init_setup = init_setup_aec62xx,
  362. .init_chipset = init_chipset_aec62xx,
  363. .init_hwif = init_hwif_aec62xx,
  364. .init_dma = init_dma_aec62xx,
  365. .channels = 2,
  366. .autodma = AUTODMA,
  367. .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
  368. .bootable = NEVER_BOARD,
  369. },{ /* 3 */
  370. .name = "AEC6X80",
  371. .init_setup = init_setup_aec6x80,
  372. .init_chipset = init_chipset_aec62xx,
  373. .init_hwif = init_hwif_aec62xx,
  374. .init_dma = init_dma_aec62xx,
  375. .channels = 2,
  376. .autodma = AUTODMA,
  377. .bootable = OFF_BOARD,
  378. },{ /* 4 */
  379. .name = "AEC6X80R",
  380. .init_setup = init_setup_aec6x80,
  381. .init_chipset = init_chipset_aec62xx,
  382. .init_hwif = init_hwif_aec62xx,
  383. .init_dma = init_dma_aec62xx,
  384. .channels = 2,
  385. .autodma = AUTODMA,
  386. .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
  387. .bootable = OFF_BOARD,
  388. }
  389. };
  390. /**
  391. * aec62xx_init_one - called when a AEC is found
  392. * @dev: the aec62xx device
  393. * @id: the matching pci id
  394. *
  395. * Called when the PCI registration layer (or the IDE initialization)
  396. * finds a device matching our IDE device tables.
  397. */
  398. static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  399. {
  400. ide_pci_device_t *d = &aec62xx_chipsets[id->driver_data];
  401. return d->init_setup(dev, d);
  402. }
  403. static struct pci_device_id aec62xx_pci_tbl[] = {
  404. { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  405. { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  406. { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  407. { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  408. { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  409. { 0, },
  410. };
  411. MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);
  412. static struct pci_driver driver = {
  413. .name = "AEC62xx_IDE",
  414. .id_table = aec62xx_pci_tbl,
  415. .probe = aec62xx_init_one,
  416. };
  417. static int aec62xx_ide_init(void)
  418. {
  419. return ide_pci_register_driver(&driver);
  420. }
  421. module_init(aec62xx_ide_init);
  422. MODULE_AUTHOR("Andre Hedrick");
  423. MODULE_DESCRIPTION("PCI driver module for ARTOP AEC62xx IDE");
  424. MODULE_LICENSE("GPL");