linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] c_can: Add support for eg20t (pch_can)
@ 2014-04-03 14:14 Alexander Stein
  2014-04-03 14:55 ` Alexander Stein
  2014-04-03 18:41 ` Wolfgang Grandegger
  0 siblings, 2 replies; 37+ messages in thread
From: Alexander Stein @ 2014-04-03 14:14 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc, "Kleine-Budde <mkl"
  Cc: Alexander Stein, linux-can

Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
---
 drivers/net/can/c_can/c_can_pci.c | 50 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c
index bce0be5..128788c 100644
--- a/drivers/net/can/c_can/c_can_pci.c
+++ b/drivers/net/can/c_can/c_can_pci.c
@@ -19,9 +19,13 @@
 
 #include "c_can.h"
 
+#define PCI_DEVICE_ID_PCH_CAN	0x8818
+#define PCH_PCI_SOFT_RESET	0x01fc
+
 enum c_can_pci_reg_align {
 	C_CAN_REG_ALIGN_16,
 	C_CAN_REG_ALIGN_32,
+	C_CAN_REG_32,
 };
 
 struct c_can_pci_data {
@@ -31,6 +35,10 @@ struct c_can_pci_data {
 	enum c_can_pci_reg_align reg_align;
 	/* Set the frequency */
 	unsigned int freq;
+	/* PCI bar number */
+	int bar;
+	/* Callback for reset */
+	void (*init)(const struct c_can_priv *priv, bool enable);
 };
 
 /*
@@ -63,6 +71,29 @@ static void c_can_pci_write_reg_aligned_to_32bit(struct c_can_priv *priv,
 	writew(val, priv->base + 2 * priv->regs[index]);
 }
 
+static u16 c_can_pci_read_reg_32bit(struct c_can_priv *priv,
+				    enum reg index)
+{
+	return (u16)ioread32(priv->base + 2 * priv->regs[index]);
+}
+
+static void c_can_pci_write_reg_32bit(struct c_can_priv *priv,
+				      enum reg index, u16 val)
+{
+	iowrite32((u32)val, priv->base + 2 * priv->regs[index]);
+}
+
+static void c_can_pci_reset_pch(const struct c_can_priv *priv, bool enable)
+{
+	if (enable) {
+		u32 __iomem *addr = priv->base + PCH_PCI_SOFT_RESET;
+
+		/* write to sw reset register */
+		iowrite32(1, addr);
+		iowrite32(0, addr);
+	}
+}
+
 static int c_can_pci_probe(struct pci_dev *pdev,
 			   const struct pci_device_id *ent)
 {
@@ -87,7 +118,7 @@ static int c_can_pci_probe(struct pci_dev *pdev,
 	pci_set_master(pdev);
 	pci_enable_msi(pdev);
 
-	addr = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
+	addr = pci_iomap(pdev, c_can_pci_data->bar, pci_resource_len(pdev, 0));
 	if (!addr) {
 		dev_err(&pdev->dev,
 			"device has no PCI memory resources, "
@@ -142,11 +173,17 @@ static int c_can_pci_probe(struct pci_dev *pdev,
 		priv->read_reg = c_can_pci_read_reg_aligned_to_16bit;
 		priv->write_reg = c_can_pci_write_reg_aligned_to_16bit;
 		break;
+	case C_CAN_REG_32:
+		priv->read_reg = c_can_pci_read_reg_32bit;
+		priv->write_reg = c_can_pci_write_reg_32bit;
+		break;
 	default:
 		ret = -EINVAL;
 		goto out_free_c_can;
 	}
 
+	priv->raminit = c_can_pci_data->init;
+
 	ret = register_c_can_dev(dev);
 	if (ret) {
 		dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
@@ -193,6 +230,15 @@ static struct c_can_pci_data c_can_sta2x11= {
 	.type = BOSCH_C_CAN,
 	.reg_align = C_CAN_REG_ALIGN_32,
 	.freq = 52000000, /* 52 Mhz */
+	.bar = 0,
+};
+
+static struct c_can_pci_data c_can_pch = {
+	.type = BOSCH_C_CAN,
+	.reg_align = C_CAN_REG_32,
+	.freq = 50000000, /* 50 MHz */
+	.init = c_can_pci_reset_pch,
+	.bar = 1,
 };
 
 #define C_CAN_ID(_vend, _dev, _driverdata) {		\
@@ -202,6 +248,8 @@ static struct c_can_pci_data c_can_sta2x11= {
 static DEFINE_PCI_DEVICE_TABLE(c_can_pci_tbl) = {
 	C_CAN_ID(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_CAN,
 		 c_can_sta2x11),
+	C_CAN_ID(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH_CAN,
+		 c_can_pch),
 	{},
 };
 static struct pci_driver c_can_pci_driver = {
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2014-04-17 19:53 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-03 14:14 [PATCH] c_can: Add support for eg20t (pch_can) Alexander Stein
2014-04-03 14:55 ` Alexander Stein
2014-04-03 14:59   ` Marc Kleine-Budde
2014-04-03 15:11     ` Thomas Gleixner
2014-04-03 15:47       ` Alexander Stein
2014-04-03 19:28         ` Oliver Hartkopp
2014-04-03 20:59           ` Thomas Gleixner
2014-04-03 20:28         ` Thomas Gleixner
2014-04-03 18:41 ` Wolfgang Grandegger
2014-04-07  9:47   ` Alexander Stein
2014-04-07 10:19     ` Wolfgang Grandegger
2014-04-07 12:06     ` Thomas Gleixner
2014-04-07 12:07       ` Marc Kleine-Budde
2014-04-07 12:24         ` Alexander Stein
2014-04-07 12:34           ` Thomas Gleixner
2014-04-07 12:48             ` Alexander Stein
2014-04-07 12:56               ` Thomas Gleixner
2014-04-07 12:58                 ` Alexander Stein
2014-04-07 13:31                   ` Thomas Gleixner
2014-04-07 14:27                     ` Alexander Stein
2014-04-07 15:24                       ` Thomas Gleixner
2014-04-07 15:36                         ` Alexander Stein
2014-04-07 15:53                           ` Thomas Gleixner
2014-04-07 16:06                             ` Alexander Stein
2014-04-07 16:27                               ` Thomas Gleixner
2014-04-08  7:07                                 ` Alexander Stein
2014-04-08  8:26                                   ` Thomas Gleixner
2014-04-08  8:36                                     ` Alexander Stein
2014-04-08  7:18                                 ` Alexander Stein
2014-04-08  7:35                                   ` Thomas Gleixner
2014-04-07 16:27                             ` Wolfgang Grandegger
2014-04-07 20:03                               ` Thomas Gleixner
2014-04-08  6:17                                 ` Alexander Stein
2014-04-08  8:04                                   ` Thomas Gleixner
2014-04-07 18:11                         ` Marc Kleine-Budde
2014-04-07 18:15                           ` Thomas Gleixner
2014-04-17 19:53   ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).