diff options
author | Yu-Ping Wu <yupingso@chromium.org> | 2020-09-07 17:24:26 +0800 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2020-10-19 06:50:20 +0000 |
commit | e68ef7d75ca82f08dabe5848e816800462a66806 (patch) | |
tree | 99acf6903c75753719caef237ae8806a46053777 /src/drivers/camera | |
parent | f580d9ffef93243509e84d558e42a8722d0ad6e7 (diff) |
drivers/camera: Add config CHROMEOS_CAMERA
Add cros_camera_info struct for camera information, and
check_cros_camera_info() for checking the magic, CRC and version.
BUG=b:144820097
TEST=emerge-kukui coreboot
BRANCH=kukui
Change-Id: I1215fec76643b0cf7e09433e1190e8bd387e6953
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46042
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/drivers/camera')
-rw-r--r-- | src/drivers/camera/Kconfig | 7 | ||||
-rw-r--r-- | src/drivers/camera/Makefile.inc | 1 | ||||
-rw-r--r-- | src/drivers/camera/cros_camera.c | 39 | ||||
-rw-r--r-- | src/drivers/camera/cros_camera.h | 27 |
4 files changed, 74 insertions, 0 deletions
diff --git a/src/drivers/camera/Kconfig b/src/drivers/camera/Kconfig new file mode 100644 index 0000000000..1c0c0a3634 --- /dev/null +++ b/src/drivers/camera/Kconfig @@ -0,0 +1,7 @@ +config CHROMEOS_CAMERA + bool + default n + help + Camera with identifiers following Chrome OS Camera Info. The info is + usually available on MIPI camera EEPROM for identifying correct + drivers and config. diff --git a/src/drivers/camera/Makefile.inc b/src/drivers/camera/Makefile.inc new file mode 100644 index 0000000000..1a6e609465 --- /dev/null +++ b/src/drivers/camera/Makefile.inc @@ -0,0 +1 @@ +ramstage-$(CONFIG_CHROMEOS_CAMERA) += cros_camera.c diff --git a/src/drivers/camera/cros_camera.c b/src/drivers/camera/cros_camera.c new file mode 100644 index 0000000000..ff39678033 --- /dev/null +++ b/src/drivers/camera/cros_camera.c @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <console/console.h> +#include <crc_byte.h> +#include <string.h> + +#include "cros_camera.h" + +int check_cros_camera_info(const struct cros_camera_info *info) +{ + if (memcmp(info->magic, CROS_CAMERA_INFO_MAGIC, sizeof(info->magic))) { + printk(BIOS_ERR, "Invalid magic in camera info\n"); + return -1; + } + + const uint8_t *ptr = (void *)(&info->crc16 + 1); + uint16_t crc16 = 0; + while (ptr < (uint8_t *)info + sizeof(struct cros_camera_info)) + crc16 = crc16_byte(crc16, *ptr++); + + if (info->crc16 != crc16) { + printk(BIOS_ERR, "Incorrect CRC16: expected %#06x, got %#06x\n", + crc16, info->crc16); + return -1; + } + + if (info->version != CROS_CAMERA_INFO_VERSION) { + printk(BIOS_ERR, "Unknown camera info version: %u\n", + info->version); + return -1; + } + if (info->size < CROS_CAMERA_INFO_SIZE_MIN) { + printk(BIOS_ERR, "Size of camera info is too small: %u\n", + info->size); + return -1; + } + + return 0; +} diff --git a/src/drivers/camera/cros_camera.h b/src/drivers/camera/cros_camera.h new file mode 100644 index 0000000000..f69e77d3e5 --- /dev/null +++ b/src/drivers/camera/cros_camera.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __VENDORCODE_GOOGLE_CHROMEOS_CAMERA_H +#define __VENDORCODE_GOOGLE_CHROMEOS_CAMERA_H + +#include <stdint.h> + +#define CROS_CAMERA_INFO_MAGIC "CrOS" +#define CROS_CAMERA_INFO_VERSION 1 +#define CROS_CAMERA_INFO_SIZE_MIN 0x0a + +struct cros_camera_info { + uint8_t magic[4]; /* CROS_CAMERA_INFO_MAGIC */ + uint16_t crc16; + uint8_t version; + uint8_t size; + uint16_t data_format; + uint16_t module_pid; + uint8_t module_vid[2]; + uint8_t sensor_vid[2]; + uint16_t sensor_pid; +}; + +/* Returns 0 on success, non-zero on errors. */ +int check_cros_camera_info(const struct cros_camera_info *info); + +#endif |