* 'for-linus' of git://codeaurora.org/quic/kernel/davidb/linux-msm: (35 commits) mmc: msm_sdcc: Check for only DATA_END interrupt to end a request mmc: msm_sdcc: Fix bug in PIO mode when data size is not word aligned mmc: msm_sdcc: Reset SDCC in case of data transfer errors mmc: msm_sdcc: Add prog done interrupt support mmc: msm_sdcc: Fix possible circular locking dependency warning MSM: Add USB support for MSM7x30 MSM: Add USB suport for QSD8x50 msm: initial framebuffer support msm: add handling for clocks tagged as CLK_MINMAX msm: trout: change name of pmdh_clk to mddi_clk msm: add CLK_MINMAX to pmdh_clk msm: trout: add gpio_to_irq msm: iommu: Use the correct memory allocation flag msm_serial: Remove redundant unlikely() msm: iommu: Miscellaneous code cleanup msm: iommu: Support cache-coherent memory access msm: iommu: Definitions for extended memory attributes msm: iommu: Kconfig dependency for the IOMMU API msm: iommu: Check if device is already attached msm: iommu: Kconfig item for cacheable page tables ...tirimbino
commit
b69fc2efc9
@ -0,0 +1,297 @@ |
||||
/* linux/arch/arm/mach-msm/board-trout-mddi.c
|
||||
** Author: Brian Swetland <swetland@google.com> |
||||
*/ |
||||
|
||||
#include <linux/kernel.h> |
||||
#include <linux/init.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/delay.h> |
||||
#include <linux/leds.h> |
||||
#include <linux/clk.h> |
||||
#include <linux/err.h> |
||||
|
||||
#include <asm/io.h> |
||||
#include <asm/gpio.h> |
||||
#include <asm/mach-types.h> |
||||
|
||||
#include <mach/msm_fb.h> |
||||
#include <mach/vreg.h> |
||||
|
||||
#include "board-trout.h" |
||||
#include "proc_comm.h" |
||||
#include "devices.h" |
||||
|
||||
#define TROUT_DEFAULT_BACKLIGHT_BRIGHTNESS 255 |
||||
|
||||
#define MDDI_CLIENT_CORE_BASE 0x108000 |
||||
#define LCD_CONTROL_BLOCK_BASE 0x110000 |
||||
#define SPI_BLOCK_BASE 0x120000 |
||||
#define I2C_BLOCK_BASE 0x130000 |
||||
#define PWM_BLOCK_BASE 0x140000 |
||||
#define GPIO_BLOCK_BASE 0x150000 |
||||
#define SYSTEM_BLOCK1_BASE 0x160000 |
||||
#define SYSTEM_BLOCK2_BASE 0x170000 |
||||
|
||||
|
||||
#define DPSUS (MDDI_CLIENT_CORE_BASE|0x24) |
||||
#define SYSCLKENA (MDDI_CLIENT_CORE_BASE|0x2C) |
||||
#define PWM0OFF (PWM_BLOCK_BASE|0x1C) |
||||
|
||||
#define V_VDDE2E_VDD2_GPIO 0 |
||||
#define MDDI_RST_N 82 |
||||
|
||||
#define MDDICAP0 (MDDI_CLIENT_CORE_BASE|0x00) |
||||
#define MDDICAP1 (MDDI_CLIENT_CORE_BASE|0x04) |
||||
#define MDDICAP2 (MDDI_CLIENT_CORE_BASE|0x08) |
||||
#define MDDICAP3 (MDDI_CLIENT_CORE_BASE|0x0C) |
||||
#define MDCAPCHG (MDDI_CLIENT_CORE_BASE|0x10) |
||||
#define MDCRCERC (MDDI_CLIENT_CORE_BASE|0x14) |
||||
#define TTBUSSEL (MDDI_CLIENT_CORE_BASE|0x18) |
||||
#define DPSET0 (MDDI_CLIENT_CORE_BASE|0x1C) |
||||
#define DPSET1 (MDDI_CLIENT_CORE_BASE|0x20) |
||||
#define DPSUS (MDDI_CLIENT_CORE_BASE|0x24) |
||||
#define DPRUN (MDDI_CLIENT_CORE_BASE|0x28) |
||||
#define SYSCKENA (MDDI_CLIENT_CORE_BASE|0x2C) |
||||
#define TESTMODE (MDDI_CLIENT_CORE_BASE|0x30) |
||||
#define FIFOMONI (MDDI_CLIENT_CORE_BASE|0x34) |
||||
#define INTMONI (MDDI_CLIENT_CORE_BASE|0x38) |
||||
#define MDIOBIST (MDDI_CLIENT_CORE_BASE|0x3C) |
||||
#define MDIOPSET (MDDI_CLIENT_CORE_BASE|0x40) |
||||
#define BITMAP0 (MDDI_CLIENT_CORE_BASE|0x44) |
||||
#define BITMAP1 (MDDI_CLIENT_CORE_BASE|0x48) |
||||
#define BITMAP2 (MDDI_CLIENT_CORE_BASE|0x4C) |
||||
#define BITMAP3 (MDDI_CLIENT_CORE_BASE|0x50) |
||||
#define BITMAP4 (MDDI_CLIENT_CORE_BASE|0x54) |
||||
|
||||
#define SRST (LCD_CONTROL_BLOCK_BASE|0x00) |
||||
#define PORT_ENB (LCD_CONTROL_BLOCK_BASE|0x04) |
||||
#define START (LCD_CONTROL_BLOCK_BASE|0x08) |
||||
#define PORT (LCD_CONTROL_BLOCK_BASE|0x0C) |
||||
#define CMN (LCD_CONTROL_BLOCK_BASE|0x10) |
||||
#define GAMMA (LCD_CONTROL_BLOCK_BASE|0x14) |
||||
#define INTFLG (LCD_CONTROL_BLOCK_BASE|0x18) |
||||
#define INTMSK (LCD_CONTROL_BLOCK_BASE|0x1C) |
||||
#define MPLFBUF (LCD_CONTROL_BLOCK_BASE|0x20) |
||||
#define HDE_LEFT (LCD_CONTROL_BLOCK_BASE|0x24) |
||||
#define VDE_TOP (LCD_CONTROL_BLOCK_BASE|0x28) |
||||
#define PXL (LCD_CONTROL_BLOCK_BASE|0x30) |
||||
#define HCYCLE (LCD_CONTROL_BLOCK_BASE|0x34) |
||||
#define HSW (LCD_CONTROL_BLOCK_BASE|0x38) |
||||
#define HDE_START (LCD_CONTROL_BLOCK_BASE|0x3C) |
||||
#define HDE_SIZE (LCD_CONTROL_BLOCK_BASE|0x40) |
||||
#define VCYCLE (LCD_CONTROL_BLOCK_BASE|0x44) |
||||
#define VSW (LCD_CONTROL_BLOCK_BASE|0x48) |
||||
#define VDE_START (LCD_CONTROL_BLOCK_BASE|0x4C) |
||||
#define VDE_SIZE (LCD_CONTROL_BLOCK_BASE|0x50) |
||||
#define WAKEUP (LCD_CONTROL_BLOCK_BASE|0x54) |
||||
#define WSYN_DLY (LCD_CONTROL_BLOCK_BASE|0x58) |
||||
#define REGENB (LCD_CONTROL_BLOCK_BASE|0x5C) |
||||
#define VSYNIF (LCD_CONTROL_BLOCK_BASE|0x60) |
||||
#define WRSTB (LCD_CONTROL_BLOCK_BASE|0x64) |
||||
#define RDSTB (LCD_CONTROL_BLOCK_BASE|0x68) |
||||
#define ASY_DATA (LCD_CONTROL_BLOCK_BASE|0x6C) |
||||
#define ASY_DATB (LCD_CONTROL_BLOCK_BASE|0x70) |
||||
#define ASY_DATC (LCD_CONTROL_BLOCK_BASE|0x74) |
||||
#define ASY_DATD (LCD_CONTROL_BLOCK_BASE|0x78) |
||||
#define ASY_DATE (LCD_CONTROL_BLOCK_BASE|0x7C) |
||||
#define ASY_DATF (LCD_CONTROL_BLOCK_BASE|0x80) |
||||
#define ASY_DATG (LCD_CONTROL_BLOCK_BASE|0x84) |
||||
#define ASY_DATH (LCD_CONTROL_BLOCK_BASE|0x88) |
||||
#define ASY_CMDSET (LCD_CONTROL_BLOCK_BASE|0x8C) |
||||
|
||||
#define SSICTL (SPI_BLOCK_BASE|0x00) |
||||
#define SSITIME (SPI_BLOCK_BASE|0x04) |
||||
#define SSITX (SPI_BLOCK_BASE|0x08) |
||||
#define SSIRX (SPI_BLOCK_BASE|0x0C) |
||||
#define SSIINTC (SPI_BLOCK_BASE|0x10) |
||||
#define SSIINTS (SPI_BLOCK_BASE|0x14) |
||||
#define SSIDBG1 (SPI_BLOCK_BASE|0x18) |
||||
#define SSIDBG2 (SPI_BLOCK_BASE|0x1C) |
||||
#define SSIID (SPI_BLOCK_BASE|0x20) |
||||
|
||||
#define WKREQ (SYSTEM_BLOCK1_BASE|0x00) |
||||
#define CLKENB (SYSTEM_BLOCK1_BASE|0x04) |
||||
#define DRAMPWR (SYSTEM_BLOCK1_BASE|0x08) |
||||
#define INTMASK (SYSTEM_BLOCK1_BASE|0x0C) |
||||
#define GPIOSEL (SYSTEM_BLOCK2_BASE|0x00) |
||||
|
||||
#define GPIODATA (GPIO_BLOCK_BASE|0x00) |
||||
#define GPIODIR (GPIO_BLOCK_BASE|0x04) |
||||
#define GPIOIS (GPIO_BLOCK_BASE|0x08) |
||||
#define GPIOIBE (GPIO_BLOCK_BASE|0x0C) |
||||
#define GPIOIEV (GPIO_BLOCK_BASE|0x10) |
||||
#define GPIOIE (GPIO_BLOCK_BASE|0x14) |
||||
#define GPIORIS (GPIO_BLOCK_BASE|0x18) |
||||
#define GPIOMIS (GPIO_BLOCK_BASE|0x1C) |
||||
#define GPIOIC (GPIO_BLOCK_BASE|0x20) |
||||
#define GPIOOMS (GPIO_BLOCK_BASE|0x24) |
||||
#define GPIOPC (GPIO_BLOCK_BASE|0x28) |
||||
#define GPIOID (GPIO_BLOCK_BASE|0x30) |
||||
|
||||
#define SPI_WRITE(reg, val) \ |
||||
{ SSITX, 0x00010000 | (((reg) & 0xff) << 8) | ((val) & 0xff) }, \
|
||||
{ 0, 5 }, |
||||
|
||||
#define SPI_WRITE1(reg) \ |
||||
{ SSITX, (reg) & 0xff }, \
|
||||
{ 0, 5 }, |
||||
|
||||
struct mddi_table { |
||||
uint32_t reg; |
||||
uint32_t value; |
||||
}; |
||||
static struct mddi_table mddi_toshiba_init_table[] = { |
||||
{ DPSET0, 0x09e90046 }, |
||||
{ DPSET1, 0x00000118 }, |
||||
{ DPSUS, 0x00000000 }, |
||||
{ DPRUN, 0x00000001 }, |
||||
{ 1, 14 }, /* msleep 14 */ |
||||
{ SYSCKENA, 0x00000001 }, |
||||
{ CLKENB, 0x0000A1EF }, /* # SYS.CLKENB # Enable clocks for each module (without DCLK , i2cCLK) */ |
||||
|
||||
{ GPIODATA, 0x02000200 }, /* # GPI .GPIODATA # GPIO2(RESET_LCD_N) set to 0 , GPIO3(eDRAM_Power) set to 0 */ |
||||
{ GPIODIR, 0x000030D }, /* 24D # GPI .GPIODIR # Select direction of GPIO port (0,2,3,6,9 output) */ |
||||
{ GPIOSEL, 0/*0x00000173*/}, /* # SYS.GPIOSEL # GPIO port multiplexing control */ |
||||
{ GPIOPC, 0x03C300C0 }, /* # GPI .GPIOPC # GPIO2,3 PD cut */ |
||||
{ WKREQ, 0x00000000 }, /* # SYS.WKREQ # Wake-up request event is VSYNC alignment */ |
||||
|
||||
{ GPIOIBE, 0x000003FF }, |
||||
{ GPIOIS, 0x00000000 }, |
||||
{ GPIOIC, 0x000003FF }, |
||||
{ GPIOIE, 0x00000000 }, |
||||
|
||||
{ GPIODATA, 0x00040004 }, /* # GPI .GPIODATA # eDRAM VD supply */ |
||||
{ 1, 1 }, /* msleep 1 */ |
||||
{ GPIODATA, 0x02040004 }, /* # GPI .GPIODATA # eDRAM VD supply */ |
||||
{ DRAMPWR, 0x00000001 }, /* eDRAM power */ |
||||
}; |
||||
|
||||
#define GPIOSEL_VWAKEINT (1U << 0) |
||||
#define INTMASK_VWAKEOUT (1U << 0) |
||||
|
||||
|
||||
static struct clk *gp_clk; |
||||
static int trout_new_backlight = 1; |
||||
static struct vreg *vreg_mddi_1v5; |
||||
static struct vreg *vreg_lcm_2v85; |
||||
|
||||
static void trout_process_mddi_table(struct msm_mddi_client_data *client_data, |
||||
struct mddi_table *table, size_t count) |
||||
{ |
||||
int i; |
||||
for (i = 0; i < count; i++) { |
||||
uint32_t reg = table[i].reg; |
||||
uint32_t value = table[i].value; |
||||
|
||||
if (reg == 0) |
||||
udelay(value); |
||||
else if (reg == 1) |
||||
msleep(value); |
||||
else |
||||
client_data->remote_write(client_data, value, reg); |
||||
} |
||||
} |
||||
|
||||
static int trout_mddi_toshiba_client_init( |
||||
struct msm_mddi_bridge_platform_data *bridge_data, |
||||
struct msm_mddi_client_data *client_data) |
||||
{ |
||||
int panel_id; |
||||
|
||||
client_data->auto_hibernate(client_data, 0); |
||||
trout_process_mddi_table(client_data, mddi_toshiba_init_table, |
||||
ARRAY_SIZE(mddi_toshiba_init_table)); |
||||
client_data->auto_hibernate(client_data, 1); |
||||
panel_id = (client_data->remote_read(client_data, GPIODATA) >> 4) & 3; |
||||
if (panel_id > 1) { |
||||
printk(KERN_WARNING "unknown panel id at mddi_enable\n"); |
||||
return -1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static int trout_mddi_toshiba_client_uninit( |
||||
struct msm_mddi_bridge_platform_data *bridge_data, |
||||
struct msm_mddi_client_data *client_data) |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
static struct resource resources_msm_fb[] = { |
||||
{ |
||||
.start = MSM_FB_BASE, |
||||
.end = MSM_FB_BASE + MSM_FB_SIZE, |
||||
.flags = IORESOURCE_MEM, |
||||
}, |
||||
}; |
||||
|
||||
struct msm_mddi_bridge_platform_data toshiba_client_data = { |
||||
.init = trout_mddi_toshiba_client_init, |
||||
.uninit = trout_mddi_toshiba_client_uninit, |
||||
.fb_data = { |
||||
.xres = 320, |
||||
.yres = 480, |
||||
.width = 45, |
||||
.height = 67, |
||||
.output_format = 0, |
||||
}, |
||||
}; |
||||
|
||||
static struct msm_mddi_platform_data mddi_pdata = { |
||||
.clk_rate = 122880000, |
||||
.fb_resource = resources_msm_fb, |
||||
.num_clients = 1, |
||||
.client_platform_data = { |
||||
{ |
||||
.product_id = (0xd263 << 16 | 0), |
||||
.name = "mddi_c_d263_0000", |
||||
.id = 0, |
||||
.client_data = &toshiba_client_data, |
||||
.clk_rate = 0, |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
int __init trout_init_panel(void) |
||||
{ |
||||
int rc; |
||||
|
||||
if (!machine_is_trout()) |
||||
return 0; |
||||
vreg_mddi_1v5 = vreg_get(0, "gp2"); |
||||
if (IS_ERR(vreg_mddi_1v5)) |
||||
return PTR_ERR(vreg_mddi_1v5); |
||||
vreg_lcm_2v85 = vreg_get(0, "gp4"); |
||||
if (IS_ERR(vreg_lcm_2v85)) |
||||
return PTR_ERR(vreg_lcm_2v85); |
||||
|
||||
trout_new_backlight = system_rev >= 5; |
||||
if (trout_new_backlight) { |
||||
uint32_t config = PCOM_GPIO_CFG(27, 0, GPIO_OUTPUT, |
||||
GPIO_NO_PULL, GPIO_8MA); |
||||
msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &config, 0); |
||||
} else { |
||||
uint32_t config = PCOM_GPIO_CFG(27, 1, GPIO_OUTPUT, |
||||
GPIO_NO_PULL, GPIO_8MA); |
||||
msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &config, 0); |
||||
|
||||
gp_clk = clk_get(NULL, "gp_clk"); |
||||
if (IS_ERR(gp_clk)) { |
||||
printk(KERN_ERR "trout_init_panel: could not get gp" |
||||
"clock\n"); |
||||
gp_clk = NULL; |
||||
} |
||||
rc = clk_set_rate(gp_clk, 19200000); |
||||
if (rc) |
||||
printk(KERN_ERR "trout_init_panel: set clock rate " |
||||
"failed\n"); |
||||
} |
||||
|
||||
rc = platform_device_register(&msm_device_mdp); |
||||
if (rc) |
||||
return rc; |
||||
msm_device_mddi0.dev.platform_data = &mddi_pdata; |
||||
return platform_device_register(&msm_device_mddi0); |
||||
} |
||||
|
||||
device_initcall(trout_init_panel); |
@ -0,0 +1,426 @@ |
||||
/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
|
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License version 2 and |
||||
* only version 2 as published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
||||
* 02110-1301, USA. |
||||
* |
||||
*/ |
||||
#define pr_fmt(fmt) "%s: " fmt, __func__ |
||||
|
||||
#include <linux/bitmap.h> |
||||
#include <linux/bitops.h> |
||||
#include <linux/gpio.h> |
||||
#include <linux/init.h> |
||||
#include <linux/interrupt.h> |
||||
#include <linux/io.h> |
||||
#include <linux/irq.h> |
||||
#include <linux/module.h> |
||||
#include <linux/platform_device.h> |
||||
#include <linux/spinlock.h> |
||||
#include <mach/msm_iomap.h> |
||||
#include "gpiomux.h" |
||||
|
||||
/* Bits of interest in the GPIO_IN_OUT register.
|
||||
*/ |
||||
enum { |
||||
GPIO_IN = 0, |
||||
GPIO_OUT = 1 |
||||
}; |
||||
|
||||
/* Bits of interest in the GPIO_INTR_STATUS register.
|
||||
*/ |
||||
enum { |
||||
INTR_STATUS = 0, |
||||
}; |
||||
|
||||
/* Bits of interest in the GPIO_CFG register.
|
||||
*/ |
||||
enum { |
||||
GPIO_OE = 9, |
||||
}; |
||||
|
||||
/* Bits of interest in the GPIO_INTR_CFG register.
|
||||
* When a GPIO triggers, two separate decisions are made, controlled |
||||
* by two separate flags. |
||||
* |
||||
* - First, INTR_RAW_STATUS_EN controls whether or not the GPIO_INTR_STATUS |
||||
* register for that GPIO will be updated to reflect the triggering of that |
||||
* gpio. If this bit is 0, this register will not be updated. |
||||
* - Second, INTR_ENABLE controls whether an interrupt is triggered. |
||||
* |
||||
* If INTR_ENABLE is set and INTR_RAW_STATUS_EN is NOT set, an interrupt |
||||
* can be triggered but the status register will not reflect it. |
||||
*/ |
||||
enum { |
||||
INTR_ENABLE = 0, |
||||
INTR_POL_CTL = 1, |
||||
INTR_DECT_CTL = 2, |
||||
INTR_RAW_STATUS_EN = 3, |
||||
}; |
||||
|
||||
/* Codes of interest in GPIO_INTR_CFG_SU.
|
||||
*/ |
||||
enum { |
||||
TARGET_PROC_SCORPION = 4, |
||||
TARGET_PROC_NONE = 7, |
||||
}; |
||||
|
||||
|
||||
#define GPIO_INTR_CFG_SU(gpio) (MSM_TLMM_BASE + 0x0400 + (0x04 * (gpio))) |
||||
#define GPIO_CONFIG(gpio) (MSM_TLMM_BASE + 0x1000 + (0x10 * (gpio))) |
||||
#define GPIO_IN_OUT(gpio) (MSM_TLMM_BASE + 0x1004 + (0x10 * (gpio))) |
||||
#define GPIO_INTR_CFG(gpio) (MSM_TLMM_BASE + 0x1008 + (0x10 * (gpio))) |
||||
#define GPIO_INTR_STATUS(gpio) (MSM_TLMM_BASE + 0x100c + (0x10 * (gpio))) |
||||
|
||||
/**
|
||||
* struct msm_gpio_dev: the MSM8660 SoC GPIO device structure |
||||
* |
||||
* @enabled_irqs: a bitmap used to optimize the summary-irq handler. By |
||||
* keeping track of which gpios are unmasked as irq sources, we avoid |
||||
* having to do readl calls on hundreds of iomapped registers each time |
||||
* the summary interrupt fires in order to locate the active interrupts. |
||||
* |
||||
* @wake_irqs: a bitmap for tracking which interrupt lines are enabled |
||||
* as wakeup sources. When the device is suspended, interrupts which are |
||||
* not wakeup sources are disabled. |
||||
* |
||||
* @dual_edge_irqs: a bitmap used to track which irqs are configured |
||||
* as dual-edge, as this is not supported by the hardware and requires |
||||
* some special handling in the driver. |
||||
*/ |
||||
struct msm_gpio_dev { |
||||
struct gpio_chip gpio_chip; |
||||
DECLARE_BITMAP(enabled_irqs, NR_GPIO_IRQS); |
||||
DECLARE_BITMAP(wake_irqs, NR_GPIO_IRQS); |
||||
DECLARE_BITMAP(dual_edge_irqs, NR_GPIO_IRQS); |
||||
}; |
||||
|
||||
static DEFINE_SPINLOCK(tlmm_lock); |
||||
|
||||
static inline struct msm_gpio_dev *to_msm_gpio_dev(struct gpio_chip *chip) |
||||
{ |
||||
return container_of(chip, struct msm_gpio_dev, gpio_chip); |
||||
} |
||||
|
||||
static inline void set_gpio_bits(unsigned n, void __iomem *reg) |
||||
{ |
||||
writel(readl(reg) | n, reg); |
||||
} |
||||
|
||||
static inline void clear_gpio_bits(unsigned n, void __iomem *reg) |
||||
{ |
||||
writel(readl(reg) & ~n, reg); |
||||
} |
||||
|
||||
static int msm_gpio_get(struct gpio_chip *chip, unsigned offset) |
||||
{ |
||||
return readl(GPIO_IN_OUT(offset)) & BIT(GPIO_IN); |
||||
} |
||||
|
||||
static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int val) |
||||
{ |
||||
writel(val ? BIT(GPIO_OUT) : 0, GPIO_IN_OUT(offset)); |
||||
} |
||||
|
||||
static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
||||
{ |
||||
unsigned long irq_flags; |
||||
|
||||
spin_lock_irqsave(&tlmm_lock, irq_flags); |
||||
clear_gpio_bits(BIT(GPIO_OE), GPIO_CONFIG(offset)); |
||||
spin_unlock_irqrestore(&tlmm_lock, irq_flags); |
||||
return 0; |
||||
} |
||||
|
||||
static int msm_gpio_direction_output(struct gpio_chip *chip, |
||||
unsigned offset, |
||||
int val) |
||||
{ |
||||
unsigned long irq_flags; |
||||
|
||||
spin_lock_irqsave(&tlmm_lock, irq_flags); |
||||
msm_gpio_set(chip, offset, val); |
||||
set_gpio_bits(BIT(GPIO_OE), GPIO_CONFIG(offset)); |
||||
spin_unlock_irqrestore(&tlmm_lock, irq_flags); |
||||
return 0; |
||||
} |
||||
|
||||
static int msm_gpio_request(struct gpio_chip *chip, unsigned offset) |
||||
{ |
||||
return msm_gpiomux_get(chip->base + offset); |
||||
} |
||||
|
||||
static void msm_gpio_free(struct gpio_chip *chip, unsigned offset) |
||||
{ |
||||
msm_gpiomux_put(chip->base + offset); |
||||
} |
||||
|
||||
static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
||||
{ |
||||
return MSM_GPIO_TO_INT(chip->base + offset); |
||||
} |
||||
|
||||
static inline int msm_irq_to_gpio(struct gpio_chip *chip, unsigned irq) |
||||
{ |
||||
return irq - MSM_GPIO_TO_INT(chip->base); |
||||
} |
||||
|
||||
static struct msm_gpio_dev msm_gpio = { |
||||
.gpio_chip = { |
||||
.base = 0, |
||||
.ngpio = NR_GPIO_IRQS, |
||||
.direction_input = msm_gpio_direction_input, |
||||
.direction_output = msm_gpio_direction_output, |
||||
.get = msm_gpio_get, |
||||
.set = msm_gpio_set, |
||||
.to_irq = msm_gpio_to_irq, |
||||
.request = msm_gpio_request, |
||||
.free = msm_gpio_free, |
||||
}, |
||||
}; |
||||
|
||||
/* For dual-edge interrupts in software, since the hardware has no
|
||||
* such support: |
||||
* |
||||
* At appropriate moments, this function may be called to flip the polarity |
||||
* settings of both-edge irq lines to try and catch the next edge. |
||||
* |
||||
* The attempt is considered successful if: |
||||
* - the status bit goes high, indicating that an edge was caught, or |
||||
* - the input value of the gpio doesn't change during the attempt. |
||||
* If the value changes twice during the process, that would cause the first |
||||
* test to fail but would force the second, as two opposite |
||||
* transitions would cause a detection no matter the polarity setting. |
||||
* |
||||
* The do-loop tries to sledge-hammer closed the timing hole between |
||||
* the initial value-read and the polarity-write - if the line value changes |
||||
* during that window, an interrupt is lost, the new polarity setting is |
||||
* incorrect, and the first success test will fail, causing a retry. |
||||
* |
||||
* Algorithm comes from Google's msmgpio driver, see mach-msm/gpio.c. |
||||
*/ |
||||
static void msm_gpio_update_dual_edge_pos(unsigned gpio) |
||||
{ |
||||
int loop_limit = 100; |
||||
unsigned val, val2, intstat; |
||||
|
||||
do { |
||||
val = readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN); |
||||
if (val) |
||||
clear_gpio_bits(BIT(INTR_POL_CTL), GPIO_INTR_CFG(gpio)); |
||||
else |
||||
set_gpio_bits(BIT(INTR_POL_CTL), GPIO_INTR_CFG(gpio)); |
||||
val2 = readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN); |
||||
intstat = readl(GPIO_INTR_STATUS(gpio)) & BIT(INTR_STATUS); |
||||
if (intstat || val == val2) |
||||
return; |
||||
} while (loop_limit-- > 0); |
||||
pr_err("dual-edge irq failed to stabilize, " |
||||
"interrupts dropped. %#08x != %#08x\n", |
||||
val, val2); |
||||
} |
||||
|
||||
static void msm_gpio_irq_ack(unsigned int irq) |
||||
{ |
||||
int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, irq); |
||||
|
||||
writel(BIT(INTR_STATUS), GPIO_INTR_STATUS(gpio)); |
||||
if (test_bit(gpio, msm_gpio.dual_edge_irqs)) |
||||
msm_gpio_update_dual_edge_pos(gpio); |
||||
} |
||||
|
||||
static void msm_gpio_irq_mask(unsigned int irq) |
||||
{ |
||||
int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, irq); |
||||
unsigned long irq_flags; |
||||
|
||||
spin_lock_irqsave(&tlmm_lock, irq_flags); |
||||
writel(TARGET_PROC_NONE, GPIO_INTR_CFG_SU(gpio)); |
||||
clear_gpio_bits(INTR_RAW_STATUS_EN | INTR_ENABLE, GPIO_INTR_CFG(gpio)); |
||||
__clear_bit(gpio, msm_gpio.enabled_irqs); |
||||
spin_unlock_irqrestore(&tlmm_lock, irq_flags); |
||||
} |
||||
|
||||
static void msm_gpio_irq_unmask(unsigned int irq) |
||||
{ |
||||
int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, irq); |
||||
unsigned long irq_flags; |
||||
|
||||
spin_lock_irqsave(&tlmm_lock, irq_flags); |
||||
__set_bit(gpio, msm_gpio.enabled_irqs); |
||||
set_gpio_bits(INTR_RAW_STATUS_EN | INTR_ENABLE, GPIO_INTR_CFG(gpio)); |
||||
writel(TARGET_PROC_SCORPION, GPIO_INTR_CFG_SU(gpio)); |
||||
spin_unlock_irqrestore(&tlmm_lock, irq_flags); |
||||
} |
||||
|
||||
static int msm_gpio_irq_set_type(unsigned int irq, unsigned int flow_type) |
||||
{ |
||||
int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, irq); |
||||
unsigned long irq_flags; |
||||
uint32_t bits; |
||||
|
||||
spin_lock_irqsave(&tlmm_lock, irq_flags); |
||||
|
||||
bits = readl(GPIO_INTR_CFG(gpio)); |
||||
|
||||
if (flow_type & IRQ_TYPE_EDGE_BOTH) { |
||||
bits |= BIT(INTR_DECT_CTL); |
||||
irq_desc[irq].handle_irq = handle_edge_irq; |
||||
if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) |
||||
__set_bit(gpio, msm_gpio.dual_edge_irqs); |
||||
else |
||||
__clear_bit(gpio, msm_gpio.dual_edge_irqs); |
||||
} else { |
||||
bits &= ~BIT(INTR_DECT_CTL); |
||||
irq_desc[irq].handle_irq = handle_level_irq; |
||||
__clear_bit(gpio, msm_gpio.dual_edge_irqs); |
||||
} |
||||
|
||||
if (flow_type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_HIGH)) |
||||
bits |= BIT(INTR_POL_CTL); |
||||
else |
||||
bits &= ~BIT(INTR_POL_CTL); |
||||
|
||||
writel(bits, GPIO_INTR_CFG(gpio)); |
||||
|
||||
if ((flow_type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) |
||||
msm_gpio_update_dual_edge_pos(gpio); |
||||
|
||||
spin_unlock_irqrestore(&tlmm_lock, irq_flags); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
/*
|
||||
* When the summary IRQ is raised, any number of GPIO lines may be high. |
||||
* It is the job of the summary handler to find all those GPIO lines |
||||
* which have been set as summary IRQ lines and which are triggered, |
||||
* and to call their interrupt handlers. |
||||
*/ |
||||
static void msm_summary_irq_handler(unsigned int irq, struct irq_desc *desc) |
||||
{ |
||||
unsigned long i; |
||||
|
||||
for (i = find_first_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS); |
||||
i < NR_GPIO_IRQS; |
||||
i = find_next_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS, i + 1)) { |
||||
if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) |
||||
generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip, |
||||
i)); |
||||
} |
||||
desc->chip->ack(irq); |
||||
} |
||||
|
||||
static int msm_gpio_irq_set_wake(unsigned int irq, unsigned int on) |
||||
{ |
||||
int gpio = msm_irq_to_gpio(&msm_gpio.gpio_chip, irq); |
||||
|
||||
if (on) { |
||||
if (bitmap_empty(msm_gpio.wake_irqs, NR_GPIO_IRQS)) |
||||
set_irq_wake(TLMM_SCSS_SUMMARY_IRQ, 1); |
||||
set_bit(gpio, msm_gpio.wake_irqs); |
||||
} else { |
||||
clear_bit(gpio, msm_gpio.wake_irqs); |
||||
if (bitmap_empty(msm_gpio.wake_irqs, NR_GPIO_IRQS)) |
||||
set_irq_wake(TLMM_SCSS_SUMMARY_IRQ, 0); |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static struct irq_chip msm_gpio_irq_chip = { |
||||
.name = "msmgpio", |
||||
.mask = msm_gpio_irq_mask, |
||||
.unmask = msm_gpio_irq_unmask, |
||||
.ack = msm_gpio_irq_ack, |
||||
.set_type = msm_gpio_irq_set_type, |
||||
.set_wake = msm_gpio_irq_set_wake, |
||||
}; |
||||
|
||||
static int __devinit msm_gpio_probe(struct platform_device *dev) |
||||
{ |
||||
int i, irq, ret; |
||||
|
||||
bitmap_zero(msm_gpio.enabled_irqs, NR_GPIO_IRQS); |
||||
bitmap_zero(msm_gpio.wake_irqs, NR_GPIO_IRQS); |
||||
bitmap_zero(msm_gpio.dual_edge_irqs, NR_GPIO_IRQS); |
||||
msm_gpio.gpio_chip.label = dev->name; |
||||
ret = gpiochip_add(&msm_gpio.gpio_chip); |
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
for (i = 0; i < msm_gpio.gpio_chip.ngpio; ++i) { |
||||
irq = msm_gpio_to_irq(&msm_gpio.gpio_chip, i); |
||||
set_irq_chip(irq, &msm_gpio_irq_chip); |
||||
set_irq_handler(irq, handle_level_irq); |
||||
set_irq_flags(irq, IRQF_VALID); |
||||
} |
||||
|
||||
set_irq_chained_handler(TLMM_SCSS_SUMMARY_IRQ, |
||||
msm_summary_irq_handler); |
||||
return 0; |
||||
} |
||||
|
||||
static int __devexit msm_gpio_remove(struct platform_device *dev) |
||||
{ |
||||
int ret = gpiochip_remove(&msm_gpio.gpio_chip); |
||||
|
||||
if (ret < 0) |
||||
return ret; |
||||
|
||||
set_irq_handler(TLMM_SCSS_SUMMARY_IRQ, NULL); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static struct platform_driver msm_gpio_driver = { |
||||
.probe = msm_gpio_probe, |
||||
.remove = __devexit_p(msm_gpio_remove), |
||||
.driver = { |
||||
.name = "msmgpio", |
||||
.owner = THIS_MODULE, |
||||
}, |
||||
}; |
||||
|
||||
static struct platform_device msm_device_gpio = { |
||||
.name = "msmgpio", |
||||
.id = -1, |
||||
}; |
||||
|
||||
static int __init msm_gpio_init(void) |
||||
{ |
||||
int rc; |
||||
|
||||
rc = platform_driver_register(&msm_gpio_driver); |
||||
if (!rc) { |
||||
rc = platform_device_register(&msm_device_gpio); |
||||
if (rc) |
||||
platform_driver_unregister(&msm_gpio_driver); |
||||
} |
||||
|
||||
return rc; |
||||
} |
||||
|
||||
static void __exit msm_gpio_exit(void) |
||||
{ |
||||
platform_device_unregister(&msm_device_gpio); |
||||
platform_driver_unregister(&msm_gpio_driver); |
||||
} |
||||
|
||||
postcore_initcall(msm_gpio_init); |
||||
module_exit(msm_gpio_exit); |
||||
|
||||
MODULE_AUTHOR("Gregory Bean <gbean@codeaurora.org>"); |
||||
MODULE_DESCRIPTION("Driver for Qualcomm MSM TLMMv2 SoC GPIOs"); |
||||
MODULE_LICENSE("GPL v2"); |
||||
MODULE_ALIAS("platform:msmgpio"); |
Loading…
Reference in new issue