Skip to content

Commit

Permalink
Disconnect spi from gpio dependency
Browse files Browse the repository at this point in the history
This fixes frank-zago#29
  • Loading branch information
mjsir911 committed Mar 12, 2024
1 parent 9d65db4 commit 793ea2f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
1 change: 1 addition & 0 deletions ch341-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
static const struct mfd_cell ch341_devs[] = {
{ .name = "ch341-gpio", },
{ .name = "ch341-i2c", },
{ .name = "ch341-spi", },
};

static int ch341_usb_probe(struct usb_interface *iface,
Expand Down
9 changes: 0 additions & 9 deletions gpio-ch341.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
#include <linux/usb.h>
#include <linux/version.h>

static const struct mfd_cell ch341_gpio_devs[] = {
{ .name = "ch341-spi", },
};

#define CH341_GPIO_NUM_PINS 16 /* Number of GPIO pins */

/* GPIO chip commands */
Expand Down Expand Up @@ -411,11 +407,6 @@ static int ch341_gpio_probe(struct platform_device *pdev)
return ret;
}

ret = mfd_add_hotplug_devices(&pdev->dev, ch341_gpio_devs,
ARRAY_SIZE(ch341_gpio_devs));
if (ret)
dev_warn(&pdev->dev, "Failed to add mfd SPI device to gpio.");

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion spi-ch341.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static void ch341_cleanup(struct spi_device *spi)

static int ch341_spi_probe(struct platform_device *pdev)
{
struct ch341_ddata *ch341 = dev_get_drvdata(pdev->dev.parent->parent);
struct ch341_ddata *ch341 = dev_get_drvdata(pdev->dev.parent);
struct spi_controller *master;
struct ch341_spi *dev;
int ret;
Expand Down

2 comments on commit 793ea2f

@frank-zago
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But spi is a client of gpio. If spi is active, it uses some pins from gpio, which other applications must then not use.

@mjsir911
Copy link
Owner Author

@mjsir911 mjsir911 commented on 793ea2f Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other gpio drivers in the kernel tree right now load other drivers and what you're doing here causes an issue with deregistering devices as seen in frank-zago#29.

With the above changes, all that happens is:

  • no gpio driver loaded, loads spi driver:

      [10612.409431] ch341-spi ch341-spi.12.auto: CH341 SPI Controller: ch341-spi.12.auto
      [10612.409442] spi_master (null): cannot find GPIO chip ch341, deferring
      [10612.409468] ch341-spi ch341-spi.15.auto: CH341 SPI Controller: ch341-spi.15.auto
      [10612.409471] spi_master (null): cannot find GPIO chip ch341, deferring
    
  • loading gpio driver after spi driver works successfully

  • both drivers loaded, unloads gpio driver: rmmod: ERROR: Module gpio_ch341 is in use

Please sign in to comment.