// SPDX-License-Identifier: GPL-2.0-only
/*
* Driver for the Microchip PD692X0 PoE PSE Controller driver (I2C bus)
*
* Copyright (c) 2023 Bootlin, Kory Maincent <kory.maincent@bootlin.com>
*/
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pse-pd/pse.h>
#define PD692X0_PSE_NAME "pd692x0_pse"
#define PD692X0_MAX_PIS 48
#define PD692X0_MAX_MANAGERS 12
#define PD692X0_MAX_MANAGER_PORTS 8
#define PD692X0_MAX_HW_PORTS (PD692X0_MAX_MANAGERS * PD692X0_MAX_MANAGER_PORTS)
#define PD69200_BT_PROD_VER 24
#define PD69210_BT_PROD_VER 26
#define PD69220_BT_PROD_VER 29
#define PD692X0_FW_MAJ_VER 3
#define PD692X0_FW_MIN_VER 5
#define PD692X0_FW_PATCH_VER 5
enum pd692x0_fw_state {
PD692X0_FW_UNKNOWN,
PD692X0_FW_OK,
PD692X0_FW_BROKEN,
PD692X0_FW_NEED_UPDATE,
PD692X0_FW_PREPARE,
PD692X0_FW_WRITE,
PD692X0_FW_COMPLETE,
};
struct pd692x0_msg {
u8 key;
u8 echo;
u8 sub[3];
u8 data[8];
__be16 chksum;
} __packed;
struct pd692x0_msg_ver {
u8 prod;
u8 maj_sw_ver;
u8 min_sw_ver;
u8 pa_sw_ver;
u8 param;
u8 build;
};
enum {
PD692X0_KEY_CMD,
PD692X0_KEY_PRG,
PD692X0_KEY_REQ,
PD692X0_KEY_TLM,
PD692X0_KEY_TEST,
PD692X0_KEY_REPORT = 0x52
};
enum {
PD692X0_MSG_RESET,
PD692X0_MSG_GET_SYS_STATUS,
PD692X0_MSG_GET_SW_VER,
PD692X0_MSG_SET_TMP_PORT_MATRIX,
PD692X0_MSG_PRG_PORT_MATRIX,
PD692X0_MSG_SET_PORT_PARAM,
PD692X0_MSG_GET_PORT_STATUS,
PD692X0_MSG_DOWNLOAD_CMD,
/* add new message above here */
PD692X0_MSG_CNT
};
struct pd692x0_priv {
struct i2c_client *client;
struct pse_controller_dev pcdev;
struct device_node *np;
enum pd692x0_fw_state fw_state;
struct fw_upload *fwl;
bool cancel_request;
u8 msg_id;
bool last_cmd_key;
unsigned long last_cmd_key_time;
enum ethtool_c33_pse_admin_state admin_state[PD692X0_MAX_PIS];
};
/* Template list of communication messages. The non-null bytes defined here
* constitute the fixed portion of the messages. The remaining bytes will
* be configured later within the functions. Refer to the "PD692x0 BT Serial
* Communication Protocol User Guide" for comprehensive details on messages
* content.
*/
static const struct pd692x0_msg pd692x0_msg_template_list[PD692X0_MSG_CNT] = {
[PD692X0_MSG_RESET] = {
.key = PD692X0_KEY_CMD,
.sub = {0x07, 0x55, 0x00},
.data = {0x55, 0x00, 0x55, 0x4e,
0x4e, 0x4e, 0x4e, 0x4e},
},
[PD692X0_MSG_GET_SYS_STATUS] = {
.key = PD692X0_KEY_REQ,
.sub = {0x07, 0xd0, 0x4e},
.data = {0x4e, 0x4e, 0x4e, 0x4e,
0x4e, 0x4e, 0x4e, 0x4e},
},
[PD692X0_MSG_GET_SW_VER] = {
.key = PD692X0_KEY_REQ,
.sub = {0x07, 0x1e, 0x21},
.data = {0x4e, 0x4e, 0x4e, 0x4e,
0x4e, 0x4e, 0x4e,