m8xx_pcmcia.c 32 KB

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