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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * I/O delay strategies for inb_p/outb_p
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Allow for a DMI based override of port 0x80, needed for certain HP laptops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * and possibly other systems. Also allow for the gradual elimination of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * outb_p/inb_p API uses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define IO_DELAY_TYPE_0X80	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define IO_DELAY_TYPE_0XED	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define IO_DELAY_TYPE_UDELAY	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define IO_DELAY_TYPE_NONE	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #if defined(CONFIG_IO_DELAY_0X80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DEFAULT_IO_DELAY_TYPE	IO_DELAY_TYPE_0X80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #elif defined(CONFIG_IO_DELAY_0XED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DEFAULT_IO_DELAY_TYPE	IO_DELAY_TYPE_0XED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #elif defined(CONFIG_IO_DELAY_UDELAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DEFAULT_IO_DELAY_TYPE	IO_DELAY_TYPE_UDELAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #elif defined(CONFIG_IO_DELAY_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define DEFAULT_IO_DELAY_TYPE	IO_DELAY_TYPE_NONE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) int io_delay_type __read_mostly = DEFAULT_IO_DELAY_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int __initdata io_delay_override;
^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)  * Paravirt wants native_io_delay to be a constant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) void native_io_delay(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	switch (io_delay_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	case IO_DELAY_TYPE_0X80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		asm volatile ("outb %al, $0x80");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	case IO_DELAY_TYPE_0XED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		asm volatile ("outb %al, $0xed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	case IO_DELAY_TYPE_UDELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		 * 2 usecs is an upper-bound for the outb delay but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		 * note that udelay doesn't have the bus-level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		 * side-effects that outb does, nor does udelay() have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 * precise timings during very early bootup (the delays
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		 * are shorter until calibrated):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	case IO_DELAY_TYPE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		break;
^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) EXPORT_SYMBOL(native_io_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (io_delay_type == IO_DELAY_TYPE_0X80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		pr_notice("%s: using 0xed I/O delay port\n", id->ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		io_delay_type = IO_DELAY_TYPE_0XED;
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^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)  * Quirk table for systems that misbehave (lock up, etc.) if port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * 0x80 is used:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static const struct dmi_system_id io_delay_0xed_port_dmi_table[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.callback	= dmi_io_delay_0xed_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		.ident		= "Compaq Presario V6000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		.matches	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			DMI_MATCH(DMI_BOARD_VENDOR,	"Quanta"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			DMI_MATCH(DMI_BOARD_NAME,	"30B7")
^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) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		.callback	= dmi_io_delay_0xed_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		.ident		= "HP Pavilion dv9000z",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.matches	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			DMI_MATCH(DMI_BOARD_VENDOR,	"Quanta"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			DMI_MATCH(DMI_BOARD_NAME,	"30B9")
^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) 		.callback	= dmi_io_delay_0xed_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		.ident		= "HP Pavilion dv6000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		.matches	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			DMI_MATCH(DMI_BOARD_VENDOR,	"Quanta"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			DMI_MATCH(DMI_BOARD_NAME,	"30B8")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		}
^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) 		.callback	= dmi_io_delay_0xed_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		.ident		= "HP Pavilion tx1000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		.matches	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			DMI_MATCH(DMI_BOARD_VENDOR,	"Quanta"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			DMI_MATCH(DMI_BOARD_NAME,	"30BF")
^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) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		.callback	= dmi_io_delay_0xed_port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		.ident		= "Presario F700",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		.matches	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			DMI_MATCH(DMI_BOARD_VENDOR,	"Quanta"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			DMI_MATCH(DMI_BOARD_NAME,	"30D3")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void __init io_delay_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (!io_delay_override)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		dmi_check_system(io_delay_0xed_port_dmi_table);
^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 int __init io_delay_param(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (!strcmp(s, "0x80"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		io_delay_type = IO_DELAY_TYPE_0X80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	else if (!strcmp(s, "0xed"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		io_delay_type = IO_DELAY_TYPE_0XED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	else if (!strcmp(s, "udelay"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		io_delay_type = IO_DELAY_TYPE_UDELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	else if (!strcmp(s, "none"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		io_delay_type = IO_DELAY_TYPE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	io_delay_override = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) early_param("io_delay", io_delay_param);