// SPDX-License-Identifier: GPL-2.0 /* * Freescale QUICC Engine UART device driver * * Author: Timur Tabi <timur@freescale.com> * * Copyright 2007 Freescale Semiconductor, Inc. * * This driver adds support for UART devices via Freescale's QUICC Engine * found on some Freescale SOCs. * * If Soft-UART support is needed but not already present, then this driver * will request and upload the "Soft-UART" microcode upon probe. The * filename of the microcode should be fsl_qe_ucode_uart_X_YZ.bin, where "X" * is the name of the SOC (e.g. 8323), and YZ is the revision of the SOC, * (e.g. "11" for 1.1).
*/
/* * The GUMR flag for Soft UART. This would normally be defined in qe.h, * but Soft-UART is a hack and we want to keep everything related to it in * this file.
*/ #define UCC_SLOW_GUMR_H_SUART 0x00004000 /* Soft-UART */
/* * soft_uart is 1 if we need to use Soft-UART mode
*/ staticint soft_uart; /* * firmware_loaded is 1 if the firmware has been loaded, 0 otherwise.
*/ staticint firmware_loaded;
/* Enable this macro to configure all serial ports in internal loopback
mode */ /* #define LOOPBACK */
/* The major and minor device numbers are defined in * Documentation/admin-guide/devices.txt. For the QE * UART, we have major number 204 and minor numbers 46 - 49, which are the * same as for the CPM2. This decision was made because no Freescale part * has both a CPM and a QE.
*/ #define SERIAL_QE_MAJOR 204 #define SERIAL_QE_MINOR 46
/* Since we only have minor numbers 46 - 49, there is a hard limit of 4 ports */ #define UCC_MAX_UART 4
/* The number of buffer descriptors for receiving characters. */ #define RX_NUM_FIFO 4
/* The number of buffer descriptors for transmitting characters. */ #define TX_NUM_FIFO 4
/* The maximum size of the character buffer for a single RX BD. */ #define RX_BUF_SIZE 32
/* The maximum size of the character buffer for a single TX BD. */ #define TX_BUF_SIZE 32
/* * The number of jiffies to wait after receiving a close command before the * device is actually closed. This allows the last few characters to be * sent over the wire.
*/ #define UCC_WAIT_CLOSING 100
struct ucc_uart_pram { struct ucc_slow_pram common;
u8 res1[8]; /* reserved */
__be16 maxidl; /* Maximum idle chars */
__be16 idlc; /* temp idle counter */
__be16 brkcr; /* Break count register */
__be16 parec; /* receive parity error counter */
__be16 frmec; /* receive framing error counter */
__be16 nosec; /* receive noise counter */
__be16 brkec; /* receive break condition counter */
__be16 brkln; /* last received break length */
__be16 uaddr[2]; /* UART address character 1 & 2 */
__be16 rtemp; /* Temp storage */
__be16 toseq; /* Transmit out of sequence char */
__be16 cchars[8]; /* control characters 1-8 */
__be16 rccm; /* receive control character mask */
__be16 rccr; /* receive control character register */
__be16 rlbc; /* receive last break character */
__be16 res2; /* reserved */
__be32 res3; /* reserved, should be cleared */
u8 res4; /* reserved, should be cleared */
u8 res5[3]; /* reserved, should be cleared */
__be32 res6; /* reserved, should be cleared */
__be32 res7; /* reserved, should be cleared */
__be32 res8; /* reserved, should be cleared */
__be32 res9; /* reserved, should be cleared */
__be32 res10; /* reserved, should be cleared */
__be32 res11; /* reserved, should be cleared */
__be32 res12; /* reserved, should be cleared */
__be32 res13; /* reserved, should be cleared */ /* The rest is for Soft-UART only */
__be16 supsmr; /* 0x90, Shadow UPSMR */
__be16 res92; /* 0x92, reserved, initialize to 0 */
__be32 rx_state; /* 0x94, RX state, initialize to 0 */
__be32 rx_cnt; /* 0x98, RX count, initialize to 0 */
u8 rx_length; /* 0x9C, Char length, set to 1+CL+PEN+1+SL */
u8 rx_bitmark; /* 0x9D, reserved, initialize to 0 */
u8 rx_temp_dlst_qe; /* 0x9E, reserved, initialize to 0 */
u8 res14[0xBC - 0x9F]; /* reserved */
__be32 dump_ptr; /* 0xBC, Dump pointer */
__be32 rx_frame_rem; /* 0xC0, reserved, initialize to 0 */
u8 rx_frame_rem_size; /* 0xC4, reserved, initialize to 0 */
u8 tx_mode; /* 0xC5, mode, 0=AHDLC, 1=UART */
__be16 tx_state; /* 0xC6, TX state */
u8 res15[0xD0 - 0xC8]; /* reserved */
__be32 resD0; /* 0xD0, reserved, initialize to 0 */
u8 resD4; /* 0xD4, reserved, initialize to 0 */
__be16 resD5; /* 0xD5, reserved, initialize to 0 */
} __attribute__ ((packed));
/* * Virtual to physical address translation. * * Given the virtual address for a character buffer, this function returns * the physical (DMA) equivalent.
*/ staticinline dma_addr_t cpu2qe_addr(void *addr, struct uart_qe_port *qe_port)
{ if (likely((addr >= qe_port->bd_virt)) &&
(addr < (qe_port->bd_virt + qe_port->bd_size))) return qe_port->bd_dma_addr + (addr - qe_port->bd_virt);
/* * Return 1 if the QE is done transmitting all buffers for this port * * This function scans each BD in sequence. If we find a BD that is not * ready (READY=1), then we return 0 indicating that the QE is still sending * data. If we reach the last BD (WRAP=1), then we know we've scanned * the entire list, and all BDs are done.
*/ staticunsignedint qe_uart_tx_empty(struct uart_port *port)
{ struct uart_qe_port *qe_port =
container_of(port, struct uart_qe_port, port); struct qe_bd __iomem *bdp = qe_port->tx_bd_base;
while (1) { if (ioread16be(&bdp->status) & BD_SC_READY) /* This BD is not done, so return "not done" */ return 0;
if (ioread16be(&bdp->status) & BD_SC_WRAP) /* * This BD is done and it's the last one, so return * "done"
*/ return 1;
bdp++;
}
}
/* * Set the modem control lines * * Although the QE can control the modem control lines (e.g. CTS), we * don't need that support. This function must exist, however, otherwise * the kernel will panic.
*/ staticvoid qe_uart_set_mctrl(struct uart_port *port, unsignedint mctrl)
{
}
/* * Get the current modem control line status * * Although the QE can control the modem control lines (e.g. CTS), this * driver currently doesn't support that, so we always return Carrier * Detect, Data Set Ready, and Clear To Send.
*/ staticunsignedint qe_uart_get_mctrl(struct uart_port *port)
{ return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
}
/* * Disable the transmit interrupt. * * Although this function is called "stop_tx", it does not actually stop * transmission of data. Instead, it tells the QE to not generate an * interrupt when the UCC is finished sending characters.
*/ staticvoid qe_uart_stop_tx(struct uart_port *port)
{ struct uart_qe_port *qe_port =
container_of(port, struct uart_qe_port, port);
/* * Transmit as many characters to the HW as possible. * * This function will attempt to stuff of all the characters from the * kernel's transmit buffer into TX BDs. * * A return value of non-zero indicates that it successfully stuffed all * characters from the kernel buffer. * * A return value of zero indicates that there are still characters in the * kernel's buffer that have not been transmitted, but there are no more BDs * available. This function should be called again after a BD has been made * available.
*/ staticint qe_uart_tx_pump(struct uart_qe_port *qe_port)
{ struct qe_bd __iomem *bdp; unsignedchar *p; unsignedint count; struct uart_port *port = &qe_port->port; struct tty_port *tport = &port->state->port;
/* Handle xon/xoff */ if (port->x_char) { /* Pick next descriptor and fill from buffer */
bdp = qe_port->tx_cur;
p = qe2cpu_addr(ioread32be(&bdp->buf), qe_port);
*p++ = port->x_char;
iowrite16be(1, &bdp->length);
qe_setbits_be16(&bdp->status, BD_SC_READY); /* Get next BD. */ if (ioread16be(&bdp->status) & BD_SC_WRAP)
bdp = qe_port->tx_bd_base; else
bdp++;
qe_port->tx_cur = bdp;
port->icount.tx++;
port->x_char = 0; return 1;
}
if (kfifo_is_empty(&tport->xmit_fifo) || uart_tx_stopped(port)) {
qe_uart_stop_tx(port); return 0;
}
/* Pick next descriptor and fill from buffer */
bdp = qe_port->tx_cur;
while (!(ioread16be(&bdp->status) & BD_SC_READY) &&
!kfifo_is_empty(&tport->xmit_fifo)) {
p = qe2cpu_addr(ioread32be(&bdp->buf), qe_port);
count = uart_fifo_out(port, p, qe_port->tx_fifosize);
/* Get next BD. */ if (ioread16be(&bdp->status) & BD_SC_WRAP)
bdp = qe_port->tx_bd_base; else
bdp++;
}
qe_port->tx_cur = bdp;
if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
uart_write_wakeup(port);
if (kfifo_is_empty(&tport->xmit_fifo)) { /* The kernel buffer is empty, so turn off TX interrupts. We don't need to be told when the QE is finished transmitting
the data. */
qe_uart_stop_tx(port); return 0;
}
return 1;
}
/* * Start transmitting data * * This function will start transmitting any available data, if the port * isn't already transmitting data.
*/ staticvoid qe_uart_start_tx(struct uart_port *port)
{ struct uart_qe_port *qe_port =
container_of(port, struct uart_qe_port, port);
/* If we currently are transmitting, then just return */ if (ioread16be(&qe_port->uccp->uccm) & UCC_UART_UCCE_TX) return;
/* Otherwise, pump the port and start transmission */ if (qe_uart_tx_pump(qe_port))
qe_setbits_be16(&qe_port->uccp->uccm, UCC_UART_UCCE_TX);
}
/* Start or stop sending break signal * * This function controls the sending of a break signal. If break_state=1, * then we start sending a break signal. If break_state=0, then we stop * sending the break signal.
*/ staticvoid qe_uart_break_ctl(struct uart_port *port, int break_state)
{ struct uart_qe_port *qe_port =
container_of(port, struct uart_qe_port, port);
if (break_state)
ucc_slow_stop_tx(qe_port->us_private); else
ucc_slow_restart_tx(qe_port->us_private);
}
/* ISR helper function for receiving character. * * This function is called by the ISR to handling receiving characters
*/ staticvoid qe_uart_int_rx(struct uart_qe_port *qe_port)
{ int i; unsignedchar ch, *cp; struct uart_port *port = &qe_port->port; struct tty_port *tport = &port->state->port; struct qe_bd __iomem *bdp;
u16 status; unsignedint flg;
/* Just loop through the closed BDs and copy the characters into * the buffer.
*/
bdp = qe_port->rx_cur; while (1) {
status = ioread16be(&bdp->status);
/* If this one is empty, then we assume we've read them all */ if (status & BD_SC_EMPTY) break;
/* get number of characters, and check space in RX buffer */
i = ioread16be(&bdp->length);
/* If we don't have enough room in RX buffer for the entire BD, * then we try later, which will be the next RX interrupt.
*/ if (tty_buffer_request_room(tport, i) < i) {
dev_dbg(port->dev, "ucc-uart: no room in RX buffer\n"); return;
}
/* get pointer */
cp = qe2cpu_addr(ioread32be(&bdp->buf), qe_port);
/* loop through the buffer */ while (i-- > 0) {
ch = *cp++;
port->icount.rx++;
flg = TTY_NORMAL;
if (!i && status &
(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV)) goto handle_error; if (uart_handle_sysrq_char(port, ch)) continue;
/* This BD is ready to be used again. Clear status. get next */
qe_clrsetbits_be16(&bdp->status,
BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV | BD_SC_ID,
BD_SC_EMPTY); if (ioread16be(&bdp->status) & BD_SC_WRAP)
bdp = qe_port->rx_bd_base; else
bdp++;
}
/* Write back buffer pointer */
qe_port->rx_cur = bdp;
/* Overrun does not affect the current character ! */ if (status & BD_SC_OV)
tty_insert_flip_char(tport, 0, TTY_OVERRUN);
port->sysrq = 0; goto error_return;
}
/* Interrupt handler * * This interrupt handler is called after a BD is processed.
*/ static irqreturn_t qe_uart_int(int irq, void *data)
{ struct uart_qe_port *qe_port = (struct uart_qe_port *) data; struct ucc_slow __iomem *uccp = qe_port->uccp;
u16 events;
/* Clear the interrupts */
events = ioread16be(&uccp->ucce);
iowrite16be(events, &uccp->ucce);
if (events & UCC_UART_UCCE_BRKE)
uart_handle_break(&qe_port->port);
if (events & UCC_UART_UCCE_RX)
qe_uart_int_rx(qe_port);
if (events & UCC_UART_UCCE_TX)
qe_uart_tx_pump(qe_port);
return events ? IRQ_HANDLED : IRQ_NONE;
}
/* Initialize buffer descriptors * * This function initializes all of the RX and TX buffer descriptors.
*/ staticvoid qe_uart_initbd(struct uart_qe_port *qe_port)
{ int i; void *bd_virt; struct qe_bd __iomem *bdp;
/* Set the physical address of the host memory buffers in the buffer * descriptors, and the virtual address for us to work with.
*/
bd_virt = qe_port->bd_virt;
bdp = qe_port->rx_bd_base;
qe_port->rx_cur = qe_port->rx_bd_base; for (i = 0; i < (qe_port->rx_nrfifos - 1); i++) {
iowrite16be(BD_SC_EMPTY | BD_SC_INTRPT, &bdp->status);
iowrite32be(cpu2qe_addr(bd_virt, qe_port), &bdp->buf);
iowrite16be(0, &bdp->length);
bd_virt += qe_port->rx_fifosize;
bdp++;
}
/* Set the physical address of the host memory * buffers in the buffer descriptors, and the * virtual address for us to work with.
*/
bd_virt = qe_port->bd_virt +
L1_CACHE_ALIGN(qe_port->rx_nrfifos * qe_port->rx_fifosize);
qe_port->tx_cur = qe_port->tx_bd_base;
bdp = qe_port->tx_bd_base; for (i = 0; i < (qe_port->tx_nrfifos - 1); i++) {
iowrite16be(BD_SC_INTRPT, &bdp->status);
iowrite32be(cpu2qe_addr(bd_virt, qe_port), &bdp->buf);
iowrite16be(0, &bdp->length);
bd_virt += qe_port->tx_fifosize;
bdp++;
}
/* Loopback requires the preamble bit to be set on the first TX BD */ #ifdef LOOPBACK
qe_setbits_be16(&qe_port->tx_cur->status, BD_SC_P); #endif
/* * Initialize a UCC for UART. * * This function configures a given UCC to be used as a UART device. Basic * UCC initialization is handled in qe_uart_request_port(). This function * does all the UART-specific stuff.
*/ staticvoid qe_uart_init_ucc(struct uart_qe_port *qe_port)
{
u32 cecr_subblock; struct ucc_slow __iomem *uccp = qe_port->uccp; struct ucc_uart_pram __iomem *uccup = qe_port->uccup;
unsignedint i;
/* First, disable TX and RX in the UCC */
ucc_slow_disable(qe_port->us_private, COMM_DIR_RX_AND_TX);
/* Program the UCC UART parameter RAM */
iowrite8(UCC_BMR_GBL | UCC_BMR_BO_BE, &uccup->common.rbmr);
iowrite8(UCC_BMR_GBL | UCC_BMR_BO_BE, &uccup->common.tbmr);
iowrite16be(qe_port->rx_fifosize, &uccup->common.mrblr);
iowrite16be(0x10, &uccup->maxidl);
iowrite16be(1, &uccup->brkcr);
iowrite16be(0, &uccup->parec);
iowrite16be(0, &uccup->frmec);
iowrite16be(0, &uccup->nosec);
iowrite16be(0, &uccup->brkec);
iowrite16be(0, &uccup->uaddr[0]);
iowrite16be(0, &uccup->uaddr[1]);
iowrite16be(0, &uccup->toseq); for (i = 0; i < 8; i++)
iowrite16be(0xC000, &uccup->cchars[i]);
iowrite16be(0xc0ff, &uccup->rccm);
/* Configure the GUMR registers for UART */ if (soft_uart) { /* Soft-UART requires a 1X multiplier for TX */
qe_clrsetbits_be32(&uccp->gumr_l,
UCC_SLOW_GUMR_L_MODE_MASK | UCC_SLOW_GUMR_L_TDCR_MASK | UCC_SLOW_GUMR_L_RDCR_MASK,
UCC_SLOW_GUMR_L_MODE_UART | UCC_SLOW_GUMR_L_TDCR_1 | UCC_SLOW_GUMR_L_RDCR_16);
/* * If we're using Soft-UART mode, then we need to make sure the * firmware has been uploaded first.
*/ if (soft_uart && !firmware_loaded) {
dev_err(port->dev, "Soft-UART firmware not uploaded\n"); return -ENODEV;
}
/* Wait for all the BDs marked sent */ while (!qe_uart_tx_empty(port)) { if (!--timeout) {
dev_warn(port->dev, "shutdown timeout\n"); break;
}
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(2);
}
if (qe_port->wait_closing) { /* Wait a bit longer */
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(qe_port->wait_closing);
}
/* * Configure the port. * * We say we're a CPM-type port because that's mostly true. Once the device * is configured, this driver operates almost identically to the CPM serial * driver.
*/ staticvoid qe_uart_config_port(struct uart_port *port, int flags)
{ if (flags & UART_CONFIG_TYPE) {
port->type = PORT_CPM;
qe_uart_request_port(port);
}
}
/* * Release any memory and I/O resources that were allocated in * qe_uart_request_port().
*/ staticvoid qe_uart_release_port(struct uart_port *port)
{ struct uart_qe_port *qe_port =
container_of(port, struct uart_qe_port, port); struct ucc_slow_private *uccs = qe_port->us_private;
/* * Verify that the data in serial_struct is suitable for this device.
*/ staticint qe_uart_verify_port(struct uart_port *port, struct serial_struct *ser)
{ if (ser->type != PORT_UNKNOWN && ser->type != PORT_CPM) return -EINVAL;
if (ser->irq < 0 || ser->irq >= irq_get_nr_irqs()) return -EINVAL;
#ifdef CONFIG_PPC32 /* * Obtain the SOC model number and revision level * * This function parses the device tree to obtain the SOC model. It then * reads the SVR register to the revision. * * The device tree stores the SOC model two different ways. * * The new way is: * * cpu@0 { * compatible = "PowerPC,8323"; * device_type = "cpu"; * ... * * * The old way is: * PowerPC,8323@0 { * device_type = "cpu"; * ... * * This code first checks the new way, and then the old way.
*/ staticunsignedint soc_info(unsignedint *rev_h, unsignedint *rev_l)
{ struct device_node *np; constchar *soc_string; unsignedint svr; unsignedint soc;
/* Find the CPU node */
np = of_find_node_by_type(NULL, "cpu"); if (!np) return 0; /* Find the compatible property */
soc_string = of_get_property(np, "compatible", NULL); if (!soc_string) /* No compatible property, so try the name. */
soc_string = np->name;
of_node_put(np);
/* Extract the SOC number from the "PowerPC," string */ if ((sscanf(soc_string, "PowerPC,%u", &soc) != 1) || !soc) return 0;
/* Get the revision from the SVR */
svr = mfspr(SPRN_SVR);
*rev_h = (svr >> 4) & 0xf;
*rev_l = svr & 0xf;
return soc;
}
/* * requst_firmware_nowait() callback function * * This function is called by the kernel when a firmware is made available, * or if it times out waiting for the firmware.
*/ staticvoid uart_firmware_cont(conststruct firmware *fw, void *context)
{ struct qe_firmware *firmware; struct device *dev = context; int ret;
if (!fw) {
dev_err(dev, "firmware not found\n"); return;
}
/* Check if the firmware has been uploaded. */ if (qe_fw_info && strstr(qe_fw_info->id, "Soft-UART")) {
firmware_loaded = 1;
} else { char filename[32]; unsignedint soc; unsignedint rev_h; unsignedint rev_l;
soc = soc_info(&rev_h, &rev_l); if (!soc) {
dev_err(&ofdev->dev, "unknown CPU model\n"); return -ENXIO;
}
sprintf(filename, "fsl_qe_ucode_uart_%u_%u%u.bin",
soc, rev_h, rev_l);
dev_info(&ofdev->dev, "waiting for firmware %s\n",
filename);
/* * We call request_firmware_nowait instead of * request_firmware so that the driver can load and * initialize the ports without holding up the rest of * the kernel. If hotplug support is enabled in the * kernel, then we use it.
*/
ret = request_firmware_nowait(THIS_MODULE,
FW_ACTION_UEVENT, filename, &ofdev->dev,
GFP_KERNEL, &ofdev->dev, uart_firmware_cont); if (ret) {
dev_err(&ofdev->dev, "could not load firmware %s\n",
filename); return ret;
}
} return 0;
}
/* * Determine if we need Soft-UART mode
*/
ret = soft_uart_init(ofdev); if (ret) return ret;
qe_port = kzalloc(sizeof(struct uart_qe_port), GFP_KERNEL); if (!qe_port) {
dev_err(&ofdev->dev, "can't allocate QE port structure\n"); return -ENOMEM;
}
/* Search for IRQ and mapbase */
ret = of_address_to_resource(np, 0, &res); if (ret) {
dev_err(&ofdev->dev, "missing 'reg' property in device tree\n"); goto out_free;
} if (!res.start) {
dev_err(&ofdev->dev, "invalid 'reg' property in device tree\n");
ret = -EINVAL; goto out_free;
}
qe_port->port.mapbase = res.start;
/* Get the UCC number (device ID) */ /* UCCs are numbered 1-7 */ if (of_property_read_u32(np, "cell-index", &val)) { if (of_property_read_u32(np, "device-id", &val)) {
dev_err(&ofdev->dev, "UCC is unspecified in device tree\n");
ret = -EINVAL; goto out_free;
}
}
if (val < 1 || val > UCC_MAX_NUM) {
dev_err(&ofdev->dev, "no support for UCC%u\n", val);
ret = -ENODEV; goto out_free;
}
qe_port->ucc_num = val - 1;
/* * In the future, we should not require the BRG to be specified in the * device tree. If no clock-source is specified, then just pick a BRG * to use. This requires a new QE library function that manages BRG * assignments.
*/
sprop = of_get_property(np, "rx-clock-name", NULL); if (!sprop) {
dev_err(&ofdev->dev, "missing rx-clock-name in device tree\n");
ret = -ENODEV; goto out_free;
}
qe_port->us_info.rx_clock = qe_clock_source(sprop); if ((qe_port->us_info.rx_clock < QE_BRG1) ||
(qe_port->us_info.rx_clock > QE_BRG16)) {
dev_err(&ofdev->dev, "rx-clock-name must be a BRG for UART\n");
ret = -ENODEV; goto out_free;
}
#ifdef LOOPBACK /* In internal loopback mode, TX and RX must use the same clock */
qe_port->us_info.tx_clock = qe_port->us_info.rx_clock; #else
sprop = of_get_property(np, "tx-clock-name", NULL); if (!sprop) {
dev_err(&ofdev->dev, "missing tx-clock-name in device tree\n");
ret = -ENODEV; goto out_free;
}
qe_port->us_info.tx_clock = qe_clock_source(sprop); #endif if ((qe_port->us_info.tx_clock < QE_BRG1) ||
(qe_port->us_info.tx_clock > QE_BRG16)) {
dev_err(&ofdev->dev, "tx-clock-name must be a BRG for UART\n");
ret = -ENODEV; goto out_free;
}
/* Get the port number, numbered 0-3 */ if (of_property_read_u32(np, "port-number", &val)) {
dev_err(&ofdev->dev, "missing port-number in device tree\n");
ret = -EINVAL; goto out_free;
}
qe_port->port.line = val; if (qe_port->port.line >= UCC_MAX_UART) {
dev_err(&ofdev->dev, "port-number must be 0-%u\n",
UCC_MAX_UART - 1);
ret = -EINVAL; goto out_free;
}
qe_port->port.irq = irq_of_parse_and_map(np, 0); if (qe_port->port.irq == 0) {
dev_err(&ofdev->dev, "could not map IRQ for UCC%u\n",
qe_port->ucc_num + 1);
ret = -EINVAL; goto out_free;
}
/* * Newer device trees have an "fsl,qe" compatible property for the QE * node, but we still need to support older device trees.
*/
np = of_find_compatible_node(NULL, NULL, "fsl,qe"); if (!np) {
np = of_find_node_by_type(NULL, "qe"); if (!np) {
dev_err(&ofdev->dev, "could not find 'qe' node\n");
ret = -EINVAL; goto out_free;
}
}
if (of_property_read_u32(np, "brg-frequency", &val)) {
dev_err(&ofdev->dev, "missing brg-frequency in device tree\n");
ret = -EINVAL; goto out_np;
}
if (val)
qe_port->port.uartclk = val; else { if (!IS_ENABLED(CONFIG_PPC32)) {
dev_err(&ofdev->dev, "invalid brg-frequency in device tree\n");
ret = -EINVAL; goto out_np;
}
/* * Older versions of U-Boot do not initialize the brg-frequency * property, so in this case we assume the BRG frequency is * half the QE bus frequency.
*/ if (of_property_read_u32(np, "bus-frequency", &val)) {
dev_err(&ofdev->dev, "missing QE bus-frequency in device tree\n");
ret = -EINVAL; goto out_np;
} if (val)
qe_port->port.uartclk = val / 2; else {
dev_err(&ofdev->dev, "invalid QE bus-frequency in device tree\n");
ret = -EINVAL; goto out_np;
}
}
/* Make sure ucc_slow_init() initializes both TX and RX */
qe_port->us_info.init_tx = 1;
qe_port->us_info.init_rx = 1;
/* Add the port to the uart sub-system. This will cause * qe_uart_config_port() to be called, so the us_info structure must * be initialized.
*/
ret = uart_add_one_port(&ucc_uart_driver, &qe_port->port); if (ret) {
dev_err(&ofdev->dev, "could not add /dev/ttyQE%u\n",
qe_port->port.line); goto out_np;
}
platform_set_drvdata(ofdev, qe_port);
dev_info(&ofdev->dev, "UCC%u assigned to /dev/ttyQE%u\n",
qe_port->ucc_num + 1, qe_port->port.line);
/* Display the mknod command for this device */
dev_dbg(&ofdev->dev, "mknod command is 'mknod /dev/ttyQE%u c %u %u'\n",
qe_port->port.line, SERIAL_QE_MAJOR,
SERIAL_QE_MINOR + qe_port->port.line);
ret = uart_register_driver(&ucc_uart_driver); if (ret) {
printk(KERN_ERR "ucc-uart: could not register UART driver\n"); return ret;
}
ret = platform_driver_register(&ucc_uart_of_driver); if (ret) {
printk(KERN_ERR "ucc-uart: could not register platform driver\n");
uart_unregister_driver(&ucc_uart_driver);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.