hid-mcp2200 added driver for MCP2200 GPIOs
PATCH 1/1 hid-mcp2200 added driver for MCP2200 GPIOs
Added a gpiochip compatible driver to control the 8 GPIOs of the MCP2200 by using the HID interface.
Using GPIOs with alternative functions (GP0<->SSPND, GP1<->USBCFG, GP6<->RXLED, GP7<->TXLED) will reset the functions, if set (unset by default).
The driver was tested while also using the UART of the chip. Setting and reading the GPIOs has no effect on the UART communication. However, a reset is triggered after the CONFIGURE command. If the GPIO Direction is constantly changed, this will affect the communication at low baud rates. This is a hardware problem of the MCP2200 and is not caused by the driver.
--- drivers/hid/Kconfig | 10 + drivers/hid/Makefile | 1 + drivers/hid/hid-mcp2200.c | 421 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 432 insertions(+) create mode 100644 drivers/hid/hid-mcp2200.c
drivers/hid/Kconfig +10 -0
@@ -1283,6 +1283,16 @@ config HID_MCP2221 To compile this driver as a module, choose M here: the module will be called hid-mcp2221.ko. +config HID_MCP2200 + tristate "Microchip MCP2200 HID USB-to-GPIO bridge" + depends on USB_HID + imply GPIOLIB + help + Provides GPIO functionality over USB-HID through MCP2200 device. + + To compile this driver as a module, choose M here: the module + will be called hid-mcp2200.ko. + config HID_KUNIT_TEST tristate "KUnit tests for HID" if !KUNIT_ALL_TESTS depends on KUNIT=y
drivers/hid/Makefile +1 -0
@@ -79,6 +79,7 @@ obj-$(CONFIG_HID_MACALLY) += hid-macally.o obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o obj-$(CONFIG_HID_MALTRON) += hid-maltron.o obj-$(CONFIG_HID_MCP2221) += hid-mcp2221.o +obj-$(CONFIG_HID_MCP2200) += hid-mcp2200.o obj-$(CONFIG_HID_MAYFLASH) += hid-mf.o obj-$(CONFIG_HID_MEGAWORLD_FF) += hid-megaworld.o obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o
drivers/hid/hid-mcp2200.c new file +421 -0
421 lines not on this page · raw message
Signature · 1 line
2.41.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Johannes,
kernel test robot noticed the following build errors:
[auto build test ERROR on v6.4-rc5]
[also build test ERROR on linus/master next-20230609] [cannot apply to hid/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Johannes-Roith/hid-mcp2200-added-driver-for-MCP2200-GPIOs/20230611-225658 base: v6.4-rc5 patch link: https://lore.kernel.org/r/20230611144831.41238-1-johannes%40gnu-linux.rocks patch subject: [PATCH] hid-mcp2200 added driver for MCP2200 GPIOs config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230612/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build):
git checkout v6.4-rc5
b4 shazam https://lore.kernel.org/r/[email protected]
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/hid/hid-mcp2200.c:16:
>> drivers/hid/hid-mcp2200.c:403:51: error: 'USB_DEVICE_ID_MCP2200' undeclared here (not in a function); did you mean 'USB_DEVICE_ID_MCP2221'?
403 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_MCP2200) },
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/hid.h:715:54: note: in definition of macro 'HID_USB_DEVICE'
715 | .bus = BUS_USB, .vendor = (ven), .product = (prod)
| ^~~~vim +403 drivers/hid/hid-mcp2200.c
401
402 static const struct hid_device_id mcp2200_devices[] = {
> 403 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_MCP2200) }, 404 { }
405 };
406 MODULE_DEVICE_TABLE(hid, mcp2200_devices);
407
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Johannes,
kernel test robot noticed the following build errors:
[auto build test ERROR on v6.4-rc5]
[also build test ERROR on linus/master next-20230609] [cannot apply to hid/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Johannes-Roith/hid-mcp2200-added-driver-for-MCP2200-GPIOs/20230611-225658 base: v6.4-rc5 patch link: https://lore.kernel.org/r/20230611144831.41238-1-johannes%40gnu-linux.rocks patch subject: [PATCH] hid-mcp2200 added driver for MCP2200 GPIOs config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230612/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build):
git checkout v6.4-rc5
b4 shazam https://lore.kernel.org/r/[email protected]
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from drivers/hid/hid-mcp2200.c:16:
>> drivers/hid/hid-mcp2200.c:403:51: error: 'USB_DEVICE_ID_MCP2200' undeclared here (not in a function); did you mean 'USB_DEVICE_ID_MCP2221'?
403 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_MCP2200) },
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/hid.h:715:54: note: in definition of macro 'HID_USB_DEVICE'
715 | .bus = BUS_USB, .vendor = (ven), .product = (prod)
| ^~~~vim +403 drivers/hid/hid-mcp2200.c
401
402 static const struct hid_device_id mcp2200_devices[] = {
> 403 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_MCP2200) }, 404 { }
405 };
406 MODULE_DEVICE_TABLE(hid, mcp2200_devices);
407
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Joannes,
[...]
drivers/hid/hid-mcp2200.c line 118
Quoted 12 lines
drivers/hid/hid-mcp2200.c new file +12
-0+/* this executes the READ_ALL cmd */ +static int mcp_cmd_read_all (struct mcp2200 *mcp) +{ +struct mcp_read_all *read_all; +int len, t; + +reinit_completion (&mcp->wait_in_report); +mutex_lock (&mcp->lock); + + read_all =kzalloc (sizeof (struct mcp_read_all ),GFP_KERNEL ); +if (!read_all) +return -ENOMEM ;
where are you unlocking?
drivers/hid/hid-mcp2200.c line 125
Quoted 6 lines
drivers/hid/hid-mcp2200.c new file +6
-0+ read_all->cmd =READ_ALL ; + len =hid_hw_output_report (mcp->hdev, (u8 *) read_all, +sizeof (struct mcp_read_all )); + +if (len !=sizeof (struct mcp_read_all )) +return -EINVAL ;
what about read_all? what about the lock?
drivers/hid/hid-mcp2200.c line 135
Quoted 10 lines
drivers/hid/hid-mcp2200.c new file +10
-0+ +kfree (read_all); +mutex_unlock (&mcp->lock); + t =wait_for_completion_timeout (&mcp->wait_in_report,msecs_to_jiffies (4000 )); +if (!t) +return -ETIMEDOUT ; + +/* return status, negative value if wrong response was received */ +return mcp->status; +}
[...]
Andi