mpc8xx.c 20 KB

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