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)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2012 ARM Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/gpio/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_data/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define SYS_ID			0x000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define SYS_SW			0x004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define SYS_LED			0x008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define SYS_100HZ		0x024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define SYS_FLAGSSET		0x030
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define SYS_FLAGSCLR		0x034
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define SYS_NVFLAGS		0x038
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define SYS_NVFLAGSSET		0x038
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define SYS_NVFLAGSCLR		0x03c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define SYS_MCI			0x048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define SYS_FLASH		0x04c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define SYS_CFGSW		0x058
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define SYS_24MHZ		0x05c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define SYS_MISC		0x060
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define SYS_DMA			0x064
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define SYS_PROCID0		0x084
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define SYS_PROCID1		0x088
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define SYS_CFGDATA		0x0a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define SYS_CFGCTRL		0x0a4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define SYS_CFGSTAT		0x0a8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /* The sysreg block is just a random collection of various functions... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.label = "sys_led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.base = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.ngpio = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.label = "sys_mci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.base = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.ngpio = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.label = "sys_flash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.base = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.ngpio = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static struct mfd_cell vexpress_sysreg_cells[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		.name = "basic-mmio-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		.of_compatible = "arm,vexpress-sysreg,sys_led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		.num_resources = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		.resources = (struct resource []) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.platform_data = &vexpress_sysreg_sys_led_pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		.name = "basic-mmio-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		.of_compatible = "arm,vexpress-sysreg,sys_mci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		.num_resources = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		.resources = (struct resource []) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.platform_data = &vexpress_sysreg_sys_mci_pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		.pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.name = "basic-mmio-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.of_compatible = "arm,vexpress-sysreg,sys_flash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		.num_resources = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		.resources = (struct resource []) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		.platform_data = &vexpress_sysreg_sys_flash_pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		.pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		.name = "vexpress-syscfg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		.num_resources = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.resources = (struct resource []) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			DEFINE_RES_MEM(SYS_MISC, 0x4c),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^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) static int vexpress_sysreg_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct resource *mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct gpio_chip *mmc_gpio_chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (!mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (!base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	 * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	 * older trees using sysreg node for MMC control lines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (!mmc_gpio_chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			NULL, NULL, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	mmc_gpio_chip->ngpio = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	devm_gpiochip_add_data(&pdev->dev, mmc_gpio_chip, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			vexpress_sysreg_cells,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static const struct of_device_id vexpress_sysreg_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	{ .compatible = "arm,vexpress-sysreg", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) MODULE_DEVICE_TABLE(of, vexpress_sysreg_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static struct platform_driver vexpress_sysreg_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		.name = "vexpress-sysreg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.of_match_table = vexpress_sysreg_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	.probe = vexpress_sysreg_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) module_platform_driver(vexpress_sysreg_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) MODULE_LICENSE("GPL v2");