pax_global_header00006660000000000000000000000064147644714210014524gustar00rootroot0000000000000052 comment=feab312cc9cbaa2d5066978e2bbfed8eb6450905 vision-drivers-0~git202503130554.feab312c/000077500000000000000000000000001476447142100175355ustar00rootroot00000000000000vision-drivers-0~git202503130554.feab312c/CODE_OF_CONDUCT.md000066400000000000000000000124761476447142100223460ustar00rootroot00000000000000# Contributor Covenant Code of Conduct ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at CommunityCodeOfConduct AT intel DOT com. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html [Mozilla CoC]: https://github.com/mozilla/diversity [FAQ]: https://www.contributor-covenant.org/faq vision-drivers-0~git202503130554.feab312c/CONTRIBUTING.md000066400000000000000000000043711476447142100217730ustar00rootroot00000000000000# Contributing ### License is licensed under the terms in [LICENSE]. 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`. vision-drivers-0~git202503130554.feab312c/LICENSE.txt000066400000000000000000000432541476447142100213700ustar00rootroot00000000000000 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. vision-drivers-0~git202503130554.feab312c/Makefile000066400000000000000000000010021476447142100211660ustar00rootroot00000000000000# SPDX-License-Identifier: GPL-2.0-only # Copyright (c) 2024 Intel Corporation. obj-m += intel_cvs.o intel_cvs-y := drivers/misc/icvs/intel_cvs.o drivers/misc/icvs/intel_cvs_update.o KERNELRELEASE ?= $(shell uname -r) KERNEL_SRC ?= /lib/modules/$(KERNELRELEASE)/build PWD := $(shell pwd) ccflags-y += -I$(src)/include/ all: $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules modules_install: $(MAKE) INSTALL_MOD_DIR=/updates -C $(KERNEL_SRC) M=$(PWD) modules_install clean: $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean vision-drivers-0~git202503130554.feab312c/README.md000066400000000000000000000023241476447142100210150ustar00rootroot00000000000000# Intel Vision Driver This repository supports Intel Vision Driver on Intel Lunar Lake (LNL) CVS-enabled Platforms ## Dependencies * Intel LNL platform BIOS and CVS device * Linux kernel v6.7-rc8 or later * Intel LJCA USB driver, adding LNL GPIO PID (INTC10B5) support ## Build instructions Ways to build the USBIO drivers 1. build out of kernel source tree 2. build with dkms 3. build with kernel source tree aren't supported yet Build was tested on Ubuntu 22.04 LNL CVS platform running kernel v6.7-rc8 ### Build out of kernel source tree * Prerequisite: 6.7-rc8 (or later) kernel with ```ljca``` and ```gpio_ljca``` module/driver loaded, header and build packages, to install required package ``` $ sudo apt-get install build-essential ``` To compile the Intel Vision driver: ``` $ cd vision-drivers $ make ``` ### Check LJCA drivers are loaded before vision driver can be installed ``` $ lsmod | grep -e ljca -e gpio_ljca ``` ### Installing the vision driver ``` $ sudo insmod intel_cvs.ko ``` ### Uninstall the vision driver ``` $ sudo rmmod intel_cvs ``` ### Build with dkms a dkms.conf file is also provided as an example for building with dkms which can be used by ```dkms add, build and install```. vision-drivers-0~git202503130554.feab312c/dkms.conf000066400000000000000000000004321476447142100213410ustar00rootroot00000000000000PACKAGE_NAME="vision-driver" PACKAGE_VERSION="1.0.0" MAKE="make KERNELRELEASE=$kernelver KERNEL_SRC=$kernel_source_dir" CLEAN="make KERNELRELEASE=$kernelver KERNEL_SRC=$kernel_source_dir clean" BUILT_MODULE_NAME[0]="intel_cvs" DEST_MODULE_LOCATION[0]="/updates" AUTOINSTALL="yes"vision-drivers-0~git202503130554.feab312c/drivers/000077500000000000000000000000001476447142100212135ustar00rootroot00000000000000vision-drivers-0~git202503130554.feab312c/drivers/misc/000077500000000000000000000000001476447142100221465ustar00rootroot00000000000000vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/000077500000000000000000000000001476447142100231125ustar00rootroot00000000000000vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/Kconfig000066400000000000000000000003771476447142100244240ustar00rootroot00000000000000# SPDX-License-Identifier: GPL-2.0-only # Copyright (c) 2024 Intel Corporation. config INTEL_CVS tristate "Intel CVS" depends on CONFIG_ACPI depends on CONFIG_GPIOLIB depends on CONFIG_I2C help Add support of Intel Computer Vision System (ICVS). vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/Makefile000066400000000000000000000002461476447142100245540ustar00rootroot00000000000000# SPDX-License-Identifier: GPL-2.0-only # Copyright (c) 2024 Intel Corporation. obj-$(CONFIG_INTEL_CVS) += intel_cvs.o obj-$(CONFIG_INTEL_CVS) += intel_cvs_update.o vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/cvs_gpio.h000066400000000000000000000017171476447142100251020ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only */ /* * * Copyright (C) 2024 Intel Corporation. * */ #ifndef __CVS_GPIO_H__ #define __CVS_GPIO_H__ #include /* GPIO Full Resources */ static const struct acpi_gpio_params gpio_wake = { 0, 0, false }; static const struct acpi_gpio_params gpio_rst = { 1, 0, false }; static const struct acpi_gpio_params gpio_req = { 2, 0, false }; static const struct acpi_gpio_params gpio_resp = { 3, 0, false }; static const struct acpi_gpio_mapping icvs_acpi_gpios[] = { { "wake-gpio", &gpio_wake, 1 }, { "rst-gpio", &gpio_rst, 1 }, { "req-gpio", &gpio_req, 1 }, { "resp-gpio", &gpio_resp, 1 }, {} }; /* GPIO Light Resources */ static const struct acpi_gpio_params lgpio_req = { 0, 0, false }; static const struct acpi_gpio_params lgpio_resp = { 1, 0, false }; static const struct acpi_gpio_mapping icvs_acpi_lgpios[] = { { "req-gpio", &lgpio_req, 1 }, { "resp-gpio", &lgpio_resp, 1 }, {} }; #endif // __CVS_GPIO_H__ vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/intel_cvs.c000066400000000000000000000437671476447142100252650ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-only /* * * Copyright (C) 2024 Intel Corporation. * */ #include #include #include #include #include #include #include #include "cvs_gpio.h" #include "intel_cvs_update.h" struct intel_cvs *cvs; static irqreturn_t cvs_irq_handler(int irq, void *devid) { struct intel_cvs *icvs = devid; icvs->hostwake_event_arg = 1; wake_up_interruptible(&icvs->hostwake_event); return IRQ_RETVAL(true); } static int cvs_init(struct intel_cvs *icvs) { int ret = -EINVAL; if (!icvs || !icvs->dev || !icvs->rst) return -EINVAL; ret = devm_request_irq(icvs->dev, icvs->irq, cvs_irq_handler, IRQF_ONESHOT | IRQF_NO_SUSPEND, dev_name(icvs->dev), icvs); if (ret) dev_err(icvs->dev, "Failed to request irq"); return ret; } static int find_oem_prod_id(acpi_handle handle, const char *method_name, unsigned long long *value) { acpi_status status; status = acpi_evaluate_integer(handle, (acpi_string)method_name, NULL, value); if (ACPI_FAILURE(status)) { dev_err(cvs->dev, "%s: ACPI method %s not found", __func__, method_name); return status; } dev_info(cvs->dev, "%s: ACPI method %s returned oem_prod_id:0x%llx", __func__, method_name, *value); return 0; } static int cvs_i2c_probe(struct i2c_client *i2c) { struct intel_cvs *icvs; acpi_handle handle; int ret = -ENODEV; if (!i2c) { pr_err("No I2C device"); return -ENODEV; } dev_info(&i2c->dev, "%s with i2c_client:%p\n", __func__, i2c); icvs = devm_kzalloc(&i2c->dev, sizeof(struct intel_cvs), GFP_KERNEL); if (!icvs) return -ENOMEM; icvs->dev = &i2c->dev; i2c_set_clientdata(i2c, icvs); cvs = icvs; ret = gpiod_count(icvs->dev, NULL); switch (ret) { case ICVS_LIGHT: icvs->cap = ICVS_LIGHTCAP; break; case ICVS_FULL: icvs->cap = ICVS_FULLCAP; break; default: dev_err(icvs->dev, "Number of GPIOs not supported: %d", ret); ret = -EINVAL; goto exit; } ret = devm_acpi_dev_add_driver_gpios(icvs->dev, icvs->cap == ICVS_FULLCAP ? icvs_acpi_gpios : icvs_acpi_lgpios); if (ret) { dev_err(icvs->dev, "Failed to add driver gpios"); goto exit; } /* Request GPIO */ icvs->req = devm_gpiod_get(icvs->dev, "req", GPIOD_OUT_HIGH); if (IS_ERR(icvs->req)) { dev_err(icvs->dev, "Get request gpiod failed. Do deferred probing"); return dev_err_probe(icvs->dev, -EPROBE_DEFER, "Do deferred probing as request gpiod failed"); } /* Response GPIO */ icvs->resp = devm_gpiod_get(icvs->dev, "resp", GPIOD_IN); if (IS_ERR(icvs->resp)) { dev_err(icvs->dev, "Get response gpiod failed. Do deferred probing"); return dev_err_probe(icvs->dev, -EPROBE_DEFER, "Do deferred probing as response gpiod failed"); } if (icvs->cap == ICVS_FULLCAP) { /* Reset GPIO */ icvs->rst = devm_gpiod_get(icvs->dev, "rst", GPIOD_OUT_HIGH); if (IS_ERR(icvs->rst)) { dev_err(icvs->dev, "Get reset gpiod failed. Do deferred probing"); return dev_err_probe(icvs->dev, -EPROBE_DEFER, "Do deferred probing as reset gpiod failed"); } /* Wake Interrupt */ ret = acpi_dev_gpio_irq_get_by(ACPI_COMPANION(icvs->dev), "wake-gpio", 0); if (ret > 0) { icvs->irq = ret; } else { dev_err(icvs->dev, "Failed to get right wake interrupt:%d", ret); ret = -EINVAL; goto exit; } INIT_WORK(&icvs->fw_dl_task, cvs_fw_dl_thread); init_waitqueue_head(&icvs->hostwake_event); init_waitqueue_head(&icvs->update_complete_event); init_waitqueue_head(&icvs->lvfs_fwdl_complete_event); icvs->fw_dl_task_finished = false; ret = cvs_init(icvs); if (ret) dev_err(icvs->dev, "Failed to initialize\n"); find_oem_prod_id(handle, "OPID", &icvs->oem_prod_id); } mdelay(FW_PREPARE_MS); ret = cvs_acquire_camera_sensor_internal(); if (ret) { dev_err(cvs->dev, "%s:Acquire sensor fail", __func__); goto exit; } else { dev_info(cvs->dev, "%s:Transfer of ownership success", __func__); } icvs->icvs_sensor_state = CV_SENSOR_VISION_ACQUIRED_STATE; ret = cvs_get_device_cap(&icvs->cv_fw_capability); if (ret) goto exit; ret = cvs_write_i2c(SET_HOST_IDENTIFIER, NULL, 0); if (ret) { dev_err(cvs->dev, "%s:set_host_identifier cmd failed", __func__); goto exit; } acpi_dev_clear_dependencies(ACPI_COMPANION(icvs->dev)); exit: if (ret) devm_kfree(icvs->dev, icvs); return ret; } static void cvs_exit(struct intel_cvs *icvs) { if (icvs && icvs->dev && icvs->rst) devm_free_irq(icvs->dev, icvs->irq, icvs); } static void cvs_i2c_remove(struct i2c_client *i2c) { struct intel_cvs *icvs; dev_info(&i2c->dev, "%s\n", __func__); icvs = i2c_get_clientdata(i2c); if (icvs) { cvs->close_fw_dl_task = true; if (icvs->cap == ICVS_FULLCAP) { if (cvs->fw_dl_task_started && !cvs->fw_dl_task_finished) { dev_info(cvs->dev, "%s:signal cvs_fw_dl_thread() to stop", __func__); cvs->hostwake_event_arg = 1; wake_up_interruptible(&cvs->hostwake_event); dev_info(cvs->dev, "%s:Wait for cvs_fw_dl_thread() to stop", __func__); wait_event_interruptible(cvs->update_complete_event, cvs->update_complete_event_arg == 1); dev_info(cvs->dev, "%s:cvs_fw_dl_thread() stopped", __func__); mdelay(WAIT_HOST_RELEASE_MS); } cvs_exit(icvs); } devm_kfree(&i2c->dev, icvs); } } int cvs_read_i2c(u16 cmd, char *data, int size) { struct intel_cvs *ctx = cvs; struct i2c_client *i2c = container_of(cvs->dev, struct i2c_client, dev); int cnt; char *in_data; in_data = devm_kzalloc(ctx->dev, (CVMAGICNUMSIZE + size), GFP_KERNEL); if (!in_data) { dev_err(cvs->dev, "%s:Buffer allocation failed", __func__); return -ENOMEM; } u16 cvs_cmd = (((cmd) >> 8) & 0x00ff) | (((cmd) << 8) & 0xff00); if (size < 0 || !data) return -EINVAL; cnt = i2c_master_send(i2c, (const char *)&cvs_cmd, sizeof(u16)); if (cnt != sizeof(u16)) { dev_err(&i2c->dev, "%s:cmd:%x count:%d (!=2)\n", __func__, cmd, cnt); return -EIO; } if (ctx->magic_num_support) { u32 magic_num_received; cnt = i2c_master_recv(i2c, in_data, size + CVMAGICNUMSIZE); magic_num_received = ((u32 *)in_data)[0]; if (magic_num_received == CVMAGICNUM) { dev_dbg(&i2c->dev, "%s:Valid magic number", __func__); memcpy(data, in_data + CVMAGICNUMSIZE, size); } else { dev_dbg(&i2c->dev, "%s:Invalid magic number", __func__); return -EIO; } } else { cnt = i2c_master_recv(i2c, (char *)data, size); } return cnt; } int cvs_acquire_camera_sensor_internal(void) { int val, retry = 20; if (!cvs) return -EINVAL; if (cvs->icvs_state == CV_FW_DOWNLOADING_STATE || cvs->icvs_state == CV_FW_FLASHING_STATE) return -EBUSY; if (cvs->owner != CVS_CAMERA_IPU) { do { gpiod_set_value_cansleep(cvs->req, 0); mdelay(GPIO_READ_DELAY_MS); val = gpiod_get_value_cansleep(cvs->resp); } while (val != 0 && retry--); if (val != 0) { dev_err(cvs->dev, "%s:error! val %d (!=0)", __func__, val); return -EIO; } } cvs->owner = CVS_CAMERA_IPU; cvs->int_ref_count++; return 0; } int cvs_release_camera_sensor_internal(void) { int val, retry = 20; if (!cvs) return -EINVAL; if (cvs->icvs_state == CV_FW_DOWNLOADING_STATE) return -EBUSY; if (cvs->int_ref_count == 0) return 0; if (cvs->owner != CVS_CAMERA_CVS && cvs->int_ref_count == 1) { do { gpiod_set_value_cansleep(cvs->req, 1); mdelay(GPIO_READ_DELAY_MS); val = gpiod_get_value_cansleep(cvs->resp); } while (val != 1 && retry--); if (val != 1) { dev_err(cvs->dev, "%s:error! val %d (!=1)", __func__, val); return -EIO; } } cvs->int_ref_count--; cvs->owner = (cvs->int_ref_count == 0) ? CVS_CAMERA_CVS : CVS_CAMERA_IPU; return 0; } #ifdef DEBUG_CVS enum cvs_state cvs_state; int cvs_exec_cmd(enum cvs_command command) { int rc; if (!cvs) return -EINVAL; if (cvs->icvs_state == CV_FW_DOWNLOADING_STATE || cvs->icvs_state == CV_FW_FLASHING_STATE) { dev_err(cvs->dev, "%s:Device busy, cmd:0X%x can't be queried now", __func__, command); cvs_state = cvs->cv_fw_state; return -EBUSY; } switch (command) { case GET_DEVICE_STATE: rc = cvs_read_i2c(GET_DEVICE_STATE, (char *)&cvs_state, sizeof(char)); if (rc <= 0) goto err_out; break; case GET_FW_VERSION: rc = cvs_read_i2c(GET_FW_VERSION, (char *)&cvs->ver, sizeof(struct cvs_fw)); if (rc <= 0) goto err_out; break; case GET_VID_PID: rc = cvs_read_i2c(GET_VID_PID, (char *)&cvs->id, sizeof(struct cvs_id)); if (rc <= 0) goto err_out; break; default: dev_err(cvs->dev, "%s:command %x not implemented\n", __func__, command); } return 0; err_out: dev_err(cvs->dev, "%s:CVS command 0x%x failed, cvs_read_i2c: %d", __func__, command, rc); return -EIO; } static void cvs_state_str(const enum cvs_state stat, u8 *buf) { int n = 0; *buf = 0; if (stat == DEVICE_OFF_STATE) { sprintf(buf, "%s", "DEVICE_OFF_STATE"); } else { if (stat & PRIVACY_ON_BIT_MASK) n += sprintf(buf + n, "%s, ", "PRIVACY_ON_BIT_MASK"); if (stat & DEVICE_ON_BIT_MASK) n += sprintf(buf + n, "%s, ", "DEVICE_ON_BIT_MASK"); if (stat & SENSOR_OWNER_BIT_MASK) n += sprintf(buf + n, "%s, ", "SENSOR_OWNER_BIT_MASK"); if (stat & DEVICE_DWNLD_STATE_MASK) n += sprintf(buf + n, "%s, ", "DEVICE_DWNLD_STATE_MASK"); if (stat & DEVICE_DWNLD_ERROR_MASK) n += sprintf(buf + n, "%s, ", "DEVICE_DWNLD_ERROR_MASK"); if (stat & DEVICE_DWNLD_BUSY_MASK) n += sprintf(buf + n, "%s, ", "DEVICE_DWNLD_BUSY_MASK"); } } static ssize_t coredump_show(struct device *dev, struct device_attribute *attr, char *buf) { u8 stat_name[256] = ""; cvs_state_str(cvs_state, stat_name); return sysfs_emit(buf, "CVS VID/PID : 0x%x 0x%x\n" "CVS Firmware Ver: %d.%d.%d.%d (0x%x.0x%x.0x%x.0x%x)\n" "CVS Device State: 0x%x (%s)\n" "Reference Count : %d\n" "CVS Owner : %s\n", cvs->id.vid, cvs->id.pid, cvs->ver.major, cvs->ver.minor, cvs->ver.hotfix, cvs->ver.build, cvs->ver.major, cvs->ver.minor, cvs->ver.hotfix, cvs->ver.build, cvs_state, stat_name, cvs->int_ref_count, ((cvs->owner == CVS_CAMERA_NONE) ? "NONE" : (cvs->owner == CVS_CAMERA_CVS) ? "CVS" : (cvs->owner == CVS_CAMERA_IPU) ? "HOST" : "UNKNOWN")); } static DEVICE_ATTR_RO(coredump); static ssize_t cmd_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { if (sysfs_streq(buf, "state")) cvs_exec_cmd(GET_DEVICE_STATE); else if (sysfs_streq(buf, "version")) cvs_exec_cmd(GET_FW_VERSION); else if (sysfs_streq(buf, "id")) cvs_exec_cmd(GET_VID_PID); else dev_err(cvs->dev, "%s:invalid %s command\n", __func__, buf); return count; } static ssize_t cmd_show(struct device *dev, struct device_attribute *attr, char *buf) { return sysfs_emit(buf, "command: %s\n", "[coredump, state, version, id]"); } static DEVICE_ATTR_RW(cmd); #endif //DEBUG_CVS static ssize_t cvs_ctrl_data_pre_show(struct device *dev, struct device_attribute *attr, char *buf) { unsigned long flags; int count; if (!buf) { dev_err(cvs->dev, "%s: buff is null", __func__); return -EINVAL; } count = sizeof(struct cvs_to_plugin_interface); memset(&cvs->info_fwupd, 0, sizeof(struct ctrl_data_fwupd)); cvs->fw_dl_task_finished = false; cvs->fw_dl_task_started = false; if (cvs_get_fwver_vid_pid()) { dev_err(cvs->dev, "%s:Not able to read vid/pid", __func__); return -EIO; } dev_info(cvs->dev, "%s:Device fw version is %d.%d.%d.%d", __func__, cvs->ver.major, cvs->ver.minor, cvs->ver.hotfix, cvs->ver.build); /* Device vid,pid */ cvs->cvs_to_plugin.vid = cvs->id.vid; cvs->cvs_to_plugin.pid = cvs->id.pid; cvs->cvs_to_plugin.opid = cvs->oem_prod_id; cvs->cvs_to_plugin.dev_capabilities = cvs->cv_fw_capability.dev_capability; /* Device FW version */ cvs->cvs_to_plugin.major = cvs->ver.major; cvs->cvs_to_plugin.minor = cvs->ver.minor; cvs->cvs_to_plugin.hotfix = cvs->ver.hotfix; cvs->cvs_to_plugin.build = cvs->ver.build; spin_lock_irqsave(&cvs->buffer_lock, flags); memcpy(buf, &cvs->cvs_to_plugin, sizeof(struct cvs_to_plugin_interface)); spin_unlock_irqrestore(&cvs->buffer_lock, flags); return count; } static ssize_t cvs_ctrl_data_pre_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { unsigned long flags; struct file *f; int fw_bin_size; ssize_t bytes_read = 0; if (!buf) { dev_err(cvs->dev, "%s:buff is null", __func__); return -EINVAL; } if (count == 0 || count != sizeof(struct plugin_to_cvs_interface)) { dev_err(cvs->dev, "%s:Wrong count:%x", __func__, (unsigned int)count); return -EINVAL; } spin_lock_irqsave(&cvs->buffer_lock, flags); memcpy(&cvs->plugin_to_cvs, buf, count); spin_unlock_irqrestore(&cvs->buffer_lock, flags); dev_dbg(cvs->dev, "%s:dl_time:%x, fl_time:%x, retry_cnt:%x, fw_bin_fd:%x", __func__, cvs->plugin_to_cvs.max_download_time, cvs->plugin_to_cvs.max_flash_time, cvs->plugin_to_cvs.max_fwupd_retry_count, cvs->plugin_to_cvs.fw_bin_fd); /* Get the file structure from the file descriptor */ f = fget(cvs->plugin_to_cvs.fw_bin_fd); if (!f) { dev_err(cvs->dev, "%s:Bad file descriptor", __func__); return -EBADF; } fw_bin_size = generic_file_llseek(f, 0, SEEK_END); dev_dbg(cvs->dev, "%s:Calculated fw_bin size:%x bytes", __func__, fw_bin_size); generic_file_llseek(f, -fw_bin_size, SEEK_CUR); cvs->fw_buffer_size = fw_bin_size; cvs->max_flashtime_ms = cvs->plugin_to_cvs.max_flash_time; cvs->fw_update_retries = cvs->plugin_to_cvs.max_fwupd_retry_count; cvs->fw_buffer = devm_kzalloc(cvs->dev, cvs->fw_buffer_size, GFP_KERNEL); if (IS_ERR_OR_NULL(cvs->fw_buffer)) { dev_err(cvs->dev, "%s:No memory for fw_buffer", __func__); fput(f); return -ENOMEM; } dev_dbg(cvs->dev, "%s:fw_buffer allocated at:%p", __func__, cvs->fw_buffer); /* Read FW binary using file descriptor */ bytes_read = kernel_read(f, cvs->fw_buffer, cvs->fw_buffer_size, &f->f_pos); fput(f); if (bytes_read != cvs->fw_buffer_size) { dev_err(cvs->dev, "%s:kernel_read failed with bytes_read:%lx", __func__, bytes_read); return -EIO; } else { dev_info(cvs->dev, "%s:Full fw_buffer received. Start fw_download", __func__); schedule_work(&cvs->fw_dl_task); cvs->fw_dl_task_started = true; } return count; } static ssize_t cvs_ctrl_data_fwupd_show(struct device *dev, struct device_attribute *attr, char *buf) { unsigned long flags; unsigned int count = sizeof(struct ctrl_data_fwupd); if (!buf) { dev_err(cvs->dev, "%s:buff is null", __func__); return -EINVAL; } cvs->info_fwupd.fw_dl_finshed = cvs->fw_dl_task_finished; cvs->info_fwupd.dev_state = cvs->cv_fw_state; cvs->info_fwupd.fw_upd_retries = cvs->fw_update_retries; spin_lock_irqsave(&cvs->buffer_lock, flags); memcpy(buf, &cvs->info_fwupd, count); spin_unlock_irqrestore(&cvs->buffer_lock, flags); if (cvs->info_fwupd.total_packets == cvs->info_fwupd.num_packets_sent) { cvs->info_fwupd.fw_dl_finshed = true; cvs->lvfs_fwdl_complete_event_arg = 1; wake_up_interruptible(&cvs->lvfs_fwdl_complete_event); } return count; } static DEVICE_ATTR_RW(cvs_ctrl_data_pre); static DEVICE_ATTR_RO(cvs_ctrl_data_fwupd); static struct attribute *cvs_attrs[] = { #ifdef DEBUG_CVS &dev_attr_coredump.attr, &dev_attr_cmd.attr, #endif &dev_attr_cvs_ctrl_data_pre.attr, &dev_attr_cvs_ctrl_data_fwupd.attr, NULL, }; ATTRIBUTE_GROUPS(cvs); #ifdef CONFIG_PM static int cvs_suspend(struct device *dev) { struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); struct intel_cvs *icvs = i2c_get_clientdata(i2c); int ret = 0; dev_info(icvs->dev, "%s:entered\n", __func__); if (icvs->cap == ICVS_FULLCAP && cvs->fw_dl_task_finished != true) { icvs->cv_suspend = true; cvs->close_fw_dl_task = true; cvs->hostwake_event_arg = 1; wake_up_interruptible(&cvs->hostwake_event); /* Wait for fw update to cancel */ dev_info(icvs->dev, "%s:wait for fw update cancel", __func__); flush_work(&icvs->fw_dl_task); dev_info(icvs->dev, "%s:fw update cancelled", __func__); } if (icvs->cap == ICVS_FULLCAP) { /* Disable IRQ */ disable_irq(icvs->irq); } dev_info(icvs->dev, "%s:completed", __func__); return ret; } static int cvs_resume(struct device *dev) { struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); struct intel_cvs *icvs = i2c_get_clientdata(i2c); int val = -1; dev_info(icvs->dev, "%s entered", __func__); /* Check if bridge is ready */ val = gpiod_get_value_cansleep(icvs->resp); if (val != 0) dev_err(icvs->dev, "%s:Wrong gpio_response val:%x read via bridge", __func__, val); if (icvs->cap == ICVS_FULLCAP) { icvs->cv_suspend = false; icvs->close_fw_dl_task = false; /* Start IRQ */ enable_irq(icvs->irq); if (cvs->fw_dl_task_started && !cvs->fw_dl_task_finished) { schedule_work(&icvs->fw_dl_task); cvs->fw_dl_task_started = true; } } dev_info(icvs->dev, "%s:completed", __func__); return 0; } static const struct dev_pm_ops icvs_pm_ops = { SYSTEM_SLEEP_PM_OPS(cvs_suspend, cvs_resume) }; #define ICVS_DEV_PM_OPS (&icvs_pm_ops) #else #define ICVS_DEV_PM_OPS NULL #endif /* CONFIG_PM */ static struct acpi_device_id acpi_cvs_ids[] = { { "INTC10CF" }, /* MTL */ { "INTC10DE" }, /* LNL */ { "INTC10E0" }, /* ARL */ { "INTC10E1" }, /* PTL */ { /* END OF LIST */ } }; MODULE_DEVICE_TABLE(acpi, acpi_cvs_ids); static struct i2c_driver cvs_i2c_driver = { .driver = { .name = "Intel CVS driver", .owner = THIS_MODULE, .acpi_match_table = ACPI_PTR(acpi_cvs_ids), .dev_groups = cvs_groups, .pm = pm_ptr(ICVS_DEV_PM_OPS), }, .probe = cvs_i2c_probe, .remove = cvs_i2c_remove }; static int __init icvs_init(void) { int ret; ret = i2c_add_driver(&cvs_i2c_driver); if (ret != 0) pr_err("Failed to register I2C driver: %d\n", ret); return ret; } module_init(icvs_init); static void __exit icvs_exit(void) { i2c_del_driver(&cvs_i2c_driver); } module_exit(icvs_exit); MODULE_AUTHOR("Lifu Wang "); MODULE_AUTHOR("Israel Cepeda "); MODULE_AUTHOR("Hemanth Rachakonda "); MODULE_AUTHOR("Srinivas Alla "); MODULE_DESCRIPTION("Intel CVS driver"); MODULE_LICENSE("GPL v2"); MODULE_SOFTDEP("pre: usbio gpio-usbio i2c-usbio"); vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/intel_cvs_update.c000066400000000000000000000266151476447142100266200ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2024 Intel Corporation. * */ #include #include "intel_cvs_update.h" extern struct intel_cvs *cvs; int cvs_write_i2c(u16 cmd, u8 *data, u32 len) { struct intel_cvs *ctx = cvs; struct i2c_client *client = container_of(cvs->dev, struct i2c_client, dev); int count; u16 cv_cmd = (((cmd) >> 8) & 0x00ff) | (((cmd) << 8) & 0xff00); u32 cv_host_identifier_size = sizeof(union cv_host_identifiers); switch (cmd) { case FW_LOADER_START: count = i2c_master_send(client, (const char *)&cv_cmd, sizeof(u16)); if (count != sizeof(u16)) return -EIO; break; case FW_LOADER_DATA: count = i2c_master_send(client, data, len); if (count != len) return -EIO; break; case FW_LOADER_END: count = i2c_master_send(client, (const char *)&cv_cmd, sizeof(u16)); mdelay(GPIO_WRITE_DELAY_MS); if (count != sizeof(u16)) return -EIO; break; case SET_HOST_IDENTIFIER: u8 *out_buff; union cv_host_identifiers host_identifiers; out_buff = devm_kzalloc(ctx->dev, (cv_host_identifier_size + sizeof(cmd)), GFP_KERNEL); if (!out_buff) { dev_err(cvs->dev, "%s:Buffer alloc failed", __func__); return -ENOMEM; } out_buff[0] = (cmd >> 8) & 0x00ff; out_buff[1] = cmd & 0x00ff; host_identifiers.field.vision_sensing = 0; host_identifiers.field.device_power_setting = 0; host_identifiers.field.privacy_led_host = 1; host_identifiers.field.rgbcamera_pwrup_host = 1; memcpy(&out_buff[2], &host_identifiers.value, cv_host_identifier_size); count = i2c_master_send(client, (const char *)out_buff, sizeof(cmd) + cv_host_identifier_size); if (count != cv_host_identifier_size + sizeof(cmd)) return -EIO; dev_dbg(cvs->dev, "%s:set_host_identifier cmd pass", __func__); break; default: dev_err(cvs->dev, "%s:Invalid command type", __func__); return -EINVAL; } return 0; } int cvs_get_device_state(u8 *cv_fw_state) { if (!cvs) return -EINVAL; if (cvs_read_i2c(GET_DEVICE_STATE, cv_fw_state, sizeof(char)) <= 0) { dev_err(cvs->dev, "%s:cvs_read_i2c() failed", __func__); return -EIO; } if (!((*cv_fw_state) & DEVICE_ON_BIT_MASK)) { dev_err(cvs->dev, "%s:device_on bit not set", __func__); return -EINVAL; } dev_dbg(cvs->dev, "%s: fw_state:0x%x", __func__, *cv_fw_state); return 0; } int cvs_get_device_cap(struct cv_ver_capability *cv_fw_cap) { if (!cvs) return -EINVAL; cvs->magic_num_support = true; if (cvs_read_i2c(GET_DEV_CAPABILITY, (char *)cv_fw_cap, sizeof(struct cv_ver_capability)) <= 0) { dev_info(cvs->dev, "%s:Device protocol is 1.0", __func__); cvs->magic_num_support = false; } else { dev_info(cvs->dev, "%s:Device protocol is %d.%d", __func__, cvs->cv_fw_capability.protocol_ver_major, cvs->cv_fw_capability.protocol_ver_minor); dev_info(cvs->dev, "%s:Device capability is 0x%x", __func__, cvs->cv_fw_capability.dev_capability); } return 0; } int cvs_wait_for_host_wake(u64 time_ms) { int ret = -1; s64 timeout = 0; /* wait for HOST_WAKE signal, timeout in time_ms */ timeout = msecs_to_jiffies(time_ms); ret = wait_event_interruptible_timeout(cvs->hostwake_event, cvs->hostwake_event_arg == 1, timeout); if (ret <= 0) { dev_err(cvs->dev, "%s:hostwake wait timeout", __func__); return -ETIMEDOUT; } cvs->hostwake_event_arg = 0; return 0; } int cvs_reset_cv_device(void) { if (IS_ERR_OR_NULL(cvs)) return -EINVAL; gpiod_set_value_cansleep(cvs->rst, 0); mdelay(GPIO_RESET_MS); gpiod_set_value_cansleep(cvs->rst, 1); mdelay(FW_PREPARE_MS); return 0; } int cvs_dev_fw_dl_start(void) { struct intel_cvs *ctx = cvs; u8 fw_state = 0; /* check CV FW state */ if (cvs_get_device_state(&fw_state)) { dev_err(cvs->dev, "%s:cvs_get_device_state() failed", __func__); return -EIO; } if (cvs_write_i2c(FW_LOADER_START, NULL, 0)) { dev_err(cvs->dev, "%s:cvs_write_i2c() failed", __func__); return -EIO; } /* Wait for Host Wake */ if (cvs_wait_for_host_wake(WAIT_HOST_WAKE_NORMAL_MS)) { dev_err(cvs->dev, "%s:Host wake timeout", __func__); return -ETIMEDOUT; } ctx->icvs_state = CV_FW_DOWNLOADING_STATE; /* check CV FW state */ if (cvs_get_device_state(&fw_state)) { dev_err(cvs->dev, "%s:cvs_get_device_state() failed", __func__); return -EIO; } ctx->cv_fw_state = fw_state; if ((fw_state & DEVICE_DWNLD_STATE_MASK) != DEVICE_DWNLD_STATE_MASK) { dev_err(cvs->dev, "%s:fail to enter download state. fwstate:0x%x", __func__, fw_state); return -EIO; } return 0; } int cvs_dev_fw_dl_data(void) { int status = 0; struct intel_cvs *ctx = cvs; u8 fw_state = DEVICE_DWNLD_STATE_MASK; u8 *fw_buff_ptr = NULL; u32 fw_size = 0; dev_info(cvs->dev, "%s:Enter", __func__); fw_buff_ptr = (u8 *)ctx->fw_buffer + FW_BIN_HDR_SIZE; fw_size = ctx->fw_buffer_size - FW_BIN_HDR_SIZE; while ((fw_size > 0) && (ctx->icvs_state != CV_STOPPING)) { int retry = FW_MAX_RETRY; if (ctx->close_fw_dl_task) { dev_err(cvs->dev, "%s:Received close_fw_dl_task true", __func__); status = -EPERM; goto err_exit; } do { u8 out_buf[I2C_PKT_SIZE]; if (ctx->close_fw_dl_task) { dev_info(cvs->dev, "%s:Received close_fw_dl_task", __func__); status = -EPERM; goto err_exit; } /* copy data to outbuf */ memcpy(out_buf, fw_buff_ptr, fw_size > I2C_PKT_SIZE ? I2C_PKT_SIZE : fw_size); wmb(); /* Flush WC buffers after writing out_buf */ if (fw_state & DEVICE_DWNLD_STATE_MASK) { if (cvs_write_i2c(FW_LOADER_DATA, out_buf, I2C_PKT_SIZE)) { dev_err(cvs->dev, "%s:fw_loader_data failed", __func__); fw_state = DEVICE_DWNLD_ERROR_MASK; goto i2c_packet_loop_end; } } /* Wait for Host Wake */ if (cvs_wait_for_host_wake(WAIT_HOST_WAKE_NORMAL_MS)) { dev_err(cvs->dev, "%s:Host wake timeout", __func__); return -EIO; } /* Check device state */ if (cvs_get_device_state(&fw_state)) return -EIO; if (!(fw_state & DEVICE_DWNLD_STATE_MASK)) { dev_err(cvs->dev, "%s:Device not in download_state", __func__); return -EIO; } if (fw_state & DEVICE_DWNLD_BUSY_MASK) { dev_err(cvs->dev, "%s:I2C is busy for too long! fw_state:0x%x", __func__, fw_state); return -EIO; } if (ctx->icvs_state == CV_STOPPING) { dev_err(cvs->dev, "%s:cv_state is CV_STOPPING", __func__); ctx->fw_update_retries = 0; break; } i2c_packet_loop_end: } while (--retry && (fw_state & DEVICE_DWNLD_ERROR_MASK)); if ((fw_state & DEVICE_DWNLD_BUSY_MASK) || (fw_state & DEVICE_DWNLD_ERROR_MASK) || ctx->icvs_state == CV_STOPPING || !fw_state) { dev_err(cvs->dev, "%s:Wrong fw_state:0x%x, cv_state:0x%x", __func__, fw_state, ctx->icvs_state); status = -EIO; break; } ctx->info_fwupd.num_packets_sent++; fw_size -= I2C_PKT_SIZE; fw_buff_ptr += I2C_PKT_SIZE; ctx->cv_fw_state = fw_state; } err_exit: dev_info(cvs->dev, "%s:Exit with status:0x%x, fw_st:0x%x, cv_st:0x%x", __func__, status, fw_state, ctx->icvs_state); return status; } int cvs_dev_fw_dl_end(void) { struct intel_cvs *ctx = cvs; u8 fw_state = 0; if (cvs_write_i2c(FW_LOADER_END, NULL, 0)) { dev_err(cvs->dev, "%s:fw_loader_end failed", __func__); return -EIO; } if (cvs_wait_for_host_wake(WAIT_HOST_WAKE_NORMAL_MS)) { dev_err(cvs->dev, "%s:Loader_end hostwake error", __func__); return -ETIMEDOUT; } ctx->icvs_state = CV_FW_FLASHING_STATE; /* check CV FW state */ if (cvs_get_device_state(&fw_state)) { dev_err(cvs->dev, "%s:cvs_get_device_state() failed", __func__); return -EIO; } ctx->cv_fw_state = fw_state; return 0; } int cvs_dev_fw_dl(void) { int status = 0; struct intel_cvs *ctx = cvs; u8 fw_state = 0; dev_info(cvs->dev, "%s:Enter", __func__); status = cvs_dev_fw_dl_start(); if (status) { dev_err(cvs->dev, "%s:cvs_dev_fw_dl_start() fail", __func__); } else { status = cvs_dev_fw_dl_data(); if (status) dev_err(cvs->dev, "%s:cvs_dev_fw_dl_data() fail", __func__); } /* End FW download, no matter if it's pass or fail */ if (cvs_dev_fw_dl_end()) { dev_err(cvs->dev, "%s:cvs_dev_fw_dl_end() fail", __func__); return -EIO; } if (status) return status; if (cvs_wait_for_host_wake(ctx->max_flashtime_ms)) { dev_err(cvs->dev, "%s:Firmware flash hostwake error", __func__); return -ETIMEDOUT; } ctx->icvs_state = CV_INIT_STATE; if (cvs_get_device_state(&fw_state)) { dev_err(cvs->dev, "%s:cvs_get_device_state() failed", __func__); return -EIO; } ctx->cv_fw_state = fw_state; if (ctx->cv_fw_state & DEVICE_DWNLD_BUSY_MASK) { dev_err(cvs->dev, "%s: Device is still busy after flash", __func__); return -EBUSY; } if (!status && cvs->close_fw_dl_task) { status = -EINTR; dev_info(cvs->dev, "%s:Exit with status:0x%x", __func__, status); return status; } wait_event_interruptible(cvs->lvfs_fwdl_complete_event, cvs->lvfs_fwdl_complete_event_arg == 1); cvs->lvfs_fwdl_complete_event_arg = 0; if (!ctx->cv_suspend) { /* reset vision chip */ if (cvs_reset_cv_device()) { dev_err(cvs->dev, "%s:CV reset fail after flash", __func__); return -EIO; } ctx->icvs_state = CV_INIT_STATE; } dev_info(cvs->dev, "%s:Exit with status:0x%x", __func__, status); return status; } int cvs_get_fwver_vid_pid(void) { if (!cvs) return -EINVAL; if (cvs_read_i2c(GET_FW_VERSION, (char *)&cvs->ver, sizeof(struct cvs_fw)) <= 0) return -EIO; if (cvs_read_i2c(GET_VID_PID, (char *)&cvs->id, sizeof(struct cvs_id)) <= 0) return -EIO; return 0; } void cvs_fw_dl_thread(struct work_struct *arg) { int status = 0; u8 fw_state = 0; u32 fw_size = 0; struct intel_cvs *ctx = cvs; if (IS_ERR_OR_NULL(ctx)) { dev_err(cvs->dev, "%s:Invalid ctx. Exit firmware download", __func__); return; } fw_size = ctx->fw_buffer_size - FW_BIN_HDR_SIZE; ctx->info_fwupd.total_packets = fw_size / I2C_PKT_SIZE; ctx->info_fwupd.total_packets += (fw_size % I2C_PKT_SIZE) ? 1 : 0; ctx->icvs_state = CV_INIT_STATE; do { if (ctx->close_fw_dl_task) { dev_info(cvs->dev, "%s:Received close_fw_dl_task true", __func__); goto xit; } if (cvs_get_device_state(&fw_state)) { dev_err(cvs->dev, "%s:cvs_get_device_state() failed", __func__); goto xit; } status = cvs_dev_fw_dl(); cvs->info_fwupd.fw_dl_status_code = status; if (ctx->close_fw_dl_task && status == -EINTR) { dev_info(cvs->dev, "%s:flash interrupted,fw reset to factory ver", __func__); } else if (ctx->close_fw_dl_task) { dev_info(cvs->dev, "%s:cvs_dev_fw_dl cancelled", __func__); } else if (status) { dev_err(cvs->dev, "%s:cvs_dev_fw_dl fail", __func__); } else { dev_info(cvs->dev, "%s:cvs_dev_fw_dl pass", __func__); ctx->fw_update_retries--; break; } } while (--ctx->fw_update_retries); xit: /* After FW download acquire sensor to keep sensor ownserhip * with host(IPU) always.This makes IPU-Vision driver interface * simple w/o need of IPU calling vision driver interface API's */ if (ctx->icvs_sensor_state != CV_SENSOR_VISION_ACQUIRED_STATE && !ctx->cv_suspend) { if (cvs_acquire_camera_sensor_internal()) { dev_err(cvs->dev, "%s:Acquire sensor fail", __func__); } else { ctx->icvs_sensor_state = CV_SENSOR_VISION_ACQUIRED_STATE; dev_info(cvs->dev, "%s:Ownership transfer after fw_dl success", __func__); } } else { ctx->icvs_sensor_state = CV_SENSOR_VISION_ACQUIRED_STATE; } ctx->update_complete_event_arg = 1; wake_up_interruptible(&ctx->update_complete_event); ctx->fw_dl_task_finished = true; dev_info(cvs->dev, "%s:Exiting fw_dl thread", __func__); } vision-drivers-0~git202503130554.feab312c/drivers/misc/icvs/intel_cvs_update.h000066400000000000000000000013641476447142100266170ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only */ /* * * Copyright (C) 2024 Intel Corporation. * */ #ifndef __INTEL_CVS_UPDATE_H__ #define __INTEL_CVS_UPDATE_H__ int cvs_reset_cv_device(void); void cvs_fw_dl_thread(struct work_struct *arg); int cvs_get_fwver_vid_pid(void); int cvs_acquire_camera_sensor_internal(void); int cvs_release_camera_sensor_internal(void); int cvs_read_i2c(u16 cmd, char *data, int size); int cvs_write_i2c(u16 cmd, u8 *data, u32 len); int cvs_get_device_state(u8 *cv_fw_state); int cvs_get_device_cap(struct cv_ver_capability *cv_fw_cap); int cvs_wait_for_host_wake(u64 time_ms); int cvs_dev_fw_dl(void); int cvs_dev_fw_dl_start(void); int cvs_dev_fw_dl_data(void); int cvs_dev_fw_dl_end(void); #endif // __INTEL_CVS_UPDATE_H__ vision-drivers-0~git202503130554.feab312c/include/000077500000000000000000000000001476447142100211605ustar00rootroot00000000000000vision-drivers-0~git202503130554.feab312c/include/linux/000077500000000000000000000000001476447142100223175ustar00rootroot00000000000000vision-drivers-0~git202503130554.feab312c/include/linux/intel_cvs.h000066400000000000000000000110331476447142100244540ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only */ /* * * Copyright (C) 2024 Intel Corporation. * */ #ifndef __INTEL_CVS_H__ #define __INTEL_CVS_H__ #include #include #include #include #include #define DEBUG_CVS /* ICVS # of GPIOs */ #define ICVS_FULL 4 #define ICVS_LIGHT 2 #define FW_BIN_HDR_SIZE 256 #define GPIO_READ_DELAY_MS 100 #define GPIO_WRITE_DELAY_MS 100 #define GPIO_RESET_MS 2 #define FW_MAX_RETRY 5 #define I2C_PKT_SIZE 256 #define FW_PREPARE_MS 100 #define WAIT_HOST_RELEASE_MS 10 #define WAIT_HOST_WAKE_NORMAL_MS 1000 #define WAIT_HOST_WAKE_RESET_MS 1000 #define WAIT_NORMAL_MS 500 #define CVMAGICNUMSIZE sizeof(u32) #define CVMAGICNUM 0xCAFEB0BA #define CVMAGICNUM_UNKNOWN 0xDEADBEEF /* ICVS capability */ enum icvs_cap { ICVS_NOTSUP = 0, ICVS_LIGHTCAP, ICVS_FULLCAP }; /* Supported commands by CV SoC */ enum cvs_command { GET_DEVICE_STATE = 0x0800, GET_FW_VERSION = 0x0801, GET_VID_PID = 0x0802, GET_DEV_CAPABILITY = 0x0804, SET_HOST_IDENTIFIER = 0x0805, FW_LOADER_START = 0x0820, FW_LOADER_DATA = 0x0821, FW_LOADER_END = 0x0822, HOST_SET_MIPI_CONFIG = 0x0830, FACTORY_RESET = 0x0831, }; /* CV SoC device status */ enum cvs_state { DEVICE_OFF_STATE = 0x00, PRIVACY_ON_BIT_MASK = (1 << 0), DEVICE_ON_BIT_MASK = (1 << 1), SENSOR_OWNER_BIT_MASK = (1 << 2), DEVICE_DWNLD_STATE_MASK = (1 << 4), DEVICE_DWNLD_ERROR_MASK = (1 << 6), DEVICE_DWNLD_BUSY_MASK = (1 << 7), }; /* CVS sensor Status */ enum icvs_sensor_state { CV_SENSOR_RELEASED_STATE = 0, CV_SENSOR_VISION_ACQUIRED_STATE = (1 << 0), CV_SENSOR_IPU_ACQUIRED_STATE = (1 << 1) }; /* CVS driver Status */ enum icvs_state { CV_INIT_STATE = 0, CV_FW_DOWNLOADING_STATE = (1 << 1), CV_FW_FLASHING_STATE = (1 << 3), CV_STOPPING = (1 << 7) }; enum cvs_camera_owner { CVS_CAMERA_NONE = 0, CVS_CAMERA_CVS, CVS_CAMERA_IPU, }; union cv_host_identifiers { u32 value; struct { u32 reserved : 27; u32 vision_sensing : 1; u32 device_power_setting : 2; u32 privacy_led_host : 1; u32 rgbcamera_pwrup_host : 1; } field; }; enum cv_dev_capability_mask { HOST_MIPI_CONFIG_REQUIRED_MASK = (1 << 15), FW_ANTIROLLBACK_MASK = (1 << 14), PRIVACY2VISIONDRIVER_MASK = (1 << 13), FWUPDATE_RESET_REQUIRED_MASK = (1 << 12), NOCAMERA_DURING_FWUPDATE_MASK = (1 << 11), CV_POWER_DOMAIN_MASK = (1 << 10), CAPABILITY_RESERVED_BYTE_MASK = (0xFF), }; struct cv_ver_capability { u8 protocol_ver_major; u8 protocol_ver_minor; u16 dev_capability; } __packed; /* CV-returned data from i2c */ struct cvs_fw { u32 major; u32 minor; u32 hotfix; u32 build; } __packed; struct cvs_id { u16 vid; u16 pid; } __packed; /* Params updated by vision driver */ struct cvs_to_plugin_interface { /* Device FW Version */ u32 major; u32 minor; u32 hotfix; u32 build; /* Device vid,pid */ u16 vid; u16 pid; int opid; int dev_capabilities; }; /* Params updated by CVS plugin */ struct plugin_to_cvs_interface { int max_download_time; /*milli sec*/ int max_flash_time; /*milli sec*/ int max_fwupd_retry_count; int fw_bin_fd; /*file descriptor*/ }; /* FW update status Info */ struct ctrl_data_fwupd { u8 dev_state; int fw_upd_retries; int total_packets; int num_packets_sent; /*0:In progress, 1: Finished */ bool fw_dl_finshed; /* 0:PASS, Non-zero error code. Read only after fw_dl finished=1 */ int fw_dl_status_code; }; struct intel_cvs { struct device *dev; enum icvs_cap cap; int irq; struct gpio_desc *rst; struct gpio_desc *req; struct gpio_desc *resp; /* CVS Status */ struct cvs_id id; struct cvs_fw ver; enum icvs_state icvs_state; enum icvs_sensor_state icvs_sensor_state; bool magic_num_support; struct cv_ver_capability cv_fw_capability; unsigned long long oem_prod_id; enum cvs_camera_owner owner; int int_ref_count; /* FW update info */ struct work_struct fw_dl_task; u32 fw_update_retries; void *fw_buffer; u32 fw_buffer_size; u32 max_flashtime_ms; u8 cv_fw_state; bool fw_dl_task_finished; bool close_fw_dl_task; wait_queue_head_t hostwake_event; wait_queue_head_t update_complete_event; wait_queue_head_t lvfs_fwdl_complete_event; int hostwake_event_arg; int update_complete_event_arg; int lvfs_fwdl_complete_event_arg; bool cv_suspend; bool fw_dl_task_started; spinlock_t buffer_lock; struct cvs_to_plugin_interface cvs_to_plugin; struct plugin_to_cvs_interface plugin_to_cvs; struct ctrl_data_fwupd info_fwupd; }; #ifdef DEBUG_CVS int cvs_sysfs_dump(char *buf); int cvs_exec_cmd(enum cvs_command command); #endif #endif // __INTEL_CVS_H__ vision-drivers-0~git202503130554.feab312c/security.md000066400000000000000000000006261476447142100217320ustar00rootroot00000000000000# 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).