m8xx_pcmcia.c 32 KB

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