[SERIAL] sunsu: Convert to of_driver framework.

Signed-off-by: David S. Miller <davem@davemloft.net>

authored by David S. Miller and committed by David S. Miller 1708d242 4fa97dcf

+175 -352
+175 -352
drivers/serial/sunsu.c
··· 40 41 #include <asm/io.h> 42 #include <asm/irq.h> 43 - #include <asm/oplib.h> 44 - #include <asm/ebus.h> 45 - #ifdef CONFIG_SPARC64 46 - #include <asm/isa.h> 47 - #endif 48 49 #if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 50 #define SUPPORT_SYSRQ ··· 91 /* Probing information. */ 92 enum su_type su_type; 93 unsigned int type_probed; /* XXX Stupid */ 94 - int port_node; 95 96 #ifdef CONFIG_SERIO 97 - struct serio *serio; 98 int serio_open; 99 #endif 100 }; ··· 506 /* Stop-A is handled by drivers/char/keyboard.c now. */ 507 if (up->su_type == SU_PORT_KBD) { 508 #ifdef CONFIG_SERIO 509 - serio_interrupt(up->serio, ch, 0, regs); 510 #endif 511 } else if (up->su_type == SU_PORT_MS) { 512 int ret = suncore_mouse_baud_detection(ch, is_break); ··· 520 521 case 0: 522 #ifdef CONFIG_SERIO 523 - serio_interrupt(up->serio, ch, 0, regs); 524 #endif 525 break; 526 }; ··· 1028 { 1029 unsigned char status1, status2, scratch, scratch2, scratch3; 1030 unsigned char save_lcr, save_mcr; 1031 - struct linux_ebus_device *dev = NULL; 1032 - struct linux_ebus *ebus; 1033 - #ifdef CONFIG_SPARC64 1034 - struct sparc_isa_bridge *isa_br; 1035 - struct sparc_isa_device *isa_dev; 1036 - #endif 1037 - #ifndef CONFIG_SPARC64 1038 - struct linux_prom_registers reg0; 1039 - #endif 1040 unsigned long flags; 1041 1042 - if (!up->port_node || !up->su_type) 1043 return; 1044 1045 up->type_probed = PORT_UNKNOWN; 1046 up->port.iotype = UPIO_MEM; 1047 - 1048 - /* 1049 - * First we look for Ebus-bases su's 1050 - */ 1051 - for_each_ebus(ebus) { 1052 - for_each_ebusdev(dev, ebus) { 1053 - if (dev->prom_node->node == up->port_node) { 1054 - /* 1055 - * The EBus is broken on sparc; it delivers 1056 - * virtual addresses in resources. Oh well... 1057 - * This is correct on sparc64, though. 1058 - */ 1059 - up->port.membase = (char *) dev->resource[0].start; 1060 - /* 1061 - * This is correct on both architectures. 1062 - */ 1063 - up->port.mapbase = dev->resource[0].start; 1064 - up->port.irq = dev->irqs[0]; 1065 - goto ebus_done; 1066 - } 1067 - } 1068 - } 1069 - 1070 - #ifdef CONFIG_SPARC64 1071 - for_each_isa(isa_br) { 1072 - for_each_isadev(isa_dev, isa_br) { 1073 - if (isa_dev->prom_node->node == up->port_node) { 1074 - /* Same on sparc64. Cool architecure... */ 1075 - up->port.membase = (char *) isa_dev->resource.start; 1076 - up->port.mapbase = isa_dev->resource.start; 1077 - up->port.irq = isa_dev->irq; 1078 - goto ebus_done; 1079 - } 1080 - } 1081 - } 1082 - #endif 1083 - 1084 - #ifdef CONFIG_SPARC64 1085 - /* 1086 - * Not on Ebus, bailing. 1087 - */ 1088 - return; 1089 - #else 1090 - /* 1091 - * Not on Ebus, must be OBIO. 1092 - */ 1093 - if (prom_getproperty(up->port_node, "reg", 1094 - (char *)&reg0, sizeof(reg0)) == -1) { 1095 - prom_printf("sunsu: no \"reg\" property\n"); 1096 - return; 1097 - } 1098 - prom_apply_obio_ranges(&reg0, 1); 1099 - if (reg0.which_io != 0) { /* Just in case... */ 1100 - prom_printf("sunsu: bus number nonzero: 0x%x:%x\n", 1101 - reg0.which_io, reg0.phys_addr); 1102 - return; 1103 - } 1104 - up->port.mapbase = reg0.phys_addr; 1105 - if ((up->port.membase = ioremap(reg0.phys_addr, reg0.reg_size)) == 0) { 1106 - prom_printf("sunsu: Cannot map registers.\n"); 1107 - return; 1108 - } 1109 - 1110 - /* 1111 - * 0x20 is sun4m thing, Dave Redman heritage. 1112 - * See arch/sparc/kernel/irq.c. 1113 - */ 1114 - #define IRQ_4M(n) ((n)|0x20) 1115 - 1116 - /* 1117 - * There is no intr property on MrCoffee, so hardwire it. 1118 - */ 1119 - up->port.irq = IRQ_4M(13); 1120 - #endif 1121 - 1122 - ebus_done: 1123 1124 spin_lock_irqsave(&up->port.lock, flags); 1125 ··· 1181 .major = TTY_MAJOR, 1182 }; 1183 1184 - static int __init sunsu_kbd_ms_init(struct uart_sunsu_port *up, int channel) 1185 { 1186 int quot, baud; 1187 #ifdef CONFIG_SERIO 1188 struct serio *serio; 1189 #endif 1190 - 1191 - spin_lock_init(&up->port.lock); 1192 - up->port.line = channel; 1193 - up->port.type = PORT_UNKNOWN; 1194 - up->port.uartclk = (SU_BASE_BAUD * 16); 1195 1196 if (up->su_type == SU_PORT_KBD) { 1197 up->cflag = B1200 | CS8 | CLOCAL | CREAD; ··· 1199 1200 sunsu_autoconfig(up); 1201 if (up->port.type == PORT_UNKNOWN) 1202 - return -1; 1203 - 1204 - printk(KERN_INFO "su%d at 0x%p (irq = %d) is a %s\n", 1205 - channel, 1206 - up->port.membase, up->port.irq, 1207 - sunsu_type(&up->port)); 1208 1209 #ifdef CONFIG_SERIO 1210 - up->serio = serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 1211 - if (serio) { 1212 - memset(serio, 0, sizeof(*serio)); 1213 1214 - serio->port_data = up; 1215 - 1216 - serio->id.type = SERIO_RS232; 1217 - if (up->su_type == SU_PORT_KBD) { 1218 - serio->id.proto = SERIO_SUNKBD; 1219 - strlcpy(serio->name, "sukbd", sizeof(serio->name)); 1220 - } else { 1221 - serio->id.proto = SERIO_SUN; 1222 - serio->id.extra = 1; 1223 - strlcpy(serio->name, "sums", sizeof(serio->name)); 1224 - } 1225 - strlcpy(serio->phys, (channel == 0 ? "su/serio0" : "su/serio1"), 1226 - sizeof(serio->phys)); 1227 - 1228 - serio->write = sunsu_serio_write; 1229 - serio->open = sunsu_serio_open; 1230 - serio->close = sunsu_serio_close; 1231 - 1232 - serio_register_port(serio); 1233 } else { 1234 - printk(KERN_WARNING "su%d: not enough memory for serio port\n", 1235 - channel); 1236 } 1237 #endif 1238 1239 sunsu_change_speed(&up->port, up->cflag, 0, quot); ··· 1355 * Register console. 1356 */ 1357 1358 - static inline struct console *SUNSU_CONSOLE(void) 1359 { 1360 int i; 1361 1362 if (con_is_present()) 1363 return NULL; 1364 1365 - for (i = 0; i < UART_NR; i++) { 1366 int this_minor = sunsu_reg.minor + i; 1367 1368 if ((this_minor - 64) == (serial_console - 1)) 1369 break; 1370 } 1371 - if (i == UART_NR) 1372 - return NULL; 1373 - if (sunsu_ports[i].port_node == 0) 1374 return NULL; 1375 1376 sunsu_cons.index = i; ··· 1376 return &sunsu_cons; 1377 } 1378 #else 1379 - #define SUNSU_CONSOLE() (NULL) 1380 #define sunsu_serial_console_init() do { } while (0) 1381 #endif 1382 1383 - static int __init sunsu_serial_init(void) 1384 { 1385 - int instance, ret, i; 1386 1387 - /* How many instances do we need? */ 1388 - instance = 0; 1389 - for (i = 0; i < UART_NR; i++) { 1390 - struct uart_sunsu_port *up = &sunsu_ports[i]; 1391 1392 - if (up->su_type == SU_PORT_MS || 1393 - up->su_type == SU_PORT_KBD) 1394 - continue; 1395 - 1396 - spin_lock_init(&up->port.lock); 1397 - up->port.flags |= UPF_BOOT_AUTOCONF; 1398 - up->port.type = PORT_UNKNOWN; 1399 - up->port.uartclk = (SU_BASE_BAUD * 16); 1400 - 1401 - sunsu_autoconfig(up); 1402 - if (up->port.type == PORT_UNKNOWN) 1403 - continue; 1404 - 1405 - up->port.line = instance++; 1406 - up->port.ops = &sunsu_pops; 1407 - } 1408 - 1409 - sunsu_reg.minor = sunserial_current_minor; 1410 - 1411 - sunsu_reg.nr = instance; 1412 - 1413 - ret = uart_register_driver(&sunsu_reg); 1414 - if (ret < 0) 1415 - return ret; 1416 - 1417 - sunsu_reg.tty_driver->name_base = sunsu_reg.minor - 64; 1418 - 1419 - sunserial_current_minor += instance; 1420 - 1421 - sunsu_reg.cons = SUNSU_CONSOLE(); 1422 - 1423 - for (i = 0; i < UART_NR; i++) { 1424 - struct uart_sunsu_port *up = &sunsu_ports[i]; 1425 - 1426 - /* Do not register Keyboard/Mouse lines with UART 1427 - * layer. 1428 - */ 1429 - if (up->su_type == SU_PORT_MS || 1430 - up->su_type == SU_PORT_KBD) 1431 - continue; 1432 - 1433 - if (up->port.type == PORT_UNKNOWN) 1434 - continue; 1435 - 1436 - uart_add_one_port(&sunsu_reg, &up->port); 1437 - } 1438 - 1439 - return 0; 1440 - } 1441 - 1442 - static int su_node_ok(int node, char *name, int namelen) 1443 - { 1444 - if (strncmp(name, "su", namelen) == 0 || 1445 - strncmp(name, "su_pnp", namelen) == 0) 1446 - return 1; 1447 - 1448 - if (strncmp(name, "serial", namelen) == 0) { 1449 - char compat[32]; 1450 - int clen; 1451 - 1452 - /* Is it _really_ a 'su' device? */ 1453 - clen = prom_getproperty(node, "compatible", compat, sizeof(compat)); 1454 - if (clen > 0) { 1455 - if (strncmp(compat, "sab82532", 8) == 0) { 1456 - /* Nope, Siemens serial, not for us. */ 1457 - return 0; 1458 - } 1459 } 1460 - return 1; 1461 } 1462 1463 return 0; 1464 } 1465 1466 - #define SU_PROPSIZE 128 1467 1468 - /* 1469 - * Scan status structure. 1470 - * "prop" is a local variable but it eats stack to keep it in each 1471 - * stack frame of a recursive procedure. 1472 - */ 1473 - struct su_probe_scan { 1474 - int msnode, kbnode; /* PROM nodes for mouse and keyboard */ 1475 - int msx, kbx; /* minors for mouse and keyboard */ 1476 - int devices; /* scan index */ 1477 - char prop[SU_PROPSIZE]; 1478 }; 1479 1480 - /* 1481 - * We have several platforms which present 'su' in different parts 1482 - * of the device tree. 'su' may be found under obio, ebus, isa and pci. 1483 - * We walk over the tree and find them wherever PROM hides them. 1484 - */ 1485 - static void __init su_probe_any(struct su_probe_scan *t, int sunode) 1486 { 1487 - struct uart_sunsu_port *up; 1488 - int len; 1489 1490 - if (t->devices >= UART_NR) 1491 - return; 1492 - 1493 - for (; sunode != 0; sunode = prom_getsibling(sunode)) { 1494 - len = prom_getproperty(sunode, "name", t->prop, SU_PROPSIZE); 1495 - if (len <= 1) 1496 - continue; /* Broken PROM node */ 1497 - 1498 - if (su_node_ok(sunode, t->prop, len)) { 1499 - up = &sunsu_ports[t->devices]; 1500 - if (t->kbnode != 0 && sunode == t->kbnode) { 1501 - t->kbx = t->devices; 1502 - up->su_type = SU_PORT_KBD; 1503 - } else if (t->msnode != 0 && sunode == t->msnode) { 1504 - t->msx = t->devices; 1505 - up->su_type = SU_PORT_MS; 1506 - } else { 1507 - #ifdef CONFIG_SPARC64 1508 - /* 1509 - * Do not attempt to use the truncated 1510 - * keyboard/mouse ports as serial ports 1511 - * on Ultras with PC keyboard attached. 1512 - */ 1513 - if (prom_getbool(sunode, "mouse")) 1514 - continue; 1515 - if (prom_getbool(sunode, "keyboard")) 1516 - continue; 1517 - #endif 1518 - up->su_type = SU_PORT_PORT; 1519 - } 1520 - up->port_node = sunode; 1521 - ++t->devices; 1522 - } else { 1523 - su_probe_any(t, prom_getchild(sunode)); 1524 - } 1525 } 1526 - } 1527 - 1528 - static int __init sunsu_probe(void) 1529 - { 1530 - int node; 1531 - int len; 1532 - struct su_probe_scan scan; 1533 - 1534 - /* 1535 - * First, we scan the tree. 1536 - */ 1537 - scan.devices = 0; 1538 - scan.msx = -1; 1539 - scan.kbx = -1; 1540 - scan.kbnode = 0; 1541 - scan.msnode = 0; 1542 - 1543 - /* 1544 - * Get the nodes for keyboard and mouse from 'aliases'... 1545 - */ 1546 - node = prom_getchild(prom_root_node); 1547 - node = prom_searchsiblings(node, "aliases"); 1548 - if (node != 0) { 1549 - len = prom_getproperty(node, "keyboard", scan.prop, SU_PROPSIZE); 1550 - if (len > 0) { 1551 - scan.prop[len] = 0; 1552 - scan.kbnode = prom_finddevice(scan.prop); 1553 - } 1554 - 1555 - len = prom_getproperty(node, "mouse", scan.prop, SU_PROPSIZE); 1556 - if (len > 0) { 1557 - scan.prop[len] = 0; 1558 - scan.msnode = prom_finddevice(scan.prop); 1559 } 1560 } 1561 1562 - su_probe_any(&scan, prom_getchild(prom_root_node)); 1563 - 1564 - /* 1565 - * Second, we process the special case of keyboard and mouse. 1566 - * 1567 - * Currently if we got keyboard and mouse hooked to "su" ports 1568 - * we do not use any possible remaining "su" as a serial port. 1569 - * Thus, we ignore values of .msx and .kbx, then compact ports. 1570 - */ 1571 - if (scan.msx != -1 && scan.kbx != -1) { 1572 - sunsu_ports[0].su_type = SU_PORT_MS; 1573 - sunsu_ports[0].port_node = scan.msnode; 1574 - sunsu_kbd_ms_init(&sunsu_ports[0], 0); 1575 - 1576 - sunsu_ports[1].su_type = SU_PORT_KBD; 1577 - sunsu_ports[1].port_node = scan.kbnode; 1578 - sunsu_kbd_ms_init(&sunsu_ports[1], 1); 1579 - 1580 - return 0; 1581 } 1582 1583 - if (scan.msx != -1 || scan.kbx != -1) { 1584 - printk("sunsu_probe: cannot match keyboard and mouse, confused\n"); 1585 - return -ENODEV; 1586 - } 1587 1588 - if (scan.devices == 0) 1589 - return -ENODEV; 1590 - 1591 - /* 1592 - * Console must be initiated after the generic initialization. 1593 - */ 1594 - sunsu_serial_init(); 1595 - 1596 - return 0; 1597 } 1598 1599 static void __exit sunsu_exit(void) 1600 { 1601 - int i, saw_uart; 1602 - 1603 - saw_uart = 0; 1604 - for (i = 0; i < UART_NR; i++) { 1605 - struct uart_sunsu_port *up = &sunsu_ports[i]; 1606 - 1607 - if (up->su_type == SU_PORT_MS || 1608 - up->su_type == SU_PORT_KBD) { 1609 - #ifdef CONFIG_SERIO 1610 - if (up->serio) { 1611 - serio_unregister_port(up->serio); 1612 - up->serio = NULL; 1613 - } 1614 - #endif 1615 - } else if (up->port.type != PORT_UNKNOWN) { 1616 - uart_remove_one_port(&sunsu_reg, &up->port); 1617 - saw_uart++; 1618 - } 1619 - } 1620 - 1621 - if (saw_uart) 1622 uart_unregister_driver(&sunsu_reg); 1623 } 1624 1625 - module_init(sunsu_probe); 1626 module_exit(sunsu_exit); 1627 MODULE_LICENSE("GPL");
··· 40 41 #include <asm/io.h> 42 #include <asm/irq.h> 43 + #include <asm/prom.h> 44 + #include <asm/of_device.h> 45 46 #if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 47 #define SUPPORT_SYSRQ ··· 94 /* Probing information. */ 95 enum su_type su_type; 96 unsigned int type_probed; /* XXX Stupid */ 97 + unsigned long reg_size; 98 99 #ifdef CONFIG_SERIO 100 + struct serio serio; 101 int serio_open; 102 #endif 103 }; ··· 509 /* Stop-A is handled by drivers/char/keyboard.c now. */ 510 if (up->su_type == SU_PORT_KBD) { 511 #ifdef CONFIG_SERIO 512 + serio_interrupt(&up->serio, ch, 0, regs); 513 #endif 514 } else if (up->su_type == SU_PORT_MS) { 515 int ret = suncore_mouse_baud_detection(ch, is_break); ··· 523 524 case 0: 525 #ifdef CONFIG_SERIO 526 + serio_interrupt(&up->serio, ch, 0, regs); 527 #endif 528 break; 529 }; ··· 1031 { 1032 unsigned char status1, status2, scratch, scratch2, scratch3; 1033 unsigned char save_lcr, save_mcr; 1034 unsigned long flags; 1035 1036 + if (up->su_type == SU_PORT_NONE) 1037 return; 1038 1039 up->type_probed = PORT_UNKNOWN; 1040 up->port.iotype = UPIO_MEM; 1041 1042 spin_lock_irqsave(&up->port.lock, flags); 1043 ··· 1269 .major = TTY_MAJOR, 1270 }; 1271 1272 + static int __init sunsu_kbd_ms_init(struct uart_sunsu_port *up) 1273 { 1274 int quot, baud; 1275 #ifdef CONFIG_SERIO 1276 struct serio *serio; 1277 #endif 1278 1279 if (up->su_type == SU_PORT_KBD) { 1280 up->cflag = B1200 | CS8 | CLOCAL | CREAD; ··· 1292 1293 sunsu_autoconfig(up); 1294 if (up->port.type == PORT_UNKNOWN) 1295 + return -ENODEV; 1296 1297 #ifdef CONFIG_SERIO 1298 + serio = &up->serio; 1299 + serio->port_data = up; 1300 1301 + serio->id.type = SERIO_RS232; 1302 + if (up->su_type == SU_PORT_KBD) { 1303 + serio->id.proto = SERIO_SUNKBD; 1304 + strlcpy(serio->name, "sukbd", sizeof(serio->name)); 1305 } else { 1306 + serio->id.proto = SERIO_SUN; 1307 + serio->id.extra = 1; 1308 + strlcpy(serio->name, "sums", sizeof(serio->name)); 1309 } 1310 + strlcpy(serio->phys, 1311 + (!(up->port.line & 1) ? "su/serio0" : "su/serio1"), 1312 + sizeof(serio->phys)); 1313 + 1314 + serio->write = sunsu_serio_write; 1315 + serio->open = sunsu_serio_open; 1316 + serio->close = sunsu_serio_close; 1317 + serio->dev.parent = up->port.dev; 1318 + 1319 + serio_register_port(serio); 1320 #endif 1321 1322 sunsu_change_speed(&up->port, up->cflag, 0, quot); ··· 1458 * Register console. 1459 */ 1460 1461 + static inline struct console *SUNSU_CONSOLE(int num_uart) 1462 { 1463 int i; 1464 1465 if (con_is_present()) 1466 return NULL; 1467 1468 + for (i = 0; i < num_uart; i++) { 1469 int this_minor = sunsu_reg.minor + i; 1470 1471 if ((this_minor - 64) == (serial_console - 1)) 1472 break; 1473 } 1474 + if (i == num_uart) 1475 return NULL; 1476 1477 sunsu_cons.index = i; ··· 1481 return &sunsu_cons; 1482 } 1483 #else 1484 + #define SUNSU_CONSOLE(num_uart) (NULL) 1485 #define sunsu_serial_console_init() do { } while (0) 1486 #endif 1487 1488 + static enum su_type __devinit su_get_type(struct device_node *dp) 1489 { 1490 + struct device_node *ap = of_find_node_by_path("/aliases"); 1491 1492 + if (ap) { 1493 + char *keyb = of_get_property(ap, "keyboard", NULL); 1494 + char *ms = of_get_property(ap, "mouse", NULL); 1495 1496 + if (keyb) { 1497 + if (dp == of_find_node_by_path(keyb)) 1498 + return SU_PORT_KBD; 1499 } 1500 + if (ms) { 1501 + if (dp == of_find_node_by_path(ms)) 1502 + return SU_PORT_MS; 1503 + } 1504 } 1505 + 1506 + return SU_PORT_PORT; 1507 + } 1508 + 1509 + static int __devinit su_probe(struct of_device *op, const struct of_device_id *match) 1510 + { 1511 + static int inst; 1512 + struct device_node *dp = op->node; 1513 + struct uart_sunsu_port *up; 1514 + struct resource *rp; 1515 + int err; 1516 + 1517 + if (inst >= UART_NR) 1518 + return -EINVAL; 1519 + 1520 + up = &sunsu_ports[inst]; 1521 + up->port.line = inst; 1522 + 1523 + spin_lock_init(&up->port.lock); 1524 + 1525 + up->su_type = su_get_type(dp); 1526 + 1527 + rp = &op->resource[0]; 1528 + up->port.mapbase = op->resource[0].start; 1529 + 1530 + up->reg_size = (rp->end - rp->start) + 1; 1531 + up->port.membase = of_ioremap(rp, 0, up->reg_size, "su"); 1532 + if (!up->port.membase) 1533 + return -ENOMEM; 1534 + 1535 + up->port.irq = op->irqs[0]; 1536 + 1537 + up->port.dev = &op->dev; 1538 + 1539 + up->port.type = PORT_UNKNOWN; 1540 + up->port.uartclk = (SU_BASE_BAUD * 16); 1541 + 1542 + err = 0; 1543 + if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) { 1544 + err = sunsu_kbd_ms_init(up); 1545 + if (err) 1546 + goto out_unmap; 1547 + } 1548 + 1549 + up->port.flags |= UPF_BOOT_AUTOCONF; 1550 + 1551 + sunsu_autoconfig(up); 1552 + 1553 + err = -ENODEV; 1554 + if (up->port.type == PORT_UNKNOWN) 1555 + goto out_unmap; 1556 + 1557 + up->port.ops = &sunsu_pops; 1558 + 1559 + err = uart_add_one_port(&sunsu_reg, &up->port); 1560 + if (err) 1561 + goto out_unmap; 1562 + 1563 + dev_set_drvdata(&op->dev, up); 1564 + 1565 + inst++; 1566 + 1567 + return 0; 1568 + 1569 + out_unmap: 1570 + of_iounmap(up->port.membase, up->reg_size); 1571 + return err; 1572 + } 1573 + 1574 + static int __devexit su_remove(struct of_device *dev) 1575 + { 1576 + struct uart_sunsu_port *up = dev_get_drvdata(&dev->dev);; 1577 + 1578 + if (up->su_type == SU_PORT_MS || 1579 + up->su_type == SU_PORT_KBD) { 1580 + #ifdef CONFIG_SERIO 1581 + serio_unregister_port(&up->serio); 1582 + #endif 1583 + } else if (up->port.type != PORT_UNKNOWN) 1584 + uart_remove_one_port(&sunsu_reg, &up->port); 1585 1586 return 0; 1587 } 1588 1589 + static struct of_device_id su_match[] = { 1590 + { 1591 + .name = "su", 1592 + }, 1593 + { 1594 + .name = "su_pnp", 1595 + }, 1596 + { 1597 + .name = "serial", 1598 + .compatible = "su", 1599 + }, 1600 + {}, 1601 + }; 1602 + MODULE_DEVICE_TABLE(of, su_match); 1603 1604 + static struct of_platform_driver su_driver = { 1605 + .name = "su", 1606 + .match_table = su_match, 1607 + .probe = su_probe, 1608 + .remove = __devexit_p(su_remove), 1609 }; 1610 1611 + static int num_uart; 1612 + 1613 + static int __init sunsu_init(void) 1614 { 1615 + struct device_node *dp; 1616 + int err; 1617 1618 + num_uart = 0; 1619 + for_each_node_by_name(dp, "su") { 1620 + if (su_get_type(dp) == SU_PORT_PORT) 1621 + num_uart++; 1622 } 1623 + for_each_node_by_name(dp, "su_pnp") { 1624 + if (su_get_type(dp) == SU_PORT_PORT) 1625 + num_uart++; 1626 + } 1627 + for_each_node_by_name(dp, "serial") { 1628 + if (of_device_is_compatible(dp, "su")) { 1629 + if (su_get_type(dp) == SU_PORT_PORT) 1630 + num_uart++; 1631 } 1632 } 1633 1634 + if (num_uart) { 1635 + sunsu_reg.minor = sunserial_current_minor; 1636 + sunsu_reg.nr = num_uart; 1637 + err = uart_register_driver(&sunsu_reg); 1638 + if (err) 1639 + return err; 1640 + sunsu_reg.tty_driver->name_base = sunsu_reg.minor - 64; 1641 + sunserial_current_minor += num_uart; 1642 + sunsu_reg.cons = SUNSU_CONSOLE(num_uart); 1643 } 1644 1645 + err = of_register_driver(&su_driver, &of_bus_type); 1646 + if (err && num_uart) 1647 + uart_unregister_driver(&sunsu_reg); 1648 1649 + return err; 1650 } 1651 1652 static void __exit sunsu_exit(void) 1653 { 1654 + if (num_uart) 1655 uart_unregister_driver(&sunsu_reg); 1656 } 1657 1658 + module_init(sunsu_init); 1659 module_exit(sunsu_exit); 1660 MODULE_LICENSE("GPL");