m32r_cfc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. /*
  2. * drivers/pcmcia/m32r_cfc.c
  3. *
  4. * Device driver for the CFC functionality of M32R.
  5. *
  6. * Copyright (c) 2001, 2002, 2003, 2004
  7. * Hiroyuki Kondo, Naoto Sugai, Hayato Fujiwara
  8. */
  9. #include <linux/module.h>
  10. #include <linux/moduleparam.h>
  11. #include <linux/init.h>
  12. #include <linux/config.h>
  13. #include <linux/types.h>
  14. #include <linux/fcntl.h>
  15. #include <linux/string.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/timer.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include <linux/ioport.h>
  22. #include <linux/delay.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/bitops.h>
  27. #include <asm/irq.h>
  28. #include <asm/io.h>
  29. #include <asm/system.h>
  30. #include <pcmcia/cs_types.h>
  31. #include <pcmcia/ss.h>
  32. #include <pcmcia/cs.h>
  33. #undef MAX_IO_WIN /* FIXME */
  34. #define MAX_IO_WIN 1
  35. #undef MAX_WIN /* FIXME */
  36. #define MAX_WIN 1
  37. #include "m32r_cfc.h"
  38. #ifdef DEBUG
  39. static int m32r_cfc_debug;
  40. module_param(m32r_cfc_debug, int, 0644);
  41. #define debug(lvl, fmt, arg...) do { \
  42. if (m32r_cfc_debug > (lvl)) \
  43. printk(KERN_DEBUG "m32r_cfc: " fmt , ## arg); \
  44. } while (0)
  45. #else
  46. #define debug(n, args...) do { } while (0)
  47. #endif
  48. /* Poll status interval -- 0 means default to interrupt */
  49. static int poll_interval = 0;
  50. typedef enum pcc_space { as_none = 0, as_comm, as_attr, as_io } pcc_as_t;
  51. typedef struct pcc_socket {
  52. u_short type, flags;
  53. struct pcmcia_socket socket;
  54. unsigned int number;
  55. kio_addr_t ioaddr;
  56. u_long mapaddr;
  57. u_long base; /* PCC register base */
  58. u_char cs_irq1, cs_irq2, intr;
  59. pccard_io_map io_map[MAX_IO_WIN];
  60. pccard_mem_map mem_map[MAX_WIN];
  61. u_char io_win;
  62. u_char mem_win;
  63. pcc_as_t current_space;
  64. u_char last_iodbex;
  65. #ifdef CONFIG_PROC_FS
  66. struct proc_dir_entry *proc;
  67. #endif
  68. } pcc_socket_t;
  69. static int pcc_sockets = 0;
  70. static pcc_socket_t socket[M32R_MAX_PCC] = {
  71. { 0, }, /* ... */
  72. };
  73. /*====================================================================*/
  74. static unsigned int pcc_get(u_short, unsigned int);
  75. static void pcc_set(u_short, unsigned int , unsigned int );
  76. static DEFINE_SPINLOCK(pcc_lock);
  77. #if !defined(CONFIG_PLAT_USRV)
  78. static inline u_long pcc_port2addr(unsigned long port, int size) {
  79. u_long addr = 0;
  80. u_long odd;
  81. if (size == 1) { /* byte access */
  82. odd = (port&1) << 11;
  83. port -= port & 1;
  84. addr = CFC_IO_MAPBASE_BYTE - CFC_IOPORT_BASE + odd + port;
  85. } else if (size == 2)
  86. addr = CFC_IO_MAPBASE_WORD - CFC_IOPORT_BASE + port;
  87. return addr;
  88. }
  89. #else /* CONFIG_PLAT_USRV */
  90. static inline u_long pcc_port2addr(unsigned long port, int size) {
  91. u_long odd;
  92. u_long addr = ((port - CFC_IOPORT_BASE) & 0xf000) << 8;
  93. if (size == 1) { /* byte access */
  94. odd = port & 1;
  95. port -= odd;
  96. odd <<= 11;
  97. addr = (addr | CFC_IO_MAPBASE_BYTE) + odd + (port & 0xfff);
  98. } else if (size == 2) /* word access */
  99. addr = (addr | CFC_IO_MAPBASE_WORD) + (port & 0xfff);
  100. return addr;
  101. }
  102. #endif /* CONFIG_PLAT_USRV */
  103. void pcc_ioread_byte(int sock, unsigned long port, void *buf, size_t size,
  104. size_t nmemb, int flag)
  105. {
  106. u_long addr;
  107. unsigned char *bp = (unsigned char *)buf;
  108. unsigned long flags;
  109. debug(3, "m32r_cfc: pcc_ioread_byte: sock=%d, port=%#lx, buf=%p, "
  110. "size=%u, nmemb=%d, flag=%d\n",
  111. sock, port, buf, size, nmemb, flag);
  112. addr = pcc_port2addr(port, 1);
  113. if (!addr) {
  114. printk("m32r_cfc:ioread_byte null port :%#lx\n",port);
  115. return;
  116. }
  117. debug(3, "m32r_cfc: pcc_ioread_byte: addr=%#lx\n", addr);
  118. spin_lock_irqsave(&pcc_lock, flags);
  119. /* read Byte */
  120. while (nmemb--)
  121. *bp++ = readb(addr);
  122. spin_unlock_irqrestore(&pcc_lock, flags);
  123. }
  124. void pcc_ioread_word(int sock, unsigned long port, void *buf, size_t size,
  125. size_t nmemb, int flag)
  126. {
  127. u_long addr;
  128. unsigned short *bp = (unsigned short *)buf;
  129. unsigned long flags;
  130. debug(3, "m32r_cfc: pcc_ioread_word: sock=%d, port=%#lx, "
  131. "buf=%p, size=%u, nmemb=%d, flag=%d\n",
  132. sock, port, buf, size, nmemb, flag);
  133. if (size != 2)
  134. printk("m32r_cfc: ioread_word :illigal size %u : %#lx\n", size,
  135. port);
  136. if (size == 9)
  137. printk("m32r_cfc: ioread_word :insw \n");
  138. addr = pcc_port2addr(port, 2);
  139. if (!addr) {
  140. printk("m32r_cfc:ioread_word null port :%#lx\n",port);
  141. return;
  142. }
  143. debug(3, "m32r_cfc: pcc_ioread_word: addr=%#lx\n", addr);
  144. spin_lock_irqsave(&pcc_lock, flags);
  145. /* read Word */
  146. while (nmemb--)
  147. *bp++ = readw(addr);
  148. spin_unlock_irqrestore(&pcc_lock, flags);
  149. }
  150. void pcc_iowrite_byte(int sock, unsigned long port, void *buf, size_t size,
  151. size_t nmemb, int flag)
  152. {
  153. u_long addr;
  154. unsigned char *bp = (unsigned char *)buf;
  155. unsigned long flags;
  156. debug(3, "m32r_cfc: pcc_iowrite_byte: sock=%d, port=%#lx, "
  157. "buf=%p, size=%u, nmemb=%d, flag=%d\n",
  158. sock, port, buf, size, nmemb, flag);
  159. /* write Byte */
  160. addr = pcc_port2addr(port, 1);
  161. if (!addr) {
  162. printk("m32r_cfc:iowrite_byte null port:%#lx\n",port);
  163. return;
  164. }
  165. debug(3, "m32r_cfc: pcc_iowrite_byte: addr=%#lx\n", addr);
  166. spin_lock_irqsave(&pcc_lock, flags);
  167. while (nmemb--)
  168. writeb(*bp++, addr);
  169. spin_unlock_irqrestore(&pcc_lock, flags);
  170. }
  171. void pcc_iowrite_word(int sock, unsigned long port, void *buf, size_t size,
  172. size_t nmemb, int flag)
  173. {
  174. u_long addr;
  175. unsigned short *bp = (unsigned short *)buf;
  176. unsigned long flags;
  177. debug(3, "m32r_cfc: pcc_iowrite_word: sock=%d, port=%#lx, "
  178. "buf=%p, size=%u, nmemb=%d, flag=%d\n",
  179. sock, port, buf, size, nmemb, flag);
  180. if(size != 2)
  181. printk("m32r_cfc: iowrite_word :illigal size %u : %#lx\n",
  182. size, port);
  183. if(size == 9)
  184. printk("m32r_cfc: iowrite_word :outsw \n");
  185. addr = pcc_port2addr(port, 2);
  186. if (!addr) {
  187. printk("m32r_cfc:iowrite_word null addr :%#lx\n",port);
  188. return;
  189. }
  190. #if 1
  191. if (addr & 1) {
  192. printk("m32r_cfc:iowrite_word port addr (%#lx):%#lx\n", port,
  193. addr);
  194. return;
  195. }
  196. #endif
  197. debug(3, "m32r_cfc: pcc_iowrite_word: addr=%#lx\n", addr);
  198. spin_lock_irqsave(&pcc_lock, flags);
  199. while (nmemb--)
  200. writew(*bp++, addr);
  201. spin_unlock_irqrestore(&pcc_lock, flags);
  202. }
  203. /*====================================================================*/
  204. #define IS_REGISTERED 0x2000
  205. #define IS_ALIVE 0x8000
  206. typedef struct pcc_t {
  207. char *name;
  208. u_short flags;
  209. } pcc_t;
  210. static pcc_t pcc[] = {
  211. #if !defined(CONFIG_PLAT_USRV)
  212. { "m32r_cfc", 0 }, { "", 0 },
  213. #else /* CONFIG_PLAT_USRV */
  214. { "m32r_cfc", 0 }, { "m32r_cfc", 0 }, { "m32r_cfc", 0 },
  215. { "m32r_cfc", 0 }, { "m32r_cfc", 0 }, { "", 0 },
  216. #endif /* CONFIG_PLAT_USRV */
  217. };
  218. static irqreturn_t pcc_interrupt(int, void *, struct pt_regs *);
  219. /*====================================================================*/
  220. static struct timer_list poll_timer;
  221. static unsigned int pcc_get(u_short sock, unsigned int reg)
  222. {
  223. unsigned int val = inw(reg);
  224. debug(3, "m32r_cfc: pcc_get: reg(0x%08x)=0x%04x\n", reg, val);
  225. return val;
  226. }
  227. static void pcc_set(u_short sock, unsigned int reg, unsigned int data)
  228. {
  229. outw(data, reg);
  230. debug(3, "m32r_cfc: pcc_set: reg(0x%08x)=0x%04x\n", reg, data);
  231. }
  232. /*======================================================================
  233. See if a card is present, powered up, in IO mode, and already
  234. bound to a (non PC Card) Linux driver. We leave these alone.
  235. We make an exception for cards that seem to be serial devices.
  236. ======================================================================*/
  237. static int __init is_alive(u_short sock)
  238. {
  239. unsigned int stat;
  240. debug(3, "m32r_cfc: is_alive:\n");
  241. printk("CF: ");
  242. stat = pcc_get(sock, (unsigned int)PLD_CFSTS);
  243. if (!stat)
  244. printk("No ");
  245. printk("Card is detected at socket %d : stat = 0x%08x\n", sock, stat);
  246. debug(3, "m32r_cfc: is_alive: sock stat is 0x%04x\n", stat);
  247. return 0;
  248. }
  249. static void add_pcc_socket(ulong base, int irq, ulong mapaddr, kio_addr_t ioaddr)
  250. {
  251. pcc_socket_t *t = &socket[pcc_sockets];
  252. debug(3, "m32r_cfc: add_pcc_socket: base=%#lx, irq=%d, "
  253. "mapaddr=%#lx, ioaddr=%08x\n",
  254. base, irq, mapaddr, ioaddr);
  255. /* add sockets */
  256. t->ioaddr = ioaddr;
  257. t->mapaddr = mapaddr;
  258. #if !defined(CONFIG_PLAT_USRV)
  259. t->base = 0;
  260. t->flags = 0;
  261. t->cs_irq1 = irq; // insert irq
  262. t->cs_irq2 = irq + 1; // eject irq
  263. #else /* CONFIG_PLAT_USRV */
  264. t->base = base;
  265. t->flags = 0;
  266. t->cs_irq1 = 0; // insert irq
  267. t->cs_irq2 = 0; // eject irq
  268. #endif /* CONFIG_PLAT_USRV */
  269. if (is_alive(pcc_sockets))
  270. t->flags |= IS_ALIVE;
  271. /* add pcc */
  272. #if !defined(CONFIG_PLAT_USRV)
  273. request_region((unsigned int)PLD_CFRSTCR, 0x20, "m32r_cfc");
  274. #else /* CONFIG_PLAT_USRV */
  275. {
  276. unsigned int reg_base;
  277. reg_base = (unsigned int)PLD_CFRSTCR;
  278. reg_base |= pcc_sockets << 8;
  279. request_region(reg_base, 0x20, "m32r_cfc");
  280. }
  281. #endif /* CONFIG_PLAT_USRV */
  282. printk(KERN_INFO " %s ", pcc[pcc_sockets].name);
  283. printk("pcc at 0x%08lx\n", t->base);
  284. /* Update socket interrupt information, capabilities */
  285. t->socket.features |= (SS_CAP_PCCARD | SS_CAP_STATIC_MAP);
  286. t->socket.map_size = M32R_PCC_MAPSIZE;
  287. t->socket.io_offset = ioaddr; /* use for io access offset */
  288. t->socket.irq_mask = 0;
  289. #if !defined(CONFIG_PLAT_USRV)
  290. t->socket.pci_irq = PLD_IRQ_CFIREQ ; /* card interrupt */
  291. #else /* CONFIG_PLAT_USRV */
  292. t->socket.pci_irq = PLD_IRQ_CF0 + pcc_sockets;
  293. #endif /* CONFIG_PLAT_USRV */
  294. #ifndef CONFIG_PLAT_USRV
  295. /* insert interrupt */
  296. request_irq(irq, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt);
  297. #ifndef CONFIG_PLAT_MAPPI3
  298. /* eject interrupt */
  299. request_irq(irq+1, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt);
  300. #endif
  301. debug(3, "m32r_cfc: enable CFMSK, RDYSEL\n");
  302. pcc_set(pcc_sockets, (unsigned int)PLD_CFIMASK, 0x01);
  303. #endif /* CONFIG_PLAT_USRV */
  304. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
  305. pcc_set(pcc_sockets, (unsigned int)PLD_CFCR1, 0x0200);
  306. #endif
  307. pcc_sockets++;
  308. return;
  309. }
  310. /*====================================================================*/
  311. static irqreturn_t pcc_interrupt(int irq, void *dev, struct pt_regs *regs)
  312. {
  313. int i;
  314. u_int events = 0;
  315. int handled = 0;
  316. debug(3, "m32r_cfc: pcc_interrupt: irq=%d, dev=%p, regs=%p\n",
  317. irq, dev, regs);
  318. for (i = 0; i < pcc_sockets; i++) {
  319. if (socket[i].cs_irq1 != irq && socket[i].cs_irq2 != irq)
  320. continue;
  321. handled = 1;
  322. debug(3, "m32r_cfc: pcc_interrupt: socket %d irq 0x%02x ",
  323. i, irq);
  324. events |= SS_DETECT; /* insert or eject */
  325. if (events)
  326. pcmcia_parse_events(&socket[i].socket, events);
  327. }
  328. debug(3, "m32r_cfc: pcc_interrupt: done\n");
  329. return IRQ_RETVAL(handled);
  330. } /* pcc_interrupt */
  331. static void pcc_interrupt_wrapper(u_long data)
  332. {
  333. debug(3, "m32r_cfc: pcc_interrupt_wrapper:\n");
  334. pcc_interrupt(0, NULL, NULL);
  335. init_timer(&poll_timer);
  336. poll_timer.expires = jiffies + poll_interval;
  337. add_timer(&poll_timer);
  338. }
  339. /*====================================================================*/
  340. static int _pcc_get_status(u_short sock, u_int *value)
  341. {
  342. u_int status;
  343. debug(3, "m32r_cfc: _pcc_get_status:\n");
  344. status = pcc_get(sock, (unsigned int)PLD_CFSTS);
  345. *value = (status) ? SS_DETECT : 0;
  346. debug(3, "m32r_cfc: _pcc_get_status: status=0x%08x\n", status);
  347. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
  348. if ( status ) {
  349. /* enable CF power */
  350. status = inw((unsigned int)PLD_CPCR);
  351. if (!(status & PLD_CPCR_CF)) {
  352. debug(3, "m32r_cfc: _pcc_get_status: "
  353. "power on (CPCR=0x%08x)\n", status);
  354. status |= PLD_CPCR_CF;
  355. outw(status, (unsigned int)PLD_CPCR);
  356. udelay(100);
  357. }
  358. *value |= SS_POWERON;
  359. pcc_set(sock, (unsigned int)PLD_CFBUFCR,0);/* enable buffer */
  360. udelay(100);
  361. *value |= SS_READY; /* always ready */
  362. *value |= SS_3VCARD;
  363. } else {
  364. /* disable CF power */
  365. status = inw((unsigned int)PLD_CPCR);
  366. status &= ~PLD_CPCR_CF;
  367. outw(status, (unsigned int)PLD_CPCR);
  368. udelay(100);
  369. debug(3, "m32r_cfc: _pcc_get_status: "
  370. "power off (CPCR=0x%08x)\n", status);
  371. }
  372. #elif defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
  373. if ( status ) {
  374. status = pcc_get(sock, (unsigned int)PLD_CPCR);
  375. if (status == 0) { /* power off */
  376. pcc_set(sock, (unsigned int)PLD_CPCR, 1);
  377. pcc_set(sock, (unsigned int)PLD_CFBUFCR,0); /* force buffer off for ZA-36 */
  378. udelay(50);
  379. }
  380. *value |= SS_POWERON;
  381. pcc_set(sock, (unsigned int)PLD_CFBUFCR,0);
  382. udelay(50);
  383. pcc_set(sock, (unsigned int)PLD_CFRSTCR, 0x0101);
  384. udelay(25); /* for IDE reset */
  385. pcc_set(sock, (unsigned int)PLD_CFRSTCR, 0x0100);
  386. mdelay(2); /* for IDE reset */
  387. *value |= SS_READY;
  388. *value |= SS_3VCARD;
  389. } else {
  390. /* disable CF power */
  391. pcc_set(sock, (unsigned int)PLD_CPCR, 0);
  392. udelay(100);
  393. debug(3, "m32r_cfc: _pcc_get_status: "
  394. "power off (CPCR=0x%08x)\n", status);
  395. }
  396. #else
  397. #error no platform configuration
  398. #endif
  399. debug(3, "m32r_cfc: _pcc_get_status: GetStatus(%d) = %#4.4x\n",
  400. sock, *value);
  401. return 0;
  402. } /* _get_status */
  403. /*====================================================================*/
  404. static int _pcc_get_socket(u_short sock, socket_state_t *state)
  405. {
  406. // pcc_socket_t *t = &socket[sock];
  407. state->flags = 0;
  408. state->csc_mask = SS_DETECT;
  409. state->csc_mask |= SS_READY;
  410. state->io_irq = 0;
  411. state->Vcc = 33; /* 3.3V fixed */
  412. state->Vpp = 33;
  413. debug(3, "m32r_cfc: GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, "
  414. "io_irq %d, csc_mask %#2.2x\n", sock, state->flags,
  415. state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
  416. return 0;
  417. } /* _get_socket */
  418. /*====================================================================*/
  419. static int _pcc_set_socket(u_short sock, socket_state_t *state)
  420. {
  421. debug(3, "m32r_cfc: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
  422. "io_irq %d, csc_mask %#2.2x)\n", sock, state->flags,
  423. state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
  424. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
  425. if (state->Vcc) {
  426. if ((state->Vcc != 50) && (state->Vcc != 33))
  427. return -EINVAL;
  428. /* accept 5V and 3.3V */
  429. }
  430. #endif
  431. if (state->flags & SS_RESET) {
  432. debug(3, ":RESET\n");
  433. pcc_set(sock,(unsigned int)PLD_CFRSTCR,0x101);
  434. }else{
  435. pcc_set(sock,(unsigned int)PLD_CFRSTCR,0x100);
  436. }
  437. if (state->flags & SS_OUTPUT_ENA){
  438. debug(3, ":OUTPUT_ENA\n");
  439. /* bit clear */
  440. pcc_set(sock,(unsigned int)PLD_CFBUFCR,0);
  441. } else {
  442. pcc_set(sock,(unsigned int)PLD_CFBUFCR,1);
  443. }
  444. #ifdef DEBUG
  445. if(state->flags & SS_IOCARD){
  446. debug(3, ":IOCARD");
  447. }
  448. if (state->flags & SS_PWR_AUTO) {
  449. debug(3, ":PWR_AUTO");
  450. }
  451. if (state->csc_mask & SS_DETECT)
  452. debug(3, ":csc-SS_DETECT");
  453. if (state->flags & SS_IOCARD) {
  454. if (state->csc_mask & SS_STSCHG)
  455. debug(3, ":STSCHG");
  456. } else {
  457. if (state->csc_mask & SS_BATDEAD)
  458. debug(3, ":BATDEAD");
  459. if (state->csc_mask & SS_BATWARN)
  460. debug(3, ":BATWARN");
  461. if (state->csc_mask & SS_READY)
  462. debug(3, ":READY");
  463. }
  464. debug(3, "\n");
  465. #endif
  466. return 0;
  467. } /* _set_socket */
  468. /*====================================================================*/
  469. static int _pcc_set_io_map(u_short sock, struct pccard_io_map *io)
  470. {
  471. u_char map;
  472. debug(3, "m32r_cfc: SetIOMap(%d, %d, %#2.2x, %d ns, "
  473. "%#lx-%#lx)\n", sock, io->map, io->flags,
  474. io->speed, io->start, io->stop);
  475. map = io->map;
  476. return 0;
  477. } /* _set_io_map */
  478. /*====================================================================*/
  479. static int _pcc_set_mem_map(u_short sock, struct pccard_mem_map *mem)
  480. {
  481. u_char map = mem->map;
  482. u_long addr;
  483. pcc_socket_t *t = &socket[sock];
  484. debug(3, "m32r_cfc: SetMemMap(%d, %d, %#2.2x, %d ns, "
  485. "%#lx, %#x)\n", sock, map, mem->flags,
  486. mem->speed, mem->static_start, mem->card_start);
  487. /*
  488. * sanity check
  489. */
  490. if ((map > MAX_WIN) || (mem->card_start > 0x3ffffff)){
  491. return -EINVAL;
  492. }
  493. /*
  494. * de-activate
  495. */
  496. if ((mem->flags & MAP_ACTIVE) == 0) {
  497. t->current_space = as_none;
  498. return 0;
  499. }
  500. /*
  501. * Set mode
  502. */
  503. if (mem->flags & MAP_ATTRIB) {
  504. t->current_space = as_attr;
  505. } else {
  506. t->current_space = as_comm;
  507. }
  508. /*
  509. * Set address
  510. */
  511. addr = t->mapaddr + (mem->card_start & M32R_PCC_MAPMASK);
  512. mem->static_start = addr + mem->card_start;
  513. return 0;
  514. } /* _set_mem_map */
  515. #if 0 /* driver model ordering issue */
  516. /*======================================================================
  517. Routines for accessing socket information and register dumps via
  518. /proc/bus/pccard/...
  519. ======================================================================*/
  520. static ssize_t show_info(struct class_device *class_dev, char *buf)
  521. {
  522. pcc_socket_t *s = container_of(class_dev, struct pcc_socket,
  523. socket.dev);
  524. return sprintf(buf, "type: %s\nbase addr: 0x%08lx\n",
  525. pcc[s->type].name, s->base);
  526. }
  527. static ssize_t show_exca(struct class_device *class_dev, char *buf)
  528. {
  529. /* FIXME */
  530. return 0;
  531. }
  532. static CLASS_DEVICE_ATTR(info, S_IRUGO, show_info, NULL);
  533. static CLASS_DEVICE_ATTR(exca, S_IRUGO, show_exca, NULL);
  534. #endif
  535. /*====================================================================*/
  536. /* this is horribly ugly... proper locking needs to be done here at
  537. * some time... */
  538. #define LOCKED(x) do { \
  539. int retval; \
  540. unsigned long flags; \
  541. spin_lock_irqsave(&pcc_lock, flags); \
  542. retval = x; \
  543. spin_unlock_irqrestore(&pcc_lock, flags); \
  544. return retval; \
  545. } while (0)
  546. static int pcc_get_status(struct pcmcia_socket *s, u_int *value)
  547. {
  548. unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
  549. if (socket[sock].flags & IS_ALIVE) {
  550. debug(3, "m32r_cfc: pcc_get_status: sock(%d) -EINVAL\n", sock);
  551. *value = 0;
  552. return -EINVAL;
  553. }
  554. debug(3, "m32r_cfc: pcc_get_status: sock(%d)\n", sock);
  555. LOCKED(_pcc_get_status(sock, value));
  556. }
  557. static int pcc_get_socket(struct pcmcia_socket *s, socket_state_t *state)
  558. {
  559. unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
  560. if (socket[sock].flags & IS_ALIVE) {
  561. debug(3, "m32r_cfc: pcc_get_socket: sock(%d) -EINVAL\n", sock);
  562. return -EINVAL;
  563. }
  564. debug(3, "m32r_cfc: pcc_get_socket: sock(%d)\n", sock);
  565. LOCKED(_pcc_get_socket(sock, state));
  566. }
  567. static int pcc_set_socket(struct pcmcia_socket *s, socket_state_t *state)
  568. {
  569. unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
  570. if (socket[sock].flags & IS_ALIVE) {
  571. debug(3, "m32r_cfc: pcc_set_socket: sock(%d) -EINVAL\n", sock);
  572. return -EINVAL;
  573. }
  574. debug(3, "m32r_cfc: pcc_set_socket: sock(%d)\n", sock);
  575. LOCKED(_pcc_set_socket(sock, state));
  576. }
  577. static int pcc_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
  578. {
  579. unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
  580. if (socket[sock].flags & IS_ALIVE) {
  581. debug(3, "m32r_cfc: pcc_set_io_map: sock(%d) -EINVAL\n", sock);
  582. return -EINVAL;
  583. }
  584. debug(3, "m32r_cfc: pcc_set_io_map: sock(%d)\n", sock);
  585. LOCKED(_pcc_set_io_map(sock, io));
  586. }
  587. static int pcc_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *mem)
  588. {
  589. unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
  590. if (socket[sock].flags & IS_ALIVE) {
  591. debug(3, "m32r_cfc: pcc_set_mem_map: sock(%d) -EINVAL\n", sock);
  592. return -EINVAL;
  593. }
  594. debug(3, "m32r_cfc: pcc_set_mem_map: sock(%d)\n", sock);
  595. LOCKED(_pcc_set_mem_map(sock, mem));
  596. }
  597. static int pcc_init(struct pcmcia_socket *s)
  598. {
  599. debug(3, "m32r_cfc: pcc_init()\n");
  600. return 0;
  601. }
  602. static struct pccard_operations pcc_operations = {
  603. .init = pcc_init,
  604. .get_status = pcc_get_status,
  605. .get_socket = pcc_get_socket,
  606. .set_socket = pcc_set_socket,
  607. .set_io_map = pcc_set_io_map,
  608. .set_mem_map = pcc_set_mem_map,
  609. };
  610. /*====================================================================*/
  611. static struct device_driver pcc_driver = {
  612. .name = "cfc",
  613. .bus = &platform_bus_type,
  614. .suspend = pcmcia_socket_dev_suspend,
  615. .resume = pcmcia_socket_dev_resume,
  616. };
  617. static struct platform_device pcc_device = {
  618. .name = "cfc",
  619. .id = 0,
  620. };
  621. /*====================================================================*/
  622. static int __init init_m32r_pcc(void)
  623. {
  624. int i, ret;
  625. ret = driver_register(&pcc_driver);
  626. if (ret)
  627. return ret;
  628. ret = platform_device_register(&pcc_device);
  629. if (ret){
  630. driver_unregister(&pcc_driver);
  631. return ret;
  632. }
  633. #if defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
  634. pcc_set(0, (unsigned int)PLD_CFCR0, 0x0f0f);
  635. pcc_set(0, (unsigned int)PLD_CFCR1, 0x0200);
  636. #endif
  637. pcc_sockets = 0;
  638. #if !defined(CONFIG_PLAT_USRV)
  639. add_pcc_socket(M32R_PCC0_BASE, PLD_IRQ_CFC_INSERT, CFC_ATTR_MAPBASE,
  640. CFC_IOPORT_BASE);
  641. #else /* CONFIG_PLAT_USRV */
  642. {
  643. ulong base, mapaddr;
  644. kio_addr_t ioaddr;
  645. for (i = 0 ; i < M32R_MAX_PCC ; i++) {
  646. base = (ulong)PLD_CFRSTCR;
  647. base = base | (i << 8);
  648. ioaddr = (i + 1) << 12;
  649. mapaddr = CFC_ATTR_MAPBASE | (i << 20);
  650. add_pcc_socket(base, 0, mapaddr, ioaddr);
  651. }
  652. }
  653. #endif /* CONFIG_PLAT_USRV */
  654. if (pcc_sockets == 0) {
  655. printk("socket is not found.\n");
  656. platform_device_unregister(&pcc_device);
  657. driver_unregister(&pcc_driver);
  658. return -ENODEV;
  659. }
  660. /* Set up interrupt handler(s) */
  661. for (i = 0 ; i < pcc_sockets ; i++) {
  662. socket[i].socket.dev.dev = &pcc_device.dev;
  663. socket[i].socket.ops = &pcc_operations;
  664. socket[i].socket.resource_ops = &pccard_nonstatic_ops;
  665. socket[i].socket.owner = THIS_MODULE;
  666. socket[i].number = i;
  667. ret = pcmcia_register_socket(&socket[i].socket);
  668. if (!ret)
  669. socket[i].flags |= IS_REGISTERED;
  670. #if 0 /* driver model ordering issue */
  671. class_device_create_file(&socket[i].socket.dev,
  672. &class_device_attr_info);
  673. class_device_create_file(&socket[i].socket.dev,
  674. &class_device_attr_exca);
  675. #endif
  676. }
  677. /* Finally, schedule a polling interrupt */
  678. if (poll_interval != 0) {
  679. poll_timer.function = pcc_interrupt_wrapper;
  680. poll_timer.data = 0;
  681. init_timer(&poll_timer);
  682. poll_timer.expires = jiffies + poll_interval;
  683. add_timer(&poll_timer);
  684. }
  685. return 0;
  686. } /* init_m32r_pcc */
  687. static void __exit exit_m32r_pcc(void)
  688. {
  689. int i;
  690. for (i = 0; i < pcc_sockets; i++)
  691. if (socket[i].flags & IS_REGISTERED)
  692. pcmcia_unregister_socket(&socket[i].socket);
  693. platform_device_unregister(&pcc_device);
  694. if (poll_interval != 0)
  695. del_timer_sync(&poll_timer);
  696. driver_unregister(&pcc_driver);
  697. } /* exit_m32r_pcc */
  698. module_init(init_m32r_pcc);
  699. module_exit(exit_m32r_pcc);
  700. MODULE_LICENSE("Dual MPL/GPL");
  701. /*====================================================================*/