static int phytium_uart_probe(struct amba_device *dev, const struct amba_id *id) { struct phytium_uart_port *pup; struct vendor_data *vendor = id->data; int portnr, ret; portnr = phytium_find_free_port(); if (portnr < 0) return portnr; pup = devm_kzalloc(&dev->dev, sizeof(struct phytium_uart_port), GFP_KERNEL); if(!pup) return -ENOMEM; pup->clk = devm_clk_get(&dev->dev, NULL); if(IS_ERR(pup->clk)) return PTR_ERR(pup->clk); pup->port.irq = dev->irq[0]; pup->port.line = portnr; pup->vendor = vendor; pup->fifosize = 32; pup->port.iotype = pup->vendor->access_32b ? UPIO_MEM32 : UPIO_MEM; pup->port.ops = &phytium_uart_ops; snprintf(pup->type, sizeof(pup->type), "PL011 rev%u", amba_rev(dev)); ret = phytium_setup_port(&dev->dev, pup, &dev->res, portnr); if (ret) return ret; amba_set_drvdata(dev, pup); return phytium_register_port(pup); }在这段linux内核驱动中加入读取acpi表中描述的固定波特率,并设置波特率的操作,给出详细代码
时间: 2024-03-02 14:54:26 浏览: 139
UART_INT.zip_UART_INT_uart int
在这段驱动中,由于使用的是AMBA总线,因此无法直接使用ACPI匹配设备。不过,我们可以在驱动中添加代码来读取设备树中的固定波特率信息,从而设置波特率。
下面是一个简单的示例代码,用于在驱动中读取设备树中的固定波特率信息:
```
static int phytium_uart_probe(struct amba_device *dev, const struct amba_id *id)
{
struct phytium_uart_port *pup;
struct vendor_data *vendor = id->data;
int portnr, ret;
u32 baudrate;
// 获取波特率信息
if (of_property_read_u32(dev->dev.of_node, "baudrate", &baudrate)) {
dev_info(&dev->dev, "no baudrate specified, using default\n");
baudrate = 115200;
} else {
dev_info(&dev->dev, "using baudrate %u\n", baudrate);
}
portnr = phytium_find_free_port();
if (portnr < 0)
return portnr;
pup = devm_kzalloc(&dev->dev, sizeof(struct phytium_uart_port),
GFP_KERNEL);
if (!pup)
return -ENOMEM;
pup->clk = devm_clk_get(&dev->dev, NULL);
if (IS_ERR(pup->clk))
return PTR_ERR(pup->clk);
pup->port.irq = dev->irq[0];
pup->port.line = portnr;
pup->vendor = vendor;
pup->fifosize = 32;
pup->port.iotype = pup->vendor->access_32b ? UPIO_MEM32 : UPIO_MEM;
pup->port.ops = &phytium_uart_ops;
snprintf(pup->type, sizeof(pup->type), "PL011 rev%u", amba_rev(dev));
// 设置波特率
pup->port.uartclk = clk_get_rate(pup->clk);
baudrate = uart_get_baud_rate(&pup->port, baudrate, baudrate);
ret = phytium_setup_port(&dev->dev, pup, &dev->res, portnr);
if (ret)
return ret;
amba_set_drvdata(dev, pup);
return phytium_register_port(pup);
}
```
在这个示例代码中,我们使用了`of_property_read_u32()`函数来读取设备树中的`baudrate`属性。如果设备树中没有指定该属性,则默认使用115200作为波特率。接下来,我们使用`uart_get_baud_rate()`函数来获取实际使用的波特率,并将其传递给`phytium_setup_port()`函数来进行端口设置。
阅读全文