aboutsummaryrefslogtreecommitdiff
path: root/linux
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2026-11-01 16:10:29 +0100
committerJavier <dev.git@javispedro.com>2026-11-01 16:10:29 +0100
commit8f0045914642dc58a0b9dac251726d909324b3b4 (patch)
treeaf44547cab64d8ae9c07b6073a54f0e8385c8580 /linux
parentda550acda776107b9505290d2e37eb465a90a5a1 (diff)
downloadchu-8f0045914642dc58a0b9dac251726d909324b3b4.tar.gz
chu-8f0045914642dc58a0b9dac251726d909324b3b4.zip
linux: powerdown device on module removal
Diffstat (limited to 'linux')
-rw-r--r--linux/chudisk.c21
-rw-r--r--linux/makefile2
2 files changed, 17 insertions, 6 deletions
diff --git a/linux/chudisk.c b/linux/chudisk.c
index c2eb2f7..f50551c 100644
--- a/linux/chudisk.c
+++ b/linux/chudisk.c
@@ -48,6 +48,7 @@ static int softblk = 1024;
#include "lnxabs.h"
#include "ch375lnx.h"
+#include <chuver.h>
#include <scsi.h>
#if ENABLE_DLOG
@@ -565,7 +566,8 @@ static __init int chudisk_init(void)
return -ENXIO;
}
- printk(KERN_INFO "chudisk: found CH375 v.%x at 0x%hx, using major %d\n",
+ printk(KERN_INFO "chudisk: v%x.%x, found CH375 v.%x at 0x%hx, using major %d\n",
+ CHUDISK_VERSION_MAJOR, CHUDISK_VERSION_MINOR,
ch375_get_version(dev), dev->io_base, MAJOR_NR);
// Set defaults for unit
@@ -584,6 +586,7 @@ static __init int chudisk_init(void)
blksize_size[MAJOR_NR] = chudisk_blksizes;
hardsect_size[MAJOR_NR] = chudisk_hardsectsizes;
+ // Add ourselves to the genhd linked list
chudisk_gendisk.major = MAJOR_NR;
chudisk_gendisk.nr_real = 1;
chudisk_gendisk.next = gendisk_head;
@@ -596,11 +599,10 @@ static __init int chudisk_init(void)
static void chudisk_exit(void)
{
+ struct ch375 *dev = &chudisk_dev[0];
struct gendisk **gdp;
- unregister_blkdev(MAJOR_NR, "chud");
- release_region(io, 2);
-
+ // Remove from genhd list
for(gdp = &gendisk_head; *gdp; gdp = &((*gdp)->next)) {
if (*gdp == &chudisk_gendisk) {
*gdp = (*gdp)->next;
@@ -608,14 +610,23 @@ static void chudisk_exit(void)
}
}
+ // Remove from blkdev
blk_dev[MAJOR_NR].request_fn = NULL;
blk_size[MAJOR_NR] = NULL;
blksize_size[MAJOR_NR] = NULL;
hardsect_size[MAJOR_NR] = NULL;
+ unregister_blkdev(MAJOR_NR, "chud");
+
+ // Turn off the chip
+ ch375_set_usb_mode(dev, CH375_USB_MODE_HOST_DISABLED);
+ mdelay(1);
+ ch375_enter_sleep(dev);
+
+ // And unregister driver
+ release_region(io, 2);
dprintf("chudisk: bye\n");
}
-
module_init(chudisk_init);
module_exit(chudisk_exit);
diff --git a/linux/makefile b/linux/makefile
index e88ebac..9e07d27 100644
--- a/linux/makefile
+++ b/linux/makefile
@@ -19,7 +19,7 @@ clean:
install: chudisk.o
install -m0644 chudisk.o $(MODDIR)/block
- depmod
+ depmod -a
uninstall:
rm -f $(MODDIR)/block/chudisk.o