Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2011 Code Aurora Forum. All rights reserved. |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 11 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 12 | #include <linux/bitops.h> |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 14 | #include <linux/io.h> |
Rohit Vaswani | a513aa8d | 2011-07-18 15:14:28 -0700 | [diff] [blame] | 15 | #include <mach/gpiomux.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 16 | #include <mach/proc_comm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 17 | #include "gpio.h" |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 18 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 19 | void __msm_gpiomux_write(unsigned gpio, struct gpiomux_setting val) |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 20 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | unsigned tlmm_config; |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 22 | unsigned tlmm_disable = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | void __iomem *out_reg; |
| 24 | unsigned offset; |
| 25 | uint32_t bits; |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 26 | int rc; |
| 27 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | tlmm_config = (val.drv << 17) | |
| 29 | (val.pull << 15) | |
| 30 | ((gpio & 0x3ff) << 4) | |
| 31 | val.func; |
| 32 | if (val.func == GPIOMUX_FUNC_GPIO) { |
| 33 | tlmm_config |= (val.dir > GPIOMUX_IN ? BIT(14) : 0); |
| 34 | msm_gpio_find_out(gpio, &out_reg, &offset); |
| 35 | bits = __raw_readl(out_reg); |
| 36 | if (val.dir == GPIOMUX_OUT_HIGH) |
| 37 | __raw_writel(bits | BIT(offset), out_reg); |
| 38 | else |
| 39 | __raw_writel(bits & ~BIT(offset), out_reg); |
| 40 | } |
| 41 | mb(); |
Gregory Bean | 1963a2a | 2010-08-28 10:05:44 -0700 | [diff] [blame] | 42 | rc = msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, |
| 43 | &tlmm_config, &tlmm_disable); |
| 44 | if (rc) |
| 45 | pr_err("%s: unexpected proc_comm failure %d: %08x %08x\n", |
| 46 | __func__, rc, tlmm_config, tlmm_disable); |
| 47 | } |