mpc8xx.c 19 KB

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