blob: 6ec4e33c61bb3bffed5812e00b6b266471b32d78 [file] [log] [blame]
Unnati Gandhib3820bc2014-07-04 16:56:27 +05301/* Copyright (c) 2014, 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#include <blsp_qup.h>
34
35void gpio_tlmm_config(uint32_t gpio, uint8_t func,
36 uint8_t dir, uint8_t pull,
37 uint8_t drvstr, uint32_t enable)
38{
39 uint32_t val = 0;
40 val |= pull;
41 val |= func << 2;
42 val |= drvstr << 6;
43 val |= enable << 9;
44 writel(val, (uint32_t *)GPIO_CONFIG_ADDR(gpio));
45 return;
46}
47
48void gpio_set(uint32_t gpio, uint32_t dir)
49{
50 writel(dir, (uint32_t *)GPIO_IN_OUT_ADDR(gpio));
51 return;
52}
53
54/* Configure gpio for blsp uart 2 */
55void gpio_config_uart_dm(uint8_t id)
56{
57 /* configure rx gpio */
Unnati Gandhi67adfe12014-09-30 13:14:22 +053058 gpio_tlmm_config(5, 2, GPIO_INPUT, GPIO_NO_PULL,
Unnati Gandhib3820bc2014-07-04 16:56:27 +053059 GPIO_8MA, GPIO_DISABLE);
60
61 /* configure tx gpio */
Unnati Gandhi67adfe12014-09-30 13:14:22 +053062 gpio_tlmm_config(4, 2, GPIO_OUTPUT, GPIO_NO_PULL,
Unnati Gandhib3820bc2014-07-04 16:56:27 +053063 GPIO_8MA, GPIO_DISABLE);
64}
Unnati Gandhif4cb6622014-08-28 13:54:56 +053065
66uint32_t gpio_status(uint32_t gpio)
67{
68 return readl(GPIO_IN_OUT_ADDR(gpio)) & GPIO_IN;
69}
70
Unnati Gandhi88cf23b2014-12-10 15:39:12 +053071void gpio_config_blsp_i2c(uint8_t blsp_id, uint8_t qup_id)
72{
73 if(blsp_id == BLSP_ID_1) {
74 switch (qup_id) {
75 case QUP_ID_1:
76 /* configure I2C SDA gpio */
77 gpio_tlmm_config(6, 3, GPIO_OUTPUT, GPIO_NO_PULL,
78 GPIO_8MA, GPIO_DISABLE);
79
80 /* configure I2C SCL gpio */
81 gpio_tlmm_config(7, 3, GPIO_OUTPUT, GPIO_NO_PULL,
82 GPIO_8MA, GPIO_DISABLE);
83 break;
84 case QUP_ID_2:
85 /* configure I2C SDA gpio */
86 gpio_tlmm_config(111, 3, GPIO_OUTPUT, GPIO_NO_PULL,
87 GPIO_8MA, GPIO_DISABLE);
88
89 /* configure I2C SCL gpio */
90 gpio_tlmm_config(112, 3, GPIO_OUTPUT, GPIO_NO_PULL,
91 GPIO_8MA, GPIO_DISABLE);
92 break;
93 case QUP_ID_3:
94 /* configure I2C SDA gpio */
95 gpio_tlmm_config(29, 3, GPIO_OUTPUT, GPIO_NO_PULL,
96 GPIO_8MA, GPIO_DISABLE);
97
98 /* configure I2C SCL gpio */
99 gpio_tlmm_config(30, 3, GPIO_OUTPUT, GPIO_NO_PULL,
100 GPIO_8MA, GPIO_DISABLE);
101 break;
102 case QUP_ID_4:
103 /* configure I2C SDA gpio */
104 gpio_tlmm_config(14, 3, GPIO_OUTPUT, GPIO_NO_PULL,
105 GPIO_8MA, GPIO_DISABLE);
106
107 /* configure I2C SCL gpio */
108 gpio_tlmm_config(15, 3, GPIO_OUTPUT, GPIO_NO_PULL,
109 GPIO_8MA, GPIO_DISABLE);
110 break;
111 case QUP_ID_5:
112 /* configure I2C SDA gpio */
113 gpio_tlmm_config(18, 3, GPIO_OUTPUT, GPIO_NO_PULL,
114 GPIO_8MA, GPIO_DISABLE);
115
116 /* configure I2C SCL gpio */
117 gpio_tlmm_config(19, 3, GPIO_OUTPUT, GPIO_NO_PULL,
118 GPIO_8MA, GPIO_DISABLE);
119 break;
120
121 default:
122 dprintf(CRITICAL, "Incorrect QUP id %d\n",qup_id);
123 ASSERT(0);
124 };
125 } else {
126 dprintf(CRITICAL, "Incorrect BLSP id %d\n",blsp_id);
127 ASSERT(0);
128 }
129}