mpc8xx.c 20 KB

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