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