m32r_cfc.c 20 KB

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