Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 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. |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation nor the names of its |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 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> |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 32 | #include <platform/gpio.h> |
| 33 | #include <gsbi.h> |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 34 | |
| 35 | void gpio_tlmm_config(uint32_t gpio, uint8_t func, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 36 | uint8_t dir, uint8_t pull, |
| 37 | uint8_t drvstr, uint32_t enable) |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 38 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 39 | unsigned int val = 0; |
| 40 | val |= pull; |
| 41 | val |= func << 2; |
| 42 | val |= drvstr << 6; |
| 43 | val |= enable << 9; |
| 44 | unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio); |
| 45 | writel(val, addr); |
| 46 | return; |
Shashank Mittal | c69512e | 2010-09-22 16:40:48 -0700 | [diff] [blame] | 47 | } |
Subbaraman Narayanamurthy | b0111a1 | 2011-02-03 14:24:16 -0800 | [diff] [blame] | 48 | |
| 49 | void gpio_set(uint32_t gpio, uint32_t dir) |
| 50 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 51 | unsigned int *addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio); |
| 52 | writel(dir, addr); |
| 53 | return; |
Subbaraman Narayanamurthy | b0111a1 | 2011-02-03 14:24:16 -0800 | [diff] [blame] | 54 | } |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 55 | |
| 56 | /* Configure gpio for uart - based on gsbi id */ |
| 57 | void gpio_config_uart_dm(uint8_t id) |
| 58 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 59 | switch (id) { |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 60 | case GSBI_ID_12: |
| 61 | /* configure rx gpio */ |
| 62 | gpio_tlmm_config(117, 2, GPIO_INPUT, GPIO_NO_PULL, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 63 | GPIO_8MA, GPIO_DISABLE); |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 64 | /* configure tx gpio */ |
| 65 | gpio_tlmm_config(118, 2, GPIO_OUTPUT, GPIO_NO_PULL, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 66 | GPIO_8MA, GPIO_DISABLE); |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 67 | break; |
| 68 | default: |
| 69 | ASSERT(0); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /* Configure gpio for i2c - based on gsbi id */ |
| 74 | void gpio_config_i2c(uint8_t id) |
| 75 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 76 | switch (id) { |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 77 | case GSBI_ID_8: |
| 78 | gpio_tlmm_config(64, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 79 | GPIO_2MA, GPIO_DISABLE); |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 80 | gpio_tlmm_config(65, 1, GPIO_OUTPUT, GPIO_NO_PULL, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 81 | GPIO_2MA, GPIO_DISABLE); |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 82 | break; |
| 83 | default: |
| 84 | ASSERT(0); |
| 85 | } |
| 86 | } |
| 87 | |
Shashank Mittal | 6df1607 | 2011-07-14 18:44:01 -0700 | [diff] [blame] | 88 | void gpio_config_pshold(void) |
| 89 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 90 | gpio_tlmm_config(92, 1, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_12MA, |
| 91 | GPIO_DISABLE); |
Shashank Mittal | 6df1607 | 2011-07-14 18:44:01 -0700 | [diff] [blame] | 92 | } |