mpc8xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /*
  2. * linux/drivers/ide/ppc/ide-m8xx.c
  3. *
  4. * Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de
  5. * Modified for direct IDE interface
  6. * by Thomas Lange, thomas@corelatus.com
  7. * Modified for direct IDE interface on 8xx without using the PCMCIA
  8. * controller
  9. * by Steven.Scholz@imc-berlin.de
  10. * Moved out of arch/ppc/kernel/m8xx_setup.c, other minor cleanups
  11. * by Mathew Locke <mattl@mvista.com>
  12. */
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/stddef.h>
  18. #include <linux/unistd.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/slab.h>
  21. #include <linux/user.h>
  22. #include <linux/a.out.h>
  23. #include <linux/tty.h>
  24. #include <linux/major.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/reboot.h>
  27. #include <linux/init.h>
  28. #include <linux/ioport.h>
  29. #include <linux/ide.h>
  30. #include <linux/bootmem.h>
  31. #include <asm/mpc8xx.h>
  32. #include <asm/mmu.h>
  33. #include <asm/processor.h>
  34. #include <asm/residual.h>
  35. #include <asm/io.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/ide.h>
  38. #include <asm/8xx_immap.h>
  39. #include <asm/machdep.h>
  40. #include <asm/irq.h>
  41. static int identify (volatile u8 *p);
  42. static void print_fixed (volatile u8 *p);
  43. static void print_funcid (int func);
  44. static int check_ide_device (unsigned long base);
  45. static void ide_interrupt_ack (void *dev);
  46. static void m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio);
  47. typedef struct ide_ioport_desc {
  48. unsigned long base_off; /* Offset to PCMCIA memory */
  49. unsigned long reg_off[IDE_NR_PORTS]; /* controller register offsets */
  50. int irq; /* IRQ */
  51. } ide_ioport_desc_t;
  52. ide_ioport_desc_t ioport_dsc[MAX_HWIFS] = {
  53. #ifdef IDE0_BASE_OFFSET
  54. { IDE0_BASE_OFFSET,
  55. {
  56. IDE0_DATA_REG_OFFSET,
  57. IDE0_ERROR_REG_OFFSET,
  58. IDE0_NSECTOR_REG_OFFSET,
  59. IDE0_SECTOR_REG_OFFSET,
  60. IDE0_LCYL_REG_OFFSET,
  61. IDE0_HCYL_REG_OFFSET,
  62. IDE0_SELECT_REG_OFFSET,
  63. IDE0_STATUS_REG_OFFSET,
  64. IDE0_CONTROL_REG_OFFSET,
  65. IDE0_IRQ_REG_OFFSET,
  66. },
  67. IDE0_INTERRUPT,
  68. },
  69. #ifdef IDE1_BASE_OFFSET
  70. { IDE1_BASE_OFFSET,
  71. {
  72. IDE1_DATA_REG_OFFSET,
  73. IDE1_ERROR_REG_OFFSET,
  74. IDE1_NSECTOR_REG_OFFSET,
  75. IDE1_SECTOR_REG_OFFSET,
  76. IDE1_LCYL_REG_OFFSET,
  77. IDE1_HCYL_REG_OFFSET,
  78. IDE1_SELECT_REG_OFFSET,
  79. IDE1_STATUS_REG_OFFSET,
  80. IDE1_CONTROL_REG_OFFSET,
  81. IDE1_IRQ_REG_OFFSET,
  82. },
  83. IDE1_INTERRUPT,
  84. },
  85. #endif /* IDE1_BASE_OFFSET */
  86. #endif /* IDE0_BASE_OFFSET */
  87. };
  88. ide_pio_timings_t ide_pio_clocks[6];
  89. int hold_time[6] = {30, 20, 15, 10, 10, 10 }; /* PIO Mode 5 with IORDY (nonstandard) */
  90. /*
  91. * Warning: only 1 (ONE) PCMCIA slot supported here,
  92. * which must be correctly initialized by the firmware (PPCBoot).
  93. */
  94. static int _slot_ = -1; /* will be read from PCMCIA registers */
  95. /* Make clock cycles and always round up */
  96. #define PCMCIA_MK_CLKS( t, T ) (( (t) * ((T)/1000000) + 999U ) / 1000U )
  97. /*
  98. * IDE stuff.
  99. */
  100. static int
  101. m8xx_ide_default_irq(unsigned long base)
  102. {
  103. #ifdef CONFIG_BLK_DEV_MPC8xx_IDE
  104. if (base >= MAX_HWIFS)
  105. return 0;
  106. printk("[%d] m8xx_ide_default_irq %d\n",__LINE__,ioport_dsc[base].irq);
  107. return (ioport_dsc[base].irq);
  108. #else
  109. return 9;
  110. #endif
  111. }
  112. static unsigned long
  113. m8xx_ide_default_io_base(int index)
  114. {
  115. return index;
  116. }
  117. #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4))
  118. #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4))
  119. /*
  120. * The TQM850L hardware has two pins swapped! Grrrrgh!
  121. */
  122. #ifdef CONFIG_TQM850L
  123. #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXOE
  124. #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXRESET
  125. #else
  126. #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXRESET
  127. #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXOE
  128. #endif
  129. #if defined(CONFIG_BLK_DEV_MPC8xx_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
  130. #define PCMCIA_SCHLVL IDE0_INTERRUPT /* Status Change Interrupt Level */
  131. static int pcmcia_schlvl = PCMCIA_SCHLVL;
  132. #endif
  133. /*
  134. * See include/linux/ide.h for definition of hw_regs_t (p, base)
  135. */
  136. /*
  137. * m8xx_ide_init_hwif_ports for a direct IDE interface _using_
  138. */
  139. #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
  140. static void
  141. m8xx_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port,
  142. unsigned long ctrl_port, int *irq)
  143. {
  144. unsigned long *p = hw->io_ports;
  145. int i;
  146. typedef struct {
  147. ulong br;
  148. ulong or;
  149. } pcmcia_win_t;
  150. volatile pcmcia_win_t *win;
  151. volatile pcmconf8xx_t *pcmp;
  152. uint *pgcrx;
  153. u32 pcmcia_phy_base;
  154. u32 pcmcia_phy_end;
  155. static unsigned long pcmcia_base = 0;
  156. unsigned long base;
  157. *p = 0;
  158. if (irq)
  159. *irq = 0;
  160. pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia));
  161. if (!pcmcia_base) {
  162. /*
  163. * Read out PCMCIA registers. Since the reset values
  164. * are undefined, we sure hope that they have been
  165. * set up by firmware
  166. */
  167. /* Scan all registers for valid settings */
  168. pcmcia_phy_base = 0xFFFFFFFF;
  169. pcmcia_phy_end = 0;
  170. /* br0 is start of brX and orX regs */
  171. win = (pcmcia_win_t *) \
  172. (&(((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0));
  173. for (i = 0; i < 8; i++) {
  174. if (win->or & 1) { /* This bank is marked as valid */
  175. if (win->br < pcmcia_phy_base) {
  176. pcmcia_phy_base = win->br;
  177. }
  178. if ((win->br + PCMCIA_MEM_SIZE) > pcmcia_phy_end) {
  179. pcmcia_phy_end = win->br + PCMCIA_MEM_SIZE;
  180. }
  181. /* Check which slot that has been defined */
  182. _slot_ = (win->or >> 2) & 1;
  183. } /* Valid bank */
  184. win++;
  185. } /* for */
  186. printk ("PCMCIA slot %c: phys mem %08x...%08x (size %08x)\n",
  187. 'A' + _slot_,
  188. pcmcia_phy_base, pcmcia_phy_end,
  189. pcmcia_phy_end - pcmcia_phy_base);
  190. pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base,
  191. pcmcia_phy_end-pcmcia_phy_base);
  192. #ifdef DEBUG
  193. printk ("PCMCIA virt base: %08lx\n", pcmcia_base);
  194. #endif
  195. /* Compute clock cycles for PIO timings */
  196. for (i=0; i<6; ++i) {
  197. bd_t *binfo = (bd_t *)__res;
  198. hold_time[i] =
  199. PCMCIA_MK_CLKS (hold_time[i],
  200. binfo->bi_busfreq);
  201. ide_pio_clocks[i].setup_time =
  202. PCMCIA_MK_CLKS (ide_pio_timings[i].setup_time,
  203. binfo->bi_busfreq);
  204. ide_pio_clocks[i].active_time =
  205. PCMCIA_MK_CLKS (ide_pio_timings[i].active_time,
  206. binfo->bi_busfreq);
  207. ide_pio_clocks[i].cycle_time =
  208. PCMCIA_MK_CLKS (ide_pio_timings[i].cycle_time,
  209. binfo->bi_busfreq);
  210. #if 0
  211. printk ("PIO mode %d timings: %d/%d/%d => %d/%d/%d\n",
  212. i,
  213. ide_pio_clocks[i].setup_time,
  214. ide_pio_clocks[i].active_time,
  215. ide_pio_clocks[i].hold_time,
  216. ide_pio_clocks[i].cycle_time,
  217. ide_pio_timings[i].setup_time,
  218. ide_pio_timings[i].active_time,
  219. ide_pio_timings[i].hold_time,
  220. ide_pio_timings[i].cycle_time);
  221. #endif
  222. }
  223. }
  224. if (data_port >= MAX_HWIFS)
  225. return;
  226. if (_slot_ == -1) {
  227. printk ("PCMCIA slot has not been defined! Using A as default\n");
  228. _slot_ = 0;
  229. }
  230. #ifdef CONFIG_IDE_8xx_PCCARD
  231. #ifdef DEBUG
  232. printk ("PIPR = 0x%08X slot %c ==> mask = 0x%X\n",
  233. pcmp->pcmc_pipr,
  234. 'A' + _slot_,
  235. M8XX_PCMCIA_CD1(_slot_) | M8XX_PCMCIA_CD2(_slot_) );
  236. #endif /* DEBUG */
  237. if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) {
  238. printk ("No card in slot %c: PIPR=%08x\n",
  239. 'A' + _slot_, (u32) pcmp->pcmc_pipr);
  240. return; /* No card in slot */
  241. }
  242. check_ide_device (pcmcia_base);
  243. #endif /* CONFIG_IDE_8xx_PCCARD */
  244. base = pcmcia_base + ioport_dsc[data_port].base_off;
  245. #ifdef DEBUG
  246. printk ("base: %08x + %08x = %08x\n",
  247. pcmcia_base, ioport_dsc[data_port].base_off, base);
  248. #endif
  249. for (i = 0; i < IDE_NR_PORTS; ++i) {
  250. #ifdef DEBUG
  251. printk ("port[%d]: %08x + %08x = %08x\n",
  252. i,
  253. base,
  254. ioport_dsc[data_port].reg_off[i],
  255. i, base + ioport_dsc[data_port].reg_off[i]);
  256. #endif
  257. *p++ = base + ioport_dsc[data_port].reg_off[i];
  258. }
  259. if (irq) {
  260. #ifdef CONFIG_IDE_8xx_PCCARD
  261. unsigned int reg;
  262. *irq = ioport_dsc[data_port].irq;
  263. if (_slot_)
  264. pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcrb;
  265. else
  266. pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcra;
  267. reg = *pgcrx;
  268. reg |= mk_int_int_mask (pcmcia_schlvl) << 24;
  269. reg |= mk_int_int_mask (pcmcia_schlvl) << 16;
  270. *pgcrx = reg;
  271. #else /* direct connected IDE drive, i.e. external IRQ, not the PCMCIA irq */
  272. *irq = ioport_dsc[data_port].irq;
  273. #endif /* CONFIG_IDE_8xx_PCCARD */
  274. }
  275. /* register routine to tune PIO mode */
  276. ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc;
  277. hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack;
  278. /* Enable Harddisk Interrupt,
  279. * and make it edge sensitive
  280. */
  281. /* (11-18) Set edge detect for irq, no wakeup from low power mode */
  282. ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel |=
  283. (0x80000000 >> ioport_dsc[data_port].irq);
  284. #ifdef CONFIG_IDE_8xx_PCCARD
  285. /* Make sure we don't get garbage irq */
  286. ((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pscr = 0xFFFF;
  287. /* Enable falling edge irq */
  288. pcmp->pcmc_per = 0x100000 >> (16 * _slot_);
  289. #endif /* CONFIG_IDE_8xx_PCCARD */
  290. } /* m8xx_ide_init_hwif_ports() using 8xx internal PCMCIA interface */
  291. #endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */
  292. /*
  293. * m8xx_ide_init_hwif_ports for a direct IDE interface _not_ using
  294. * MPC8xx's internal PCMCIA interface
  295. */
  296. #if defined(CONFIG_IDE_EXT_DIRECT)
  297. void m8xx_ide_init_hwif_ports (hw_regs_t *hw,
  298. unsigned long data_port, unsigned long ctrl_port, int *irq)
  299. {
  300. unsigned long *p = hw->io_ports;
  301. int i;
  302. u32 ide_phy_base;
  303. u32 ide_phy_end;
  304. static unsigned long ide_base = 0;
  305. unsigned long base;
  306. *p = 0;
  307. if (irq)
  308. *irq = 0;
  309. if (!ide_base) {
  310. /* TODO:
  311. * - add code to read ORx, BRx
  312. */
  313. ide_phy_base = CFG_ATA_BASE_ADDR;
  314. ide_phy_end = CFG_ATA_BASE_ADDR + 0x200;
  315. printk ("IDE phys mem : %08x...%08x (size %08x)\n",
  316. ide_phy_base, ide_phy_end,
  317. ide_phy_end - ide_phy_base);
  318. ide_base=(unsigned long)ioremap(ide_phy_base,
  319. ide_phy_end-ide_phy_base);
  320. #ifdef DEBUG
  321. printk ("IDE virt base: %08lx\n", ide_base);
  322. #endif
  323. }
  324. if (data_port >= MAX_HWIFS)
  325. return;
  326. base = ide_base + ioport_dsc[data_port].base_off;
  327. #ifdef DEBUG
  328. printk ("base: %08x + %08x = %08x\n",
  329. ide_base, ioport_dsc[data_port].base_off, base);
  330. #endif
  331. for (i = 0; i < IDE_NR_PORTS; ++i) {
  332. #ifdef DEBUG
  333. printk ("port[%d]: %08x + %08x = %08x\n",
  334. i,
  335. base,
  336. ioport_dsc[data_port].reg_off[i],
  337. i, base + ioport_dsc[data_port].reg_off[i]);
  338. #endif
  339. *p++ = base + ioport_dsc[data_port].reg_off[i];
  340. }
  341. if (irq) {
  342. /* direct connected IDE drive, i.e. external IRQ */
  343. *irq = ioport_dsc[data_port].irq;
  344. }
  345. /* register routine to tune PIO mode */
  346. ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc;
  347. hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack;
  348. /* Enable Harddisk Interrupt,
  349. * and make it edge sensitive
  350. */
  351. /* (11-18) Set edge detect for irq, no wakeup from low power mode */
  352. ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |=
  353. (0x80000000 >> ioport_dsc[data_port].irq);
  354. } /* m8xx_ide_init_hwif_ports() for CONFIG_IDE_8xx_DIRECT */
  355. #endif /* CONFIG_IDE_8xx_DIRECT */
  356. /* -------------------------------------------------------------------- */
  357. /* PCMCIA Timing */
  358. #ifndef PCMCIA_SHT
  359. #define PCMCIA_SHT(t) ((t & 0x0F)<<16) /* Strobe Hold Time */
  360. #define PCMCIA_SST(t) ((t & 0x0F)<<12) /* Strobe Setup Time */
  361. #define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */
  362. #endif
  363. /* Calculate PIO timings */
  364. static void
  365. m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio)
  366. {
  367. ide_pio_data_t d;
  368. #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
  369. volatile pcmconf8xx_t *pcmp;
  370. ulong timing, mask, reg;
  371. #endif
  372. pio = ide_get_best_pio_mode(drive, pio, 4, &d);
  373. #if 1
  374. printk("%s[%d] %s: best PIO mode: %d\n",
  375. __FILE__,__LINE__,__FUNCTION__, pio);
  376. #endif
  377. #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
  378. pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia));
  379. mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF));
  380. timing = PCMCIA_SHT(hold_time[pio] )
  381. | PCMCIA_SST(ide_pio_clocks[pio].setup_time )
  382. | PCMCIA_SL (ide_pio_clocks[pio].active_time)
  383. ;
  384. #if 1
  385. printk ("Setting timing bits 0x%08lx in PCMCIA controller\n", timing);
  386. #endif
  387. if ((reg = pcmp->pcmc_por0 & mask) != 0)
  388. pcmp->pcmc_por0 = reg | timing;
  389. if ((reg = pcmp->pcmc_por1 & mask) != 0)
  390. pcmp->pcmc_por1 = reg | timing;
  391. if ((reg = pcmp->pcmc_por2 & mask) != 0)
  392. pcmp->pcmc_por2 = reg | timing;
  393. if ((reg = pcmp->pcmc_por3 & mask) != 0)
  394. pcmp->pcmc_por3 = reg | timing;
  395. if ((reg = pcmp->pcmc_por4 & mask) != 0)
  396. pcmp->pcmc_por4 = reg | timing;
  397. if ((reg = pcmp->pcmc_por5 & mask) != 0)
  398. pcmp->pcmc_por5 = reg | timing;
  399. if ((reg = pcmp->pcmc_por6 & mask) != 0)
  400. pcmp->pcmc_por6 = reg | timing;
  401. if ((reg = pcmp->pcmc_por7 & mask) != 0)
  402. pcmp->pcmc_por7 = reg | timing;
  403. #elif defined(CONFIG_IDE_EXT_DIRECT)
  404. printk("%s[%d] %s: not implemented yet!\n",
  405. __FILE__,__LINE__,__FUNCTION__);
  406. #endif /* defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_PCMCIA */
  407. }
  408. static void
  409. ide_interrupt_ack (void *dev)
  410. {
  411. #ifdef CONFIG_IDE_8xx_PCCARD
  412. u_int pscr, pipr;
  413. #if (PCMCIA_SOCKETS_NO == 2)
  414. u_int _slot_;
  415. #endif
  416. /* get interrupt sources */
  417. pscr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr;
  418. pipr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr;
  419. /*
  420. * report only if both card detect signals are the same
  421. * not too nice done,
  422. * we depend on that CD2 is the bit to the left of CD1...
  423. */
  424. if(_slot_==-1){
  425. printk("PCMCIA slot has not been defined! Using A as default\n");
  426. _slot_=0;
  427. }
  428. if(((pipr & M8XX_PCMCIA_CD2(_slot_)) >> 1) ^
  429. (pipr & M8XX_PCMCIA_CD1(_slot_)) ) {
  430. printk ("card detect interrupt\n");
  431. }
  432. /* clear the interrupt sources */
  433. ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr = pscr;
  434. #else /* ! CONFIG_IDE_8xx_PCCARD */
  435. /*
  436. * Only CONFIG_IDE_8xx_PCCARD is using the interrupt of the
  437. * MPC8xx's PCMCIA controller, so there is nothing to be done here
  438. * for CONFIG_IDE_8xx_DIRECT and CONFIG_IDE_EXT_DIRECT.
  439. * The interrupt is handled somewhere else. -- Steven
  440. */
  441. #endif /* CONFIG_IDE_8xx_PCCARD */
  442. }
  443. /*
  444. * CIS Tupel codes
  445. */
  446. #define CISTPL_NULL 0x00
  447. #define CISTPL_DEVICE 0x01
  448. #define CISTPL_LONGLINK_CB 0x02
  449. #define CISTPL_INDIRECT 0x03
  450. #define CISTPL_CONFIG_CB 0x04
  451. #define CISTPL_CFTABLE_ENTRY_CB 0x05
  452. #define CISTPL_LONGLINK_MFC 0x06
  453. #define CISTPL_BAR 0x07
  454. #define CISTPL_PWR_MGMNT 0x08
  455. #define CISTPL_EXTDEVICE 0x09
  456. #define CISTPL_CHECKSUM 0x10
  457. #define CISTPL_LONGLINK_A 0x11
  458. #define CISTPL_LONGLINK_C 0x12
  459. #define CISTPL_LINKTARGET 0x13
  460. #define CISTPL_NO_LINK 0x14
  461. #define CISTPL_VERS_1 0x15
  462. #define CISTPL_ALTSTR 0x16
  463. #define CISTPL_DEVICE_A 0x17
  464. #define CISTPL_JEDEC_C 0x18
  465. #define CISTPL_JEDEC_A 0x19
  466. #define CISTPL_CONFIG 0x1a
  467. #define CISTPL_CFTABLE_ENTRY 0x1b
  468. #define CISTPL_DEVICE_OC 0x1c
  469. #define CISTPL_DEVICE_OA 0x1d
  470. #define CISTPL_DEVICE_GEO 0x1e
  471. #define CISTPL_DEVICE_GEO_A 0x1f
  472. #define CISTPL_MANFID 0x20
  473. #define CISTPL_FUNCID 0x21
  474. #define CISTPL_FUNCE 0x22
  475. #define CISTPL_SWIL 0x23
  476. #define CISTPL_END 0xff
  477. /*
  478. * CIS Function ID codes
  479. */
  480. #define CISTPL_FUNCID_MULTI 0x00
  481. #define CISTPL_FUNCID_MEMORY 0x01
  482. #define CISTPL_FUNCID_SERIAL 0x02
  483. #define CISTPL_FUNCID_PARALLEL 0x03
  484. #define CISTPL_FUNCID_FIXED 0x04
  485. #define CISTPL_FUNCID_VIDEO 0x05
  486. #define CISTPL_FUNCID_NETWORK 0x06
  487. #define CISTPL_FUNCID_AIMS 0x07
  488. #define CISTPL_FUNCID_SCSI 0x08
  489. /*
  490. * Fixed Disk FUNCE codes
  491. */
  492. #define CISTPL_IDE_INTERFACE 0x01
  493. #define CISTPL_FUNCE_IDE_IFACE 0x01
  494. #define CISTPL_FUNCE_IDE_MASTER 0x02
  495. #define CISTPL_FUNCE_IDE_SLAVE 0x03
  496. /* First feature byte */
  497. #define CISTPL_IDE_SILICON 0x04
  498. #define CISTPL_IDE_UNIQUE 0x08
  499. #define CISTPL_IDE_DUAL 0x10
  500. /* Second feature byte */
  501. #define CISTPL_IDE_HAS_SLEEP 0x01
  502. #define CISTPL_IDE_HAS_STANDBY 0x02
  503. #define CISTPL_IDE_HAS_IDLE 0x04
  504. #define CISTPL_IDE_LOW_POWER 0x08
  505. #define CISTPL_IDE_REG_INHIBIT 0x10
  506. #define CISTPL_IDE_HAS_INDEX 0x20
  507. #define CISTPL_IDE_IOIS16 0x40
  508. /* -------------------------------------------------------------------- */
  509. #define MAX_TUPEL_SZ 512
  510. #define MAX_FEATURES 4
  511. static int check_ide_device (unsigned long base)
  512. {
  513. volatile u8 *ident = NULL;
  514. volatile u8 *feature_p[MAX_FEATURES];
  515. volatile u8 *p, *start;
  516. int n_features = 0;
  517. u8 func_id = ~0;
  518. u8 code, len;
  519. unsigned short config_base = 0;
  520. int found = 0;
  521. int i;
  522. #ifdef DEBUG
  523. printk ("PCMCIA MEM: %08lX\n", base);
  524. #endif
  525. start = p = (volatile u8 *) base;
  526. while ((p - start) < MAX_TUPEL_SZ) {
  527. code = *p; p += 2;
  528. if (code == 0xFF) { /* End of chain */
  529. break;
  530. }
  531. len = *p; p += 2;
  532. #ifdef DEBUG_PCMCIA
  533. { volatile u8 *q = p;
  534. printk ("\nTuple code %02x length %d\n\tData:",
  535. code, len);
  536. for (i = 0; i < len; ++i) {
  537. printk (" %02x", *q);
  538. q+= 2;
  539. }
  540. }
  541. #endif /* DEBUG_PCMCIA */
  542. switch (code) {
  543. case CISTPL_VERS_1:
  544. ident = p + 4;
  545. break;
  546. case CISTPL_FUNCID:
  547. func_id = *p;
  548. break;
  549. case CISTPL_FUNCE:
  550. if (n_features < MAX_FEATURES)
  551. feature_p[n_features++] = p;
  552. break;
  553. case CISTPL_CONFIG:
  554. config_base = (*(p+6) << 8) + (*(p+4));
  555. default:
  556. break;
  557. }
  558. p += 2 * len;
  559. }
  560. found = identify (ident);
  561. if (func_id != ((u8)~0)) {
  562. print_funcid (func_id);
  563. if (func_id == CISTPL_FUNCID_FIXED)
  564. found = 1;
  565. else
  566. return (1); /* no disk drive */
  567. }
  568. for (i=0; i<n_features; ++i) {
  569. print_fixed (feature_p[i]);
  570. }
  571. if (!found) {
  572. printk ("unknown card type\n");
  573. return (1);
  574. }
  575. /* set level mode irq and I/O mapped device in config reg*/
  576. *((u8 *)(base + config_base)) = 0x41;
  577. return (0);
  578. }
  579. /* ------------------------------------------------------------------------- */
  580. static void print_funcid (int func)
  581. {
  582. switch (func) {
  583. case CISTPL_FUNCID_MULTI:
  584. printk (" Multi-Function");
  585. break;
  586. case CISTPL_FUNCID_MEMORY:
  587. printk (" Memory");
  588. break;
  589. case CISTPL_FUNCID_SERIAL:
  590. printk (" Serial Port");
  591. break;
  592. case CISTPL_FUNCID_PARALLEL:
  593. printk (" Parallel Port");
  594. break;
  595. case CISTPL_FUNCID_FIXED:
  596. printk (" Fixed Disk");
  597. break;
  598. case CISTPL_FUNCID_VIDEO:
  599. printk (" Video Adapter");
  600. break;
  601. case CISTPL_FUNCID_NETWORK:
  602. printk (" Network Adapter");
  603. break;
  604. case CISTPL_FUNCID_AIMS:
  605. printk (" AIMS Card");
  606. break;
  607. case CISTPL_FUNCID_SCSI:
  608. printk (" SCSI Adapter");
  609. break;
  610. default:
  611. printk (" Unknown");
  612. break;
  613. }
  614. printk (" Card\n");
  615. }
  616. /* ------------------------------------------------------------------------- */
  617. static void print_fixed (volatile u8 *p)
  618. {
  619. if (p == NULL)
  620. return;
  621. switch (*p) {
  622. case CISTPL_FUNCE_IDE_IFACE:
  623. { u8 iface = *(p+2);
  624. printk ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
  625. printk (" interface ");
  626. break;
  627. }
  628. case CISTPL_FUNCE_IDE_MASTER:
  629. case CISTPL_FUNCE_IDE_SLAVE:
  630. { u8 f1 = *(p+2);
  631. u8 f2 = *(p+4);
  632. printk ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
  633. if (f1 & CISTPL_IDE_UNIQUE)
  634. printk (" [unique]");
  635. printk ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
  636. if (f2 & CISTPL_IDE_HAS_SLEEP)
  637. printk (" [sleep]");
  638. if (f2 & CISTPL_IDE_HAS_STANDBY)
  639. printk (" [standby]");
  640. if (f2 & CISTPL_IDE_HAS_IDLE)
  641. printk (" [idle]");
  642. if (f2 & CISTPL_IDE_LOW_POWER)
  643. printk (" [low power]");
  644. if (f2 & CISTPL_IDE_REG_INHIBIT)
  645. printk (" [reg inhibit]");
  646. if (f2 & CISTPL_IDE_HAS_INDEX)
  647. printk (" [index]");
  648. if (f2 & CISTPL_IDE_IOIS16)
  649. printk (" [IOis16]");
  650. break;
  651. }
  652. }
  653. printk ("\n");
  654. }
  655. /* ------------------------------------------------------------------------- */
  656. #define MAX_IDENT_CHARS 64
  657. #define MAX_IDENT_FIELDS 4
  658. static u8 *known_cards[] = {
  659. "ARGOSY PnPIDE D5",
  660. NULL
  661. };
  662. static int identify (volatile u8 *p)
  663. {
  664. u8 id_str[MAX_IDENT_CHARS];
  665. u8 data;
  666. u8 *t;
  667. u8 **card;
  668. int i, done;
  669. if (p == NULL)
  670. return (0); /* Don't know */
  671. t = id_str;
  672. done =0;
  673. for (i=0; i<=4 && !done; ++i, p+=2) {
  674. while ((data = *p) != '\0') {
  675. if (data == 0xFF) {
  676. done = 1;
  677. break;
  678. }
  679. *t++ = data;
  680. if (t == &id_str[MAX_IDENT_CHARS-1]) {
  681. done = 1;
  682. break;
  683. }
  684. p += 2;
  685. }
  686. if (!done)
  687. *t++ = ' ';
  688. }
  689. *t = '\0';
  690. while (--t > id_str) {
  691. if (*t == ' ')
  692. *t = '\0';
  693. else
  694. break;
  695. }
  696. printk ("Card ID: %s\n", id_str);
  697. for (card=known_cards; *card; ++card) {
  698. if (strcmp(*card, id_str) == 0) { /* found! */
  699. return (1);
  700. }
  701. }
  702. return (0); /* don't know */
  703. }
  704. void m8xx_ide_init(void)
  705. {
  706. ppc_ide_md.default_irq = m8xx_ide_default_irq;
  707. ppc_ide_md.default_io_base = m8xx_ide_default_io_base;
  708. ppc_ide_md.ide_init_hwif = m8xx_ide_init_hwif_ports;
  709. }