Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4e16625 authored by Boojin Kim's avatar Boojin Kim Committed by Vinod Koul
Browse files

ARM: SAMSUNG: Add common DMA operations



This patch adds common DMA operations which are used for Samsung DMA
drivers. Currently there are two types of DMA driver for Samsung SoCs.
The one is S3C-DMA for S3C SoCs and the other is PL330-DMA for S5P SoCs.
This patch provides funcion pointers for common DMA operations to DMA
client driver like SPI and Audio. It makes DMA client drivers support
multi-platform.
In addition, this common DMA operations implement the shared actions
that are needed for DMA client driver. For example shared actions are
filter() function for dma_request_channel() and parameter passing for
device_prep_slave_sg().

Signed-off-by: default avatarBoojin Kim <boojin.kim@samsung.com>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarVinod Koul <vinod.koul@intel.com>
Signed-off-by: default avatarKukjin Kim <kgene.kim@samsung.com>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
parent aa0de00e
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -13,7 +13,6 @@
#ifndef __ASM_ARCH_DMA_H
#ifndef __ASM_ARCH_DMA_H
#define __ASM_ARCH_DMA_H __FILE__
#define __ASM_ARCH_DMA_H __FILE__


#include <plat/dma.h>
#include <linux/sysdev.h>
#include <linux/sysdev.h>


#define MAX_DMA_TRANSFER_SIZE   0x100000 /* Data Unit is half word  */
#define MAX_DMA_TRANSFER_SIZE   0x100000 /* Data Unit is half word  */
@@ -51,6 +50,13 @@ enum dma_ch {
	DMACH_MAX,		/* the end entry */
	DMACH_MAX,		/* the end entry */
};
};


static inline bool samsung_dma_is_dmadev(void)
{
	return false;
}

#include <plat/dma.h>

#define DMACH_LOW_LEVEL	(1<<28)	/* use this to specifiy hardware ch no */
#define DMACH_LOW_LEVEL	(1<<28)	/* use this to specifiy hardware ch no */


/* we have 4 dma channels */
/* we have 4 dma channels */
+4 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,10 @@ static __inline__ bool s3c_dma_has_circular(void)
	return true;
	return true;
}
}


static inline bool samsung_dma_is_dmadev(void)
{
	return false;
}
#define S3C2410_DMAF_CIRCULAR		(1 << 0)
#define S3C2410_DMAF_CIRCULAR		(1 << 0)


#include <plat/dma.h>
#include <plat/dma.h>
+4 −2
Original line number Original line Diff line number Diff line
@@ -63,9 +63,11 @@ obj-$(CONFIG_SAMSUNG_DEV_BACKLIGHT) += dev-backlight.o


# DMA support
# DMA support


obj-$(CONFIG_S3C_DMA)		+= dma.o
obj-$(CONFIG_S3C_DMA)		+= dma.o s3c-dma-ops.o


obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o
obj-$(CONFIG_SAMSUNG_DMADEV)	+= dma-ops.o

obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o s3c-dma-ops.o


# PM support
# PM support


+131 −0
Original line number Original line Diff line number Diff line
/* linux/arch/arm/plat-samsung/dma-ops.c
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Samsung DMA Operations
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/amba/pl330.h>
#include <linux/scatterlist.h>

#include <mach/dma.h>

static inline bool pl330_filter(struct dma_chan *chan, void *param)
{
	struct dma_pl330_peri *peri = chan->private;
	return peri->peri_id == (unsigned)param;
}

static unsigned samsung_dmadev_request(enum dma_ch dma_ch,
				struct samsung_dma_info *info)
{
	struct dma_chan *chan;
	dma_cap_mask_t mask;
	struct dma_slave_config slave_config;

	dma_cap_zero(mask);
	dma_cap_set(info->cap, mask);

	chan = dma_request_channel(mask, pl330_filter, (void *)dma_ch);

	if (info->direction == DMA_FROM_DEVICE) {
		memset(&slave_config, 0, sizeof(struct dma_slave_config));
		slave_config.direction = info->direction;
		slave_config.src_addr = info->fifo;
		slave_config.src_addr_width = info->width;
		slave_config.src_maxburst = 1;
		dmaengine_slave_config(chan, &slave_config);
	} else if (info->direction == DMA_TO_DEVICE) {
		memset(&slave_config, 0, sizeof(struct dma_slave_config));
		slave_config.direction = info->direction;
		slave_config.dst_addr = info->fifo;
		slave_config.dst_addr_width = info->width;
		slave_config.dst_maxburst = 1;
		dmaengine_slave_config(chan, &slave_config);
	}

	return (unsigned)chan;
}

static int samsung_dmadev_release(unsigned ch,
			struct s3c2410_dma_client *client)
{
	dma_release_channel((struct dma_chan *)ch);

	return 0;
}

static int samsung_dmadev_prepare(unsigned ch,
			struct samsung_dma_prep_info *info)
{
	struct scatterlist sg;
	struct dma_chan *chan = (struct dma_chan *)ch;
	struct dma_async_tx_descriptor *desc;

	switch (info->cap) {
	case DMA_SLAVE:
		sg_init_table(&sg, 1);
		sg_dma_len(&sg) = info->len;
		sg_set_page(&sg, pfn_to_page(PFN_DOWN(info->buf)),
			    info->len, offset_in_page(info->buf));
		sg_dma_address(&sg) = info->buf;

		desc = chan->device->device_prep_slave_sg(chan,
			&sg, 1, info->direction, DMA_PREP_INTERRUPT);
		break;
	case DMA_CYCLIC:
		desc = chan->device->device_prep_dma_cyclic(chan,
			info->buf, info->len, info->period, info->direction);
		break;
	default:
		dev_err(&chan->dev->device, "unsupported format\n");
		return -EFAULT;
	}

	if (!desc) {
		dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
		return -EFAULT;
	}

	desc->callback = info->fp;
	desc->callback_param = info->fp_param;

	dmaengine_submit((struct dma_async_tx_descriptor *)desc);

	return 0;
}

static inline int samsung_dmadev_trigger(unsigned ch)
{
	dma_async_issue_pending((struct dma_chan *)ch);

	return 0;
}

static inline int samsung_dmadev_flush(unsigned ch)
{
	return dmaengine_terminate_all((struct dma_chan *)ch);
}

struct samsung_dma_ops dmadev_ops = {
	.request	= samsung_dmadev_request,
	.release	= samsung_dmadev_release,
	.prepare	= samsung_dmadev_prepare,
	.trigger	= samsung_dmadev_trigger,
	.started	= NULL,
	.flush		= samsung_dmadev_flush,
	.stop		= samsung_dmadev_flush,
};

void *samsung_dmadev_get_ops(void)
{
	return &dmadev_ops;
}
EXPORT_SYMBOL(samsung_dmadev_get_ops);
+63 −0
Original line number Original line Diff line number Diff line
/* arch/arm/plat-samsung/include/plat/dma-ops.h
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Samsung DMA support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __SAMSUNG_DMA_OPS_H_
#define __SAMSUNG_DMA_OPS_H_ __FILE__

#include <linux/dmaengine.h>

struct samsung_dma_prep_info {
	enum dma_transaction_type cap;
	enum dma_data_direction direction;
	dma_addr_t buf;
	unsigned long period;
	unsigned long len;
	void (*fp)(void *data);
	void *fp_param;
};

struct samsung_dma_info {
	enum dma_transaction_type cap;
	enum dma_data_direction direction;
	enum dma_slave_buswidth width;
	dma_addr_t fifo;
	struct s3c2410_dma_client *client;
};

struct samsung_dma_ops {
	unsigned (*request)(enum dma_ch ch, struct samsung_dma_info *info);
	int (*release)(unsigned ch, struct s3c2410_dma_client *client);
	int (*prepare)(unsigned ch, struct samsung_dma_prep_info *info);
	int (*trigger)(unsigned ch);
	int (*started)(unsigned ch);
	int (*flush)(unsigned ch);
	int (*stop)(unsigned ch);
};

extern void *samsung_dmadev_get_ops(void);
extern void *s3c_dma_get_ops(void);

static inline void *__samsung_dma_get_ops(void)
{
	if (samsung_dma_is_dmadev())
		return samsung_dmadev_get_ops();
	else
		return s3c_dma_get_ops();
}

/*
 * samsung_dma_get_ops
 * get the set of samsung dma operations
 */
#define samsung_dma_get_ops() __samsung_dma_get_ops()

#endif /* __SAMSUNG_DMA_OPS_H_ */
Loading