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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  * Copyright (C) 2004 - 2007  Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static int __init memchunk_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 	return 1; /* accept anything that begins with "memchunk." */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) __setup("memchunk.", memchunk_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static void __init memchunk_cmdline_override(char *name, unsigned long *sizep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	char *p = boot_command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	int k = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	while ((p = strstr(p, "memchunk."))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		p += 9; /* strlen("memchunk.") */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		if (!strncmp(name, p, k) && p[k] == '=') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 			p += k + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 			*sizep = memparse(p, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 			pr_info("%s: forcing memory chunk size to 0x%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 				name, *sizep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int __init platform_resource_setup_memory(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 					  char *name, unsigned long memsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	dma_addr_t dma_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	r = pdev->resource + pdev->num_resources - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	if (r->flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		pr_warn("%s: unable to find empty space for resource\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	memchunk_cmdline_override(name, &memsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	if (!memsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	buf = dma_alloc_coherent(&pdev->dev, memsize, &dma_handle, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		pr_warn("%s: unable to allocate memory\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	r->flags = IORESOURCE_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	r->start = dma_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	r->end = r->start + memsize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	r->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }