Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Remote processor messaging - sample client driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2011 Texas Instruments, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 2011 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  * Ohad Ben-Cohen <ohad@wizery.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  * Brian Swetland <swetland@google.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/rpmsg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define MSG		"hello world!"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static int count = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) module_param(count, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct instance_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	int rx_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 						void *priv, u32 src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	struct instance_data *idata = dev_get_drvdata(&rpdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	dev_info(&rpdev->dev, "incoming msg %d (src: 0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		 ++idata->rx_count, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 			     true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	/* samples should not live forever */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	if (idata->rx_count >= count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		dev_info(&rpdev->dev, "goodbye!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	/* send a new message now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int rpmsg_sample_probe(struct rpmsg_device *rpdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	struct instance_data *idata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 					rpdev->src, rpdev->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	idata = devm_kzalloc(&rpdev->dev, sizeof(*idata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	if (!idata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	dev_set_drvdata(&rpdev->dev, idata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	/* send a message to our remote processor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static void rpmsg_sample_remove(struct rpmsg_device *rpdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	dev_info(&rpdev->dev, "rpmsg sample client driver is removed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct rpmsg_device_id rpmsg_driver_sample_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	{ .name	= "rpmsg-client-sample" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_sample_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static struct rpmsg_driver rpmsg_sample_client = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 	.drv.name	= KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	.id_table	= rpmsg_driver_sample_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	.probe		= rpmsg_sample_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	.callback	= rpmsg_sample_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 	.remove		= rpmsg_sample_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) module_rpmsg_driver(rpmsg_sample_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) MODULE_DESCRIPTION("Remote processor messaging sample client driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) MODULE_LICENSE("GPL v2");