Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 296073
b: refs/heads/master
c: e2f9157
h: refs/heads/master
i:
  296071: d06f9c5
v: v3
  • Loading branch information
Olof Johansson committed Feb 7, 2012
1 parent 090420e commit a7b77e6
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 13ae3d5bdf737d6078a562154ff4fef0ba5d0de1
refs/heads/master: e2f91578b35347341482f6af9e4fcf3174531efd
2 changes: 1 addition & 1 deletion trunk/arch/arm/mach-tegra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += pinmux-tegra30-tables.o
obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += board-dt-tegra30.o
obj-$(CONFIG_SMP) += platsmp.o localtimer.o headsmp.o
obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o
obj-$(CONFIG_TEGRA_SYSTEM_DMA) += dma.o
obj-$(CONFIG_TEGRA_SYSTEM_DMA) += dma.o apbio.o
obj-$(CONFIG_CPU_FREQ) += cpu-tegra.o
obj-$(CONFIG_TEGRA_PCI) += pcie.o
obj-$(CONFIG_USB_SUPPORT) += usb_phy.o
Expand Down
145 changes: 145 additions & 0 deletions trunk/arch/arm/mach-tegra/apbio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (C) 2010 NVIDIA Corporation.
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/

#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/dma-mapping.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/sched.h>
#include <linux/mutex.h>

#include <mach/dma.h>
#include <mach/iomap.h>

#include "apbio.h"

static DEFINE_MUTEX(tegra_apb_dma_lock);

static struct tegra_dma_channel *tegra_apb_dma;
static u32 *tegra_apb_bb;
static dma_addr_t tegra_apb_bb_phys;
static DECLARE_COMPLETION(tegra_apb_wait);

bool tegra_apb_init(void)
{
struct tegra_dma_channel *ch;

mutex_lock(&tegra_apb_dma_lock);

/* Check to see if we raced to setup */
if (tegra_apb_dma)
goto out;

ch = tegra_dma_allocate_channel(TEGRA_DMA_MODE_ONESHOT |
TEGRA_DMA_SHARED);

if (!ch)
goto out_fail;

tegra_apb_bb = dma_alloc_coherent(NULL, sizeof(u32),
&tegra_apb_bb_phys, GFP_KERNEL);
if (!tegra_apb_bb) {
pr_err("%s: can not allocate bounce buffer\n", __func__);
tegra_dma_free_channel(ch);
goto out_fail;
}

tegra_apb_dma = ch;
out:
mutex_unlock(&tegra_apb_dma_lock);
return true;

out_fail:
mutex_unlock(&tegra_apb_dma_lock);
return false;
}

static void apb_dma_complete(struct tegra_dma_req *req)
{
complete(&tegra_apb_wait);
}

u32 tegra_apb_readl(unsigned long offset)
{
struct tegra_dma_req req;
int ret;

if (!tegra_apb_dma && !tegra_apb_init())
return readl(IO_TO_VIRT(offset));

mutex_lock(&tegra_apb_dma_lock);
req.complete = apb_dma_complete;
req.to_memory = 1;
req.dest_addr = tegra_apb_bb_phys;
req.dest_bus_width = 32;
req.dest_wrap = 1;
req.source_addr = offset;
req.source_bus_width = 32;
req.source_wrap = 4;
req.req_sel = TEGRA_DMA_REQ_SEL_CNTR;
req.size = 4;

INIT_COMPLETION(tegra_apb_wait);

tegra_dma_enqueue_req(tegra_apb_dma, &req);

ret = wait_for_completion_timeout(&tegra_apb_wait,
msecs_to_jiffies(50));

if (WARN(ret == 0, "apb read dma timed out")) {
tegra_dma_dequeue_req(tegra_apb_dma, &req);
*(u32 *)tegra_apb_bb = 0;
}

mutex_unlock(&tegra_apb_dma_lock);
return *((u32 *)tegra_apb_bb);
}

void tegra_apb_writel(u32 value, unsigned long offset)
{
struct tegra_dma_req req;
int ret;

if (!tegra_apb_dma && !tegra_apb_init()) {
writel(value, IO_TO_VIRT(offset));
return;
}

mutex_lock(&tegra_apb_dma_lock);
*((u32 *)tegra_apb_bb) = value;
req.complete = apb_dma_complete;
req.to_memory = 0;
req.dest_addr = offset;
req.dest_wrap = 4;
req.dest_bus_width = 32;
req.source_addr = tegra_apb_bb_phys;
req.source_bus_width = 32;
req.source_wrap = 1;
req.req_sel = TEGRA_DMA_REQ_SEL_CNTR;
req.size = 4;

INIT_COMPLETION(tegra_apb_wait);

tegra_dma_enqueue_req(tegra_apb_dma, &req);

ret = wait_for_completion_timeout(&tegra_apb_wait,
msecs_to_jiffies(50));

if (WARN(ret == 0, "apb write dma timed out"))
tegra_dma_dequeue_req(tegra_apb_dma, &req);

mutex_unlock(&tegra_apb_dma_lock);
}
39 changes: 39 additions & 0 deletions trunk/arch/arm/mach-tegra/apbio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2010 NVIDIA Corporation.
* Copyright (C) 2010 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/

#ifndef __MACH_TEGRA_APBIO_H
#define __MACH_TEGRA_APBIO_H

#ifdef CONFIG_TEGRA_SYSTEM_DMA

u32 tegra_apb_readl(unsigned long offset);
void tegra_apb_writel(u32 value, unsigned long offset);

#else
#include <asm/io.h>
#include <mach/io.h>

static inline u32 tegra_apb_readl(unsigned long offset)
{
return readl(IO_TO_VIRT(offset));
}

static inline void tegra_apb_writel(u32 value, unsigned long offset)
{
writel(value, IO_TO_VIRT(offset));
}
#endif

#endif
2 changes: 2 additions & 0 deletions trunk/arch/arm/mach-tegra/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <mach/iomap.h>
#include <mach/suspend.h>

#include "apbio.h"

#define APB_DMA_GEN 0x000
#define GEN_ENABLE (1<<31)

Expand Down

0 comments on commit a7b77e6

Please sign in to comment.