legacy_serial.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/serial.h>
  4. #include <linux/serial_8250.h>
  5. #include <linux/serial_core.h>
  6. #include <linux/console.h>
  7. #include <linux/pci.h>
  8. #include <linux/of_address.h>
  9. #include <linux/of_device.h>
  10. #include <linux/serial_reg.h>
  11. #include <asm/io.h>
  12. #include <asm/mmu.h>
  13. #include <asm/prom.h>
  14. #include <asm/serial.h>
  15. #include <asm/udbg.h>
  16. #include <asm/pci-bridge.h>
  17. #include <asm/ppc-pci.h>
  18. #undef DEBUG
  19. #ifdef DEBUG
  20. #define DBG(fmt...) do { printk(fmt); } while(0)
  21. #else
  22. #define DBG(fmt...) do { } while(0)
  23. #endif
  24. #define MAX_LEGACY_SERIAL_PORTS 8
  25. static struct plat_serial8250_port
  26. legacy_serial_ports[MAX_LEGACY_SERIAL_PORTS+1];
  27. static struct legacy_serial_info {
  28. struct device_node *np;
  29. unsigned int speed;
  30. unsigned int clock;
  31. int irq_check_parent;
  32. phys_addr_t taddr;
  33. } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
  34. static const struct of_device_id legacy_serial_parents[] __initconst = {
  35. {.type = "soc",},
  36. {.type = "tsi-bridge",},
  37. {.type = "opb", },
  38. {.compatible = "ibm,opb",},
  39. {.compatible = "simple-bus",},
  40. {.compatible = "wrs,epld-localbus",},
  41. {},
  42. };
  43. static unsigned int legacy_serial_count;
  44. static int legacy_serial_console = -1;
  45. static const upf_t legacy_port_flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
  46. UPF_SHARE_IRQ | UPF_FIXED_PORT;
  47. static unsigned int tsi_serial_in(struct uart_port *p, int offset)
  48. {
  49. unsigned int tmp;
  50. offset = offset << p->regshift;
  51. if (offset == UART_IIR) {
  52. tmp = readl(p->membase + (UART_IIR & ~3));
  53. return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */
  54. } else
  55. return readb(p->membase + offset);
  56. }
  57. static void tsi_serial_out(struct uart_port *p, int offset, int value)
  58. {
  59. offset = offset << p->regshift;
  60. if (!((offset == UART_IER) && (value & UART_IER_UUE)))
  61. writeb(value, p->membase + offset);
  62. }
  63. static int __init add_legacy_port(struct device_node *np, int want_index,
  64. int iotype, phys_addr_t base,
  65. phys_addr_t taddr, unsigned long irq,
  66. upf_t flags, int irq_check_parent)
  67. {
  68. const __be32 *clk, *spd, *rs;
  69. u32 clock = BASE_BAUD * 16;
  70. u32 shift = 0;
  71. int index;
  72. /* get clock freq. if present */
  73. clk = of_get_property(np, "clock-frequency", NULL);
  74. if (clk && *clk)
  75. clock = be32_to_cpup(clk);
  76. /* get default speed if present */
  77. spd = of_get_property(np, "current-speed", NULL);
  78. /* get register shift if present */
  79. rs = of_get_property(np, "reg-shift", NULL);
  80. if (rs && *rs)
  81. shift = be32_to_cpup(rs);
  82. /* If we have a location index, then try to use it */
  83. if (want_index >= 0 && want_index < MAX_LEGACY_SERIAL_PORTS)
  84. index = want_index;
  85. else
  86. index = legacy_serial_count;
  87. /* if our index is still out of range, that mean that
  88. * array is full, we could scan for a free slot but that
  89. * make little sense to bother, just skip the port
  90. */
  91. if (index >= MAX_LEGACY_SERIAL_PORTS)
  92. return -1;
  93. if (index >= legacy_serial_count)
  94. legacy_serial_count = index + 1;
  95. /* Check if there is a port who already claimed our slot */
  96. if (legacy_serial_infos[index].np != NULL) {
  97. /* if we still have some room, move it, else override */
  98. if (legacy_serial_count < MAX_LEGACY_SERIAL_PORTS) {
  99. printk(KERN_DEBUG "Moved legacy port %d -> %d\n",
  100. index, legacy_serial_count);
  101. legacy_serial_ports[legacy_serial_count] =
  102. legacy_serial_ports[index];
  103. legacy_serial_infos[legacy_serial_count] =
  104. legacy_serial_infos[index];
  105. legacy_serial_count++;
  106. } else {
  107. printk(KERN_DEBUG "Replacing legacy port %d\n", index);
  108. }
  109. }
  110. /* Now fill the entry */
  111. memset(&legacy_serial_ports[index], 0,
  112. sizeof(struct plat_serial8250_port));
  113. if (iotype == UPIO_PORT)
  114. legacy_serial_ports[index].iobase = base;
  115. else
  116. legacy_serial_ports[index].mapbase = base;
  117. legacy_serial_ports[index].iotype = iotype;
  118. legacy_serial_ports[index].uartclk = clock;
  119. legacy_serial_ports[index].irq = irq;
  120. legacy_serial_ports[index].flags = flags;
  121. legacy_serial_ports[index].regshift = shift;
  122. legacy_serial_infos[index].taddr = taddr;
  123. legacy_serial_infos[index].np = of_node_get(np);
  124. legacy_serial_infos[index].clock = clock;
  125. legacy_serial_infos[index].speed = spd ? be32_to_cpup(spd) : 0;
  126. legacy_serial_infos[index].irq_check_parent = irq_check_parent;
  127. if (iotype == UPIO_TSI) {
  128. legacy_serial_ports[index].serial_in = tsi_serial_in;
  129. legacy_serial_ports[index].serial_out = tsi_serial_out;
  130. }
  131. printk(KERN_DEBUG "Found legacy serial port %d for %pOF\n",
  132. index, np);
  133. printk(KERN_DEBUG " %s=%llx, taddr=%llx, irq=%lx, clk=%d, speed=%d\n",
  134. (iotype == UPIO_PORT) ? "port" : "mem",
  135. (unsigned long long)base, (unsigned long long)taddr, irq,
  136. legacy_serial_ports[index].uartclk,
  137. legacy_serial_infos[index].speed);
  138. return index;
  139. }
  140. static int __init add_legacy_soc_port(struct device_node *np,
  141. struct device_node *soc_dev)
  142. {
  143. u64 addr;
  144. const __be32 *addrp;
  145. struct device_node *tsi = of_get_parent(np);
  146. /* We only support ports that have a clock frequency properly
  147. * encoded in the device-tree.
  148. */
  149. if (of_get_property(np, "clock-frequency", NULL) == NULL)
  150. return -1;
  151. /* if reg-offset don't try to use it */
  152. if ((of_get_property(np, "reg-offset", NULL) != NULL))
  153. return -1;
  154. /* if rtas uses this device, don't try to use it as well */
  155. if (of_get_property(np, "used-by-rtas", NULL) != NULL)
  156. return -1;
  157. /* Get the address */
  158. addrp = of_get_address(soc_dev, 0, NULL, NULL);
  159. if (addrp == NULL)
  160. return -1;
  161. addr = of_translate_address(soc_dev, addrp);
  162. if (addr == OF_BAD_ADDR)
  163. return -1;
  164. /* Add port, irq will be dealt with later. We passed a translated
  165. * IO port value. It will be fixed up later along with the irq
  166. */
  167. if (of_node_is_type(tsi, "tsi-bridge"))
  168. return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
  169. 0, legacy_port_flags, 0);
  170. else
  171. return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
  172. 0, legacy_port_flags, 0);
  173. }
  174. static int __init add_legacy_isa_port(struct device_node *np,
  175. struct device_node *isa_brg)
  176. {
  177. const __be32 *reg;
  178. const char *typep;
  179. int index = -1;
  180. u64 taddr;
  181. DBG(" -> add_legacy_isa_port(%pOF)\n", np);
  182. /* Get the ISA port number */
  183. reg = of_get_property(np, "reg", NULL);
  184. if (reg == NULL)
  185. return -1;
  186. /* Verify it's an IO port, we don't support anything else */
  187. if (!(be32_to_cpu(reg[0]) & 0x00000001))
  188. return -1;
  189. /* Now look for an "ibm,aix-loc" property that gives us ordering
  190. * if any...
  191. */
  192. typep = of_get_property(np, "ibm,aix-loc", NULL);
  193. /* If we have a location index, then use it */
  194. if (typep && *typep == 'S')
  195. index = simple_strtol(typep+1, NULL, 0) - 1;
  196. /* Translate ISA address. If it fails, we still register the port
  197. * with no translated address so that it can be picked up as an IO
  198. * port later by the serial driver
  199. *
  200. * Note: Don't even try on P8 lpc, we know it's not directly mapped
  201. */
  202. if (!of_device_is_compatible(isa_brg, "ibm,power8-lpc") ||
  203. of_get_property(isa_brg, "ranges", NULL)) {
  204. taddr = of_translate_address(np, reg);
  205. if (taddr == OF_BAD_ADDR)
  206. taddr = 0;
  207. } else
  208. taddr = 0;
  209. /* Add port, irq will be dealt with later */
  210. return add_legacy_port(np, index, UPIO_PORT, be32_to_cpu(reg[1]),
  211. taddr, 0, legacy_port_flags, 0);
  212. }
  213. #ifdef CONFIG_PCI
  214. static int __init add_legacy_pci_port(struct device_node *np,
  215. struct device_node *pci_dev)
  216. {
  217. u64 addr, base;
  218. const __be32 *addrp;
  219. unsigned int flags;
  220. int iotype, index = -1, lindex = 0;
  221. DBG(" -> add_legacy_pci_port(%pOF)\n", np);
  222. /* We only support ports that have a clock frequency properly
  223. * encoded in the device-tree (that is have an fcode). Anything
  224. * else can't be used that early and will be normally probed by
  225. * the generic 8250_pci driver later on. The reason is that 8250
  226. * compatible UARTs on PCI need all sort of quirks (port offsets
  227. * etc...) that this code doesn't know about
  228. */
  229. if (of_get_property(np, "clock-frequency", NULL) == NULL)
  230. return -1;
  231. /* Get the PCI address. Assume BAR 0 */
  232. addrp = of_get_pci_address(pci_dev, 0, NULL, &flags);
  233. if (addrp == NULL)
  234. return -1;
  235. /* We only support BAR 0 for now */
  236. iotype = (flags & IORESOURCE_MEM) ? UPIO_MEM : UPIO_PORT;
  237. addr = of_translate_address(pci_dev, addrp);
  238. if (addr == OF_BAD_ADDR)
  239. return -1;
  240. /* Set the IO base to the same as the translated address for MMIO,
  241. * or to the domain local IO base for PIO (it will be fixed up later)
  242. */
  243. if (iotype == UPIO_MEM)
  244. base = addr;
  245. else
  246. base = of_read_number(&addrp[2], 1);
  247. /* Try to guess an index... If we have subdevices of the pci dev,
  248. * we get to their "reg" property
  249. */
  250. if (np != pci_dev) {
  251. const __be32 *reg = of_get_property(np, "reg", NULL);
  252. if (reg && (be32_to_cpup(reg) < 4))
  253. index = lindex = be32_to_cpup(reg);
  254. }
  255. /* Local index means it's the Nth port in the PCI chip. Unfortunately
  256. * the offset to add here is device specific. We know about those
  257. * EXAR ports and we default to the most common case. If your UART
  258. * doesn't work for these settings, you'll have to add your own special
  259. * cases here
  260. */
  261. if (of_device_is_compatible(pci_dev, "pci13a8,152") ||
  262. of_device_is_compatible(pci_dev, "pci13a8,154") ||
  263. of_device_is_compatible(pci_dev, "pci13a8,158")) {
  264. addr += 0x200 * lindex;
  265. base += 0x200 * lindex;
  266. } else {
  267. addr += 8 * lindex;
  268. base += 8 * lindex;
  269. }
  270. /* Add port, irq will be dealt with later. We passed a translated
  271. * IO port value. It will be fixed up later along with the irq
  272. */
  273. return add_legacy_port(np, index, iotype, base, addr, 0,
  274. legacy_port_flags, np != pci_dev);
  275. }
  276. #endif
  277. static void __init setup_legacy_serial_console(int console)
  278. {
  279. struct legacy_serial_info *info = &legacy_serial_infos[console];
  280. struct plat_serial8250_port *port = &legacy_serial_ports[console];
  281. void __iomem *addr;
  282. unsigned int stride;
  283. stride = 1 << port->regshift;
  284. /* Check if a translated MMIO address has been found */
  285. if (info->taddr) {
  286. addr = ioremap(info->taddr, 0x1000);
  287. if (addr == NULL)
  288. return;
  289. udbg_uart_init_mmio(addr, stride);
  290. } else {
  291. /* Check if it's PIO and we support untranslated PIO */
  292. if (port->iotype == UPIO_PORT && isa_io_special)
  293. udbg_uart_init_pio(port->iobase, stride);
  294. else
  295. return;
  296. }
  297. /* Try to query the current speed */
  298. if (info->speed == 0)
  299. info->speed = udbg_probe_uart_speed(info->clock);
  300. /* Set it up */
  301. DBG("default console speed = %d\n", info->speed);
  302. udbg_uart_setup(info->speed, info->clock);
  303. }
  304. /*
  305. * This is called very early, as part of setup_system() or eventually
  306. * setup_arch(), basically before anything else in this file. This function
  307. * will try to build a list of all the available 8250-compatible serial ports
  308. * in the machine using the Open Firmware device-tree. It currently only deals
  309. * with ISA and PCI busses but could be extended. It allows a very early boot
  310. * console to be initialized, that list is also used later to provide 8250 with
  311. * the machine non-PCI ports and to properly pick the default console port
  312. */
  313. void __init find_legacy_serial_ports(void)
  314. {
  315. struct device_node *np, *stdout = NULL;
  316. const char *path;
  317. int index;
  318. DBG(" -> find_legacy_serial_port()\n");
  319. /* Now find out if one of these is out firmware console */
  320. path = of_get_property(of_chosen, "linux,stdout-path", NULL);
  321. if (path == NULL)
  322. path = of_get_property(of_chosen, "stdout-path", NULL);
  323. if (path != NULL) {
  324. stdout = of_find_node_by_path(path);
  325. if (stdout)
  326. DBG("stdout is %pOF\n", stdout);
  327. } else {
  328. DBG(" no linux,stdout-path !\n");
  329. }
  330. /* Iterate over all the 16550 ports, looking for known parents */
  331. for_each_compatible_node(np, "serial", "ns16550") {
  332. struct device_node *parent = of_get_parent(np);
  333. if (!parent)
  334. continue;
  335. if (of_match_node(legacy_serial_parents, parent) != NULL) {
  336. if (of_device_is_available(np)) {
  337. index = add_legacy_soc_port(np, np);
  338. if (index >= 0 && np == stdout)
  339. legacy_serial_console = index;
  340. }
  341. }
  342. of_node_put(parent);
  343. }
  344. /* Next, fill our array with ISA ports */
  345. for_each_node_by_type(np, "serial") {
  346. struct device_node *isa = of_get_parent(np);
  347. if (of_node_name_eq(isa, "isa") || of_node_name_eq(isa, "lpc")) {
  348. if (of_device_is_available(np)) {
  349. index = add_legacy_isa_port(np, isa);
  350. if (index >= 0 && np == stdout)
  351. legacy_serial_console = index;
  352. }
  353. }
  354. of_node_put(isa);
  355. }
  356. #ifdef CONFIG_PCI
  357. /* Next, try to locate PCI ports */
  358. for (np = NULL; (np = of_find_all_nodes(np));) {
  359. struct device_node *pci, *parent = of_get_parent(np);
  360. if (of_node_name_eq(parent, "isa")) {
  361. of_node_put(parent);
  362. continue;
  363. }
  364. if (!of_node_name_eq(np, "serial") &&
  365. !of_node_is_type(np, "serial")) {
  366. of_node_put(parent);
  367. continue;
  368. }
  369. /* Check for known pciclass, and also check whether we have
  370. * a device with child nodes for ports or not
  371. */
  372. if (of_device_is_compatible(np, "pciclass,0700") ||
  373. of_device_is_compatible(np, "pciclass,070002"))
  374. pci = np;
  375. else if (of_device_is_compatible(parent, "pciclass,0700") ||
  376. of_device_is_compatible(parent, "pciclass,070002"))
  377. pci = parent;
  378. else {
  379. of_node_put(parent);
  380. continue;
  381. }
  382. index = add_legacy_pci_port(np, pci);
  383. if (index >= 0 && np == stdout)
  384. legacy_serial_console = index;
  385. of_node_put(parent);
  386. }
  387. #endif
  388. DBG("legacy_serial_console = %d\n", legacy_serial_console);
  389. if (legacy_serial_console >= 0)
  390. setup_legacy_serial_console(legacy_serial_console);
  391. DBG(" <- find_legacy_serial_port()\n");
  392. }
  393. static struct platform_device serial_device = {
  394. .name = "serial8250",
  395. .id = PLAT8250_DEV_PLATFORM,
  396. .dev = {
  397. .platform_data = legacy_serial_ports,
  398. },
  399. };
  400. static void __init fixup_port_irq(int index,
  401. struct device_node *np,
  402. struct plat_serial8250_port *port)
  403. {
  404. unsigned int virq;
  405. DBG("fixup_port_irq(%d)\n", index);
  406. virq = irq_of_parse_and_map(np, 0);
  407. if (!virq && legacy_serial_infos[index].irq_check_parent) {
  408. np = of_get_parent(np);
  409. if (np == NULL)
  410. return;
  411. virq = irq_of_parse_and_map(np, 0);
  412. of_node_put(np);
  413. }
  414. if (!virq)
  415. return;
  416. port->irq = virq;
  417. #ifdef CONFIG_SERIAL_8250_FSL
  418. if (of_device_is_compatible(np, "fsl,ns16550")) {
  419. port->handle_irq = fsl8250_handle_irq;
  420. port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE);
  421. }
  422. #endif
  423. }
  424. static void __init fixup_port_pio(int index,
  425. struct device_node *np,
  426. struct plat_serial8250_port *port)
  427. {
  428. #ifdef CONFIG_PCI
  429. struct pci_controller *hose;
  430. DBG("fixup_port_pio(%d)\n", index);
  431. hose = pci_find_hose_for_OF_device(np);
  432. if (hose) {
  433. unsigned long offset = (unsigned long)hose->io_base_virt -
  434. #ifdef CONFIG_PPC64
  435. pci_io_base;
  436. #else
  437. isa_io_base;
  438. #endif
  439. DBG("port %d, IO %lx -> %lx\n",
  440. index, port->iobase, port->iobase + offset);
  441. port->iobase += offset;
  442. }
  443. #endif
  444. }
  445. static void __init fixup_port_mmio(int index,
  446. struct device_node *np,
  447. struct plat_serial8250_port *port)
  448. {
  449. DBG("fixup_port_mmio(%d)\n", index);
  450. port->membase = ioremap(port->mapbase, 0x100);
  451. }
  452. /*
  453. * This is called as an arch initcall, hopefully before the PCI bus is
  454. * probed and/or the 8250 driver loaded since we need to register our
  455. * platform devices before 8250 PCI ones are detected as some of them
  456. * must properly "override" the platform ones.
  457. *
  458. * This function fixes up the interrupt value for platform ports as it
  459. * couldn't be done earlier before interrupt maps have been parsed. It
  460. * also "corrects" the IO address for PIO ports for the same reason,
  461. * since earlier, the PHBs virtual IO space wasn't assigned yet. It then
  462. * registers all those platform ports for use by the 8250 driver when it
  463. * finally loads.
  464. */
  465. static int __init serial_dev_init(void)
  466. {
  467. int i;
  468. if (legacy_serial_count == 0)
  469. return -ENODEV;
  470. /*
  471. * Before we register the platform serial devices, we need
  472. * to fixup their interrupts and their IO ports.
  473. */
  474. DBG("Fixing serial ports interrupts and IO ports ...\n");
  475. for (i = 0; i < legacy_serial_count; i++) {
  476. struct plat_serial8250_port *port = &legacy_serial_ports[i];
  477. struct device_node *np = legacy_serial_infos[i].np;
  478. if (!port->irq)
  479. fixup_port_irq(i, np, port);
  480. if (port->iotype == UPIO_PORT)
  481. fixup_port_pio(i, np, port);
  482. if ((port->iotype == UPIO_MEM) || (port->iotype == UPIO_TSI))
  483. fixup_port_mmio(i, np, port);
  484. }
  485. DBG("Registering platform serial ports\n");
  486. return platform_device_register(&serial_device);
  487. }
  488. device_initcall(serial_dev_init);
  489. #ifdef CONFIG_SERIAL_8250_CONSOLE
  490. /*
  491. * This is called very early, as part of console_init() (typically just after
  492. * time_init()). This function is respondible for trying to find a good
  493. * default console on serial ports. It tries to match the open firmware
  494. * default output with one of the available serial console drivers that have
  495. * been probed earlier by find_legacy_serial_ports()
  496. */
  497. static int __init check_legacy_serial_console(void)
  498. {
  499. struct device_node *prom_stdout = NULL;
  500. int i, speed = 0, offset = 0;
  501. const char *name;
  502. const __be32 *spd;
  503. DBG(" -> check_legacy_serial_console()\n");
  504. /* The user has requested a console so this is already set up. */
  505. if (strstr(boot_command_line, "console=")) {
  506. DBG(" console was specified !\n");
  507. return -EBUSY;
  508. }
  509. if (!of_chosen) {
  510. DBG(" of_chosen is NULL !\n");
  511. return -ENODEV;
  512. }
  513. if (legacy_serial_console < 0) {
  514. DBG(" legacy_serial_console not found !\n");
  515. return -ENODEV;
  516. }
  517. /* We are getting a weird phandle from OF ... */
  518. /* ... So use the full path instead */
  519. name = of_get_property(of_chosen, "linux,stdout-path", NULL);
  520. if (name == NULL)
  521. name = of_get_property(of_chosen, "stdout-path", NULL);
  522. if (name == NULL) {
  523. DBG(" no stdout-path !\n");
  524. return -ENODEV;
  525. }
  526. prom_stdout = of_find_node_by_path(name);
  527. if (!prom_stdout) {
  528. DBG(" can't find stdout package %s !\n", name);
  529. return -ENODEV;
  530. }
  531. DBG("stdout is %pOF\n", prom_stdout);
  532. name = of_get_property(prom_stdout, "name", NULL);
  533. if (!name) {
  534. DBG(" stdout package has no name !\n");
  535. goto not_found;
  536. }
  537. spd = of_get_property(prom_stdout, "current-speed", NULL);
  538. if (spd)
  539. speed = be32_to_cpup(spd);
  540. if (strcmp(name, "serial") != 0)
  541. goto not_found;
  542. /* Look for it in probed array */
  543. for (i = 0; i < legacy_serial_count; i++) {
  544. if (prom_stdout != legacy_serial_infos[i].np)
  545. continue;
  546. offset = i;
  547. speed = legacy_serial_infos[i].speed;
  548. break;
  549. }
  550. if (i >= legacy_serial_count)
  551. goto not_found;
  552. of_node_put(prom_stdout);
  553. DBG("Found serial console at ttyS%d\n", offset);
  554. if (speed) {
  555. static char __initdata opt[16];
  556. sprintf(opt, "%d", speed);
  557. return add_preferred_console("ttyS", offset, opt);
  558. } else
  559. return add_preferred_console("ttyS", offset, NULL);
  560. not_found:
  561. DBG("No preferred console found !\n");
  562. of_node_put(prom_stdout);
  563. return -ENODEV;
  564. }
  565. console_initcall(check_legacy_serial_console);
  566. #endif /* CONFIG_SERIAL_8250_CONSOLE */