Re: [PATCH v7 3/3] can: Allwinner A10/A20 CAN Controller support - Kernel module
On Tue, Sep 15, 2015 at 01:17:12AM +0200, Gerhard Bertelsmann wrote: > Kernel module for Allwinner A10/A20 CAN > > Signed-off-by: Gerhard Bertelsmann> --- > > drivers/net/can/Kconfig| 10 + > drivers/net/can/Makefile | 1 + > drivers/net/can/sun4i_can.c| 857 > + > 3 files changed, 868 insertions(+) > > > diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig > index e8c96b8..6d04183 100644 > --- a/drivers/net/can/Kconfig > +++ b/drivers/net/can/Kconfig > @@ -129,6 +129,16 @@ config CAN_RCAR > To compile this driver as a module, choose M here: the module will > be called rcar_can. > > +config CAN_SUN4I > + tristate "Allwinner A10 CAN controller" > + depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST > + ---help--- > + Say Y here if you want to use CAN controller found on Allwinner > + A10/A20 SoCs. > + > + To compile this driver as a module, choose M here: the module will > + be called sun4i_can. > + > config CAN_XILINXCAN > tristate "Xilinx CAN" > depends on ARCH_ZYNQ || ARM64 || MICROBLAZE || COMPILE_TEST > diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile > index c533c62..1f21cef 100644 > --- a/drivers/net/can/Makefile > +++ b/drivers/net/can/Makefile > @@ -27,6 +27,7 @@ obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o > obj-$(CONFIG_PCH_CAN)+= pch_can.o > obj-$(CONFIG_CAN_GRCAN) += grcan.o > obj-$(CONFIG_CAN_RCAR) += rcar_can.o > +obj-$(CONFIG_CAN_SUN4I) += sun4i_can.o > obj-$(CONFIG_CAN_XILINXCAN) += xilinx_can.o > > subdir-ccflags-y += -D__CHECK_ENDIAN__ > diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c > new file mode 100644 > index 000..8e32520 > --- /dev/null > +++ b/drivers/net/can/sun4i_can.c > @@ -0,0 +1,857 @@ > +/* > + * sun4i_can.c - CAN bus controller driver for Allwinner SUN4I 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 > + * Copyright (C) 2007 Wolfgang Grandegger > + * 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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define DRV_NAME "sun4i_can" > + > +/* Registers address (physical base address 0x01C2BC00) */ > +#define SUNXI_REG_MSEL_ADDR 0x /* CAN Mode Select */ > +#define SUNXI_REG_CMD_ADDR 0x0004 /* CAN Command */ >
Re: [PATCH v7 3/3] can: Allwinner A10/A20 CAN Controller support - Kernel module
On 09/15/2015 04:28 PM, Maxime Ripard wrote: >> +static int sunxican_get_berr_counter(const struct net_device *dev, >> + struct can_berr_counter *bec) >> +{ >> +struct sunxican_priv *priv = netdev_priv(dev); >> +u32 errors; >> +int err; >> + >> +err = clk_prepare_enable(priv->clk); >> +if (err) { >> +netdev_err(dev, "could not enable clock\n"); >> +return err; >> +} > > Can this function be called if the device is closed? If not, then this > clock calls are useless. Yes, that's why there are there. > >> +errors = readl(priv->base + SUNXI_REG_ERRC_ADDR); >> + >> +bec->txerr = errors & 0xFF; >> +bec->rxerr = (errors >> 16) & 0xFF; >> + >> +clk_disable_unprepare(priv->clk); >> + >> +return 0; >> +} [...] >> +static int sunxican_open(struct net_device *dev) >> +{ >> +struct sunxican_priv *priv = netdev_priv(dev); >> +int err; >> + >> +/* common open */ >> +err = open_candev(dev); >> +if (err) >> +return err; >> + >> +/* register interrupt handler */ >> +err = request_irq(dev->irq, sunxi_can_interrupt, IRQF_SHARED, > > We don't have any shared interrupt as far as I know, do you really > need this flag? Not needed, but the IRQ handler properly returns HANDLED or NONE. So it's better to remove this flag then? > >> + dev->name, dev); >> +if (err) { >> +netdev_err(dev, "request_irq err: %d\n", err); >> +goto exit_irq; >> +} >> + >> +/* turn on clocking for CAN peripheral block */ >> +err = clk_prepare_enable(priv->clk); >> +if (err) { >> +netdev_err(dev, "could not enable CAN peripheral clock\n"); >> +goto exit_clock; >> +} >> + >> +err = sunxi_can_start(dev); >> +if (err) { >> +netdev_err(dev, "could not start CAN peripheral\n"); >> +goto exit_can_start; >> +} >> + >> +can_led_event(dev, CAN_LED_EVENT_OPEN); >> +netif_start_queue(dev); >> + >> +return 0; >> + >> +exit_can_start: >> +clk_disable_unprepare(priv->clk); >> +exit_clock: >> +free_irq(dev->irq, dev); >> +exit_irq: >> +close_candev(dev); >> +return err; >> +} Marc -- Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions| Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917- | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de | signature.asc Description: OpenPGP digital signature
[PATCH v7 3/3] can: Allwinner A10/A20 CAN Controller support - Kernel module
Kernel module for Allwinner A10/A20 CAN Signed-off-by: Gerhard Bertelsmann--- drivers/net/can/Kconfig| 10 + drivers/net/can/Makefile | 1 + drivers/net/can/sun4i_can.c| 857 + 3 files changed, 868 insertions(+) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index e8c96b8..6d04183 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -129,6 +129,16 @@ config CAN_RCAR To compile this driver as a module, choose M here: the module will be called rcar_can. +config CAN_SUN4I + tristate "Allwinner A10 CAN controller" + depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST + ---help--- + Say Y here if you want to use CAN controller found on Allwinner + A10/A20 SoCs. + + To compile this driver as a module, choose M here: the module will + be called sun4i_can. + config CAN_XILINXCAN tristate "Xilinx CAN" depends on ARCH_ZYNQ || ARM64 || MICROBLAZE || COMPILE_TEST diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile index c533c62..1f21cef 100644 --- a/drivers/net/can/Makefile +++ b/drivers/net/can/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o obj-$(CONFIG_PCH_CAN) += pch_can.o obj-$(CONFIG_CAN_GRCAN)+= grcan.o obj-$(CONFIG_CAN_RCAR) += rcar_can.o +obj-$(CONFIG_CAN_SUN4I)+= sun4i_can.o obj-$(CONFIG_CAN_XILINXCAN)+= xilinx_can.o subdir-ccflags-y += -D__CHECK_ENDIAN__ diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c new file mode 100644 index 000..8e32520 --- /dev/null +++ b/drivers/net/can/sun4i_can.c @@ -0,0 +1,857 @@ +/* + * sun4i_can.c - CAN bus controller driver for Allwinner SUN4I 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 + * Copyright (C) 2007 Wolfgang Grandegger + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "sun4i_can" + +/* Registers address (physical base address 0x01C2BC00) */ +#define SUNXI_REG_MSEL_ADDR0x /* CAN Mode Select */ +#define SUNXI_REG_CMD_ADDR 0x0004 /* CAN Command */ +#define SUNXI_REG_STA_ADDR 0x0008 /* CAN Status */ +#define SUNXI_REG_INT_ADDR 0x000c /* CAN Interrupt Flag */ +#define SUNXI_REG_INTEN_ADDR 0x0010 /* CAN Interrupt Enable */ +#define SUNXI_REG_BTIME_ADDR 0x0014 /* CAN Bus Timing 0 */ +#define SUNXI_REG_TEWL_ADDR0x0018 /*