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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Driver for TANBAC TB0219 base board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2005  Yoichi Yuasa <yuasa@linux-mips.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/vr41xx/giu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/vr41xx/tb0219.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) MODULE_DESCRIPTION("TANBAC TB0219 base board driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static int major;	/* default is dynamic major device number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) module_param(major, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) MODULE_PARM_DESC(major, "Major device number");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void (*old_machine_restart)(char *command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void __iomem *tb0219_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static DEFINE_SPINLOCK(tb0219_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define tb0219_read(offset)		readw(tb0219_base + (offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define tb0219_write(offset, value)	writew((value), tb0219_base + (offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define TB0219_START	0x0a000000UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define TB0219_SIZE	0x20UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define TB0219_LED			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define TB0219_GPIO_INPUT		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define TB0219_GPIO_OUTPUT		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define TB0219_DIP_SWITCH		0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define TB0219_MISC			0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define TB0219_RESET			0x0e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define TB0219_PCI_SLOT1_IRQ_STATUS	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define TB0219_PCI_SLOT2_IRQ_STATUS	0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define TB0219_PCI_SLOT3_IRQ_STATUS	0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) typedef enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	TYPE_LED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	TYPE_GPIO_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) } tb0219_type_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * Minor device number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *	 0 = 7 segment LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *	16 = GPIO IN 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *	17 = GPIO IN 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *	18 = GPIO IN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *	19 = GPIO IN 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *	20 = GPIO IN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *	21 = GPIO IN 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *	22 = GPIO IN 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *	23 = GPIO IN 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *	32 = GPIO OUT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *	33 = GPIO OUT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *	34 = GPIO OUT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *	35 = GPIO OUT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *	36 = GPIO OUT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *	37 = GPIO OUT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *	38 = GPIO OUT 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *	39 = GPIO OUT 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *	48 = DIP switch 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *	49 = DIP switch 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *	50 = DIP switch 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *	51 = DIP switch 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *	52 = DIP switch 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *	53 = DIP switch 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *	54 = DIP switch 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *	55 = DIP switch 8
^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) static inline char get_led(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return (char)tb0219_read(TB0219_LED);
^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) static inline char get_gpio_input_pin(unsigned int pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	uint16_t values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	values = tb0219_read(TB0219_GPIO_INPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (values & (1 << pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return '1';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static inline char get_gpio_output_pin(unsigned int pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	uint16_t values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	values = tb0219_read(TB0219_GPIO_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (values & (1 << pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return '1';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return '0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline char get_dip_switch(unsigned int pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	uint16_t values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	values = tb0219_read(TB0219_DIP_SWITCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (values & (1 << pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return '1';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return '0';
^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) static inline int set_led(char command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	tb0219_write(TB0219_LED, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return 0;
^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 inline int set_gpio_output_pin(unsigned int pin, char command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	uint16_t value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (command != '0' && command != '1')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	spin_lock_irqsave(&tb0219_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	value = tb0219_read(TB0219_GPIO_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (command == '0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		value &= ~(1 << pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		value |= 1 << pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	tb0219_write(TB0219_GPIO_OUTPUT, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	spin_unlock_irqrestore(&tb0219_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static ssize_t tanbac_tb0219_read(struct file *file, char __user *buf, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)                                   loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unsigned int minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	char value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	minor = iminor(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	switch (minor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		value = get_led();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	case 16 ... 23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		value = get_gpio_input_pin(minor - 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	case 32 ... 39:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		value = get_gpio_output_pin(minor - 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	case 48 ... 55:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		value = get_dip_switch(minor - 48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (put_user(value, buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static ssize_t tanbac_tb0219_write(struct file *file, const char __user *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)                                    size_t len, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	unsigned int minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	tb0219_type_t type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	minor = iminor(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	switch (minor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		type = TYPE_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	case 32 ... 39:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		type = TYPE_GPIO_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (get_user(c, data + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		case TYPE_LED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			retval = set_led(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		case TYPE_GPIO_OUTPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			retval = set_gpio_output_pin(minor - 32, c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int tanbac_tb0219_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned int minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	minor = iminor(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	switch (minor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	case 16 ... 23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	case 32 ... 39:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	case 48 ... 55:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return stream_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int tanbac_tb0219_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static const struct file_operations tb0219_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.read		= tanbac_tb0219_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	.write		= tanbac_tb0219_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	.open		= tanbac_tb0219_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	.release	= tanbac_tb0219_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	.llseek		= no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static void tb0219_restart(char *command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	tb0219_write(TB0219_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void tb0219_pci_irq_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	/* PCI Slot 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	vr41xx_set_irq_trigger(TB0219_PCI_SLOT1_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	vr41xx_set_irq_level(TB0219_PCI_SLOT1_PIN, IRQ_LEVEL_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* PCI Slot 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	vr41xx_set_irq_trigger(TB0219_PCI_SLOT2_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	vr41xx_set_irq_level(TB0219_PCI_SLOT2_PIN, IRQ_LEVEL_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* PCI Slot 3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	vr41xx_set_irq_trigger(TB0219_PCI_SLOT3_PIN, IRQ_TRIGGER_LEVEL, IRQ_SIGNAL_THROUGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	vr41xx_set_irq_level(TB0219_PCI_SLOT3_PIN, IRQ_LEVEL_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int tb0219_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (request_mem_region(TB0219_START, TB0219_SIZE, "TB0219") == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	tb0219_base = ioremap(TB0219_START, TB0219_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (tb0219_base == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		release_mem_region(TB0219_START, TB0219_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	retval = register_chrdev(major, "TB0219", &tb0219_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		iounmap(tb0219_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		tb0219_base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		release_mem_region(TB0219_START, TB0219_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	old_machine_restart = _machine_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	_machine_restart = tb0219_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	tb0219_pci_irq_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (major == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		major = retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		printk(KERN_INFO "TB0219: major number %d\n", major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int tb0219_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	_machine_restart = old_machine_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	iounmap(tb0219_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	tb0219_base = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	release_mem_region(TB0219_START, TB0219_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static struct platform_device *tb0219_platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static struct platform_driver tb0219_device_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	.probe		= tb0219_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.remove		= tb0219_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		.name	= "TB0219",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static int __init tanbac_tb0219_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	tb0219_platform_device = platform_device_alloc("TB0219", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!tb0219_platform_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	retval = platform_device_add(tb0219_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		platform_device_put(tb0219_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	retval = platform_driver_register(&tb0219_device_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		platform_device_unregister(tb0219_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static void __exit tanbac_tb0219_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	platform_driver_unregister(&tb0219_device_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	platform_device_unregister(tb0219_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) module_init(tanbac_tb0219_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) module_exit(tanbac_tb0219_exit);