blob: 441c8bafdff769ff38b838cc15e39b1fe97a8ea9 [file] [log] [blame]
Deepa Dinamani645e9b12012-12-21 14:23:40 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
32#include <platform/gpio.h>
33
34void gpio_tlmm_config(uint32_t gpio, uint8_t func,
35 uint8_t dir, uint8_t pull,
36 uint8_t drvstr, uint32_t enable)
37{
38 uint32_t val = 0;
39 val |= pull;
40 val |= func << 2;
41 val |= drvstr << 6;
42 val |= enable << 9;
43 writel(val, (uint32_t *)GPIO_CONFIG_ADDR(gpio));
44 return;
45}
46
Ray Zhang3bd5bd12013-04-19 18:14:09 +080047void gpio_set_dir(uint32_t gpio, uint32_t dir)
Deepa Dinamani645e9b12012-12-21 14:23:40 -080048{
49 writel(dir, (uint32_t *)GPIO_IN_OUT_ADDR(gpio));
50 return;
51}
52
Ray Zhang3bd5bd12013-04-19 18:14:09 +080053void gpio_set_value(uint32_t gpio, uint32_t value)
54{
55 /* GPIO_OUTPUT */
56 if (value) {
57 writel(GPIO_OUT_VAL(gpio),
58 (uint32_t *)GPIO_OUT_SET_ADDR(gpio));
59 } else {
60 writel(GPIO_OUT_VAL(gpio),
61 (uint32_t *)GPIO_OUT_CLR_ADDR(gpio));
62 }
63 /* GPIO_OE */
64 writel(GPIO_OUT_OE_VAL(gpio),
65 (uint32_t *)GPIO_OUT_OE_SET_ADDR(gpio));
66
67 return;
68}
69
Deepa Dinamanieb299a22013-02-25 11:49:30 -080070uint32_t gpio_status(uint32_t gpio)
71{
72 return readl(GPIO_IN_OUT_ADDR(gpio)) & GPIO_IN;
73}
74
Deepa Dinamani645e9b12012-12-21 14:23:40 -080075/* Configure gpio for blsp uart 2 */
76void gpio_config_uart_dm(uint8_t id)
77{
Deepa Dinamani0a6c48c2013-02-04 15:45:01 -080078 /* Configure GPIOs for BLSP1 UART3. */
79 /* configure rx gpio */
80 gpio_tlmm_config(9, 2, GPIO_INPUT, GPIO_NO_PULL,
Deepa Dinamani645e9b12012-12-21 14:23:40 -080081 GPIO_8MA, GPIO_DISABLE);
82
Deepa Dinamani0a6c48c2013-02-04 15:45:01 -080083 /* configure tx gpio */
84 gpio_tlmm_config(8, 2, GPIO_OUTPUT, GPIO_NO_PULL,
Deepa Dinamani645e9b12012-12-21 14:23:40 -080085 GPIO_8MA, GPIO_DISABLE);
86}