pata_legacy.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. /*
  2. * pata-legacy.c - Legacy port PATA/SATA controller driver.
  3. * Copyright 2005/2006 Red Hat <alan@redhat.com>, all rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; see the file COPYING. If not, write to
  17. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * An ATA driver for the legacy ATA ports.
  20. *
  21. * Data Sources:
  22. * Opti 82C465/82C611 support: Data sheets at opti-inc.com
  23. * HT6560 series:
  24. * Promise 20230/20620:
  25. * http://www.ryston.cz/petr/vlb/pdc20230b.html
  26. * http://www.ryston.cz/petr/vlb/pdc20230c.html
  27. * http://www.ryston.cz/petr/vlb/pdc20630.html
  28. *
  29. * Unsupported but docs exist:
  30. * Appian/Adaptec AIC25VL01/Cirrus Logic PD7220
  31. * Winbond W83759A
  32. *
  33. * This driver handles legacy (that is "ISA/VLB side") IDE ports found
  34. * on PC class systems. There are three hybrid devices that are exceptions
  35. * The Cyrix 5510/5520 where a pre SFF ATA device is on the bridge and
  36. * the MPIIX where the tuning is PCI side but the IDE is "ISA side".
  37. *
  38. * Specific support is included for the ht6560a/ht6560b/opti82c611a/
  39. * opti82c465mv/promise 20230c/20630
  40. *
  41. * Use the autospeed and pio_mask options with:
  42. * Appian ADI/2 aka CLPD7220 or AIC25VL01.
  43. * Use the jumpers, autospeed and set pio_mask to the mode on the jumpers with
  44. * Goldstar GM82C711, PIC-1288A-125, UMC 82C871F, Winbond W83759,
  45. * Winbond W83759A, Promise PDC20230-B
  46. *
  47. * For now use autospeed and pio_mask as above with the W83759A. This may
  48. * change.
  49. *
  50. * TODO
  51. * Merge existing pata_qdi driver
  52. *
  53. */
  54. #include <linux/kernel.h>
  55. #include <linux/module.h>
  56. #include <linux/pci.h>
  57. #include <linux/init.h>
  58. #include <linux/blkdev.h>
  59. #include <linux/delay.h>
  60. #include <scsi/scsi_host.h>
  61. #include <linux/ata.h>
  62. #include <linux/libata.h>
  63. #include <linux/platform_device.h>
  64. #define DRV_NAME "pata_legacy"
  65. #define DRV_VERSION "0.5.3"
  66. #define NR_HOST 6
  67. static int legacy_port[NR_HOST] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
  68. static int legacy_irq[NR_HOST] = { 15, 14, 11, 10, 8, 12 };
  69. struct legacy_data {
  70. unsigned long timing;
  71. u8 clock[2];
  72. u8 last;
  73. int fast;
  74. struct platform_device *platform_dev;
  75. };
  76. static struct legacy_data legacy_data[NR_HOST];
  77. static struct ata_host *legacy_host[NR_HOST];
  78. static int nr_legacy_host;
  79. static int probe_all; /* Set to check all ISA port ranges */
  80. static int ht6560a; /* HT 6560A on primary 1, secondary 2, both 3 */
  81. static int ht6560b; /* HT 6560A on primary 1, secondary 2, both 3 */
  82. static int opti82c611a; /* Opti82c611A on primary 1, secondary 2, both 3 */
  83. static int opti82c46x; /* Opti 82c465MV present (pri/sec autodetect) */
  84. static int autospeed; /* Chip present which snoops speed changes */
  85. static int pio_mask = 0x1F; /* PIO range for autospeed devices */
  86. /**
  87. * legacy_set_mode - mode setting
  88. * @ap: IDE interface
  89. *
  90. * Use a non standard set_mode function. We don't want to be tuned.
  91. *
  92. * The BIOS configured everything. Our job is not to fiddle. Just use
  93. * whatever PIO the hardware is using and leave it at that. When we
  94. * get some kind of nice user driven API for control then we can
  95. * expand on this as per hdparm in the base kernel.
  96. */
  97. static void legacy_set_mode(struct ata_port *ap)
  98. {
  99. int i;
  100. for (i = 0; i < ATA_MAX_DEVICES; i++) {
  101. struct ata_device *dev = &ap->device[i];
  102. if (ata_dev_enabled(dev)) {
  103. dev->pio_mode = XFER_PIO_0;
  104. dev->xfer_mode = XFER_PIO_0;
  105. dev->xfer_shift = ATA_SHIFT_PIO;
  106. dev->flags |= ATA_DFLAG_PIO;
  107. }
  108. }
  109. }
  110. static struct scsi_host_template legacy_sht = {
  111. .module = THIS_MODULE,
  112. .name = DRV_NAME,
  113. .ioctl = ata_scsi_ioctl,
  114. .queuecommand = ata_scsi_queuecmd,
  115. .can_queue = ATA_DEF_QUEUE,
  116. .this_id = ATA_SHT_THIS_ID,
  117. .sg_tablesize = LIBATA_MAX_PRD,
  118. .max_sectors = ATA_MAX_SECTORS,
  119. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  120. .emulated = ATA_SHT_EMULATED,
  121. .use_clustering = ATA_SHT_USE_CLUSTERING,
  122. .proc_name = DRV_NAME,
  123. .dma_boundary = ATA_DMA_BOUNDARY,
  124. .slave_configure = ata_scsi_slave_config,
  125. .bios_param = ata_std_bios_param,
  126. };
  127. /*
  128. * These ops are used if the user indicates the hardware
  129. * snoops the commands to decide on the mode and handles the
  130. * mode selection "magically" itself. Several legacy controllers
  131. * do this. The mode range can be set if it is not 0x1F by setting
  132. * pio_mask as well.
  133. */
  134. static struct ata_port_operations simple_port_ops = {
  135. .port_disable = ata_port_disable,
  136. .tf_load = ata_tf_load,
  137. .tf_read = ata_tf_read,
  138. .check_status = ata_check_status,
  139. .exec_command = ata_exec_command,
  140. .dev_select = ata_std_dev_select,
  141. .freeze = ata_bmdma_freeze,
  142. .thaw = ata_bmdma_thaw,
  143. .error_handler = ata_bmdma_error_handler,
  144. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  145. .qc_prep = ata_qc_prep,
  146. .qc_issue = ata_qc_issue_prot,
  147. .data_xfer = ata_pio_data_xfer_noirq,
  148. .irq_handler = ata_interrupt,
  149. .irq_clear = ata_bmdma_irq_clear,
  150. .port_start = ata_port_start,
  151. .port_stop = ata_port_stop,
  152. .host_stop = ata_host_stop
  153. };
  154. static struct ata_port_operations legacy_port_ops = {
  155. .set_mode = legacy_set_mode,
  156. .port_disable = ata_port_disable,
  157. .tf_load = ata_tf_load,
  158. .tf_read = ata_tf_read,
  159. .check_status = ata_check_status,
  160. .exec_command = ata_exec_command,
  161. .dev_select = ata_std_dev_select,
  162. .error_handler = ata_bmdma_error_handler,
  163. .qc_prep = ata_qc_prep,
  164. .qc_issue = ata_qc_issue_prot,
  165. .data_xfer = ata_pio_data_xfer_noirq,
  166. .irq_handler = ata_interrupt,
  167. .irq_clear = ata_bmdma_irq_clear,
  168. .port_start = ata_port_start,
  169. .port_stop = ata_port_stop,
  170. .host_stop = ata_host_stop
  171. };
  172. /*
  173. * Promise 20230C and 20620 support
  174. *
  175. * This controller supports PIO0 to PIO2. We set PIO timings conservatively to
  176. * allow for 50MHz Vesa Local Bus. The 20620 DMA support is weird being DMA to
  177. * controller and PIO'd to the host and not supported.
  178. */
  179. static void pdc20230_set_piomode(struct ata_port *ap, struct ata_device *adev)
  180. {
  181. int tries = 5;
  182. int pio = adev->pio_mode - XFER_PIO_0;
  183. u8 rt;
  184. unsigned long flags;
  185. /* Safe as UP only. Force I/Os to occur together */
  186. local_irq_save(flags);
  187. /* Unlock the control interface */
  188. do
  189. {
  190. inb(0x1F5);
  191. outb(inb(0x1F2) | 0x80, 0x1F2);
  192. inb(0x1F2);
  193. inb(0x3F6);
  194. inb(0x3F6);
  195. inb(0x1F2);
  196. inb(0x1F2);
  197. }
  198. while((inb(0x1F2) & 0x80) && --tries);
  199. local_irq_restore(flags);
  200. outb(inb(0x1F4) & 0x07, 0x1F4);
  201. rt = inb(0x1F3);
  202. rt &= 0x07 << (3 * adev->devno);
  203. if (pio)
  204. rt |= (1 + 3 * pio) << (3 * adev->devno);
  205. udelay(100);
  206. outb(inb(0x1F2) | 0x01, 0x1F2);
  207. udelay(100);
  208. inb(0x1F5);
  209. }
  210. static void pdc_data_xfer_vlb(struct ata_device *adev, unsigned char *buf, unsigned int buflen, int write_data)
  211. {
  212. struct ata_port *ap = adev->ap;
  213. int slop = buflen & 3;
  214. unsigned long flags;
  215. if (ata_id_has_dword_io(adev->id)) {
  216. local_irq_save(flags);
  217. /* Perform the 32bit I/O synchronization sequence */
  218. inb(ap->ioaddr.nsect_addr);
  219. inb(ap->ioaddr.nsect_addr);
  220. inb(ap->ioaddr.nsect_addr);
  221. /* Now the data */
  222. if (write_data)
  223. outsl(ap->ioaddr.data_addr, buf, buflen >> 2);
  224. else
  225. insl(ap->ioaddr.data_addr, buf, buflen >> 2);
  226. if (unlikely(slop)) {
  227. u32 pad;
  228. if (write_data) {
  229. memcpy(&pad, buf + buflen - slop, slop);
  230. outl(le32_to_cpu(pad), ap->ioaddr.data_addr);
  231. } else {
  232. pad = cpu_to_le16(inl(ap->ioaddr.data_addr));
  233. memcpy(buf + buflen - slop, &pad, slop);
  234. }
  235. }
  236. local_irq_restore(flags);
  237. }
  238. else
  239. ata_pio_data_xfer_noirq(adev, buf, buflen, write_data);
  240. }
  241. static struct ata_port_operations pdc20230_port_ops = {
  242. .set_piomode = pdc20230_set_piomode,
  243. .port_disable = ata_port_disable,
  244. .tf_load = ata_tf_load,
  245. .tf_read = ata_tf_read,
  246. .check_status = ata_check_status,
  247. .exec_command = ata_exec_command,
  248. .dev_select = ata_std_dev_select,
  249. .error_handler = ata_bmdma_error_handler,
  250. .qc_prep = ata_qc_prep,
  251. .qc_issue = ata_qc_issue_prot,
  252. .data_xfer = pdc_data_xfer_vlb,
  253. .irq_handler = ata_interrupt,
  254. .irq_clear = ata_bmdma_irq_clear,
  255. .port_start = ata_port_start,
  256. .port_stop = ata_port_stop,
  257. .host_stop = ata_host_stop
  258. };
  259. /*
  260. * Holtek 6560A support
  261. *
  262. * This controller supports PIO0 to PIO2 (no IORDY even though higher timings
  263. * can be loaded).
  264. */
  265. static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
  266. {
  267. u8 active, recover;
  268. struct ata_timing t;
  269. /* Get the timing data in cycles. For now play safe at 50Mhz */
  270. ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000);
  271. active = FIT(t.active, 2, 15);
  272. recover = FIT(t.recover, 4, 15);
  273. inb(0x3E6);
  274. inb(0x3E6);
  275. inb(0x3E6);
  276. inb(0x3E6);
  277. outb(recover << 4 | active, ap->ioaddr.device_addr);
  278. inb(ap->ioaddr.status_addr);
  279. }
  280. static struct ata_port_operations ht6560a_port_ops = {
  281. .set_piomode = ht6560a_set_piomode,
  282. .port_disable = ata_port_disable,
  283. .tf_load = ata_tf_load,
  284. .tf_read = ata_tf_read,
  285. .check_status = ata_check_status,
  286. .exec_command = ata_exec_command,
  287. .dev_select = ata_std_dev_select,
  288. .error_handler = ata_bmdma_error_handler,
  289. .qc_prep = ata_qc_prep,
  290. .qc_issue = ata_qc_issue_prot,
  291. .data_xfer = ata_pio_data_xfer, /* Check vlb/noirq */
  292. .irq_handler = ata_interrupt,
  293. .irq_clear = ata_bmdma_irq_clear,
  294. .port_start = ata_port_start,
  295. .port_stop = ata_port_stop,
  296. .host_stop = ata_host_stop
  297. };
  298. /*
  299. * Holtek 6560B support
  300. *
  301. * This controller supports PIO0 to PIO4. We honour the BIOS/jumper FIFO setting
  302. * unless we see an ATAPI device in which case we force it off.
  303. *
  304. * FIXME: need to implement 2nd channel support.
  305. */
  306. static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
  307. {
  308. u8 active, recover;
  309. struct ata_timing t;
  310. /* Get the timing data in cycles. For now play safe at 50Mhz */
  311. ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000);
  312. active = FIT(t.active, 2, 15);
  313. recover = FIT(t.recover, 2, 16);
  314. recover &= 0x15;
  315. inb(0x3E6);
  316. inb(0x3E6);
  317. inb(0x3E6);
  318. inb(0x3E6);
  319. outb(recover << 4 | active, ap->ioaddr.device_addr);
  320. if (adev->class != ATA_DEV_ATA) {
  321. u8 rconf = inb(0x3E6);
  322. if (rconf & 0x24) {
  323. rconf &= ~ 0x24;
  324. outb(rconf, 0x3E6);
  325. }
  326. }
  327. inb(ap->ioaddr.status_addr);
  328. }
  329. static struct ata_port_operations ht6560b_port_ops = {
  330. .set_piomode = ht6560b_set_piomode,
  331. .port_disable = ata_port_disable,
  332. .tf_load = ata_tf_load,
  333. .tf_read = ata_tf_read,
  334. .check_status = ata_check_status,
  335. .exec_command = ata_exec_command,
  336. .dev_select = ata_std_dev_select,
  337. .error_handler = ata_bmdma_error_handler,
  338. .qc_prep = ata_qc_prep,
  339. .qc_issue = ata_qc_issue_prot,
  340. .data_xfer = ata_pio_data_xfer, /* FIXME: Check 32bit and noirq */
  341. .irq_handler = ata_interrupt,
  342. .irq_clear = ata_bmdma_irq_clear,
  343. .port_start = ata_port_start,
  344. .port_stop = ata_port_stop,
  345. .host_stop = ata_host_stop
  346. };
  347. /*
  348. * Opti core chipset helpers
  349. */
  350. /**
  351. * opti_syscfg - read OPTI chipset configuration
  352. * @reg: Configuration register to read
  353. *
  354. * Returns the value of an OPTI system board configuration register.
  355. */
  356. static u8 opti_syscfg(u8 reg)
  357. {
  358. unsigned long flags;
  359. u8 r;
  360. /* Uniprocessor chipset and must force cycles adjancent */
  361. local_irq_save(flags);
  362. outb(reg, 0x22);
  363. r = inb(0x24);
  364. local_irq_restore(flags);
  365. return r;
  366. }
  367. /*
  368. * Opti 82C611A
  369. *
  370. * This controller supports PIO0 to PIO3.
  371. */
  372. static void opti82c611a_set_piomode(struct ata_port *ap, struct ata_device *adev)
  373. {
  374. u8 active, recover, setup;
  375. struct ata_timing t;
  376. struct ata_device *pair = ata_dev_pair(adev);
  377. int clock;
  378. int khz[4] = { 50000, 40000, 33000, 25000 };
  379. u8 rc;
  380. /* Enter configuration mode */
  381. inw(ap->ioaddr.error_addr);
  382. inw(ap->ioaddr.error_addr);
  383. outb(3, ap->ioaddr.nsect_addr);
  384. /* Read VLB clock strapping */
  385. clock = 1000000000 / khz[inb(ap->ioaddr.lbah_addr) & 0x03];
  386. /* Get the timing data in cycles */
  387. ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000);
  388. /* Setup timing is shared */
  389. if (pair) {
  390. struct ata_timing tp;
  391. ata_timing_compute(pair, pair->pio_mode, &tp, clock, 1000);
  392. ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP);
  393. }
  394. active = FIT(t.active, 2, 17) - 2;
  395. recover = FIT(t.recover, 1, 16) - 1;
  396. setup = FIT(t.setup, 1, 4) - 1;
  397. /* Select the right timing bank for write timing */
  398. rc = inb(ap->ioaddr.lbal_addr);
  399. rc &= 0x7F;
  400. rc |= (adev->devno << 7);
  401. outb(rc, ap->ioaddr.lbal_addr);
  402. /* Write the timings */
  403. outb(active << 4 | recover, ap->ioaddr.error_addr);
  404. /* Select the right bank for read timings, also
  405. load the shared timings for address */
  406. rc = inb(ap->ioaddr.device_addr);
  407. rc &= 0xC0;
  408. rc |= adev->devno; /* Index select */
  409. rc |= (setup << 4) | 0x04;
  410. outb(rc, ap->ioaddr.device_addr);
  411. /* Load the read timings */
  412. outb(active << 4 | recover, ap->ioaddr.data_addr);
  413. /* Ensure the timing register mode is right */
  414. rc = inb (ap->ioaddr.lbal_addr);
  415. rc &= 0x73;
  416. rc |= 0x84;
  417. outb(rc, ap->ioaddr.lbal_addr);
  418. /* Exit command mode */
  419. outb(0x83, ap->ioaddr.nsect_addr);
  420. }
  421. static struct ata_port_operations opti82c611a_port_ops = {
  422. .set_piomode = opti82c611a_set_piomode,
  423. .port_disable = ata_port_disable,
  424. .tf_load = ata_tf_load,
  425. .tf_read = ata_tf_read,
  426. .check_status = ata_check_status,
  427. .exec_command = ata_exec_command,
  428. .dev_select = ata_std_dev_select,
  429. .error_handler = ata_bmdma_error_handler,
  430. .qc_prep = ata_qc_prep,
  431. .qc_issue = ata_qc_issue_prot,
  432. .data_xfer = ata_pio_data_xfer,
  433. .irq_handler = ata_interrupt,
  434. .irq_clear = ata_bmdma_irq_clear,
  435. .port_start = ata_port_start,
  436. .port_stop = ata_port_stop,
  437. .host_stop = ata_host_stop
  438. };
  439. /*
  440. * Opti 82C465MV
  441. *
  442. * This controller supports PIO0 to PIO3. Unlike the 611A the MVB
  443. * version is dual channel but doesn't have a lot of unique registers.
  444. */
  445. static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
  446. {
  447. u8 active, recover, setup;
  448. struct ata_timing t;
  449. struct ata_device *pair = ata_dev_pair(adev);
  450. int clock;
  451. int khz[4] = { 50000, 40000, 33000, 25000 };
  452. u8 rc;
  453. u8 sysclk;
  454. /* Get the clock */
  455. sysclk = opti_syscfg(0xAC) & 0xC0; /* BIOS set */
  456. /* Enter configuration mode */
  457. inw(ap->ioaddr.error_addr);
  458. inw(ap->ioaddr.error_addr);
  459. outb(3, ap->ioaddr.nsect_addr);
  460. /* Read VLB clock strapping */
  461. clock = 1000000000 / khz[sysclk];
  462. /* Get the timing data in cycles */
  463. ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000);
  464. /* Setup timing is shared */
  465. if (pair) {
  466. struct ata_timing tp;
  467. ata_timing_compute(pair, pair->pio_mode, &tp, clock, 1000);
  468. ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP);
  469. }
  470. active = FIT(t.active, 2, 17) - 2;
  471. recover = FIT(t.recover, 1, 16) - 1;
  472. setup = FIT(t.setup, 1, 4) - 1;
  473. /* Select the right timing bank for write timing */
  474. rc = inb(ap->ioaddr.lbal_addr);
  475. rc &= 0x7F;
  476. rc |= (adev->devno << 7);
  477. outb(rc, ap->ioaddr.lbal_addr);
  478. /* Write the timings */
  479. outb(active << 4 | recover, ap->ioaddr.error_addr);
  480. /* Select the right bank for read timings, also
  481. load the shared timings for address */
  482. rc = inb(ap->ioaddr.device_addr);
  483. rc &= 0xC0;
  484. rc |= adev->devno; /* Index select */
  485. rc |= (setup << 4) | 0x04;
  486. outb(rc, ap->ioaddr.device_addr);
  487. /* Load the read timings */
  488. outb(active << 4 | recover, ap->ioaddr.data_addr);
  489. /* Ensure the timing register mode is right */
  490. rc = inb (ap->ioaddr.lbal_addr);
  491. rc &= 0x73;
  492. rc |= 0x84;
  493. outb(rc, ap->ioaddr.lbal_addr);
  494. /* Exit command mode */
  495. outb(0x83, ap->ioaddr.nsect_addr);
  496. /* We need to know this for quad device on the MVB */
  497. ap->host->private_data = ap;
  498. }
  499. /**
  500. * opt82c465mv_qc_issue_prot - command issue
  501. * @qc: command pending
  502. *
  503. * Called when the libata layer is about to issue a command. We wrap
  504. * this interface so that we can load the correct ATA timings. The
  505. * MVB has a single set of timing registers and these are shared
  506. * across channels. As there are two registers we really ought to
  507. * track the last two used values as a sort of register window. For
  508. * now we just reload on a channel switch. On the single channel
  509. * setup this condition never fires so we do nothing extra.
  510. *
  511. * FIXME: dual channel needs ->serialize support
  512. */
  513. static unsigned int opti82c46x_qc_issue_prot(struct ata_queued_cmd *qc)
  514. {
  515. struct ata_port *ap = qc->ap;
  516. struct ata_device *adev = qc->dev;
  517. /* If timings are set and for the wrong channel (2nd test is
  518. due to a libata shortcoming and will eventually go I hope) */
  519. if (ap->host->private_data != ap->host
  520. && ap->host->private_data != NULL)
  521. opti82c46x_set_piomode(ap, adev);
  522. return ata_qc_issue_prot(qc);
  523. }
  524. static struct ata_port_operations opti82c46x_port_ops = {
  525. .set_piomode = opti82c46x_set_piomode,
  526. .port_disable = ata_port_disable,
  527. .tf_load = ata_tf_load,
  528. .tf_read = ata_tf_read,
  529. .check_status = ata_check_status,
  530. .exec_command = ata_exec_command,
  531. .dev_select = ata_std_dev_select,
  532. .error_handler = ata_bmdma_error_handler,
  533. .qc_prep = ata_qc_prep,
  534. .qc_issue = opti82c46x_qc_issue_prot,
  535. .data_xfer = ata_pio_data_xfer,
  536. .irq_handler = ata_interrupt,
  537. .irq_clear = ata_bmdma_irq_clear,
  538. .port_start = ata_port_start,
  539. .port_stop = ata_port_stop,
  540. .host_stop = ata_host_stop
  541. };
  542. /**
  543. * legacy_init_one - attach a legacy interface
  544. * @port: port number
  545. * @io: I/O port start
  546. * @ctrl: control port
  547. * @irq: interrupt line
  548. *
  549. * Register an ISA bus IDE interface. Such interfaces are PIO and we
  550. * assume do not support IRQ sharing.
  551. */
  552. static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl, int irq)
  553. {
  554. struct legacy_data *ld = &legacy_data[nr_legacy_host];
  555. struct ata_probe_ent ae;
  556. struct platform_device *pdev;
  557. int ret = -EBUSY;
  558. struct ata_port_operations *ops = &legacy_port_ops;
  559. int pio_modes = pio_mask;
  560. u32 mask = (1 << port);
  561. if (request_region(io, 8, "pata_legacy") == NULL)
  562. return -EBUSY;
  563. if (request_region(ctrl, 1, "pata_legacy") == NULL)
  564. goto fail_io;
  565. pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0);
  566. if (pdev == NULL)
  567. goto fail_dev;
  568. if (ht6560a & mask) {
  569. ops = &ht6560a_port_ops;
  570. pio_modes = 0x07;
  571. }
  572. if (ht6560b & mask) {
  573. ops = &ht6560b_port_ops;
  574. pio_modes = 0x1F;
  575. }
  576. if (opti82c611a & mask) {
  577. ops = &opti82c611a_port_ops;
  578. pio_modes = 0x0F;
  579. }
  580. if (opti82c46x & mask) {
  581. ops = &opti82c46x_port_ops;
  582. pio_modes = 0x0F;
  583. }
  584. /* Probe for automatically detectable controllers */
  585. if (io == 0x1F0 && ops == &legacy_port_ops) {
  586. unsigned long flags;
  587. local_irq_save(flags);
  588. /* Probes */
  589. inb(0x1F5);
  590. outb(inb(0x1F2) | 0x80, 0x1F2);
  591. inb(0x1F2);
  592. inb(0x3F6);
  593. inb(0x3F6);
  594. inb(0x1F2);
  595. inb(0x1F2);
  596. if ((inb(0x1F2) & 0x80) == 0) {
  597. /* PDC20230c or 20630 ? */
  598. printk(KERN_INFO "PDC20230-C/20630 VLB ATA controller detected.\n");
  599. pio_modes = 0x07;
  600. ops = &pdc20230_port_ops;
  601. udelay(100);
  602. inb(0x1F5);
  603. } else {
  604. outb(0x55, 0x1F2);
  605. inb(0x1F2);
  606. inb(0x1F2);
  607. if (inb(0x1F2) == 0x00) {
  608. printk(KERN_INFO "PDC20230-B VLB ATA controller detected.\n");
  609. }
  610. }
  611. local_irq_restore(flags);
  612. }
  613. /* Chip does mode setting by command snooping */
  614. if (ops == &legacy_port_ops && (autospeed & mask))
  615. ops = &simple_port_ops;
  616. memset(&ae, 0, sizeof(struct ata_probe_ent));
  617. INIT_LIST_HEAD(&ae.node);
  618. ae.dev = &pdev->dev;
  619. ae.port_ops = ops;
  620. ae.sht = &legacy_sht;
  621. ae.n_ports = 1;
  622. ae.pio_mask = pio_modes;
  623. ae.irq = irq;
  624. ae.irq_flags = 0;
  625. ae.port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST;
  626. ae.port[0].cmd_addr = io;
  627. ae.port[0].altstatus_addr = ctrl;
  628. ae.port[0].ctl_addr = ctrl;
  629. ata_std_ports(&ae.port[0]);
  630. ae.private_data = ld;
  631. ret = ata_device_add(&ae);
  632. if (ret == 0) {
  633. ret = -ENODEV;
  634. goto fail;
  635. }
  636. legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev);
  637. ld->platform_dev = pdev;
  638. return 0;
  639. fail:
  640. platform_device_unregister(pdev);
  641. fail_dev:
  642. release_region(ctrl, 1);
  643. fail_io:
  644. release_region(io, 8);
  645. return ret;
  646. }
  647. /**
  648. * legacy_check_special_cases - ATA special cases
  649. * @p: PCI device to check
  650. * @master: set this if we find an ATA master
  651. * @master: set this if we find an ATA secondary
  652. *
  653. * A small number of vendors implemented early PCI ATA interfaces on bridge logic
  654. * without the ATA interface being PCI visible. Where we have a matching PCI driver
  655. * we must skip the relevant device here. If we don't know about it then the legacy
  656. * driver is the right driver anyway.
  657. */
  658. static void legacy_check_special_cases(struct pci_dev *p, int *primary, int *secondary)
  659. {
  660. /* Cyrix CS5510 pre SFF MWDMA ATA on the bridge */
  661. if (p->vendor == 0x1078 && p->device == 0x0000) {
  662. *primary = *secondary = 1;
  663. return;
  664. }
  665. /* Cyrix CS5520 pre SFF MWDMA ATA on the bridge */
  666. if (p->vendor == 0x1078 && p->device == 0x0002) {
  667. *primary = *secondary = 1;
  668. return;
  669. }
  670. /* Intel MPIIX - PIO ATA on non PCI side of bridge */
  671. if (p->vendor == 0x8086 && p->device == 0x1234) {
  672. u16 r;
  673. pci_read_config_word(p, 0x6C, &r);
  674. if (r & 0x8000) { /* ATA port enabled */
  675. if (r & 0x4000)
  676. *secondary = 1;
  677. else
  678. *primary = 1;
  679. }
  680. return;
  681. }
  682. }
  683. /**
  684. * legacy_init - attach legacy interfaces
  685. *
  686. * Attach legacy IDE interfaces by scanning the usual IRQ/port suspects.
  687. * Right now we do not scan the ide0 and ide1 address but should do so
  688. * for non PCI systems or systems with no PCI IDE legacy mode devices.
  689. * If you fix that note there are special cases to consider like VLB
  690. * drivers and CS5510/20.
  691. */
  692. static __init int legacy_init(void)
  693. {
  694. int i;
  695. int ct = 0;
  696. int primary = 0;
  697. int secondary = 0;
  698. int last_port = NR_HOST;
  699. struct pci_dev *p = NULL;
  700. for_each_pci_dev(p) {
  701. int r;
  702. /* Check for any overlap of the system ATA mappings. Native mode controllers
  703. stuck on these addresses or some devices in 'raid' mode won't be found by
  704. the storage class test */
  705. for (r = 0; r < 6; r++) {
  706. if (pci_resource_start(p, r) == 0x1f0)
  707. primary = 1;
  708. if (pci_resource_start(p, r) == 0x170)
  709. secondary = 1;
  710. }
  711. /* Check for special cases */
  712. legacy_check_special_cases(p, &primary, &secondary);
  713. /* If PCI bus is present then don't probe for tertiary legacy ports */
  714. if (probe_all == 0)
  715. last_port = 2;
  716. }
  717. /* If an OPTI 82C46X is present find out where the channels are */
  718. if (opti82c46x) {
  719. static const char *optis[4] = {
  720. "3/463MV", "5MV",
  721. "5MVA", "5MVB"
  722. };
  723. u8 chans = 1;
  724. u8 ctrl = (opti_syscfg(0x30) & 0xC0) >> 6;
  725. opti82c46x = 3; /* Assume master and slave first */
  726. printk(KERN_INFO DRV_NAME ": Opti 82C46%s chipset support.\n", optis[ctrl]);
  727. if (ctrl == 3)
  728. chans = (opti_syscfg(0x3F) & 0x20) ? 2 : 1;
  729. ctrl = opti_syscfg(0xAC);
  730. /* Check enabled and this port is the 465MV port. On the
  731. MVB we may have two channels */
  732. if (ctrl & 8) {
  733. if (ctrl & 4)
  734. opti82c46x = 2; /* Slave */
  735. else
  736. opti82c46x = 1; /* Master */
  737. if (chans == 2)
  738. opti82c46x = 3; /* Master and Slave */
  739. } /* Slave only */
  740. else if (chans == 1)
  741. opti82c46x = 1;
  742. }
  743. for (i = 0; i < last_port; i++) {
  744. /* Skip primary if we have seen a PCI one */
  745. if (i == 0 && primary == 1)
  746. continue;
  747. /* Skip secondary if we have seen a PCI one */
  748. if (i == 1 && secondary == 1)
  749. continue;
  750. if (legacy_init_one(i, legacy_port[i],
  751. legacy_port[i] + 0x0206,
  752. legacy_irq[i]) == 0)
  753. ct++;
  754. }
  755. if (ct != 0)
  756. return 0;
  757. return -ENODEV;
  758. }
  759. static __exit void legacy_exit(void)
  760. {
  761. int i;
  762. for (i = 0; i < nr_legacy_host; i++) {
  763. struct legacy_data *ld = &legacy_data[i];
  764. struct ata_port *ap =legacy_host[i]->ports[0];
  765. unsigned long io = ap->ioaddr.cmd_addr;
  766. unsigned long ctrl = ap->ioaddr.ctl_addr;
  767. ata_host_remove(legacy_host[i]);
  768. platform_device_unregister(ld->platform_dev);
  769. if (ld->timing)
  770. release_region(ld->timing, 2);
  771. release_region(io, 8);
  772. release_region(ctrl, 1);
  773. }
  774. }
  775. MODULE_AUTHOR("Alan Cox");
  776. MODULE_DESCRIPTION("low-level driver for legacy ATA");
  777. MODULE_LICENSE("GPL");
  778. MODULE_VERSION(DRV_VERSION);
  779. module_param(probe_all, int, 0);
  780. module_param(autospeed, int, 0);
  781. module_param(ht6560a, int, 0);
  782. module_param(ht6560b, int, 0);
  783. module_param(opti82c611a, int, 0);
  784. module_param(opti82c46x, int, 0);
  785. module_param(pio_mask, int, 0);
  786. module_init(legacy_init);
  787. module_exit(legacy_exit);