m8xx_pcmcia.c 32 KB

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