pax_global_header00006660000000000000000000000064151007531460014514gustar00rootroot0000000000000052 comment=ee221ecae757d43ab3fb39433f389373b2026109 usbio-drivers-0~git202510282139.ee221eca/000077500000000000000000000000001510075314600173455ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/CONTRIBUTING.md000066400000000000000000000043621510075314600216030ustar00rootroot00000000000000# Contributing ### License USBIO is licensed under the terms in [GPL-2.0 license](./GPL-2.0 license) file. By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. ### Sign your work Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org](http://developercertificate.org/)): ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 660 York Street, Suite 102, San Francisco, CA 94110 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` Then you just add a line to every git commit message: Signed-off-by: Joe Smith Use your real name (sorry, no pseudonyms or anonymous contributions.) If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with `git commit -s`. usbio-drivers-0~git202510282139.ee221eca/LICENSE.txt000066400000000000000000000432541510075314600212000ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. usbio-drivers-0~git202510282139.ee221eca/Makefile000066400000000000000000000010371510075314600210060ustar00rootroot00000000000000# Copyright (c) 2025 Intel Corporation. # SPDX-License-Identifier: GPL-2.0 obj-m += usbio.o usbio-y := drivers/usb/misc/usbio.o obj-m += gpio-usbio.o gpio-usbio-y := drivers/gpio/gpio-usbio.o obj-m += i2c-usbio.o i2c-usbio-y := drivers/i2c/busses/i2c-usbio.o KERNELRELEASE := $(shell uname -r) KDIR := /lib/modules/$(KERNELRELEASE)/build PWD := $(shell pwd) ccflags-y += -I$(src)/include/ all: $(MAKE) -C $(KDIR) M=$(PWD) modules modules_install: $(MAKE) -C $(KDIR) M=$(PWD) modules_install clean: $(MAKE) -C $(KDIR) M=$(PWD) clean usbio-drivers-0~git202510282139.ee221eca/README.md000066400000000000000000000045101510075314600206240ustar00rootroot00000000000000# USBIO driver stack This repository supports USBIO drivers on Intel's Meteor Lake, Arrow Lake, Lunar Lake and Panther Lake platforms. ## Build types * Kernel module * Dynamic Kernel module * Kernel source code ### Kernel Module Requires 6.8 (or later) kernel's headers installed * To compile: ``` $cd usbio-drivers $make -j`nproc` ``` * To install modules ``` $sudo make modules_install $sudo depmod -a ``` ### Dynamic Kernel Module A dkms.conf is provided to build and install the driver stack * Prepare dkms: ``` $sudo mkdir /usr/src/usbio-0.3 $sudo cp -R . /usr/src/usbio-0.3/ ``` * Build and install dkms ``` $sudo dkms add -m usbio -v 0.3 $sudo dkms build -m usbio -v 0.3 $sudo dkms install -m usbio -v 0.3 ``` ### Kernel source code Tested on kernel 6.8, 6.11, 6.14 and 6.17 * Copy drivers into kernel source code * Update the required Kconfigs and Makefiles Add to drivers/usb/misc/Kconfig ``` config USB_USBIO tristate "Intel USBIO Bridge support" depends on USB && ACPI select AUXILIARY_BUS help This adds support for Intel USBIO drivers. This enables the USBIO bridge driver module in charge to talk to the USB device. Additional drivers such as GPIO_USBIO and I2C_USBIO must be enabled in order to use the device's full functionality. This driver can also be built as a module. If so, the module will be called usbio. ``` Add to drivers/usb/misc/Makefile ``` obj-$(CONFIG_USB_USBIO) += usbio.o ``` Add to drivers/gpio/Kconfig ``` config GPIO_USBIO tristate "Intel USBIO GPIO support" depends on USB_USBIO default USB_USBIO help Select this option to enable GPIO driver for the INTEL USBIO driver stack. This driver can also be built as a module. If so, the module will be called gpio_usbio. ``` Add to drivers/gpio/Makefile ``` obj-$(CONFIG_GPIO_USBIO) += gpio-usbio.o ``` Add to drivers/i2c/busses/Kconfig ``` config I2C_USBIO tristate "Intel USBIO I2C Adapter support" depends on USB_USBIO default USB_USBIO help Select this option to enable I2C driver for the INTEL USBIO driver stack. This driver can also be built as a module. If so, the module will be called i2c_usbio. ``` Add to drivers/i2c/busses/Makefile ``` obj-$(CONFIG_I2C_USBIO) += i2c-usbio.o ``` Enable drivers in .config ``` CONFIG_USB_USBIO=y CONFIG_GPIO_USBIO=y CONFIG_I2C_USBIO=y ``` * Compile and install new kernel usbio-drivers-0~git202510282139.ee221eca/SECURITY.md000066400000000000000000000006251510075314600211410ustar00rootroot00000000000000# Security Policy Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. ## Reporting a Vulnerability Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). usbio-drivers-0~git202510282139.ee221eca/dkms.conf000066400000000000000000000005361510075314600211560ustar00rootroot00000000000000PACKAGE_NAME="usbio" PACKAGE_VERSION="0.2" MAKE="make -C . KERNELDIR=/lib/modules/${kernelver}/build" CLEAN="make -C . clean" BUILT_MODULE_NAME[0]="usbio" DEST_MODULE_LOCATION[0]="/updates" BUILT_MODULE_NAME[1]="gpio-usbio" DEST_MODULE_LOCATION[1]="/updates" BUILT_MODULE_NAME[2]="i2c-usbio" DEST_MODULE_LOCATION[2]="/updates" AUTOINSTALL="yes" usbio-drivers-0~git202510282139.ee221eca/drivers/000077500000000000000000000000001510075314600210235ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/drivers/gpio/000077500000000000000000000000001510075314600217615ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/drivers/gpio/gpio-usbio.c000066400000000000000000000162501510075314600242060ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2025 Intel Corporation. */ #include #include #include #include #include #include #include #include /** * struct usbio_gpio - represents usbio gpio controller * * @gc: gpio chip for the usbio gpio * @chip: usbio gpio chip data * @client: usbio client reference */ struct usbio_gpio { struct gpio_chip gc; struct usbio_gpio_chip *chip; struct usbio_client *client; }; static const struct acpi_device_id usbio_gpio_acpi_hids[] = { { "INTC1007" }, /* MTL */ { "INTC10B2" }, /* ARL */ { "INTC10B5" }, /* LNL */ { "INTC10E2" }, /* PTL */ { } }; static int usbio_gpio_val_bank_and_pin(struct gpio_chip *gc, unsigned int offset, struct usbio_gpio_bank **gbank) { struct usbio_gpio *gpio = gpiochip_get_data(gc); struct usbio_gpio_chip *chip = gpio->chip; struct usbio_gpio_bank *bank; int pin; if (offset >= gc->ngpio) return -EINVAL; bank = &chip->banks[offset / USBIO_GPIOSPERBANK]; pin = offset % USBIO_GPIOSPERBANK; if (~bank->bitmap & BIT(pin)) return -EINVAL; *gbank = bank; return pin; } static int usbio_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) { struct usbio_gpio_bank *bank; int pin; u8 cfg; pin = usbio_gpio_val_bank_and_pin(gc, offset, &bank); if (pin < 0) return pin; cfg = bank->config[pin] & USBIO_GPIO_PINMOD_MASK; if (cfg == USBIO_GPIO_PINMOD_OUTPUT) return GPIO_LINE_DIRECTION_OUT; return GPIO_LINE_DIRECTION_IN; } static int usbio_gpio_direction_input(struct gpio_chip *gc, unsigned int offset) { struct usbio_gpio *gpio = gpiochip_get_data(gc); struct usbio_gpio_bank *bank; struct usbio_gpio_init gbuf; int pin; pin = usbio_gpio_val_bank_and_pin(gc, offset, &bank); if (pin < 0) return pin; bank->config[pin] &= ~USBIO_GPIO_PINMOD_MASK; bank->config[pin] |= USBIO_GPIO_SET_PINMOD(USBIO_GPIO_PINMOD_INPUT); gbuf.bankid = offset / USBIO_GPIOSPERBANK; gbuf.config = bank->config[pin]; gbuf.pincount = 1; gbuf.pin = pin; return usbio_transfer(gpio->client, USBIO_GPIOCMD_INIT, &gbuf, sizeof(gbuf), NULL, 0); } static int usbio_gpio_get(struct gpio_chip *gc, unsigned int offset) { struct usbio_gpio *gpio = gpiochip_get_data(gc); struct usbio_gpio_bank *bank; struct usbio_gpio_rw gbuf; int pin, ret; pin = usbio_gpio_val_bank_and_pin(gc, offset, &bank); if (pin < 0) return pin; gbuf.bankid = offset / USBIO_GPIOSPERBANK; gbuf.pincount = 1; gbuf.pin = pin; ret = usbio_transfer(gpio->client, USBIO_GPIOCMD_READ, &gbuf, sizeof(gbuf) - sizeof(gbuf.value), &gbuf, sizeof(gbuf)); return ret == sizeof(gbuf.value) ? (gbuf.value >> pin) & 1 : -EINVAL; } #if KERNEL_VERSION(6, 17, 0) > LINUX_VERSION_CODE static void usbio_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) #else static int usbio_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) #endif { struct usbio_gpio *gpio = gpiochip_get_data(gc); struct usbio_gpio_bank *bank; struct usbio_gpio_rw gbuf; int pin; pin = usbio_gpio_val_bank_and_pin(gc, offset, &bank); if (pin < 0) #if KERNEL_VERSION(6, 17, 0) > LINUX_VERSION_CODE return; #else return -EINVAL; #endif gbuf.bankid = offset / USBIO_GPIOSPERBANK; gbuf.pincount = 1; gbuf.pin = pin; gbuf.value = value << pin; #if KERNEL_VERSION(6, 17, 0) > LINUX_VERSION_CODE usbio_transfer(gpio->client, USBIO_GPIOCMD_WRITE, &gbuf, sizeof(gbuf), NULL, 0); #else return usbio_transfer(gpio->client, USBIO_GPIOCMD_WRITE, &gbuf, sizeof(gbuf), NULL, 0); #endif } static int usbio_gpio_direction_output(struct gpio_chip *gc, unsigned int offset, int value) { struct usbio_gpio *gpio = gpiochip_get_data(gc); struct usbio_gpio_bank *bank; struct usbio_gpio_init gbuf; int pin, ret; pin = usbio_gpio_val_bank_and_pin(gc, offset, &bank); if (pin < 0) return pin; bank->config[pin] &= ~USBIO_GPIO_PINMOD_MASK; bank->config[pin] |= USBIO_GPIO_SET_PINMOD(USBIO_GPIO_PINMOD_OUTPUT); gbuf.bankid = offset / USBIO_GPIOSPERBANK; gbuf.config = bank->config[pin]; gbuf.pincount = 1; gbuf.pin = pin; ret = usbio_transfer(gpio->client, USBIO_GPIOCMD_INIT, &gbuf, sizeof(gbuf), NULL, 0); if (ret) return ret; #if KERNEL_VERSION(6, 17, 0) > LINUX_VERSION_CODE usbio_gpio_set(gc, offset, value); return 0; #else return usbio_gpio_set(gc, offset, value); #endif } static int usbio_gpio_set_config(struct gpio_chip *gc, unsigned int offset, unsigned long config) { struct usbio_gpio_bank *bank; int pin; u8 pincfg; pin = usbio_gpio_val_bank_and_pin(gc, offset, &bank); if (pin < 0) return pin; pincfg = USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_DEFAULT); switch (pinconf_to_config_param(config)) { case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: break; case PIN_CONFIG_BIAS_PULL_UP: pincfg |= USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_PULLUP); break; case PIN_CONFIG_BIAS_PULL_DOWN: pincfg |= USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_PULLDOWN); break; case PIN_CONFIG_DRIVE_PUSH_PULL: pincfg |= USBIO_GPIO_SET_PINCFG(USBIO_GPIO_PINCFG_PUSHPULL); break; default: return -ENOTSUPP; } bank->config[pin] = pincfg; return 0; } static int usbio_gpio_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *adev_id) { struct device *dev = &adev->dev; struct usbio_gpio *gpio; int ret; usbio_client_acpi_bind(adev, usbio_gpio_acpi_hids); gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL); if (!gpio) return -ENOMEM; gpio->client = auxiliary_get_usbio_client(adev); gpio->chip = dev_get_platdata(dev); gpio->gc.label = ACPI_COMPANION(dev) ? acpi_dev_name(ACPI_COMPANION(dev)) : dev_name(dev); gpio->gc.parent = dev; gpio->gc.owner = THIS_MODULE; gpio->gc.get_direction = usbio_gpio_get_direction; gpio->gc.direction_input = usbio_gpio_direction_input; gpio->gc.direction_output = usbio_gpio_direction_output; gpio->gc.get = usbio_gpio_get; gpio->gc.set = usbio_gpio_set; gpio->gc.set_config = usbio_gpio_set_config; gpio->gc.base = -1; gpio->gc.ngpio = gpio->chip->nbanks * USBIO_GPIOSPERBANK; gpio->gc.can_sleep = true; auxiliary_set_drvdata(adev, gpio); ret = gpiochip_add_data(&gpio->gc, gpio); if (ret) { devm_kfree(dev, gpio); return ret; } if (has_acpi_companion(dev)) acpi_dev_clear_dependencies(ACPI_COMPANION(dev)); return 0; } static void usbio_gpio_remove(struct auxiliary_device *adev) { struct device *dev = &adev->dev; struct usbio_gpio *gpio = auxiliary_get_drvdata(adev); gpiochip_remove(&gpio->gc); devm_kfree(dev, gpio); } static const struct auxiliary_device_id usbio_gpio_id_table[] = { { "usbio.usbio-gpio" }, { } }; MODULE_DEVICE_TABLE(auxiliary, usbio_gpio_id_table); static struct auxiliary_driver usbio_gpio_driver = { .name = USBIO_GPIO_CLIENT, .probe = usbio_gpio_probe, .remove = usbio_gpio_remove, .id_table = usbio_gpio_id_table }; module_auxiliary_driver(usbio_gpio_driver); MODULE_DESCRIPTION("Intel USBIO GPIO driver"); MODULE_AUTHOR("Israel Cepeda "); MODULE_LICENSE("GPL"); #if KERNEL_VERSION(6, 13, 0) > LINUX_VERSION_CODE MODULE_IMPORT_NS(USBIO); #else MODULE_IMPORT_NS("USBIO"); #endif usbio-drivers-0~git202510282139.ee221eca/drivers/i2c/000077500000000000000000000000001510075314600215005ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/drivers/i2c/busses/000077500000000000000000000000001510075314600230045ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/drivers/i2c/busses/i2c-usbio.c000066400000000000000000000127111510075314600247460ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2025 Intel Corporation. */ #include #include #include #include #include #include #include #include /** * struct usbio_i2c - represents usbio i2c bus * * @bus: usbio i2c bus reference * @adap: i2c adapter for the usbio i2c * @client: usbio client reference */ struct usbio_i2c { struct i2c_adapter adap; struct usbio_i2c_bus *bus; struct usbio_client *client; }; static const struct acpi_device_id usbio_i2c_acpi_hids[] = { { "INTC1008" }, /* MTL */ { "INTC10B3" }, /* ARL */ { "INTC10B6" }, /* LNL */ { "INTC10E3" }, /* PTL */ { } }; static void usbio_i2c_uninit(struct i2c_adapter *adap, struct i2c_msg *msg) { struct usbio_i2c *i2c = i2c_get_adapdata(adap); struct usbio_i2c_uninit ubuf; ubuf.busid = i2c->bus->id; ubuf.config = msg->addr; usbio_transfer(i2c->client, USBIO_I2CCMD_UNINIT, &ubuf, sizeof(ubuf), NULL, 0); } static int usbio_i2c_init(struct i2c_adapter *adap, struct i2c_msg *msg) { struct usbio_i2c *i2c = i2c_get_adapdata(adap); struct usbio_i2c_init ibuf; int ret; ibuf.busid = i2c->bus->id; ibuf.config = msg->addr; ibuf.speed = i2c->bus->speed; ret = usbio_transfer(i2c->client, USBIO_I2CCMD_INIT, &ibuf, sizeof(ibuf), &ibuf, sizeof(ibuf)); if (ret < 0) return ret; return ret == sizeof(ibuf) ? 0 : -EIO; } static int usbio_i2c_read(struct i2c_adapter *adap, struct i2c_msg *msg) { struct usbio_i2c *i2c = i2c_get_adapdata(adap); struct usbio_i2c_rw *rbuf; int ret; rbuf = kzalloc(sizeof(*rbuf) + msg->len, GFP_KERNEL); if (!rbuf) return -ENOMEM; rbuf->busid = i2c->bus->id; rbuf->config = msg->addr; rbuf->size = msg->len; ret = usbio_transfer(i2c->client, USBIO_I2CCMD_READ, rbuf, sizeof(*rbuf), rbuf, sizeof(*rbuf) + msg->len); if (ret < 0) goto exit; ret = ret == sizeof(*rbuf) + msg->len ? 0 : -EIO; if (ret) goto exit; memcpy(msg->buf, rbuf->data, msg->len); exit: kfree(rbuf); return ret; } static int usbio_i2c_write(struct i2c_adapter *adap, struct i2c_msg *msg) { struct usbio_i2c *i2c = i2c_get_adapdata(adap); struct usbio_i2c_rw *wbuf; int ret; wbuf = kzalloc(sizeof(*wbuf) + msg->len, GFP_KERNEL); if (!wbuf) return -ENOMEM; wbuf->busid = i2c->bus->id; wbuf->config = msg->addr; wbuf->size = msg->len; memcpy(wbuf->data, msg->buf, msg->len); ret = usbio_transfer(i2c->client, USBIO_I2CCMD_WRITE, wbuf, sizeof(*wbuf) + msg->len, wbuf, sizeof(*wbuf)); if (ret < 0) goto exit; ret = ret + wbuf->size == sizeof(*wbuf) + msg->len ? 0 : -EIO; exit: kfree(wbuf); return ret; } static int usbio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { int ret; ret = usbio_i2c_init(adap, msgs); if (ret) return ret; for (int i = 0; i < num; ret = ++i) { if (msgs[i].flags & I2C_M_RD) ret = usbio_i2c_read(adap, &msgs[i]); else ret = usbio_i2c_write(adap, &msgs[i]); if (ret) break; } usbio_i2c_uninit(adap, msgs); return ret; } static u32 usbio_i2c_func(struct i2c_adapter *adap) { return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SMBUS_EMUL; } static const struct i2c_adapter_quirks usbio_i2c_quirks = { .flags = I2C_AQ_NO_REP_START, .max_read_len = SZ_4K, .max_write_len = SZ_4K }; static const struct i2c_algorithm usbio_i2c_algo = { .master_xfer = usbio_i2c_xfer, .functionality = usbio_i2c_func }; static int usbio_i2c_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *adev_id) { struct device *dev = &adev->dev; struct usbio_i2c *i2c; u32 speed; int ret; usbio_client_acpi_bind(adev, usbio_i2c_acpi_hids); i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); if (!i2c) return -ENOMEM; i2c->client = auxiliary_get_usbio_client(adev); i2c->bus = dev_get_platdata(dev); speed = i2c_acpi_find_bus_speed(dev); if (speed && speed < i2c->bus->speed) /* Use requested bus speed */ i2c->bus->speed = speed; i2c->adap.owner = THIS_MODULE; i2c->adap.class = I2C_CLASS_HWMON; i2c->adap.dev.parent = dev; i2c->adap.algo = &usbio_i2c_algo; i2c->adap.quirks = &usbio_i2c_quirks; if (i2c->bus->quirks) /* Use USBIO bus specific quirks */ i2c->adap.quirks = i2c->bus->quirks; device_set_node(&i2c->adap.dev, dev_fwnode(dev)); snprintf(i2c->adap.name, sizeof(i2c->adap.name), "%s.%d", USBIO_I2C_CLIENT, i2c->bus->id); auxiliary_set_drvdata(adev, i2c); i2c_set_adapdata(&i2c->adap, i2c); ret = i2c_add_adapter(&i2c->adap); if (ret) { devm_kfree(dev, i2c); return ret; } if (has_acpi_companion(&i2c->adap.dev)) acpi_dev_clear_dependencies(ACPI_COMPANION(&i2c->adap.dev)); return 0; } static void usbio_i2c_remove(struct auxiliary_device *adev) { struct device *dev = &adev->dev; struct usbio_i2c *i2c = auxiliary_get_drvdata(adev); i2c_del_adapter(&i2c->adap); devm_kfree(dev, i2c); } static const struct auxiliary_device_id usbio_i2c_id_table[] = { { "usbio.usbio-i2c" }, { } }; MODULE_DEVICE_TABLE(auxiliary, usbio_i2c_id_table); static struct auxiliary_driver usbio_i2c_driver = { .name = USBIO_I2C_CLIENT, .probe = usbio_i2c_probe, .remove = usbio_i2c_remove, .id_table = usbio_i2c_id_table }; module_auxiliary_driver(usbio_i2c_driver); MODULE_DESCRIPTION("Intel USBIO I2C driver"); MODULE_AUTHOR("Israel Cepeda "); MODULE_LICENSE("GPL"); #if KERNEL_VERSION(6, 13, 0) > LINUX_VERSION_CODE MODULE_IMPORT_NS(USBIO); #else MODULE_IMPORT_NS("USBIO"); #endif usbio-drivers-0~git202510282139.ee221eca/drivers/usb/000077500000000000000000000000001510075314600216145ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/drivers/usb/misc/000077500000000000000000000000001510075314600225475ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/drivers/usb/misc/usbio.c000066400000000000000000000662161510075314600240470ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0 /* * Intel USBIO Bridge driver * * Copyright (c) 2025 Intel Corporation. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /************************************* * USBIO Bridge Protocol Definitions * *************************************/ /* USBIO Packet Type */ #define USBIO_PKTTYPE_CTRL 1 #define USBIO_PKTTYPE_DBG 2 #define USBIO_PKTTYPE_GPIO USBIO_GPIO #define USBIO_PKTTYPE_I2C USBIO_I2C /* USBIO Control Commands */ #define USBIO_CTRLCMD_PROTVER 0 #define USBIO_CTRLCMD_FWVER 1 #define USBIO_CTRLCMD_HS 2 #define USBIO_CTRLCMD_ENUMGPIO 16 #define USBIO_CTRLCMD_ENUMI2C 17 /* USBIO Packet Flags */ #define USBIO_PKTFLAG_ACK BIT(0) #define USBIO_PKTFLAG_RSP BIT(1) #define USBIO_PKTFLAG_CMP BIT(2) #define USBIO_PKTFLAG_ERR BIT(3) #define USBIO_PKTFLAGS_REQRESP (USBIO_PKTFLAG_CMP | USBIO_PKTFLAG_ACK) #define USBIO_PKTFLAGS_ISRSP (USBIO_PKTFLAG_CMP | USBIO_PKTFLAG_RSP) /* USBIO Packet Header */ struct usbio_packet_header { u8 type; u8 cmd; u8 flags; } __packed; #define USBIO_CTRLXFER_TIMEOUT 0 #define USBIO_BULKXFER_TIMEOUT 80 /* USBIO Control Transfer Packet */ struct usbio_ctrl_packet { struct usbio_packet_header header; u8 len; u8 data[] __counted_by(len); } __packed; /* USBIO Bulk Transfer Packet */ struct usbio_bulk_packet { struct usbio_packet_header header; u16 len; u8 data[] __counted_by(len); } __packed; struct usbio_protver { u8 ver; } __packed; struct usbio_fwver { u8 major; u8 minor; u16 patch; u16 build; } __packed; struct usbio_gpio_bank_desc { u8 id; u8 pins; u32 bmap; } __packed; #define USBIO_I2C_BUS_ADDR_CAP_10B BIT(3) /* 10bit address support */ #define USBIO_I2C_BUS_MODE_CAP_MASK 0x3 #define USBIO_I2C_BUS_MODE_CAP_SM 0 /* Standard Mode */ #define USBIO_I2C_BUS_MODE_CAP_FM 1 /* Fast Mode */ #define USBIO_I2C_BUS_MODE_CAP_FMP 2 /* Fast Mode+ */ #define USBIO_I2C_BUS_MODE_CAP_HSM 3 /* High-Speed Mode */ struct usbio_i2c_bus_desc { u8 id; u8 caps; } __packed; u32 usbio_i2c_speeds[] = { I2C_MAX_STANDARD_MODE_FREQ, I2C_MAX_FAST_MODE_FREQ, I2C_MAX_FAST_MODE_PLUS_FREQ, I2C_MAX_HIGH_SPEED_MODE_FREQ }; /*********************************** * USBIO Bridge Device Definitions * ***********************************/ struct usbio_dev_info { struct usbio_protver protver; struct usbio_fwver fwver; }; /********************************** * USBIO Firmware Quirks * **********************************/ #define USBIO_FWQUIRK_BULKSIZE BIT(0) /* Overwrite bulk size */ #define USBIO_FWQUIRK_NOTASYNC BIT(1) /* Sequential ctrl and bulk xfers */ #define USBIO_FWQUIRK_GPIOMAP BIT(8) /* Ignore FW GPIO Map */ #define USBIO_FWQUIRK_I2CNIACK BIT(16) /* I2C No Init ACK */ #define USBIO_FWQUIRK_I2CCHUNK BIT(17) /* Use I2C chunk transfers size */ #define USBIO_FWQUIRK_I2CADAPT BIT(18) /* Use FW specific adapter quirk */ struct usbio_fw_quirks { u32 quirks; u16 bulk_size; const struct i2c_adapter_quirks *i2c_quirks; }; /* Lattice NX40 FW quirks */ static struct usbio_fw_quirks lat_nx40_quirks = { .quirks = USBIO_FWQUIRK_BULKSIZE | USBIO_FWQUIRK_I2CCHUNK, .bulk_size = 62 }; /* Lattice NX33(U) I2C quirks */ static const struct i2c_adapter_quirks lat_nx33_i2c_quirks = { .flags = I2C_AQ_NO_REP_START, .max_read_len = 52, .max_write_len = 52 }; /* Lattice NX33 FW quirks */ static struct usbio_fw_quirks lat_nx33_quirks = { .quirks = USBIO_FWQUIRK_GPIOMAP | USBIO_FWQUIRK_BULKSIZE | USBIO_FWQUIRK_I2CCHUNK | USBIO_FWQUIRK_I2CADAPT | USBIO_FWQUIRK_I2CNIACK, .bulk_size = 62, .i2c_quirks = &lat_nx33_i2c_quirks }; /* Synaptics Sabre FW quirks */ static struct usbio_fw_quirks syn_sabre_quirks = { .quirks = USBIO_FWQUIRK_BULKSIZE | USBIO_FWQUIRK_I2CCHUNK, .bulk_size = 63 }; /** * struct usbio_device - the usb device exposing IOs * * @dev: the device in the usb interface * @udev: the detected usb device * @intf: the usb interface * @ctrl_pipe: the control transfer pipe * @ctrlbuf_len: the size of the control transfer pipe * @ctrlbuf: the buffer used for control transfers * @txpipe: the bulk out pipe * @txbuf_len: the size of the bulk out pipe * @txbuf: the buffer used for bulk out transfers * @urb: the urb to read bulk pipe * @rxpipe: the bulk in pipe * @rxbuf_len: the size of the bulk in pipe * @rxdat_len: the data length at rx buffer * @rxbuf: the buffer used for bulk in transfers * @info: the device's protocol and firmware information * @ctllock: protection against access concurrency for control transfers * @done: completion object as request is done * @blklock: protection against access concurrency for bulk transfers * @cli_list: device's client list * @nr_gpio_banks: the number of gpio banks * @gpios: the gpio banks array * @chip: the usbio gpio chip data * @nr_i2c_buses: the number of i2c buses * @i2cs: the i2c buses array * @i2cbus: the usbio i2c bus data * @fw_quirks: the usbio firmware quirks */ struct usbio_device { struct device *dev; struct usb_device *udev; struct usb_interface *intf; unsigned int ctrl_pipe; u16 ctrlbuf_len; void *ctrlbuf; unsigned int txpipe; u16 txbuf_len; void *txbuf; struct urb *urb; unsigned int rxpipe; u16 rxbuf_len; u16 rxdat_len; void *rxbuf; struct usbio_dev_info info; /* Control transfer concurrency lock */ struct mutex ctllock; struct completion done; /* Async Bulk transfer concurrency lock */ struct mutex blklock; /* Bulk transfer concurrency lock */ struct mutex *lock; struct list_head cli_list; unsigned int nr_gpio_banks; struct usbio_gpio_bank_desc gpios[USBIO_MAX_GPIOBANKS]; struct usbio_gpio_chip *chip; unsigned int nr_i2c_buses; struct usbio_i2c_bus_desc i2cs[USBIO_MAX_I2CBUSES]; struct usbio_i2c_bus *i2cbus; struct usbio_fw_quirks *fw_quirks; }; /** * struct usbio_match_ids_walk_data - used to find matching ACPI hids and uids * * @adev: store the matching acpi device * @hids: the list of acpi device ids to match * @id: the usbio client id to match */ struct usbio_match_ids_walk_data { struct acpi_device *adev; const struct acpi_device_id *hids; const u32 id; }; static int usbio_control_msg(struct usbio_device *usbio, struct usbio_packet_header *pkt, const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) { struct usbio_ctrl_packet *cpkt; unsigned int pipe; u16 cpkt_len = sizeof(*cpkt) + obuf_len; u8 request = USB_TYPE_VENDOR | USB_RECIP_DEVICE; int ret; ret = usb_autopm_get_interface(usbio->intf); if (ret) return ret; if (cpkt_len > usbio->ctrlbuf_len) { ret = -EMSGSIZE; goto exit; } /* Prepare Control Packet Header */ cpkt = usbio->ctrlbuf; cpkt->header.type = pkt->type; cpkt->header.cmd = pkt->cmd; cpkt->header.flags = pkt->flags; cpkt->len = obuf_len; /* Copy the data */ memcpy(cpkt->data, obuf, obuf_len); pipe = usb_sndctrlpipe(usbio->udev, usbio->ctrl_pipe); ret = usb_control_msg(usbio->udev, pipe, 0, request | USB_DIR_OUT, 0, 0, (void *)cpkt, cpkt_len, USBIO_CTRLXFER_TIMEOUT); if (ret < 0) { dev_err(usbio->dev, "Write CTRLXFER failed: %d", ret); goto exit; } /* Check for protocol error */ if (ret != cpkt_len) { ret = -EPROTO; goto exit; } if (pkt->flags & USBIO_PKTFLAG_ACK) { cpkt_len = sizeof(*cpkt) + ibuf_len; if (cpkt_len > usbio->ctrlbuf_len) { ret = -EMSGSIZE; goto exit; } pipe = usb_rcvctrlpipe(usbio->udev, usbio->ctrl_pipe); ret = usb_control_msg(usbio->udev, pipe, 0, request | USB_DIR_IN, 0, 0, (void *)cpkt, cpkt_len, USBIO_CTRLXFER_TIMEOUT); if (ret < 0) { dev_err(usbio->dev, "Read CTRLXFER failed: %d", ret); goto exit; } /* Check for protocol error */ if (ret < sizeof(*cpkt)) { ret = -EPROTO; goto exit; } /* Check for valid reply header */ if (cpkt->header.type == pkt->type && cpkt->header.cmd == pkt->cmd && cpkt->header.flags & USBIO_PKTFLAG_RSP) { /* Check the error flag */ if (cpkt->header.flags & USBIO_PKTFLAG_ERR) { ret = -EREMOTEIO; goto exit; } if (ibuf_len < cpkt->len) { ret = -ENOBUFS; goto exit; } /* Copy the data */ memcpy(ibuf, cpkt->data, cpkt->len); ret = cpkt->len; goto exit; } dev_err(usbio->dev, "Unexpected reply: %u:%u:%u", cpkt->header.type, cpkt->header.cmd, cpkt->header.flags); ret = -EPROTO; goto exit; } ret = cpkt_len - sizeof(*cpkt); exit: usb_autopm_put_interface(usbio->intf); return ret; } static void usbio_bulk_recv(struct urb *urb) { struct usbio_bulk_packet *bpkt = urb->transfer_buffer; struct usbio_device *usbio = urb->context; if (urb->status) { /* URB Error */ if (urb->status != -ENOENT) dev_err(usbio->dev, "URB status:%d", urb->status); goto exit; } /* Verify the received packet is a response */ if (bpkt->header.flags & USBIO_PKTFLAG_RSP) { usbio->rxdat_len = urb->actual_length; complete(&usbio->done); } exit: usb_submit_urb(usbio->urb, GFP_ATOMIC); } static int usbio_bulk_msg(struct usbio_device *usbio, struct usbio_packet_header *pkt, bool last, const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len, int timeout) { struct usbio_bulk_packet *bpkt; u16 bpkt_len = sizeof(*bpkt) + obuf_len; int ret, act; ret = usb_autopm_get_interface(usbio->intf); if (ret) return ret; if (bpkt_len > usbio->txbuf_len) { ret = -EMSGSIZE; goto exit; } if (ibuf_len) reinit_completion(&usbio->done); /* If no data to send, skip to read */ if (!obuf_len) goto read; /* Prepare Bulk Packet Header */ bpkt = (struct usbio_bulk_packet *)usbio->txbuf; bpkt->header.type = pkt->type; bpkt->header.cmd = pkt->cmd; bpkt->header.flags = last ? pkt->flags : 0; bpkt->len = obuf_len; /* Copy the data */ memcpy(bpkt->data, obuf, obuf_len); ret = usb_bulk_msg(usbio->udev, usbio->txpipe, (void *)bpkt, bpkt_len, &act, timeout); if (ret) { dev_err(usbio->dev, "Write Bulk transfer failed: %d", ret); goto exit; } /* Check for protocol error */ if (act != bpkt_len) { ret = -EPROTO; goto exit; } read: if (last && pkt->flags & USBIO_PKTFLAG_ACK) { bpkt_len = sizeof(*bpkt) + ibuf_len; if (bpkt_len > usbio->txbuf_len) { ret = -EMSGSIZE; goto exit; } ret = wait_for_completion_timeout(&usbio->done, timeout); if (!ret) { /* Timed out */ dev_err(usbio->dev, "Read Bulk transfer timed out: %d", timeout); ret = -ETIMEDOUT; goto exit; } act = usbio->rxdat_len; bpkt = (struct usbio_bulk_packet *)usbio->rxbuf; /* Check protocol error */ if (act < sizeof(*bpkt)) { ret = -EPROTO; goto exit; } /* Check for valid reply header */ if (bpkt->header.type == pkt->type && bpkt->header.cmd == pkt->cmd && bpkt->header.flags & USBIO_PKTFLAG_RSP) { /* Check the error flag */ if (bpkt->header.flags & USBIO_PKTFLAG_ERR) { ret = -EREMOTEIO; goto exit; } if (ibuf_len < bpkt->len) { ret = -ENOBUFS; goto exit; } /* Copy the data */ memcpy(ibuf, bpkt->data, bpkt->len); ret = bpkt->len; goto exit; } dev_err(usbio->dev, "Unexpected reply: %u:%u", bpkt->header.type, bpkt->header.cmd); ret = -EPROTO; goto exit; } ret = bpkt_len - sizeof(*bpkt); exit: usb_autopm_put_interface(usbio->intf); return ret; } static int usbio_ctrl_req(struct usbio_device *usbio, u8 cmd, void *ibuf, u8 len) { struct usbio_packet_header pkt = { USBIO_PKTTYPE_CTRL, cmd, USBIO_PKTFLAGS_REQRESP }; int ret; ret = usbio_control_msg(usbio, &pkt, NULL, 0, ibuf, len); if (ret < 0) return ret; if (ret != len) return -EPROTO; return 0; } static int usbio_match_device_ids(struct acpi_device *adev, void *data) { struct usbio_match_ids_walk_data *wd = data; char *uid; unsigned int id = 0; if (!acpi_match_device_ids(adev, wd->hids)) { uid = acpi_device_uid(adev); if (uid) for (int i = 0; i < strlen(uid); i++) if (!kstrtouint(&uid[i], 10, &id)) break; if (!uid || wd->id == id) { wd->adev = adev; return 1; } } return 0; } void usbio_client_acpi_bind(struct auxiliary_device *adev, const struct acpi_device_id *hids) { struct device *dev = &adev->dev; struct acpi_device *parent; struct usbio_match_ids_walk_data wd = { .adev = NULL, .hids = hids, .id = adev->id }; parent = ACPI_COMPANION(dev->parent); if (!parent) return; acpi_dev_for_each_child(parent, usbio_match_device_ids, &wd); if (wd.adev) ACPI_COMPANION_SET(dev, wd.adev); } #if KERNEL_VERSION(6, 13, 0) > LINUX_VERSION_CODE EXPORT_SYMBOL_NS_GPL(usbio_client_acpi_bind, USBIO); #else EXPORT_SYMBOL_NS_GPL(usbio_client_acpi_bind, "USBIO"); #endif static void usbio_auxdev_release(struct device *dev) { struct auxiliary_device *adev = to_auxiliary_dev(dev); struct usbio_client *client = auxiliary_get_usbio_client(adev); kfree(client); } static void usbio_add_client(struct usbio_device *usbio, char *name, u8 type, u8 id, void *data) { struct usbio_client *client; struct auxiliary_device *adev; int ret; client = kzalloc(sizeof(*client), GFP_KERNEL); if (!client) { ret = -ENOMEM; goto exit; } client->type = type; client->id = id; client->bridge = usbio; adev = &client->adev; adev->name = name; adev->id = id; adev->dev.parent = usbio->dev; adev->dev.platform_data = data; adev->dev.release = usbio_auxdev_release; ret = auxiliary_device_init(adev); if (ret) goto exit; ret = auxiliary_device_add(adev); if (ret) auxiliary_device_uninit(adev); exit: if (ret) { dev_warn(usbio->dev, "Client %s.%d add failed: %d", name, id, ret); kfree(client); return; } list_add_tail(&client->link, &usbio->cli_list); } static int usbio_ctrl_enumgpios(struct usbio_device *usbio) { struct usbio_packet_header pkt = { USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_ENUMGPIO, USBIO_PKTFLAGS_REQRESP }; struct usbio_gpio_bank_desc *gpio; int ret; gpio = usbio->gpios; ret = usbio_control_msg(usbio, &pkt, 0, 0, gpio, sizeof(usbio->gpios)); if (ret < 0 || ret % sizeof(*gpio)) { dev_err(usbio->dev, "CTRL ENUMGPIO failed: %d", ret); return ret; } usbio->nr_gpio_banks = ret / sizeof(*gpio); if (!usbio->nr_gpio_banks) return 0; if (usbio->nr_gpio_banks > USBIO_MAX_GPIOBANKS) { dev_warn(usbio->dev, "MAX GPIO banks: %u", USBIO_MAX_GPIOBANKS); usbio->nr_gpio_banks = USBIO_MAX_GPIOBANKS; } size_t size = sizeof(struct usbio_gpio_chip) + usbio->nr_gpio_banks * sizeof(struct usbio_gpio_bank); usbio->chip = kzalloc(size, GFP_KERNEL); if (!usbio->chip) return -ENOMEM; usbio->chip->nbanks = usbio->nr_gpio_banks; for (int i = 0; i < usbio->chip->nbanks; i++) if (usbio->fw_quirks && usbio->fw_quirks->quirks & USBIO_FWQUIRK_GPIOMAP) usbio->chip->banks[i].bitmap = ~0U; else usbio->chip->banks[i].bitmap = gpio[i].bmap; usbio_add_client(usbio, USBIO_GPIO_CLIENT, USBIO_GPIO, 0, usbio->chip); return 0; } static int usbio_ctrl_enumi2cs(struct usbio_device *usbio) { struct usbio_packet_header pkt = { USBIO_PKTTYPE_CTRL, USBIO_CTRLCMD_ENUMI2C, USBIO_PKTFLAGS_REQRESP }; struct usbio_i2c_bus_desc *i2c; int ret; i2c = usbio->i2cs; ret = usbio_control_msg(usbio, &pkt, 0, 0, i2c, sizeof(usbio->i2cs)); if (ret < 0 || ret % sizeof(*i2c)) { dev_err(usbio->dev, "CTRL ENUMI2C failed: %d", ret); return ret; } usbio->nr_i2c_buses = ret / sizeof(*i2c); if (!usbio->nr_i2c_buses) return 0; if (usbio->nr_i2c_buses > USBIO_MAX_I2CBUSES) { dev_warn(usbio->dev, "MAX I2C buses: %u", USBIO_MAX_I2CBUSES); usbio->nr_i2c_buses = USBIO_MAX_I2CBUSES; } size_t size = usbio->nr_i2c_buses * sizeof(struct usbio_i2c_bus); usbio->i2cbus = kzalloc(size, GFP_KERNEL); if (!usbio->i2cbus) return -ENOMEM; for (int i = 0; i < usbio->nr_i2c_buses; i++) { struct usbio_i2c_bus *bus = &usbio->i2cbus[i]; bus->id = i2c[i].id; bus->speed = usbio_i2c_speeds[i2c[i].caps & USBIO_I2C_BUS_MODE_CAP_MASK]; if (usbio->fw_quirks && usbio->fw_quirks->quirks & USBIO_FWQUIRK_I2CADAPT) bus->quirks = usbio->fw_quirks->i2c_quirks; usbio_add_client(usbio, USBIO_I2C_CLIENT, USBIO_I2C, bus->id, bus); } return 0; } static int usbio_gpio_handler(struct usbio_device *usbio, u8 cmd, const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) { const struct usbio_gpio_init *init = obuf; struct usbio_packet_header pkt = { USBIO_PKTTYPE_GPIO, cmd, ibuf_len ? USBIO_PKTFLAGS_REQRESP : USBIO_PKTFLAG_CMP }; int ret; if (!init || init->bankid > usbio->nr_gpio_banks) return -EINVAL; mutex_lock(&usbio->ctllock); ret = usbio_control_msg(usbio, &pkt, obuf, obuf_len, ibuf, ibuf_len); if (ret > 0) ret -= obuf_len; mutex_unlock(&usbio->ctllock); return ret; } #define I2C_RW_OVERHEAD (sizeof(struct usbio_bulk_packet) + \ sizeof(struct usbio_i2c_rw)) static int usbio_i2c_handler(struct usbio_device *usbio, u8 cmd, const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) { const struct usbio_i2c_init *init = obuf; struct usbio_packet_header pkt = { USBIO_PKTTYPE_I2C, cmd, ibuf_len ? USBIO_PKTFLAGS_REQRESP : USBIO_PKTFLAG_CMP }; int ret, timeout = USBIO_BULKXFER_TIMEOUT; if (!usbio->txpipe || !usbio->rxpipe) return -EPERM; if (!init || init->busid > usbio->nr_i2c_buses) return -EINVAL; u8 bid = init->busid; u16 len = 0; switch (cmd) { case USBIO_I2CCMD_INIT: if (usbio->fw_quirks && usbio->fw_quirks->quirks & USBIO_FWQUIRK_I2CNIACK) /* No ACK for I2C Init */ pkt.flags = USBIO_PKTFLAG_CMP; break; case USBIO_I2CCMD_WRITE: const struct usbio_i2c_rw *i2cwr = obuf; u16 txchunk = usbio->txbuf_len - I2C_RW_OVERHEAD; u16 wsize = i2cwr->size; if (wsize <= txchunk) { timeout += DIV_ROUND_UP(wsize * 1000, usbio->i2cbus[bid].speed); break; } /* Need to split the output buffer */ struct usbio_i2c_rw *wr; wr = kzalloc(sizeof(*wr) + txchunk, GFP_KERNEL); if (!wr) return -ENOMEM; /* Copy the header */ memcpy(wr, i2cwr, sizeof(*wr)); mutex_lock(usbio->lock); do { if (usbio->fw_quirks && usbio->fw_quirks->quirks & USBIO_FWQUIRK_I2CCHUNK) wr->size = txchunk; /* Copy the data chunk */ memcpy(wr->data, &i2cwr->data[len], txchunk); len += txchunk; timeout = USBIO_BULKXFER_TIMEOUT + DIV_ROUND_UP(txchunk * 1000, usbio->i2cbus[bid].speed); ret = usbio_bulk_msg(usbio, &pkt, wsize == len, wr, sizeof(*wr) + txchunk, ibuf, ibuf_len, timeout); if (ret < 0) break; if (wsize - len < txchunk) txchunk = wsize - len; } while (wsize > len); mutex_unlock(usbio->lock); if (usbio->fw_quirks && usbio->fw_quirks->quirks & USBIO_FWQUIRK_I2CCHUNK) ((struct usbio_i2c_rw *)ibuf)->size = len; kfree(wr); return ret; case USBIO_I2CCMD_READ: struct usbio_i2c_rw *i2crd = ibuf; u16 rxchunk = usbio->rxbuf_len - I2C_RW_OVERHEAD; u16 rsize = i2crd->size; if (rsize <= rxchunk) { timeout += DIV_ROUND_UP(rsize * 1000, usbio->i2cbus[bid].speed); break; } /* Need to split the input buffer */ struct usbio_i2c_rw *rd; rd = kzalloc(sizeof(*rd) + rxchunk, GFP_KERNEL); if (!rd) return -ENOMEM; mutex_lock(usbio->lock); do { if (rsize - len < rxchunk) rxchunk = rsize - len; timeout = USBIO_BULKXFER_TIMEOUT + DIV_ROUND_UP(rxchunk * 1000, usbio->i2cbus[bid].speed); ret = usbio_bulk_msg(usbio, &pkt, true, obuf, len == 0 ? obuf_len : 0, rd, sizeof(*rd) + rxchunk, timeout); if (ret < 0) break; memcpy(&i2crd->data[len], rd->data, rxchunk); len += rxchunk; } while (rsize > len); mutex_unlock(usbio->lock); if (rsize == len) i2crd->size = rd->size; kfree(rd); return ret < 0 ? ret : sizeof(*i2crd) + i2crd->size; } mutex_lock(usbio->lock); ret = usbio_bulk_msg(usbio, &pkt, true, obuf, obuf_len, ibuf, ibuf_len, timeout); mutex_unlock(usbio->lock); return ret; } int usbio_transfer(struct usbio_client *client, u8 cmd, const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len) { struct usbio_device *usbio; int ret = -EINVAL; if (!client || (!obuf && obuf_len) || (!ibuf && ibuf_len)) return ret; if (!client->bridge) return -ENODEV; usbio = client->bridge; switch (client->type) { case USBIO_GPIO: if (usbio_gpiocmd_valid(cmd)) ret = usbio_gpio_handler(usbio, cmd, obuf, obuf_len, ibuf, ibuf_len); break; case USBIO_I2C: if (usbio_i2ccmd_valid(cmd)) { ret = usbio_i2c_handler(usbio, cmd, obuf, obuf_len, ibuf, ibuf_len); if (ret == -EREMOTEIO) /* Didn't respond */ return -ENXIO; } break; } return ret; } #if KERNEL_VERSION(6, 13, 0) > LINUX_VERSION_CODE EXPORT_SYMBOL_NS_GPL(usbio_transfer, USBIO); #else EXPORT_SYMBOL_NS_GPL(usbio_transfer, "USBIO"); #endif static ssize_t usbio_devinfo_show(struct device *dev, struct device_attribute *attr, char *buf) { struct usbio_device *usbio = dev_get_drvdata(dev); struct usbio_fwver *fwver = &usbio->info.fwver; struct usbio_protver *protver = &usbio->info.protver; struct usbio_gpio_bank_desc *gpio = usbio->gpios; struct usbio_i2c_bus_desc *i2c = usbio->i2cs; unsigned int i; int len; /* Firmware and Protocol Version */ len = sysfs_emit(buf, "Firmware Version: %u.%u.%u.%u\n" "Protocol Version(BCD): %02x\n", fwver->major, fwver->minor, fwver->patch, fwver->build, protver->ver); /* GPIO Banks */ len += sysfs_emit_at(buf, len, "GPIO Banks: %u\n", usbio->nr_gpio_banks); for (i = 0; i < usbio->nr_gpio_banks; i++) { len += sysfs_emit_at(buf, len, "\tBank%u[%u] map: %#08x\n", gpio[i].id, gpio[i].pins, gpio[i].bmap); } /* I2C Buses */ len += sysfs_emit_at(buf, len, "I2C Buses: %u\n", usbio->nr_i2c_buses); for (i = 0; i < usbio->nr_i2c_buses; i++) { len += sysfs_emit_at(buf, len, "\tBus%u caps: %#02x\n", i2c[i].id, i2c[i].caps); } /* FW Quirks */ if (usbio->fw_quirks) { len += sysfs_emit_at(buf, len, "FW Quirks: %#04x\n", usbio->fw_quirks->quirks); } return len; } static DEVICE_ATTR_RO(usbio_devinfo); static int usbio_suspend(struct usb_interface *intf, pm_message_t msg) { struct usbio_device *usbio = usb_get_intfdata(intf); usb_kill_urb(usbio->urb); return 0; } static int usbio_resume(struct usb_interface *intf) { struct usbio_device *usbio = usb_get_intfdata(intf); return usb_submit_urb(usbio->urb, GFP_KERNEL); } static void usbio_disconnect(struct usb_interface *intf) { struct device *dev = &intf->dev; struct usbio_device *usbio = usb_get_intfdata(intf); struct usbio_client *cli, *prev; device_remove_file(dev, &dev_attr_usbio_devinfo); usb_kill_urb(usbio->urb); list_for_each_entry_safe_reverse(cli, prev, &usbio->cli_list, link) { /* Remove bridge from client */ cli->bridge = NULL; /* Remove client from the list */ list_del_init(&cli->link); /* Remove auxiliary device */ auxiliary_device_delete(&cli->adev); auxiliary_device_uninit(&cli->adev); } usb_free_urb(usbio->urb); kfree(usbio->i2cbus); kfree(usbio->chip); kfree(usbio->ctrlbuf); kfree(usbio->txbuf); kfree(usbio->rxbuf); mutex_destroy(&usbio->ctllock); mutex_destroy(&usbio->blklock); usb_set_intfdata(intf, NULL); usb_put_intf(intf); devm_kfree(dev, usbio); } static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(intf); struct usb_endpoint_descriptor *epin, *epout; struct device *dev = &intf->dev; struct usbio_device *usbio; int ret = -ENOMEM; usbio = devm_kzalloc(dev, sizeof(*usbio), GFP_KERNEL); if (!usbio) return ret; usbio->dev = dev; usbio->udev = udev; usbio->intf = usb_get_intf(intf); usb_set_intfdata(intf, usbio); mutex_init(&usbio->ctllock); mutex_init(&usbio->blklock); usbio->lock = &usbio->blklock; init_completion(&usbio->done); INIT_LIST_HEAD(&usbio->cli_list); if (id->driver_info) { /* Get firmware quirks */ usbio->fw_quirks = (struct usbio_fw_quirks *)id->driver_info; /* USBIO is designed to work using control and bulk transfers * asynchronously. Unfortunately there are some devices that * can't handle it. Hence the need to use the same mutex to * avoid concurrency issues */ if (usbio->fw_quirks->quirks & USBIO_FWQUIRK_NOTASYNC) /* Use control transfer mutex */ usbio->lock = &usbio->ctllock; } usbio->ctrl_pipe = usb_endpoint_num(&udev->ep0.desc); usbio->ctrlbuf_len = usb_maxpacket(udev, usbio->ctrl_pipe); usbio->ctrlbuf = kzalloc(usbio->ctrlbuf_len, GFP_KERNEL); if (!usbio->ctrlbuf) goto error; /* Find the first bulk-in and bulk-out endpoints */ if (usb_find_common_endpoints(intf->cur_altsetting, &epin, &epout, NULL, NULL)) { dev_warn(dev, "Couldn't find bulk-in and bulk-out endpoints"); goto no_bulk; } usbio->txpipe = usb_sndbulkpipe(udev, usb_endpoint_num(epout)); usbio->txbuf_len = usb_endpoint_maxp(epout); usbio->txbuf = kzalloc(usbio->txbuf_len, GFP_KERNEL); if (!usbio->txbuf) goto error; usbio->rxpipe = usb_rcvbulkpipe(udev, usb_endpoint_num(epin)); usbio->rxbuf_len = usb_endpoint_maxp(epin); usbio->rxbuf = kzalloc(usbio->rxbuf_len, GFP_KERNEL); if (!usbio->rxbuf) goto error; usbio->urb = usb_alloc_urb(0, GFP_KERNEL); if (!usbio->urb) goto error; if (usbio->fw_quirks && usbio->fw_quirks->quirks & USBIO_FWQUIRK_BULKSIZE) { /* Use the bulk size from the quirks */ usbio->rxbuf_len = usbio->fw_quirks->bulk_size; usbio->txbuf_len = usbio->fw_quirks->bulk_size; } usb_fill_bulk_urb(usbio->urb, udev, usbio->rxpipe, usbio->rxbuf, usbio->rxbuf_len, usbio_bulk_recv, usbio); ret = usb_submit_urb(usbio->urb, GFP_KERNEL); if (ret) { dev_err(dev, "Failed to submit usb urb"); goto error; } no_bulk: /* Init USBIO device */ ret = usbio_ctrl_req(usbio, USBIO_CTRLCMD_HS, NULL, 0); if (ret) goto error; /* Get protocol version */ ret = usbio_ctrl_req(usbio, USBIO_CTRLCMD_PROTVER, &usbio->info.protver, sizeof(usbio->info.protver)); if (ret) goto error; /* Get firmware version */ ret = usbio_ctrl_req(usbio, USBIO_CTRLCMD_FWVER, &usbio->info.fwver, sizeof(usbio->info.fwver)); if (ret) goto error; /* Enumerate IOs */ ret = usbio_ctrl_enumgpios(usbio); if (ret) goto error; ret = usbio_ctrl_enumi2cs(usbio); if (ret) goto error; dev_set_drvdata(dev, usbio); device_create_file(dev, &dev_attr_usbio_devinfo); return 0; error: usbio_disconnect(intf); return ret; } static const struct usb_device_id usbio_table[] = { { USB_DEVICE(0x2AC1, 0x20C1), /* Lattice NX40 */ .driver_info = (unsigned long)&lat_nx40_quirks }, { USB_DEVICE(0x2AC1, 0x20C9), /* Lattice NX33 */ .driver_info = (unsigned long)&lat_nx33_quirks }, { USB_DEVICE(0x2AC1, 0x20CB) , /* Lattice NX33U */ .driver_info = (unsigned long)&lat_nx33_quirks }, { USB_DEVICE(0x06CB, 0x0701), /* Synaptics Sabre */ .driver_info = (unsigned long)&syn_sabre_quirks }, { } }; MODULE_DEVICE_TABLE(usb, usbio_table); static struct usb_driver usbio_driver = { .name = "usbio-bridge", .probe = usbio_probe, .disconnect = usbio_disconnect, .suspend = usbio_suspend, .resume = usbio_resume, .id_table = usbio_table, .supports_autosuspend = 1 }; module_usb_driver(usbio_driver); MODULE_DESCRIPTION("Intel USBIO Bridge driver"); MODULE_AUTHOR("Israel Cepeda "); MODULE_LICENSE("GPL"); usbio-drivers-0~git202510282139.ee221eca/include/000077500000000000000000000000001510075314600207705ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/include/linux/000077500000000000000000000000001510075314600221275ustar00rootroot00000000000000usbio-drivers-0~git202510282139.ee221eca/include/linux/usbio.h000066400000000000000000000063301510075314600234230ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2025 Intel Corporation. * */ #ifndef _LINUX_USBIO_H_ #define _LINUX_USBIO_H_ #include #include #include #define auxiliary_get_usbio_client(auxdev) \ container_of(auxdev, struct usbio_client, adev) struct usbio_device; /** * struct usbio_client - represents a usbio client * * @type: client type * @id: client id * @auxdev: auxiliary device object * @bridge: usbio bridge who service the client * @link: usbio bridge clients */ struct usbio_client { u8 type; u8 id; struct auxiliary_device adev; struct usbio_device *bridge; struct list_head link; }; /*********************** * USBIO Clients Names * ***********************/ #define USBIO_GPIO_CLIENT "usbio-gpio" #define USBIO_I2C_CLIENT "usbio-i2c" /************************** * USBIO Type Definitions * **************************/ /* 0-2 Reserved/NA */ #define USBIO_GPIO 3 #define USBIO_I2C 4 /* USBIO GPIO commands */ enum usbio_gpio_cmd { USBIO_GPIOCMD_DEINIT, USBIO_GPIOCMD_INIT, USBIO_GPIOCMD_READ, USBIO_GPIOCMD_WRITE, USBIO_GPIOCMD_END }; static inline bool usbio_gpiocmd_valid(u8 cmd) { return cmd >= USBIO_GPIOCMD_DEINIT && cmd < USBIO_GPIOCMD_END; } /* USBIO GPIO config */ enum usbio_gpio_pincfg { USBIO_GPIO_PINCFG_DEFAULT, USBIO_GPIO_PINCFG_PULLUP, USBIO_GPIO_PINCFG_PULLDOWN, USBIO_GPIO_PINCFG_PUSHPULL }; #define USBIO_GPIO_PINCFG_SHIFT 2 #define USBIO_GPIO_PINCFG_MASK (0x3 << USBIO_GPIO_PINCFG_SHIFT) #define USBIO_GPIO_SET_PINCFG(pin) \ (((pin) << USBIO_GPIO_PINCFG_SHIFT) & USBIO_GPIO_PINCFG_MASK) enum usbio_gpio_pinmode { USBIO_GPIO_PINMOD_INVAL, USBIO_GPIO_PINMOD_INPUT, USBIO_GPIO_PINMOD_OUTPUT, USBIO_GPIO_PINMOD_MAXVAL }; #define USBIO_GPIO_PINMOD_MASK 0x3 #define USBIO_GPIO_SET_PINMOD(pin) ((pin) & USBIO_GPIO_PINMOD_MASK) /************************* * USBIO GPIO Controller * *************************/ #define USBIO_MAX_GPIOBANKS 5 #define USBIO_GPIOSPERBANK 32 struct usbio_gpio_bank { u8 config[USBIO_GPIOSPERBANK]; u32 bitmap; }; struct usbio_gpio_chip { int nbanks; struct usbio_gpio_bank banks[] __counted_by(nbanks); }; struct usbio_gpio_init { u8 bankid; u8 config; u8 pincount; u8 pin; } __packed; struct usbio_gpio_rw { u8 bankid; u8 pincount; u8 pin; u32 value; } __packed; /* USBIO I2C commands */ enum usbio_i2c_cmd { USBIO_I2CCMD_UNINIT, USBIO_I2CCMD_INIT, USBIO_I2CCMD_READ, USBIO_I2CCMD_WRITE, USBIO_I2CCMD_END }; static inline bool usbio_i2ccmd_valid(u8 cmd) { return cmd >= USBIO_I2CCMD_UNINIT && cmd < USBIO_I2CCMD_END; } /************************ * USBIO I2C Controller * ************************/ #define USBIO_MAX_I2CBUSES 5 struct usbio_i2c_bus { u8 id; u32 speed; const struct i2c_adapter_quirks *quirks; } __packed; struct usbio_i2c_uninit { u8 busid; u16 config; } __packed; struct usbio_i2c_init { u8 busid; u16 config; u32 speed; } __packed; struct usbio_i2c_rw { u8 busid; u16 config; u16 size; u8 data[] __counted_by(size); } __packed; void usbio_client_acpi_bind(struct auxiliary_device *adev, const struct acpi_device_id *hids); int usbio_transfer(struct usbio_client *client, u8 cmd, const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len); #endif