mpc8xx.c 20 KB

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