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

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

Merge "qcom: rpm-smd: Use arch_init and implement deferred probe mechanism"

parents e140eb00 90774044
Loading
Loading
Loading
Loading
+49 −43
Original line number Diff line number Diff line
@@ -59,13 +59,11 @@ struct msm_rpm_driver_data {
	spinlock_t smd_lock_write;
	spinlock_t smd_lock_read;
	struct completion smd_open;
	struct completion remote_open;
};

#define DEFAULT_BUFFER_SIZE 256
#define DEBUG_PRINT_BUFFER_SIZE 512
#define MAX_SLEEP_BUFFER 128
#define SMD_CHANNEL_NOTIF_TIMEOUT 5000
#define GFP_FLAG(noirq) (noirq ? GFP_ATOMIC : GFP_KERNEL)
#define INV_RSC "resource does not exist"
#define ERR "err\0"
@@ -75,6 +73,7 @@ struct msm_rpm_driver_data {

static ATOMIC_NOTIFIER_HEAD(msm_rpm_sleep_notifier);
static bool standalone;
static int probe_status = -EPROBE_DEFER;

int msm_rpm_register_notifier(struct notifier_block *nb)
{
@@ -498,6 +497,9 @@ static int msm_rpm_add_kvp_data_common(struct msm_rpm_request *handle,
	uint32_t i;
	uint32_t data_size, msg_size;

	if (probe_status)
		return probe_status;

	if (!handle) {
		pr_err("%s(): Invalid handle\n", __func__);
		return -EINVAL;
@@ -566,6 +568,9 @@ static struct msm_rpm_request *msm_rpm_create_request_common(
{
	struct msm_rpm_request *cdata;

	if (probe_status)
		return ERR_PTR(probe_status);

	cdata = kzalloc(sizeof(struct msm_rpm_request),
			GFP_FLAG(noirq));

@@ -1050,6 +1055,9 @@ static int msm_rpm_send_data(struct msm_rpm_request *cdata,
	uint32_t msg_size;
	int req_hdr_sz, msg_hdr_sz;

	if (probe_status)
		return probe_status;

	if (!cdata->msg_hdr.data_len)
		return 1;

@@ -1262,6 +1270,10 @@ int msm_rpm_send_message(enum msm_rpm_set set, uint32_t rsc_type,
	int i, rc;
	struct msm_rpm_request *req =
		msm_rpm_create_request(set, rsc_type, rsc_id, nelems);

	if (IS_ERR(req))
		return PTR_ERR(req);

	if (!req)
		return -ENOMEM;

@@ -1285,6 +1297,10 @@ int msm_rpm_send_message_noirq(enum msm_rpm_set set, uint32_t rsc_type,
	int i, rc;
	struct msm_rpm_request *req =
		msm_rpm_create_request_noirq(set, rsc_type, rsc_id, nelems);

	if (IS_ERR(req))
		return PTR_ERR(req);

	if (!req)
		return -ENOMEM;

@@ -1330,62 +1346,52 @@ void msm_rpm_exit_sleep(void)
}
EXPORT_SYMBOL(msm_rpm_exit_sleep);

static int msm_rpm_smd_remote_probe(struct platform_device *pdev)
{
	if (pdev && pdev->id == msm_rpm_data.ch_type)
		complete(&msm_rpm_data.remote_open);
	return 0;
}

static struct platform_driver msm_rpm_smd_remote_driver = {
	.probe = msm_rpm_smd_remote_probe,
	.driver = {
		.owner = THIS_MODULE,
	},
};

static int msm_rpm_dev_probe(struct platform_device *pdev)
{
	char *key = NULL;
	int ret;
	int ret = 0;

	key = "rpm-channel-name";
	ret = of_property_read_string(pdev->dev.of_node, key,
					&msm_rpm_data.ch_name);
	if (ret)
	if (ret) {
		pr_err("%s(): Failed to read node: %s, key=%s\n", __func__,
			pdev->dev.of_node->full_name, key);
		goto fail;
	}

	key = "rpm-channel-type";
	ret = of_property_read_u32(pdev->dev.of_node, key,
					&msm_rpm_data.ch_type);
	if (ret)
	if (ret) {
		pr_err("%s(): Failed to read node: %s, key=%s\n", __func__,
			pdev->dev.of_node->full_name, key);
		goto fail;
	}

	key = "rpm-standalone";
	standalone = of_property_read_bool(pdev->dev.of_node, key);
	if (standalone)
		goto skip_smd_init;

	msm_rpm_smd_remote_driver.driver.name = msm_rpm_data.ch_name;
	init_completion(&msm_rpm_data.remote_open);
	init_completion(&msm_rpm_data.smd_open);
	spin_lock_init(&msm_rpm_data.smd_lock_write);
	spin_lock_init(&msm_rpm_data.smd_lock_read);
	INIT_WORK(&msm_rpm_data.work, msm_rpm_smd_work);

	platform_driver_register(&msm_rpm_smd_remote_driver);
	ret = wait_for_completion_timeout(&msm_rpm_data.remote_open,
			msecs_to_jiffies(SMD_CHANNEL_NOTIF_TIMEOUT));

	if (!ret || smd_named_open_on_edge(msm_rpm_data.ch_name,
	ret = smd_named_open_on_edge(msm_rpm_data.ch_name,
				msm_rpm_data.ch_type,
				&msm_rpm_data.ch_info,
				&msm_rpm_data,
				msm_rpm_notify)) {
		pr_info("Cannot open RPM channel %s %d\n", msm_rpm_data.ch_name,
				msm_rpm_notify);
	if (ret) {
		if (ret != -EPROBE_DEFER) {
			pr_err("%s: Cannot open RPM channel %s %d\n",
				__func__, msm_rpm_data.ch_name,
				msm_rpm_data.ch_type);

		}
		goto fail;
	}

	init_completion(&msm_rpm_data.smd_open);
	spin_lock_init(&msm_rpm_data.smd_lock_write);
	spin_lock_init(&msm_rpm_data.smd_lock_read);
	INIT_WORK(&msm_rpm_data.work, msm_rpm_smd_work);

	wait_for_completion(&msm_rpm_data.smd_open);

@@ -1393,21 +1399,21 @@ static int msm_rpm_dev_probe(struct platform_device *pdev)

	msm_rpm_smd_wq = alloc_workqueue("rpm-smd",
			WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_HIGHPRI, 1);
	if (!msm_rpm_smd_wq)
		return -EINVAL;
	if (!msm_rpm_smd_wq) {
		pr_err("%s: Unable to alloc rpm-smd workqueue\n", __func__);
		ret = -EINVAL;
		goto fail;
	}
	queue_work(msm_rpm_smd_wq, &msm_rpm_data.work);

skip_smd_init:
	of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);

	if (standalone)
		pr_info("%s(): RPM running in standalone mode\n", __func__);

	return 0;
		pr_info("%s: RPM running in standalone mode\n", __func__);
fail:
	pr_err("%s(): Failed to read node: %s, key=%s\n", __func__,
			pdev->dev.of_node->full_name, key);
	return -EINVAL;
	probe_status = ret;
	return probe_status;
}

static struct of_device_id msm_rpm_match_table[] =  {
@@ -1435,4 +1441,4 @@ int __init msm_rpm_driver_init(void)
	return platform_driver_register(&msm_rpm_device_driver);
}
EXPORT_SYMBOL(msm_rpm_driver_init);
late_initcall(msm_rpm_driver_init);
arch_initcall(msm_rpm_driver_init);