ARM Linux driver : how to write to a physical address?

Hi All,

I'm writing a device driver for an ARM based board (Cirrus EP9302). One of the functions of the driver is to be able to write values to the address 0x23800000. How do you actually write to a physical address from within the kernel?

Reply to
Loading thread data ...

Did you check how the other device drivers do it? (BTW: The kernel is full of examples).


Reply to
Juergen Beisert



Just type cast the address to a variable and use it. Any thing that is directly mapped to the processors address space can be accssed like that. Also try __raw_read Api, should be available on ARM.

Reply to


unsigned long *ptr =3D 0xphysicaladdr

*ptr =3D yourdata.
Reply to

This would be wrong on other architectures (I am unfamiliar with ARM but I believe most of them have an MMU and therefore it is wrong there too). Normally you would need a phys_to_virt() to convert the physical address to the virtual address used in the kernel process.


unsigned long *ptr = phys_to_virt( 0xphysicaladdr );

*ptr = yourdata;


formatting link

Cheers, John McCallum Edinburgh

Reply to
John McCallum

Uzytkownik "John McCallum" napisal w wiadomosci news:gci1ej$k03$1$


Please dont't forget about: volatile. Lot of time I spent, when I was trying to understad WHY :)

volatile unsigned long *ptr = phys_to_virt( 0xphysicaladdr );

*ptr = yourdata;

Grzegorz Kania Czerwionka, Poland

Reply to
Grzegorz Kania


t I



phys_to_virt() only works with directly mapped physical address. I don't think using phys_to_virt() is the best idea, anyway. Usually you do this in several steps in a device driver:

  1. Call request_mem_region() to request virtual memory region;
  2. Call ioremap() to map physical address to virtual address;
  3. Read/write mapped virtual address by using iowriteXX() / ioreadXX(), etc. Here XX can be 8, 16, or 32 for example, represents bit width.
  4. Call iounmap() and release_mem_region() to release memory mapping;

Thanks, Marco Wang

Reply to
Marco Wang

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.