[SERIAL] sunzilog: Convert to of_driver.

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

authored by David S. Miller and committed by David S. Miller 36764631 8f96cd1a

+274 -543
+274 -543
drivers/serial/sunzilog.c
··· 1 - /* 2 - * sunzilog.c 3 * 4 * Driver for Zilog serial chips found on Sun workstations and 5 * servers. This driver could actually be made more generic. ··· 9 * C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell for their 10 * work there. 11 * 12 - * Copyright (C) 2002 David S. Miller (davem@redhat.com) 13 */ 14 15 #include <linux/config.h> ··· 37 38 #include <asm/io.h> 39 #include <asm/irq.h> 40 - #ifdef CONFIG_SPARC64 41 - #include <asm/fhc.h> 42 - #endif 43 - #include <asm/sbus.h> 44 45 #if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 46 #define SUPPORT_SYSRQ ··· 62 #define ZSDELAY() 63 #define ZSDELAY_LONG() 64 #define ZS_WSYNC(__channel) \ 65 - sbus_readb(&((__channel)->control)) 66 #endif 67 68 static int num_sunzilog; ··· 104 unsigned char prev_status; 105 106 #ifdef CONFIG_SERIO 107 - struct serio *serio; 108 int serio_open; 109 #endif 110 }; ··· 135 { 136 unsigned char retval; 137 138 - sbus_writeb(reg, &channel->control); 139 ZSDELAY(); 140 - retval = sbus_readb(&channel->control); 141 ZSDELAY(); 142 143 return retval; ··· 146 static void write_zsreg(struct zilog_channel __iomem *channel, 147 unsigned char reg, unsigned char value) 148 { 149 - sbus_writeb(reg, &channel->control); 150 ZSDELAY(); 151 - sbus_writeb(value, &channel->control); 152 ZSDELAY(); 153 } 154 ··· 159 for (i = 0; i < 32; i++) { 160 unsigned char regval; 161 162 - regval = sbus_readb(&channel->control); 163 ZSDELAY(); 164 if (regval & Rx_CH_AV) 165 break; 166 167 regval = read_zsreg(channel, R1); 168 - sbus_readb(&channel->data); 169 ZSDELAY(); 170 171 if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) { 172 - sbus_writeb(ERR_RES, &channel->control); 173 ZSDELAY(); 174 ZS_WSYNC(channel); 175 } ··· 191 udelay(100); 192 } 193 194 - sbus_writeb(ERR_RES, &channel->control); 195 ZSDELAY(); 196 ZS_WSYNC(channel); 197 ··· 288 /* Stop-A is handled by drivers/char/keyboard.c now. */ 289 #ifdef CONFIG_SERIO 290 if (up->serio_open) 291 - serio_interrupt(up->serio, ch, 0, regs); 292 #endif 293 } else if (ZS_IS_MOUSE(up)) { 294 int ret = suncore_mouse_baud_detection(ch, is_break); ··· 303 case 0: 304 #ifdef CONFIG_SERIO 305 if (up->serio_open) 306 - serio_interrupt(up->serio, ch, 0, regs); 307 #endif 308 break; 309 }; ··· 327 328 r1 = read_zsreg(channel, R1); 329 if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) { 330 - sbus_writeb(ERR_RES, &channel->control); 331 ZSDELAY(); 332 ZS_WSYNC(channel); 333 } 334 335 - ch = sbus_readb(&channel->control); 336 ZSDELAY(); 337 338 /* This funny hack depends upon BRK_ABRT not interfering ··· 344 if (!(ch & Rx_CH_AV)) 345 break; 346 347 - ch = sbus_readb(&channel->data); 348 ZSDELAY(); 349 350 ch &= up->parity_mask; ··· 403 { 404 unsigned char status; 405 406 - status = sbus_readb(&channel->control); 407 ZSDELAY(); 408 409 - sbus_writeb(RES_EXT_INT, &channel->control); 410 ZSDELAY(); 411 ZS_WSYNC(channel); 412 ··· 418 * confusing the PROM. 419 */ 420 while (1) { 421 - status = sbus_readb(&channel->control); 422 ZSDELAY(); 423 if (!(status & BRK_ABRT)) 424 break; ··· 455 struct circ_buf *xmit; 456 457 if (ZS_IS_CONS(up)) { 458 - unsigned char status = sbus_readb(&channel->control); 459 ZSDELAY(); 460 461 /* TX still busy? Just wait for the next TX done interrupt. ··· 484 485 if (up->port.x_char) { 486 up->flags |= SUNZILOG_FLAG_TX_ACTIVE; 487 - sbus_writeb(up->port.x_char, &channel->data); 488 ZSDELAY(); 489 ZS_WSYNC(channel); 490 ··· 503 goto ack_tx_int; 504 505 up->flags |= SUNZILOG_FLAG_TX_ACTIVE; 506 - sbus_writeb(xmit->buf[xmit->tail], &channel->data); 507 ZSDELAY(); 508 ZS_WSYNC(channel); 509 ··· 516 return; 517 518 ack_tx_int: 519 - sbus_writeb(RES_Tx_P, &channel->control); 520 ZSDELAY(); 521 ZS_WSYNC(channel); 522 } ··· 537 /* Channel A */ 538 tty = NULL; 539 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) { 540 - sbus_writeb(RES_H_IUS, &channel->control); 541 ZSDELAY(); 542 ZS_WSYNC(channel); 543 ··· 560 spin_lock(&up->port.lock); 561 tty = NULL; 562 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { 563 - sbus_writeb(RES_H_IUS, &channel->control); 564 ZSDELAY(); 565 ZS_WSYNC(channel); 566 ··· 591 unsigned char status; 592 593 channel = ZILOG_CHANNEL_FROM_PORT(port); 594 - status = sbus_readb(&channel->control); 595 ZSDELAY(); 596 597 return status; ··· 679 up->flags |= SUNZILOG_FLAG_TX_ACTIVE; 680 up->flags &= ~SUNZILOG_FLAG_TX_STOPPED; 681 682 - status = sbus_readb(&channel->control); 683 ZSDELAY(); 684 685 /* TX busy? Just wait for the TX done interrupt. */ ··· 690 * IRQ sending engine. 691 */ 692 if (port->x_char) { 693 - sbus_writeb(port->x_char, &channel->data); 694 ZSDELAY(); 695 ZS_WSYNC(channel); 696 ··· 699 } else { 700 struct circ_buf *xmit = &port->info->xmit; 701 702 - sbus_writeb(xmit->buf[xmit->tail], &channel->data); 703 ZSDELAY(); 704 ZS_WSYNC(channel); 705 ··· 776 struct zilog_channel __iomem *channel; 777 778 channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 779 - up->prev_status = sbus_readb(&channel->control); 780 781 /* Enable receiver and transmitter. */ 782 up->curregs[R3] |= RxENAB; ··· 960 961 static const char *sunzilog_type(struct uart_port *port) 962 { 963 - return "SunZilog"; 964 } 965 966 /* We do not request/release mappings of the registers here, this ··· 1009 static struct zilog_layout __iomem **sunzilog_chip_regs; 1010 1011 static struct uart_sunzilog_port *sunzilog_irq_chain; 1012 - static int zilog_irq = -1; 1013 1014 static struct uart_driver sunzilog_reg = { 1015 .owner = THIS_MODULE, ··· 1017 .major = TTY_MAJOR, 1018 }; 1019 1020 - static void * __init alloc_one_table(unsigned long size) 1021 { 1022 - void *ret; 1023 1024 - ret = kmalloc(size, GFP_KERNEL); 1025 - if (ret != NULL) 1026 - memset(ret, 0, size); 1027 1028 - return ret; 1029 } 1030 1031 - static void __init sunzilog_alloc_tables(void) 1032 { 1033 - sunzilog_port_table = 1034 - alloc_one_table(NUM_CHANNELS * sizeof(struct uart_sunzilog_port)); 1035 - sunzilog_chip_regs = 1036 - alloc_one_table(NUM_SUNZILOG * sizeof(struct zilog_layout __iomem *)); 1037 - 1038 - if (sunzilog_port_table == NULL || sunzilog_chip_regs == NULL) { 1039 - prom_printf("SunZilog: Cannot allocate tables.\n"); 1040 - prom_halt(); 1041 - } 1042 - } 1043 - 1044 - #ifdef CONFIG_SPARC64 1045 - 1046 - /* We used to attempt to use the address property of the Zilog device node 1047 - * but that totally is not necessary on sparc64. 1048 - */ 1049 - static struct zilog_layout __iomem * __init get_zs_sun4u(int chip, int zsnode) 1050 - { 1051 - void __iomem *mapped_addr; 1052 - unsigned int sun4u_ino; 1053 - struct sbus_bus *sbus = NULL; 1054 - struct sbus_dev *sdev = NULL; 1055 - int err; 1056 - 1057 - if (central_bus == NULL) { 1058 - for_each_sbus(sbus) { 1059 - for_each_sbusdev(sdev, sbus) { 1060 - if (sdev->prom_node == zsnode) 1061 - goto found; 1062 - } 1063 - } 1064 - } 1065 - found: 1066 - if (sdev == NULL && central_bus == NULL) { 1067 - prom_printf("SunZilog: sdev&&central == NULL for " 1068 - "Zilog %d in get_zs_sun4u.\n", chip); 1069 - prom_halt(); 1070 - } 1071 - if (central_bus == NULL) { 1072 - mapped_addr = 1073 - sbus_ioremap(&sdev->resource[0], 0, 1074 - PAGE_SIZE, 1075 - "Zilog Registers"); 1076 - } else { 1077 - struct linux_prom_registers zsregs[1]; 1078 - 1079 - err = prom_getproperty(zsnode, "reg", 1080 - (char *) &zsregs[0], 1081 - sizeof(zsregs)); 1082 - if (err == -1) { 1083 - prom_printf("SunZilog: Cannot map " 1084 - "Zilog %d regs on " 1085 - "central bus.\n", chip); 1086 - prom_halt(); 1087 - } 1088 - apply_fhc_ranges(central_bus->child, 1089 - &zsregs[0], 1); 1090 - apply_central_ranges(central_bus, &zsregs[0], 1); 1091 - mapped_addr = (void __iomem *) 1092 - ((((u64)zsregs[0].which_io)<<32UL) | 1093 - ((u64)zsregs[0].phys_addr)); 1094 - } 1095 - 1096 - if (zilog_irq == -1) { 1097 - if (central_bus) { 1098 - unsigned long iclr, imap; 1099 - 1100 - iclr = central_bus->child->fhc_regs.uregs 1101 - + FHC_UREGS_ICLR; 1102 - imap = central_bus->child->fhc_regs.uregs 1103 - + FHC_UREGS_IMAP; 1104 - zilog_irq = build_irq(0, iclr, imap); 1105 - } else { 1106 - err = prom_getproperty(zsnode, "interrupts", 1107 - (char *) &sun4u_ino, 1108 - sizeof(sun4u_ino)); 1109 - zilog_irq = sbus_build_irq(sbus_root, sun4u_ino); 1110 - } 1111 - } 1112 - 1113 - return (struct zilog_layout __iomem *) mapped_addr; 1114 - } 1115 - #else /* CONFIG_SPARC64 */ 1116 - 1117 - /* 1118 - * XXX The sun4d case is utterly screwed: it tries to re-walk the tree 1119 - * (for the 3rd time) in order to find bootbus and cpu. Streamline it. 1120 - */ 1121 - static struct zilog_layout __iomem * __init get_zs_sun4cmd(int chip, int node) 1122 - { 1123 - struct linux_prom_irqs irq_info[2]; 1124 - void __iomem *mapped_addr = NULL; 1125 - int zsnode, cpunode, bbnode; 1126 - struct linux_prom_registers zsreg[4]; 1127 - struct resource res; 1128 - 1129 - if (sparc_cpu_model == sun4d) { 1130 - int walk; 1131 - 1132 - zsnode = 0; 1133 - bbnode = 0; 1134 - cpunode = 0; 1135 - for (walk = prom_getchild(prom_root_node); 1136 - (walk = prom_searchsiblings(walk, "cpu-unit")) != 0; 1137 - walk = prom_getsibling(walk)) { 1138 - bbnode = prom_getchild(walk); 1139 - if (bbnode && 1140 - (bbnode = prom_searchsiblings(bbnode, "bootbus"))) { 1141 - if ((zsnode = prom_getchild(bbnode)) == node) { 1142 - cpunode = walk; 1143 - break; 1144 - } 1145 - } 1146 - } 1147 - if (!walk) { 1148 - prom_printf("SunZilog: Cannot find the %d'th bootbus on sun4d.\n", 1149 - (chip / 2)); 1150 - prom_halt(); 1151 - } 1152 - 1153 - if (prom_getproperty(zsnode, "reg", 1154 - (char *) zsreg, sizeof(zsreg)) == -1) { 1155 - prom_printf("SunZilog: Cannot map Zilog %d\n", chip); 1156 - prom_halt(); 1157 - } 1158 - /* XXX Looks like an off by one? */ 1159 - prom_apply_generic_ranges(bbnode, cpunode, zsreg, 1); 1160 - res.start = zsreg[0].phys_addr; 1161 - res.end = res.start + (8 - 1); 1162 - res.flags = zsreg[0].which_io | IORESOURCE_IO; 1163 - mapped_addr = sbus_ioremap(&res, 0, 8, "Zilog Serial"); 1164 - 1165 - } else { 1166 - zsnode = node; 1167 - 1168 - #if 0 /* XXX When was this used? */ 1169 - if (prom_getintdefault(zsnode, "slave", -1) != chipid) { 1170 - zsnode = prom_getsibling(zsnode); 1171 - continue; 1172 - } 1173 - #endif 1174 - 1175 - /* 1176 - * "address" is only present on ports that OBP opened 1177 - * (from Mitch Bradley's "Hitchhiker's Guide to OBP"). 1178 - * We do not use it. 1179 - */ 1180 - 1181 - if (prom_getproperty(zsnode, "reg", 1182 - (char *) zsreg, sizeof(zsreg)) == -1) { 1183 - prom_printf("SunZilog: Cannot map Zilog %d\n", chip); 1184 - prom_halt(); 1185 - } 1186 - if (sparc_cpu_model == sun4m) /* Crude. Pass parent. XXX */ 1187 - prom_apply_obio_ranges(zsreg, 1); 1188 - res.start = zsreg[0].phys_addr; 1189 - res.end = res.start + (8 - 1); 1190 - res.flags = zsreg[0].which_io | IORESOURCE_IO; 1191 - mapped_addr = sbus_ioremap(&res, 0, 8, "Zilog Serial"); 1192 - } 1193 - 1194 - if (prom_getproperty(zsnode, "intr", 1195 - (char *) irq_info, sizeof(irq_info)) 1196 - % sizeof(struct linux_prom_irqs)) { 1197 - prom_printf("SunZilog: Cannot get IRQ property for Zilog %d.\n", 1198 - chip); 1199 - prom_halt(); 1200 - } 1201 - if (zilog_irq == -1) { 1202 - zilog_irq = irq_info[0].pri; 1203 - } else if (zilog_irq != irq_info[0].pri) { 1204 - /* XXX. Dumb. Should handle per-chip IRQ, for add-ons. */ 1205 - prom_printf("SunZilog: Inconsistent IRQ layout for Zilog %d.\n", 1206 - chip); 1207 - prom_halt(); 1208 - } 1209 - 1210 - return (struct zilog_layout __iomem *) mapped_addr; 1211 - } 1212 - #endif /* !(CONFIG_SPARC64) */ 1213 - 1214 - /* Get the address of the registers for SunZilog instance CHIP. */ 1215 - static struct zilog_layout __iomem * __init get_zs(int chip, int node) 1216 - { 1217 - if (chip < 0 || chip >= NUM_SUNZILOG) { 1218 - prom_printf("SunZilog: Illegal chip number %d in get_zs.\n", chip); 1219 - prom_halt(); 1220 - } 1221 - 1222 - #ifdef CONFIG_SPARC64 1223 - return get_zs_sun4u(chip, node); 1224 - #else 1225 - 1226 - if (sparc_cpu_model == sun4) { 1227 - struct resource res; 1228 - 1229 - /* Not probe-able, hard code it. */ 1230 - switch (chip) { 1231 - case 0: 1232 - res.start = 0xf1000000; 1233 - break; 1234 - case 1: 1235 - res.start = 0xf0000000; 1236 - break; 1237 - }; 1238 - zilog_irq = 12; 1239 - res.end = (res.start + (8 - 1)); 1240 - res.flags = IORESOURCE_IO; 1241 - return sbus_ioremap(&res, 0, 8, "SunZilog"); 1242 - } 1243 - 1244 - return get_zs_sun4cmd(chip, node); 1245 - #endif 1246 } 1247 1248 #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */ ··· 1071 * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM 1072 */ 1073 do { 1074 - unsigned char val = sbus_readb(&channel->control); 1075 if (val & Tx_BUF_EMP) { 1076 ZSDELAY(); 1077 break; ··· 1079 udelay(5); 1080 } while (--loops); 1081 1082 - sbus_writeb(ch, &channel->data); 1083 ZSDELAY(); 1084 ZS_WSYNC(channel); 1085 } ··· 1196 .data = &sunzilog_reg, 1197 }; 1198 1199 - static int __init sunzilog_console_init(void) 1200 - { 1201 - int i; 1202 - 1203 - if (con_is_present()) 1204 - return 0; 1205 - 1206 - for (i = 0; i < NUM_CHANNELS; i++) { 1207 - int this_minor = sunzilog_reg.minor + i; 1208 - 1209 - if ((this_minor - 64) == (serial_console - 1)) 1210 - break; 1211 - } 1212 - if (i == NUM_CHANNELS) 1213 - return 0; 1214 - 1215 - sunzilog_console.index = i; 1216 - sunzilog_port_table[i].flags |= SUNZILOG_FLAG_IS_CONS; 1217 - register_console(&sunzilog_console); 1218 - return 0; 1219 - } 1220 - 1221 static inline struct console *SUNZILOG_CONSOLE(void) 1222 { 1223 int i; ··· 1220 1221 #else 1222 #define SUNZILOG_CONSOLE() (NULL) 1223 - #define sunzilog_console_init() do { } while (0) 1224 #endif 1225 - 1226 - /* 1227 - * We scan the PROM tree recursively. This is the most reliable way 1228 - * to find Zilog nodes on various platforms. However, we face an extreme 1229 - * shortage of kernel stack, so we must be very careful. To that end, 1230 - * we scan only to a certain depth, and we use a common property buffer 1231 - * in the scan structure. 1232 - */ 1233 - #define ZS_PROPSIZE 128 1234 - #define ZS_SCAN_DEPTH 5 1235 - 1236 - struct zs_probe_scan { 1237 - int depth; 1238 - void (*scanner)(struct zs_probe_scan *t, int node); 1239 - 1240 - int devices; 1241 - char prop[ZS_PROPSIZE]; 1242 - }; 1243 - 1244 - static int __inline__ sunzilog_node_ok(int node, const char *name, int len) 1245 - { 1246 - if (strncmp(name, "zs", len) == 0) 1247 - return 1; 1248 - /* Don't fold this procedure just yet. Compare to su_node_ok(). */ 1249 - return 0; 1250 - } 1251 - 1252 - static void __init sunzilog_scan(struct zs_probe_scan *t, int node) 1253 - { 1254 - int len; 1255 - 1256 - for (; node != 0; node = prom_getsibling(node)) { 1257 - len = prom_getproperty(node, "name", t->prop, ZS_PROPSIZE); 1258 - if (len <= 1) 1259 - continue; /* Broken PROM node */ 1260 - if (sunzilog_node_ok(node, t->prop, len)) { 1261 - (*t->scanner)(t, node); 1262 - } else { 1263 - if (t->depth < ZS_SCAN_DEPTH) { 1264 - t->depth++; 1265 - sunzilog_scan(t, prom_getchild(node)); 1266 - --t->depth; 1267 - } 1268 - } 1269 - } 1270 - } 1271 - 1272 - static void __init sunzilog_prepare(void) 1273 - { 1274 - struct uart_sunzilog_port *up; 1275 - struct zilog_layout __iomem *rp; 1276 - int channel, chip; 1277 - 1278 - /* 1279 - * Temporary fix. 1280 - */ 1281 - for (channel = 0; channel < NUM_CHANNELS; channel++) 1282 - spin_lock_init(&sunzilog_port_table[channel].port.lock); 1283 - 1284 - sunzilog_irq_chain = up = &sunzilog_port_table[0]; 1285 - for (channel = 0; channel < NUM_CHANNELS - 1; channel++) 1286 - up[channel].next = &up[channel + 1]; 1287 - up[channel].next = NULL; 1288 - 1289 - for (chip = 0; chip < NUM_SUNZILOG; chip++) { 1290 - rp = sunzilog_chip_regs[chip]; 1291 - up[(chip * 2) + 0].port.membase = (void __iomem *)&rp->channelA; 1292 - up[(chip * 2) + 1].port.membase = (void __iomem *)&rp->channelB; 1293 - 1294 - /* Channel A */ 1295 - up[(chip * 2) + 0].port.iotype = UPIO_MEM; 1296 - up[(chip * 2) + 0].port.irq = zilog_irq; 1297 - up[(chip * 2) + 0].port.uartclk = ZS_CLOCK; 1298 - up[(chip * 2) + 0].port.fifosize = 1; 1299 - up[(chip * 2) + 0].port.ops = &sunzilog_pops; 1300 - up[(chip * 2) + 0].port.type = PORT_SUNZILOG; 1301 - up[(chip * 2) + 0].port.flags = 0; 1302 - up[(chip * 2) + 0].port.line = (chip * 2) + 0; 1303 - up[(chip * 2) + 0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A; 1304 - 1305 - /* Channel B */ 1306 - up[(chip * 2) + 1].port.iotype = UPIO_MEM; 1307 - up[(chip * 2) + 1].port.irq = zilog_irq; 1308 - up[(chip * 2) + 1].port.uartclk = ZS_CLOCK; 1309 - up[(chip * 2) + 1].port.fifosize = 1; 1310 - up[(chip * 2) + 1].port.ops = &sunzilog_pops; 1311 - up[(chip * 2) + 1].port.type = PORT_SUNZILOG; 1312 - up[(chip * 2) + 1].port.flags = 0; 1313 - up[(chip * 2) + 1].port.line = (chip * 2) + 1; 1314 - up[(chip * 2) + 1].flags |= 0; 1315 - } 1316 - } 1317 1318 static void __init sunzilog_init_kbdms(struct uart_sunzilog_port *up, int channel) 1319 { ··· 1235 up->cflag = B4800 | CS8 | CLOCAL | CREAD; 1236 baud = 4800; 1237 } 1238 - printk(KERN_INFO "zs%d at 0x%p (irq = %d) is a SunZilog\n", 1239 - channel, up->port.membase, zilog_irq); 1240 1241 up->curregs[R15] = BRKIE; 1242 brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); ··· 1246 #ifdef CONFIG_SERIO 1247 static void __init sunzilog_register_serio(struct uart_sunzilog_port *up, int channel) 1248 { 1249 - struct serio *serio; 1250 1251 - up->serio = serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 1252 - if (serio) { 1253 - memset(serio, 0, sizeof(*serio)); 1254 1255 - serio->port_data = up; 1256 - 1257 - serio->id.type = SERIO_RS232; 1258 - if (channel == KEYBOARD_LINE) { 1259 - serio->id.proto = SERIO_SUNKBD; 1260 - strlcpy(serio->name, "zskbd", sizeof(serio->name)); 1261 - } else { 1262 - serio->id.proto = SERIO_SUN; 1263 - serio->id.extra = 1; 1264 - strlcpy(serio->name, "zsms", sizeof(serio->name)); 1265 - } 1266 - strlcpy(serio->phys, 1267 - (channel == KEYBOARD_LINE ? "zs/serio0" : "zs/serio1"), 1268 - sizeof(serio->phys)); 1269 - 1270 - serio->write = sunzilog_serio_write; 1271 - serio->open = sunzilog_serio_open; 1272 - serio->close = sunzilog_serio_close; 1273 - 1274 - serio_register_port(serio); 1275 } else { 1276 - printk(KERN_WARNING "zs%d: not enough memory for serio port\n", 1277 - channel); 1278 } 1279 } 1280 #endif 1281 1282 - static void __init sunzilog_init_hw(void) 1283 { 1284 - int i; 1285 1286 - for (i = 0; i < NUM_CHANNELS; i++) { 1287 - struct uart_sunzilog_port *up = &sunzilog_port_table[i]; 1288 - struct zilog_channel __iomem *channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 1289 - unsigned long flags; 1290 - int baud, brg; 1291 1292 - spin_lock_irqsave(&up->port.lock, flags); 1293 1294 - if (ZS_IS_CHANNEL_A(up)) { 1295 - write_zsreg(channel, R9, FHWRES); 1296 - ZSDELAY_LONG(); 1297 - (void) read_zsreg(channel, R0); 1298 - } 1299 1300 - if (i == KEYBOARD_LINE || i == MOUSE_LINE) { 1301 - sunzilog_init_kbdms(up, i); 1302 - up->curregs[R9] |= (NV | MIE); 1303 - write_zsreg(channel, R9, up->curregs[R9]); 1304 - } else { 1305 - /* Normal serial TTY. */ 1306 - up->parity_mask = 0xff; 1307 - up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB; 1308 - up->curregs[R4] = PAR_EVEN | X16CLK | SB1; 1309 - up->curregs[R3] = RxENAB | Rx8; 1310 - up->curregs[R5] = TxENAB | Tx8; 1311 - up->curregs[R9] = NV | MIE; 1312 - up->curregs[R10] = NRZ; 1313 - up->curregs[R11] = TCBR | RCBR; 1314 - baud = 9600; 1315 - brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); 1316 - up->curregs[R12] = (brg & 0xff); 1317 - up->curregs[R13] = (brg >> 8) & 0xff; 1318 - up->curregs[R14] = BRSRC | BRENAB; 1319 - __load_zsregs(channel, up->curregs); 1320 - write_zsreg(channel, R9, up->curregs[R9]); 1321 - } 1322 - 1323 - spin_unlock_irqrestore(&up->port.lock, flags); 1324 1325 #ifdef CONFIG_SERIO 1326 - if (i == KEYBOARD_LINE || i == MOUSE_LINE) 1327 - sunzilog_register_serio(up, i); 1328 #endif 1329 - } 1330 } 1331 1332 - static struct zilog_layout __iomem * __init get_zs(int chip, int node); 1333 - 1334 - static void __init sunzilog_scan_probe(struct zs_probe_scan *t, int node) 1335 { 1336 - sunzilog_chip_regs[t->devices] = get_zs(t->devices, node); 1337 - t->devices++; 1338 - } 1339 - 1340 - static int __init sunzilog_ports_init(void) 1341 - { 1342 - struct zs_probe_scan scan; 1343 int ret; 1344 - int uart_count; 1345 - int i; 1346 1347 - printk(KERN_DEBUG "SunZilog: %d chips.\n", NUM_SUNZILOG); 1348 1349 - scan.scanner = sunzilog_scan_probe; 1350 - scan.depth = 0; 1351 - scan.devices = 0; 1352 - sunzilog_scan(&scan, prom_getchild(prom_root_node)); 1353 - 1354 - sunzilog_prepare(); 1355 - 1356 - if (request_irq(zilog_irq, sunzilog_interrupt, SA_SHIRQ, 1357 - "SunZilog", sunzilog_irq_chain)) { 1358 - prom_printf("SunZilog: Unable to register zs interrupt handler.\n"); 1359 - prom_halt(); 1360 - } 1361 - 1362 - sunzilog_init_hw(); 1363 - 1364 - /* We can only init this once we have probed the Zilogs 1365 - * in the system. Do not count channels assigned to keyboards 1366 - * or mice when we are deciding how many ports to register. 1367 - */ 1368 - uart_count = 0; 1369 - for (i = 0; i < NUM_CHANNELS; i++) { 1370 - struct uart_sunzilog_port *up = &sunzilog_port_table[i]; 1371 - 1372 - if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) 1373 - continue; 1374 - 1375 - uart_count++; 1376 - } 1377 - 1378 - sunzilog_reg.nr = uart_count; 1379 - sunzilog_reg.minor = sunserial_current_minor; 1380 - 1381 - ret = uart_register_driver(&sunzilog_reg); 1382 - if (ret == 0) { 1383 - sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64; 1384 - sunzilog_reg.cons = SUNZILOG_CONSOLE(); 1385 - 1386 - sunserial_current_minor += uart_count; 1387 - 1388 - for (i = 0; i < NUM_CHANNELS; i++) { 1389 - struct uart_sunzilog_port *up = &sunzilog_port_table[i]; 1390 - 1391 - if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) 1392 - continue; 1393 - 1394 - if (uart_add_one_port(&sunzilog_reg, &up->port)) { 1395 - printk(KERN_ERR 1396 - "SunZilog: failed to add port zs%d\n", i); 1397 - } 1398 - } 1399 - } 1400 1401 return ret; 1402 } 1403 1404 - static void __init sunzilog_scan_count(struct zs_probe_scan *t, int node) 1405 { 1406 - t->devices++; 1407 - } 1408 1409 - static int __init sunzilog_ports_count(void) 1410 - { 1411 - struct zs_probe_scan scan; 1412 1413 - /* Sun4 Zilog setup is hard coded, no probing to do. */ 1414 - if (sparc_cpu_model == sun4) 1415 - return 2; 1416 1417 - scan.scanner = sunzilog_scan_count; 1418 - scan.depth = 0; 1419 - scan.devices = 0; 1420 1421 - sunzilog_scan(&scan, prom_getchild(prom_root_node)); 1422 1423 - return scan.devices; 1424 - } 1425 1426 - static int __init sunzilog_init(void) 1427 - { 1428 1429 - NUM_SUNZILOG = sunzilog_ports_count(); 1430 - if (NUM_SUNZILOG == 0) 1431 - return -ENODEV; 1432 1433 - sunzilog_alloc_tables(); 1434 - 1435 - sunzilog_ports_init(); 1436 1437 return 0; 1438 } 1439 1440 - static void __exit sunzilog_exit(void) 1441 { 1442 - int i; 1443 1444 - for (i = 0; i < NUM_CHANNELS; i++) { 1445 - struct uart_sunzilog_port *up = &sunzilog_port_table[i]; 1446 - 1447 - if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) { 1448 #ifdef CONFIG_SERIO 1449 - if (up->serio) { 1450 - serio_unregister_port(up->serio); 1451 - up->serio = NULL; 1452 - } 1453 #endif 1454 - } else 1455 - uart_remove_one_port(&sunzilog_reg, &up->port); 1456 } 1457 1458 - uart_unregister_driver(&sunzilog_reg); 1459 } 1460 1461 module_init(sunzilog_init);
··· 1 + /* sunzilog.c: Zilog serial driver for Sparc systems. 2 * 3 * Driver for Zilog serial chips found on Sun workstations and 4 * servers. This driver could actually be made more generic. ··· 10 * C. Dost, Pete Zaitcev, Ted Ts'o and Alex Buell for their 11 * work there. 12 * 13 + * Copyright (C) 2002, 2006 David S. Miller (davem@davemloft.net) 14 */ 15 16 #include <linux/config.h> ··· 38 39 #include <asm/io.h> 40 #include <asm/irq.h> 41 + #include <asm/prom.h> 42 + #include <asm/of_device.h> 43 44 #if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 45 #define SUPPORT_SYSRQ ··· 65 #define ZSDELAY() 66 #define ZSDELAY_LONG() 67 #define ZS_WSYNC(__channel) \ 68 + readb(&((__channel)->control)) 69 #endif 70 71 static int num_sunzilog; ··· 107 unsigned char prev_status; 108 109 #ifdef CONFIG_SERIO 110 + struct serio serio; 111 int serio_open; 112 #endif 113 }; ··· 138 { 139 unsigned char retval; 140 141 + writeb(reg, &channel->control); 142 ZSDELAY(); 143 + retval = readb(&channel->control); 144 ZSDELAY(); 145 146 return retval; ··· 149 static void write_zsreg(struct zilog_channel __iomem *channel, 150 unsigned char reg, unsigned char value) 151 { 152 + writeb(reg, &channel->control); 153 ZSDELAY(); 154 + writeb(value, &channel->control); 155 ZSDELAY(); 156 } 157 ··· 162 for (i = 0; i < 32; i++) { 163 unsigned char regval; 164 165 + regval = readb(&channel->control); 166 ZSDELAY(); 167 if (regval & Rx_CH_AV) 168 break; 169 170 regval = read_zsreg(channel, R1); 171 + readb(&channel->data); 172 ZSDELAY(); 173 174 if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) { 175 + writeb(ERR_RES, &channel->control); 176 ZSDELAY(); 177 ZS_WSYNC(channel); 178 } ··· 194 udelay(100); 195 } 196 197 + writeb(ERR_RES, &channel->control); 198 ZSDELAY(); 199 ZS_WSYNC(channel); 200 ··· 291 /* Stop-A is handled by drivers/char/keyboard.c now. */ 292 #ifdef CONFIG_SERIO 293 if (up->serio_open) 294 + serio_interrupt(&up->serio, ch, 0, regs); 295 #endif 296 } else if (ZS_IS_MOUSE(up)) { 297 int ret = suncore_mouse_baud_detection(ch, is_break); ··· 306 case 0: 307 #ifdef CONFIG_SERIO 308 if (up->serio_open) 309 + serio_interrupt(&up->serio, ch, 0, regs); 310 #endif 311 break; 312 }; ··· 330 331 r1 = read_zsreg(channel, R1); 332 if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) { 333 + writeb(ERR_RES, &channel->control); 334 ZSDELAY(); 335 ZS_WSYNC(channel); 336 } 337 338 + ch = readb(&channel->control); 339 ZSDELAY(); 340 341 /* This funny hack depends upon BRK_ABRT not interfering ··· 347 if (!(ch & Rx_CH_AV)) 348 break; 349 350 + ch = readb(&channel->data); 351 ZSDELAY(); 352 353 ch &= up->parity_mask; ··· 406 { 407 unsigned char status; 408 409 + status = readb(&channel->control); 410 ZSDELAY(); 411 412 + writeb(RES_EXT_INT, &channel->control); 413 ZSDELAY(); 414 ZS_WSYNC(channel); 415 ··· 421 * confusing the PROM. 422 */ 423 while (1) { 424 + status = readb(&channel->control); 425 ZSDELAY(); 426 if (!(status & BRK_ABRT)) 427 break; ··· 458 struct circ_buf *xmit; 459 460 if (ZS_IS_CONS(up)) { 461 + unsigned char status = readb(&channel->control); 462 ZSDELAY(); 463 464 /* TX still busy? Just wait for the next TX done interrupt. ··· 487 488 if (up->port.x_char) { 489 up->flags |= SUNZILOG_FLAG_TX_ACTIVE; 490 + writeb(up->port.x_char, &channel->data); 491 ZSDELAY(); 492 ZS_WSYNC(channel); 493 ··· 506 goto ack_tx_int; 507 508 up->flags |= SUNZILOG_FLAG_TX_ACTIVE; 509 + writeb(xmit->buf[xmit->tail], &channel->data); 510 ZSDELAY(); 511 ZS_WSYNC(channel); 512 ··· 519 return; 520 521 ack_tx_int: 522 + writeb(RES_Tx_P, &channel->control); 523 ZSDELAY(); 524 ZS_WSYNC(channel); 525 } ··· 540 /* Channel A */ 541 tty = NULL; 542 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) { 543 + writeb(RES_H_IUS, &channel->control); 544 ZSDELAY(); 545 ZS_WSYNC(channel); 546 ··· 563 spin_lock(&up->port.lock); 564 tty = NULL; 565 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { 566 + writeb(RES_H_IUS, &channel->control); 567 ZSDELAY(); 568 ZS_WSYNC(channel); 569 ··· 594 unsigned char status; 595 596 channel = ZILOG_CHANNEL_FROM_PORT(port); 597 + status = readb(&channel->control); 598 ZSDELAY(); 599 600 return status; ··· 682 up->flags |= SUNZILOG_FLAG_TX_ACTIVE; 683 up->flags &= ~SUNZILOG_FLAG_TX_STOPPED; 684 685 + status = readb(&channel->control); 686 ZSDELAY(); 687 688 /* TX busy? Just wait for the TX done interrupt. */ ··· 693 * IRQ sending engine. 694 */ 695 if (port->x_char) { 696 + writeb(port->x_char, &channel->data); 697 ZSDELAY(); 698 ZS_WSYNC(channel); 699 ··· 702 } else { 703 struct circ_buf *xmit = &port->info->xmit; 704 705 + writeb(xmit->buf[xmit->tail], &channel->data); 706 ZSDELAY(); 707 ZS_WSYNC(channel); 708 ··· 779 struct zilog_channel __iomem *channel; 780 781 channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 782 + up->prev_status = readb(&channel->control); 783 784 /* Enable receiver and transmitter. */ 785 up->curregs[R3] |= RxENAB; ··· 963 964 static const char *sunzilog_type(struct uart_port *port) 965 { 966 + return "zs"; 967 } 968 969 /* We do not request/release mappings of the registers here, this ··· 1012 static struct zilog_layout __iomem **sunzilog_chip_regs; 1013 1014 static struct uart_sunzilog_port *sunzilog_irq_chain; 1015 1016 static struct uart_driver sunzilog_reg = { 1017 .owner = THIS_MODULE, ··· 1021 .major = TTY_MAJOR, 1022 }; 1023 1024 + static int __init sunzilog_alloc_tables(void) 1025 { 1026 + struct uart_sunzilog_port *up; 1027 + unsigned long size; 1028 + int i; 1029 1030 + size = NUM_CHANNELS * sizeof(struct uart_sunzilog_port); 1031 + sunzilog_port_table = kzalloc(size, GFP_KERNEL); 1032 + if (!sunzilog_port_table) 1033 + return -ENOMEM; 1034 1035 + for (i = 0; i < NUM_CHANNELS; i++) { 1036 + up = &sunzilog_port_table[i]; 1037 + 1038 + spin_lock_init(&up->port.lock); 1039 + 1040 + if (i == 0) 1041 + sunzilog_irq_chain = up; 1042 + 1043 + if (i < NUM_CHANNELS - 1) 1044 + up->next = up + 1; 1045 + else 1046 + up->next = NULL; 1047 + } 1048 + 1049 + size = NUM_SUNZILOG * sizeof(struct zilog_layout __iomem *); 1050 + sunzilog_chip_regs = kzalloc(size, GFP_KERNEL); 1051 + if (!sunzilog_chip_regs) { 1052 + kfree(sunzilog_port_table); 1053 + sunzilog_irq_chain = NULL; 1054 + return -ENOMEM; 1055 + } 1056 + 1057 + return 0; 1058 } 1059 1060 + static void sunzilog_free_tables(void) 1061 { 1062 + kfree(sunzilog_port_table); 1063 + sunzilog_irq_chain = NULL; 1064 + kfree(sunzilog_chip_regs); 1065 } 1066 1067 #define ZS_PUT_CHAR_MAX_DELAY 2000 /* 10 ms */ ··· 1260 * udelay with ZSDELAY as that is a NOP on some platforms. -DaveM 1261 */ 1262 do { 1263 + unsigned char val = readb(&channel->control); 1264 if (val & Tx_BUF_EMP) { 1265 ZSDELAY(); 1266 break; ··· 1268 udelay(5); 1269 } while (--loops); 1270 1271 + writeb(ch, &channel->data); 1272 ZSDELAY(); 1273 ZS_WSYNC(channel); 1274 } ··· 1385 .data = &sunzilog_reg, 1386 }; 1387 1388 static inline struct console *SUNZILOG_CONSOLE(void) 1389 { 1390 int i; ··· 1431 1432 #else 1433 #define SUNZILOG_CONSOLE() (NULL) 1434 #endif 1435 1436 static void __init sunzilog_init_kbdms(struct uart_sunzilog_port *up, int channel) 1437 { ··· 1539 up->cflag = B4800 | CS8 | CLOCAL | CREAD; 1540 baud = 4800; 1541 } 1542 1543 up->curregs[R15] = BRKIE; 1544 brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); ··· 1552 #ifdef CONFIG_SERIO 1553 static void __init sunzilog_register_serio(struct uart_sunzilog_port *up, int channel) 1554 { 1555 + struct serio *serio = &up->serio; 1556 1557 + serio->port_data = up; 1558 1559 + serio->id.type = SERIO_RS232; 1560 + if (channel == KEYBOARD_LINE) { 1561 + serio->id.proto = SERIO_SUNKBD; 1562 + strlcpy(serio->name, "zskbd", sizeof(serio->name)); 1563 } else { 1564 + serio->id.proto = SERIO_SUN; 1565 + serio->id.extra = 1; 1566 + strlcpy(serio->name, "zsms", sizeof(serio->name)); 1567 } 1568 + strlcpy(serio->phys, 1569 + (channel == KEYBOARD_LINE ? "zs/serio0" : "zs/serio1"), 1570 + sizeof(serio->phys)); 1571 + 1572 + serio->write = sunzilog_serio_write; 1573 + serio->open = sunzilog_serio_open; 1574 + serio->close = sunzilog_serio_close; 1575 + serio->dev.parent = up->port.dev; 1576 + 1577 + serio_register_port(serio); 1578 } 1579 #endif 1580 1581 + static void __init sunzilog_init_hw(struct uart_sunzilog_port *up) 1582 { 1583 + struct zilog_channel __iomem *channel; 1584 + unsigned long flags; 1585 + int baud, brg; 1586 1587 + channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 1588 1589 + spin_lock_irqsave(&up->port.lock, flags); 1590 + if (ZS_IS_CHANNEL_A(up)) { 1591 + write_zsreg(channel, R9, FHWRES); 1592 + ZSDELAY_LONG(); 1593 + (void) read_zsreg(channel, R0); 1594 + } 1595 1596 + if (up->port.line == KEYBOARD_LINE || 1597 + up->port.line == MOUSE_LINE) { 1598 + sunzilog_init_kbdms(up, up->port.line); 1599 + up->curregs[R9] |= (NV | MIE); 1600 + write_zsreg(channel, R9, up->curregs[R9]); 1601 + } else { 1602 + /* Normal serial TTY. */ 1603 + up->parity_mask = 0xff; 1604 + up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB; 1605 + up->curregs[R4] = PAR_EVEN | X16CLK | SB1; 1606 + up->curregs[R3] = RxENAB | Rx8; 1607 + up->curregs[R5] = TxENAB | Tx8; 1608 + up->curregs[R9] = NV | MIE; 1609 + up->curregs[R10] = NRZ; 1610 + up->curregs[R11] = TCBR | RCBR; 1611 + baud = 9600; 1612 + brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); 1613 + up->curregs[R12] = (brg & 0xff); 1614 + up->curregs[R13] = (brg >> 8) & 0xff; 1615 + up->curregs[R14] = BRSRC | BRENAB; 1616 + __load_zsregs(channel, up->curregs); 1617 + write_zsreg(channel, R9, up->curregs[R9]); 1618 + } 1619 1620 + spin_unlock_irqrestore(&up->port.lock, flags); 1621 1622 #ifdef CONFIG_SERIO 1623 + if (up->port.line == KEYBOARD_LINE || up->port.line == MOUSE_LINE) 1624 + sunzilog_register_serio(up, up->port.line); 1625 #endif 1626 } 1627 1628 + static int __devinit zs_get_instance(struct device_node *dp) 1629 { 1630 int ret; 1631 1632 + ret = of_getintprop_default(dp, "slave", -1); 1633 + if (ret != -1) 1634 + return ret; 1635 1636 + if (of_find_property(dp, "keyboard", NULL)) 1637 + ret = 1; 1638 + else 1639 + ret = 0; 1640 1641 return ret; 1642 } 1643 1644 + static int __devinit zs_probe(struct of_device *dev, const struct of_device_id *match) 1645 { 1646 + static int zilog_irq = -1; 1647 + struct of_device *op = to_of_device(&dev->dev); 1648 + struct uart_sunzilog_port *up; 1649 + struct zilog_layout __iomem *rp; 1650 + int inst = zs_get_instance(dev->node); 1651 + int err; 1652 1653 + sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0, 1654 + sizeof(struct zilog_layout), 1655 + "zs"); 1656 + if (!sunzilog_chip_regs[inst]) 1657 + return -ENOMEM; 1658 1659 + rp = sunzilog_chip_regs[inst]; 1660 1661 + if (zilog_irq == -1) { 1662 + zilog_irq = op->irqs[0]; 1663 + err = request_irq(zilog_irq, sunzilog_interrupt, SA_SHIRQ, 1664 + "zs", sunzilog_irq_chain); 1665 + if (err) { 1666 + of_iounmap(rp, sizeof(struct zilog_layout)); 1667 1668 + return err; 1669 + } 1670 + } 1671 1672 + up = &sunzilog_port_table[inst * 2]; 1673 1674 + /* Channel A */ 1675 + up[0].port.mapbase = op->resource[0].start + 0x00; 1676 + up[0].port.membase = (void __iomem *) &rp->channelA; 1677 + up[0].port.iotype = UPIO_MEM; 1678 + up[0].port.irq = op->irqs[0]; 1679 + up[0].port.uartclk = ZS_CLOCK; 1680 + up[0].port.fifosize = 1; 1681 + up[0].port.ops = &sunzilog_pops; 1682 + up[0].port.type = PORT_SUNZILOG; 1683 + up[0].port.flags = 0; 1684 + up[0].port.line = (inst * 2) + 0; 1685 + up[0].port.dev = &op->dev; 1686 + up[0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A; 1687 + if (inst == 1) 1688 + up[0].flags |= SUNZILOG_FLAG_CONS_KEYB; 1689 + sunzilog_init_hw(&up[0]); 1690 1691 + /* Channel B */ 1692 + up[1].port.mapbase = op->resource[0].start + 0x04; 1693 + up[1].port.membase = (void __iomem *) &rp->channelB; 1694 + up[1].port.iotype = UPIO_MEM; 1695 + up[1].port.irq = op->irqs[0]; 1696 + up[1].port.uartclk = ZS_CLOCK; 1697 + up[1].port.fifosize = 1; 1698 + up[1].port.ops = &sunzilog_pops; 1699 + up[1].port.type = PORT_SUNZILOG; 1700 + up[1].port.flags = 0; 1701 + up[1].port.line = (inst * 2) + 1; 1702 + up[1].port.dev = &op->dev; 1703 + up[1].flags |= 0; 1704 + if (inst == 1) 1705 + up[1].flags |= SUNZILOG_FLAG_CONS_MOUSE; 1706 + sunzilog_init_hw(&up[1]); 1707 1708 + if (inst != 1) { 1709 + err = uart_add_one_port(&sunzilog_reg, &up[0].port); 1710 + if (err) { 1711 + of_iounmap(rp, sizeof(struct zilog_layout)); 1712 + return err; 1713 + } 1714 + err = uart_add_one_port(&sunzilog_reg, &up[1].port); 1715 + if (err) { 1716 + uart_remove_one_port(&sunzilog_reg, &up[0].port); 1717 + of_iounmap(rp, sizeof(struct zilog_layout)); 1718 + return err; 1719 + } 1720 + } 1721 1722 return 0; 1723 } 1724 1725 + static int __devexit zs_remove(struct of_device *dev) 1726 { 1727 + struct uart_sunzilog_port *up = dev_get_drvdata(&dev->dev); 1728 + struct zilog_channel __iomem *channel; 1729 1730 + if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) { 1731 #ifdef CONFIG_SERIO 1732 + serio_unregister_port(&up->serio); 1733 #endif 1734 + } else 1735 + uart_remove_one_port(&sunzilog_reg, &up->port); 1736 + 1737 + channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 1738 + 1739 + of_iounmap(channel, sizeof(struct zilog_channel)); 1740 + 1741 + return 0; 1742 + } 1743 + 1744 + static struct of_device_id zs_match[] = { 1745 + { 1746 + .name = "zs", 1747 + }, 1748 + {}, 1749 + }; 1750 + MODULE_DEVICE_TABLE(of, zs_match); 1751 + 1752 + static struct of_platform_driver zs_driver = { 1753 + .name = "zs", 1754 + .match_table = zs_match, 1755 + .probe = zs_probe, 1756 + .remove = __devexit_p(zs_remove), 1757 + }; 1758 + 1759 + static int __init sunzilog_init(void) 1760 + { 1761 + struct device_node *dp; 1762 + int err; 1763 + 1764 + NUM_SUNZILOG = 0; 1765 + for_each_node_by_name(dp, "zs") 1766 + NUM_SUNZILOG++; 1767 + 1768 + if (NUM_SUNZILOG) { 1769 + int uart_count; 1770 + 1771 + err = sunzilog_alloc_tables(); 1772 + if (err) 1773 + return err; 1774 + 1775 + /* Subtract 1 for keyboard, 1 for mouse. */ 1776 + uart_count = (NUM_SUNZILOG * 2) - 2; 1777 + 1778 + sunzilog_reg.nr = uart_count; 1779 + sunzilog_reg.minor = sunserial_current_minor; 1780 + err = uart_register_driver(&sunzilog_reg); 1781 + if (err) { 1782 + sunzilog_free_tables(); 1783 + return err; 1784 + } 1785 + sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64; 1786 + sunzilog_reg.cons = SUNZILOG_CONSOLE(); 1787 + 1788 + sunserial_current_minor += uart_count; 1789 } 1790 1791 + return of_register_driver(&zs_driver, &of_bus_type); 1792 + } 1793 + 1794 + static void __exit sunzilog_exit(void) 1795 + { 1796 + of_unregister_driver(&zs_driver); 1797 + 1798 + if (NUM_SUNZILOG) { 1799 + uart_unregister_driver(&sunzilog_reg); 1800 + sunzilog_free_tables(); 1801 + } 1802 } 1803 1804 module_init(sunzilog_init);