mpc8xx.c 20 KB

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