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)  * Coldfire generic GPIO support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #ifndef coldfire_gpio_h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define coldfire_gpio_h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/coldfire.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/mcfsim.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/mcfgpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * The Generic GPIO functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * If the gpio is a compile time constant and is one of the Coldfire gpios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * use the inline version, otherwise dispatch thru gpiolib.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static inline int gpio_get_value(unsigned gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (__builtin_constant_p(gpio) && gpio < MCFGPIO_PIN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		return mcfgpio_read(__mcfgpio_ppdr(gpio)) & mcfgpio_bit(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		return __gpio_get_value(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static inline void gpio_set_value(unsigned gpio, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (__builtin_constant_p(gpio) && gpio < MCFGPIO_PIN_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		if (gpio < MCFGPIO_SCR_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			MCFGPIO_PORTTYPE data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			data = mcfgpio_read(__mcfgpio_podr(gpio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 				data |= mcfgpio_bit(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 				data &= ~mcfgpio_bit(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			mcfgpio_write(data, __mcfgpio_podr(gpio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 				mcfgpio_write(mcfgpio_bit(gpio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 						MCFGPIO_SETR_PORT(gpio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				mcfgpio_write(~mcfgpio_bit(gpio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 						MCFGPIO_CLRR_PORT(gpio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		__gpio_set_value(gpio, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static inline int gpio_to_irq(unsigned gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #if defined(MCFGPIO_IRQ_MIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if ((gpio >= MCFGPIO_IRQ_MIN) && (gpio < MCFGPIO_IRQ_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (gpio < MCFGPIO_IRQ_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return gpio + MCFGPIO_IRQ_VECBASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return __gpio_to_irq(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static inline int irq_to_gpio(unsigned irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return (irq >= MCFGPIO_IRQ_VECBASE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		irq < (MCFGPIO_IRQ_VECBASE + MCFGPIO_IRQ_MAX)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		irq - MCFGPIO_IRQ_VECBASE : -ENXIO;
^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) static inline int gpio_cansleep(unsigned gpio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return gpio < MCFGPIO_PIN_MAX ? 0 : __gpio_cansleep(gpio);
^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) #ifndef CONFIG_GPIOLIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static inline int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	err = gpio_request(gpio, label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (flags & GPIOF_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		err = gpio_direction_input(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		err = gpio_direction_output(gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			(flags & GPIOF_INIT_HIGH) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		gpio_free(gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #endif /* !CONFIG_GPIOLIB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #endif