m8xx_pcmcia.c 32 KB

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