mpc8xx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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_array;
  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. hw->chipset = ide_generic;
  264. return 0;
  265. }
  266. #endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */
  267. /*
  268. * m8xx_ide_init_ports() for a direct IDE interface _not_ using
  269. * MPC8xx's internal PCMCIA interface
  270. */
  271. #if defined(CONFIG_IDE_EXT_DIRECT)
  272. static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
  273. {
  274. unsigned long *p = hw->io_ports_array;
  275. int i;
  276. u32 ide_phy_base;
  277. u32 ide_phy_end;
  278. static unsigned long ide_base = 0;
  279. unsigned long base;
  280. *p = 0;
  281. if (!ide_base) {
  282. /* TODO:
  283. * - add code to read ORx, BRx
  284. */
  285. ide_phy_base = CFG_ATA_BASE_ADDR;
  286. ide_phy_end = CFG_ATA_BASE_ADDR + 0x200;
  287. printk ("IDE phys mem : %08x...%08x (size %08x)\n",
  288. ide_phy_base, ide_phy_end,
  289. ide_phy_end - ide_phy_base);
  290. if (!request_mem_region(ide_phy_base, 0x200, DRV_NAME)) {
  291. printk(KERN_ERR "%s: resources busy\n", DRV_NAME);
  292. return -EBUSY;
  293. }
  294. ide_base=(unsigned long)ioremap(ide_phy_base,
  295. ide_phy_end-ide_phy_base);
  296. #ifdef DEBUG
  297. printk ("IDE virt base: %08lx\n", ide_base);
  298. #endif
  299. }
  300. base = ide_base + ioport_dsc[data_port].base_off;
  301. #ifdef DEBUG
  302. printk ("base: %08x + %08x = %08x\n",
  303. ide_base, ioport_dsc[data_port].base_off, base);
  304. #endif
  305. for (i = 0; i < IDE_NR_PORTS; ++i) {
  306. #ifdef DEBUG
  307. printk ("port[%d]: %08x + %08x = %08x\n",
  308. i,
  309. base,
  310. ioport_dsc[data_port].reg_off[i],
  311. i, base + ioport_dsc[data_port].reg_off[i]);
  312. #endif
  313. *p++ = base + ioport_dsc[data_port].reg_off[i];
  314. }
  315. /* direct connected IDE drive, i.e. external IRQ */
  316. hw->irq = ioport_dsc[data_port].irq;
  317. hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack;
  318. /* Enable Harddisk Interrupt,
  319. * and make it edge sensitive
  320. */
  321. /* (11-18) Set edge detect for irq, no wakeup from low power mode */
  322. ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |=
  323. (0x80000000 >> ioport_dsc[data_port].irq);
  324. hw->chipset = ide_generic;
  325. return 0;
  326. }
  327. #endif /* CONFIG_IDE_8xx_DIRECT */
  328. /* -------------------------------------------------------------------- */
  329. /* PCMCIA Timing */
  330. #ifndef PCMCIA_SHT
  331. #define PCMCIA_SHT(t) ((t & 0x0F)<<16) /* Strobe Hold Time */
  332. #define PCMCIA_SST(t) ((t & 0x0F)<<12) /* Strobe Setup Time */
  333. #define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */
  334. #endif
  335. /* Calculate PIO timings */
  336. static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
  337. {
  338. #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
  339. volatile pcmconf8xx_t *pcmp;
  340. ulong timing, mask, reg;
  341. pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia));
  342. mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF));
  343. timing = PCMCIA_SHT(hold_time[pio] )
  344. | PCMCIA_SST(ide_pio_clocks[pio].setup_time )
  345. | PCMCIA_SL (ide_pio_clocks[pio].active_time)
  346. ;
  347. #if 1
  348. printk ("Setting timing bits 0x%08lx in PCMCIA controller\n", timing);
  349. #endif
  350. if ((reg = pcmp->pcmc_por0 & mask) != 0)
  351. pcmp->pcmc_por0 = reg | timing;
  352. if ((reg = pcmp->pcmc_por1 & mask) != 0)
  353. pcmp->pcmc_por1 = reg | timing;
  354. if ((reg = pcmp->pcmc_por2 & mask) != 0)
  355. pcmp->pcmc_por2 = reg | timing;
  356. if ((reg = pcmp->pcmc_por3 & mask) != 0)
  357. pcmp->pcmc_por3 = reg | timing;
  358. if ((reg = pcmp->pcmc_por4 & mask) != 0)
  359. pcmp->pcmc_por4 = reg | timing;
  360. if ((reg = pcmp->pcmc_por5 & mask) != 0)
  361. pcmp->pcmc_por5 = reg | timing;
  362. if ((reg = pcmp->pcmc_por6 & mask) != 0)
  363. pcmp->pcmc_por6 = reg | timing;
  364. if ((reg = pcmp->pcmc_por7 & mask) != 0)
  365. pcmp->pcmc_por7 = reg | timing;
  366. #elif defined(CONFIG_IDE_EXT_DIRECT)
  367. printk("%s[%d] %s: not implemented yet!\n",
  368. __FILE__, __LINE__, __func__);
  369. #endif /* defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_PCMCIA */
  370. }
  371. static const struct ide_port_ops m8xx_port_ops = {
  372. .set_pio_mode = m8xx_ide_set_pio_mode,
  373. };
  374. static void
  375. ide_interrupt_ack (void *dev)
  376. {
  377. #ifdef CONFIG_IDE_8xx_PCCARD
  378. u_int pscr, pipr;
  379. #if (PCMCIA_SOCKETS_NO == 2)
  380. u_int _slot_;
  381. #endif
  382. /* get interrupt sources */
  383. pscr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr;
  384. pipr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr;
  385. /*
  386. * report only if both card detect signals are the same
  387. * not too nice done,
  388. * we depend on that CD2 is the bit to the left of CD1...
  389. */
  390. if(_slot_==-1){
  391. printk("PCMCIA slot has not been defined! Using A as default\n");
  392. _slot_=0;
  393. }
  394. if(((pipr & M8XX_PCMCIA_CD2(_slot_)) >> 1) ^
  395. (pipr & M8XX_PCMCIA_CD1(_slot_)) ) {
  396. printk ("card detect interrupt\n");
  397. }
  398. /* clear the interrupt sources */
  399. ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr = pscr;
  400. #else /* ! CONFIG_IDE_8xx_PCCARD */
  401. /*
  402. * Only CONFIG_IDE_8xx_PCCARD is using the interrupt of the
  403. * MPC8xx's PCMCIA controller, so there is nothing to be done here
  404. * for CONFIG_IDE_8xx_DIRECT and CONFIG_IDE_EXT_DIRECT.
  405. * The interrupt is handled somewhere else. -- Steven
  406. */
  407. #endif /* CONFIG_IDE_8xx_PCCARD */
  408. }
  409. /*
  410. * CIS Tupel codes
  411. */
  412. #define CISTPL_NULL 0x00
  413. #define CISTPL_DEVICE 0x01
  414. #define CISTPL_LONGLINK_CB 0x02
  415. #define CISTPL_INDIRECT 0x03
  416. #define CISTPL_CONFIG_CB 0x04
  417. #define CISTPL_CFTABLE_ENTRY_CB 0x05
  418. #define CISTPL_LONGLINK_MFC 0x06
  419. #define CISTPL_BAR 0x07
  420. #define CISTPL_PWR_MGMNT 0x08
  421. #define CISTPL_EXTDEVICE 0x09
  422. #define CISTPL_CHECKSUM 0x10
  423. #define CISTPL_LONGLINK_A 0x11
  424. #define CISTPL_LONGLINK_C 0x12
  425. #define CISTPL_LINKTARGET 0x13
  426. #define CISTPL_NO_LINK 0x14
  427. #define CISTPL_VERS_1 0x15
  428. #define CISTPL_ALTSTR 0x16
  429. #define CISTPL_DEVICE_A 0x17
  430. #define CISTPL_JEDEC_C 0x18
  431. #define CISTPL_JEDEC_A 0x19
  432. #define CISTPL_CONFIG 0x1a
  433. #define CISTPL_CFTABLE_ENTRY 0x1b
  434. #define CISTPL_DEVICE_OC 0x1c
  435. #define CISTPL_DEVICE_OA 0x1d
  436. #define CISTPL_DEVICE_GEO 0x1e
  437. #define CISTPL_DEVICE_GEO_A 0x1f
  438. #define CISTPL_MANFID 0x20
  439. #define CISTPL_FUNCID 0x21
  440. #define CISTPL_FUNCE 0x22
  441. #define CISTPL_SWIL 0x23
  442. #define CISTPL_END 0xff
  443. /*
  444. * CIS Function ID codes
  445. */
  446. #define CISTPL_FUNCID_MULTI 0x00
  447. #define CISTPL_FUNCID_MEMORY 0x01
  448. #define CISTPL_FUNCID_SERIAL 0x02
  449. #define CISTPL_FUNCID_PARALLEL 0x03
  450. #define CISTPL_FUNCID_FIXED 0x04
  451. #define CISTPL_FUNCID_VIDEO 0x05
  452. #define CISTPL_FUNCID_NETWORK 0x06
  453. #define CISTPL_FUNCID_AIMS 0x07
  454. #define CISTPL_FUNCID_SCSI 0x08
  455. /*
  456. * Fixed Disk FUNCE codes
  457. */
  458. #define CISTPL_IDE_INTERFACE 0x01
  459. #define CISTPL_FUNCE_IDE_IFACE 0x01
  460. #define CISTPL_FUNCE_IDE_MASTER 0x02
  461. #define CISTPL_FUNCE_IDE_SLAVE 0x03
  462. /* First feature byte */
  463. #define CISTPL_IDE_SILICON 0x04
  464. #define CISTPL_IDE_UNIQUE 0x08
  465. #define CISTPL_IDE_DUAL 0x10
  466. /* Second feature byte */
  467. #define CISTPL_IDE_HAS_SLEEP 0x01
  468. #define CISTPL_IDE_HAS_STANDBY 0x02
  469. #define CISTPL_IDE_HAS_IDLE 0x04
  470. #define CISTPL_IDE_LOW_POWER 0x08
  471. #define CISTPL_IDE_REG_INHIBIT 0x10
  472. #define CISTPL_IDE_HAS_INDEX 0x20
  473. #define CISTPL_IDE_IOIS16 0x40
  474. /* -------------------------------------------------------------------- */
  475. #define MAX_TUPEL_SZ 512
  476. #define MAX_FEATURES 4
  477. static int check_ide_device (unsigned long base)
  478. {
  479. volatile u8 *ident = NULL;
  480. volatile u8 *feature_p[MAX_FEATURES];
  481. volatile u8 *p, *start;
  482. int n_features = 0;
  483. u8 func_id = ~0;
  484. u8 code, len;
  485. unsigned short config_base = 0;
  486. int found = 0;
  487. int i;
  488. #ifdef DEBUG
  489. printk ("PCMCIA MEM: %08lX\n", base);
  490. #endif
  491. start = p = (volatile u8 *) base;
  492. while ((p - start) < MAX_TUPEL_SZ) {
  493. code = *p; p += 2;
  494. if (code == 0xFF) { /* End of chain */
  495. break;
  496. }
  497. len = *p; p += 2;
  498. #ifdef DEBUG_PCMCIA
  499. { volatile u8 *q = p;
  500. printk ("\nTuple code %02x length %d\n\tData:",
  501. code, len);
  502. for (i = 0; i < len; ++i) {
  503. printk (" %02x", *q);
  504. q+= 2;
  505. }
  506. }
  507. #endif /* DEBUG_PCMCIA */
  508. switch (code) {
  509. case CISTPL_VERS_1:
  510. ident = p + 4;
  511. break;
  512. case CISTPL_FUNCID:
  513. func_id = *p;
  514. break;
  515. case CISTPL_FUNCE:
  516. if (n_features < MAX_FEATURES)
  517. feature_p[n_features++] = p;
  518. break;
  519. case CISTPL_CONFIG:
  520. config_base = (*(p+6) << 8) + (*(p+4));
  521. default:
  522. break;
  523. }
  524. p += 2 * len;
  525. }
  526. found = identify (ident);
  527. if (func_id != ((u8)~0)) {
  528. print_funcid (func_id);
  529. if (func_id == CISTPL_FUNCID_FIXED)
  530. found = 1;
  531. else
  532. return (1); /* no disk drive */
  533. }
  534. for (i=0; i<n_features; ++i) {
  535. print_fixed (feature_p[i]);
  536. }
  537. if (!found) {
  538. printk ("unknown card type\n");
  539. return (1);
  540. }
  541. /* set level mode irq and I/O mapped device in config reg*/
  542. *((u8 *)(base + config_base)) = 0x41;
  543. return (0);
  544. }
  545. /* ------------------------------------------------------------------------- */
  546. static void print_funcid (int func)
  547. {
  548. switch (func) {
  549. case CISTPL_FUNCID_MULTI:
  550. printk (" Multi-Function");
  551. break;
  552. case CISTPL_FUNCID_MEMORY:
  553. printk (" Memory");
  554. break;
  555. case CISTPL_FUNCID_SERIAL:
  556. printk (" Serial Port");
  557. break;
  558. case CISTPL_FUNCID_PARALLEL:
  559. printk (" Parallel Port");
  560. break;
  561. case CISTPL_FUNCID_FIXED:
  562. printk (" Fixed Disk");
  563. break;
  564. case CISTPL_FUNCID_VIDEO:
  565. printk (" Video Adapter");
  566. break;
  567. case CISTPL_FUNCID_NETWORK:
  568. printk (" Network Adapter");
  569. break;
  570. case CISTPL_FUNCID_AIMS:
  571. printk (" AIMS Card");
  572. break;
  573. case CISTPL_FUNCID_SCSI:
  574. printk (" SCSI Adapter");
  575. break;
  576. default:
  577. printk (" Unknown");
  578. break;
  579. }
  580. printk (" Card\n");
  581. }
  582. /* ------------------------------------------------------------------------- */
  583. static void print_fixed (volatile u8 *p)
  584. {
  585. if (p == NULL)
  586. return;
  587. switch (*p) {
  588. case CISTPL_FUNCE_IDE_IFACE:
  589. { u8 iface = *(p+2);
  590. printk ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
  591. printk (" interface ");
  592. break;
  593. }
  594. case CISTPL_FUNCE_IDE_MASTER:
  595. case CISTPL_FUNCE_IDE_SLAVE:
  596. { u8 f1 = *(p+2);
  597. u8 f2 = *(p+4);
  598. printk ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
  599. if (f1 & CISTPL_IDE_UNIQUE)
  600. printk (" [unique]");
  601. printk ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
  602. if (f2 & CISTPL_IDE_HAS_SLEEP)
  603. printk (" [sleep]");
  604. if (f2 & CISTPL_IDE_HAS_STANDBY)
  605. printk (" [standby]");
  606. if (f2 & CISTPL_IDE_HAS_IDLE)
  607. printk (" [idle]");
  608. if (f2 & CISTPL_IDE_LOW_POWER)
  609. printk (" [low power]");
  610. if (f2 & CISTPL_IDE_REG_INHIBIT)
  611. printk (" [reg inhibit]");
  612. if (f2 & CISTPL_IDE_HAS_INDEX)
  613. printk (" [index]");
  614. if (f2 & CISTPL_IDE_IOIS16)
  615. printk (" [IOis16]");
  616. break;
  617. }
  618. }
  619. printk ("\n");
  620. }
  621. /* ------------------------------------------------------------------------- */
  622. #define MAX_IDENT_CHARS 64
  623. #define MAX_IDENT_FIELDS 4
  624. static u8 *known_cards[] = {
  625. "ARGOSY PnPIDE D5",
  626. NULL
  627. };
  628. static int identify (volatile u8 *p)
  629. {
  630. u8 id_str[MAX_IDENT_CHARS];
  631. u8 data;
  632. u8 *t;
  633. u8 **card;
  634. int i, done;
  635. if (p == NULL)
  636. return (0); /* Don't know */
  637. t = id_str;
  638. done =0;
  639. for (i=0; i<=4 && !done; ++i, p+=2) {
  640. while ((data = *p) != '\0') {
  641. if (data == 0xFF) {
  642. done = 1;
  643. break;
  644. }
  645. *t++ = data;
  646. if (t == &id_str[MAX_IDENT_CHARS-1]) {
  647. done = 1;
  648. break;
  649. }
  650. p += 2;
  651. }
  652. if (!done)
  653. *t++ = ' ';
  654. }
  655. *t = '\0';
  656. while (--t > id_str) {
  657. if (*t == ' ')
  658. *t = '\0';
  659. else
  660. break;
  661. }
  662. printk ("Card ID: %s\n", id_str);
  663. for (card=known_cards; *card; ++card) {
  664. if (strcmp(*card, id_str) == 0) { /* found! */
  665. return (1);
  666. }
  667. }
  668. return (0); /* don't know */
  669. }
  670. static int __init mpc8xx_ide_probe(void)
  671. {
  672. hw_regs_t hw;
  673. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  674. #ifdef IDE0_BASE_OFFSET
  675. memset(&hw, 0, sizeof(hw));
  676. if (!m8xx_ide_init_ports(&hw, 0)) {
  677. ide_hwif_t *hwif = ide_find_port();
  678. if (hwif) {
  679. ide_init_port_hw(hwif, &hw);
  680. hwif->pio_mask = ATA_PIO4;
  681. hwif->port_ops = &m8xx_port_ops;
  682. idx[0] = hwif->index;
  683. }
  684. }
  685. #ifdef IDE1_BASE_OFFSET
  686. memset(&hw, 0, sizeof(hw));
  687. if (!m8xx_ide_init_ports(&hw, 1)) {
  688. ide_hwif_t *mate = ide_find_port();
  689. if (mate) {
  690. ide_init_port_hw(mate, &hw);
  691. mate->pio_mask = ATA_PIO4;
  692. mate->port_ops = &m8xx_port_ops;
  693. idx[1] = mate->index;
  694. }
  695. }
  696. #endif
  697. #endif
  698. ide_device_add(idx, NULL);
  699. return 0;
  700. }
  701. module_init(mpc8xx_ide_probe);
  702. MODULE_LICENSE("GPL");