File: uart.c

package info (click to toggle)
linux 3.16.51-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-updates
  • size: 755,292 kB
  • sloc: ansic: 12,235,573; asm: 277,597; perl: 53,071; xml: 47,771; makefile: 30,539; sh: 7,977; python: 6,697; cpp: 5,131; yacc: 4,254; lex: 2,215; awk: 741; pascal: 231; lisp: 218; sed: 30
file content (87 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright 2013 Tilera Corporation. All Rights Reserved.
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation, version 2.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
 *   NON INFRINGEMENT.  See the GNU General Public License for
 *   more details.
 */

/*
 * Implementation of UART gxio calls.
 */

#include <linux/io.h>
#include <linux/errno.h>
#include <linux/module.h>

#include <gxio/uart.h>
#include <gxio/iorpc_globals.h>
#include <gxio/iorpc_uart.h>
#include <gxio/kiorpc.h>

int gxio_uart_init(gxio_uart_context_t *context, int uart_index)
{
	char file[32];
	int fd;

	snprintf(file, sizeof(file), "uart/%d/iorpc", uart_index);
	fd = hv_dev_open((HV_VirtAddr) file, 0);
	if (fd < 0) {
		if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
			return fd;
		else
			return -ENODEV;
	}

	context->fd = fd;

	/* Map in the MMIO space. */
	context->mmio_base = (void __force *)
		iorpc_ioremap(fd, HV_UART_MMIO_OFFSET, HV_UART_MMIO_SIZE);

	if (context->mmio_base == NULL) {
		hv_dev_close(context->fd);
		context->fd = -1;
		return -ENODEV;
	}

	return 0;
}

EXPORT_SYMBOL_GPL(gxio_uart_init);

int gxio_uart_destroy(gxio_uart_context_t *context)
{
	iounmap((void __force __iomem *)(context->mmio_base));
	hv_dev_close(context->fd);

	context->mmio_base = NULL;
	context->fd = -1;

	return 0;
}

EXPORT_SYMBOL_GPL(gxio_uart_destroy);

/* UART register write wrapper. */
void gxio_uart_write(gxio_uart_context_t *context, uint64_t offset,
		     uint64_t word)
{
	__gxio_mmio_write(context->mmio_base + offset, word);
}

EXPORT_SYMBOL_GPL(gxio_uart_write);

/* UART register read wrapper. */
uint64_t gxio_uart_read(gxio_uart_context_t *context, uint64_t offset)
{
	return __gxio_mmio_read(context->mmio_base + offset);
}

EXPORT_SYMBOL_GPL(gxio_uart_read);