This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

register base address & its contents to print using printk in kernel driver code

Dear Ti  E2E community,

Could you please let me know how the register base address & offset can be printed using printk, the above gives only the suggestions of printing the register contents, Am trying to print the register base address

For example: could you please let me know how usb_ctrl1 register base address can be printed using printk in driver code for example I need to print the address of  (usb_ctrl->phy_reg + reg) in phy-am335x-control.c

Could you please kindly do the needful in how to print the register base address using printk in kernel driver code

Kindly do the needful as early as possible

Awaiting for your replies

Many Thanks in advance

  • Could anybody pls provide any inputs w.r.t the above query

    I have even tried find googling also but I was unable to figure it out

    Kindly do the needful as early as possible

    Many Thanks in advance

  • Do you want to know its physical or logical base address? The physical address is listed in the TRM, you don't have to printk it in kernel.
  • Hi,

    The usb_ctrl->phy_reg is passed as the IO resource from the board/dts file so if you look at file archarm/boot/dts/am33xx.dtsi

    usb_ctrl_mod: control@44e10620 {
    compatible = "ti,am335x-usb-ctrl-module";
    reg = <0x44e10620 0x10
    0x44e10648 0x4>;
    reg-names = "phy_ctrl", "wakeup";
    status = "disabled";
    };

    and in file phy-am335x-control.c this address (0x44e10620) io remapped (size 0x10) and assigned to ctrl_usb->phy_reg.

    158 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl");
    159 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res);
    160 if (IS_ERR(ctrl_usb->phy_reg))
    161 return PTR_ERR(ctrl_usb->phy_reg);

    -->>> So the base address is 0x44e10620 but in the kernel this is IO remapped in kernel space (which will have different address).

    so if you want to print the values of address (0x44e10620) from userspace you can used dev2mem.

    Hope this clears your doubts!!

    Cheers,
    --Prabhakar Lad

  • Hi,

    Could you please let me know how the register base address & offset can be printed using printk, the above gives only the suggestions of printing the register contents, Am trying to print the register base address

    You can use "__raw_readl" API to print the contents of register at kernel code or as Prabhakar said, you can use "devmem2" command to see the content of register at user space.
    You have to add the OFFSET with BASE address of particular USB address to get physical address of that USB register say, status register(connectivity,error status etc.,)
  • Dear Bin Liu,

    Thanks a lot for all your quick responses & really appreciate the same, I understand from all your suggestions that physical address in kernel cannot be directly printed in kernel

    Sorry for my poor understanding, Is my understanding is correct???

    Could you please let me know how physical address can be converted & printed interms of logical address in kernel space using printk

    Could any body please demonstrate for printing logical address (corresponding to physical address) using printk

    for example could you show me for: usb_ctrl1 register address using printk

    Kindly do the needful as early as possible

    Once again many thanks in advance

    Many Thanks in advance
  • Hi Srini,
    Tell us which exact USB register do you want to read ?
    Purpose of reading the register that reg etc., ?
    If you print the content of USB base address you would get value of USB "REVISION"

    If you want to read USB0 Control register then do the following:

    USB0 CONTROL reg offset -> 0x620 (please refer to the page no
    CONTROL MODULE base address -> 0x44E10000
    PHYSICAL address of USB0 control register -> 0x44E10620

    Ex:
    static void __iomem *base;

    base = ioremap( 0x44E10000, SZ_4K);

    printk("USB0 Control reg = %x\n",__raw_readl(base+0x620));

    Actually, if you want to see the content of USB control register value, also you can put the following line at line no 85 at "drivers/usb/phy/phy-am335x-control.c

    printk("USB0 control value 0x%x\n",val);

    Just now seen the following post, Pavel given almost all possibilities, still any problem?

    e2e.ti.com/.../386669
  • Sorry for such a silly question Titus,

    Ex:

    static void __iomem *base;

    base = ioremap( 0x44E10000, SZ_4K);

    Could you please let me know what is this SZ_4K?? what is its value??? why it is always SZ_4K??

    Could you please let me know how this base variable can be printed is it possible to print using "%p"  format specifier  or should I use "%x" format specifier using printk???

    Is it possible to print using printk("%p", base); does this work ????

    Kindly do the needful as early as possible

    Many Thanks in advance again

  • Yes, you can use "%p" also.
    It is 32bit address that's why we have to mention "0x4" there.

    base = ioremap( 0x44E10000, 4);

    lxr.free-electrons.com/.../io.h
    lxr.free-electrons.com/.../sizes.h
  • Thanks a lot for your time Titus & for your explanation ,

    Once again many thanks Titus, Pavel , Prabhakar & Bin Liu

    Now my doubts are cleared

    Thanks a lot once again to all
  • Srini said:
    I understand from all your suggestions that physical address in kernel cannot be directly printed in kernel

    Sorry for my poor understanding, Is my understanding is correct???

    Not really. My point is that the base physical address is known, why you bother to figure out how to print it from the variable, it does not help on debugging or anything. It has no difference from printk("%s", "0x44E10000").