Control USART RTS pin from driver on embedded board

淺唱寂寞╮ 提交于 2019-12-13 16:06:42

问题


I'm porting the lirc_serial kernel module to work on our embedded board. We only need to implement the IR transmitter function.

For only the transmitter, the custom driver need only control the RTS pin on /dev/ttyS0, from within the module.

On standard hardware, the driver loads:

00:05: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A

NEW APPROACH

I have not figured out how to deactivate the current driver for the serial port, so rather than create a new driver, how would you use the current 8250-dw driver to change the RTS pin on behalf of my kernel module? Something like this?

Using line disciplines per this article on the slip driver looked promising, Just take slip.c and remove the network side of the code. But it needs a user space program (slattach or dip) to open /dev/ttyS0 and activate the line discipline.

Is that possible (or a good idea) from within a kernel module?

In this similar question, How do I open/write/read a uart device from a kernel module?, Ian Abbott suggested backporting serdev to kernel 4.9.

That's getting a bit involved and we're already behind schedule. Is there an easier way?

ORIGINAL QUESTION

However, the embedded board (based on the BayTrail Atom E3845) has the serial port controller in memory mapped I/O:

80860F0A:00: ttyS0 at MMIO 0x90a0c000 (irq = 39, base_baud = 2764800) is a 16550A
80860F0A:01: ttyS1 at MMIO 0x90a0e000 (irq = 40, base_baud = 2764800) is a 16550A

I'm new to driver development. I guess 0x90a0c000 is the physical address of the controller?

To probe the module, I first remapped 0x90a0c000 to a virtual address using ioremap_nocache and then tried to reserve the memory using request_mem_region. That failed.

ioVirtBase = ioremap_nocache(iommap, 8);

TQTRACE("ecp_serial_probe: devm_ioremap for MMIO 0x%X returned 0x%X\n", (uint32_t)iommap, (uint32_t)ioVirtBase);
if (ioVirtBase != NULL)
{
    tqDumpBuffer(ioVirtBase, 8);
}

tqRes = request_mem_region((uint32_t)ioVirtBase, 8, ECP_DRIVER_NAME);
TQTRACE("ecp_serial_probe: request_mem_region for 0x%X returned 0x%X\n", (uint32_t)ioVirtBase, (uint32_t)tqRes);
if (!tqRes)
{
    TQTRACE("ecp_serial_probe: Cannot request memory at 0x%X\n", (uint32_t)iommap);
    return -ENXIO;
}

Is this the correct order of the functions?

Also, it seems request_mem_region fails because the device is under control of 80860F0A ?? There is no such entry in lsmod but there is an entry in /sys/devices.

Do I need to unload that driver to control the USART? How?

# ls -l  /sys/devices/platform/80860F0A\:00
lrwxrwxrwx 1 root root    0 Jul  8 23:30 driver -> ../../../bus/platform/drivers/dw-apb-uart
-rw-r--r-- 1 root root 4096 Jul  9 17:02 driver_override
lrwxrwxrwx 1 root root    0 Jul  9 17:14 firmware_node -> ../../LNXSYSTM:00/LNXSYBUS:00/80860F0A:00
-r--r--r-- 1 root root 4096 Jul  9 17:02 modalias
drwxr-xr-x 2 root root    0 Jul  9 17:02 power
lrwxrwxrwx 1 root root    0 Jul  8 23:30 subsystem -> ../../../bus/platform
drwxr-xr-x 3 root root    0 Jul  8 23:30 tty
-rw-r--r-- 1 root root 4096 Jul  9 17:02 uevent
drwxr-xr-x 3 root root    0 Jul  8 23:30 VCOM0001:00

dmesg output below. Dumping the data at the remapped virtual address is not consistent. Sometimes all 0xFF, other times, 00 00 00 00 41 02 1C 48. I don't understand that either...

MARK Tue Jul 9 17:45:35 SGT 2019
ecp_serial: ecp_serial_exit_module()
Spectre V2 : System may be vulnerable to spectre v2
ecp_serial: loading module not compiled with retpoline compiler.
ecp_serial: ecp_serial_init_module()
ecp_serial: ecp_serial_init()
ecp_serial: ecp_serial_probe() iommap=0x90A0C000
ecp_serial: ecp_serial_probe: devm_ioremap for MMIO 0x90A0C000 returned 0xE3296000
ecp_serial: Dump address 0xE3296000:
      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
0000  FF FF FF FF FF FF FF FF 
ecp_serial: ecp_serial_probe: request_mem_region for 0xE3296000 returned 0x0
ecp_serial: ecp_serial_probe: Cannot request memory at 0x90A0C000
platform ecp_serial.0: lirc_dev: driver ecp_serial registered at minor = 0

MARK Tue Jul 9 17:46:08 SGT 2019
ecp_serial: ecp_serial_exit_module()
Spectre V2 : System may be vulnerable to spectre v2
ecp_serial: loading module not compiled with retpoline compiler.
ecp_serial: ecp_serial_init_module()
ecp_serial: ecp_serial_init()
ecp_serial: ecp_serial_probe() iommap=0x90A0C000
ecp_serial: ecp_serial_probe: devm_ioremap for MMIO 0x90A0C000 returned 0xE32A2000
ecp_serial: Dump address 0xE32A2000:
      00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
0000  00 00 00 00 41 02 1C 48 
ecp_serial: ecp_serial_probe: request_mem_region for 0xE32A2000 returned 0x0
ecp_serial: ecp_serial_probe: Cannot request memory at 0x90A0C000
platform ecp_serial.0: lirc_dev: driver ecp_serial registered at minor = 0

What proc/iomem has to say

90a0c000-90a0cfff : 80860F0A:00
90a0e000-90a0efff : 80860F0A:01

So indeed, the memory is under control of another driver... But how to unload it if it is not listed in lsmod ?

# rmmod 80860F0A:00
ERROR: Module 80860F0A:00 does not exist in /proc/modules
# rmmod 80860F0A
ERROR: Module 80860F0A does not exist in /proc/modules

OS INFO

# uname -a
Linux ecp 4.4.127-1.el6.elrepo.i686 #1 SMP Sun Apr 8 09:44:43 EDT 2018 i686 i686 i386 GNU/Linux
# cat /etc/centos-release
CentOS release 6.6 (Final)

来源:https://stackoverflow.com/questions/56954882/control-usart-rts-pin-from-driver-on-embedded-board

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!