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

Commit dec0ec1b authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

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

parents 1241542d 9ff02efa
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -968,9 +968,9 @@ static int bg_rsb_remove(struct platform_device *pdev)
	return 0;
}

static int bg_rsb_resume(struct platform_device *pdev)
static int bg_rsb_resume(struct device *pldev)
{
	int rc;
	struct platform_device *pdev = to_platform_device(pldev);
	struct bgrsb_priv *dev = platform_get_drvdata(pdev);

	if (dev->bgrsb_current_state == BGRSB_STATE_RSB_CONFIGURED)
@@ -978,12 +978,6 @@ static int bg_rsb_resume(struct platform_device *pdev)

	if (dev->bgrsb_current_state == BGRSB_STATE_INIT) {
		if (bgrsb_ldo_work(dev, BGRSB_ENABLE_LDO11) == 0) {
			rc = bgrsb_configr_rsb(dev, true);
			if (rc != 0) {
				pr_err("BG failed to configure RSB %d\n", rc);
				bgrsb_ldo_work(dev, BGRSB_DISABLE_LDO11);
				return rc;
			}
			dev->bgrsb_current_state = BGRSB_STATE_RSB_CONFIGURED;
			pr_debug("RSB Cofigured\n");
			return 0;
@@ -993,8 +987,9 @@ static int bg_rsb_resume(struct platform_device *pdev)
	return -EINVAL;
}

static int bg_rsb_suspend(struct platform_device *pdev, pm_message_t state)
static int bg_rsb_suspend(struct device *pldev)
{
	struct platform_device *pdev = to_platform_device(pldev);
	struct bgrsb_priv *dev = platform_get_drvdata(pdev);

	if (dev->bgrsb_current_state == BGRSB_STATE_INIT)
@@ -1021,15 +1016,19 @@ static const struct of_device_id bg_rsb_of_match[] = {
	{ }
};

static const struct dev_pm_ops pm_rsb = {
	.resume		= bg_rsb_resume,
	.suspend	= bg_rsb_suspend,
};

static struct platform_driver bg_rsb_driver = {
	.driver = {
		.name = "bg-rsb",
		.of_match_table = bg_rsb_of_match,
		.pm = &pm_rsb,
	},
	.probe		= bg_rsb_probe,
	.remove		= bg_rsb_remove,
	.resume		= bg_rsb_resume,
	.suspend	= bg_rsb_suspend,
};

module_platform_driver(bg_rsb_driver);
+91 −33
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/kthread.h>
#include <linux/dma-mapping.h>
#include "bgcom.h"
#include "bgrsb.h"
#include "bgcom_interface.h"
@@ -62,6 +63,7 @@ enum bgcom_req_type {
	BGCOM_READ_REG = 0,
	BGCOM_READ_FIFO = 1,
	BGCOM_READ_AHB = 2,
	BGCOM_WRITE_REG = 3,
};

struct bg_spi_priv {
@@ -111,6 +113,17 @@ static DECLARE_WORK(input_work , send_input_events);

static struct mutex bg_resume_mutex;

static atomic_t  bg_is_spi_active;
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)
{
	data[pos] = '\0';
@@ -194,6 +207,10 @@ static int read_bg_locl(enum bgcom_req_type req_type,
	case BGCOM_READ_FIFO:
		ret = bgcom_fifo_read(&clnt_handle, no_of_words, buf);
		break;
	case BGCOM_WRITE_REG:
		ret = bgcom_reg_write(&clnt_handle, BG_CMND_REG,
					no_of_words, buf);
		break;
	case BGCOM_READ_AHB:
		break;
	}
@@ -229,6 +246,9 @@ static int bgcom_transfer(void *handle, uint8_t *tx_buf,
	tx_xfer = &bg_spi->xfer1;
	spi = bg_spi->spi;

	if (!atomic_read(&bg_is_spi_active))
		return -ECANCELED;

	mutex_lock(&bg_spi->xfer_mutex);
	bg_spi_reinit_xfer(tx_xfer);
	tx_xfer->tx_buf = tx_buf;
@@ -439,6 +459,7 @@ static void bg_irq_tasklet_hndlr_l(void)
int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	uint32_t num_words, void *read_buf)
{
	dma_addr_t dma_hndl_tx, dma_hndl_rx;
	uint32_t txn_len;
	uint8_t *tx_buf;
	uint8_t *rx_buf;
@@ -446,6 +467,7 @@ int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	int ret;
	uint8_t cmnd = 0;
	uint32_t ahb_addr = 0;
	struct spi_device *spi = get_spi_device();

	if (!handle || !read_buf || num_words == 0
		|| num_words > BG_SPI_MAX_WORDS) {
@@ -468,15 +490,16 @@ int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
	size = num_words*BG_SPI_WORD_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)
		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) {
		kfree(tx_buf);
		dma_free_coherent(&spi->dev, txn_len, tx_buf, dma_hndl_tx);
		return -ENOMEM;
	}

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

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

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

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

	tx_buf = kzalloc(txn_len, GFP_KERNEL);

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

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

	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;
}
EXPORT_SYMBOL(bgcom_ahb_write);
@@ -617,6 +640,11 @@ int bgcom_fifo_read(void *handle, uint32_t num_words,
		return -EBUSY;
	}

	if (bgcom_resume(handle)) {
		pr_err("Failed to resume\n");
		return -EBUSY;
	}

	size = num_words*BG_SPI_WORD_SIZE;
	txn_len = BG_SPI_READ_LEN + size;
	tx_buf = kzalloc(txn_len, GFP_KERNEL | GFP_ATOMIC);
@@ -667,6 +695,11 @@ int bgcom_reg_write(void *handle, uint8_t reg_start_addr,
		return -EBUSY;
	}

	if (bgcom_resume(handle)) {
		pr_err("Failed to resume\n");
		return -EBUSY;
	}

	size = num_regs*BG_SPI_WORD_SIZE;
	txn_len = BG_SPI_WRITE_CMND_LEN + size;

@@ -769,6 +802,9 @@ int bgcom_resume(void *handle)
	if (handle == NULL)
		return -EINVAL;

	if (!atomic_read(&bg_is_spi_active))
		return -ECANCELED;

	cntx = (struct bg_context *)handle;
	bg_spi = cntx->bg_spi;

@@ -798,29 +834,9 @@ EXPORT_SYMBOL(bgcom_resume);

int bgcom_suspend(void *handle)
{
	struct bg_spi_priv *bg_spi;
	struct bg_context *cntx;
	uint32_t cmnd_reg = 0;
	int ret = 0;

	if (handle == NULL)
	if (!handle)
		return -EINVAL;

	cntx = (struct bg_context *)handle;
	bg_spi = cntx->bg_spi;
	mutex_lock(&bg_resume_mutex);
	if (bg_spi->bg_state == BGCOM_STATE_SUSPEND)
		goto unlock;

	cmnd_reg |= BIT(31);
	ret = bgcom_reg_write(handle, BG_CMND_REG, 1, &cmnd_reg);
	if (ret == 0)
		bg_spi->bg_state = BGCOM_STATE_SUSPEND;

unlock:
	mutex_unlock(&bg_resume_mutex);
	pr_info("suspended with : %d\n", ret);
	return ret;
	return 0;
}
EXPORT_SYMBOL(bgcom_suspend);

@@ -933,7 +949,6 @@ static int bg_spi_probe(struct spi_device *spi)
	struct bg_spi_priv *bg_spi;
	struct device_node *node;
	int irq_gpio = 0;
	int bg_irq = 0;
	int ret;

	bg_spi = devm_kzalloc(&spi->dev, sizeof(*bg_spi),
@@ -971,6 +986,8 @@ static int bg_spi_probe(struct spi_device *spi)
	if (ret)
		goto err_ret;

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

@@ -992,6 +1009,46 @@ static int bg_spi_remove(struct spi_device *spi)
	return 0;
}

static int bgcom_pm_suspend(struct device *dev)
{
	uint32_t cmnd_reg = 0;
	struct spi_device *s_dev = to_spi_device(dev);
	struct bg_spi_priv *bg_spi = spi_get_drvdata(s_dev);
	int ret = 0;

	if (bg_spi->bg_state == BGCOM_STATE_SUSPEND)
		return 0;

	cmnd_reg |= BIT(31);
	ret = read_bg_locl(BGCOM_WRITE_REG, 1, &cmnd_reg);
	if (ret == 0) {
		bg_spi->bg_state = BGCOM_STATE_SUSPEND;
		atomic_set(&bg_is_spi_active, 0);
	}
	pr_info("suspended with : %d\n", ret);
	return ret;
}

static int bgcom_pm_resume(struct device *dev)
{
	struct bg_context clnt_handle;
	int ret;
	struct bg_spi_priv *spi =
		container_of(bg_com_drv, struct bg_spi_priv, lhandle);

	clnt_handle.bg_spi = spi;
	atomic_set(&bg_is_spi_active, 1);
	ret = bgcom_resume(&clnt_handle);
	if (ret == 0)
		pr_info("Bgcom resumed\n");
	return ret;
}

static const struct dev_pm_ops bgcom_pm = {
	.suspend = bgcom_pm_suspend,
	.resume = bgcom_pm_resume,
};

static const struct of_device_id bg_spi_of_match[] = {
	{ .compatible = "qcom,bg-spi", },
	{ }
@@ -1002,6 +1059,7 @@ static struct spi_driver bg_spi_driver = {
	.driver = {
		.name = "bg-spi",
		.of_match_table = bg_spi_of_match,
		.pm = &bgcom_pm,
	},
	.probe = bg_spi_probe,
	.remove = bg_spi_remove,