#include <linux/err.h>
 #include <linux/irq.h>
 #include <linux/suspend.h>
+#include <linux/mm.h>
 
 #include <asm/io.h>
 #include <asm/ioctls.h>
        sg_set_page(&atmel_port->sg_tx,
                        virt_to_page(port->state->xmit.buf),
                        UART_XMIT_SIZE,
-                       (unsigned long)port->state->xmit.buf & ~PAGE_MASK);
+                       offset_in_page(port->state->xmit.buf));
        nent = dma_map_sg(port->dev,
                                &atmel_port->sg_tx,
                                1,
        sg_set_page(&atmel_port->sg_rx,
                    virt_to_page(ring->buf),
                    sizeof(struct atmel_uart_char) * ATMEL_SERIAL_RINGSIZE,
-                   (unsigned long)ring->buf & ~PAGE_MASK);
+                   offset_in_page(ring->buf));
        nent = dma_map_sg(port->dev,
                          &atmel_port->sg_rx,
                          1,