m8xx_pcmcia.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. /*
  2. * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
  3. *
  4. * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
  5. * (C) 2001-2002 Montavista Software, Inc.
  6. * <mlocke@mvista.com>
  7. *
  8. * Support for two slots by Cyclades Corporation
  9. * <oliver.kurth@cyclades.de>
  10. * Further fixes, v2.6 kernel port
  11. * <marcelo.tosatti@cyclades.com>
  12. *
  13. * Some fixes, additions (C) 2005 Montavista Software, Inc.
  14. * <vbordug@ru.mvista.com>
  15. *
  16. * "The ExCA standard specifies that socket controllers should provide
  17. * two IO and five memory windows per socket, which can be independently
  18. * configured and positioned in the host address space and mapped to
  19. * arbitrary segments of card address space. " - David A Hinds. 1999
  20. *
  21. * This controller does _not_ meet the ExCA standard.
  22. *
  23. * m8xx pcmcia controller brief info:
  24. * + 8 windows (attrib, mem, i/o)
  25. * + up to two slots (SLOT_A and SLOT_B)
  26. * + inputpins, outputpins, event and mask registers.
  27. * - no offset register. sigh.
  28. *
  29. * Because of the lacking offset register we must map the whole card.
  30. * We assign each memory window PCMCIA_MEM_WIN_SIZE address space.
  31. * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO
  32. * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE.
  33. * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE.
  34. * They are maximum 64KByte each...
  35. */
  36. #include <linux/module.h>
  37. #include <linux/init.h>
  38. #include <linux/types.h>
  39. #include <linux/fcntl.h>
  40. #include <linux/string.h>
  41. #include <asm/io.h>
  42. #include <asm/bitops.h>
  43. #include <asm/system.h>
  44. #include <linux/kernel.h>
  45. #include <linux/errno.h>
  46. #include <linux/sched.h>
  47. #include <linux/slab.h>
  48. #include <linux/timer.h>
  49. #include <linux/ioport.h>
  50. #include <linux/delay.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/platform_device.h>
  53. #include <asm/mpc8xx.h>
  54. #include <asm/8xx_immap.h>
  55. #include <asm/irq.h>
  56. #include <pcmcia/version.h>
  57. #include <pcmcia/cs_types.h>
  58. #include <pcmcia/cs.h>
  59. #include <pcmcia/ss.h>
  60. #ifdef PCMCIA_DEBUG
  61. static int pc_debug = PCMCIA_DEBUG;
  62. module_param(pc_debug, int, 0);
  63. #define dprintk(args...) printk(KERN_DEBUG "m8xx_pcmcia: " args);
  64. #else
  65. #define dprintk(args...)
  66. #endif
  67. #define pcmcia_info(args...) printk(KERN_INFO "m8xx_pcmcia: "args)
  68. #define pcmcia_error(args...) printk(KERN_ERR "m8xx_pcmcia: "args)
  69. static const char *version = "Version 0.06, Aug 2005";
  70. MODULE_LICENSE("Dual MPL/GPL");
  71. #if !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B)
  72. /* The RPX series use SLOT_B */
  73. #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE)
  74. #define CONFIG_PCMCIA_SLOT_B
  75. #define CONFIG_BD_IS_MHZ
  76. #endif
  77. /* The ADS board use SLOT_A */
  78. #ifdef CONFIG_ADS
  79. #define CONFIG_PCMCIA_SLOT_A
  80. #define CONFIG_BD_IS_MHZ
  81. #endif
  82. /* The FADS series are a mess */
  83. #ifdef CONFIG_FADS
  84. #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC860) || defined(CONFIG_MPC821)
  85. #define CONFIG_PCMCIA_SLOT_A
  86. #else
  87. #define CONFIG_PCMCIA_SLOT_B
  88. #endif
  89. #endif
  90. #if defined(CONFIG_MPC885ADS)
  91. #define CONFIG_PCMCIA_SLOT_A
  92. #define PCMCIA_GLITCHY_CD
  93. #endif
  94. /* Cyclades ACS uses both slots */
  95. #ifdef CONFIG_PRxK
  96. #define CONFIG_PCMCIA_SLOT_A
  97. #define CONFIG_PCMCIA_SLOT_B
  98. #endif
  99. #endif /* !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B) */
  100. #if defined(CONFIG_PCMCIA_SLOT_A) && defined(CONFIG_PCMCIA_SLOT_B)
  101. #define PCMCIA_SOCKETS_NO 2
  102. /* We have only 8 windows, dualsocket support will be limited. */
  103. #define PCMCIA_MEM_WIN_NO 2
  104. #define PCMCIA_IO_WIN_NO 2
  105. #define PCMCIA_SLOT_MSG "SLOT_A and SLOT_B"
  106. #elif defined(CONFIG_PCMCIA_SLOT_A) || defined(CONFIG_PCMCIA_SLOT_B)
  107. #define PCMCIA_SOCKETS_NO 1
  108. /* full support for one slot */
  109. #define PCMCIA_MEM_WIN_NO 5
  110. #define PCMCIA_IO_WIN_NO 2
  111. /* define _slot_ to be able to optimize macros */
  112. #ifdef CONFIG_PCMCIA_SLOT_A
  113. #define _slot_ 0
  114. #define PCMCIA_SLOT_MSG "SLOT_A"
  115. #else
  116. #define _slot_ 1
  117. #define PCMCIA_SLOT_MSG "SLOT_B"
  118. #endif
  119. #else
  120. #error m8xx_pcmcia: Bad configuration!
  121. #endif
  122. /* ------------------------------------------------------------------------- */
  123. #define PCMCIA_MEM_WIN_BASE 0xe0000000 /* base address for memory window 0 */
  124. #define PCMCIA_MEM_WIN_SIZE 0x04000000 /* each memory window is 64 MByte */
  125. #define PCMCIA_IO_WIN_BASE _IO_BASE /* base address for io window 0 */
  126. #define PCMCIA_SCHLVL PCMCIA_INTERRUPT /* Status Change Interrupt Level */
  127. /* ------------------------------------------------------------------------- */
  128. /* 2.4.x and newer has this always in HZ */
  129. #define M8XX_BUSFREQ ((((bd_t *)&(__res))->bi_busfreq))
  130. static int pcmcia_schlvl = PCMCIA_SCHLVL;
  131. static DEFINE_SPINLOCK(events_lock);
  132. #define PCMCIA_SOCKET_KEY_5V 1
  133. #define PCMCIA_SOCKET_KEY_LV 2
  134. /* look up table for pgcrx registers */
  135. static u32 *m8xx_pgcrx[2] = {
  136. &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pgcra,
  137. &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pgcrb
  138. };
  139. /*
  140. * This structure is used to address each window in the PCMCIA controller.
  141. *
  142. * Keep in mind that we assume that pcmcia_win[n+1] is mapped directly
  143. * after pcmcia_win[n]...
  144. */
  145. struct pcmcia_win {
  146. u32 br;
  147. u32 or;
  148. };
  149. /*
  150. * For some reason the hardware guys decided to make both slots share
  151. * some registers.
  152. *
  153. * Could someone invent object oriented hardware ?
  154. *
  155. * The macros are used to get the right bit from the registers.
  156. * SLOT_A : slot = 0
  157. * SLOT_B : slot = 1
  158. */
  159. #define M8XX_PCMCIA_VS1(slot) (0x80000000 >> (slot << 4))
  160. #define M8XX_PCMCIA_VS2(slot) (0x40000000 >> (slot << 4))
  161. #define M8XX_PCMCIA_VS_MASK(slot) (0xc0000000 >> (slot << 4))
  162. #define M8XX_PCMCIA_VS_SHIFT(slot) (30 - (slot << 4))
  163. #define M8XX_PCMCIA_WP(slot) (0x20000000 >> (slot << 4))
  164. #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4))
  165. #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4))
  166. #define M8XX_PCMCIA_BVD2(slot) (0x04000000 >> (slot << 4))
  167. #define M8XX_PCMCIA_BVD1(slot) (0x02000000 >> (slot << 4))
  168. #define M8XX_PCMCIA_RDY(slot) (0x01000000 >> (slot << 4))
  169. #define M8XX_PCMCIA_RDY_L(slot) (0x00800000 >> (slot << 4))
  170. #define M8XX_PCMCIA_RDY_H(slot) (0x00400000 >> (slot << 4))
  171. #define M8XX_PCMCIA_RDY_R(slot) (0x00200000 >> (slot << 4))
  172. #define M8XX_PCMCIA_RDY_F(slot) (0x00100000 >> (slot << 4))
  173. #define M8XX_PCMCIA_MASK(slot) (0xFFFF0000 >> (slot << 4))
  174. #define M8XX_PCMCIA_POR_VALID 0x00000001
  175. #define M8XX_PCMCIA_POR_WRPROT 0x00000002
  176. #define M8XX_PCMCIA_POR_ATTRMEM 0x00000010
  177. #define M8XX_PCMCIA_POR_IO 0x00000018
  178. #define M8XX_PCMCIA_POR_16BIT 0x00000040
  179. #define M8XX_PGCRX(slot) m8xx_pgcrx[slot]
  180. #define M8XX_PGCRX_CXOE 0x00000080
  181. #define M8XX_PGCRX_CXRESET 0x00000040
  182. /* we keep one lookup table per socket to check flags */
  183. #define PCMCIA_EVENTS_MAX 5 /* 4 max at a time + termination */
  184. struct event_table {
  185. u32 regbit;
  186. u32 eventbit;
  187. };
  188. struct socket_info {
  189. void (*handler)(void *info, u32 events);
  190. void *info;
  191. u32 slot;
  192. socket_state_t state;
  193. struct pccard_mem_map mem_win[PCMCIA_MEM_WIN_NO];
  194. struct pccard_io_map io_win[PCMCIA_IO_WIN_NO];
  195. struct event_table events[PCMCIA_EVENTS_MAX];
  196. struct pcmcia_socket socket;
  197. };
  198. static struct socket_info socket[PCMCIA_SOCKETS_NO];
  199. /*
  200. * Search this table to see if the windowsize is
  201. * supported...
  202. */
  203. #define M8XX_SIZES_NO 32
  204. static const u32 m8xx_size_to_gray[M8XX_SIZES_NO] =
  205. {
  206. 0x00000001, 0x00000002, 0x00000008, 0x00000004,
  207. 0x00000080, 0x00000040, 0x00000010, 0x00000020,
  208. 0x00008000, 0x00004000, 0x00001000, 0x00002000,
  209. 0x00000100, 0x00000200, 0x00000800, 0x00000400,
  210. 0x0fffffff, 0xffffffff, 0xffffffff, 0xffffffff,
  211. 0x01000000, 0x02000000, 0xffffffff, 0x04000000,
  212. 0x00010000, 0x00020000, 0x00080000, 0x00040000,
  213. 0x00800000, 0x00400000, 0x00100000, 0x00200000
  214. };
  215. /* ------------------------------------------------------------------------- */
  216. static irqreturn_t m8xx_interrupt(int irq, void *dev);
  217. #define PCMCIA_BMT_LIMIT (15*4) /* Bus Monitor Timeout value */
  218. /* ------------------------------------------------------------------------- */
  219. /* board specific stuff: */
  220. /* voltage_set(), hardware_enable() and hardware_disable() */
  221. /* ------------------------------------------------------------------------- */
  222. /* RPX Boards from Embedded Planet */
  223. #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE)
  224. /* The RPX boards seems to have it's bus monitor timeout set to 6*8 clocks.
  225. * SYPCR is write once only, therefore must the slowest memory be faster
  226. * than the bus monitor or we will get a machine check due to the bus timeout.
  227. */
  228. #define PCMCIA_BOARD_MSG "RPX CLASSIC or RPX LITE"
  229. #undef PCMCIA_BMT_LIMIT
  230. #define PCMCIA_BMT_LIMIT (6*8)
  231. static int voltage_set(int slot, int vcc, int vpp)
  232. {
  233. u32 reg = 0;
  234. switch(vcc) {
  235. case 0: break;
  236. case 33:
  237. reg |= BCSR1_PCVCTL4;
  238. break;
  239. case 50:
  240. reg |= BCSR1_PCVCTL5;
  241. break;
  242. default:
  243. return 1;
  244. }
  245. switch(vpp) {
  246. case 0: break;
  247. case 33:
  248. case 50:
  249. if(vcc == vpp)
  250. reg |= BCSR1_PCVCTL6;
  251. else
  252. return 1;
  253. break;
  254. case 120:
  255. reg |= BCSR1_PCVCTL7;
  256. default:
  257. return 1;
  258. }
  259. if(!((vcc == 50) || (vcc == 0)))
  260. return 1;
  261. /* first, turn off all power */
  262. out_be32(((u32 *)RPX_CSR_ADDR), in_be32(((u32 *)RPX_CSR_ADDR)) & ~(BCSR1_PCVCTL4 | BCSR1_PCVCTL5 | BCSR1_PCVCTL6 | BCSR1_PCVCTL7));
  263. /* enable new powersettings */
  264. out_be32(((u32 *)RPX_CSR_ADDR), in_be32(((u32 *)RPX_CSR_ADDR)) | reg);
  265. return 0;
  266. }
  267. #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
  268. #define hardware_enable(_slot_) /* No hardware to enable */
  269. #define hardware_disable(_slot_) /* No hardware to disable */
  270. #endif /* CONFIG_RPXCLASSIC */
  271. /* FADS Boards from Motorola */
  272. #if defined(CONFIG_FADS)
  273. #define PCMCIA_BOARD_MSG "FADS"
  274. static int voltage_set(int slot, int vcc, int vpp)
  275. {
  276. u32 reg = 0;
  277. switch(vcc) {
  278. case 0:
  279. break;
  280. case 33:
  281. reg |= BCSR1_PCCVCC0;
  282. break;
  283. case 50:
  284. reg |= BCSR1_PCCVCC1;
  285. break;
  286. default:
  287. return 1;
  288. }
  289. switch(vpp) {
  290. case 0:
  291. break;
  292. case 33:
  293. case 50:
  294. if(vcc == vpp)
  295. reg |= BCSR1_PCCVPP1;
  296. else
  297. return 1;
  298. break;
  299. case 120:
  300. if ((vcc == 33) || (vcc == 50))
  301. reg |= BCSR1_PCCVPP0;
  302. else
  303. return 1;
  304. default:
  305. return 1;
  306. }
  307. /* first, turn off all power */
  308. out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) & ~(BCSR1_PCCVCC_MASK | BCSR1_PCCVPP_MASK));
  309. /* enable new powersettings */
  310. out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) | reg);
  311. return 0;
  312. }
  313. #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
  314. static void hardware_enable(int slot)
  315. {
  316. out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) & ~BCSR1_PCCEN);
  317. }
  318. static void hardware_disable(int slot)
  319. {
  320. out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) | BCSR1_PCCEN);
  321. }
  322. #endif
  323. /* MPC885ADS Boards */
  324. #if defined(CONFIG_MPC885ADS)
  325. #define PCMCIA_BOARD_MSG "MPC885ADS"
  326. static int voltage_set(int slot, int vcc, int vpp)
  327. {
  328. u32 reg = 0;
  329. unsigned *bcsr_io;
  330. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  331. switch(vcc) {
  332. case 0:
  333. break;
  334. case 33:
  335. reg |= BCSR1_PCCVCC0;
  336. break;
  337. case 50:
  338. reg |= BCSR1_PCCVCC1;
  339. break;
  340. default:
  341. goto out_unmap;
  342. }
  343. switch(vpp) {
  344. case 0:
  345. break;
  346. case 33:
  347. case 50:
  348. if(vcc == vpp)
  349. reg |= BCSR1_PCCVPP1;
  350. else
  351. goto out_unmap;
  352. break;
  353. case 120:
  354. if ((vcc == 33) || (vcc == 50))
  355. reg |= BCSR1_PCCVPP0;
  356. else
  357. goto out_unmap;
  358. default:
  359. goto out_unmap;
  360. }
  361. /* first, turn off all power */
  362. out_be32(bcsr_io, in_be32(bcsr_io) & ~(BCSR1_PCCVCC_MASK | BCSR1_PCCVPP_MASK));
  363. /* enable new powersettings */
  364. out_be32(bcsr_io, in_be32(bcsr_io) | reg);
  365. iounmap(bcsr_io);
  366. return 0;
  367. out_unmap:
  368. iounmap(bcsr_io);
  369. return 1;
  370. }
  371. #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
  372. static void hardware_enable(int slot)
  373. {
  374. unsigned *bcsr_io;
  375. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  376. out_be32(bcsr_io, in_be32(bcsr_io) & ~BCSR1_PCCEN);
  377. iounmap(bcsr_io);
  378. }
  379. static void hardware_disable(int slot)
  380. {
  381. unsigned *bcsr_io;
  382. bcsr_io = ioremap(BCSR1, sizeof(unsigned long));
  383. out_be32(bcsr_io, in_be32(bcsr_io) | BCSR1_PCCEN);
  384. iounmap(bcsr_io);
  385. }
  386. #endif
  387. /* ------------------------------------------------------------------------- */
  388. /* Motorola MBX860 */
  389. #if defined(CONFIG_MBX)
  390. #define PCMCIA_BOARD_MSG "MBX"
  391. static int voltage_set(int slot, int vcc, int vpp)
  392. {
  393. u8 reg = 0;
  394. switch(vcc) {
  395. case 0:
  396. break;
  397. case 33:
  398. reg |= CSR2_VCC_33;
  399. break;
  400. case 50:
  401. reg |= CSR2_VCC_50;
  402. break;
  403. default:
  404. return 1;
  405. }
  406. switch(vpp) {
  407. case 0:
  408. break;
  409. case 33:
  410. case 50:
  411. if(vcc == vpp)
  412. reg |= CSR2_VPP_VCC;
  413. else
  414. return 1;
  415. break;
  416. case 120:
  417. if ((vcc == 33) || (vcc == 50))
  418. reg |= CSR2_VPP_12;
  419. else
  420. return 1;
  421. default:
  422. return 1;
  423. }
  424. /* first, turn off all power */
  425. out_8((u8 *)MBX_CSR2_ADDR, in_8((u8 *)MBX_CSR2_ADDR) & ~(CSR2_VCC_MASK | CSR2_VPP_MASK));
  426. /* enable new powersettings */
  427. out_8((u8 *)MBX_CSR2_ADDR, in_8((u8 *)MBX_CSR2_ADDR) | reg);
  428. return 0;
  429. }
  430. #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V
  431. #define hardware_enable(_slot_) /* No hardware to enable */
  432. #define hardware_disable(_slot_) /* No hardware to disable */
  433. #endif /* CONFIG_MBX */
  434. #if defined(CONFIG_PRxK)
  435. #include <asm/cpld.h>
  436. extern volatile fpga_pc_regs *fpga_pc;
  437. #define PCMCIA_BOARD_MSG "MPC855T"
  438. static int voltage_set(int slot, int vcc, int vpp)
  439. {
  440. u8 reg = 0;
  441. u8 regread;
  442. cpld_regs *ccpld = get_cpld();
  443. switch(vcc) {
  444. case 0:
  445. break;
  446. case 33:
  447. reg |= PCMCIA_VCC_33;
  448. break;
  449. case 50:
  450. reg |= PCMCIA_VCC_50;
  451. break;
  452. default:
  453. return 1;
  454. }
  455. switch(vpp) {
  456. case 0:
  457. break;
  458. case 33:
  459. case 50:
  460. if(vcc == vpp)
  461. reg |= PCMCIA_VPP_VCC;
  462. else
  463. return 1;
  464. break;
  465. case 120:
  466. if ((vcc == 33) || (vcc == 50))
  467. reg |= PCMCIA_VPP_12;
  468. else
  469. return 1;
  470. default:
  471. return 1;
  472. }
  473. reg = reg >> (slot << 2);
  474. regread = in_8(&ccpld->fpga_pc_ctl);
  475. if (reg != (regread & ((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> (slot << 2)))) {
  476. /* enable new powersettings */
  477. regread = regread & ~((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> (slot << 2));
  478. out_8(&ccpld->fpga_pc_ctl, reg | regread);
  479. msleep(100);
  480. }
  481. return 0;
  482. }
  483. #define socket_get(_slot_) PCMCIA_SOCKET_KEY_LV
  484. #define hardware_enable(_slot_) /* No hardware to enable */
  485. #define hardware_disable(_slot_) /* No hardware to disable */
  486. #endif /* CONFIG_PRxK */
  487. static void m8xx_shutdown(void)
  488. {
  489. u32 m, i;
  490. struct pcmcia_win *w;
  491. for(i = 0; i < PCMCIA_SOCKETS_NO; i++){
  492. w = (void *) &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0;
  493. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr, M8XX_PCMCIA_MASK(i));
  494. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per, in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per) & ~M8XX_PCMCIA_MASK(i));
  495. /* turn off interrupt and disable CxOE */
  496. out_be32(M8XX_PGCRX(i), M8XX_PGCRX_CXOE);
  497. /* turn off memory windows */
  498. for(m = 0; m < PCMCIA_MEM_WIN_NO; m++) {
  499. out_be32(&w->or, 0); /* set to not valid */
  500. w++;
  501. }
  502. /* turn off voltage */
  503. voltage_set(i, 0, 0);
  504. /* disable external hardware */
  505. hardware_disable(i);
  506. }
  507. free_irq(pcmcia_schlvl, NULL);
  508. }
  509. static struct device_driver m8xx_driver = {
  510. .name = "m8xx-pcmcia",
  511. .bus = &platform_bus_type,
  512. .suspend = pcmcia_socket_dev_suspend,
  513. .resume = pcmcia_socket_dev_resume,
  514. };
  515. static struct platform_device m8xx_device = {
  516. .name = "m8xx-pcmcia",
  517. .id = 0,
  518. };
  519. static u32 pending_events[PCMCIA_SOCKETS_NO];
  520. static DEFINE_SPINLOCK(pending_event_lock);
  521. static irqreturn_t m8xx_interrupt(int irq, void *dev)
  522. {
  523. struct socket_info *s;
  524. struct event_table *e;
  525. unsigned int i, events, pscr, pipr, per;
  526. dprintk("Interrupt!\n");
  527. /* get interrupt sources */
  528. pscr = in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr);
  529. pipr = in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr);
  530. per = in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per);
  531. for(i = 0; i < PCMCIA_SOCKETS_NO; i++) {
  532. s = &socket[i];
  533. e = &s->events[0];
  534. events = 0;
  535. while(e->regbit) {
  536. if(pscr & e->regbit)
  537. events |= e->eventbit;
  538. e++;
  539. }
  540. /*
  541. * report only if both card detect signals are the same
  542. * not too nice done,
  543. * we depend on that CD2 is the bit to the left of CD1...
  544. */
  545. if(events & SS_DETECT)
  546. if(((pipr & M8XX_PCMCIA_CD2(i)) >> 1) ^
  547. (pipr & M8XX_PCMCIA_CD1(i)))
  548. {
  549. events &= ~SS_DETECT;
  550. }
  551. #ifdef PCMCIA_GLITCHY_CD
  552. /*
  553. * I've experienced CD problems with my ADS board.
  554. * We make an extra check to see if there was a
  555. * real change of Card detection.
  556. */
  557. if((events & SS_DETECT) &&
  558. ((pipr &
  559. (M8XX_PCMCIA_CD2(i) | M8XX_PCMCIA_CD1(i))) == 0) &&
  560. (s->state.Vcc | s->state.Vpp)) {
  561. events &= ~SS_DETECT;
  562. /*printk( "CD glitch workaround - CD = 0x%08x!\n",
  563. (pipr & (M8XX_PCMCIA_CD2(i)
  564. | M8XX_PCMCIA_CD1(i))));*/
  565. }
  566. #endif
  567. /* call the handler */
  568. dprintk("slot %u: events = 0x%02x, pscr = 0x%08x, "
  569. "pipr = 0x%08x\n",
  570. i, events, pscr, pipr);
  571. if(events) {
  572. spin_lock(&pending_event_lock);
  573. pending_events[i] |= events;
  574. spin_unlock(&pending_event_lock);
  575. /*
  576. * Turn off RDY_L bits in the PER mask on
  577. * CD interrupt receival.
  578. *
  579. * They can generate bad interrupts on the
  580. * ACS4,8,16,32. - marcelo
  581. */
  582. per &= ~M8XX_PCMCIA_RDY_L(0);
  583. per &= ~M8XX_PCMCIA_RDY_L(1);
  584. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per, per);
  585. if (events)
  586. pcmcia_parse_events(&socket[i].socket, events);
  587. }
  588. }
  589. /* clear the interrupt sources */
  590. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr, pscr);
  591. dprintk("Interrupt done.\n");
  592. return IRQ_HANDLED;
  593. }
  594. static u32 m8xx_get_graycode(u32 size)
  595. {
  596. u32 k;
  597. for(k = 0; k < M8XX_SIZES_NO; k++)
  598. if(m8xx_size_to_gray[k] == size)
  599. break;
  600. if((k == M8XX_SIZES_NO) || (m8xx_size_to_gray[k] == -1))
  601. k = -1;
  602. return k;
  603. }
  604. static u32 m8xx_get_speed(u32 ns, u32 is_io)
  605. {
  606. u32 reg, clocks, psst, psl, psht;
  607. if(!ns) {
  608. /*
  609. * We get called with IO maps setup to 0ns
  610. * if not specified by the user.
  611. * They should be 255ns.
  612. */
  613. if(is_io)
  614. ns = 255;
  615. else
  616. ns = 100; /* fast memory if 0 */
  617. }
  618. /*
  619. * In PSST, PSL, PSHT fields we tell the controller
  620. * timing parameters in CLKOUT clock cycles.
  621. * CLKOUT is the same as GCLK2_50.
  622. */
  623. /* how we want to adjust the timing - in percent */
  624. #define ADJ 180 /* 80 % longer accesstime - to be sure */
  625. clocks = ((M8XX_BUSFREQ / 1000) * ns) / 1000;
  626. clocks = (clocks * ADJ) / (100*1000);
  627. if(clocks >= PCMCIA_BMT_LIMIT) {
  628. printk( "Max access time limit reached\n");
  629. clocks = PCMCIA_BMT_LIMIT-1;
  630. }
  631. psst = clocks / 7; /* setup time */
  632. psht = clocks / 7; /* hold time */
  633. psl = (clocks * 5) / 7; /* strobe length */
  634. psst += clocks - (psst + psht + psl);
  635. reg = psst << 12;
  636. reg |= psl << 7;
  637. reg |= psht << 16;
  638. return reg;
  639. }
  640. static int m8xx_get_status(struct pcmcia_socket *sock, unsigned int *value)
  641. {
  642. int lsock = container_of(sock, struct socket_info, socket)->slot;
  643. struct socket_info *s = &socket[lsock];
  644. unsigned int pipr, reg;
  645. pipr = in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr);
  646. *value = ((pipr & (M8XX_PCMCIA_CD1(lsock)
  647. | M8XX_PCMCIA_CD2(lsock))) == 0) ? SS_DETECT : 0;
  648. *value |= (pipr & M8XX_PCMCIA_WP(lsock)) ? SS_WRPROT : 0;
  649. if (s->state.flags & SS_IOCARD)
  650. *value |= (pipr & M8XX_PCMCIA_BVD1(lsock)) ? SS_STSCHG : 0;
  651. else {
  652. *value |= (pipr & M8XX_PCMCIA_RDY(lsock)) ? SS_READY : 0;
  653. *value |= (pipr & M8XX_PCMCIA_BVD1(lsock)) ? SS_BATDEAD : 0;
  654. *value |= (pipr & M8XX_PCMCIA_BVD2(lsock)) ? SS_BATWARN : 0;
  655. }
  656. if (s->state.Vcc | s->state.Vpp)
  657. *value |= SS_POWERON;
  658. /*
  659. * Voltage detection:
  660. * This driver only supports 16-Bit pc-cards.
  661. * Cardbus is not handled here.
  662. *
  663. * To determine what voltage to use we must read the VS1 and VS2 pin.
  664. * Depending on what socket type is present,
  665. * different combinations mean different things.
  666. *
  667. * Card Key Socket Key VS1 VS2 Card Vcc for CIS parse
  668. *
  669. * 5V 5V, LV* NC NC 5V only 5V (if available)
  670. *
  671. * 5V 5V, LV* GND NC 5 or 3.3V as low as possible
  672. *
  673. * 5V 5V, LV* GND GND 5, 3.3, x.xV as low as possible
  674. *
  675. * LV* 5V - - shall not fit into socket
  676. *
  677. * LV* LV* GND NC 3.3V only 3.3V
  678. *
  679. * LV* LV* NC GND x.xV x.xV (if avail.)
  680. *
  681. * LV* LV* GND GND 3.3 or x.xV as low as possible
  682. *
  683. * *LV means Low Voltage
  684. *
  685. *
  686. * That gives us the following table:
  687. *
  688. * Socket VS1 VS2 Voltage
  689. *
  690. * 5V NC NC 5V
  691. * 5V NC GND none (should not be possible)
  692. * 5V GND NC >= 3.3V
  693. * 5V GND GND >= x.xV
  694. *
  695. * LV NC NC 5V (if available)
  696. * LV NC GND x.xV (if available)
  697. * LV GND NC 3.3V
  698. * LV GND GND >= x.xV
  699. *
  700. * So, how do I determine if I have a 5V or a LV
  701. * socket on my board? Look at the socket!
  702. *
  703. *
  704. * Socket with 5V key:
  705. * ++--------------------------------------------+
  706. * || |
  707. * || ||
  708. * || ||
  709. * | |
  710. * +---------------------------------------------+
  711. *
  712. * Socket with LV key:
  713. * ++--------------------------------------------+
  714. * || |
  715. * | ||
  716. * | ||
  717. * | |
  718. * +---------------------------------------------+
  719. *
  720. *
  721. * With other words - LV only cards does not fit
  722. * into the 5V socket!
  723. */
  724. /* read out VS1 and VS2 */
  725. reg = (pipr & M8XX_PCMCIA_VS_MASK(lsock))
  726. >> M8XX_PCMCIA_VS_SHIFT(lsock);
  727. if(socket_get(lsock) == PCMCIA_SOCKET_KEY_LV) {
  728. switch(reg) {
  729. case 1:
  730. *value |= SS_3VCARD;
  731. break; /* GND, NC - 3.3V only */
  732. case 2:
  733. *value |= SS_XVCARD;
  734. break; /* NC. GND - x.xV only */
  735. };
  736. }
  737. dprintk("GetStatus(%d) = %#2.2x\n", lsock, *value);
  738. return 0;
  739. }
  740. static int m8xx_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
  741. {
  742. int lsock = container_of(sock, struct socket_info, socket)->slot;
  743. struct socket_info *s = &socket[lsock];
  744. struct event_table *e;
  745. unsigned int reg;
  746. unsigned long flags;
  747. dprintk( "SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
  748. "io_irq %d, csc_mask %#2.2x)\n", lsock, state->flags,
  749. state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
  750. /* First, set voltage - bail out if invalid */
  751. if(voltage_set(lsock, state->Vcc, state->Vpp))
  752. return -EINVAL;
  753. /* Take care of reset... */
  754. if(state->flags & SS_RESET)
  755. out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) | M8XX_PGCRX_CXRESET); /* active high */
  756. else
  757. out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) & ~M8XX_PGCRX_CXRESET);
  758. /* ... and output enable. */
  759. /* The CxOE signal is connected to a 74541 on the ADS.
  760. I guess most other boards used the ADS as a reference.
  761. I tried to control the CxOE signal with SS_OUTPUT_ENA,
  762. but the reset signal seems connected via the 541.
  763. If the CxOE is left high are some signals tristated and
  764. no pullups are present -> the cards act wierd.
  765. So right now the buffers are enabled if the power is on. */
  766. if(state->Vcc || state->Vpp)
  767. out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) & ~M8XX_PGCRX_CXOE); /* active low */
  768. else
  769. out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) | M8XX_PGCRX_CXOE);
  770. /*
  771. * We'd better turn off interrupts before
  772. * we mess with the events-table..
  773. */
  774. spin_lock_irqsave(&events_lock, flags);
  775. /*
  776. * Play around with the interrupt mask to be able to
  777. * give the events the generic pcmcia driver wants us to.
  778. */
  779. e = &s->events[0];
  780. reg = 0;
  781. if(state->csc_mask & SS_DETECT) {
  782. e->eventbit = SS_DETECT;
  783. reg |= e->regbit = (M8XX_PCMCIA_CD2(lsock)
  784. | M8XX_PCMCIA_CD1(lsock));
  785. e++;
  786. }
  787. if(state->flags & SS_IOCARD) {
  788. /*
  789. * I/O card
  790. */
  791. if(state->csc_mask & SS_STSCHG) {
  792. e->eventbit = SS_STSCHG;
  793. reg |= e->regbit = M8XX_PCMCIA_BVD1(lsock);
  794. e++;
  795. }
  796. /*
  797. * If io_irq is non-zero we should enable irq.
  798. */
  799. if(state->io_irq) {
  800. out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) | mk_int_int_mask(state->io_irq) << 24);
  801. /*
  802. * Strange thing here:
  803. * The manual does not tell us which interrupt
  804. * the sources generate.
  805. * Anyhow, I found out that RDY_L generates IREQLVL.
  806. *
  807. * We use level triggerd interrupts, and they don't
  808. * have to be cleared in PSCR in the interrupt handler.
  809. */
  810. reg |= M8XX_PCMCIA_RDY_L(lsock);
  811. }
  812. else
  813. out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) & 0x00ffffff);
  814. }
  815. else {
  816. /*
  817. * Memory card
  818. */
  819. if(state->csc_mask & SS_BATDEAD) {
  820. e->eventbit = SS_BATDEAD;
  821. reg |= e->regbit = M8XX_PCMCIA_BVD1(lsock);
  822. e++;
  823. }
  824. if(state->csc_mask & SS_BATWARN) {
  825. e->eventbit = SS_BATWARN;
  826. reg |= e->regbit = M8XX_PCMCIA_BVD2(lsock);
  827. e++;
  828. }
  829. /* What should I trigger on - low/high,raise,fall? */
  830. if(state->csc_mask & SS_READY) {
  831. e->eventbit = SS_READY;
  832. reg |= e->regbit = 0; //??
  833. e++;
  834. }
  835. }
  836. e->regbit = 0; /* terminate list */
  837. /*
  838. * Clear the status changed .
  839. * Port A and Port B share the same port.
  840. * Writing ones will clear the bits.
  841. */
  842. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr, reg);
  843. /*
  844. * Write the mask.
  845. * Port A and Port B share the same port.
  846. * Need for read-modify-write.
  847. * Ones will enable the interrupt.
  848. */
  849. /*
  850. reg |= ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per
  851. & M8XX_PCMCIA_MASK(lsock);
  852. */
  853. reg |= in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per) &
  854. (M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1));
  855. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per, reg);
  856. spin_unlock_irqrestore(&events_lock, flags);
  857. /* copy the struct and modify the copy */
  858. s->state = *state;
  859. return 0;
  860. }
  861. static int m8xx_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
  862. {
  863. int lsock = container_of(sock, struct socket_info, socket)->slot;
  864. struct socket_info *s = &socket[lsock];
  865. struct pcmcia_win *w;
  866. unsigned int reg, winnr;
  867. #define M8XX_SIZE (io->stop - io->start + 1)
  868. #define M8XX_BASE (PCMCIA_IO_WIN_BASE + io->start)
  869. dprintk( "SetIOMap(%d, %d, %#2.2x, %d ns, "
  870. "%#4.4x-%#4.4x)\n", lsock, io->map, io->flags,
  871. io->speed, io->start, io->stop);
  872. if ((io->map >= PCMCIA_IO_WIN_NO) || (io->start > 0xffff)
  873. || (io->stop > 0xffff) || (io->stop < io->start))
  874. return -EINVAL;
  875. if((reg = m8xx_get_graycode(M8XX_SIZE)) == -1)
  876. return -EINVAL;
  877. if(io->flags & MAP_ACTIVE) {
  878. dprintk( "io->flags & MAP_ACTIVE\n");
  879. winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO)
  880. + (lsock * PCMCIA_IO_WIN_NO) + io->map;
  881. /* setup registers */
  882. w = (void *) &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0;
  883. w += winnr;
  884. out_be32(&w->or, 0); /* turn off window first */
  885. out_be32(&w->br, M8XX_BASE);
  886. reg <<= 27;
  887. reg |= M8XX_PCMCIA_POR_IO |(lsock << 2);
  888. reg |= m8xx_get_speed(io->speed, 1);
  889. if(io->flags & MAP_WRPROT)
  890. reg |= M8XX_PCMCIA_POR_WRPROT;
  891. if(io->flags & (MAP_16BIT | MAP_AUTOSZ))
  892. reg |= M8XX_PCMCIA_POR_16BIT;
  893. if(io->flags & MAP_ACTIVE)
  894. reg |= M8XX_PCMCIA_POR_VALID;
  895. out_be32(&w->or, reg);
  896. dprintk("Socket %u: Mapped io window %u at %#8.8x, "
  897. "OR = %#8.8x.\n", lsock, io->map, w->br, w->or);
  898. } else {
  899. /* shutdown IO window */
  900. winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO)
  901. + (lsock * PCMCIA_IO_WIN_NO) + io->map;
  902. /* setup registers */
  903. w = (void *) &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0;
  904. w += winnr;
  905. out_be32(&w->or, 0); /* turn off window */
  906. out_be32(&w->br, 0); /* turn off base address */
  907. dprintk("Socket %u: Unmapped io window %u at %#8.8x, "
  908. "OR = %#8.8x.\n", lsock, io->map, w->br, w->or);
  909. }
  910. /* copy the struct and modify the copy */
  911. s->io_win[io->map] = *io;
  912. s->io_win[io->map].flags &= (MAP_WRPROT
  913. | MAP_16BIT
  914. | MAP_ACTIVE);
  915. dprintk("SetIOMap exit\n");
  916. return 0;
  917. }
  918. static int m8xx_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem)
  919. {
  920. int lsock = container_of(sock, struct socket_info, socket)->slot;
  921. struct socket_info *s = &socket[lsock];
  922. struct pcmcia_win *w;
  923. struct pccard_mem_map *old;
  924. unsigned int reg, winnr;
  925. dprintk( "SetMemMap(%d, %d, %#2.2x, %d ns, "
  926. "%#5.5lx, %#5.5x)\n", lsock, mem->map, mem->flags,
  927. mem->speed, mem->static_start, mem->card_start);
  928. if ((mem->map >= PCMCIA_MEM_WIN_NO)
  929. // || ((mem->s) >= PCMCIA_MEM_WIN_SIZE)
  930. || (mem->card_start >= 0x04000000)
  931. || (mem->static_start & 0xfff) /* 4KByte resolution */
  932. || (mem->card_start & 0xfff))
  933. return -EINVAL;
  934. if((reg = m8xx_get_graycode(PCMCIA_MEM_WIN_SIZE)) == -1) {
  935. printk( "Cannot set size to 0x%08x.\n", PCMCIA_MEM_WIN_SIZE);
  936. return -EINVAL;
  937. }
  938. reg <<= 27;
  939. winnr = (lsock * PCMCIA_MEM_WIN_NO) + mem->map;
  940. /* Setup the window in the pcmcia controller */
  941. w = (void *) &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0;
  942. w += winnr;
  943. reg |= lsock << 2;
  944. reg |= m8xx_get_speed(mem->speed, 0);
  945. if(mem->flags & MAP_ATTRIB)
  946. reg |= M8XX_PCMCIA_POR_ATTRMEM;
  947. if(mem->flags & MAP_WRPROT)
  948. reg |= M8XX_PCMCIA_POR_WRPROT;
  949. if(mem->flags & MAP_16BIT)
  950. reg |= M8XX_PCMCIA_POR_16BIT;
  951. if(mem->flags & MAP_ACTIVE)
  952. reg |= M8XX_PCMCIA_POR_VALID;
  953. out_be32(&w->or, reg);
  954. dprintk("Socket %u: Mapped memory window %u at %#8.8x, "
  955. "OR = %#8.8x.\n", lsock, mem->map, w->br, w->or);
  956. if(mem->flags & MAP_ACTIVE) {
  957. /* get the new base address */
  958. mem->static_start = PCMCIA_MEM_WIN_BASE +
  959. (PCMCIA_MEM_WIN_SIZE * winnr)
  960. + mem->card_start;
  961. }
  962. dprintk("SetMemMap(%d, %d, %#2.2x, %d ns, "
  963. "%#5.5lx, %#5.5x)\n", lsock, mem->map, mem->flags,
  964. mem->speed, mem->static_start, mem->card_start);
  965. /* copy the struct and modify the copy */
  966. old = &s->mem_win[mem->map];
  967. *old = *mem;
  968. old->flags &= (MAP_ATTRIB
  969. | MAP_WRPROT
  970. | MAP_16BIT
  971. | MAP_ACTIVE);
  972. return 0;
  973. }
  974. static int m8xx_sock_init(struct pcmcia_socket *sock)
  975. {
  976. int i;
  977. pccard_io_map io = { 0, 0, 0, 0, 1 };
  978. pccard_mem_map mem = { 0, 0, 0, 0, 0, 0 };
  979. dprintk( "sock_init(%d)\n", s);
  980. m8xx_set_socket(sock, &dead_socket);
  981. for (i = 0; i < PCMCIA_IO_WIN_NO; i++) {
  982. io.map = i;
  983. m8xx_set_io_map(sock, &io);
  984. }
  985. for (i = 0; i < PCMCIA_MEM_WIN_NO; i++) {
  986. mem.map = i;
  987. m8xx_set_mem_map(sock, &mem);
  988. }
  989. return 0;
  990. }
  991. static int m8xx_suspend(struct pcmcia_socket *sock)
  992. {
  993. return m8xx_set_socket(sock, &dead_socket);
  994. }
  995. static struct pccard_operations m8xx_services = {
  996. .init = m8xx_sock_init,
  997. .suspend = m8xx_suspend,
  998. .get_status = m8xx_get_status,
  999. .set_socket = m8xx_set_socket,
  1000. .set_io_map = m8xx_set_io_map,
  1001. .set_mem_map = m8xx_set_mem_map,
  1002. };
  1003. static int __init m8xx_init(void)
  1004. {
  1005. struct pcmcia_win *w;
  1006. unsigned int i,m;
  1007. pcmcia_info("%s\n", version);
  1008. if (driver_register(&m8xx_driver))
  1009. return -1;
  1010. pcmcia_info(PCMCIA_BOARD_MSG " using " PCMCIA_SLOT_MSG
  1011. " with IRQ %u.\n", pcmcia_schlvl);
  1012. /* Configure Status change interrupt */
  1013. if(request_irq(pcmcia_schlvl, m8xx_interrupt, 0,
  1014. "m8xx_pcmcia", NULL)) {
  1015. pcmcia_error("Cannot allocate IRQ %u for SCHLVL!\n",
  1016. pcmcia_schlvl);
  1017. return -1;
  1018. }
  1019. w = (void *) &((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0;
  1020. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr,
  1021. M8XX_PCMCIA_MASK(0)| M8XX_PCMCIA_MASK(1));
  1022. out_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per,
  1023. in_be32(&((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_per) &
  1024. ~(M8XX_PCMCIA_MASK(0)| M8XX_PCMCIA_MASK(1)));
  1025. /* connect interrupt and disable CxOE */
  1026. out_be32(M8XX_PGCRX(0), M8XX_PGCRX_CXOE | (mk_int_int_mask(pcmcia_schlvl) << 16));
  1027. out_be32(M8XX_PGCRX(1), M8XX_PGCRX_CXOE | (mk_int_int_mask(pcmcia_schlvl) << 16));
  1028. /* intialize the fixed memory windows */
  1029. for(i = 0; i < PCMCIA_SOCKETS_NO; i++){
  1030. for(m = 0; m < PCMCIA_MEM_WIN_NO; m++) {
  1031. out_be32(&w->br, PCMCIA_MEM_WIN_BASE +
  1032. (PCMCIA_MEM_WIN_SIZE
  1033. * (m + i * PCMCIA_MEM_WIN_NO)));
  1034. out_be32(&w->or, 0); /* set to not valid */
  1035. w++;
  1036. }
  1037. }
  1038. /* turn off voltage */
  1039. voltage_set(0, 0, 0);
  1040. voltage_set(1, 0, 0);
  1041. /* Enable external hardware */
  1042. hardware_enable(0);
  1043. hardware_enable(1);
  1044. platform_device_register(&m8xx_device);
  1045. for (i = 0 ; i < PCMCIA_SOCKETS_NO; i++) {
  1046. socket[i].slot = i;
  1047. socket[i].socket.owner = THIS_MODULE;
  1048. socket[i].socket.features = SS_CAP_PCCARD | SS_CAP_MEM_ALIGN | SS_CAP_STATIC_MAP;
  1049. socket[i].socket.irq_mask = 0x000;
  1050. socket[i].socket.map_size = 0x1000;
  1051. socket[i].socket.io_offset = 0;
  1052. socket[i].socket.pci_irq = i ? 7 : 9;
  1053. socket[i].socket.ops = &m8xx_services;
  1054. socket[i].socket.resource_ops = &pccard_iodyn_ops;
  1055. socket[i].socket.cb_dev = NULL;
  1056. socket[i].socket.dev.dev = &m8xx_device.dev;
  1057. }
  1058. for (i = 0; i < PCMCIA_SOCKETS_NO; i++)
  1059. pcmcia_register_socket(&socket[i].socket);
  1060. return 0;
  1061. }
  1062. static void __exit m8xx_exit(void)
  1063. {
  1064. int i;
  1065. for (i = 0; i < PCMCIA_SOCKETS_NO; i++)
  1066. pcmcia_unregister_socket(&socket[i].socket);
  1067. m8xx_shutdown();
  1068. platform_device_unregister(&m8xx_device);
  1069. driver_unregister(&m8xx_driver);
  1070. }
  1071. module_init(m8xx_init);
  1072. module_exit(m8xx_exit);