legacy_serial.c 19 KB

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