Search code examples
clinux-kernellinux-device-driverdevice-driveruart

Mapping UART register address to kernel for writing device drivers


How will I map register addresses specifically UART registers to kernel for writing device drivers for UART?

I have gone through the omap-serial.c.But I did not find the mapping of the registers defined in it.

Is it different from the mapping of standalone UART driver?


Solution

  • As a device driver writer, it is your job to read the hardware documentation. The serial port documentation will specify the bits in the control and status registers and provide guidance on how to determine their addresses. Usually that guidance is in a system integrator's document.

    Let's say your research determines that the UART's registers are at 0x31080220. Your code would then have:

    struct resource *uart_res;  // resource handle
    uint  *uart;                // pointer to actual control/status registers
    uart_res = request_mem_region (0x31080220, 4*4, "my_uart");   // map 16 bytes
    if (!uart_res)
    {
         error ("unable to map memory region");
         return -ENOMEM;
    }
    uart = ioremap (0x31080220, 4*4);
    if (!uart)
    {
          release_mem_region (0x31080220, 4*4);
          error ("unable to map");
          return -ENOMEM;
    }
    

    Then you can use the uart pointer to access the registers.

    status = ioread32 (uart + 0);   // read the status register
    iowrite32 (0xf0f0, uart + 4);   // foo foo to control register
    

    Give precise target information for the manufacturer, model, and options—just like an automobile—and someone will help you find the specifics.