linux/drivers/usb/typec/ucsi/ucsi_stm32g0.c

// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
/*
 * UCSI driver for STMicroelectronics STM32G0 Type-C PD controller
 *
 * Copyright (C) 2022, STMicroelectronics - All Rights Reserved
 * Author: Fabrice Gasnier <[email protected]>.
 */

#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/unaligned.h>

#include "ucsi.h"

/* STM32G0 I2C bootloader addr: 0b1010001x (See AN2606) */
#define STM32G0_I2C_BL_ADDR

/* STM32G0 I2C bootloader max data size */
#define STM32G0_I2C_BL_SZ

/* STM32 I2C bootloader commands (See AN4221) */
#define STM32_CMD_GVR
#define STM32_CMD_GVR_LEN
#define STM32_CMD_RM
#define STM32_CMD_WM
#define STM32_CMD_ADDR_LEN
#define STM32_CMD_ERASE
#define STM32_CMD_ERASE_SPECIAL_LEN
#define STM32_CMD_GLOBAL_MASS_ERASE

/* STM32 I2C bootloader answer status */
#define STM32G0_I2C_BL_ACK
#define STM32G0_I2C_BL_NACK
#define STM32G0_I2C_BL_BUSY

/* STM32G0 flash definitions */
#define STM32G0_USER_OPTION_BYTES
#define STM32G0_USER_OB_NBOOT0
#define STM32G0_USER_OB_NBOOT_SEL
#define STM32G0_USER_OB_BOOT_MAIN
#define STM32G0_MAIN_MEM_ADDR

/* STM32 Firmware definitions: additional commands */
#define STM32G0_FW_GETVER
#define STM32G0_FW_GETVER_LEN
#define STM32G0_FW_RSTGOBL
#define STM32G0_FW_KEYWORD

/* ucsi_stm32g0_fw_info located at the end of the firmware */
struct ucsi_stm32g0_fw_info {};

struct ucsi_stm32g0 {};

/*
 * Bootloader commands helpers:
 * - send command (2 bytes)
 * - check ack
 * Then either:
 * - receive data
 * - receive data + check ack
 * - send data + check ack
 * These operations depends on the command and have various length.
 */
static int ucsi_stm32g0_bl_check_ack(struct ucsi *ucsi)
{}

static int ucsi_stm32g0_bl_cmd_check_ack(struct ucsi *ucsi, unsigned int cmd, bool check_ack)
{}

static int ucsi_stm32g0_bl_cmd(struct ucsi *ucsi, unsigned int cmd)
{}

static int ucsi_stm32g0_bl_rcv_check_ack(struct ucsi *ucsi, void *data, size_t len, bool check_ack)
{}

static int ucsi_stm32g0_bl_rcv(struct ucsi *ucsi, void *data, size_t len)
{}

static int ucsi_stm32g0_bl_rcv_woack(struct ucsi *ucsi, void *data, size_t len)
{}

static int ucsi_stm32g0_bl_send(struct ucsi *ucsi, void *data, size_t len)
{}

/* Bootloader commands */
static int ucsi_stm32g0_bl_get_version(struct ucsi *ucsi, u8 *bl_version)
{}

static int ucsi_stm32g0_bl_send_addr(struct ucsi *ucsi, u32 addr)
{}

static int ucsi_stm32g0_bl_global_mass_erase(struct ucsi *ucsi)
{}

static int ucsi_stm32g0_bl_write(struct ucsi *ucsi, u32 addr, const void *data, size_t len)
{}

static int ucsi_stm32g0_bl_read(struct ucsi *ucsi, u32 addr, void *data, size_t len)
{}

/* Firmware commands (the same address as the bootloader) */
static int ucsi_stm32g0_fw_cmd(struct ucsi *ucsi, unsigned int cmd)
{}

static int ucsi_stm32g0_fw_rcv(struct ucsi *ucsi, void *data, size_t len)
{}

/* UCSI ops */
static int ucsi_stm32g0_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t len)
{}

static int ucsi_stm32g0_read_version(struct ucsi *ucsi, u16 *version)
{}

static int ucsi_stm32g0_read_cci(struct ucsi *ucsi, u32 *cci)
{}

static int ucsi_stm32g0_read_message_in(struct ucsi *ucsi, void *val, size_t len)
{}

static int ucsi_stm32g0_async_control(struct ucsi *ucsi, u64 command)
{}

static irqreturn_t ucsi_stm32g0_irq_handler(int irq, void *data)
{}

static const struct ucsi_operations ucsi_stm32g0_ops =;

static int ucsi_stm32g0_register(struct ucsi *ucsi)
{}

static void ucsi_stm32g0_unregister(struct ucsi *ucsi)
{}

static void ucsi_stm32g0_fw_cb(const struct firmware *fw, void *context)
{}

static int ucsi_stm32g0_probe_bootloader(struct ucsi *ucsi)
{}

static int ucsi_stm32g0_probe(struct i2c_client *client)
{}

static void ucsi_stm32g0_remove(struct i2c_client *client)
{}

static int ucsi_stm32g0_suspend(struct device *dev)
{}

static int ucsi_stm32g0_resume(struct device *dev)
{}

static DEFINE_SIMPLE_DEV_PM_OPS(ucsi_stm32g0_pm_ops, ucsi_stm32g0_suspend, ucsi_stm32g0_resume);

static const struct of_device_id __maybe_unused ucsi_stm32g0_typec_of_match[] =;
MODULE_DEVICE_TABLE(of, ucsi_stm32g0_typec_of_match);

static const struct i2c_device_id ucsi_stm32g0_typec_i2c_devid[] =;
MODULE_DEVICE_TABLE(i2c, ucsi_stm32g0_typec_i2c_devid);

static struct i2c_driver ucsi_stm32g0_i2c_driver =;
module_i2c_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();
MODULE_ALIAS();