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)  *    EISA "eeprom" support routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
^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) #include <linux/module.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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/eisa_eeprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define 	EISA_EEPROM_MINOR 241
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	return fixed_size_llseek(file, offset, origin, HPEE_MAX_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static ssize_t eisa_eeprom_read(struct file * file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			      char __user *buf, size_t count, loff_t *ppos )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	unsigned char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (*ppos < 0 || *ppos >= HPEE_MAX_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	tmp = kmalloc(count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			tmp[i] = readb(eisa_eeprom_addr+(*ppos)++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		if (copy_to_user (buf, tmp, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		kfree (tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	return ret;
^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) static int eisa_eeprom_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (file->f_mode & FMODE_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int eisa_eeprom_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *	The various file operations we support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static const struct file_operations eisa_eeprom_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.owner =	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.llseek =	eisa_eeprom_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.read =		eisa_eeprom_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.open =		eisa_eeprom_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.release =	eisa_eeprom_release,
^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 struct miscdevice eisa_eeprom_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	EISA_EEPROM_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	"eisa_eeprom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	&eisa_eeprom_fops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int __init eisa_eeprom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!eisa_eeprom_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	retval = misc_register(&eisa_eeprom_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return retval;
^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) 	printk(KERN_INFO "EISA EEPROM at 0x%px\n", eisa_eeprom_addr);
^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) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) module_init(eisa_eeprom_init);