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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) // Copyright (c) 2017-18 Linaro Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/of_platform.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/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/reboot-mode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define PON_SOFT_RB_SPARE		0x8f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define GEN1_REASON_SHIFT		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define GEN2_REASON_SHIFT		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct pm8916_pon {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	u32 baseaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	struct reboot_mode_driver reboot_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	long reason_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int pm8916_reboot_mode_write(struct reboot_mode_driver *reboot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 				    unsigned int magic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	struct pm8916_pon *pon = container_of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 			(reboot, struct pm8916_pon, reboot_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	ret = regmap_update_bits(pon->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 				 pon->baseaddr + PON_SOFT_RB_SPARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 				 GENMASK(7, pon->reason_shift),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 				 magic << pon->reason_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		dev_err(pon->dev, "update reboot mode bits failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int pm8916_pon_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	struct pm8916_pon *pon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	pon = devm_kzalloc(&pdev->dev, sizeof(*pon), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	if (!pon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	pon->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	pon->regmap = dev_get_regmap(pdev->dev.parent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	if (!pon->regmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		dev_err(&pdev->dev, "failed to locate regmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	error = of_property_read_u32(pdev->dev.of_node, "reg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 				     &pon->baseaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	pon->reboot_mode.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	pon->reason_shift = (long)of_device_get_match_data(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	pon->reboot_mode.write = pm8916_reboot_mode_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	error = devm_reboot_mode_register(&pdev->dev, &pon->reboot_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		dev_err(&pdev->dev, "can't register reboot mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	platform_set_drvdata(pdev, pon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	return devm_of_platform_populate(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct of_device_id pm8916_pon_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	{ .compatible = "qcom,pm8916-pon", .data = (void *)GEN1_REASON_SHIFT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	{ .compatible = "qcom,pms405-pon", .data = (void *)GEN1_REASON_SHIFT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	{ .compatible = "qcom,pm8998-pon", .data = (void *)GEN2_REASON_SHIFT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) MODULE_DEVICE_TABLE(of, pm8916_pon_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct platform_driver pm8916_pon_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 	.probe = pm8916_pon_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 		.name = "pm8916-pon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) 		.of_match_table = of_match_ptr(pm8916_pon_id_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) module_platform_driver(pm8916_pon_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) MODULE_DESCRIPTION("pm8916 Power On driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) MODULE_LICENSE("GPL v2");