mpc8xx.c 20 KB

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