Netdev List
 help / color / mirror / Atom feed
* [PATCH 4/4] ARM:FlexCAN Controller for platform_ type
From: Bhaskar Upadhaya @ 2011-08-08 15:01 UTC (permalink / raw)
  To: netdev, mkl, holt, wg, davem, linuxppc-release, b22300,
	<socketcan-
  Cc: Bhaskar Upadhaya

Rearrange the existing ARM based FlexCAN implementation, so as to
support powerpc based FlexCAN on P1010.
Signed-off-by: Bhaskar Upadhaya <bhaskar.upadhaya@freescale.com>
---
 Based on http://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git
 Branch master

 drivers/net/can/flexcan.c       |  105 ++++++++++++++-------------------------
 drivers/net/can/flexcan_iface.c |   99 ++++++++++++++++++++++++++++++++++++
 2 files changed, 136 insertions(+), 68 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 1c1af24..b4d9afb 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -993,37 +993,29 @@ void __devexit unregister_flexcandev(struct net_device *dev)
 	unregister_candev(dev);
 }
 
-static int __devinit flexcan_probe(struct platform_device *pdev)
+int flexcan_dev_init(struct device *pdev, struct flexcan_resource flexcan_res,
+		 struct flexcan_interface *flexcan_ops)
 {
 	struct net_device *dev;
 	struct flexcan_priv *priv;
-	struct resource *mem;
 	struct clk *clk;
 	void __iomem *base;
-	resource_size_t mem_size;
-	int err, irq;
+	int err;
 
-	clk = clk_get(&pdev->dev, NULL);
+	clk = flexcan_ops->clk_get(pdev, NULL);
 	if (IS_ERR(clk)) {
-		dev_err(&pdev->dev, "no clock defined\n");
+		dev_err(pdev, "no clock defined\n");
 		err = PTR_ERR(clk);
 		goto failed_clock;
 	}
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	irq = platform_get_irq(pdev, 0);
-	if (!mem || irq <= 0) {
-		err = -ENODEV;
-		goto failed_get;
-	}
-
-	mem_size = resource_size(mem);
-	if (!request_mem_region(mem->start, mem_size, pdev->name)) {
+	if (!request_mem_region
+	    (flexcan_res.addr, flexcan_res.size, flexcan_res.drv_name)) {
 		err = -EBUSY;
-		goto failed_get;
+		goto failed_req;
 	}
 
-	base = ioremap(mem->start, mem_size);
+	base = ioremap(flexcan_res.addr, flexcan_res.size);
 	if (!base) {
 		err = -ENOMEM;
 		goto failed_map;
@@ -1036,11 +1028,11 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
 	}
 
 	dev->netdev_ops = &flexcan_netdev_ops;
-	dev->irq = irq;
+	dev->irq = flexcan_res.irq;
 	dev->flags |= IFF_ECHO; /* we support local echo in hardware */
 
 	priv = netdev_priv(dev);
-	priv->can.clock.freq = clk_get_rate(clk);
+	priv->can.clock.freq = flexcan_ops->clk_get_rate(clk);
 	priv->can.bittiming_const = &flexcan_bittiming_const;
 	priv->can.do_set_mode = flexcan_set_mode;
 	priv->can.do_get_berr_counter = flexcan_get_berr_counter;
@@ -1050,20 +1042,21 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
 	priv->base = base;
 	priv->dev = dev;
 	priv->clk = clk;
-	priv->pdata = pdev->dev.platform_data;
+	priv->pdata = pdev->platform_data;
+	priv->flexcan_ops = flexcan_ops;
 
 	netif_napi_add(dev, &priv->napi, flexcan_poll, FLEXCAN_NAPI_WEIGHT);
 
-	dev_set_drvdata(&pdev->dev, dev);
-	SET_NETDEV_DEV(dev, &pdev->dev);
+	dev_set_drvdata(pdev, dev);
+	SET_NETDEV_DEV(dev, pdev);
 
 	err = register_flexcandev(dev);
 	if (err) {
-		dev_err(&pdev->dev, "registering netdev failed\n");
+		dev_err(pdev, "registering netdev failed\n");
 		goto failed_register;
 	}
 
-	dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
+	dev_info(pdev, "device registered (reg_base=%p, irq=%d)\n",
 		 priv->base, dev->irq);
 
 	return 0;
@@ -1073,55 +1066,31 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
  failed_alloc:
 	iounmap(base);
  failed_map:
-	release_mem_region(mem->start, mem_size);
- failed_get:
+	release_mem_region(flexcan_res.addr, flexcan_res.size);
+ failed_req:
 	clk_put(clk);
  failed_clock:
 	return err;
 }
 
-static int __devexit flexcan_remove(struct platform_device *pdev)
+void flexcan_reg_dump(struct net_device *dev)
 {
-	struct net_device *dev = platform_get_drvdata(pdev);
-	struct flexcan_priv *priv = netdev_priv(dev);
-	struct resource *mem;
-
-	unregister_flexcandev(dev);
-	platform_set_drvdata(pdev, NULL);
-	iounmap(priv->base);
-
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(mem->start, resource_size(mem));
-
-	clk_put(priv->clk);
-
-	free_candev(dev);
-
-	return 0;
-}
-
-static struct platform_driver flexcan_driver = {
-	.driver.name = DRV_NAME,
-	.probe = flexcan_probe,
-	.remove = __devexit_p(flexcan_remove),
-};
-
-static int __init flexcan_init(void)
-{
-	pr_info("%s netdevice driver\n", DRV_NAME);
-	return platform_driver_register(&flexcan_driver);
-}
+	const struct flexcan_priv *priv = netdev_priv(dev);
+	struct flexcan_regs __iomem *regs = priv->base;
 
-static void __exit flexcan_exit(void)
-{
-	platform_driver_unregister(&flexcan_driver);
-	pr_info("%s: driver removed\n", DRV_NAME);
+	dev_dbg(dev->dev.parent, "can-mcr 0x%x \r\n can-ctrl 0x%x \r\n"
+			"can-ecr 0x%x \r\n can-esr 0x%x \r\n"
+			"can-rxgmask 0x%x \r\n can-rx14mask 0x%x \r\n"
+			"can-rx15mask 0x%x \r\n can-imask1 0x%x \r\n"
+			"can-iflag1 0x%x \r\n"
+			"in  func <%s> line <%d> \r\n",
+			flexcan_read(&regs->mcr),
+			flexcan_read(&regs->ctrl),
+			flexcan_read(&regs->ecr),
+			flexcan_read(&regs->esr),
+			flexcan_read(&regs->rxgmask),
+			flexcan_read(&regs->rx14mask),
+			flexcan_read(&regs->rx15mask),
+			flexcan_read(&regs->imask1),
+			flexcan_read(&regs->iflag1), __func__, __LINE__);
 }
-
-module_init(flexcan_init);
-module_exit(flexcan_exit);
-
-MODULE_AUTHOR("Sascha Hauer <kernel@pengutronix.de>, "
-	      "Marc Kleine-Budde <kernel@pengutronix.de>");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("CAN port driver for flexcan based chip");
diff --git a/drivers/net/can/flexcan_iface.c b/drivers/net/can/flexcan_iface.c
index 0c5f6dd..faa6c07 100644
--- a/drivers/net/can/flexcan_iface.c
+++ b/drivers/net/can/flexcan_iface.c
@@ -180,7 +180,55 @@ failed_req:
 	return err;
 }
 
+/**
+ * flexcan_plt_resource_init - initialize the resources for
+ *				"platform" type architecture like "ARM"
+ * @flexcan_res: input buffer filled with address for accessing h/w registers
+ *		of CAN
+ * @pdev: the CAN device to be used
+ * @flexcan_ops: input buffer containing different utility functions
+ *
+ * fills the flexcan_res with the address detail
+ * for accessing the h/w registers of FlexCAN block.
+ * flexcan_ops is filled with different clock functions and normal read/write
+ *
+ * Return value
+ *    - On Success
+ *	       0
+ *    - On Failure
+ *	   error value
+ */
+static int flexcan_plt_resource_init(struct flexcan_resource *flexcan_res,
+				 struct platform_device *pdev,
+				 struct flexcan_interface *flexcan_ops)
+{
+	int err, irq;
+	resource_size_t mem_size;
+	struct resource *mem;
+
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	irq = platform_get_irq(pdev, 0);
+	if (!mem || irq <= 0) {
+		dev_err(&pdev->dev, "Cannot map to irq\n");
+		err = -ENODEV;
+		goto failed_get;
+	}
+
+	mem_size = resource_size(mem);
+	flexcan_res->addr = mem->start;
+	flexcan_res->size = mem_size;
+	flexcan_res->drv_name = pdev->name;
+
+	flexcan_ops->clk_enable = clk_enable;
+	flexcan_ops->clk_disable = clk_disable;
+	flexcan_ops->clk_get_rate = clk_get_rate;
+	flexcan_ops->clk_get = clk_get;
+	flexcan_ops->clk_put = clk_put;
+	return 0;
 
+failed_get:
+	return err;
+}
 
 /**
  * flexcan_probe - performs the resource initialization
@@ -212,6 +260,15 @@ static int flexcan_probe(struct platform_device *pdev)
 			err = -EINVAL;
 			goto failed_req;
 		}
+	} else {
+		err = flexcan_plt_resource_init(&flexcan_res, pdev,
+						&flexcan_ops);
+		if (err) {
+			dev_err(&pdev->dev, "Flexcan Initialization"
+				 "failed with err (%d)\n", err);
+			err = -EINVAL;
+			goto failed_req;
+		}
 	}
 
 	err = flexcan_dev_init(&pdev->dev, flexcan_res, &flexcan_ops);
@@ -251,6 +308,9 @@ static int flexcan_remove(struct platform_device *pdev)
 		addr = of_translate_address(pdev->dev.of_node,
 		    of_get_address(pdev->dev.of_node, 0, &size, NULL));
 		release_mem_region(addr, size);
+	} else {
+		mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		release_mem_region(addr, size);
 	}	clk_put(priv->clk);
 
 	platform_set_drvdata(pdev, NULL);
@@ -259,3 +319,42 @@ static int flexcan_remove(struct platform_device *pdev)
 	return 0;
 }
 
+
+static struct of_device_id flexcan_match[] = {
+	{
+	 .compatible = "fsl,flexcan-v1.0",
+	 },
+	{},
+};
+
+MODULE_DEVICE_TABLE(of, flexcan_match);
+
+static struct platform_driver flexcan_driver = {
+	.driver = {
+		.name = "DRV_NAME",
+		.owner = THIS_MODULE,
+#ifdef CONFIG_OF
+		.of_match_table = flexcan_match,
+#endif
+	},
+	.probe = flexcan_probe,
+	.remove = flexcan_remove,
+};
+
+static int __init flexcan_init(void)
+{
+	return platform_driver_register(&flexcan_driver);
+}
+
+static void __exit flexcan_exit(void)
+{
+	platform_driver_unregister(&flexcan_driver);
+}
+
+module_init(flexcan_init);
+module_exit(flexcan_exit);
+
+MODULE_AUTHOR("Sascha Hauer <kernel@pengutronix.de>, "
+		"Marc Kleine-Budde <kernel@pengutronix.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("CAN port driver for flexcan based chip");
-- 
1.5.6.5



^ permalink raw reply related

* [PATCH 3/4] powerpc/p1010: FlexCAN Controller for of_ type
From: Bhaskar Upadhaya @ 2011-08-08 15:00 UTC (permalink / raw)
  To: netdev, mkl, holt, wg, davem, linuxppc-release, b22300,
	<socketcan-
  Cc: Bhaskar Upadhaya

Provide FlexCAN support for Freescale P1010 SoC.
Modify the existing FlexCAN, so as to support the of_type approach on
P1010(power architecture based)SoC.

FlexCAN is a communication controller implementing the CAN protocol according
to the CAN 2.0B protocol specification.
This controller is available on Freescale P1010 platform.
Signed-off-by: Bhaskar Upadhaya <bhaskar.upadhaya@freescale.com>
---
Based on git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git
 Branch master

 drivers/net/can/Kconfig         |    8 +-
 drivers/net/can/Makefile        |    4 +-
 drivers/net/can/flexcan.c       |  162 ++++++++++++------------
 drivers/net/can/flexcan_iface.c |  261 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 349 insertions(+), 86 deletions(-)
 create mode 100644 drivers/net/can/flexcan_iface.c

diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index f6c98fb..882da54 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -98,9 +98,12 @@ config HAVE_CAN_FLEXCAN
 
 config CAN_FLEXCAN
 	tristate "Support for Freescale FLEXCAN based chips"
-	depends on CAN_DEV && HAVE_CAN_FLEXCAN
+	depends on CAN_DEV && (!ARM || HAVE_CAN_FLEXCAN)
+	select PPC_CLOCK
 	---help---
-	  Say Y here if you want to support for Freescale FlexCAN.
+	  Say Y here if you want support for Freescale FlexCAN.
+	  Flexcan Module is implementing the CAN Protocol
+	  version 2.0
 
 config PCH_CAN
 	tristate "PCH CAN"
@@ -123,6 +126,7 @@ source "drivers/net/can/softing/Kconfig"
 config CAN_DEBUG_DEVICES
 	bool "CAN devices debugging messages"
 	depends on CAN
+	default N
 	---help---
 	  Say Y here if you want the CAN device drivers to produce a bunch of
 	  debug messages to the system log.  Select this if you are having
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 24ebfe8..4965e6f 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -19,7 +19,9 @@ obj-$(CONFIG_CAN_TI_HECC)	+= ti_hecc.o
 obj-$(CONFIG_CAN_MCP251X)	+= mcp251x.o
 obj-$(CONFIG_CAN_BFIN)		+= bfin_can.o
 obj-$(CONFIG_CAN_JANZ_ICAN3)	+= janz-ican3.o
-obj-$(CONFIG_CAN_FLEXCAN)	+= flexcan.o
+obj-$(CONFIG_CAN_FLEXCAN)	+= flexcan_driver.o
+flexcan_driver-objs := flexcan.o \
+		flexcan_iface.o
 obj-$(CONFIG_PCH_CAN)		+= pch_can.o
 
 ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index a24aa12..1c1af24 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -22,10 +22,8 @@
 
 #include <linux/netdevice.h>
 #include <linux/can.h>
-#include <linux/can/dev.h>
 #include <linux/can/error.h>
 #include <linux/can/platform/flexcan.h>
-#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>
@@ -34,11 +32,6 @@
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
-
-#include <mach/clock.h>
-
-#define DRV_NAME			"flexcan"
 
 /* 8 for RX fifo and 2 error handling */
 #define FLEXCAN_NAPI_WEIGHT		(8 + 2)
@@ -167,19 +160,6 @@ struct flexcan_regs {
 	struct flexcan_mb cantxfg[64];
 };
 
-struct flexcan_priv {
-	struct can_priv can;
-	struct net_device *dev;
-	struct napi_struct napi;
-
-	void __iomem *base;
-	u32 reg_esr;
-	u32 reg_ctrl_default;
-
-	struct clk *clk;
-	struct flexcan_platform_data *pdata;
-};
-
 static struct can_bittiming_const flexcan_bittiming_const = {
 	.name = DRV_NAME,
 	.tseg1_min = 4,
@@ -229,9 +209,10 @@ static inline void flexcan_chip_enable(struct flexcan_priv *priv)
 	struct flexcan_regs __iomem *regs = priv->base;
 	u32 reg;
 
-	reg = readl(&regs->mcr);
+	reg = flexcan_read(&regs->mcr);
+
 	reg &= ~FLEXCAN_MCR_MDIS;
-	writel(reg, &regs->mcr);
+	flexcan_write(reg, &regs->mcr);
 
 	udelay(10);
 }
@@ -248,9 +229,10 @@ static inline void flexcan_chip_disable(struct flexcan_priv *priv)
 	struct flexcan_regs __iomem *regs = priv->base;
 	u32 reg;
 
-	reg = readl(&regs->mcr);
+	reg = flexcan_read(&regs->mcr);
+
 	reg |= FLEXCAN_MCR_MDIS;
-	writel(reg, &regs->mcr);
+	flexcan_write(reg, &regs->mcr);
 }
 
 /**
@@ -266,9 +248,9 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
 {
 	const struct flexcan_priv *priv = netdev_priv(dev);
 	struct flexcan_regs __iomem *regs = priv->base;
-	u32 reg = readl(&regs->ecr);
 
-	bec->txerr = (reg >> 0) & 0xff;
+	u32 reg = flexcan_read(&regs->ecr);
+	bec->txerr = reg & 0xff;
 	bec->rxerr = (reg >> 8) & 0xff;
 
 	return 0;
@@ -294,6 +276,7 @@ static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	u32 can_id;
 	u32 ctrl = FLEXCAN_MB_CNT_CODE(0xc) | (cf->can_dlc << 16);
 
+	flexcan_reg_dump(dev);
 	if (can_dropped_invalid_skb(dev, skb))
 		return NETDEV_TX_OK;
 
@@ -311,21 +294,24 @@ static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	if (cf->can_dlc > 0) {
 		u32 data = be32_to_cpup((__be32 *)&cf->data[0]);
-		writel(data, &regs->cantxfg[FLEXCAN_TX_BUF_ID].data[0]);
+		flexcan_write(data,
+			&regs->cantxfg[FLEXCAN_TX_BUF_ID].data[0]);
 	}
 	if (cf->can_dlc > 3) {
 		u32 data = be32_to_cpup((__be32 *)&cf->data[4]);
-		writel(data, &regs->cantxfg[FLEXCAN_TX_BUF_ID].data[1]);
+		flexcan_write(data,
+			&regs->cantxfg[FLEXCAN_TX_BUF_ID].data[1]);
 	}
 
-	writel(can_id, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_id);
-	writel(ctrl, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_ctrl);
+	flexcan_write(can_id, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_id);
+	flexcan_write(ctrl, &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_ctrl);
 
 	kfree_skb(skb);
 
 	/* tx_packets is incremented in flexcan_irq */
 	stats->tx_bytes += cf->can_dlc;
 
+	flexcan_reg_dump(dev);
 	return NETDEV_TX_OK;
 }
 
@@ -440,7 +426,8 @@ static void do_state(struct net_device *dev,
 				CAN_ERR_CRTL_TX_WARNING :
 				CAN_ERR_CRTL_RX_WARNING;
 		}
-	case CAN_STATE_ERROR_WARNING:	/* fallthrough */
+		/* fallthrough */
+	case CAN_STATE_ERROR_WARNING:
 		/*
 		 * from: ERROR_ACTIVE, ERROR_WARNING
 		 * to  : ERROR_PASSIVE, BUS_OFF
@@ -536,8 +523,8 @@ static void flexcan_read_fifo(const struct net_device *dev,
 	struct flexcan_mb __iomem *mb = &regs->cantxfg[0];
 	u32 reg_ctrl, reg_id;
 
-	reg_ctrl = readl(&mb->can_ctrl);
-	reg_id = readl(&mb->can_id);
+	reg_ctrl = flexcan_read(&mb->can_ctrl);
+	reg_id = flexcan_read(&mb->can_id);
 	if (reg_ctrl & FLEXCAN_MB_CNT_IDE)
 		cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
 	else
@@ -547,12 +534,13 @@ static void flexcan_read_fifo(const struct net_device *dev,
 		cf->can_id |= CAN_RTR_FLAG;
 	cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf);
 
-	*(__be32 *)(cf->data + 0) = cpu_to_be32(readl(&mb->data[0]));
-	*(__be32 *)(cf->data + 4) = cpu_to_be32(readl(&mb->data[1]));
+	*(__be32 *) (&cf->data[0]) =
+	    cpu_to_be32(flexcan_read(&mb->data[0]));
+	*(__be32 *) (&cf->data[4]) =
+	    cpu_to_be32(flexcan_read(&mb->data[1]));
 
 	/* mark as read */
-	writel(FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, &regs->iflag1);
-	readl(&regs->timer);
+	flexcan_write(FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, &regs->iflag1);
 }
 
 static int flexcan_read_frame(struct net_device *dev)
@@ -596,17 +584,17 @@ static int flexcan_poll(struct napi_struct *napi, int quota)
 	 * The error bits are cleared on read,
 	 * use saved value from irq handler.
 	 */
-	reg_esr = readl(&regs->esr) | priv->reg_esr;
+	reg_esr = flexcan_read(&regs->esr) | priv->reg_esr;
 
 	/* handle state changes */
 	work_done += flexcan_poll_state(dev, reg_esr);
 
 	/* handle RX-FIFO */
-	reg_iflag1 = readl(&regs->iflag1);
-	while (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE &&
-	       work_done < quota) {
+	reg_iflag1 = flexcan_read(&regs->iflag1);
+	while ((reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) &&
+	       (work_done < quota)) {
 		work_done += flexcan_read_frame(dev);
-		reg_iflag1 = readl(&regs->iflag1);
+		reg_iflag1 = flexcan_read(&regs->iflag1);
 	}
 
 	/* report bus errors */
@@ -616,8 +604,8 @@ static int flexcan_poll(struct napi_struct *napi, int quota)
 	if (work_done < quota) {
 		napi_complete(napi);
 		/* enable IRQs */
-		writel(FLEXCAN_IFLAG_DEFAULT, &regs->imask1);
-		writel(priv->reg_ctrl_default, &regs->ctrl);
+		flexcan_write(FLEXCAN_IFLAG_DEFAULT, &regs->imask1);
+		flexcan_write(priv->reg_ctrl_default, &regs->ctrl);
 	}
 
 	return work_done;
@@ -641,9 +629,10 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	struct flexcan_regs __iomem *regs = priv->base;
 	u32 reg_iflag1, reg_esr;
 
-	reg_iflag1 = readl(&regs->iflag1);
-	reg_esr = readl(&regs->esr);
-	writel(FLEXCAN_ESR_ERR_INT, &regs->esr);	/* ACK err IRQ */
+	flexcan_reg_dump(dev);
+	reg_iflag1 = flexcan_read(&regs->iflag1);
+	reg_esr = flexcan_read(&regs->esr);
+	flexcan_write(FLEXCAN_ESR_ERR_INT, &regs->esr);/* ACK err IRQ */
 
 	/*
 	 * schedule NAPI in case of:
@@ -659,16 +648,17 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 		 * save them for later use.
 		 */
 		priv->reg_esr = reg_esr & FLEXCAN_ESR_ERR_BUS;
-		writel(FLEXCAN_IFLAG_DEFAULT & ~FLEXCAN_IFLAG_RX_FIFO_AVAILABLE,
-		       &regs->imask1);
-		writel(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
-		       &regs->ctrl);
+		flexcan_write(FLEXCAN_IFLAG_DEFAULT &
+			~FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, &regs->imask1);
+		flexcan_write(priv->reg_ctrl_default &
+			~FLEXCAN_CTRL_ERR_ALL, &regs->ctrl);
 		napi_schedule(&priv->napi);
 	}
 
 	/* FIFO overflow */
 	if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_OVERFLOW) {
-		writel(FLEXCAN_IFLAG_RX_FIFO_OVERFLOW, &regs->iflag1);
+		flexcan_write(FLEXCAN_IFLAG_RX_FIFO_OVERFLOW,
+			&regs->iflag1);
 		dev->stats.rx_over_errors++;
 		dev->stats.rx_errors++;
 	}
@@ -677,10 +667,11 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	if (reg_iflag1 & (1 << FLEXCAN_TX_BUF_ID)) {
 		/* tx_bytes is incremented in flexcan_start_xmit */
 		stats->tx_packets++;
-		writel((1 << FLEXCAN_TX_BUF_ID), &regs->iflag1);
+		flexcan_write((1 << FLEXCAN_TX_BUF_ID), &regs->iflag1);
 		netif_wake_queue(dev);
 	}
 
+	flexcan_reg_dump(dev);
 	return IRQ_HANDLED;
 }
 
@@ -698,7 +689,7 @@ static void flexcan_set_bittiming(struct net_device *dev)
 	struct flexcan_regs __iomem *regs = priv->base;
 	u32 reg;
 
-	reg = readl(&regs->ctrl);
+	reg = flexcan_read(&regs->ctrl);
 	reg &= ~(FLEXCAN_CTRL_PRESDIV(0xff) |
 		 FLEXCAN_CTRL_RJW(0x3) |
 		 FLEXCAN_CTRL_PSEG1(0x7) |
@@ -722,11 +713,11 @@ static void flexcan_set_bittiming(struct net_device *dev)
 		reg |= FLEXCAN_CTRL_SMP;
 
 	dev_info(dev->dev.parent, "writing ctrl=0x%08x\n", reg);
-	writel(reg, &regs->ctrl);
+	flexcan_write(reg, &regs->ctrl);
 
 	/* print chip status */
 	dev_dbg(dev->dev.parent, "%s: mcr=0x%08x ctrl=0x%08x\n", __func__,
-		readl(&regs->mcr), readl(&regs->ctrl));
+		flexcan_read(&regs->mcr), flexcan_read(&regs->ctrl));
 }
 
 /**
@@ -751,10 +742,10 @@ static int flexcan_chip_start(struct net_device *dev)
 	flexcan_chip_enable(priv);
 
 	/* soft reset */
-	writel(FLEXCAN_MCR_SOFTRST, &regs->mcr);
+	flexcan_write(FLEXCAN_MCR_SOFTRST, &regs->mcr);
 	udelay(10);
 
-	reg_mcr = readl(&regs->mcr);
+	reg_mcr = flexcan_read(&regs->mcr);
 	if (reg_mcr & FLEXCAN_MCR_SOFTRST) {
 		dev_err(dev->dev.parent,
 			"Failed to softreset can module (mcr=0x%08x)\n",
@@ -776,12 +767,12 @@ static int flexcan_chip_start(struct net_device *dev)
 	 * choose format C
 	 *
 	 */
-	reg_mcr = readl(&regs->mcr);
+	reg_mcr = flexcan_read(&regs->mcr);
 	reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_FEN | FLEXCAN_MCR_HALT |
 		FLEXCAN_MCR_SUPV | FLEXCAN_MCR_WRN_EN |
 		FLEXCAN_MCR_IDAM_C;
 	dev_dbg(dev->dev.parent, "%s: writing mcr=0x%08x", __func__, reg_mcr);
-	writel(reg_mcr, &regs->mcr);
+	flexcan_write(reg_mcr, &regs->mcr);
 
 	/*
 	 * CTRL
@@ -799,7 +790,7 @@ static int flexcan_chip_start(struct net_device *dev)
 	 * (FLEXCAN_CTRL_ERR_MSK), too. Otherwise we don't get any
 	 * warning or bus passive interrupts.
 	 */
-	reg_ctrl = readl(&regs->ctrl);
+	reg_ctrl = flexcan_read(&regs->ctrl);
 	reg_ctrl &= ~FLEXCAN_CTRL_TSYN;
 	reg_ctrl |= FLEXCAN_CTRL_BOFF_REC | FLEXCAN_CTRL_LBUF |
 		FLEXCAN_CTRL_ERR_STATE | FLEXCAN_CTRL_ERR_MSK;
@@ -807,38 +798,40 @@ static int flexcan_chip_start(struct net_device *dev)
 	/* save for later use */
 	priv->reg_ctrl_default = reg_ctrl;
 	dev_dbg(dev->dev.parent, "%s: writing ctrl=0x%08x", __func__, reg_ctrl);
-	writel(reg_ctrl, &regs->ctrl);
+	flexcan_write(reg_ctrl, &regs->ctrl);
 
 	for (i = 0; i < ARRAY_SIZE(regs->cantxfg); i++) {
-		writel(0, &regs->cantxfg[i].can_ctrl);
-		writel(0, &regs->cantxfg[i].can_id);
-		writel(0, &regs->cantxfg[i].data[0]);
-		writel(0, &regs->cantxfg[i].data[1]);
+		flexcan_write(0, &regs->cantxfg[i].can_ctrl);
+		flexcan_write(0, &regs->cantxfg[i].can_id);
+		flexcan_write(0, &regs->cantxfg[i].data[0]);
+		flexcan_write(0, &regs->cantxfg[i].data[1]);
 
 		/* put MB into rx queue */
-		writel(FLEXCAN_MB_CNT_CODE(0x4), &regs->cantxfg[i].can_ctrl);
+		flexcan_write(FLEXCAN_MB_CNT_CODE(0x4),
+			&regs->cantxfg[i].can_ctrl);
 	}
 
 	/* acceptance mask/acceptance code (accept everything) */
-	writel(0x0, &regs->rxgmask);
-	writel(0x0, &regs->rx14mask);
-	writel(0x0, &regs->rx15mask);
+	flexcan_write(0x0, &regs->rxgmask);
+	flexcan_write(0x0, &regs->rx14mask);
+	flexcan_write(0x0, &regs->rx15mask);
 
 	flexcan_transceiver_switch(priv, 1);
 
 	/* synchronize with the can bus */
-	reg_mcr = readl(&regs->mcr);
+	reg_mcr = flexcan_read(&regs->mcr);
 	reg_mcr &= ~FLEXCAN_MCR_HALT;
-	writel(reg_mcr, &regs->mcr);
+	flexcan_write(reg_mcr, &regs->mcr);
 
 	priv->can.state = CAN_STATE_ERROR_ACTIVE;
 
 	/* enable FIFO interrupts */
-	writel(FLEXCAN_IFLAG_DEFAULT, &regs->imask1);
+	flexcan_write(FLEXCAN_IFLAG_DEFAULT, &regs->imask1);
 
 	/* print chip status */
 	dev_dbg(dev->dev.parent, "%s: reading mcr=0x%08x ctrl=0x%08x\n",
-		__func__, readl(&regs->mcr), readl(&regs->ctrl));
+		__func__, flexcan_read(&regs->mcr),
+			flexcan_read(&regs->ctrl));
 
 	return 0;
 
@@ -860,12 +853,12 @@ static void flexcan_chip_stop(struct net_device *dev)
 	u32 reg;
 
 	/* Disable all interrupts */
-	writel(0, &regs->imask1);
+	flexcan_write(0, &regs->imask1);
 
 	/* Disable + halt module */
-	reg = readl(&regs->mcr);
+	reg = flexcan_read(&regs->mcr);
 	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
-	writel(reg, &regs->mcr);
+	flexcan_write(reg, &regs->mcr);
 
 	flexcan_transceiver_switch(priv, 0);
 	priv->can.state = CAN_STATE_STOPPED;
@@ -935,6 +928,8 @@ static int flexcan_set_mode(struct net_device *dev, enum can_mode mode)
 		break;
 
 	default:
+		dev_dbg(dev->dev.parent, "Setting flexcan mode(%d) in func %s in line"
+					"%d \r\n", mode, __func__, __LINE__);
 		return -EOPNOTSUPP;
 	}
 
@@ -957,24 +952,24 @@ static int __devinit register_flexcandev(struct net_device *dev)
 
 	/* select "bus clock", chip must be disabled */
 	flexcan_chip_disable(priv);
-	reg = readl(&regs->ctrl);
+	reg = flexcan_read(&regs->ctrl);
 	reg |= FLEXCAN_CTRL_CLK_SRC;
-	writel(reg, &regs->ctrl);
+	flexcan_write(reg, &regs->ctrl);
 
 	flexcan_chip_enable(priv);
 
 	/* set freeze, halt and activate FIFO, restrict register access */
-	reg = readl(&regs->mcr);
+	reg = flexcan_read(&regs->mcr);
 	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT |
 		FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
-	writel(reg, &regs->mcr);
+	flexcan_write(reg, &regs->mcr);
 
 	/*
 	 * Currently we only support newer versions of this core
 	 * featuring a RX FIFO. Older cores found on some Coldfire
 	 * derivates are not yet supported.
 	 */
-	reg = readl(&regs->mcr);
+	reg = flexcan_read(&regs->mcr);
 	if (!(reg & FLEXCAN_MCR_FEN)) {
 		dev_err(dev->dev.parent,
 			"Could not enable RX FIFO, unsupported core\n");
@@ -984,6 +979,7 @@ static int __devinit register_flexcandev(struct net_device *dev)
 
 	err = register_candev(dev);
 
+	return err;
  out:
 	/* disable core and turn off clocks */
 	flexcan_chip_disable(priv);
@@ -992,7 +988,7 @@ static int __devinit register_flexcandev(struct net_device *dev)
 	return err;
 }
 
-static void __devexit unregister_flexcandev(struct net_device *dev)
+void __devexit unregister_flexcandev(struct net_device *dev)
 {
 	unregister_candev(dev);
 }
diff --git a/drivers/net/can/flexcan_iface.c b/drivers/net/can/flexcan_iface.c
new file mode 100644
index 0000000..0c5f6dd
--- /dev/null
+++ b/drivers/net/can/flexcan_iface.c
@@ -0,0 +1,261 @@
+/*
+ * flexcan_iface.c
+ *
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * Based on code originally by Andrey Volkov <avolkov@varma-el.com>
+ *
+ * LICENCE:
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/netdevice.h>
+#include <linux/can/platform/flexcan.h>
+
+struct flexcan_interface flexcan_ops;
+
+/**
+ * flexcan_of_get_clk_rate - returns the rate, used for bit-timing
+ *				calculations of FlexCAN
+ */
+static unsigned long flexcan_of_get_clk_rate(struct clk *clock)
+{
+	return clock->rate;
+}
+
+static void flexcan_of_clk_put(struct clk *clk)
+{
+	kfree(clk);
+}
+
+/**
+ * flexcan_of_clk_get - calculates the rate, used for bit-timing
+ *			calculations of FlexCAN
+ * @dev: the FlexCAN device to be used
+ * @id: id used to differentiate among different clock nodes
+ *
+ * calculate the rate based on the clock-frequency
+ * and clock-divider values from device tree.
+ * It calculate the rate being "platform" as the clock source
+ * Framework for "oscillator" as clock source is also provided.
+ *
+ * Return value
+ *    - On Success
+ *         the rate as part of clk struct, used to calculate the bit-timing
+ *	   for FlexCAN
+ *    - On Failure
+ *	   error value
+ */
+static struct clk *flexcan_of_clk_get(struct device *dev, const char *id)
+{
+	struct clk *clock;
+	u32 *clock_freq = NULL;
+	u32 *clock_divider = NULL;
+	const char *clk_source;
+	int err;
+	unsigned long rate;
+
+	clk_source = (char *)of_get_property(dev->of_node,
+			"fsl,flexcan-clock-source", NULL);
+	if (clk_source == NULL) {
+		dev_err(dev, "Cannot find fsl,flexcan-clock-source"
+				"property\n");
+		err = -EINVAL;
+		goto failed_clock;
+	}
+	if (!memcmp(clk_source, "platform", strlen(clk_source))) {
+		clock_divider = (u32 *)of_get_property(dev->of_node,
+				"fsl,flexcan-clock-divider", NULL);
+		if (*clock_divider) {
+			clock_freq = (u32 *) of_get_property(dev->of_node,
+					"clock-frequency", NULL);
+			if (clock_freq == NULL) {
+				dev_err(dev, "Cannot find clock-frequency"
+							"property\n");
+				err = -EINVAL;
+				goto failed_clock;
+			}
+			rate = DIV_ROUND_CLOSEST(*clock_freq / *clock_divider,
+						1000) * 1000;
+		} else {
+			dev_err(dev, "Cannot find valid fsl,"
+					"flexcan-clock-divider\n");
+			err = -EINVAL;
+			goto failed_clock;
+		}
+	} else if (!memcmp(clk_source, "oscillator", strlen(clk_source))) {
+		clock_divider = (u32 *)of_get_property(dev->of_node,
+				"fsl,flexcan-clock-divider", NULL);
+		clock_freq = (u32 *)of_get_property(dev->of_node,
+						"clock-frequency", NULL);
+		if (!(*clock_divider && *clock_freq)) {
+			dev_err(dev, "Cannot find valid"
+					"fsl,flexcan-clock-divider or"
+					"clock-frequency\n");
+			err = -EINVAL;
+			goto failed_clock;
+		} else { /*FIXME for keeping oscillator as clock-source*/
+				dev_err(dev, "oscillator as clock support is"
+						"not available\n");
+				err = -EINVAL;
+				goto failed_clock;
+		}
+	} else {
+		dev_err(dev, "Invalid flexcan-clock-source\n");
+		err = -EINVAL;
+		goto failed_clock;
+	}
+
+	clock = kmalloc(sizeof(struct clk), GFP_KERNEL);
+	if (!clock) {
+		dev_err(dev, "Cannot allocate memory\n");
+			err = -ENOMEM;
+		goto failed_clock;
+	}
+
+	clock->rate = rate;
+	dev_info(dev, "clock-frequency is  %lu in line %d in function %s\r\n",
+			clock->rate, __LINE__, __func__);
+	return clock;
+
+ failed_clock:
+	return ERR_PTR(err);
+}
+
+/**
+ * flexcan_of_resource_init - initialize the resources for
+ *				"of" type platform like powerpc
+ * @flexcan_res: input buffer filled with address for accessing h/w registers
+ *		of FlexCAN
+ * @pdev: the FlexCAN device to be used
+ * @flexcan_ops: input buffer containing different utility functions
+ *
+ * fills the flexcan_res with the address detail
+ * for accessing the h/w registers of FlexCAN block.
+ * flexcan_ops is filled with different clock functions and normal read/write
+ *
+ * Return value
+ *    - On Success
+ *	       0
+ *    - On Failure
+ *	   error value
+ */
+static int flexcan_of_resource_init(struct flexcan_resource *flexcan_res,
+					struct device *pdev,
+					struct flexcan_interface *flexcan_ops)
+{
+	u64 addr, size;
+	int err, irq;
+
+	addr = of_translate_address(pdev->of_node,
+			of_get_address(pdev->of_node, 0, &size, NULL));
+	flexcan_res->addr = addr;
+	flexcan_res->size = size;
+	flexcan_res->drv_name = pdev->driver->name;
+	irq = irq_of_parse_and_map(pdev->of_node, 0);
+	if (irq == NO_IRQ) {
+		dev_err(pdev, "cannot map to irq\n");
+		err = -EINVAL;
+		goto failed_req;
+	}
+
+	flexcan_res->irq = irq;
+
+	flexcan_ops->clk_enable = NULL;
+	flexcan_ops->clk_disable = NULL;
+	flexcan_ops->clk_get_rate = flexcan_of_get_clk_rate;
+	flexcan_ops->clk_get = flexcan_of_clk_get;
+	flexcan_ops->clk_put = flexcan_of_clk_put;
+	return 0;
+
+failed_req:
+	return err;
+}
+
+
+
+/**
+ * flexcan_probe - performs the resource initialization
+ *		   after detecting the architecture type like "of" or
+ *		   "platform" type
+ * @pdev: pointer to platform device
+ *
+ * initialises the resources based on "platform" or "of"
+ * type architecture.It also registers the FlexCAN with netdev layer.
+ *
+ * Return value
+ *    - On Success
+ *	       0
+ *    - On Failure
+ *	   error value
+ */
+static int flexcan_probe(struct platform_device *pdev)
+{
+	int err;
+	struct flexcan_resource flexcan_res;
+	struct device_node *np = pdev->dev.of_node;
+
+	if (np) {
+		err = flexcan_of_resource_init(&flexcan_res,
+					&pdev->dev, &flexcan_ops);
+		if (err) {
+			dev_err(&pdev->dev, "Flexcan Initialization"
+				 "failed with err (%d)\n", err);
+			err = -EINVAL;
+			goto failed_req;
+		}
+	}
+
+	err = flexcan_dev_init(&pdev->dev, flexcan_res, &flexcan_ops);
+	if (err) {
+		dev_err(&pdev->dev, "Flexcan Initialization failed with err"
+				"(%d)\n", err);
+		err = -EINVAL;
+		goto failed_req;
+	}
+
+	return 0;
+ failed_req:
+	return err;
+}
+
+/**
+ * flexcan_remove - performs the resource de-initialization
+ *		    after detecting the architecture type like "of" or
+ *		    "platform" type
+ * @pdev: pointer to platform device
+ *
+ * de-initializez the resources based on "platform" or "of"
+ * type architecture.It also unregister the FlexCAN with netdev layer.
+ */
+static int flexcan_remove(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct flexcan_priv *priv = netdev_priv(dev);
+	struct device_node *np = pdev->dev.of_node;
+	struct resource *mem;
+	u64 addr = 0, size;
+
+	unregister_flexcandev(dev);
+	iounmap(priv->base);
+
+	if (np) {
+		addr = of_translate_address(pdev->dev.of_node,
+		    of_get_address(pdev->dev.of_node, 0, &size, NULL));
+		release_mem_region(addr, size);
+	}	clk_put(priv->clk);
+
+	platform_set_drvdata(pdev, NULL);
+	free_candev(dev);
+
+	return 0;
+}
+
-- 
1.5.6.5



^ permalink raw reply related

* [PATCH 2/4][upstream] powerpc/p1010: Add description for FlexCAN functions
From: Bhaskar Upadhaya @ 2011-08-08 15:00 UTC (permalink / raw)
  To: netdev, mkl, holt, wg, davem, linuxppc-release, b22300,
	<socketcan-
  Cc: Bhaskar Upadhaya

Add description to the existing function of FlexCAN
Signed-off-by: Bhaskar Upadhaya <bhaskar.upadhaya@freescale.com>
---
 Based on http://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git
 Branch master

 drivers/net/can/flexcan.c |  121 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 111 insertions(+), 10 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 1767811..a24aa12 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2005-2006 Varma Electronics Oy
  * Copyright (c) 2009 Sascha Hauer, Pengutronix
  * Copyright (c) 2010 Marc Kleine-Budde, Pengutronix
+ * Copyright 2011 Freescale Semiconductor, Inc.
  *
  * Based on code originally by Andrey Volkov <avolkov@varma-el.com>
  *
@@ -191,8 +192,11 @@ static struct can_bittiming_const flexcan_bittiming_const = {
 	.brp_inc = 1,
 };
 
-/*
- * Swtich transceiver on or off
+/**
+ * flexcan_transceiver_switch - Switches the transceiver
+ *				on/off
+ * @priv: pointer to private data
+ * @on: 1 == turns transceiver on, 0 == turn it off
  */
 static void flexcan_transceiver_switch(const struct flexcan_priv *priv, int on)
 {
@@ -200,6 +204,12 @@ static void flexcan_transceiver_switch(const struct flexcan_priv *priv, int on)
 		priv->pdata->transceiver_switch(on);
 }
 
+/**
+ * flexcan_has_and_handle_berr - returns 0/1 after checking the
+ * Error and Status register.
+ * @priv: pointer to private data
+ * @reg_esr: error and status register.
+ */
 static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
 					      u32 reg_esr)
 {
@@ -207,6 +217,13 @@ static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
 		(reg_esr & FLEXCAN_ESR_ERR_BUS);
 }
 
+/**
+ * flexcan_chip_enable - enables the flexCAN
+ * @priv: pointer to private data
+ *
+ * Enables FlexCAN by writing to the MDIS bit
+ * of MCR
+ */
 static inline void flexcan_chip_enable(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->base;
@@ -219,6 +236,13 @@ static inline void flexcan_chip_enable(struct flexcan_priv *priv)
 	udelay(10);
 }
 
+/**
+ * flexcan_chip_disable - disables the flexCAN
+ * @priv: pointer to private data
+ *
+ * disables FlexCAN by writing to the MDIS bit
+ * of MCR
+ */
 static inline void flexcan_chip_disable(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->base;
@@ -229,6 +253,14 @@ static inline void flexcan_chip_disable(struct flexcan_priv *priv)
 	writel(reg, &regs->mcr);
 }
 
+/**
+ * flexcan_get_berr_counter - gets the Rx/Tx Error counter
+ * @dev: dev pointer of FlexCAN
+ * @bec: buffer to be filled with Tx/Rx Error Counter
+ *
+ * fills the tx/rx error counter values from the ECR
+ * register of FlexCAN
+ */
 static int flexcan_get_berr_counter(const struct net_device *dev,
 				    struct can_berr_counter *bec)
 {
@@ -242,6 +274,17 @@ static int flexcan_get_berr_counter(const struct net_device *dev,
 	return 0;
 }
 
+/**
+ * flexcan_start_xmit -
+ * @skb: socket buffer to hold CAN frames
+ * @dev: dev pointer of FlexCAN
+ *
+ * validates the incomming socket buffer and also
+ * prepares the message buffer for transmission process
+ *
+ * Return value
+ *    - NETDEV_TX_OK
+ */
 static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	const struct flexcan_priv *priv = netdev_priv(dev);
@@ -286,6 +329,16 @@ static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	return NETDEV_TX_OK;
 }
 
+/**
+ * do_bus_err - fills the FlexCAN Message buffer
+ *		depending on the Error and Status register
+ * @dev: dev pointer of FlexCAN
+ * @cf: can frame
+ * @reg_esr: error and status register
+ *
+ * checks the various error bits of Error and status
+ * register, and fills the message buffer of CAN frame accordingly
+ */
 static void do_bus_err(struct net_device *dev,
 		       struct can_frame *cf, u32 reg_esr)
 {
@@ -352,6 +405,16 @@ static int flexcan_poll_bus_err(struct net_device *dev, u32 reg_esr)
 	return 1;
 }
 
+/**
+ * do_state - updates the CAN frame depending on
+ *		CAN bus states
+ * @dev: dev pointer of FlexCAN
+ * @cf: can frame
+ * @new_state: CAN frame is filled in accordance with the new_state
+ *
+ * checks the new_state against various CAN bus states
+ * and fills the id and data fields of CAN frame accordingly
+ */
 static void do_state(struct net_device *dev,
 		     struct can_frame *cf, enum can_state new_state)
 {
@@ -418,6 +481,15 @@ static void do_state(struct net_device *dev,
 	}
 }
 
+/**
+ * flexcan_poll_state - polls FlexCAN state depending on the Fault
+ *			confinement state of ESR
+ * @dev: dev pointer of FlexCAN
+ * @reg_esr: Error and Status register
+ *
+ * polls for FlexCAN state ie busoff, error active,
+ * error passive or error warning depending on the fault confinement state
+ */
 static int flexcan_poll_state(struct net_device *dev, u32 reg_esr)
 {
 	struct flexcan_priv *priv = netdev_priv(dev);
@@ -504,6 +576,14 @@ static int flexcan_read_frame(struct net_device *dev)
 	return 1;
 }
 
+/**
+ * flexcan_poll - NAPI interface poll function
+ * @napi: napi pointer
+ * @quota: Number of packets to be processed
+ *
+ * checks whether the FIFO bits are set for Interrupt Flag1
+ * register and then process the received frames
+ */
 static int flexcan_poll(struct napi_struct *napi, int quota)
 {
 	struct net_device *dev = napi->dev;
@@ -543,6 +623,16 @@ static int flexcan_poll(struct napi_struct *napi, int quota)
 	return work_done;
 }
 
+/**
+ * flexcan_irq - ISR handler
+ * @irq: irq number
+ * @dev_id: device id
+ *
+ * handler gets called in the below context
+ * 1. When the frames are available in FIFO
+ * 2. FIFO Ovrflow
+ * 3. Transmission complete interrupt
+ */
 static irqreturn_t flexcan_irq(int irq, void *dev_id)
 {
 	struct net_device *dev = dev_id;
@@ -594,6 +684,13 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+/**
+ * flexcan_set_bittiming - Sets bit-timing paramaters
+ * @dev: dev pointer of FlexCAN
+ *
+ * sets the bit-timing parameters of FlexCAN
+ * responsible for CAN clock generation.
+ */
 static void flexcan_set_bittiming(struct net_device *dev)
 {
 	const struct flexcan_priv *priv = netdev_priv(dev);
@@ -632,11 +729,15 @@ static void flexcan_set_bittiming(struct net_device *dev)
 		readl(&regs->mcr), readl(&regs->ctrl));
 }
 
-/*
- * flexcan_chip_start
- *
- * this functions is entered with clocks enabled
+/**
+ * flexcan_chip_start - performs the basic CAN initialization
+ * @dev: dev pointer of FlexCAN
  *
+ * function is entered with clocks enabled
+ * It does the following
+ * 1. Enabling the CAN module
+ * 2. Basic registers initialization
+ * 3. Enabling FIFO
  */
 static int flexcan_chip_start(struct net_device *dev)
 {
@@ -746,11 +847,11 @@ static int flexcan_chip_start(struct net_device *dev)
 	return err;
 }
 
-/*
- * flexcan_chip_stop
- *
- * this functions is entered with clocks enabled
+/**
+ * flexcan_chip_stop -
+ * @dev: dev pointer of FlexCAN
  *
+ * disables the CAN
  */
 static void flexcan_chip_stop(struct net_device *dev)
 {
-- 
1.5.6.5



^ permalink raw reply related

* [PATCH 1/4][upstream] powerpc/p1010: Rearrange header file for FlexCAN
From: Bhaskar Upadhaya @ 2011-08-08 14:59 UTC (permalink / raw)
  To: netdev, mkl, holt, wg, davem, linuxppc-release, b22300,
	<socketcan-
  Cc: Bhaskar Upadhaya

- Rearrange header file so that it can be used by both of_ type
  and platform_ type architecture.
- Provide a common read and write interface for of_ type and platform_
  type architecture for accessing h/w registers.
Signed-off-by: Bhaskar Upadhaya <bhaskar.upadhaya@freescale.com>
---
 Based on http://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git
 Branch master

 include/linux/can/platform/flexcan.h |   65 ++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/include/linux/can/platform/flexcan.h b/include/linux/can/platform/flexcan.h
index 72b713a..8458a87 100644
--- a/include/linux/can/platform/flexcan.h
+++ b/include/linux/can/platform/flexcan.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Marc Kleine-Budde <kernel@pengutronix.de>
+ * Copyright 2011 Freescale Semiconductor, Inc.
  *
  * This file is released under the GPLv2
  *
@@ -8,6 +9,27 @@
 #ifndef __CAN_PLATFORM_FLEXCAN_H
 #define __CAN_PLATFORM_FLEXCAN_H
 
+#include <linux/clk.h>
+#include <linux/can/dev.h>
+#include <linux/io.h>
+
+#ifdef CONFIG_OF
+#include<linux/of_platform.h>
+#else
+#include <linux/platform_device.h>
+#include <mach/clock.h>
+#endif
+
+#define DRV_NAME "flexcan"
+
+#ifdef __BIG_ENDIAN
+#define flexcan_read(x)	in_be32(x)
+#define flexcan_write(x, y) out_be32(y, x)
+#else
+#define flexcan_read(x)	readl(x)
+#define flexcan_write(x, y) writel(x, y)
+#endif
+
 /**
  * struct flexcan_platform_data - flex CAN controller platform data
  * @transceiver_enable:         - called to power on/off the transceiver
@@ -17,4 +39,47 @@ struct flexcan_platform_data {
 	void (*transceiver_switch)(int enable);
 };
 
+struct flexcan_interface {
+	int (*clk_enable) (struct clk *clk);
+	void (*clk_disable) (struct clk *clk);
+	void (*clk_put) (struct clk *clk);
+	unsigned long (*clk_get_rate) (struct clk *clk);
+	struct clk *(*clk_get) (struct device *dev, const char *id);
+};
+
+struct flexcan_resource {
+	u32 irq;
+	u64 addr;
+	u64 size;
+	const char *drv_name;
+};
+
+#ifdef CONFIG_OF
+struct clk {
+	unsigned long		rate;
+	void			*data;
+};
+#endif
+
+struct flexcan_priv {
+	struct can_priv can;
+	struct net_device *dev;
+	struct napi_struct napi;
+
+	void __iomem *base;
+	u32 reg_esr;
+	u32 reg_ctrl_default;
+
+	struct clk *clk;
+	struct flexcan_interface *flexcan_ops;
+	struct flexcan_platform_data *pdata;
+};
+
+int flexcan_dev_init(struct device *pdev, struct flexcan_resource
+			flexcan_res, struct flexcan_interface *flexcan_ops);
+
+void __devexit unregister_flexcandev(struct net_device *dev);
+
+void flexcan_reg_dump(struct net_device *dev);
+
 #endif /* __CAN_PLATFORM_FLEXCAN_H */
-- 
1.5.6.5



^ permalink raw reply related

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Wolfgang Grandegger @ 2011-08-08 14:59 UTC (permalink / raw)
  To: Robin Holt
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, U Bhaskar-B22300,
	Marc Kleine-Budde, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <20110808144424.GY4926-sJ/iWh9BUns@public.gmane.org>

On 08/08/2011 04:44 PM, Robin Holt wrote:
> On Mon, Aug 08, 2011 at 04:37:44PM +0200, Wolfgang Grandegger wrote:
>> On 08/08/2011 04:21 PM, Robin Holt wrote:
>>> On Mon, Aug 08, 2011 at 04:16:27PM +0200, Wolfgang Grandegger wrote:
>>>> On 08/08/2011 03:56 PM, Robin Holt wrote:
>>>>>> commit 65bb8b060a873fa4f5188f2951081f6011259614
>>>>>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>>>>>> Date:   Fri Mar 4 20:27:58 2011 +0530
>>>>>
>>>>> On a side note, that commit fixes up "fsl,flexcan-v1.0"
>>>>> ...
>>>>> +       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
>>>>> +                       "clock_freq", gd->bus_clk, 1);
>>>>>
>>>>> Should I go back to flexcan-v1.0 in my patches?
>>>>
>>>> Well, no. Let's wait. I don't think we need it. Also, it sets
>>>> "clock_freq" while
>>>>
>>>>  http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
>>>>
>>>> documents "clock-frequencies"... :-(.
>>>
>>> You answered a different question that I was asking.  I was asking if
>>> I should change fsl,flexcan back to fsl,flexcan-v1.0 as documented on
>>> line 5.  The clock_freq looks like a uboot change will need to be made
>>> as well.
>>
>> Well, I wrote above: "Well, no. Let's wait. I don't think we need it."
>>
>> For the P1010 we can sinmply derive the clock frequency from
>> "fsl_get_sys_freq()", which is fine for the time being. No extra
>> properties, etc. The clk implemetation might go into
>>
>>  http://lxr.linux.no/#linux+v3.0.1/arch/powerpc/platforms/85xx/clock.c
>>
>> or
>>
>>  http://lxr.linux.no/#linux+v3.0.1/arch/powerpc/sysdev/fsl_soc.c
>>
>> And may depend on HAVE_CAN_FLEXCAN
>>
>> BTW, I have not found HAVE_CAN_FLEXCAN in your patch. What kernel are
>> you using?
> 
> I am starting with the v3.0 kernel, apply one patch from the freescale BSP
> we receive under NDA which introduces the P1010RDB board into the QorIQ
> platform, and then work from there for the flexcan stuff.  That patch
> introduces the HAVE_CAN_FLEXCAN.  I do not like how freescale structured
> that Kconfig bit, so I have tweaked it to be selected automatically
> when P1010RDB, NET, and CAN are selected.  That allows the CAN_FLEXCAN
> selection to determine is we are going to build the flexcan.c file.

ARM boards select HAVE_CAN_FLEXCAN and I do not see a good reason why
we should do it differently for PowerPC. 

For mainline inclusion, you should provide your patches against the
David Millers "net-next-2.6" tree, which already seems to have support
for the P1010RDB:

  config P1010_RDB
        bool "Freescale P1010RDB"
        select DEFAULT_UIMAGE
        help
          This option enables support for the MPC85xx RDB (P1010 RDB) board

          P1010RDB contains P1010Si, which provides CPU performance up to 800
          MHz and 1600 DMIPS, additional functionality and faster interfaces
          (DDR3/3L, SATA II, and PCI  Express).


> Our contact with Freescale would prefer that I not post that patch until
> we get the OK from freescale to do so since we received it under NDA.

I don't think we currently need it. I prefer dropping and cleaning up
the device tree stuff as it is not needed for the P1010 anyway. If a
new processor shows up with enhanced capabilities requiring
configuration via device tree, we or somebody else can provide a patch.
Marc, what do you think?

Wolfgang.

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Robin Holt @ 2011-08-08 14:48 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, Marc Kleine-Budde,
	U Bhaskar-B22300, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <4E3FF4B8.2010603-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>

On Mon, Aug 08, 2011 at 04:37:44PM +0200, Wolfgang Grandegger wrote:
> On 08/08/2011 04:21 PM, Robin Holt wrote:
> > On Mon, Aug 08, 2011 at 04:16:27PM +0200, Wolfgang Grandegger wrote:
> >> On 08/08/2011 03:56 PM, Robin Holt wrote:
> >>>> commit 65bb8b060a873fa4f5188f2951081f6011259614
> >>>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >>>> Date:   Fri Mar 4 20:27:58 2011 +0530
> >>>
> >>> On a side note, that commit fixes up "fsl,flexcan-v1.0"
> >>> ...
> >>> +       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
> >>> +                       "clock_freq", gd->bus_clk, 1);
> >>>
> >>> Should I go back to flexcan-v1.0 in my patches?
> >>
> >> Well, no. Let's wait. I don't think we need it. Also, it sets
> >> "clock_freq" while
> >>
> >>  http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> >>
> >> documents "clock-frequencies"... :-(.
> > 
> > You answered a different question that I was asking.  I was asking if
> > I should change fsl,flexcan back to fsl,flexcan-v1.0 as documented on
> > line 5.  The clock_freq looks like a uboot change will need to be made
> > as well.
> 
> Well, I wrote above: "Well, no. Let's wait. I don't think we need it."

My question remains "What should we be naming the device tree node in
general.  Line 5 of the fsl-flexcan.txt file specifically calls the node
"fsl,flexcan-v1.0"  In the .dts file the freescale patches introduces into
the arch/powerpc portion of the kernel, they call it that same thing.
Likewise, in the code already checked into uboot it is the same name.
Whether it is needed or not for the clock frequency, it does need to
be consistent between the .dts file and the driver for device discovery
to work.

Thanks,
Robin

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Robin Holt @ 2011-08-08 14:44 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, Marc Kleine-Budde,
	U Bhaskar-B22300, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <4E3FF4B8.2010603-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>

On Mon, Aug 08, 2011 at 04:37:44PM +0200, Wolfgang Grandegger wrote:
> On 08/08/2011 04:21 PM, Robin Holt wrote:
> > On Mon, Aug 08, 2011 at 04:16:27PM +0200, Wolfgang Grandegger wrote:
> >> On 08/08/2011 03:56 PM, Robin Holt wrote:
> >>>> commit 65bb8b060a873fa4f5188f2951081f6011259614
> >>>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >>>> Date:   Fri Mar 4 20:27:58 2011 +0530
> >>>
> >>> On a side note, that commit fixes up "fsl,flexcan-v1.0"
> >>> ...
> >>> +       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
> >>> +                       "clock_freq", gd->bus_clk, 1);
> >>>
> >>> Should I go back to flexcan-v1.0 in my patches?
> >>
> >> Well, no. Let's wait. I don't think we need it. Also, it sets
> >> "clock_freq" while
> >>
> >>  http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> >>
> >> documents "clock-frequencies"... :-(.
> > 
> > You answered a different question that I was asking.  I was asking if
> > I should change fsl,flexcan back to fsl,flexcan-v1.0 as documented on
> > line 5.  The clock_freq looks like a uboot change will need to be made
> > as well.
> 
> Well, I wrote above: "Well, no. Let's wait. I don't think we need it."
> 
> For the P1010 we can sinmply derive the clock frequency from
> "fsl_get_sys_freq()", which is fine for the time being. No extra
> properties, etc. The clk implemetation might go into
> 
>  http://lxr.linux.no/#linux+v3.0.1/arch/powerpc/platforms/85xx/clock.c
> 
> or
> 
>  http://lxr.linux.no/#linux+v3.0.1/arch/powerpc/sysdev/fsl_soc.c
> 
> And may depend on HAVE_CAN_FLEXCAN
> 
> BTW, I have not found HAVE_CAN_FLEXCAN in your patch. What kernel are
> you using?

I am starting with the v3.0 kernel, apply one patch from the freescale BSP
we receive under NDA which introduces the P1010RDB board into the QorIQ
platform, and then work from there for the flexcan stuff.  That patch
introduces the HAVE_CAN_FLEXCAN.  I do not like how freescale structured
that Kconfig bit, so I have tweaked it to be selected automatically
when P1010RDB, NET, and CAN are selected.  That allows the CAN_FLEXCAN
selection to determine is we are going to build the flexcan.c file.

Our contact with Freescale would prefer that I not post that patch until
we get the OK from freescale to do so since we received it under NDA.

Robin
> 
> Wolfgang.

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Wolfgang Grandegger @ 2011-08-08 14:37 UTC (permalink / raw)
  To: Robin Holt
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, Marc Kleine-Budde,
	U Bhaskar-B22300, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <20110808142153.GW4926-sJ/iWh9BUns@public.gmane.org>

On 08/08/2011 04:21 PM, Robin Holt wrote:
> On Mon, Aug 08, 2011 at 04:16:27PM +0200, Wolfgang Grandegger wrote:
>> On 08/08/2011 03:56 PM, Robin Holt wrote:
>>>> commit 65bb8b060a873fa4f5188f2951081f6011259614
>>>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>>>> Date:   Fri Mar 4 20:27:58 2011 +0530
>>>
>>> On a side note, that commit fixes up "fsl,flexcan-v1.0"
>>> ...
>>> +       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
>>> +                       "clock_freq", gd->bus_clk, 1);
>>>
>>> Should I go back to flexcan-v1.0 in my patches?
>>
>> Well, no. Let's wait. I don't think we need it. Also, it sets
>> "clock_freq" while
>>
>>  http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
>>
>> documents "clock-frequencies"... :-(.
> 
> You answered a different question that I was asking.  I was asking if
> I should change fsl,flexcan back to fsl,flexcan-v1.0 as documented on
> line 5.  The clock_freq looks like a uboot change will need to be made
> as well.

Well, I wrote above: "Well, no. Let's wait. I don't think we need it."

For the P1010 we can sinmply derive the clock frequency from
"fsl_get_sys_freq()", which is fine for the time being. No extra
properties, etc. The clk implemetation might go into

 http://lxr.linux.no/#linux+v3.0.1/arch/powerpc/platforms/85xx/clock.c

or

 http://lxr.linux.no/#linux+v3.0.1/arch/powerpc/sysdev/fsl_soc.c

And may depend on HAVE_CAN_FLEXCAN

BTW, I have not found HAVE_CAN_FLEXCAN in your patch. What kernel are
you using?

Wolfgang.

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Robin Holt @ 2011-08-08 14:29 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
	netdev-u79uwXL29TY76Z2rM5mHXA, U Bhaskar-B22300,
	Wolfgang Grandegger
In-Reply-To: <4E3FF068.6070905-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

On Mon, Aug 08, 2011 at 04:19:20PM +0200, Marc Kleine-Budde wrote:
> On 08/08/2011 04:03 PM, Robin Holt wrote:
> > On Mon, Aug 08, 2011 at 03:44:36PM +0200, Marc Kleine-Budde wrote:
> >> On 08/08/2011 03:08 PM, Wolfgang Grandegger wrote:
> >>> On 08/08/2011 01:31 PM, Robin Holt wrote:
> >>>> On Mon, Aug 08, 2011 at 10:37:58AM +0200, Wolfgang Grandegger wrote:
> >>>>> On 08/06/2011 04:34 PM, Robin Holt wrote:
> >>>>>> flexcan driver needs the clk_get, clk_get_rate, etc functions
> >>>>>> to work.  This patch provides the minimum functionality.
> >>>>>
> >>>>> This needs some more general thoughts... apart from the question where
> >>>>> the code should go.
> >>>>>
> >>>>> Like for the MSCAN on the MPC5200, the user should be *able* to select
> >>>>> an appropriate clock source and divider via DTS node properties.
> >>>>> Currently it seems, that the DTS properties must match some
> >>>>> pre-configured values, most likely set by the boot loader. Please
> >>>>> correct me if I'm wrong. For me this is generic and should go into the
> >>>>> Flexcan driver. From there, a platform specific function, e.g.
> >>>>> flexcan_set_clock() might be called.
> >>>>
> >>>> OK.  Dug a bit more.  The p1010 built-in clocksource seems to be the
> >>>> periphereal clock frequency which is system bus frequency divided
> >>>> by 2.  The clock source can not be changed, but the clock divider can
> >>>> by freezing the interface and setting the CTRL register.  This appears
> >>>> to only be done by the boot loader.  I do not see why we can not leave
> >>>
> >>> And likely Freescale's bootloader does also fixup the DTS Flexcan node.
> >>> Ah, oh, there's already someting in the mainline U-BOOT:
> >>>
> >>> commit 65bb8b060a873fa4f5188f2951081f6011259614
> >>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >>> Date:   Fri Mar 4 20:27:58 2011 +0530
> >>>
> >>>     powerpc/85xx: Fix up clock_freq property in CAN node of dts
> >>>
> >>>     Fix up the device tree property associated with the Flexcan clock
> >>>     frequency. This property is used to calculate the bit timing parameters
> >>>     for Flexcan.
> >>>
> >>>     Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >>>     Signed-off-by: Kumar Gala <galak-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
> >>>
> >>>
> >>>> that functionality in the boot loader and then go back to a variation
> >>>> on my earlier flexcan_clk_* patch.  Is that close to the direction you
> >>>> think we should go or have I completely misunderstood your wishes?
> >>>
> >>> The boot loader might not chose the optimum clock source and frequency,
> >>> which might even be application dependent. Therefore it would be nice to
> >>> allow the user to change it if necessary. Some CAN interfaces do even
> >>> allow to use an external clock source. The main question is where we add
> >>> that functionality. As more as I think of it, the clock interface would
> >>> not be that bad, especially if it's available.
> >>>
> >>> Furthermore, if the bootloader sets the clock source and divider, we do
> >>> not need device tree properties for it. A simply register lookup would
> >>> reveal what values are used. We may just need the input clock source.
> >>
> >> If the bootloader touches the divider _in_ the flexcan core, that would
> >> make absolutely no sense. The clock divider in the flexcan core (in the
> >> CTRL register) is the bitrate pre-scaler calculated by the bit-timing
> >> algorithm.
> >>
> >> What we need in the device tree is, from my point of view.
> >> a) the used clock source (bus clock or xtal clock)
> >> b) the frequency of that clock
> >>
> >> These problems are solved on arm via:
> >> a) bus clock is hard coded [1]
> >> b) get that clock frequency via clk_get_rate().
> > 
> > Just to make sure I understand correctly, the clk_get_rate() return
> > value comes from the device tree and a mach specific handler, right?
> > And 'mach-specific' really means what, a processor family?
> 
> I'm talking about the mainline driver, that has no device tree support.
> The clock stuff on arm currently goes like this:

What is the difference between device tree support and the clkdev based
clock sources using of_match to find a clock source for a particular
device.  It looks to me like those are filled in based upon device tree
information, but I _TRULY_ do not know what I am talking about.

> The driver asks for the clock related to the device. The architecture
> code has previously connected the flexcan device to an arch specific
> (i.mx25, i.mx35) clock. That clock is returned. Enable/disable/get_rate
> are working on that specific clock.

I will go and study that some more.  I did my cross-compile using
mxs_defconfig.  Is there a better config I should be using?  I typically
compile a kernel with the drivers I desire and then build my cscope
database using the files used in that build.

Thanks,
Robin

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Robin Holt @ 2011-08-08 14:21 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, U Bhaskar-B22300,
	Marc Kleine-Budde, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <4E3FEFBB.9050103-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>

On Mon, Aug 08, 2011 at 04:16:27PM +0200, Wolfgang Grandegger wrote:
> On 08/08/2011 03:56 PM, Robin Holt wrote:
> >> commit 65bb8b060a873fa4f5188f2951081f6011259614
> >> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >> Date:   Fri Mar 4 20:27:58 2011 +0530
> > 
> > On a side note, that commit fixes up "fsl,flexcan-v1.0"
> > ...
> > +       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
> > +                       "clock_freq", gd->bus_clk, 1);
> > 
> > Should I go back to flexcan-v1.0 in my patches?
> 
> Well, no. Let's wait. I don't think we need it. Also, it sets
> "clock_freq" while
> 
>  http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt
> 
> documents "clock-frequencies"... :-(.

You answered a different question that I was asking.  I was asking if
I should change fsl,flexcan back to fsl,flexcan-v1.0 as documented on
line 5.  The clock_freq looks like a uboot change will need to be made
as well.

Robin

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Marc Kleine-Budde @ 2011-08-08 14:19 UTC (permalink / raw)
  To: Robin Holt
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
	netdev-u79uwXL29TY76Z2rM5mHXA, U Bhaskar-B22300,
	Wolfgang Grandegger
In-Reply-To: <20110808140340.GV4926-sJ/iWh9BUns@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 4582 bytes --]

On 08/08/2011 04:03 PM, Robin Holt wrote:
> On Mon, Aug 08, 2011 at 03:44:36PM +0200, Marc Kleine-Budde wrote:
>> On 08/08/2011 03:08 PM, Wolfgang Grandegger wrote:
>>> On 08/08/2011 01:31 PM, Robin Holt wrote:
>>>> On Mon, Aug 08, 2011 at 10:37:58AM +0200, Wolfgang Grandegger wrote:
>>>>> On 08/06/2011 04:34 PM, Robin Holt wrote:
>>>>>> flexcan driver needs the clk_get, clk_get_rate, etc functions
>>>>>> to work.  This patch provides the minimum functionality.
>>>>>
>>>>> This needs some more general thoughts... apart from the question where
>>>>> the code should go.
>>>>>
>>>>> Like for the MSCAN on the MPC5200, the user should be *able* to select
>>>>> an appropriate clock source and divider via DTS node properties.
>>>>> Currently it seems, that the DTS properties must match some
>>>>> pre-configured values, most likely set by the boot loader. Please
>>>>> correct me if I'm wrong. For me this is generic and should go into the
>>>>> Flexcan driver. From there, a platform specific function, e.g.
>>>>> flexcan_set_clock() might be called.
>>>>
>>>> OK.  Dug a bit more.  The p1010 built-in clocksource seems to be the
>>>> periphereal clock frequency which is system bus frequency divided
>>>> by 2.  The clock source can not be changed, but the clock divider can
>>>> by freezing the interface and setting the CTRL register.  This appears
>>>> to only be done by the boot loader.  I do not see why we can not leave
>>>
>>> And likely Freescale's bootloader does also fixup the DTS Flexcan node.
>>> Ah, oh, there's already someting in the mainline U-BOOT:
>>>
>>> commit 65bb8b060a873fa4f5188f2951081f6011259614
>>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>>> Date:   Fri Mar 4 20:27:58 2011 +0530
>>>
>>>     powerpc/85xx: Fix up clock_freq property in CAN node of dts
>>>
>>>     Fix up the device tree property associated with the Flexcan clock
>>>     frequency. This property is used to calculate the bit timing parameters
>>>     for Flexcan.
>>>
>>>     Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>>>     Signed-off-by: Kumar Gala <galak-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
>>>
>>>
>>>> that functionality in the boot loader and then go back to a variation
>>>> on my earlier flexcan_clk_* patch.  Is that close to the direction you
>>>> think we should go or have I completely misunderstood your wishes?
>>>
>>> The boot loader might not chose the optimum clock source and frequency,
>>> which might even be application dependent. Therefore it would be nice to
>>> allow the user to change it if necessary. Some CAN interfaces do even
>>> allow to use an external clock source. The main question is where we add
>>> that functionality. As more as I think of it, the clock interface would
>>> not be that bad, especially if it's available.
>>>
>>> Furthermore, if the bootloader sets the clock source and divider, we do
>>> not need device tree properties for it. A simply register lookup would
>>> reveal what values are used. We may just need the input clock source.
>>
>> If the bootloader touches the divider _in_ the flexcan core, that would
>> make absolutely no sense. The clock divider in the flexcan core (in the
>> CTRL register) is the bitrate pre-scaler calculated by the bit-timing
>> algorithm.
>>
>> What we need in the device tree is, from my point of view.
>> a) the used clock source (bus clock or xtal clock)
>> b) the frequency of that clock
>>
>> These problems are solved on arm via:
>> a) bus clock is hard coded [1]
>> b) get that clock frequency via clk_get_rate().
> 
> Just to make sure I understand correctly, the clk_get_rate() return
> value comes from the device tree and a mach specific handler, right?
> And 'mach-specific' really means what, a processor family?

I'm talking about the mainline driver, that has no device tree support.
The clock stuff on arm currently goes like this:

The driver asks for the clock related to the device. The architecture
code has previously connected the flexcan device to an arch specific
(i.mx25, i.mx35) clock. That clock is returned. Enable/disable/get_rate
are working on that specific clock.

hope that helps, Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

[-- Attachment #2: Type: text/plain, Size: 188 bytes --]

_______________________________________________
Socketcan-core mailing list
Socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public.gmane.org
https://lists.berlios.de/mailman/listinfo/socketcan-core

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Wolfgang Grandegger @ 2011-08-08 14:19 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
	netdev-u79uwXL29TY76Z2rM5mHXA, U Bhaskar-B22300
In-Reply-To: <4E3FE844.6090005-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

On 08/08/2011 03:44 PM, Marc Kleine-Budde wrote:
> On 08/08/2011 03:08 PM, Wolfgang Grandegger wrote:
>> On 08/08/2011 01:31 PM, Robin Holt wrote:
>>> On Mon, Aug 08, 2011 at 10:37:58AM +0200, Wolfgang Grandegger wrote:
>>>> On 08/06/2011 04:34 PM, Robin Holt wrote:
>>>>> flexcan driver needs the clk_get, clk_get_rate, etc functions
>>>>> to work.  This patch provides the minimum functionality.
>>>>
>>>> This needs some more general thoughts... apart from the question where
>>>> the code should go.
>>>>
>>>> Like for the MSCAN on the MPC5200, the user should be *able* to select
>>>> an appropriate clock source and divider via DTS node properties.
>>>> Currently it seems, that the DTS properties must match some
>>>> pre-configured values, most likely set by the boot loader. Please
>>>> correct me if I'm wrong. For me this is generic and should go into the
>>>> Flexcan driver. From there, a platform specific function, e.g.
>>>> flexcan_set_clock() might be called.
>>>
>>> OK.  Dug a bit more.  The p1010 built-in clocksource seems to be the
>>> periphereal clock frequency which is system bus frequency divided
>>> by 2.  The clock source can not be changed, but the clock divider can
>>> by freezing the interface and setting the CTRL register.  This appears
>>> to only be done by the boot loader.  I do not see why we can not leave
>>
>> And likely Freescale's bootloader does also fixup the DTS Flexcan node.
>> Ah, oh, there's already someting in the mainline U-BOOT:
>>
>> commit 65bb8b060a873fa4f5188f2951081f6011259614
>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>> Date:   Fri Mar 4 20:27:58 2011 +0530
>>
>>     powerpc/85xx: Fix up clock_freq property in CAN node of dts
>>
>>     Fix up the device tree property associated with the Flexcan clock
>>     frequency. This property is used to calculate the bit timing parameters
>>     for Flexcan.
>>
>>     Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>>     Signed-off-by: Kumar Gala <galak-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
>>
>>
>>> that functionality in the boot loader and then go back to a variation
>>> on my earlier flexcan_clk_* patch.  Is that close to the direction you
>>> think we should go or have I completely misunderstood your wishes?
>>
>> The boot loader might not chose the optimum clock source and frequency,
>> which might even be application dependent. Therefore it would be nice to
>> allow the user to change it if necessary. Some CAN interfaces do even
>> allow to use an external clock source. The main question is where we add
>> that functionality. As more as I think of it, the clock interface would
>> not be that bad, especially if it's available.
>>
>> Furthermore, if the bootloader sets the clock source and divider, we do
>> not need device tree properties for it. A simply register lookup would
>> reveal what values are used. We may just need the input clock source.
> 
> If the bootloader touches the divider _in_ the flexcan core, that would
> make absolutely no sense. The clock divider in the flexcan core (in the
> CTRL register) is the bitrate pre-scaler calculated by the bit-timing
> algorithm.

Right, as I realized in the meantime. I'm still looking for some special
p1010 registers for the divider. Unfortunately, the manual is only
available under NDA :-(.

> What we need in the device tree is, from my point of view.
> a) the used clock source (bus clock or xtal clock)
> b) the frequency of that clock

Yes, and maybe an additional divider, like available for the MPC512x:

http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/mpc5xxx-mscan.txt
http://lxr.linux.no/#linux+v3.0.1/drivers/net/can/mscan/mpc5xxx_can.c#L132

Here is documented what you can expect from the PowerPC SOCs:

http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt

And there they also speak an *additional" clock divider. Maybe that
forseen for the next generations. U Bhaska, could you clarify that? Thanks?

> These problems are solved on arm via:
> a) bus clock is hard coded [1]
> b) get that clock frequency via clk_get_rate().

OK. The clk interface is fine and it should derive the frequency from
the relevant register settings and the bus clock frequency.

> Marc
> 
> [1] I just talked to Sascha (the i.mx maintainer), there's no support
> for the xtal clock, which is the OSC_AUDIO on mx35, in the i.mx clock
> framework so far.

OK. We may want to provide an interface to select taht sometimes later,
also because the P1010 does only support *one* clock source.

Wolfgang.

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Wolfgang Grandegger @ 2011-08-08 14:16 UTC (permalink / raw)
  To: Robin Holt
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, U Bhaskar-B22300,
	Marc Kleine-Budde, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <20110808135630.GU4926-sJ/iWh9BUns@public.gmane.org>

On 08/08/2011 03:56 PM, Robin Holt wrote:
>> commit 65bb8b060a873fa4f5188f2951081f6011259614
>> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>> Date:   Fri Mar 4 20:27:58 2011 +0530
> 
> On a side note, that commit fixes up "fsl,flexcan-v1.0"
> ...
> +       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
> +                       "clock_freq", gd->bus_clk, 1);
> 
> Should I go back to flexcan-v1.0 in my patches?

Well, no. Let's wait. I don't think we need it. Also, it sets
"clock_freq" while

 http://lxr.linux.no/#linux+v3.0.1/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt

documents "clock-frequencies"... :-(.

Wolfgang,

^ permalink raw reply

* Re: [PATCH 02/12] headers, ax25: Add missing #include to <linux/netrom.h>, <linux/rose.h>
From: Ralf Baechle @ 2011-08-08 14:07 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: David Miller, netdev, linux-hams
In-Reply-To: <1312809440.2591.1141.camel@deadeye>

On Mon, Aug 08, 2011 at 02:17:20PM +0100, Ben Hutchings wrote:

> These headers use the ax25_address type defined in <linux/ax25.h>.
> 
> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>

Makes sense.

Acked-by: Ralf Baechle <ralf@linux-mips.org>

  Ralf

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Robin Holt @ 2011-08-08 14:03 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
	netdev-u79uwXL29TY76Z2rM5mHXA, U Bhaskar-B22300,
	Wolfgang Grandegger
In-Reply-To: <4E3FE844.6090005-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

On Mon, Aug 08, 2011 at 03:44:36PM +0200, Marc Kleine-Budde wrote:
> On 08/08/2011 03:08 PM, Wolfgang Grandegger wrote:
> > On 08/08/2011 01:31 PM, Robin Holt wrote:
> >> On Mon, Aug 08, 2011 at 10:37:58AM +0200, Wolfgang Grandegger wrote:
> >>> On 08/06/2011 04:34 PM, Robin Holt wrote:
> >>>> flexcan driver needs the clk_get, clk_get_rate, etc functions
> >>>> to work.  This patch provides the minimum functionality.
> >>>
> >>> This needs some more general thoughts... apart from the question where
> >>> the code should go.
> >>>
> >>> Like for the MSCAN on the MPC5200, the user should be *able* to select
> >>> an appropriate clock source and divider via DTS node properties.
> >>> Currently it seems, that the DTS properties must match some
> >>> pre-configured values, most likely set by the boot loader. Please
> >>> correct me if I'm wrong. For me this is generic and should go into the
> >>> Flexcan driver. From there, a platform specific function, e.g.
> >>> flexcan_set_clock() might be called.
> >>
> >> OK.  Dug a bit more.  The p1010 built-in clocksource seems to be the
> >> periphereal clock frequency which is system bus frequency divided
> >> by 2.  The clock source can not be changed, but the clock divider can
> >> by freezing the interface and setting the CTRL register.  This appears
> >> to only be done by the boot loader.  I do not see why we can not leave
> > 
> > And likely Freescale's bootloader does also fixup the DTS Flexcan node.
> > Ah, oh, there's already someting in the mainline U-BOOT:
> > 
> > commit 65bb8b060a873fa4f5188f2951081f6011259614
> > Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > Date:   Fri Mar 4 20:27:58 2011 +0530
> > 
> >     powerpc/85xx: Fix up clock_freq property in CAN node of dts
> > 
> >     Fix up the device tree property associated with the Flexcan clock
> >     frequency. This property is used to calculate the bit timing parameters
> >     for Flexcan.
> > 
> >     Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >     Signed-off-by: Kumar Gala <galak-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
> > 
> > 
> >> that functionality in the boot loader and then go back to a variation
> >> on my earlier flexcan_clk_* patch.  Is that close to the direction you
> >> think we should go or have I completely misunderstood your wishes?
> > 
> > The boot loader might not chose the optimum clock source and frequency,
> > which might even be application dependent. Therefore it would be nice to
> > allow the user to change it if necessary. Some CAN interfaces do even
> > allow to use an external clock source. The main question is where we add
> > that functionality. As more as I think of it, the clock interface would
> > not be that bad, especially if it's available.
> > 
> > Furthermore, if the bootloader sets the clock source and divider, we do
> > not need device tree properties for it. A simply register lookup would
> > reveal what values are used. We may just need the input clock source.
> 
> If the bootloader touches the divider _in_ the flexcan core, that would
> make absolutely no sense. The clock divider in the flexcan core (in the
> CTRL register) is the bitrate pre-scaler calculated by the bit-timing
> algorithm.
> 
> What we need in the device tree is, from my point of view.
> a) the used clock source (bus clock or xtal clock)
> b) the frequency of that clock
> 
> These problems are solved on arm via:
> a) bus clock is hard coded [1]
> b) get that clock frequency via clk_get_rate().

Just to make sure I understand correctly, the clk_get_rate() return
value comes from the device tree and a mach specific handler, right?
And 'mach-specific' really means what, a processor family?

Thanks,
Robin

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Robin Holt @ 2011-08-08 13:56 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w, Marc Kleine-Budde,
	U Bhaskar-B22300, netdev-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <4E3FDFC9.7080508-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>

> commit 65bb8b060a873fa4f5188f2951081f6011259614
> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> Date:   Fri Mar 4 20:27:58 2011 +0530

On a side note, that commit fixes up "fsl,flexcan-v1.0"
...
+       do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
+                       "clock_freq", gd->bus_clk, 1);

Should I go back to flexcan-v1.0 in my patches?

Robin

^ permalink raw reply

* Re: [RFC 5/5] [powerpc] Implement a p1010rdb clock source.
From: Marc Kleine-Budde @ 2011-08-08 13:44 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w,
	netdev-u79uwXL29TY76Z2rM5mHXA, U Bhaskar-B22300
In-Reply-To: <4E3FDFC9.7080508-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 3890 bytes --]

On 08/08/2011 03:08 PM, Wolfgang Grandegger wrote:
> On 08/08/2011 01:31 PM, Robin Holt wrote:
>> On Mon, Aug 08, 2011 at 10:37:58AM +0200, Wolfgang Grandegger wrote:
>>> On 08/06/2011 04:34 PM, Robin Holt wrote:
>>>> flexcan driver needs the clk_get, clk_get_rate, etc functions
>>>> to work.  This patch provides the minimum functionality.
>>>
>>> This needs some more general thoughts... apart from the question where
>>> the code should go.
>>>
>>> Like for the MSCAN on the MPC5200, the user should be *able* to select
>>> an appropriate clock source and divider via DTS node properties.
>>> Currently it seems, that the DTS properties must match some
>>> pre-configured values, most likely set by the boot loader. Please
>>> correct me if I'm wrong. For me this is generic and should go into the
>>> Flexcan driver. From there, a platform specific function, e.g.
>>> flexcan_set_clock() might be called.
>>
>> OK.  Dug a bit more.  The p1010 built-in clocksource seems to be the
>> periphereal clock frequency which is system bus frequency divided
>> by 2.  The clock source can not be changed, but the clock divider can
>> by freezing the interface and setting the CTRL register.  This appears
>> to only be done by the boot loader.  I do not see why we can not leave
> 
> And likely Freescale's bootloader does also fixup the DTS Flexcan node.
> Ah, oh, there's already someting in the mainline U-BOOT:
> 
> commit 65bb8b060a873fa4f5188f2951081f6011259614
> Author: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> Date:   Fri Mar 4 20:27:58 2011 +0530
> 
>     powerpc/85xx: Fix up clock_freq property in CAN node of dts
> 
>     Fix up the device tree property associated with the Flexcan clock
>     frequency. This property is used to calculate the bit timing parameters
>     for Flexcan.
> 
>     Signed-off-by: Bhaskar Upadhaya <Bhaskar.Upadhaya-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>     Signed-off-by: Kumar Gala <galak-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
> 
> 
>> that functionality in the boot loader and then go back to a variation
>> on my earlier flexcan_clk_* patch.  Is that close to the direction you
>> think we should go or have I completely misunderstood your wishes?
> 
> The boot loader might not chose the optimum clock source and frequency,
> which might even be application dependent. Therefore it would be nice to
> allow the user to change it if necessary. Some CAN interfaces do even
> allow to use an external clock source. The main question is where we add
> that functionality. As more as I think of it, the clock interface would
> not be that bad, especially if it's available.
> 
> Furthermore, if the bootloader sets the clock source and divider, we do
> not need device tree properties for it. A simply register lookup would
> reveal what values are used. We may just need the input clock source.

If the bootloader touches the divider _in_ the flexcan core, that would
make absolutely no sense. The clock divider in the flexcan core (in the
CTRL register) is the bitrate pre-scaler calculated by the bit-timing
algorithm.

What we need in the device tree is, from my point of view.
a) the used clock source (bus clock or xtal clock)
b) the frequency of that clock

These problems are solved on arm via:
a) bus clock is hard coded [1]
b) get that clock frequency via clk_get_rate().

Marc

[1] I just talked to Sascha (the i.mx maintainer), there's no support
for the xtal clock, which is the OSC_AUDIO on mx35, in the i.mx clock
framework so far.

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

[-- Attachment #2: Type: text/plain, Size: 188 bytes --]

_______________________________________________
Socketcan-core mailing list
Socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public.gmane.org
https://lists.berlios.de/mailman/listinfo/socketcan-core

^ permalink raw reply

* Re: [PATCH 1/5] Define the function to write sock's security context to seq_file.
From: Stephen Smalley @ 2011-08-08 13:25 UTC (permalink / raw)
  To: Rongqing Li; +Cc: netdev, selinux, lsm
In-Reply-To: <4E3FAD40.1020404@windriver.com>

On Mon, 2011-08-08 at 17:32 +0800, Rongqing Li wrote:
> On 08/05/2011 09:56 PM, Stephen Smalley wrote:
> > I'm not sure it is a good idea to output nothing if permission is denied
> > to the socket, as opposed to some well-defined string indicating that
> > condition.  Particularly if someone later adds another field to
> > the /proc files after the context; we don't want the contents of that
> > field to be interpreted as the context if permission was denied.
> >
> 
>  From your review, I redesign the output information as below.
> 
> when disable SELinux, print "(none)" in proc
> when enable  SELinux, no error on getting security context, print the 
> real security context
> when enable  SELinux, there is error on getting security context, print 
> "??"
> 
> Do you think it is OK?

It appears that netstat presently displays a "-" if it cannot obtain the
security context or pid/program name information, so perhaps you should
follow that convention whenever you cannot obtain a security context
regardless of the particular reason. Note that your logic shouldn't be
based on whether or not SELinux is enabled/disabled per se, but rather
based on whether the security module provides security contexts, which
can be determined by checking whether the secid is set to a non-zero
value by security_sk_getsecid().  The audit system (kernel/audit*.c)
uses similar logic to decide whether or not to log task security
contexts.

-- 
Stephen Smalley
National Security Agency


^ permalink raw reply

* [PATCH 12/12] headers, ppp: Add missing #include to <linux/if_ppp.h>
From: Ben Hutchings @ 2011-08-08 13:25 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Paul Mackerras, linux-ppp
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

<linux/if_ppp.h> uses various types defined in <linux/ppp_defs.h>.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 include/linux/if_ppp.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/if_ppp.h b/include/linux/if_ppp.h
index c9ad383..4d70e16 100644
--- a/include/linux/if_ppp.h
+++ b/include/linux/if_ppp.h
@@ -35,6 +35,7 @@
 
 #include <linux/types.h>
 #include <linux/compiler.h>
+#include <linux/ppp_defs.h>
 
 /*
  * Packet sizes
-- 
1.7.5.4



^ permalink raw reply related

* [PATCH 11/12] headers, scc: Add missing #include to <linux/scc.h>
From: Ben Hutchings @ 2011-08-08 13:24 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Joerg Reuter, Klaus Kudielka, linux-hams
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

<linux/scc.h> uses SIOCDEVPRIVATE, defined in <linux/sockios.h>.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
This file isn't listed in MAINTAINERS but appears to be associated with
one of the hamradio drivers; please could one of the hams claim it?

Ben.

 include/linux/scc.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/scc.h b/include/linux/scc.h
index 3495bd9..d5916e5 100644
--- a/include/linux/scc.h
+++ b/include/linux/scc.h
@@ -3,6 +3,7 @@
 #ifndef	_SCC_H
 #define	_SCC_H
 
+#include <linux/sockios.h>
 
 /* selection of hardware types */
 
-- 
1.7.5.4




^ permalink raw reply related

* [PATCH 10/12] headers, can: Add missing #include to <linux/can/bcm.h>
From: Ben Hutchings @ 2011-08-08 13:20 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Oliver Hartkopp, Urs Thuermann
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

<linux/can/bcm.h> uses type canid_t, defined in <linux/can.h>.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 include/linux/can/bcm.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/linux/can/bcm.h b/include/linux/can/bcm.h
index 1432b27..e96154d 100644
--- a/include/linux/can/bcm.h
+++ b/include/linux/can/bcm.h
@@ -15,6 +15,7 @@
 #define CAN_BCM_H
 
 #include <linux/types.h>
+#include <linux/can.h>
 
 /**
  * struct bcm_msg_head - head of messages to/from the broadcast manager
-- 
1.7.5.4




^ permalink raw reply related

* [PATCH 09/12] headers, xtables: Add missing #include <linux/netfilter.h>
From: Ben Hutchings @ 2011-08-08 13:20 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Patrick McHardy, netfilter-devel
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

Various headers use union nf_inet_addr, defined in <linux/netfilter.h>.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 include/linux/netfilter/xt_connlimit.h |    1 +
 include/linux/netfilter/xt_conntrack.h |    1 +
 include/linux/netfilter/xt_iprange.h   |    1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/include/linux/netfilter/xt_connlimit.h b/include/linux/netfilter/xt_connlimit.h
index 0ca66e9..d1366f0 100644
--- a/include/linux/netfilter/xt_connlimit.h
+++ b/include/linux/netfilter/xt_connlimit.h
@@ -2,6 +2,7 @@
 #define _XT_CONNLIMIT_H
 
 #include <linux/types.h>
+#include <linux/netfilter.h>
 
 struct xt_connlimit_data;
 
diff --git a/include/linux/netfilter/xt_conntrack.h b/include/linux/netfilter/xt_conntrack.h
index 74b904d..e3c041d 100644
--- a/include/linux/netfilter/xt_conntrack.h
+++ b/include/linux/netfilter/xt_conntrack.h
@@ -6,6 +6,7 @@
 #define _XT_CONNTRACK_H
 
 #include <linux/types.h>
+#include <linux/netfilter.h>
 #include <linux/netfilter/nf_conntrack_tuple_common.h>
 
 #define XT_CONNTRACK_STATE_BIT(ctinfo) (1 << ((ctinfo)%IP_CT_IS_REPLY+1))
diff --git a/include/linux/netfilter/xt_iprange.h b/include/linux/netfilter/xt_iprange.h
index c1f21a7..25fd7cf 100644
--- a/include/linux/netfilter/xt_iprange.h
+++ b/include/linux/netfilter/xt_iprange.h
@@ -2,6 +2,7 @@
 #define _LINUX_NETFILTER_XT_IPRANGE_H 1
 
 #include <linux/types.h>
+#include <linux/netfilter.h>
 
 enum {
 	IPRANGE_SRC     = 1 << 0,	/* match source IP address */
-- 
1.7.5.4




^ permalink raw reply related

* [PATCH 08/12] headers, netfilter: Add missing #include <limits.h> for userland
From: Ben Hutchings @ 2011-08-08 13:20 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Patrick McHardy, netfilter-devel
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

Various headers use INT_MIN and INT_MAX, which are defined for
userland in <limits.h>.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 include/linux/netfilter_decnet.h |    3 +++
 include/linux/netfilter_ipv4.h   |    3 +++
 include/linux/netfilter_ipv6.h   |    3 +++
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/linux/netfilter_decnet.h b/include/linux/netfilter_decnet.h
index 6f42536..0b09732 100644
--- a/include/linux/netfilter_decnet.h
+++ b/include/linux/netfilter_decnet.h
@@ -11,6 +11,9 @@
 
 /* only for userspace compatibility */
 #ifndef __KERNEL__
+
+#include <limits.h> /* for INT_MIN, INT_MAX */
+
 /* IP Cache bits. */
 /* Src IP address. */
 #define NFC_DN_SRC		0x0001
diff --git a/include/linux/netfilter_ipv4.h b/include/linux/netfilter_ipv4.h
index 29c7727..fa0946c 100644
--- a/include/linux/netfilter_ipv4.h
+++ b/include/linux/netfilter_ipv4.h
@@ -9,6 +9,9 @@
 
 /* only for userspace compatibility */
 #ifndef __KERNEL__
+
+#include <limits.h> /* for INT_MIN, INT_MAX */
+
 /* IP Cache bits. */
 /* Src IP address. */
 #define NFC_IP_SRC		0x0001
diff --git a/include/linux/netfilter_ipv6.h b/include/linux/netfilter_ipv6.h
index 1f7e300..57c0251 100644
--- a/include/linux/netfilter_ipv6.h
+++ b/include/linux/netfilter_ipv6.h
@@ -12,6 +12,9 @@
 
 /* only for userspace compatibility */
 #ifndef __KERNEL__
+
+#include <limits.h> /* for INT_MIN, INT_MAX */
+
 /* IP Cache bits. */
 /* Src IP address. */
 #define NFC_IP6_SRC              0x0001
-- 
1.7.5.4




^ permalink raw reply related

* [PATCH 07/12] headers, tipc: Add missing #include to <linux/tipc_config.h> for userland
From: Ben Hutchings @ 2011-08-08 13:19 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Jon Maloy, Allan Stephens, tipc-discussion
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

<linux/tipc_config.h> defines inline functions using ntohs() etc.
For userland these are defined in <arpa/inet.h>.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 include/linux/tipc_config.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/include/linux/tipc_config.h b/include/linux/tipc_config.h
index 0db2395..9730b0e 100644
--- a/include/linux/tipc_config.h
+++ b/include/linux/tipc_config.h
@@ -41,6 +41,10 @@
 #include <linux/string.h>
 #include <asm/byteorder.h>
 
+#ifndef __KERNEL__
+#include <arpa/inet.h> /* for ntohs etc. */
+#endif
+
 /*
  * Configuration
  *
-- 
1.7.5.4




^ permalink raw reply related

* [PATCH 06/12] headers, netfilter: Use kernel type names __u8, __u16, __u32
From: Ben Hutchings @ 2011-08-08 13:19 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Patrick McHardy, netfilter-devel
In-Reply-To: <1312809302.2591.1139.camel@deadeye>

These types are guaranteed to be defined by <linux/types.h> for
both userland and kernel, unlike u_intN_t.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 include/linux/netfilter_arp/arp_tables.h  |   14 +++++++-------
 include/linux/netfilter_ipv4/ip_tables.h  |   20 ++++++++++----------
 include/linux/netfilter_ipv6/ip6_tables.h |   22 +++++++++++-----------
 3 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/include/linux/netfilter_arp/arp_tables.h b/include/linux/netfilter_arp/arp_tables.h
index adbf4bf..e08565d 100644
--- a/include/linux/netfilter_arp/arp_tables.h
+++ b/include/linux/netfilter_arp/arp_tables.h
@@ -52,7 +52,7 @@ struct arpt_arp {
 	struct in_addr smsk, tmsk;
 
 	/* Device hw address length, src+target device addresses */
-	u_int8_t arhln, arhln_mask;
+	__u8 arhln, arhln_mask;
 	struct arpt_devaddr_info src_devaddr;
 	struct arpt_devaddr_info tgt_devaddr;
 
@@ -71,9 +71,9 @@ struct arpt_arp {
 	unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
 
 	/* Flags word */
-	u_int8_t flags;
+	__u8 flags;
 	/* Inverse flags */
-	u_int16_t invflags;
+	__u16 invflags;
 };
 
 /* Values for "flag" field in struct arpt_ip (general arp structure).
@@ -102,9 +102,9 @@ struct arpt_entry
 	struct arpt_arp arp;
 
 	/* Size of arpt_entry + matches */
-	u_int16_t target_offset;
+	__u16 target_offset;
 	/* Size of arpt_entry + matches + target */
-	u_int16_t next_offset;
+	__u16 next_offset;
 
 	/* Back pointer */
 	unsigned int comefrom;
@@ -260,8 +260,8 @@ extern unsigned int arpt_do_table(struct sk_buff *skb,
 
 struct compat_arpt_entry {
 	struct arpt_arp arp;
-	u_int16_t target_offset;
-	u_int16_t next_offset;
+	__u16 target_offset;
+	__u16 next_offset;
 	compat_uint_t comefrom;
 	struct compat_xt_counters counters;
 	unsigned char elems[0];
diff --git a/include/linux/netfilter_ipv4/ip_tables.h b/include/linux/netfilter_ipv4/ip_tables.h
index 64a5d95..db79231 100644
--- a/include/linux/netfilter_ipv4/ip_tables.h
+++ b/include/linux/netfilter_ipv4/ip_tables.h
@@ -81,12 +81,12 @@ struct ipt_ip {
 	unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
 
 	/* Protocol, 0 = ANY */
-	u_int16_t proto;
+	__u16 proto;
 
 	/* Flags word */
-	u_int8_t flags;
+	__u8 flags;
 	/* Inverse flags */
-	u_int8_t invflags;
+	__u8 invflags;
 };
 
 /* Values for "flag" field in struct ipt_ip (general ip structure). */
@@ -114,9 +114,9 @@ struct ipt_entry {
 	unsigned int nfcache;
 
 	/* Size of ipt_entry + matches */
-	u_int16_t target_offset;
+	__u16 target_offset;
 	/* Size of ipt_entry + matches + target */
-	u_int16_t next_offset;
+	__u16 next_offset;
 
 	/* Back pointer */
 	unsigned int comefrom;
@@ -149,9 +149,9 @@ struct ipt_entry {
 
 /* ICMP matching stuff */
 struct ipt_icmp {
-	u_int8_t type;				/* type to match */
-	u_int8_t code[2];			/* range of code */
-	u_int8_t invflags;			/* Inverse flags */
+	__u8 type;				/* type to match */
+	__u8 code[2];				/* range of code */
+	__u8 invflags;				/* Inverse flags */
 };
 
 /* Values for "inv" field for struct ipt_icmp. */
@@ -288,8 +288,8 @@ extern unsigned int ipt_do_table(struct sk_buff *skb,
 struct compat_ipt_entry {
 	struct ipt_ip ip;
 	compat_uint_t nfcache;
-	u_int16_t target_offset;
-	u_int16_t next_offset;
+	__u16 target_offset;
+	__u16 next_offset;
 	compat_uint_t comefrom;
 	struct compat_xt_counters counters;
 	unsigned char elems[0];
diff --git a/include/linux/netfilter_ipv6/ip6_tables.h b/include/linux/netfilter_ipv6/ip6_tables.h
index c9784f7..f549adc 100644
--- a/include/linux/netfilter_ipv6/ip6_tables.h
+++ b/include/linux/netfilter_ipv6/ip6_tables.h
@@ -81,14 +81,14 @@ struct ip6t_ip6 {
 	 *   MH do not match any packets.
 	 * - You also need to set IP6T_FLAGS_PROTO to "flags" to check protocol.
 	 */
-	u_int16_t proto;
+	__u16 proto;
 	/* TOS to match iff flags & IP6T_F_TOS */
-	u_int8_t tos;
+	__u8 tos;
 
 	/* Flags word */
-	u_int8_t flags;
+	__u8 flags;
 	/* Inverse flags */
-	u_int8_t invflags;
+	__u8 invflags;
 };
 
 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
@@ -118,9 +118,9 @@ struct ip6t_entry {
 	unsigned int nfcache;
 
 	/* Size of ipt_entry + matches */
-	u_int16_t target_offset;
+	__u16 target_offset;
 	/* Size of ipt_entry + matches + target */
-	u_int16_t next_offset;
+	__u16 next_offset;
 
 	/* Back pointer */
 	unsigned int comefrom;
@@ -186,9 +186,9 @@ struct ip6t_error {
 
 /* ICMP matching stuff */
 struct ip6t_icmp {
-	u_int8_t type;				/* type to match */
-	u_int8_t code[2];			/* range of code */
-	u_int8_t invflags;			/* Inverse flags */
+	__u8 type;				/* type to match */
+	__u8 code[2];				/* range of code */
+	__u8 invflags;				/* Inverse flags */
 };
 
 /* Values for "inv" field for struct ipt_icmp. */
@@ -298,8 +298,8 @@ extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
 struct compat_ip6t_entry {
 	struct ip6t_ip6 ipv6;
 	compat_uint_t nfcache;
-	u_int16_t target_offset;
-	u_int16_t next_offset;
+	__u16 target_offset;
+	__u16 next_offset;
 	compat_uint_t comefrom;
 	struct compat_xt_counters counters;
 	unsigned char elems[0];
-- 
1.7.5.4




^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox