ide-m8xx.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:20k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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