Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Feb 10-13, 2025
Register
Loading...
Note: File does not exist in v6.8.
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * The platform specific code for virtex devices since a boot loader is not
 4 * always used.
 5 *
 6 * (C) Copyright 2008 Xilinx, Inc.
 7 */
 8
 9#include "ops.h"
10#include "io.h"
11#include "stdio.h"
12
13#define UART_DLL		0	/* Out: Divisor Latch Low */
14#define UART_DLM		1	/* Out: Divisor Latch High */
15#define UART_FCR		2	/* Out: FIFO Control Register */
16#define UART_FCR_CLEAR_RCVR 	0x02 	/* Clear the RCVR FIFO */
17#define UART_FCR_CLEAR_XMIT	0x04 	/* Clear the XMIT FIFO */
18#define UART_LCR		3	/* Out: Line Control Register */
19#define UART_MCR		4	/* Out: Modem Control Register */
20#define UART_MCR_RTS		0x02 	/* RTS complement */
21#define UART_MCR_DTR		0x01 	/* DTR complement */
22#define UART_LCR_DLAB		0x80 	/* Divisor latch access bit */
23#define UART_LCR_WLEN8		0x03 	/* Wordlength: 8 bits */
24
25static int virtex_ns16550_console_init(void *devp)
26{
27	unsigned char *reg_base;
28	u32 reg_shift, reg_offset, clk, spd;
29	u16 divisor;
30	int n;
31
32	if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1)
33		return -1;
34
35	n = getprop(devp, "reg-offset", &reg_offset, sizeof(reg_offset));
36	if (n == sizeof(reg_offset))
37		reg_base += reg_offset;
38
39	n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift));
40	if (n != sizeof(reg_shift))
41		reg_shift = 0;
42
43	n = getprop(devp, "current-speed", (void *)&spd, sizeof(spd));
44	if (n != sizeof(spd))
45		spd = 9600;
46
47	/* should there be a default clock rate?*/
48	n = getprop(devp, "clock-frequency", (void *)&clk, sizeof(clk));
49	if (n != sizeof(clk))
50		return -1;
51
52	divisor = clk / (16 * spd);
53
54	/* Access baud rate */
55	out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_DLAB);
56
57	/* Baud rate based on input clock */
58	out_8(reg_base + (UART_DLL << reg_shift), divisor & 0xFF);
59	out_8(reg_base + (UART_DLM << reg_shift), divisor >> 8);
60
61	/* 8 data, 1 stop, no parity */
62	out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_WLEN8);
63
64	/* RTS/DTR */
65	out_8(reg_base + (UART_MCR << reg_shift), UART_MCR_RTS | UART_MCR_DTR);
66
67	/* Clear transmitter and receiver */
68	out_8(reg_base + (UART_FCR << reg_shift),
69				UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR);
70	return 0;
71}
72
73/* For virtex, the kernel may be loaded without using a bootloader and if so
74   some UARTs need more setup than is provided in the normal console init
75*/
76int platform_specific_init(void)
77{
78	void *devp;
79	char devtype[MAX_PROP_LEN];
80	char path[MAX_PATH_LEN];
81
82	devp = finddevice("/chosen");
83	if (devp == NULL)
84		return -1;
85
86	if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) {
87		devp = finddevice(path);
88		if (devp == NULL)
89			return -1;
90
91		if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
92				&& !strcmp(devtype, "serial")
93				&& (dt_is_compatible(devp, "ns16550")))
94				virtex_ns16550_console_init(devp);
95	}
96	return 0;
97}