18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: BSD-3-Clause
28c2ecf20Sopenharmony_ci/* Copyright (c) 2016-2018, NXP Semiconductors
38c2ecf20Sopenharmony_ci * Copyright (c) 2018, Sensor-Technik Wiedemann GmbH
48c2ecf20Sopenharmony_ci * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
78c2ecf20Sopenharmony_ci#include <linux/packing.h>
88c2ecf20Sopenharmony_ci#include "sja1105.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define SJA1105_SIZE_RESET_CMD		4
118c2ecf20Sopenharmony_ci#define SJA1105_SIZE_SPI_MSG_HEADER	4
128c2ecf20Sopenharmony_ci#define SJA1105_SIZE_SPI_MSG_MAXLEN	(64 * 4)
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct sja1105_chunk {
158c2ecf20Sopenharmony_ci	u8	*buf;
168c2ecf20Sopenharmony_ci	size_t	len;
178c2ecf20Sopenharmony_ci	u64	reg_addr;
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic void
218c2ecf20Sopenharmony_cisja1105_spi_message_pack(void *buf, const struct sja1105_spi_message *msg)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	const int size = SJA1105_SIZE_SPI_MSG_HEADER;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	memset(buf, 0, size);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	sja1105_pack(buf, &msg->access,     31, 31, size);
288c2ecf20Sopenharmony_ci	sja1105_pack(buf, &msg->read_count, 30, 25, size);
298c2ecf20Sopenharmony_ci	sja1105_pack(buf, &msg->address,    24,  4, size);
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define sja1105_hdr_xfer(xfers, chunk) \
338c2ecf20Sopenharmony_ci	((xfers) + 2 * (chunk))
348c2ecf20Sopenharmony_ci#define sja1105_chunk_xfer(xfers, chunk) \
358c2ecf20Sopenharmony_ci	((xfers) + 2 * (chunk) + 1)
368c2ecf20Sopenharmony_ci#define sja1105_hdr_buf(hdr_bufs, chunk) \
378c2ecf20Sopenharmony_ci	((hdr_bufs) + (chunk) * SJA1105_SIZE_SPI_MSG_HEADER)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* If @rw is:
408c2ecf20Sopenharmony_ci * - SPI_WRITE: creates and sends an SPI write message at absolute
418c2ecf20Sopenharmony_ci *		address reg_addr, taking @len bytes from *buf
428c2ecf20Sopenharmony_ci * - SPI_READ:  creates and sends an SPI read message from absolute
438c2ecf20Sopenharmony_ci *		address reg_addr, writing @len bytes into *buf
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_cistatic int sja1105_xfer(const struct sja1105_private *priv,
468c2ecf20Sopenharmony_ci			sja1105_spi_rw_mode_t rw, u64 reg_addr, u8 *buf,
478c2ecf20Sopenharmony_ci			size_t len, struct ptp_system_timestamp *ptp_sts)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	struct sja1105_chunk chunk = {
508c2ecf20Sopenharmony_ci		.len = min_t(size_t, len, SJA1105_SIZE_SPI_MSG_MAXLEN),
518c2ecf20Sopenharmony_ci		.reg_addr = reg_addr,
528c2ecf20Sopenharmony_ci		.buf = buf,
538c2ecf20Sopenharmony_ci	};
548c2ecf20Sopenharmony_ci	struct spi_device *spi = priv->spidev;
558c2ecf20Sopenharmony_ci	struct spi_transfer *xfers;
568c2ecf20Sopenharmony_ci	int num_chunks;
578c2ecf20Sopenharmony_ci	int rc, i = 0;
588c2ecf20Sopenharmony_ci	u8 *hdr_bufs;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	num_chunks = DIV_ROUND_UP(len, SJA1105_SIZE_SPI_MSG_MAXLEN);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	/* One transfer for each message header, one for each message
638c2ecf20Sopenharmony_ci	 * payload (chunk).
648c2ecf20Sopenharmony_ci	 */
658c2ecf20Sopenharmony_ci	xfers = kcalloc(2 * num_chunks, sizeof(struct spi_transfer),
668c2ecf20Sopenharmony_ci			GFP_KERNEL);
678c2ecf20Sopenharmony_ci	if (!xfers)
688c2ecf20Sopenharmony_ci		return -ENOMEM;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* Packed buffers for the num_chunks SPI message headers,
718c2ecf20Sopenharmony_ci	 * stored as a contiguous array
728c2ecf20Sopenharmony_ci	 */
738c2ecf20Sopenharmony_ci	hdr_bufs = kcalloc(num_chunks, SJA1105_SIZE_SPI_MSG_HEADER,
748c2ecf20Sopenharmony_ci			   GFP_KERNEL);
758c2ecf20Sopenharmony_ci	if (!hdr_bufs) {
768c2ecf20Sopenharmony_ci		kfree(xfers);
778c2ecf20Sopenharmony_ci		return -ENOMEM;
788c2ecf20Sopenharmony_ci	}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	for (i = 0; i < num_chunks; i++) {
818c2ecf20Sopenharmony_ci		struct spi_transfer *chunk_xfer = sja1105_chunk_xfer(xfers, i);
828c2ecf20Sopenharmony_ci		struct spi_transfer *hdr_xfer = sja1105_hdr_xfer(xfers, i);
838c2ecf20Sopenharmony_ci		u8 *hdr_buf = sja1105_hdr_buf(hdr_bufs, i);
848c2ecf20Sopenharmony_ci		struct spi_transfer *ptp_sts_xfer;
858c2ecf20Sopenharmony_ci		struct sja1105_spi_message msg;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci		/* Populate the transfer's header buffer */
888c2ecf20Sopenharmony_ci		msg.address = chunk.reg_addr;
898c2ecf20Sopenharmony_ci		msg.access = rw;
908c2ecf20Sopenharmony_ci		if (rw == SPI_READ)
918c2ecf20Sopenharmony_ci			msg.read_count = chunk.len / 4;
928c2ecf20Sopenharmony_ci		else
938c2ecf20Sopenharmony_ci			/* Ignored */
948c2ecf20Sopenharmony_ci			msg.read_count = 0;
958c2ecf20Sopenharmony_ci		sja1105_spi_message_pack(hdr_buf, &msg);
968c2ecf20Sopenharmony_ci		hdr_xfer->tx_buf = hdr_buf;
978c2ecf20Sopenharmony_ci		hdr_xfer->len = SJA1105_SIZE_SPI_MSG_HEADER;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci		/* Populate the transfer's data buffer */
1008c2ecf20Sopenharmony_ci		if (rw == SPI_READ)
1018c2ecf20Sopenharmony_ci			chunk_xfer->rx_buf = chunk.buf;
1028c2ecf20Sopenharmony_ci		else
1038c2ecf20Sopenharmony_ci			chunk_xfer->tx_buf = chunk.buf;
1048c2ecf20Sopenharmony_ci		chunk_xfer->len = chunk.len;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci		/* Request timestamping for the transfer. Instead of letting
1078c2ecf20Sopenharmony_ci		 * callers specify which byte they want to timestamp, we can
1088c2ecf20Sopenharmony_ci		 * make certain assumptions:
1098c2ecf20Sopenharmony_ci		 * - A read operation will request a software timestamp when
1108c2ecf20Sopenharmony_ci		 *   what's being read is the PTP time. That is snapshotted by
1118c2ecf20Sopenharmony_ci		 *   the switch hardware at the end of the command portion
1128c2ecf20Sopenharmony_ci		 *   (hdr_xfer).
1138c2ecf20Sopenharmony_ci		 * - A write operation will request a software timestamp on
1148c2ecf20Sopenharmony_ci		 *   actions that modify the PTP time. Taking clock stepping as
1158c2ecf20Sopenharmony_ci		 *   an example, the switch writes the PTP time at the end of
1168c2ecf20Sopenharmony_ci		 *   the data portion (chunk_xfer).
1178c2ecf20Sopenharmony_ci		 */
1188c2ecf20Sopenharmony_ci		if (rw == SPI_READ)
1198c2ecf20Sopenharmony_ci			ptp_sts_xfer = hdr_xfer;
1208c2ecf20Sopenharmony_ci		else
1218c2ecf20Sopenharmony_ci			ptp_sts_xfer = chunk_xfer;
1228c2ecf20Sopenharmony_ci		ptp_sts_xfer->ptp_sts_word_pre = ptp_sts_xfer->len - 1;
1238c2ecf20Sopenharmony_ci		ptp_sts_xfer->ptp_sts_word_post = ptp_sts_xfer->len - 1;
1248c2ecf20Sopenharmony_ci		ptp_sts_xfer->ptp_sts = ptp_sts;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci		/* Calculate next chunk */
1278c2ecf20Sopenharmony_ci		chunk.buf += chunk.len;
1288c2ecf20Sopenharmony_ci		chunk.reg_addr += chunk.len / 4;
1298c2ecf20Sopenharmony_ci		chunk.len = min_t(size_t, (ptrdiff_t)(buf + len - chunk.buf),
1308c2ecf20Sopenharmony_ci				  SJA1105_SIZE_SPI_MSG_MAXLEN);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci		/* De-assert the chip select after each chunk. */
1338c2ecf20Sopenharmony_ci		if (chunk.len)
1348c2ecf20Sopenharmony_ci			chunk_xfer->cs_change = 1;
1358c2ecf20Sopenharmony_ci	}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	rc = spi_sync_transfer(spi, xfers, 2 * num_chunks);
1388c2ecf20Sopenharmony_ci	if (rc < 0)
1398c2ecf20Sopenharmony_ci		dev_err(&spi->dev, "SPI transfer failed: %d\n", rc);
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	kfree(hdr_bufs);
1428c2ecf20Sopenharmony_ci	kfree(xfers);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	return rc;
1458c2ecf20Sopenharmony_ci}
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ciint sja1105_xfer_buf(const struct sja1105_private *priv,
1488c2ecf20Sopenharmony_ci		     sja1105_spi_rw_mode_t rw, u64 reg_addr,
1498c2ecf20Sopenharmony_ci		     u8 *buf, size_t len)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	return sja1105_xfer(priv, rw, reg_addr, buf, len, NULL);
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* If @rw is:
1558c2ecf20Sopenharmony_ci * - SPI_WRITE: creates and sends an SPI write message at absolute
1568c2ecf20Sopenharmony_ci *		address reg_addr
1578c2ecf20Sopenharmony_ci * - SPI_READ:  creates and sends an SPI read message from absolute
1588c2ecf20Sopenharmony_ci *		address reg_addr
1598c2ecf20Sopenharmony_ci *
1608c2ecf20Sopenharmony_ci * The u64 *value is unpacked, meaning that it's stored in the native
1618c2ecf20Sopenharmony_ci * CPU endianness and directly usable by software running on the core.
1628c2ecf20Sopenharmony_ci */
1638c2ecf20Sopenharmony_ciint sja1105_xfer_u64(const struct sja1105_private *priv,
1648c2ecf20Sopenharmony_ci		     sja1105_spi_rw_mode_t rw, u64 reg_addr, u64 *value,
1658c2ecf20Sopenharmony_ci		     struct ptp_system_timestamp *ptp_sts)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	u8 packed_buf[8];
1688c2ecf20Sopenharmony_ci	int rc;
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	if (rw == SPI_WRITE)
1718c2ecf20Sopenharmony_ci		sja1105_pack(packed_buf, value, 63, 0, 8);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci	rc = sja1105_xfer(priv, rw, reg_addr, packed_buf, 8, ptp_sts);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (rw == SPI_READ)
1768c2ecf20Sopenharmony_ci		sja1105_unpack(packed_buf, value, 63, 0, 8);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	return rc;
1798c2ecf20Sopenharmony_ci}
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* Same as above, but transfers only a 4 byte word */
1828c2ecf20Sopenharmony_ciint sja1105_xfer_u32(const struct sja1105_private *priv,
1838c2ecf20Sopenharmony_ci		     sja1105_spi_rw_mode_t rw, u64 reg_addr, u32 *value,
1848c2ecf20Sopenharmony_ci		     struct ptp_system_timestamp *ptp_sts)
1858c2ecf20Sopenharmony_ci{
1868c2ecf20Sopenharmony_ci	u8 packed_buf[4];
1878c2ecf20Sopenharmony_ci	u64 tmp;
1888c2ecf20Sopenharmony_ci	int rc;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	if (rw == SPI_WRITE) {
1918c2ecf20Sopenharmony_ci		/* The packing API only supports u64 as CPU word size,
1928c2ecf20Sopenharmony_ci		 * so we need to convert.
1938c2ecf20Sopenharmony_ci		 */
1948c2ecf20Sopenharmony_ci		tmp = *value;
1958c2ecf20Sopenharmony_ci		sja1105_pack(packed_buf, &tmp, 31, 0, 4);
1968c2ecf20Sopenharmony_ci	}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	rc = sja1105_xfer(priv, rw, reg_addr, packed_buf, 4, ptp_sts);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	if (rw == SPI_READ) {
2018c2ecf20Sopenharmony_ci		sja1105_unpack(packed_buf, &tmp, 31, 0, 4);
2028c2ecf20Sopenharmony_ci		*value = tmp;
2038c2ecf20Sopenharmony_ci	}
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	return rc;
2068c2ecf20Sopenharmony_ci}
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_cistatic int sja1105et_reset_cmd(struct dsa_switch *ds)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	struct sja1105_private *priv = ds->priv;
2118c2ecf20Sopenharmony_ci	const struct sja1105_regs *regs = priv->info->regs;
2128c2ecf20Sopenharmony_ci	u8 packed_buf[SJA1105_SIZE_RESET_CMD] = {0};
2138c2ecf20Sopenharmony_ci	const int size = SJA1105_SIZE_RESET_CMD;
2148c2ecf20Sopenharmony_ci	u64 cold_rst = 1;
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	sja1105_pack(packed_buf, &cold_rst, 3, 3, size);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	return sja1105_xfer_buf(priv, SPI_WRITE, regs->rgu, packed_buf,
2198c2ecf20Sopenharmony_ci				SJA1105_SIZE_RESET_CMD);
2208c2ecf20Sopenharmony_ci}
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistatic int sja1105pqrs_reset_cmd(struct dsa_switch *ds)
2238c2ecf20Sopenharmony_ci{
2248c2ecf20Sopenharmony_ci	struct sja1105_private *priv = ds->priv;
2258c2ecf20Sopenharmony_ci	const struct sja1105_regs *regs = priv->info->regs;
2268c2ecf20Sopenharmony_ci	u8 packed_buf[SJA1105_SIZE_RESET_CMD] = {0};
2278c2ecf20Sopenharmony_ci	const int size = SJA1105_SIZE_RESET_CMD;
2288c2ecf20Sopenharmony_ci	u64 cold_rst = 1;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	sja1105_pack(packed_buf, &cold_rst, 2, 2, size);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	return sja1105_xfer_buf(priv, SPI_WRITE, regs->rgu, packed_buf,
2338c2ecf20Sopenharmony_ci				SJA1105_SIZE_RESET_CMD);
2348c2ecf20Sopenharmony_ci}
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ciint sja1105_inhibit_tx(const struct sja1105_private *priv,
2378c2ecf20Sopenharmony_ci		       unsigned long port_bitmap, bool tx_inhibited)
2388c2ecf20Sopenharmony_ci{
2398c2ecf20Sopenharmony_ci	const struct sja1105_regs *regs = priv->info->regs;
2408c2ecf20Sopenharmony_ci	u32 inhibit_cmd;
2418c2ecf20Sopenharmony_ci	int rc;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	rc = sja1105_xfer_u32(priv, SPI_READ, regs->port_control,
2448c2ecf20Sopenharmony_ci			      &inhibit_cmd, NULL);
2458c2ecf20Sopenharmony_ci	if (rc < 0)
2468c2ecf20Sopenharmony_ci		return rc;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	if (tx_inhibited)
2498c2ecf20Sopenharmony_ci		inhibit_cmd |= port_bitmap;
2508c2ecf20Sopenharmony_ci	else
2518c2ecf20Sopenharmony_ci		inhibit_cmd &= ~port_bitmap;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	return sja1105_xfer_u32(priv, SPI_WRITE, regs->port_control,
2548c2ecf20Sopenharmony_ci				&inhibit_cmd, NULL);
2558c2ecf20Sopenharmony_ci}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_cistruct sja1105_status {
2588c2ecf20Sopenharmony_ci	u64 configs;
2598c2ecf20Sopenharmony_ci	u64 crcchkl;
2608c2ecf20Sopenharmony_ci	u64 ids;
2618c2ecf20Sopenharmony_ci	u64 crcchkg;
2628c2ecf20Sopenharmony_ci};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci/* This is not reading the entire General Status area, which is also
2658c2ecf20Sopenharmony_ci * divergent between E/T and P/Q/R/S, but only the relevant bits for
2668c2ecf20Sopenharmony_ci * ensuring that the static config upload procedure was successful.
2678c2ecf20Sopenharmony_ci */
2688c2ecf20Sopenharmony_cistatic void sja1105_status_unpack(void *buf, struct sja1105_status *status)
2698c2ecf20Sopenharmony_ci{
2708c2ecf20Sopenharmony_ci	/* So that addition translates to 4 bytes */
2718c2ecf20Sopenharmony_ci	u32 *p = buf;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	/* device_id is missing from the buffer, but we don't
2748c2ecf20Sopenharmony_ci	 * want to diverge from the manual definition of the
2758c2ecf20Sopenharmony_ci	 * register addresses, so we'll back off one step with
2768c2ecf20Sopenharmony_ci	 * the register pointer, and never access p[0].
2778c2ecf20Sopenharmony_ci	 */
2788c2ecf20Sopenharmony_ci	p--;
2798c2ecf20Sopenharmony_ci	sja1105_unpack(p + 0x1, &status->configs,   31, 31, 4);
2808c2ecf20Sopenharmony_ci	sja1105_unpack(p + 0x1, &status->crcchkl,   30, 30, 4);
2818c2ecf20Sopenharmony_ci	sja1105_unpack(p + 0x1, &status->ids,       29, 29, 4);
2828c2ecf20Sopenharmony_ci	sja1105_unpack(p + 0x1, &status->crcchkg,   28, 28, 4);
2838c2ecf20Sopenharmony_ci}
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_cistatic int sja1105_status_get(struct sja1105_private *priv,
2868c2ecf20Sopenharmony_ci			      struct sja1105_status *status)
2878c2ecf20Sopenharmony_ci{
2888c2ecf20Sopenharmony_ci	const struct sja1105_regs *regs = priv->info->regs;
2898c2ecf20Sopenharmony_ci	u8 packed_buf[4];
2908c2ecf20Sopenharmony_ci	int rc;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	rc = sja1105_xfer_buf(priv, SPI_READ, regs->status, packed_buf, 4);
2938c2ecf20Sopenharmony_ci	if (rc < 0)
2948c2ecf20Sopenharmony_ci		return rc;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	sja1105_status_unpack(packed_buf, status);
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	return 0;
2998c2ecf20Sopenharmony_ci}
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci/* Not const because unpacking priv->static_config into buffers and preparing
3028c2ecf20Sopenharmony_ci * for upload requires the recalculation of table CRCs and updating the
3038c2ecf20Sopenharmony_ci * structures with these.
3048c2ecf20Sopenharmony_ci */
3058c2ecf20Sopenharmony_ciint static_config_buf_prepare_for_upload(struct sja1105_private *priv,
3068c2ecf20Sopenharmony_ci					 void *config_buf, int buf_len)
3078c2ecf20Sopenharmony_ci{
3088c2ecf20Sopenharmony_ci	struct sja1105_static_config *config = &priv->static_config;
3098c2ecf20Sopenharmony_ci	struct sja1105_table_header final_header;
3108c2ecf20Sopenharmony_ci	sja1105_config_valid_t valid;
3118c2ecf20Sopenharmony_ci	char *final_header_ptr;
3128c2ecf20Sopenharmony_ci	int crc_len;
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	valid = sja1105_static_config_check_valid(config);
3158c2ecf20Sopenharmony_ci	if (valid != SJA1105_CONFIG_OK) {
3168c2ecf20Sopenharmony_ci		dev_err(&priv->spidev->dev,
3178c2ecf20Sopenharmony_ci			sja1105_static_config_error_msg[valid]);
3188c2ecf20Sopenharmony_ci		return -EINVAL;
3198c2ecf20Sopenharmony_ci	}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	/* Write Device ID and config tables to config_buf */
3228c2ecf20Sopenharmony_ci	sja1105_static_config_pack(config_buf, config);
3238c2ecf20Sopenharmony_ci	/* Recalculate CRC of the last header (right now 0xDEADBEEF).
3248c2ecf20Sopenharmony_ci	 * Don't include the CRC field itself.
3258c2ecf20Sopenharmony_ci	 */
3268c2ecf20Sopenharmony_ci	crc_len = buf_len - 4;
3278c2ecf20Sopenharmony_ci	/* Read the whole table header */
3288c2ecf20Sopenharmony_ci	final_header_ptr = config_buf + buf_len - SJA1105_SIZE_TABLE_HEADER;
3298c2ecf20Sopenharmony_ci	sja1105_table_header_packing(final_header_ptr, &final_header, UNPACK);
3308c2ecf20Sopenharmony_ci	/* Modify */
3318c2ecf20Sopenharmony_ci	final_header.crc = sja1105_crc32(config_buf, crc_len);
3328c2ecf20Sopenharmony_ci	/* Rewrite */
3338c2ecf20Sopenharmony_ci	sja1105_table_header_packing(final_header_ptr, &final_header, PACK);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	return 0;
3368c2ecf20Sopenharmony_ci}
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci#define RETRIES 10
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ciint sja1105_static_config_upload(struct sja1105_private *priv)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	unsigned long port_bitmap = GENMASK_ULL(SJA1105_NUM_PORTS - 1, 0);
3438c2ecf20Sopenharmony_ci	struct sja1105_static_config *config = &priv->static_config;
3448c2ecf20Sopenharmony_ci	const struct sja1105_regs *regs = priv->info->regs;
3458c2ecf20Sopenharmony_ci	struct device *dev = &priv->spidev->dev;
3468c2ecf20Sopenharmony_ci	struct sja1105_status status;
3478c2ecf20Sopenharmony_ci	int rc, retries = RETRIES;
3488c2ecf20Sopenharmony_ci	u8 *config_buf;
3498c2ecf20Sopenharmony_ci	int buf_len;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	buf_len = sja1105_static_config_get_length(config);
3528c2ecf20Sopenharmony_ci	config_buf = kcalloc(buf_len, sizeof(char), GFP_KERNEL);
3538c2ecf20Sopenharmony_ci	if (!config_buf)
3548c2ecf20Sopenharmony_ci		return -ENOMEM;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	rc = static_config_buf_prepare_for_upload(priv, config_buf, buf_len);
3578c2ecf20Sopenharmony_ci	if (rc < 0) {
3588c2ecf20Sopenharmony_ci		dev_err(dev, "Invalid config, cannot upload\n");
3598c2ecf20Sopenharmony_ci		rc = -EINVAL;
3608c2ecf20Sopenharmony_ci		goto out;
3618c2ecf20Sopenharmony_ci	}
3628c2ecf20Sopenharmony_ci	/* Prevent PHY jabbering during switch reset by inhibiting
3638c2ecf20Sopenharmony_ci	 * Tx on all ports and waiting for current packet to drain.
3648c2ecf20Sopenharmony_ci	 * Otherwise, the PHY will see an unterminated Ethernet packet.
3658c2ecf20Sopenharmony_ci	 */
3668c2ecf20Sopenharmony_ci	rc = sja1105_inhibit_tx(priv, port_bitmap, true);
3678c2ecf20Sopenharmony_ci	if (rc < 0) {
3688c2ecf20Sopenharmony_ci		dev_err(dev, "Failed to inhibit Tx on ports\n");
3698c2ecf20Sopenharmony_ci		rc = -ENXIO;
3708c2ecf20Sopenharmony_ci		goto out;
3718c2ecf20Sopenharmony_ci	}
3728c2ecf20Sopenharmony_ci	/* Wait for an eventual egress packet to finish transmission
3738c2ecf20Sopenharmony_ci	 * (reach IFG). It is guaranteed that a second one will not
3748c2ecf20Sopenharmony_ci	 * follow, and that switch cold reset is thus safe
3758c2ecf20Sopenharmony_ci	 */
3768c2ecf20Sopenharmony_ci	usleep_range(500, 1000);
3778c2ecf20Sopenharmony_ci	do {
3788c2ecf20Sopenharmony_ci		/* Put the SJA1105 in programming mode */
3798c2ecf20Sopenharmony_ci		rc = priv->info->reset_cmd(priv->ds);
3808c2ecf20Sopenharmony_ci		if (rc < 0) {
3818c2ecf20Sopenharmony_ci			dev_err(dev, "Failed to reset switch, retrying...\n");
3828c2ecf20Sopenharmony_ci			continue;
3838c2ecf20Sopenharmony_ci		}
3848c2ecf20Sopenharmony_ci		/* Wait for the switch to come out of reset */
3858c2ecf20Sopenharmony_ci		usleep_range(1000, 5000);
3868c2ecf20Sopenharmony_ci		/* Upload the static config to the device */
3878c2ecf20Sopenharmony_ci		rc = sja1105_xfer_buf(priv, SPI_WRITE, regs->config,
3888c2ecf20Sopenharmony_ci				      config_buf, buf_len);
3898c2ecf20Sopenharmony_ci		if (rc < 0) {
3908c2ecf20Sopenharmony_ci			dev_err(dev, "Failed to upload config, retrying...\n");
3918c2ecf20Sopenharmony_ci			continue;
3928c2ecf20Sopenharmony_ci		}
3938c2ecf20Sopenharmony_ci		/* Check that SJA1105 responded well to the config upload */
3948c2ecf20Sopenharmony_ci		rc = sja1105_status_get(priv, &status);
3958c2ecf20Sopenharmony_ci		if (rc < 0)
3968c2ecf20Sopenharmony_ci			continue;
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci		if (status.ids == 1) {
3998c2ecf20Sopenharmony_ci			dev_err(dev, "Mismatch between hardware and static config "
4008c2ecf20Sopenharmony_ci				"device id. Wrote 0x%llx, wants 0x%llx\n",
4018c2ecf20Sopenharmony_ci				config->device_id, priv->info->device_id);
4028c2ecf20Sopenharmony_ci			continue;
4038c2ecf20Sopenharmony_ci		}
4048c2ecf20Sopenharmony_ci		if (status.crcchkl == 1) {
4058c2ecf20Sopenharmony_ci			dev_err(dev, "Switch reported invalid local CRC on "
4068c2ecf20Sopenharmony_ci				"the uploaded config, retrying...\n");
4078c2ecf20Sopenharmony_ci			continue;
4088c2ecf20Sopenharmony_ci		}
4098c2ecf20Sopenharmony_ci		if (status.crcchkg == 1) {
4108c2ecf20Sopenharmony_ci			dev_err(dev, "Switch reported invalid global CRC on "
4118c2ecf20Sopenharmony_ci				"the uploaded config, retrying...\n");
4128c2ecf20Sopenharmony_ci			continue;
4138c2ecf20Sopenharmony_ci		}
4148c2ecf20Sopenharmony_ci		if (status.configs == 0) {
4158c2ecf20Sopenharmony_ci			dev_err(dev, "Switch reported that configuration is "
4168c2ecf20Sopenharmony_ci				"invalid, retrying...\n");
4178c2ecf20Sopenharmony_ci			continue;
4188c2ecf20Sopenharmony_ci		}
4198c2ecf20Sopenharmony_ci		/* Success! */
4208c2ecf20Sopenharmony_ci		break;
4218c2ecf20Sopenharmony_ci	} while (--retries);
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	if (!retries) {
4248c2ecf20Sopenharmony_ci		rc = -EIO;
4258c2ecf20Sopenharmony_ci		dev_err(dev, "Failed to upload config to device, giving up\n");
4268c2ecf20Sopenharmony_ci		goto out;
4278c2ecf20Sopenharmony_ci	} else if (retries != RETRIES) {
4288c2ecf20Sopenharmony_ci		dev_info(dev, "Succeeded after %d tried\n", RETRIES - retries);
4298c2ecf20Sopenharmony_ci	}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ciout:
4328c2ecf20Sopenharmony_ci	kfree(config_buf);
4338c2ecf20Sopenharmony_ci	return rc;
4348c2ecf20Sopenharmony_ci}
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_cistatic struct sja1105_regs sja1105et_regs = {
4378c2ecf20Sopenharmony_ci	.device_id = 0x0,
4388c2ecf20Sopenharmony_ci	.prod_id = 0x100BC3,
4398c2ecf20Sopenharmony_ci	.status = 0x1,
4408c2ecf20Sopenharmony_ci	.port_control = 0x11,
4418c2ecf20Sopenharmony_ci	.vl_status = 0x10000,
4428c2ecf20Sopenharmony_ci	.config = 0x020000,
4438c2ecf20Sopenharmony_ci	.rgu = 0x100440,
4448c2ecf20Sopenharmony_ci	/* UM10944.pdf, Table 86, ACU Register overview */
4458c2ecf20Sopenharmony_ci	.pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808},
4468c2ecf20Sopenharmony_ci	.pad_mii_rx = {0x100801, 0x100803, 0x100805, 0x100807, 0x100809},
4478c2ecf20Sopenharmony_ci	.rmii_pll1 = 0x10000A,
4488c2ecf20Sopenharmony_ci	.cgu_idiv = {0x10000B, 0x10000C, 0x10000D, 0x10000E, 0x10000F},
4498c2ecf20Sopenharmony_ci	.mac = {0x200, 0x202, 0x204, 0x206, 0x208},
4508c2ecf20Sopenharmony_ci	.mac_hl1 = {0x400, 0x410, 0x420, 0x430, 0x440},
4518c2ecf20Sopenharmony_ci	.mac_hl2 = {0x600, 0x610, 0x620, 0x630, 0x640},
4528c2ecf20Sopenharmony_ci	/* UM10944.pdf, Table 78, CGU Register overview */
4538c2ecf20Sopenharmony_ci	.mii_tx_clk = {0x100013, 0x10001A, 0x100021, 0x100028, 0x10002F},
4548c2ecf20Sopenharmony_ci	.mii_rx_clk = {0x100014, 0x10001B, 0x100022, 0x100029, 0x100030},
4558c2ecf20Sopenharmony_ci	.mii_ext_tx_clk = {0x100018, 0x10001F, 0x100026, 0x10002D, 0x100034},
4568c2ecf20Sopenharmony_ci	.mii_ext_rx_clk = {0x100019, 0x100020, 0x100027, 0x10002E, 0x100035},
4578c2ecf20Sopenharmony_ci	.rgmii_tx_clk = {0x100016, 0x10001D, 0x100024, 0x10002B, 0x100032},
4588c2ecf20Sopenharmony_ci	.rmii_ref_clk = {0x100015, 0x10001C, 0x100023, 0x10002A, 0x100031},
4598c2ecf20Sopenharmony_ci	.rmii_ext_tx_clk = {0x100018, 0x10001F, 0x100026, 0x10002D, 0x100034},
4608c2ecf20Sopenharmony_ci	.ptpegr_ts = {0xC0, 0xC2, 0xC4, 0xC6, 0xC8},
4618c2ecf20Sopenharmony_ci	.ptpschtm = 0x12, /* Spans 0x12 to 0x13 */
4628c2ecf20Sopenharmony_ci	.ptppinst = 0x14,
4638c2ecf20Sopenharmony_ci	.ptppindur = 0x16,
4648c2ecf20Sopenharmony_ci	.ptp_control = 0x17,
4658c2ecf20Sopenharmony_ci	.ptpclkval = 0x18, /* Spans 0x18 to 0x19 */
4668c2ecf20Sopenharmony_ci	.ptpclkrate = 0x1A,
4678c2ecf20Sopenharmony_ci	.ptpclkcorp = 0x1D,
4688c2ecf20Sopenharmony_ci};
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_cistatic struct sja1105_regs sja1105pqrs_regs = {
4718c2ecf20Sopenharmony_ci	.device_id = 0x0,
4728c2ecf20Sopenharmony_ci	.prod_id = 0x100BC3,
4738c2ecf20Sopenharmony_ci	.status = 0x1,
4748c2ecf20Sopenharmony_ci	.port_control = 0x12,
4758c2ecf20Sopenharmony_ci	.vl_status = 0x10000,
4768c2ecf20Sopenharmony_ci	.config = 0x020000,
4778c2ecf20Sopenharmony_ci	.rgu = 0x100440,
4788c2ecf20Sopenharmony_ci	/* UM10944.pdf, Table 86, ACU Register overview */
4798c2ecf20Sopenharmony_ci	.pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808},
4808c2ecf20Sopenharmony_ci	.pad_mii_rx = {0x100801, 0x100803, 0x100805, 0x100807, 0x100809},
4818c2ecf20Sopenharmony_ci	.pad_mii_id = {0x100810, 0x100811, 0x100812, 0x100813, 0x100814},
4828c2ecf20Sopenharmony_ci	.sgmii = 0x1F0000,
4838c2ecf20Sopenharmony_ci	.rmii_pll1 = 0x10000A,
4848c2ecf20Sopenharmony_ci	.cgu_idiv = {0x10000B, 0x10000C, 0x10000D, 0x10000E, 0x10000F},
4858c2ecf20Sopenharmony_ci	.mac = {0x200, 0x202, 0x204, 0x206, 0x208},
4868c2ecf20Sopenharmony_ci	.mac_hl1 = {0x400, 0x410, 0x420, 0x430, 0x440},
4878c2ecf20Sopenharmony_ci	.mac_hl2 = {0x600, 0x610, 0x620, 0x630, 0x640},
4888c2ecf20Sopenharmony_ci	.ether_stats = {0x1400, 0x1418, 0x1430, 0x1448, 0x1460},
4898c2ecf20Sopenharmony_ci	/* UM11040.pdf, Table 114 */
4908c2ecf20Sopenharmony_ci	.mii_tx_clk = {0x100013, 0x100019, 0x10001F, 0x100025, 0x10002B},
4918c2ecf20Sopenharmony_ci	.mii_rx_clk = {0x100014, 0x10001A, 0x100020, 0x100026, 0x10002C},
4928c2ecf20Sopenharmony_ci	.mii_ext_tx_clk = {0x100017, 0x10001D, 0x100023, 0x100029, 0x10002F},
4938c2ecf20Sopenharmony_ci	.mii_ext_rx_clk = {0x100018, 0x10001E, 0x100024, 0x10002A, 0x100030},
4948c2ecf20Sopenharmony_ci	.rgmii_tx_clk = {0x100016, 0x10001C, 0x100022, 0x100028, 0x10002E},
4958c2ecf20Sopenharmony_ci	.rmii_ref_clk = {0x100015, 0x10001B, 0x100021, 0x100027, 0x10002D},
4968c2ecf20Sopenharmony_ci	.rmii_ext_tx_clk = {0x100017, 0x10001D, 0x100023, 0x100029, 0x10002F},
4978c2ecf20Sopenharmony_ci	.qlevel = {0x604, 0x614, 0x624, 0x634, 0x644},
4988c2ecf20Sopenharmony_ci	.ptpegr_ts = {0xC0, 0xC4, 0xC8, 0xCC, 0xD0},
4998c2ecf20Sopenharmony_ci	.ptpschtm = 0x13, /* Spans 0x13 to 0x14 */
5008c2ecf20Sopenharmony_ci	.ptppinst = 0x15,
5018c2ecf20Sopenharmony_ci	.ptppindur = 0x17,
5028c2ecf20Sopenharmony_ci	.ptp_control = 0x18,
5038c2ecf20Sopenharmony_ci	.ptpclkval = 0x19,
5048c2ecf20Sopenharmony_ci	.ptpclkrate = 0x1B,
5058c2ecf20Sopenharmony_ci	.ptpclkcorp = 0x1E,
5068c2ecf20Sopenharmony_ci	.ptpsyncts = 0x1F,
5078c2ecf20Sopenharmony_ci};
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ciconst struct sja1105_info sja1105e_info = {
5108c2ecf20Sopenharmony_ci	.device_id		= SJA1105E_DEVICE_ID,
5118c2ecf20Sopenharmony_ci	.part_no		= SJA1105ET_PART_NO,
5128c2ecf20Sopenharmony_ci	.static_ops		= sja1105e_table_ops,
5138c2ecf20Sopenharmony_ci	.dyn_ops		= sja1105et_dyn_ops,
5148c2ecf20Sopenharmony_ci	.qinq_tpid		= ETH_P_8021Q,
5158c2ecf20Sopenharmony_ci	.ptp_ts_bits		= 24,
5168c2ecf20Sopenharmony_ci	.ptpegr_ts_bytes	= 4,
5178c2ecf20Sopenharmony_ci	.num_cbs_shapers	= SJA1105ET_MAX_CBS_COUNT,
5188c2ecf20Sopenharmony_ci	.reset_cmd		= sja1105et_reset_cmd,
5198c2ecf20Sopenharmony_ci	.fdb_add_cmd		= sja1105et_fdb_add,
5208c2ecf20Sopenharmony_ci	.fdb_del_cmd		= sja1105et_fdb_del,
5218c2ecf20Sopenharmony_ci	.ptp_cmd_packing	= sja1105et_ptp_cmd_packing,
5228c2ecf20Sopenharmony_ci	.regs			= &sja1105et_regs,
5238c2ecf20Sopenharmony_ci	.name			= "SJA1105E",
5248c2ecf20Sopenharmony_ci};
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ciconst struct sja1105_info sja1105t_info = {
5278c2ecf20Sopenharmony_ci	.device_id		= SJA1105T_DEVICE_ID,
5288c2ecf20Sopenharmony_ci	.part_no		= SJA1105ET_PART_NO,
5298c2ecf20Sopenharmony_ci	.static_ops		= sja1105t_table_ops,
5308c2ecf20Sopenharmony_ci	.dyn_ops		= sja1105et_dyn_ops,
5318c2ecf20Sopenharmony_ci	.qinq_tpid		= ETH_P_8021Q,
5328c2ecf20Sopenharmony_ci	.ptp_ts_bits		= 24,
5338c2ecf20Sopenharmony_ci	.ptpegr_ts_bytes	= 4,
5348c2ecf20Sopenharmony_ci	.num_cbs_shapers	= SJA1105ET_MAX_CBS_COUNT,
5358c2ecf20Sopenharmony_ci	.reset_cmd		= sja1105et_reset_cmd,
5368c2ecf20Sopenharmony_ci	.fdb_add_cmd		= sja1105et_fdb_add,
5378c2ecf20Sopenharmony_ci	.fdb_del_cmd		= sja1105et_fdb_del,
5388c2ecf20Sopenharmony_ci	.ptp_cmd_packing	= sja1105et_ptp_cmd_packing,
5398c2ecf20Sopenharmony_ci	.regs			= &sja1105et_regs,
5408c2ecf20Sopenharmony_ci	.name			= "SJA1105T",
5418c2ecf20Sopenharmony_ci};
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ciconst struct sja1105_info sja1105p_info = {
5448c2ecf20Sopenharmony_ci	.device_id		= SJA1105PR_DEVICE_ID,
5458c2ecf20Sopenharmony_ci	.part_no		= SJA1105P_PART_NO,
5468c2ecf20Sopenharmony_ci	.static_ops		= sja1105p_table_ops,
5478c2ecf20Sopenharmony_ci	.dyn_ops		= sja1105pqrs_dyn_ops,
5488c2ecf20Sopenharmony_ci	.qinq_tpid		= ETH_P_8021AD,
5498c2ecf20Sopenharmony_ci	.ptp_ts_bits		= 32,
5508c2ecf20Sopenharmony_ci	.ptpegr_ts_bytes	= 8,
5518c2ecf20Sopenharmony_ci	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
5528c2ecf20Sopenharmony_ci	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
5538c2ecf20Sopenharmony_ci	.reset_cmd		= sja1105pqrs_reset_cmd,
5548c2ecf20Sopenharmony_ci	.fdb_add_cmd		= sja1105pqrs_fdb_add,
5558c2ecf20Sopenharmony_ci	.fdb_del_cmd		= sja1105pqrs_fdb_del,
5568c2ecf20Sopenharmony_ci	.ptp_cmd_packing	= sja1105pqrs_ptp_cmd_packing,
5578c2ecf20Sopenharmony_ci	.regs			= &sja1105pqrs_regs,
5588c2ecf20Sopenharmony_ci	.name			= "SJA1105P",
5598c2ecf20Sopenharmony_ci};
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ciconst struct sja1105_info sja1105q_info = {
5628c2ecf20Sopenharmony_ci	.device_id		= SJA1105QS_DEVICE_ID,
5638c2ecf20Sopenharmony_ci	.part_no		= SJA1105Q_PART_NO,
5648c2ecf20Sopenharmony_ci	.static_ops		= sja1105q_table_ops,
5658c2ecf20Sopenharmony_ci	.dyn_ops		= sja1105pqrs_dyn_ops,
5668c2ecf20Sopenharmony_ci	.qinq_tpid		= ETH_P_8021AD,
5678c2ecf20Sopenharmony_ci	.ptp_ts_bits		= 32,
5688c2ecf20Sopenharmony_ci	.ptpegr_ts_bytes	= 8,
5698c2ecf20Sopenharmony_ci	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
5708c2ecf20Sopenharmony_ci	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
5718c2ecf20Sopenharmony_ci	.reset_cmd		= sja1105pqrs_reset_cmd,
5728c2ecf20Sopenharmony_ci	.fdb_add_cmd		= sja1105pqrs_fdb_add,
5738c2ecf20Sopenharmony_ci	.fdb_del_cmd		= sja1105pqrs_fdb_del,
5748c2ecf20Sopenharmony_ci	.ptp_cmd_packing	= sja1105pqrs_ptp_cmd_packing,
5758c2ecf20Sopenharmony_ci	.regs			= &sja1105pqrs_regs,
5768c2ecf20Sopenharmony_ci	.name			= "SJA1105Q",
5778c2ecf20Sopenharmony_ci};
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ciconst struct sja1105_info sja1105r_info = {
5808c2ecf20Sopenharmony_ci	.device_id		= SJA1105PR_DEVICE_ID,
5818c2ecf20Sopenharmony_ci	.part_no		= SJA1105R_PART_NO,
5828c2ecf20Sopenharmony_ci	.static_ops		= sja1105r_table_ops,
5838c2ecf20Sopenharmony_ci	.dyn_ops		= sja1105pqrs_dyn_ops,
5848c2ecf20Sopenharmony_ci	.qinq_tpid		= ETH_P_8021AD,
5858c2ecf20Sopenharmony_ci	.ptp_ts_bits		= 32,
5868c2ecf20Sopenharmony_ci	.ptpegr_ts_bytes	= 8,
5878c2ecf20Sopenharmony_ci	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
5888c2ecf20Sopenharmony_ci	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
5898c2ecf20Sopenharmony_ci	.reset_cmd		= sja1105pqrs_reset_cmd,
5908c2ecf20Sopenharmony_ci	.fdb_add_cmd		= sja1105pqrs_fdb_add,
5918c2ecf20Sopenharmony_ci	.fdb_del_cmd		= sja1105pqrs_fdb_del,
5928c2ecf20Sopenharmony_ci	.ptp_cmd_packing	= sja1105pqrs_ptp_cmd_packing,
5938c2ecf20Sopenharmony_ci	.regs			= &sja1105pqrs_regs,
5948c2ecf20Sopenharmony_ci	.name			= "SJA1105R",
5958c2ecf20Sopenharmony_ci};
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ciconst struct sja1105_info sja1105s_info = {
5988c2ecf20Sopenharmony_ci	.device_id		= SJA1105QS_DEVICE_ID,
5998c2ecf20Sopenharmony_ci	.part_no		= SJA1105S_PART_NO,
6008c2ecf20Sopenharmony_ci	.static_ops		= sja1105s_table_ops,
6018c2ecf20Sopenharmony_ci	.dyn_ops		= sja1105pqrs_dyn_ops,
6028c2ecf20Sopenharmony_ci	.regs			= &sja1105pqrs_regs,
6038c2ecf20Sopenharmony_ci	.qinq_tpid		= ETH_P_8021AD,
6048c2ecf20Sopenharmony_ci	.ptp_ts_bits		= 32,
6058c2ecf20Sopenharmony_ci	.ptpegr_ts_bytes	= 8,
6068c2ecf20Sopenharmony_ci	.num_cbs_shapers	= SJA1105PQRS_MAX_CBS_COUNT,
6078c2ecf20Sopenharmony_ci	.setup_rgmii_delay	= sja1105pqrs_setup_rgmii_delay,
6088c2ecf20Sopenharmony_ci	.reset_cmd		= sja1105pqrs_reset_cmd,
6098c2ecf20Sopenharmony_ci	.fdb_add_cmd		= sja1105pqrs_fdb_add,
6108c2ecf20Sopenharmony_ci	.fdb_del_cmd		= sja1105pqrs_fdb_del,
6118c2ecf20Sopenharmony_ci	.ptp_cmd_packing	= sja1105pqrs_ptp_cmd_packing,
6128c2ecf20Sopenharmony_ci	.name			= "SJA1105S",
6138c2ecf20Sopenharmony_ci};
614