summaryrefslogtreecommitdiff
path: root/chip/lm4/gpio.c
blob: 2ec64ce8af5b7640c6ad4403f6b2cf8988302690 (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
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* GPIO module for Chrome EC */

#include "gpio.h"
#include "registers.h"


int gpio_pre_init(void)
{
	/* Enable clock to GPIO block A */
	LM4_SYSTEM_RCGCGPIO |= 0x0001;

	/* Turn off the LED before we make it an output */
	gpio_set(EC_GPIO_DEBUG_LED, 0);

	/* Clear GPIOAFSEL bits for block A pin 7 */
	LM4_GPIO_AFSEL(A) &= ~(0x80);

	/* Set GPIO to digital enable, output */
	LM4_GPIO_DEN(A) |= 0x80;
	LM4_GPIO_DIR(A) |= 0x80;

	return EC_SUCCESS;
}


int gpio_init(void)
{
	return EC_SUCCESS;
}


int gpio_get(enum gpio_signal signal, int *value_ptr)
{
	switch (signal) {
	case EC_GPIO_DEBUG_LED:
		*value_ptr = (LM4_GPIO_DATA_BITS(A, 0x200) & 0x80 ? 1 : 0);
		return EC_SUCCESS;
	default:
		return EC_ERROR_UNKNOWN;
	}
}


int gpio_set(enum gpio_signal signal, int value)
{
	switch (signal) {
	case EC_GPIO_DEBUG_LED:
		LM4_GPIO_DATA_BITS(A, 0x200) = (value ? 0x80 : 0);
		return EC_SUCCESS;
	default:
		return EC_ERROR_UNKNOWN;
	}
}