Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MT7615 eeprom binary from filesystem #949

Open
loswochos opened this issue Jan 26, 2025 · 0 comments
Open

MT7615 eeprom binary from filesystem #949

loswochos opened this issue Jan 26, 2025 · 0 comments

Comments

@loswochos
Copy link

I am using an MT7615 mini pcie card (https://docs.banana-pi.org/en/BPI-MT7615/BananaPi_MT7615) in a x86/64 device (Futro 940) with latest OpenWRT 23.05.5 (combined-efi ext4). Since the card does not have its own eeprom, the data has to be loaded during initialization. In this x86/64 case it seems to be the easiest to load the eeprom binary from file system which is not supported by default. I therefore use the following patch (originally from here: frank-w/BPI-Router-Linux@fe31dae) to implement this functionality:

diff -Naur a/eeprom.c b/eeprom.c

--- a/eeprom.c
+++ b/eeprom.c
@@ -10,6 +10,48 @@
 #include <linux/etherdevice.h>
 #include "mt76.h"
 
+static int
+mt76_get_eeprom_file(struct mt76_dev *dev, void *eep, int len)
+{
+	char path[64]="";
+	struct file *fp;
+	loff_t pos=0;
+	int ret;
+	struct inode *inode = NULL;
+	loff_t size;
+
+	ret = snprintf(path,sizeof(path),"/lib/firmware/mediatek/%s_rf.bin",dev->dev->driver->name);
+	if(ret<0)
+		return -EINVAL;
+	dev_info(dev->dev,"Load eeprom: %s\n",path);
+	fp = filp_open(path, O_RDONLY, 0);
+	if (IS_ERR(fp)) {
+		dev_info(dev->dev,"Open eeprom file failed: %s\n",path);
+		return -ENOENT;
+	}
+
+	inode = file_inode(fp);
+	if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
+		printk(KERN_ALERT "invalid file type: %s\n", path);
+		return -ENOENT;
+	}
+	size = i_size_read(inode->i_mapping->host);
+	if (size < 0)
+	{
+		printk(KERN_ALERT "failed getting size of %s size:%lld \n",path,size);
+		return -ENOENT;
+	}
+	ret = kernel_read(fp, eep, len, &pos);
+	if(ret < size){
+		dev_info(dev->dev,"Load eeprom ERR, count %d byte (len:%d)\n",ret,len);
+		return -ENOENT;
+	}
+	filp_close(fp, 0);
+	dev_info(dev->dev,"Load eeprom OK, count %d byte\n",ret);
+
+	return 0;
+}
+
 static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len)
 {
 #if defined(CONFIG_OF) && defined(CONFIG_MTD)
@@ -414,6 +414,7 @@
 	if (!dev->eeprom.data)
 		return -ENOMEM;
 
-	return !mt76_get_of_eeprom(dev, dev->eeprom.data, len);
+	return (!mt76_get_of_eeprom(dev, dev->eeprom.data, len)) || 
+	     (!mt76_get_eeprom_file(dev, dev->eeprom.data, len));
 }
 EXPORT_SYMBOL_GPL(mt76_eeprom_init);

It would be great if this feature could be permanently added to eeprom.c.

@loswochos loswochos changed the title MT7615e eeprom binary from filesystem MT7615 eeprom binary from filesystem Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant