10 #include <linux/module.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>
24 #include <linux/bitops.h>
38 static int poll_interval = 0;
61 static int pcc_sockets = 0;
68 static unsigned int pcc_get(
u_short,
unsigned int);
69 static void pcc_set(
u_short,
unsigned int ,
unsigned int );
73 #if !defined(CONFIG_PLAT_USRV)
88 static inline u_long pcc_port2addr(
unsigned long port,
int size) {
105 size_t nmemb,
int flag)
108 unsigned char *bp = (
unsigned char *)buf;
111 pr_debug(
"m32r_cfc: pcc_ioread_byte: sock=%d, port=%#lx, buf=%p, "
112 "size=%u, nmemb=%d, flag=%d\n",
113 sock, port, buf, size, nmemb, flag);
115 addr = pcc_port2addr(port, 1);
117 printk(
"m32r_cfc:ioread_byte null port :%#lx\n",port);
120 pr_debug(
"m32r_cfc: pcc_ioread_byte: addr=%#lx\n", addr);
126 spin_unlock_irqrestore(&pcc_lock, flags);
130 size_t nmemb,
int flag)
133 unsigned short *bp = (
unsigned short *)buf;
136 pr_debug(
"m32r_cfc: pcc_ioread_word: sock=%d, port=%#lx, "
137 "buf=%p, size=%u, nmemb=%d, flag=%d\n",
138 sock, port, buf, size, nmemb, flag);
141 printk(
"m32r_cfc: ioread_word :illigal size %u : %#lx\n", size,
144 printk(
"m32r_cfc: ioread_word :insw \n");
146 addr = pcc_port2addr(port, 2);
148 printk(
"m32r_cfc:ioread_word null port :%#lx\n",port);
151 pr_debug(
"m32r_cfc: pcc_ioread_word: addr=%#lx\n", addr);
157 spin_unlock_irqrestore(&pcc_lock, flags);
161 size_t nmemb,
int flag)
164 unsigned char *bp = (
unsigned char *)buf;
167 pr_debug(
"m32r_cfc: pcc_iowrite_byte: sock=%d, port=%#lx, "
168 "buf=%p, size=%u, nmemb=%d, flag=%d\n",
169 sock, port, buf, size, nmemb, flag);
172 addr = pcc_port2addr(port, 1);
174 printk(
"m32r_cfc:iowrite_byte null port:%#lx\n",port);
177 pr_debug(
"m32r_cfc: pcc_iowrite_byte: addr=%#lx\n", addr);
182 spin_unlock_irqrestore(&pcc_lock, flags);
186 size_t nmemb,
int flag)
189 unsigned short *bp = (
unsigned short *)buf;
192 pr_debug(
"m32r_cfc: pcc_iowrite_word: sock=%d, port=%#lx, "
193 "buf=%p, size=%u, nmemb=%d, flag=%d\n",
194 sock, port, buf, size, nmemb, flag);
197 printk(
"m32r_cfc: iowrite_word :illigal size %u : %#lx\n",
200 printk(
"m32r_cfc: iowrite_word :outsw \n");
202 addr = pcc_port2addr(port, 2);
204 printk(
"m32r_cfc:iowrite_word null addr :%#lx\n",port);
209 printk(
"m32r_cfc:iowrite_word port addr (%#lx):%#lx\n", port,
214 pr_debug(
"m32r_cfc: pcc_iowrite_word: addr=%#lx\n", addr);
219 spin_unlock_irqrestore(&pcc_lock, flags);
224 #define IS_REGISTERED 0x2000
225 #define IS_ALIVE 0x8000
232 static pcc_t pcc[] = {
233 #if !defined(CONFIG_PLAT_USRV)
234 {
"m32r_cfc", 0 }, {
"", 0 },
236 {
"m32r_cfc", 0 }, {
"m32r_cfc", 0 }, {
"m32r_cfc", 0 },
237 {
"m32r_cfc", 0 }, {
"m32r_cfc", 0 }, {
"", 0 },
249 unsigned int val =
inw(reg);
250 pr_debug(
"m32r_cfc: pcc_get: reg(0x%08x)=0x%04x\n", reg, val);
258 pr_debug(
"m32r_cfc: pcc_set: reg(0x%08x)=0x%04x\n", reg, data);
277 stat = pcc_get(sock, (
unsigned int)
PLD_CFSTS);
280 printk(
"Card is detected at socket %d : stat = 0x%08x\n", sock, stat);
281 pr_debug(
"m32r_cfc: is_alive: sock stat is 0x%04x\n", stat);
291 pr_debug(
"m32r_cfc: add_pcc_socket: base=%#lx, irq=%d, "
292 "mapaddr=%#lx, ioaddr=%08x\n",
293 base, irq, mapaddr, ioaddr);
298 #if !defined(CONFIG_PLAT_USRV)
310 if (is_alive(pcc_sockets))
314 #if !defined(CONFIG_PLAT_USRV)
318 unsigned int reg_base;
321 reg_base |= pcc_sockets << 8;
331 t->
socket.io_offset = ioaddr;
333 #if !defined(CONFIG_PLAT_USRV)
336 t->
socket.pci_irq = PLD_IRQ_CF0 + pcc_sockets;
339 #ifndef CONFIG_PLAT_USRV
341 request_irq(irq, pcc_interrupt, 0,
"m32r_cfc", pcc_interrupt);
342 #ifndef CONFIG_PLAT_MAPPI3
344 request_irq(irq+1, pcc_interrupt, 0,
"m32r_cfc", pcc_interrupt);
346 pr_debug(
"m32r_cfc: enable CFMSK, RDYSEL\n");
347 pcc_set(pcc_sockets, (
unsigned int)
PLD_CFIMASK, 0x01);
349 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
350 pcc_set(pcc_sockets, (
unsigned int)
PLD_CFCR1, 0x0200);
366 pr_debug(
"m32r_cfc: pcc_interrupt: irq=%d, dev=%p\n", irq, dev);
367 for (i = 0; i < pcc_sockets; i++) {
368 if (socket[i].cs_irq1 != irq && socket[i].cs_irq2 != irq)
372 pr_debug(
"m32r_cfc: pcc_interrupt: socket %d irq 0x%02x ",
378 pr_debug(
"m32r_cfc: pcc_interrupt: done\n");
383 static void pcc_interrupt_wrapper(
u_long data)
385 pr_debug(
"m32r_cfc: pcc_interrupt_wrapper:\n");
386 pcc_interrupt(0,
NULL);
388 poll_timer.expires =
jiffies + poll_interval;
398 pr_debug(
"m32r_cfc: _pcc_get_status:\n");
399 status = pcc_get(sock, (
unsigned int)
PLD_CFSTS);
401 pr_debug(
"m32r_cfc: _pcc_get_status: status=0x%08x\n", status);
403 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
408 pr_debug(
"m32r_cfc: _pcc_get_status: "
409 "power on (CPCR=0x%08x)\n", status);
424 status &= ~PLD_CPCR_CF;
427 pr_debug(
"m32r_cfc: _pcc_get_status: "
428 "power off (CPCR=0x%08x)\n", status);
430 #elif defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
432 status = pcc_get(sock, (
unsigned int)
PLD_CPCR);
434 pcc_set(sock, (
unsigned int)
PLD_CPCR, 1);
451 pcc_set(sock, (
unsigned int)
PLD_CPCR, 0);
453 pr_debug(
"m32r_cfc: _pcc_get_status: "
454 "power off (CPCR=0x%08x)\n", status);
457 #error no platform configuration
459 pr_debug(
"m32r_cfc: _pcc_get_status: GetStatus(%d) = %#4.4x\n",
468 pr_debug(
"m32r_cfc: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
469 "io_irq %d, csc_mask %#2.2x)\n", sock, state->
flags,
472 #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
474 if ((state->
Vcc != 50) && (state->
Vcc != 33))
522 pr_debug(
"m32r_cfc: SetIOMap(%d, %d, %#2.2x, %d ns, "
523 "%#llx-%#llx)\n", sock, io->
map, io->
flags,
525 (
unsigned long long)io->
stop);
540 pr_debug(
"m32r_cfc: SetMemMap(%d, %d, %#2.2x, %d ns, "
541 "%#llx, %#x)\n", sock, map, mem->
flags,
587 static ssize_t show_info(
struct class_device *class_dev,
char *
buf)
592 return sprintf(buf,
"type: %s\nbase addr: 0x%08lx\n",
596 static ssize_t show_exca(
struct class_device *class_dev,
char *
buf)
604 static CLASS_DEVICE_ATTR(exca,
S_IRUGO, show_exca,
NULL);
611 #define LOCKED(x) do { \
613 unsigned long flags; \
614 spin_lock_irqsave(&pcc_lock, flags); \
616 spin_unlock_irqrestore(&pcc_lock, flags); \
626 dev_dbg(&s->
dev,
"pcc_get_status: sock(%d) -EINVAL\n", sock);
630 dev_dbg(&s->
dev,
"pcc_get_status: sock(%d)\n", sock);
631 LOCKED(_pcc_get_status(sock, value));
639 dev_dbg(&s->
dev,
"pcc_set_socket: sock(%d) -EINVAL\n", sock);
642 dev_dbg(&s->
dev,
"pcc_set_socket: sock(%d)\n", sock);
643 LOCKED(_pcc_set_socket(sock, state));
650 if (socket[sock].
flags & IS_ALIVE) {
651 dev_dbg(&s->
dev,
"pcc_set_io_map: sock(%d) -EINVAL\n", sock);
654 dev_dbg(&s->
dev,
"pcc_set_io_map: sock(%d)\n", sock);
655 LOCKED(_pcc_set_io_map(sock, io));
662 if (socket[sock].
flags & IS_ALIVE) {
663 dev_dbg(&s->
dev,
"pcc_set_mem_map: sock(%d) -EINVAL\n", sock);
666 dev_dbg(&s->
dev,
"pcc_set_mem_map: sock(%d)\n", sock);
667 LOCKED(_pcc_set_mem_map(sock, mem));
678 .get_status = pcc_get_status,
679 .set_socket = pcc_set_socket,
680 .set_io_map = pcc_set_io_map,
681 .set_mem_map = pcc_set_mem_map,
701 static int __init init_m32r_pcc(
void)
715 #if defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
716 pcc_set(0, (
unsigned int)
PLD_CFCR0, 0x0f0f);
717 pcc_set(0, (
unsigned int)
PLD_CFCR1, 0x0200);
722 #if !defined(CONFIG_PLAT_USRV)
732 base = base | (i << 8);
733 ioaddr = (i + 1) << 12;
735 add_pcc_socket(base, 0, mapaddr, ioaddr);
740 if (pcc_sockets == 0) {
741 printk(
"socket is not found.\n");
749 for (i = 0 ; i < pcc_sockets ; i++) {
750 socket[
i].
socket.dev.parent = &pcc_device.
dev;
751 socket[
i].
socket.ops = &pcc_operations;
760 class_device_create_file(&socket[i].socket.dev,
761 &class_device_attr_info);
762 class_device_create_file(&socket[i].socket.dev,
763 &class_device_attr_exca);
768 if (poll_interval != 0) {
769 poll_timer.function = pcc_interrupt_wrapper;
772 poll_timer.expires =
jiffies + poll_interval;
779 static void __exit exit_m32r_pcc(
void)
783 for (i = 0; i < pcc_sockets; i++)
788 if (poll_interval != 0)