summaryrefslogtreecommitdiff
path: root/drivers/gpio/vybrid_gpio.c
blob: a508397e171ca98480558034b1b774ab68929132 (plain)
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
/*
 * Copyright (C) 2015
 * Bhuvanchandra DV, Toradex, Inc.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/imx-regs.h>
#include <asm/imx-common/iomux-v3.h>

static unsigned long gpio_ports[] = {
	[0] = GPIO0_BASE_ADDR,
	[1] = GPIO1_BASE_ADDR,
	[2] = GPIO2_BASE_ADDR,
	[3] = GPIO3_BASE_ADDR,
	[4] = GPIO4_BASE_ADDR,
};

int gpio_set_value(unsigned gpio, int value)
{
	unsigned int port = GPIO_TO_PORT(gpio);
	struct gpio_regs *regs;
	u32 mask = (1 << (gpio & GPIO_PIN_MASK));

	if (port >= ARRAY_SIZE(gpio_ports))
		return -1;

	regs = (struct gpio_regs *)gpio_ports[port];

	if (value)
		writel(mask, &regs->gpio_psor);
	else
		writel(mask, &regs->gpio_pcor);

	return 0;
}

int gpio_get_value(unsigned gpio)
{
	unsigned int port = GPIO_TO_PORT(gpio);
	struct gpio_regs *regs;
	u32 mask = (1 << (gpio & GPIO_PIN_MASK));

	if (port >= ARRAY_SIZE(gpio_ports))
		return -1;

	regs = (struct gpio_regs *)gpio_ports[port];

	return ((readl(&regs->gpio_pdir) & mask)) ? 1 : 0;
}

int gpio_request(unsigned gpio, const char *label)
{
	unsigned int port = GPIO_TO_PORT(gpio);

	if (port >= ARRAY_SIZE(gpio_ports))
		return -1;

	return 0;
}

int gpio_free(unsigned gpio)
{
	return 0;
}

int gpio_direction_input(unsigned gpio)
{
	imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_IN);

	return 0;
}

int gpio_direction_output(unsigned gpio, int value)
{
	gpio_set_value(gpio, value);

	imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_OUT);

	return 0;
}