title: Using writel to write 4 bit to ioremap-ed memory address
body: <p>I'm new to kernel programming, and now trying to write some values to a 32-bit GPIO register in a device driver. The I/O is <code>ioremap()</code>-ed to a memory address. The problem is, I don't know how <code>writel()</code>/<code>writeb()</code>/<code>writew()</code> writes bits to the addresses.</p>
  
  <p>The vendor documents says the register is on <code>0xE5200000</code>. The bits I have to write to is the <code>[0:3]</code> bits and leave the remaining 28 bits (the <code>[4:31]</code> bits) as zeros.</p>
  
  <p>This is part of the code in the device driver I've written so far:</p>
  
  <pre><code>#define TCON_ADDR 0xE250000 // The address as provided by the vendor
  static void *TIMER_CON_ADDR;
  // I have to map and write to the address when the device is opened
  static int on_dev_open(struct inode *inode, struct file *file) {
      unsigned int data;
      TIMER_CON_ADDR = ioremap(TCON_ADDR, 4); // Map the [0:4] bits to TIMER_CON_ADDR
      data = 4; // 0100 in binary
      writel(data, TIMER_CON_ADDR); // Write 0100 to TIMER_CON_ADDR
      return 0;
  }
  </code></pre>
  
  <p>The above code might just be outright gibberish to you all, but I am not familiar with <code>write(l|w|b)</code> and <code>ioremap()</code>.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Did I map the <code>[0:4]</code> bits to TIMER_CON_ADDR correctly?</li>
  <li>If not, how do I map them correctly?</li>
  <li>After I have correctly mapped the 4 bits, how do I use any of the <code>write(1|w|b)</code> functions to write bits (<code>0100</code>) to TIMER_CON_ADDR in the correct order?</li>
  <li>What does <code>write(l|w|b)</code> do under the hood to write bits?</li>
  <li>Is there any information I've missed / got wrong?</li>
  </ol>
  
  <p>Thanks for all your help in advance.</p>