2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
16 * Implementation of UART gxio calls.
20 #include <linux/errno.h>
21 #include <linux/module.h>
23 #include <gxio/uart.h>
24 #include <gxio/iorpc_globals.h>
25 #include <gxio/iorpc_uart.h>
26 #include <gxio/kiorpc.h>
28 int gxio_uart_init(gxio_uart_context_t
*context
, int uart_index
)
33 snprintf(file
, sizeof(file
), "uart/%d/iorpc", uart_index
);
34 fd
= hv_dev_open((HV_VirtAddr
) file
, 0);
36 if (fd
>= GXIO_ERR_MIN
&& fd
<= GXIO_ERR_MAX
)
44 /* Map in the MMIO space. */
45 context
->mmio_base
= (void __force
*)
46 iorpc_ioremap(fd
, HV_UART_MMIO_OFFSET
, HV_UART_MMIO_SIZE
);
48 if (context
->mmio_base
== NULL
) {
49 hv_dev_close(context
->fd
);
57 EXPORT_SYMBOL_GPL(gxio_uart_init
);
59 int gxio_uart_destroy(gxio_uart_context_t
*context
)
61 iounmap((void __force __iomem
*)(context
->mmio_base
));
62 hv_dev_close(context
->fd
);
64 context
->mmio_base
= NULL
;
70 EXPORT_SYMBOL_GPL(gxio_uart_destroy
);
72 /* UART register write wrapper. */
73 void gxio_uart_write(gxio_uart_context_t
*context
, uint64_t offset
,
76 __gxio_mmio_write(context
->mmio_base
+ offset
, word
);
79 EXPORT_SYMBOL_GPL(gxio_uart_write
);
81 /* UART register read wrapper. */
82 uint64_t gxio_uart_read(gxio_uart_context_t
*context
, uint64_t offset
)
84 return __gxio_mmio_read(context
->mmio_base
+ offset
);
87 EXPORT_SYMBOL_GPL(gxio_uart_read
);