linux/drivers/net/can/usb/f81604.c

// SPDX-License-Identifier: GPL-2.0
/* Fintek F81604 USB-to-2CAN controller driver.
 *
 * Copyright (C) 2023 Ji-Ze Hong (Peter Hong) <[email protected]>
 */
#include <linux/bitfield.h>
#include <linux/netdevice.h>
#include <linux/units.h>
#include <linux/usb.h>

#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
#include <linux/can/platform/sja1000.h>

#include <linux/unaligned.h>

/* vendor and product id */
#define F81604_VENDOR_ID
#define F81604_PRODUCT_ID
#define F81604_CAN_CLOCK
#define F81604_MAX_DEV
#define F81604_SET_DEVICE_RETRY

#define F81604_USB_TIMEOUT
#define F81604_SET_GET_REGISTER
#define F81604_PORT_OFFSET
#define F81604_MAX_RX_URBS

#define F81604_CMD_DATA

#define F81604_DLC_LEN_MASK
#define F81604_DLC_EFF_BIT
#define F81604_DLC_RTR_BIT

#define F81604_SFF_SHIFT
#define F81604_EFF_SHIFT

#define F81604_BRP_MASK
#define F81604_SJW_MASK

#define F81604_SEG1_MASK
#define F81604_SEG2_MASK

#define F81604_CLEAR_ALC
#define F81604_CLEAR_ECC
#define F81604_CLEAR_OVERRUN

/* device setting */
#define F81604_CTRL_MODE_REG
#define F81604_TX_ONESHOT
#define F81604_TX_NORMAL
#define F81604_RX_AUTO_RELEASE_BUF
#define F81604_INT_WHEN_CHANGE

#define F81604_TERMINATOR_REG
#define F81604_CAN0_TERM
#define F81604_CAN1_TERM

#define F81604_TERMINATION_DISABLED
#define F81604_TERMINATION_ENABLED

/* SJA1000 registers - manual section 6.4 (Pelican Mode) */
#define F81604_SJA1000_MOD
#define F81604_SJA1000_CMR
#define F81604_SJA1000_IR
#define F81604_SJA1000_IER
#define F81604_SJA1000_ALC
#define F81604_SJA1000_ECC
#define F81604_SJA1000_RXERR
#define F81604_SJA1000_TXERR
#define F81604_SJA1000_ACCC0
#define F81604_SJA1000_ACCM0
#define F81604_MAX_FILTER_CNT

/* Common registers - manual section 6.5 */
#define F81604_SJA1000_BTR0
#define F81604_SJA1000_BTR1
#define F81604_SJA1000_BTR1_SAMPLE_TRIPLE
#define F81604_SJA1000_OCR
#define F81604_SJA1000_CDR

/* mode register */
#define F81604_SJA1000_MOD_RM
#define F81604_SJA1000_MOD_LOM
#define F81604_SJA1000_MOD_STM

/* commands */
#define F81604_SJA1000_CMD_CDO

/* interrupt sources */
#define F81604_SJA1000_IRQ_BEI
#define F81604_SJA1000_IRQ_ALI
#define F81604_SJA1000_IRQ_EPI
#define F81604_SJA1000_IRQ_DOI
#define F81604_SJA1000_IRQ_EI
#define F81604_SJA1000_IRQ_TI
#define F81604_SJA1000_IRQ_RI
#define F81604_SJA1000_IRQ_ALL
#define F81604_SJA1000_IRQ_OFF

/* status register content */
#define F81604_SJA1000_SR_BS
#define F81604_SJA1000_SR_ES
#define F81604_SJA1000_SR_TCS

/* ECC register */
#define F81604_SJA1000_ECC_SEG
#define F81604_SJA1000_ECC_DIR
#define F81604_SJA1000_ECC_BIT
#define F81604_SJA1000_ECC_FORM
#define F81604_SJA1000_ECC_STUFF
#define F81604_SJA1000_ECC_MASK

/* ALC register */
#define F81604_SJA1000_ALC_MASK

/* table of devices that work with this driver */
static const struct usb_device_id f81604_table[] =;

MODULE_DEVICE_TABLE(usb, f81604_table);

static const struct ethtool_ops f81604_ethtool_ops =;

static const u16 f81604_termination[] =;

struct f81604_priv {};

struct f81604_port_priv {};

/* Interrupt endpoint data format:
 *	Byte 0: Status register.
 *	Byte 1: Interrupt register.
 *	Byte 2: Interrupt enable register.
 *	Byte 3: Arbitration lost capture(ALC) register.
 *	Byte 4: Error code capture(ECC) register.
 *	Byte 5: Error warning limit register.
 *	Byte 6: RX error counter register.
 *	Byte 7: TX error counter register.
 *	Byte 8: Reserved.
 */
struct f81604_int_data {} __packed __aligned();

struct f81604_sff {} __packed __aligned();

struct f81604_eff {} __packed __aligned();

struct f81604_can_frame {} __packed __aligned();

static const u8 bulk_in_addr[F81604_MAX_DEV] =;
static const u8 bulk_out_addr[F81604_MAX_DEV] =;
static const u8 int_in_addr[F81604_MAX_DEV] =;

static int f81604_write(struct usb_device *dev, u16 reg, u8 data)
{}

static int f81604_read(struct usb_device *dev, u16 reg, u8 *data)
{}

static int f81604_update_bits(struct usb_device *dev, u16 reg, u8 mask,
			      u8 data)
{}

static int f81604_sja1000_write(struct f81604_port_priv *priv, u16 reg,
				u8 data)
{}

static int f81604_sja1000_read(struct f81604_port_priv *priv, u16 reg,
			       u8 *data)
{}

static int f81604_set_reset_mode(struct f81604_port_priv *priv)
{}

static int f81604_set_normal_mode(struct f81604_port_priv *priv)
{}

static int f81604_chipset_init(struct f81604_port_priv *priv)
{}

static void f81604_process_rx_packet(struct net_device *netdev,
				     struct f81604_can_frame *frame)
{}

static void f81604_read_bulk_callback(struct urb *urb)
{}

static void f81604_handle_tx(struct f81604_port_priv *priv,
			     struct f81604_int_data *data)
{}

static void f81604_handle_can_bus_errors(struct f81604_port_priv *priv,
					 struct f81604_int_data *data)
{}

static void f81604_read_int_callback(struct urb *urb)
{}

static void f81604_unregister_urbs(struct f81604_port_priv *priv)
{}

static int f81604_register_urbs(struct f81604_port_priv *priv)
{}

static int f81604_start(struct net_device *netdev)
{}

static int f81604_set_bittiming(struct net_device *dev)
{}

static int f81604_set_mode(struct net_device *netdev, enum can_mode mode)
{}

static void f81604_write_bulk_callback(struct urb *urb)
{}

static void f81604_clear_reg_work(struct work_struct *work)
{}

static netdev_tx_t f81604_start_xmit(struct sk_buff *skb,
				     struct net_device *netdev)
{}

static int f81604_get_berr_counter(const struct net_device *netdev,
				   struct can_berr_counter *bec)
{}

/* Open USB device */
static int f81604_open(struct net_device *netdev)
{}

/* Close USB device */
static int f81604_close(struct net_device *netdev)
{}

static const struct net_device_ops f81604_netdev_ops =;

static const struct can_bittiming_const f81604_bittiming_const =;

/* Called by the usb core when driver is unloaded or device is removed */
static void f81604_disconnect(struct usb_interface *intf)
{}

static int __f81604_set_termination(struct usb_device *dev, int idx, u16 term)
{}

static int f81604_set_termination(struct net_device *netdev, u16 term)
{}

static int f81604_probe(struct usb_interface *intf,
			const struct usb_device_id *id)
{}

static struct usb_driver f81604_driver =;

module_usb_driver();

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