PATCH v2 0/4] M_CAN framework patches
Subsystems (5)
All
This patch series contains no code modifications. Based on Wolfgangs advice I moved the files to different names and committe them independently so they can be reviewed easier.
The first patch create the framework code abstracted from the main m_can.c. The second patch adapts the m_can.c to use the framework code The final patches add the TCAN device to the use the m_can framework.
Again these patches are RFC and no code modifications were made in v2. I will be updating the code based on this version.
Dan
Dan Murphy (4):
can: m_can: Create a m_can platform framework
can: m_can: Migrate the m_can code to use the framework
dt-bindings: can: tcan4x5x: Add DT bindings for TCAN4x5X driver
can: tcan4x5x: Add tcan4x5x driver to the kernel
.../devicetree/bindings/net/can/tcan4x5x.txt | 34 ++ drivers/net/can/m_can/Kconfig | 18 + drivers/net/can/m_can/Makefile | 4 +- drivers/net/can/m_can/m_can.c | 479 +++++++++--------- drivers/net/can/m_can/m_can_platform.c | 168 ++++++ drivers/net/can/m_can/m_can_platform.h | 100 ++++ drivers/net/can/m_can/tcan4x5x.c | 321 ++++++++++++ 7 files changed, 870 insertions(+), 254 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/can/tcan4x5x.txt create mode 100644 drivers/net/can/m_can/m_can_platform.c create mode 100644 drivers/net/can/m_can/m_can_platform.h create mode 100644 drivers/net/can/m_can/tcan4x5x.c
Signature · 1 line
2.20.0.rc2.7.g965798d1f2
RFC 1/1 PATCH v2 1/4] can: m_can: Create a m_can platform framework
Create a m_can platform framework that peripherial devices can register to and use common code and register sets. The peripherial devices may provide read/write and configuration support of the IP.
--- drivers/net/can/m_can/m_can_platform.c | 168 +++++++++++++++++++++++++ drivers/net/can/m_can/m_can_platform.h | 100 +++++++++++++++ 2 files changed, 268 insertions(+) create mode 100644 drivers/net/can/m_can/m_can_platform.c create mode 100644 drivers/net/can/m_can/m_can_platform.h
drivers/net/can/m_can/m_can_platform.c new file +168 -0
@@ -0,0 +1,168 @@ +/* +* CAN bus driver for Bosch M_CAN controller +* +* Copyright (C) 2014 Freescale Semiconductor, Inc. +* Dong Aisheng <[email protected]> +* +* Bosch M_CAN user manual can be obtained from: +* http://www.bosch-semiconductors.de/media/pdf_1/ipmodules_1/m_can/ +* mcan_users_manual_v302.pdf +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netdevice.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/can/dev.h> +#include <linux/pinctrl/consumer.h> + +#include "m_can_platform.h" + +static int m_can_plat_probe (struct platform_device *pdev) +{ +struct m_can_classdev *mcan_class; +struct net_device *dev; +struct m_can_priv *priv; +struct resource *res; +void __iomem *addr; +void __iomem *mram_addr; +int irq, ret =0 ; + + mcan_class =m_can_core_allocate_dev (&pdev->dev); +m_can_core_get_clocks (mcan_class); + + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"m_can" ); + addr =devm_ioremap_resource (&pdev->dev, res); + irq =platform_get_irq_byname (pdev,"int0" ); +if (IS_ERR (addr) || irq <0 ) { + ret = -EINVAL ; + goto failed_ret; + } + +/* message ram could be shared */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"message_ram" ); +if (!res) { + ret = -ENODEV ; + goto failed_ret; + } + + mram_addr =devm_ioremap (&pdev->dev, res->start,resource_size (res)); +if (!mram_addr) { + ret = -ENOMEM ; + goto failed_ret; + } + + mcan_class->net->irq = irq; + mcan_class->pm_clock_support =1 ; + mcan_class->mram_base = mram_addr; + mcan_class->can.clock.freq =clk_get_rate (mcan_class->cclk); + mcan_class->dev = &pdev->dev; + +platform_set_drvdata (pdev, mcan_class->dev); + +m_can_init_ram (mcan_class); + +m_can_core_register (mcan_class); + +failed_ret: +/* m_can_clk_stop(mcan_class);*/ +if (ret) { +pm_runtime_disable (&pdev->dev); +free_candev (mcan_class->net); + } +return ret; +} + +static __maybe_unused int m_can_suspend (struct device *dev) +{ +return m_can_core_suspend (dev); +} + +static __maybe_unused int m_can_resume (struct device *dev) +{ +return m_can_core_resume (dev); +} + +static void unregister_m_can_dev (struct net_device *dev) +{ +unregister_candev (dev); +} + +static int m_can_plat_remove (struct platform_device *pdev) +{ +struct net_device *dev =platform_get_drvdata (pdev); + +unregister_m_can_dev (dev); + +pm_runtime_disable (&pdev->dev); + +platform_set_drvdata (pdev,NULL ); + +free_candev (dev); + +return 0 ; +} + +static int __maybe_unused m_can_runtime_suspend (struct device *dev) +{ +struct net_device *ndev =dev_get_drvdata (dev); +struct m_can_classdev *priv =netdev_priv (ndev); + +clk_disable_unprepare (priv->cclk); +clk_disable_unprepare (priv->hclk); + +return 0 ; +} + +static int __maybe_unused m_can_runtime_resume (struct device *dev) +{ +struct net_device *ndev =dev_get_drvdata (dev); +struct m_can_classdev *priv =netdev_priv (ndev); +int err; + + err =clk_prepare_enable (priv->hclk); +if (err) +return err; + + err =clk_prepare_enable (priv->cclk); +if (err) +clk_disable_unprepare (priv->hclk); + +return err; +} + +static const struct dev_pm_ops m_can_pmops = { + SET_RUNTIME_PM_OPS(m_can_runtime_suspend, + m_can_runtime_resume, NULL) +SET_SYSTEM_SLEEP_PM_OPS (m_can_suspend, m_can_resume) +}; + +static const struct of_device_id m_can_of_table[] = { + { .compatible ="bosch,m_can" , .data =NULL }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (of, m_can_of_table); + +static struct platform_driver m_can_plat_driver = { + .driver = { + .name =KBUILD_MODNAME , + .of_match_table = m_can_of_table, + .pm = &m_can_pmops, + }, + .probe = m_can_plat_probe, + .remove = m_can_plat_remove, +}; + +module_platform_driver (m_can_plat_driver); + +MODULE_AUTHOR ("Dong Aisheng <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("CAN bus driver for Bosch M_CAN controller" );
drivers/net/can/m_can/m_can_platform.h new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
2.20.0.rc2.7.g965798d1f2
RFC 1/1 PATCH v2 2/4] can: m_can: Migrate the m_can code to use the framework
In reply to Dan MurphyMigrate the m_can code to use the m_can_platform framework code.
--- drivers/net/can/m_can/Kconfig | 12 + drivers/net/can/m_can/Makefile | 4 +- drivers/net/can/m_can/m_can.c | 479 ++++++++++++++++----------------- 3 files changed, 241 insertions(+), 254 deletions(-)
drivers/net/can/m_can/Kconfig +12 -0
@@ -1,5 +1,17 @@ config CAN_M_CAN + tristate "Bosch M_CAN support" + ---help--- + Say Y here if you want to support for Bosch M_CAN controller. + +config CAN_M_CAN_CORE + depends on CAN_M_CAN + tristate "Bosch M_CAN Core support" + ---help--- + Say Y here if you want to support for Bosch M_CAN controller. + +config CAN_M_CAN_PLATFORM depends on HAS_IOMEM + depends on CAN_M_CAN_CORE tristate "Bosch M_CAN devices" ---help--- Say Y here if you want to support for Bosch M_CAN controller.
drivers/net/can/m_can/Makefile +3 -1
@@ -2,4 +2,6 @@ # Makefile for the Bosch M_CAN controller driver. # -obj-$(CONFIG_CAN_M_CAN) += m_can.o +obj-$(CONFIG_CAN_M_CAN_CORE) += m_can.o +obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o +obj-$(CONFIG_CAN_M_CAN_TCAN4X5X) += tcan4x5x.o
drivers/net/can/m_can/m_can.c +226 -253
865 lines not on this page · raw message
Signature · 1 line
2.20.0.rc2.7.g965798d1f2
RFC 1/1 PATCH v2 3/4] dt-bindings: can: tcan4x5x: Add DT bindings for TCAN4x5X driver
In reply to Dan MurphyDT binding documentation for TI TCAN4x5x driver.
--- .../devicetree/bindings/net/can/tcan4x5x.txt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/can/tcan4x5x.txt
Documentation/devicetree/bindings/net/can/tcan4x5x.txt new file +34 -0
@@ -0,0 +1,34 @@ +Texas Instruments TCAN4x5x CAN Controller +================================================ + +This file provides device node information for the TCAN4x5x interface contains. + +Required properties: + - compatible: "ti,tcan4x5x" + - reg: 0 + - #address-cells : 1 + - #size-cells : 0 + - spi-max-frequency: Maximum frequency of the SPI bus the chip can + operate at should be less than or equal to 18 MHz. + - data-ready-gpios: Interrupt GPIO for data and error reporting. + - wake-up-gpios: Wake up GPIO to wake up the TCAN device + +See Documentation/devicetree/bindings/net/can/m_can.txt for additional +required property details. + +Optional properties: + - reset-gpios: Hardwired output GPIO. If not defined then software + reset. + +Example: +tcan4x5x: tcan4x5x@0 { + compatible = "ti,tcan4x5x"; + reg = <0>; + #address-cells = <1>; + #size-cells = <1>; + clocks = <&tclkin_ck>; + spi-max-frequency = <10000000>; + data-ready-gpios = <&gpio1 16 GPIO_ACTIVE_LOW>; + wake-up-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>; + reset-gpios = <&gpio1 27 GPIO_ACTIVE_LOW>; + };
Signature · 1 line
2.20.0.rc2.7.g965798d1f2
RFC 1/1 PATCH v2 4/4] can: tcan4x5x: Add tcan4x5x driver to the kernel
In reply to Dan MurphyAdd the TCAN4x5x SPI CAN driver. This device
uses the Bosch MCAN IP core along with a SPI
interface map. Leverage the MCAN common core
code to manage the MCAN IP.
This device has a special method to indicate a
write/read operation on the data payload.
--- drivers/net/can/m_can/Kconfig | 6 + drivers/net/can/m_can/tcan4x5x.c | 321 +++++++++++++++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100644 drivers/net/can/m_can/tcan4x5x.c
drivers/net/can/m_can/Kconfig +6 -0
@@ -15,3 +15,9 @@ config CAN_M_CAN_PLATFORM tristate "Bosch M_CAN devices" ---help--- Say Y here if you want to support for Bosch M_CAN controller. + +config CAN_M_CAN_TCAN4X5X + depends on CAN_M_CAN_CORE + tristate "TCAN4X5X M_CAN device" + ---help--- + Say Y here if you want to support for TI M_CAN controller.
drivers/net/can/m_can/tcan4x5x.c new file +321 -0
321 lines not on this page · raw message
Signature · 1 line
2.20.0.rc2.7.g965798d1f2