linux/drivers/net/can/sun4i_can.c

/*
 * sun4i_can.c - CAN bus controller driver for Allwinner SUN4I&SUN7I based SoCs
 *
 * Copyright (C) 2013 Peter Chen
 * Copyright (C) 2015 Gerhard Bertelsmann
 * All rights reserved.
 *
 * Parts of this software are based on (derived from) the SJA1000 code by:
 *   Copyright (C) 2014 Oliver Hartkopp <[email protected]>
 *   Copyright (C) 2007 Wolfgang Grandegger <[email protected]>
 *   Copyright (C) 2002-2007 Volkswagen Group Electronic Research
 *   Copyright (C) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33,
 *   38106 Braunschweig, GERMANY
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of Volkswagen nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * Alternatively, provided that this notice is retained in full, this
 * software may be distributed under the terms of the GNU General
 * Public License ("GPL") version 2, in which case the provisions of the
 * GPL apply INSTEAD OF those given above.
 *
 * The provided data structures and external interfaces from this code
 * are not restricted to be used by modules with a GPL compatible license.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 */

#include <linux/netdevice.h>
#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/ethtool.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/reset.h>

#define DRV_NAME

/* Registers address (physical base address 0x01C2BC00) */
#define SUN4I_REG_MSEL_ADDR
#define SUN4I_REG_CMD_ADDR
#define SUN4I_REG_STA_ADDR
#define SUN4I_REG_INT_ADDR
#define SUN4I_REG_INTEN_ADDR
#define SUN4I_REG_BTIME_ADDR
#define SUN4I_REG_TEWL_ADDR
#define SUN4I_REG_ERRC_ADDR
#define SUN4I_REG_RMCNT_ADDR
#define SUN4I_REG_RBUFSA_ADDR
#define SUN4I_REG_BUF0_ADDR
#define SUN4I_REG_BUF1_ADDR
#define SUN4I_REG_BUF2_ADDR
#define SUN4I_REG_BUF3_ADDR
#define SUN4I_REG_BUF4_ADDR
#define SUN4I_REG_BUF5_ADDR
#define SUN4I_REG_BUF6_ADDR
#define SUN4I_REG_BUF7_ADDR
#define SUN4I_REG_BUF8_ADDR
#define SUN4I_REG_BUF9_ADDR
#define SUN4I_REG_BUF10_ADDR
#define SUN4I_REG_BUF11_ADDR
#define SUN4I_REG_BUF12_ADDR
#define SUN4I_REG_ACPC_ADDR
#define SUN4I_REG_ACPM_ADDR
#define SUN4I_REG_ACPC_ADDR_D1
#define SUN4I_REG_ACPM_ADDR_D1
#define SUN4I_REG_RBUF_RBACK_START_ADDR
#define SUN4I_REG_RBUF_RBACK_END_ADDR

/* Controller Register Description */

/* mode select register (r/w)
 * offset:0x0000 default:0x0000_0001
 */
#define SUN4I_MSEL_SLEEP_MODE
#define SUN4I_MSEL_WAKE_UP
#define SUN4I_MSEL_SINGLE_FILTER
#define SUN4I_MSEL_DUAL_FILTERS
#define SUN4I_MSEL_LOOPBACK_MODE
#define SUN4I_MSEL_LISTEN_ONLY_MODE
#define SUN4I_MSEL_RESET_MODE

/* command register (w)
 * offset:0x0004 default:0x0000_0000
 */
#define SUN4I_CMD_BUS_OFF_REQ
#define SUN4I_CMD_SELF_RCV_REQ
#define SUN4I_CMD_CLEAR_OR_FLAG
#define SUN4I_CMD_RELEASE_RBUF
#define SUN4I_CMD_ABORT_REQ
#define SUN4I_CMD_TRANS_REQ

/* status register (r)
 * offset:0x0008 default:0x0000_003c
 */
#define SUN4I_STA_BIT_ERR
#define SUN4I_STA_FORM_ERR
#define SUN4I_STA_STUFF_ERR
#define SUN4I_STA_OTHER_ERR
#define SUN4I_STA_MASK_ERR
#define SUN4I_STA_ERR_DIR
#define SUN4I_STA_ERR_SEG_CODE
#define SUN4I_STA_START
#define SUN4I_STA_ID28_21
#define SUN4I_STA_ID20_18
#define SUN4I_STA_SRTR
#define SUN4I_STA_IDE
#define SUN4I_STA_ID17_13
#define SUN4I_STA_ID12_5
#define SUN4I_STA_ID4_0
#define SUN4I_STA_RTR
#define SUN4I_STA_RB1
#define SUN4I_STA_RB0
#define SUN4I_STA_DLEN
#define SUN4I_STA_DATA_FIELD
#define SUN4I_STA_CRC_SEQUENCE
#define SUN4I_STA_CRC_DELIMITER
#define SUN4I_STA_ACK
#define SUN4I_STA_ACK_DELIMITER
#define SUN4I_STA_END
#define SUN4I_STA_INTERMISSION
#define SUN4I_STA_ACTIVE_ERROR
#define SUN4I_STA_PASSIVE_ERROR
#define SUN4I_STA_TOLERATE_DOMINANT_BITS
#define SUN4I_STA_ERROR_DELIMITER
#define SUN4I_STA_OVERLOAD
#define SUN4I_STA_BUS_OFF
#define SUN4I_STA_ERR_STA
#define SUN4I_STA_TRANS_BUSY
#define SUN4I_STA_RCV_BUSY
#define SUN4I_STA_TRANS_OVER
#define SUN4I_STA_TBUF_RDY
#define SUN4I_STA_DATA_ORUN
#define SUN4I_STA_RBUF_RDY

/* interrupt register (r)
 * offset:0x000c default:0x0000_0000
 */
#define SUN4I_INT_BUS_ERR
#define SUN4I_INT_ARB_LOST
#define SUN4I_INT_ERR_PASSIVE
#define SUN4I_INT_WAKEUP
#define SUN4I_INT_DATA_OR
#define SUN4I_INT_ERR_WRN
#define SUN4I_INT_TBUF_VLD
#define SUN4I_INT_RBUF_VLD

/* interrupt enable register (r/w)
 * offset:0x0010 default:0x0000_0000
 */
#define SUN4I_INTEN_BERR
#define SUN4I_INTEN_ARB_LOST
#define SUN4I_INTEN_ERR_PASSIVE
#define SUN4I_INTEN_WAKEUP
#define SUN4I_INTEN_OR
#define SUN4I_INTEN_ERR_WRN
#define SUN4I_INTEN_TX
#define SUN4I_INTEN_RX

/* error code */
#define SUN4I_ERR_INRCV
#define SUN4I_ERR_INTRANS

/* filter mode */
#define SUN4I_FILTER_CLOSE
#define SUN4I_SINGLE_FLTER_MODE
#define SUN4I_DUAL_FILTER_MODE

/* message buffer flags */
#define SUN4I_MSG_EFF_FLAG
#define SUN4I_MSG_RTR_FLAG

/* max. number of interrupts handled in ISR */
#define SUN4I_CAN_MAX_IRQ
#define SUN4I_MODE_MAX_RETRIES

/**
 * struct sun4ican_quirks - Differences between SoC variants.
 *
 * @has_reset: SoC needs reset deasserted.
 * @acp_offset: Offset of ACPC and ACPM registers
 */
struct sun4ican_quirks {};

struct sun4ican_priv {};

static const struct can_bittiming_const sun4ican_bittiming_const =;

static void sun4i_can_write_cmdreg(struct sun4ican_priv *priv, u8 val)
{}

static int set_normal_mode(struct net_device *dev)
{}

static int set_reset_mode(struct net_device *dev)
{}

/* bittiming is called in reset_mode only */
static int sun4ican_set_bittiming(struct net_device *dev)
{}

static int sun4ican_get_berr_counter(const struct net_device *dev,
				     struct can_berr_counter *bec)
{}

static int sun4i_can_start(struct net_device *dev)
{}

static int sun4i_can_stop(struct net_device *dev)
{}

static int sun4ican_set_mode(struct net_device *dev, enum can_mode mode)
{}

/* transmit a CAN message
 * message layout in the sk_buff should be like this:
 * xx xx xx xx         ff         ll 00 11 22 33 44 55 66 77
 * [ can_id ] [flags] [len] [can data (up to 8 bytes]
 */
static netdev_tx_t sun4ican_start_xmit(struct sk_buff *skb, struct net_device *dev)
{}

static void sun4i_can_rx(struct net_device *dev)
{}

static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
{}

static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id)
{}

static int sun4ican_open(struct net_device *dev)
{}

static int sun4ican_close(struct net_device *dev)
{}

static const struct net_device_ops sun4ican_netdev_ops =;

static const struct ethtool_ops sun4ican_ethtool_ops =;

static const struct sun4ican_quirks sun4ican_quirks_a10 =;

static const struct sun4ican_quirks sun4ican_quirks_r40 =;

static const struct sun4ican_quirks sun4ican_quirks_d1 =;

static const struct of_device_id sun4ican_of_match[] =;

MODULE_DEVICE_TABLE(of, sun4ican_of_match);

static void sun4ican_remove(struct platform_device *pdev)
{}

static int sun4ican_probe(struct platform_device *pdev)
{}

static struct platform_driver sun4i_can_driver =;

module_platform_driver();

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