mpc8xx.c 19 KB

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