blob: ee1e17a916fe889dfefb664b9f6c1abb1513219d [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/io.h>
14#include <mach/msm_iomap.h>
Rohit Vaswania513aa8d2011-07-18 15:14:28 -070015#include <mach/gpiomux.h>
Gregory Bean1963a2a2010-08-28 10:05:44 -070016
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017#define GPIO_CFG(n) (MSM_TLMM_BASE + 0x1000 + (0x10 * n))
18#define GPIO_IN_OUT(n) (MSM_TLMM_BASE + 0x1004 + (0x10 * n))
19
20void __msm_gpiomux_write(unsigned gpio, struct gpiomux_setting val)
Gregory Bean1963a2a2010-08-28 10:05:44 -070021{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022 uint32_t bits;
23
24 bits = (val.drv << 6) | (val.func << 2) | val.pull;
25 if (val.func == GPIOMUX_FUNC_GPIO) {
26 bits |= val.dir > GPIOMUX_IN ? BIT(9) : 0;
27 __raw_writel(val.dir == GPIOMUX_OUT_HIGH ? BIT(1) : 0,
28 GPIO_IN_OUT(gpio));
29 }
30 __raw_writel(bits, GPIO_CFG(gpio));
31 mb();
Gregory Bean1963a2a2010-08-28 10:05:44 -070032}