blob: a87e9ccc341c7930461e1f59ec0b74bdf0de93ac [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010-2011 Code Aurora Forum. All rights reserved.
Gregory Bean1963a2a2010-08-28 10:05:44 -07002 *
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 Bean1963a2a2010-08-28 10:05:44 -070011 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070012#include <linux/bitops.h>
Gregory Bean1963a2a2010-08-28 10:05:44 -070013#include <linux/kernel.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070014#include <linux/io.h>
Rohit Vaswania513aa8d2011-07-18 15:14:28 -070015#include <mach/gpiomux.h>
Gregory Bean1963a2a2010-08-28 10:05:44 -070016#include "proc_comm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017#include "gpio.h"
Gregory Bean1963a2a2010-08-28 10:05:44 -070018
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019void __msm_gpiomux_write(unsigned gpio, struct gpiomux_setting val)
Gregory Bean1963a2a2010-08-28 10:05:44 -070020{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021 unsigned tlmm_config;
Gregory Bean1963a2a2010-08-28 10:05:44 -070022 unsigned tlmm_disable = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023 void __iomem *out_reg;
24 unsigned offset;
25 uint32_t bits;
Gregory Bean1963a2a2010-08-28 10:05:44 -070026 int rc;
27
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028 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 Bean1963a2a2010-08-28 10:05:44 -070042 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}