m32r_cfc.c 20 KB

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