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)  *  Copyright (c) 2005 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Kyungmin Park <kyungmin.park@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Overview:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *   This is a device driver for the OneNAND flash for generic boards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mtd/onenand.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mtd/partitions.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Note: Driver name and platform data format have been updated!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * This version of the driver is named "onenand-flash" and takes struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * onenand_platform_data as platform data. The old ARM-specific version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * with the name "onenand" used to take struct flash_platform_data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define DRIVER_NAME	"onenand-flash"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct onenand_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct mtd_info		mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct onenand_chip	onenand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int generic_onenand_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct onenand_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct resource *res = pdev->resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned long size = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		goto out_free_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	info->onenand.base = ioremap(res->start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (!info->onenand.base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto out_release_mem_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	err = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		goto out_iounmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	info->onenand.irq = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	info->mtd.dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	info->mtd.priv = &info->onenand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (onenand_scan(&info->mtd, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		err = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		goto out_iounmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	err = mtd_device_register(&info->mtd, pdata ? pdata->parts : NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				  pdata ? pdata->nr_parts : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	platform_set_drvdata(pdev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) out_iounmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	iounmap(info->onenand.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) out_release_mem_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	release_mem_region(res->start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) out_free_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int generic_onenand_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct onenand_info *info = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct resource *res = pdev->resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned long size = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		onenand_release(&info->mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		release_mem_region(res->start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		iounmap(info->onenand.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct platform_driver generic_onenand_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		.name		= DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.probe		= generic_onenand_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	.remove		= generic_onenand_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) module_platform_driver(generic_onenand_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) MODULE_ALIAS("platform:" DRIVER_NAME);