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) /* auxio.c: Probing for the Sparc AUXIO register at boot time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Refactoring for unified NCR/PCIO support 2002 Eric Brower (ebrower@usa.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/auxio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) void __iomem *auxio_register = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) EXPORT_SYMBOL(auxio_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) enum auxio_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	AUXIO_TYPE_NODEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	AUXIO_TYPE_SBUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	AUXIO_TYPE_EBUS
^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 enum auxio_type auxio_devtype = AUXIO_TYPE_NODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static DEFINE_SPINLOCK(auxio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static void __auxio_rmw(u8 bits_on, u8 bits_off, int ebus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (auxio_register) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		u8 regval, newval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		spin_lock_irqsave(&auxio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		regval = (ebus ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			  (u8) readl(auxio_register) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			  sbus_readb(auxio_register));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		newval =  regval | bits_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		newval &= ~bits_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		if (!ebus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			newval &= ~AUXIO_AUX1_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		if (ebus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			writel((u32) newval, auxio_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			sbus_writeb(newval, auxio_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		spin_unlock_irqrestore(&auxio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^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) static void __auxio_set_bit(u8 bit, int on, int ebus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u8 bits_on = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u8 bits_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (!on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		u8 tmp = bits_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		bits_off = bits_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		bits_on = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	__auxio_rmw(bits_on, bits_off, ebus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) void auxio_set_led(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int ebus = auxio_devtype == AUXIO_TYPE_EBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u8 bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	bit = (ebus ? AUXIO_PCIO_LED : AUXIO_AUX1_LED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	__auxio_set_bit(bit, on, ebus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) EXPORT_SYMBOL(auxio_set_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static void __auxio_sbus_set_lte(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	__auxio_set_bit(AUXIO_AUX1_LTE, on, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) void auxio_set_lte(int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	switch(auxio_devtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	case AUXIO_TYPE_SBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		__auxio_sbus_set_lte(on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	case AUXIO_TYPE_EBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		break;
^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) EXPORT_SYMBOL(auxio_set_lte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static const struct of_device_id auxio_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		.name = "auxio",
^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) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_DEVICE_TABLE(of, auxio_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int auxio_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct device_node *dp = dev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (of_node_name_eq(dp->parent, "ebus")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		auxio_devtype = AUXIO_TYPE_EBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		size = sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	} else if (of_node_name_eq(dp->parent, "sbus")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		auxio_devtype = AUXIO_TYPE_SBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		size = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		printk("auxio: Unknown parent bus type [%pOFn]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		       dp->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	auxio_register = of_ioremap(&dev->resource[0], 0, size, "auxio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!auxio_register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	printk(KERN_INFO "AUXIO: Found device at %pOF\n", dp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (auxio_devtype == AUXIO_TYPE_EBUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		auxio_set_led(AUXIO_LED_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static struct platform_driver auxio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.probe		= auxio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		.name = "auxio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.of_match_table = auxio_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int __init auxio_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return platform_driver_register(&auxio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* Must be after subsys_initcall() so that busses are probed.  Must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * be before device_initcall() because things like the floppy driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * need to use the AUXIO register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) fs_initcall(auxio_init);