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

Commit 48f011ab authored by Arjun Singh's avatar Arjun Singh Committed by Gerrit - the friendly Code Review server
Browse files

soc: qcom: bgcom: add support for reserved cma memory allocation



Adds support for reserved cma memory for read write assests.

Change-Id: I7518ba1ed30aabd641e930d3a897c30c40234f4a
Signed-off-by: default avatarArjun Singh <arsingh@codeaurora.org>
Signed-off-by: default avatarRamesh Yadav Javadi <javadi@codeaurora.org>
parent 04dddde8
Loading
Loading
Loading
Loading
+23 −10
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <linux/gpio.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/of_gpio.h>
#include <linux/kthread.h>
#include <linux/kthread.h>
#include <linux/dma-mapping.h>
#include "bgcom.h"
#include "bgcom.h"
#include "bgrsb.h"
#include "bgrsb.h"
#include "bgcom_interface.h"
#include "bgcom_interface.h"
@@ -116,6 +117,14 @@ static struct mutex bg_resume_mutex;
static atomic_t  bg_is_spi_active;
static atomic_t  bg_is_spi_active;
static int bg_irq;
static int bg_irq;


static struct spi_device *get_spi_device(void)
{
	struct bg_spi_priv *bg_spi = container_of(bg_com_drv,
						struct bg_spi_priv, lhandle);
	struct spi_device *spi = bg_spi->spi;
	return spi;
}

static void augmnt_fifo(uint8_t *data, int pos)
static void augmnt_fifo(uint8_t *data, int pos)
{
{
	data[pos] = '\0';
	data[pos] = '\0';
@@ -454,6 +463,7 @@ static void bg_irq_tasklet_hndlr_l(void)
int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	uint32_t num_words, void *read_buf)
	uint32_t num_words, void *read_buf)
{
{
	dma_addr_t dma_hndl_tx, dma_hndl_rx;
	uint32_t txn_len;
	uint32_t txn_len;
	uint8_t *tx_buf;
	uint8_t *tx_buf;
	uint8_t *rx_buf;
	uint8_t *rx_buf;
@@ -461,6 +471,7 @@ int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	int ret;
	int ret;
	uint8_t cmnd = 0;
	uint8_t cmnd = 0;
	uint32_t ahb_addr = 0;
	uint32_t ahb_addr = 0;
	struct spi_device *spi = get_spi_device();


	if (!handle || !read_buf || num_words == 0
	if (!handle || !read_buf || num_words == 0
		|| num_words > BG_SPI_MAX_WORDS) {
		|| num_words > BG_SPI_MAX_WORDS) {
@@ -483,15 +494,16 @@ int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	size = num_words*BG_SPI_WORD_SIZE;
	size = num_words*BG_SPI_WORD_SIZE;
	txn_len = BG_SPI_AHB_READ_CMD_LEN + size;
	txn_len = BG_SPI_AHB_READ_CMD_LEN + size;


	tx_buf = kzalloc(txn_len, GFP_KERNEL);


	tx_buf = dma_zalloc_coherent(&spi->dev, txn_len,
					&dma_hndl_tx, GFP_KERNEL);
	if (!tx_buf)
	if (!tx_buf)
		return -ENOMEM;
		return -ENOMEM;


	rx_buf = kzalloc(txn_len, GFP_KERNEL);
	rx_buf = dma_zalloc_coherent(&spi->dev, txn_len,

					&dma_hndl_rx, GFP_KERNEL);
	if (!rx_buf) {
	if (!rx_buf) {
		kfree(tx_buf);
		dma_free_coherent(&spi->dev, txn_len, tx_buf, dma_hndl_tx);
		return -ENOMEM;
		return -ENOMEM;
	}
	}


@@ -506,8 +518,8 @@ int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	if (!ret)
	if (!ret)
		memcpy(read_buf, rx_buf+BG_SPI_AHB_READ_CMD_LEN, size);
		memcpy(read_buf, rx_buf+BG_SPI_AHB_READ_CMD_LEN, size);


	kfree(tx_buf);
	dma_free_coherent(&spi->dev, txn_len, tx_buf, dma_hndl_tx);
	kfree(rx_buf);
	dma_free_coherent(&spi->dev, txn_len, rx_buf, dma_hndl_rx);
	return ret;
	return ret;
}
}
EXPORT_SYMBOL(bgcom_ahb_read);
EXPORT_SYMBOL(bgcom_ahb_read);
@@ -515,12 +527,14 @@ EXPORT_SYMBOL(bgcom_ahb_read);
int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr,
int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr,
	uint32_t num_words, void *write_buf)
	uint32_t num_words, void *write_buf)
{
{
	dma_addr_t dma_hndl;
	uint32_t txn_len;
	uint32_t txn_len;
	uint8_t *tx_buf;
	uint8_t *tx_buf;
	uint32_t size;
	uint32_t size;
	int ret;
	int ret;
	uint8_t cmnd = 0;
	uint8_t cmnd = 0;
	uint32_t ahb_addr = 0;
	uint32_t ahb_addr = 0;
	struct spi_device *spi = get_spi_device();


	if (!handle || !write_buf || num_words == 0
	if (!handle || !write_buf || num_words == 0
		|| num_words > BG_SPI_MAX_WORDS) {
		|| num_words > BG_SPI_MAX_WORDS) {
@@ -543,9 +557,7 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr,


	size = num_words*BG_SPI_WORD_SIZE;
	size = num_words*BG_SPI_WORD_SIZE;
	txn_len = BG_SPI_AHB_CMD_LEN + size;
	txn_len = BG_SPI_AHB_CMD_LEN + size;

	tx_buf = dma_zalloc_coherent(&spi->dev, txn_len, &dma_hndl, GFP_KERNEL);
	tx_buf = kzalloc(txn_len, GFP_KERNEL);

	if (!tx_buf)
	if (!tx_buf)
		return -ENOMEM;
		return -ENOMEM;


@@ -557,7 +569,7 @@ int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr,
	memcpy(tx_buf+BG_SPI_AHB_CMD_LEN, write_buf, size);
	memcpy(tx_buf+BG_SPI_AHB_CMD_LEN, write_buf, size);


	ret = bgcom_transfer(handle, tx_buf, NULL, txn_len);
	ret = bgcom_transfer(handle, tx_buf, NULL, txn_len);
	kfree(tx_buf);
	dma_free_coherent(&spi->dev, txn_len, tx_buf, dma_hndl);
	return ret;
	return ret;
}
}
EXPORT_SYMBOL(bgcom_ahb_write);
EXPORT_SYMBOL(bgcom_ahb_write);
@@ -973,6 +985,7 @@ static int bg_spi_probe(struct spi_device *spi)
		goto err_ret;
		goto err_ret;


	atomic_set(&bg_is_spi_active, 1);
	atomic_set(&bg_is_spi_active, 1);
	dma_set_coherent_mask(&spi->dev, DMA_BIT_MASK(64));
	pr_info("Bgcom Probed successfully\n");
	pr_info("Bgcom Probed successfully\n");
	return ret;
	return ret;