Giter Club home page Giter Club logo

ch341-i2c-spi-gpio's People

Contributors

bibimbop avatar frank-zago avatar mr-nice avatar mskalski avatar pacoandres avatar thomasschlien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ch341-i2c-spi-gpio's Issues

Setup question

Forgive me my lacking understanding of Linux modules. I'm stuck setting up this project. I don't understand the next instruction properly.

This will create ch341-buses.ko, which can the be insmod'ed.

Compile the code works flawlessly and results in the aforementioned ch341-buses.ko file. Using insmod is not clear to me.
As far as I understand, I'm supposed to run

sudo insmod ch341-buses.ko

But this results in the following error,

insmod: ERROR: could not insert module ch341-buses.ko: Invalid module format

Thanks in advance.

Update the driver to the MFD branch

Currently the other driver is developed in the mfd branch. This should take over at some point since that is the form it would take to be upstreamed, not the all-in-one version.

BUG: unable to handle page fault for address: ffffffffc300b1e8

I compiled the code sudo make install and followed the instructions in your notes
I made sure I have installed the headers for the kernel I am running that is 5.15.0-83-generic on linux mint.
I did try reboot and uninstall reinstall but same error when I install the device that is it's that USB_LoRa_adapter-PINE64_RFM90.
I see this error in dmeg :
[ 362.668007] BUG: unable to handle page fault for address: ffffffffc300b1e8
[ 362.668010] #PF: supervisor write access in kernel mode
[ 362.668011] #PF: error_code(0x0003) - permissions violation
[ 362.668013] PGD 1ec415067 P4D 1ec415067 PUD 1ec417067 PMD 11cb79067 PTE 8000000108ea3061
[ 362.668017] Oops: 0003 [#1] SMP PTI
[ 362.668019] CPU: 3 PID: 4995 Comm: systemd-udevd Tainted: P OE 5.15.0-83-generic #92-Ubuntu
for full error see link
driver_bug.txt

after I upgraded kernel to 6.1.0-1027-oem
recompiled sudo make install. seems ok now. no dmesg errors seen. I haven't fully tested the device with it yet but might be ok.

[q] what is max SPI transfer size ?

while trying to send 256 bytes I'm seeing the corruption/driver freeze after size of 121. Is this is limitation of the driver or ch341 chip itself ?

extracting ch341 device from USB while running gpiomon leads to kernel oops

Not sure if this is driver bug

Mar 25 14:49:24 x kernel: [71454.865260] gpio_stub_drv gpiochip2: REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED
Mar 25 14:49:24 x kernel: [71454.865333] ------------[ cut here ]------------
Mar 25 14:49:24 x kernel: [71454.865477] Call Trace:
Mar 25 14:49:24 x kernel: [71454.865478]  <TASK>
Mar 25 14:49:24 x kernel: [71454.865481]  unregister_irq_proc+0xf2/0x120
Mar 25 14:49:24 x kernel: [71454.865485]  free_desc+0x2e/0x80
Mar 25 14:49:24 x kernel: [71454.865488]  irq_free_descs+0x60/0xb0
Mar 25 14:49:24 x kernel: [71454.865492]  ch341_gpio_remove+0x5b/0x70 [ch341_buses]
Mar 25 14:49:24 x kernel: [71454.865500]  ch341_usb_disconnect+0x21/0x60 [ch341_buses]
Mar 25 14:49:24 x kernel: [71454.865505]  usb_unbind_interface+0x8e/0x280
Mar 25 14:49:24 x kernel: [71454.865510]  device_remove+0x65/0x80
Mar 25 14:49:24 x kernel: [71454.865514]  device_release_driver_internal+0x222/0x2a0
Mar 25 14:49:24 x kernel: [71454.865517]  device_release_driver+0x12/0x20
Mar 25 14:49:24 x kernel: [71454.865520]  bus_remove_device+0xde/0x160
Mar 25 14:49:24 x kernel: [71454.865523]  device_del+0x192/0x3f0
Mar 25 14:49:24 x kernel: [71454.865526]  ? kobject_put+0x67/0xa0
Mar 25 14:49:24 x kernel: [71454.865531]  usb_disable_device+0xd2/0x270
Mar 25 14:49:24 x kernel: [71454.865533]  usb_disconnect+0xe9/0x2e0
Mar 25 14:49:24 x kernel: [71454.865537]  hub_port_connect+0x90/0xc20
Mar 25 14:49:24 x kernel: [71454.865539]  hub_port_connect_change+0xb8/0x380
Mar 25 14:49:24 x kernel: [71454.865546]  port_event+0x652/0x810
Mar 25 14:49:24 x kernel: [71454.865549]  hub_event+0x155/0x450
Mar 25 14:49:24 x kernel: [71454.865551]  process_one_work+0x222/0x430
Mar 25 14:49:24 x kernel: [71454.865554]  worker_thread+0x50/0x3e0
Mar 25 14:49:24 x kernel: [71454.865556]  ? __pfx_worker_thread+0x10/0x10
Mar 25 14:49:24 x kernel: [71454.865557]  kthread+0xe6/0x110
Mar 25 14:49:24 x kernel: [71454.865560]  ? __pfx_kthread+0x10/0x10
Mar 25 14:49:24 x kernel: [71454.865563]  ret_from_fork+0x29/0x50
Mar 25 14:49:24 x kernel: [71454.865566]  </TASK>
Mar 25 14:49:24 x kernel: [71454.865566] ---[ end trace 0000000000000000 ]---

gpiochipN number going up indefinitely.

Hi,

Every time I unplug / replug in my ch341 the /dev/gpiochipN number is incremented by one. I'm pretty sure this isn't standard/expected behaviour, should probably recycle / use the lowest number.

6.2.x kernel port

Small fix needed:

diff --git a/ch341-core.c b/ch341-core.c
index 50c2f67..c979bea 100644
--- a/ch341-core.c
+++ b/ch341-core.c
@@ -103,6 +103,8 @@ static const struct usb_device_id ch341_usb_table[] = {
        { }
 };
 
+MODULE_DEVICE_TABLE(usb, ch341_usb_table);
+
 static struct usb_driver ch341_usb_driver = {
        .name       = "ch341-buses",
        .id_table   = ch341_usb_table,

Driver doesn't support 0-length transfers to control CS line

Edit: this is using the device as SPI.
We use a 0-length ioctl transfer to control the CS:

    xfer.tx_buf = NULL;
    xfer.len = 0;

    xfer.rx_buf = NULL
    xfer.cs_change = true; //(or false)

This is returning a 110 timeout error. Instead, it should either enable or disable the CS line.

support xfer->cs_change in multi-part SPI messages

Hi, thanks for this driver. It's been really useful.

I looked at the stock transfer_one_message implementation from the kernel's [spi.c], and it explicitly handles xfer->cs_change which the this driver currently doesn't. cs_change is meant to tell the SPI driver to momentarily toggle the CS mid-message, since some chips require that to "commit" a command.

Fix i2c handling

eeprom were never written correctly, and the reason is that the ch341 wasn't ready for the next request. See PR #7

could not insert module ch341-core.ko: Invalid module format

Hi,

I get the following error when I try to insert the modules.

(base) ➜  ch341-i2c-spi-gpio git:(master) ✗ sudo insmod ch341-core.ko   
insmod: ERROR: could not insert module ch341-core.ko: Invalid module format

I saw on a previous issue that it could have been built against the wrong kernel headers, how would I build against the right ones?

This is what modprobe returns:

(base) ➜  ch341-i2c-spi-gpio git:(master) ✗ modinfo ch341-core.ko
filename:       /home/adam/apps/ch341-i2c-spi-gpio/ch341-core.ko
license:        GPL
description:    CH341 USB to I2C/SPI/GPIO adapter
author:         Frank Zago <[email protected]>
srcversion:     76BBA2A35D7BD3BEBADD4D8
alias:          usb:v1A86p5512d*dc*dsc*dp*ic*isc*ip*in*
depends:        
retpoline:      Y
name:           ch341_core
vermagic:       6.2.0-26-generic SMP preempt mod_unload modversions 

Thanks

Fix README

The README Changed in 1dfa031 :

For instance, the following declares a flash memory at CS 0, and a user device (spidev) at CS 1:

$ echo "spidev 0" > /sys/class/spi_master/spi0/new_device
$ echo "spi-nor 1" > /sys/class/spi_master/spi0/new_device

so the text now describes the opposite CS order to those of the commands.

spi-ch341.c : error with kernel 6.8.0

Linux version 6.8.0
spi-ch341.c:196:54: error: array subscript is not an integer
spi-ch341.c:515:25: error: implicit declaration of function ‘gpiochip_find’; did you mean ‘gpiochip_add’?

udev for SPI

I'm trying to put together udev rules for firing up an SPI device automatically on plug. I think there's an issue, that the ch341-spi driver doesn't actually expose what SPI number the USB has grabbed. So, on most systems, that will be "/sys/class/spi_master/spi0" but if the system has an existing SPI bus, I suspect the CH341 may become SPI1 instead. Would it be possible to set a udev ENV value that identifies which SPI bus number the driver is using? Or is there an easier solution?

open i2c device using ioctl is not supported

Hello!

I'm trying to setup mlx90640 i2c device using CH341T-V3 usb stick. When device opened via ioctl command I get following:

I2C device tree: '/dev/i2c-7'
Starting...
Configured...0
refresh = 0
Ioctl read i2c error:: Operation not supported

Checking the source code it seems like ioctl call failed:

        ioctl_msg[0].len	= 	len;
        ioctl_msg[0].addr	= 	device->addr;
        ioctl_msg[0].buf	=	buf;
        ioctl_msg[0].flags	=	flags | I2C_M_RD;

        /* Package to i2c message to operation i2c device */
        ioctl_data.nmsgs	=	1;
        ioctl_data.msgs		=	ioctl_msg;

        ioctl(device->bus, I2C_RDWR, (unsigned long)&ioctl_data) == -1

I'm not sure if drive fully support linux i2c bus commands or not.

Full source:

oops on unload during irq monitoring.

To reproduce:

  • load drivers
  • gpiomon --rising-edge /dev/gpiochipN 10
  • unload drivers (specifically gpio_ch341)
[ 7366.300590] ------------[ cut here ]------------
[ 7366.300591] remove_proc_entry: removing non-empty directory 'irq/206', leaking at least 'gpiomon'
[ 7366.300597] WARNING: CPU: 2 PID: 23863 at fs/proc/generic.c:717 remove_proc_entry+0x19c/0x1c0
[ 7366.300602] Modules linked in: spi_ch341(O) i2c_ch341(O) gpio_ch341(O) ch341_core(O-) rfcomm uas qrtr bnep usb_storage uvcvideo videobuf2_vmalloc videobuf2_memops uvc btusb videobuf2_v4l2 btrtl btintel videodev btbcm btmtk videobuf2_common mc bluetooth hid_sensor_als hid_sensor_trigger industrialio_triggered_buffer hid_sensor_iio_common kfifo_buf industrialio hid_sensor_hub intel_ishtp_hid vfat fat snd_hda_codec_hdmi snd_sof_pci_intel_tgl snd_sof_intel_hda_common snd_soc_hdac_hda snd_sof_pci snd_sof_xtensa_dsp snd_sof_intel_hda snd_sof snd_sof_utils snd_soc_acpi_intel_match snd_soc_acpi snd_soc_core iwlmvm intel_powerclamp snd_compress snd_hda_codec_idt cros_usbpd_charger snd_sof_intel_hda_mlink snd_hda_codec_generic cros_ec_sysfs coretemp cros_ec_chardev cros_usbpd_logger cros_usbpd_notify snd_hda_ext_core ofpart mac80211 snd_hda_intel snd_intel_dspcfg kvm_intel spi_nor iTCO_wdt snd_hda_codec cros_ec_dev joydev mei_hdcp mei_pxp mtd mei_wdt ee1004 libarc4 hid_multitouch iTCO_vendor_support cros_ec_lpcs snd_hwdep
[ 7366.300634]  cros_ec kvm snd_hda_core irqbypass crct10dif_pclmul iwlwifi polyval_clmulni snd_pcm polyval_generic snd_timer ghash_clmulni_intel cfg80211 mei_me i2c_i801 snd intel_ish_ipc sha512_ssse3 ucsi_acpi spi_intel_pci binfmt_misc sha256_ssse3 sha1_ssse3 rapl intel_cstate intel_uncore serio_raw pcspkr intel_rapl_msr typec_ucsi spi_intel rfkill wmi_bmof soundcore i2c_smbus intel_ishtp mei idma64 thunderbolt typec igen6_edac i2c_hid_acpi intel_pmc_core i2c_hid pinctrl_tigerlake intel_vsec pinctrl_intel pmt_telemetry pwm_lpss pmt_class acpi_pad xhci_pci xhci_pci_renesas xhci_hcd crc32_pclmul crc32c_intel usbcore usb_common
[ 7366.300655] Unloaded tainted modules: i2c_ch341(O):32 spi_ch341(O):31 gpio_ch341(O):30 ch341_core(O):32 [last unloaded: i2c_ch341(O)]
[ 7366.300659] CPU: 2 PID: 23863 Comm: rmmod Kdump: loaded Tainted: G  R     W  O       6.8.0-rc4-devel+ #26
[ 7366.300660] Hardware name: Framework Laptop/FRANBMCP0C, BIOS 03.17 10/27/2022
[ 7366.300661] RIP: 0010:remove_proc_entry+0x19c/0x1c0
[ 7366.300663] Code: c7 58 d4 dc 82 48 85 c0 48 8d 90 78 ff ff ff 48 0f 45 c2 48 8b 53 f0 4c 8b 80 a0 00 00 00 48 8b 92 a0 00 00 00 e8 c4 cc be ff <0f> 0b e9 76 ff ff ff 48 8b 73 18 48 c7 c7 30 d4 dc 82 e8 ad cc be
[ 7366.300664] RSP: 0018:ffffc90000e03a60 EFLAGS: 00010282
[ 7366.300666] RAX: 0000000000000000 RBX: ffff8881e12b6ec8 RCX: 0000000000000027
[ 7366.300667] RDX: ffff88888fa9da08 RSI: 0000000000000001 RDI: ffff88888fa9da00
[ 7366.300667] RBP: ffff8881e12b6e40 R08: 0000000000000000 R09: ffffc90000e038e8
[ 7366.300668] R10: 0000000000000003 R11: ffffffff83126d18 R12: ffff8881e12b6ec0
[ 7366.300669] R13: ffffc90000e03ab6 R14: ffffc90000e03ab6 R15: ffff8881002e86c0
[ 7366.300669] FS:  00007f88ca20bc40(0000) GS:ffff88888fa80000(0000) knlGS:0000000000000000
[ 7366.300670] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 7366.300671] CR2: 000056172b9b8848 CR3: 00000001d93f6002 CR4: 0000000000f70ef0
[ 7366.300672] PKRU: 55555554
[ 7366.300673] Call Trace:
[ 7366.300674]  <TASK>
[ 7366.300675]  ? remove_proc_entry+0x19c/0x1c0
[ 7366.300677]  ? __warn+0x81/0x130
[ 7366.300680]  ? remove_proc_entry+0x19c/0x1c0
[ 7366.300682]  ? report_bug+0x171/0x1a0
[ 7366.300684]  ? console_unlock+0x78/0x120
[ 7366.300686]  ? handle_bug+0x3c/0x80
[ 7366.300688]  ? exc_invalid_op+0x17/0x70
[ 7366.300689]  ? asm_exc_invalid_op+0x1a/0x20
[ 7366.300692]  ? remove_proc_entry+0x19c/0x1c0
[ 7366.300694]  unregister_irq_proc+0xf4/0x120
[ 7366.300696]  free_desc+0x3d/0xe0
[ 7366.300698]  ? __irq_get_desc_lock+0x55/0x90
[ 7366.300700]  ? __irq_put_desc_unlock+0x1c/0x50
[ 7366.300701]  ? irq_set_chip_data+0x4c/0x80
[ 7366.300703]  irq_free_descs+0x47/0x70
[ 7366.300706]  gpiochip_irqchip_remove+0xdf/0x210
[ 7366.300709]  gpiochip_remove+0x3e/0x150
[ 7366.300710]  ch341_gpio_remove+0x22/0x40 [gpio_ch341]
[ 7366.300714]  platform_remove+0x3c/0x60
[ 7366.300716]  device_release_driver_internal+0x19f/0x200
[ 7366.300719]  bus_remove_device+0xc6/0x130
[ 7366.300720]  device_del+0x15c/0x3f0
[ 7366.300722]  ? kfree+0x29f/0x2f0
[ 7366.300725]  platform_device_del.part.0+0x13/0x70
[ 7366.300726]  platform_device_unregister+0x20/0x40
[ 7366.300728]  mfd_remove_devices_fn+0xd4/0xf0
[ 7366.300730]  ? __pfx_mfd_remove_devices_fn+0x10/0x10
[ 7366.300732]  device_for_each_child_reverse+0x6e/0xb0
[ 7366.300734]  devm_mfd_dev_release+0x36/0x60
[ 7366.300735]  release_nodes+0x3d/0xb0
[ 7366.300738]  devres_release_all+0x8c/0xc0
[ 7366.300739]  device_unbind_cleanup+0xe/0x70
[ 7366.300741]  device_release_driver_internal+0x1c4/0x200
[ 7366.300743]  driver_detach+0x48/0x90
[ 7366.300744]  bus_remove_driver+0x6d/0xf0
[ 7366.300746]  usb_deregister+0x76/0xd0 [usbcore]
[ 7366.300768]  __do_sys_delete_module+0x1d2/0x320
[ 7366.300770]  do_syscall_64+0x86/0x1a0
[ 7366.300773]  ? syscall_exit_to_user_mode+0x89/0x230
[ 7366.300775]  ? do_syscall_64+0x95/0x1a0
[ 7366.300777]  ? exc_page_fault+0x7f/0x180
[ 7366.300779]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
[ 7366.300781] RIP: 0033:0x7f88ca303997
[ 7366.300783] Code: 73 01 c3 48 8b 0d 91 b4 0a 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 b0 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 61 b4 0a 00 f7 d8 64 89 01 48
[ 7366.300783] RSP: 002b:00007fff3e963f68 EFLAGS: 00000202 ORIG_RAX: 00000000000000b0
[ 7366.300785] RAX: ffffffffffffffda RBX: 000056172b9ae700 RCX: 00007f88ca303997
[ 7366.300785] RDX: 000000000000000a RSI: 0000000000000800 RDI: 000056172b9ae768
[ 7366.300786] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
[ 7366.300787] R10: 0000000000000000 R11: 0000000000000202 R12: 00007fff3e9641b0
[ 7366.300787] R13: 00007fff3e96567b R14: 000056172b9ae2a0 R15: 000056172b9ae700
[ 7366.300788]  </TASK>
[ 7366.300789] ---[ end trace 0000000000000000 ]---
[ 7366.300795] gpio gpiochip12: REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED
[ 7366.300932] ------------[ cut here ]------------
[ 7366.300934] WARNING: CPU: 3 PID: 23849 at drivers/gpio/gpiolib.c:2352 gpiod_free+0x1b/0x40
[ 7366.300938] Modules linked in: spi_ch341(O) i2c_ch341(O) gpio_ch341(O) ch341_core(O-) rfcomm uas qrtr bnep usb_storage uvcvideo videobuf2_vmalloc videobuf2_memops uvc btusb videobuf2_v4l2 btrtl btintel videodev btbcm btmtk videobuf2_common mc bluetooth hid_sensor_als hid_sensor_trigger industrialio_triggered_buffer hid_sensor_iio_common kfifo_buf industrialio hid_sensor_hub intel_ishtp_hid vfat fat snd_hda_codec_hdmi snd_sof_pci_intel_tgl snd_sof_intel_hda_common snd_soc_hdac_hda snd_sof_pci snd_sof_xtensa_dsp snd_sof_intel_hda snd_sof snd_sof_utils snd_soc_acpi_intel_match snd_soc_acpi snd_soc_core iwlmvm intel_powerclamp snd_compress snd_hda_codec_idt cros_usbpd_charger snd_sof_intel_hda_mlink snd_hda_codec_generic cros_ec_sysfs coretemp cros_ec_chardev cros_usbpd_logger cros_usbpd_notify snd_hda_ext_core ofpart mac80211 snd_hda_intel snd_intel_dspcfg kvm_intel spi_nor iTCO_wdt snd_hda_codec cros_ec_dev joydev mei_hdcp mei_pxp mtd mei_wdt ee1004 libarc4 hid_multitouch iTCO_vendor_support cros_ec_lpcs snd_hwdep
[ 7366.300964]  cros_ec kvm snd_hda_core irqbypass crct10dif_pclmul iwlwifi polyval_clmulni snd_pcm polyval_generic snd_timer ghash_clmulni_intel cfg80211 mei_me i2c_i801 snd intel_ish_ipc sha512_ssse3 ucsi_acpi spi_intel_pci binfmt_misc sha256_ssse3 sha1_ssse3 rapl intel_cstate intel_uncore serio_raw pcspkr intel_rapl_msr typec_ucsi spi_intel rfkill wmi_bmof soundcore i2c_smbus intel_ishtp mei idma64 thunderbolt typec igen6_edac i2c_hid_acpi intel_pmc_core i2c_hid pinctrl_tigerlake intel_vsec pinctrl_intel pmt_telemetry pwm_lpss pmt_class acpi_pad xhci_pci xhci_pci_renesas xhci_hcd crc32_pclmul crc32c_intel usbcore usb_common
[ 7366.300980] Unloaded tainted modules: i2c_ch341(O):32 spi_ch341(O):31 gpio_ch341(O):30 ch341_core(O):32 [last unloaded: i2c_ch341(O)]
[ 7366.300983] CPU: 3 PID: 23849 Comm: gpiomon Kdump: loaded Tainted: G  R     W  O       6.8.0-rc4-devel+ #26
[ 7366.300986] Hardware name: Framework Laptop/FRANBMCP0C, BIOS 03.17 10/27/2022
[ 7366.300986] RIP: 0010:gpiod_free+0x1b/0x40
[ 7366.300988] Code: 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 0f 1f 00 0f 1f 44 00 00 48 85 ff 74 27 53 48 89 fb e8 f9 d2 ff ff 84 c0 75 02 <0f> 0b 48 8b 03 48 8b b8 68 03 00 00 e8 34 d8 7e ff 48 8b 3b 5b e9
[ 7366.300989] RSP: 0018:ffffc90000aabdb8 EFLAGS: 00010246
[ 7366.300990] RAX: 0000000000000000 RBX: ffff8882643f3990 RCX: ffff888104624900
[ 7366.300991] RDX: 0000000000000000 RSI: 0000000000000002 RDI: ffff8881aa9933a8
[ 7366.300992] RBP: 00000000000a0005 R08: 0000000000000000 R09: 0000000000000000
[ 7366.300992] R10: 0000000000000000 R11: 0000000000000001 R12: ffff8881005b6300
[ 7366.300993] R13: ffff88810155f520 R14: ffff8882f3862b40 R15: 0000000000000000
[ 7366.300994] FS:  00007f5a4a584740(0000) GS:ffff88888fac0000(0000) knlGS:0000000000000000
[ 7366.300995] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 7366.300996] CR2: 000034c59af5e000 CR3: 00000001043fe004 CR4: 0000000000f70ef0
[ 7366.300997] PKRU: 55555554
[ 7366.300997] Call Trace:
[ 7366.300998]  <TASK>
[ 7366.300998]  ? gpiod_free+0x1b/0x40
[ 7366.301000]  ? __warn+0x81/0x130
[ 7366.301002]  ? gpiod_free+0x1b/0x40
[ 7366.301003]  ? report_bug+0x171/0x1a0
[ 7366.301006]  ? handle_bug+0x3c/0x80
[ 7366.301007]  ? exc_invalid_op+0x17/0x70
[ 7366.301008]  ? asm_exc_invalid_op+0x1a/0x20
[ 7366.301011]  ? gpiod_free+0x1b/0x40
[ 7366.301012]  ? gpiod_free+0x17/0x40
[ 7366.301014]  lineevent_free+0x38/0x60
[ 7366.301015]  lineevent_release+0x15/0x20
[ 7366.301016]  __fput+0x97/0x2c0
[ 7366.301019]  __x64_sys_close+0x3d/0x80
[ 7366.301022]  do_syscall_64+0x86/0x1a0
[ 7366.301025]  ? ksys_read+0x6f/0xf0
[ 7366.301026]  ? syscall_exit_to_user_mode+0x89/0x230
[ 7366.301028]  ? do_syscall_64+0x95/0x1a0
[ 7366.301029]  ? do_syscall_64+0x95/0x1a0
[ 7366.301031]  ? do_syscall_64+0x95/0x1a0
[ 7366.301032]  ? syscall_exit_to_user_mode+0x89/0x230
[ 7366.301034]  ? do_syscall_64+0x95/0x1a0
[ 7366.301035]  ? exc_page_fault+0x7f/0x180
[ 7366.301037]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
[ 7366.301039] RIP: 0033:0x7f5a4a66d2e0
[ 7366.301041] Code: 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 80 3d 89 40 0c 00 00 74 17 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 48 c3 0f 1f 80 00 00 00 00 48 83 ec 18 89 7c
[ 7366.301041] RSP: 002b:00007ffca843cd48 EFLAGS: 00000202 ORIG_RAX: 0000000000000003
[ 7366.301043] RAX: ffffffffffffffda RBX: 00007ffca843cd80 RCX: 00007f5a4a66d2e0
[ 7366.301043] RDX: 0000000000000001 RSI: 00007ffca843ce70 RDI: 0000000000000005
[ 7366.301044] RBP: 0000558276b46500 R08: 0000558276b46570 R09: 00007f5a4a729b20
[ 7366.301044] R10: 0000000000000000 R11: 0000000000000202 R12: 00007ffca843cd80
[ 7366.301045] R13: 0000558276b462a0 R14: 00007ffca843d054 R15: 0000000000000001
[ 7366.301046]  </TASK>
[ 7366.301047] ---[ end trace 0000000000000000 ]---

IRQ?

Hi!

I don't really know much about hardware interrupts, but I'm comparing this project to: https://github.com/UncleGrumpy/spi-ch341-usb.git

with the above fork, this works:

$ gpioinfo
gpiochip31 - 3 lines:
	line   0:    "dio_irq"       unused   input  active-high 
	line   1:   "dio_busy"       unused   input  active-high 
	line   2:  "dio_reset"       unused   input  active-high 
$ gpiomon /dev/gpiochip31 0
^C
$ gpiomon /dev/gpiochip31 1
^C
$ gpiomon /dev/gpiochip31 2
^C

With your version, I can't watch any of the pins:

$ gpiomon /dev/gpiochip32 10
gpiomon: error waiting for events: Invalid argument

#INI output signal question

How to drive it ? It is 26 output only pin of 341B/A/F, described as #INI "Initialize the printer, active low, connect to INIT" in datasheet in print port mode or as RST# "Reset output, active low" in parallel mode.

Thank you for your work

If possible, list some Todo List, and then we may be able to participate if we are interested.

adapter quirk: msg too long

i2c i2c-7: adapter quirk: msg too long (addr 0x0033, size 1664, read)

Tested on Debian, kernel 5.10.0-22-amd64, i2c device: Melexis MLX90640 sensor

no i2c and spi devices.

I'm using Debian 11. CH341T board. Compiled without errors.

dmesg
[ 1873.605531] usb 1-2: New USB device found, idVendor=1a86, idProduct=5512, bcdDevice= 3.04
[ 1873.605534] usb 1-2: New USB device strings: Mfr=0, Product=0, SerialNumber=0

sudo insmod ch341-buses.ko
ls -l /dev/* | grep ch341
crw-rw---- 1 root ch341 254, 0 сер 29 14:47 /dev/gpiochip0

why don't i2c and spi devices show up?

driver ignores SPI bus lock

I have a device that the kernel reliably fails to initialize when using the driver.
After debugging, it looks like it has to do with the driver taking a lock via master->bus_lock_flag during initialization, which somehow changes the bus traffic, I suspect it has to do with CS but haven't pinned it down.

To check, I implemented a simplified version of set_cs/transfer_one so that I could test the default kernel impl of transfer_one_message. The problem immediately went way.

To make sure I correctly identified the problem, I modified transfer_one_message
from the project so it does not release CS if the bus is locked - again, the problem went away.

Please have a look at this. Here's my modified version, if it helps:

static int ch341_spi_transfer_one_message(struct spi_master *master,
                      struct spi_message *m)
{
    struct ch341_device *dev = spi_master_get_devdata(master);
    struct spi_device *spi = m->spi;
    struct spi_client *client = &dev->spi_clients[spi->chip_select];
    struct gpio_desc *cs;
    bool lsb = spi->mode & SPI_LSB_FIRST;
    struct spi_transfer *xfer;
    unsigned int tx_len = 0;
    unsigned int buf_idx = 0;
    int status;
    bool bus_is_locked = false;
    unsigned long flags;

    spin_lock_irqsave(&master->bus_lock_spinlock, flags);
    bus_is_locked = master->bus_lock_flag;
    spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);

    if (spi->mode & SPI_NO_CS) {
        cs = NULL;
    } else {
        cs = client->gpio;

        if (spi->mode & SPI_CS_HIGH)
            gpiod_set_value_cansleep(cs, 1);
        else
            gpiod_set_value_cansleep(cs, 0);
    }
    list_for_each_entry(xfer, &m->transfers, transfer_list) {;
        buf_idx = copy_to_device(client->buf, buf_idx, xfer->tx_buf, xfer->len, lsb);
        tx_len += xfer->len;
    }

    status = spi_transfer(dev, client->buf, buf_idx, buf_idx - tx_len);
    if (cs && !bus_is_locked) {
        if (spi->mode & SPI_CS_HIGH)
            gpiod_set_value_cansleep(cs, 0);
        else
            gpiod_set_value_cansleep(cs, 1);
    }

    if (status >= 0) {
        buf_idx = 0;
        list_for_each_entry(xfer, &m->transfers, transfer_list)
            buf_idx = copy_from_device(xfer->rx_buf, client->buf,
                           buf_idx, xfer->len, lsb);

        m->actual_length = tx_len;
        status = 0;
    }

    m->status = status;
    spi_finalize_current_message(master);

    return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.