mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-10-29 07:18:51 +01:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
23
drivers/net/can/c_can/Kconfig
Normal file
23
drivers/net/can/c_can/Kconfig
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
menuconfig CAN_C_CAN
|
||||
tristate "Bosch C_CAN/D_CAN devices"
|
||||
depends on HAS_IOMEM
|
||||
|
||||
if CAN_C_CAN
|
||||
|
||||
config CAN_C_CAN_PLATFORM
|
||||
tristate "Generic Platform Bus based C_CAN/D_CAN driver"
|
||||
---help---
|
||||
This driver adds support for the C_CAN/D_CAN chips connected
|
||||
to the "platform bus" (Linux abstraction for directly to the
|
||||
processor attached devices) which can be found on various
|
||||
boards from ST Microelectronics (http://www.st.com) like the
|
||||
SPEAr1310 and SPEAr320 evaluation boards & TI (www.ti.com)
|
||||
boards like am335x, dm814x, dm813x and dm811x.
|
||||
|
||||
config CAN_C_CAN_PCI
|
||||
tristate "Generic PCI Bus based C_CAN/D_CAN driver"
|
||||
depends on PCI
|
||||
---help---
|
||||
This driver adds support for the C_CAN/D_CAN chips connected
|
||||
to the PCI bus.
|
||||
endif
|
||||
7
drivers/net/can/c_can/Makefile
Normal file
7
drivers/net/can/c_can/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Makefile for the Bosch C_CAN controller drivers.
|
||||
#
|
||||
|
||||
obj-$(CONFIG_CAN_C_CAN) += c_can.o
|
||||
obj-$(CONFIG_CAN_C_CAN_PLATFORM) += c_can_platform.o
|
||||
obj-$(CONFIG_CAN_C_CAN_PCI) += c_can_pci.o
|
||||
1278
drivers/net/can/c_can/c_can.c
Normal file
1278
drivers/net/can/c_can/c_can.c
Normal file
File diff suppressed because it is too large
Load diff
207
drivers/net/can/c_can/c_can.h
Normal file
207
drivers/net/can/c_can/c_can.h
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* CAN bus driver for Bosch C_CAN controller
|
||||
*
|
||||
* Copyright (C) 2010 ST Microelectronics
|
||||
* Bhupesh Sharma <bhupesh.sharma@st.com>
|
||||
*
|
||||
* Borrowed heavily from the C_CAN driver originally written by:
|
||||
* Copyright (C) 2007
|
||||
* - Sascha Hauer, Marc Kleine-Budde, Pengutronix <s.hauer@pengutronix.de>
|
||||
* - Simon Kallweit, intefo AG <simon.kallweit@intefo.ch>
|
||||
*
|
||||
* Bosch C_CAN controller is compliant to CAN protocol version 2.0 part A and B.
|
||||
* Bosch C_CAN user manual can be obtained from:
|
||||
* http://www.semiconductors.bosch.de/media/en/pdf/ipmodules_1/c_can/
|
||||
* users_manual_c_can.pdf
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public
|
||||
* License version 2. This program is licensed "as is" without any
|
||||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#ifndef C_CAN_H
|
||||
#define C_CAN_H
|
||||
|
||||
/* message object split */
|
||||
#define C_CAN_NO_OF_OBJECTS 32
|
||||
#define C_CAN_MSG_OBJ_RX_NUM 16
|
||||
#define C_CAN_MSG_OBJ_TX_NUM 16
|
||||
|
||||
#define C_CAN_MSG_OBJ_RX_FIRST 1
|
||||
#define C_CAN_MSG_OBJ_RX_LAST (C_CAN_MSG_OBJ_RX_FIRST + \
|
||||
C_CAN_MSG_OBJ_RX_NUM - 1)
|
||||
|
||||
#define C_CAN_MSG_OBJ_TX_FIRST (C_CAN_MSG_OBJ_RX_LAST + 1)
|
||||
#define C_CAN_MSG_OBJ_TX_LAST (C_CAN_MSG_OBJ_TX_FIRST + \
|
||||
C_CAN_MSG_OBJ_TX_NUM - 1)
|
||||
|
||||
#define C_CAN_MSG_OBJ_RX_SPLIT 9
|
||||
#define C_CAN_MSG_RX_LOW_LAST (C_CAN_MSG_OBJ_RX_SPLIT - 1)
|
||||
#define RECEIVE_OBJECT_BITS 0x0000ffff
|
||||
|
||||
enum reg {
|
||||
C_CAN_CTRL_REG = 0,
|
||||
C_CAN_CTRL_EX_REG,
|
||||
C_CAN_STS_REG,
|
||||
C_CAN_ERR_CNT_REG,
|
||||
C_CAN_BTR_REG,
|
||||
C_CAN_INT_REG,
|
||||
C_CAN_TEST_REG,
|
||||
C_CAN_BRPEXT_REG,
|
||||
C_CAN_IF1_COMREQ_REG,
|
||||
C_CAN_IF1_COMMSK_REG,
|
||||
C_CAN_IF1_MASK1_REG,
|
||||
C_CAN_IF1_MASK2_REG,
|
||||
C_CAN_IF1_ARB1_REG,
|
||||
C_CAN_IF1_ARB2_REG,
|
||||
C_CAN_IF1_MSGCTRL_REG,
|
||||
C_CAN_IF1_DATA1_REG,
|
||||
C_CAN_IF1_DATA2_REG,
|
||||
C_CAN_IF1_DATA3_REG,
|
||||
C_CAN_IF1_DATA4_REG,
|
||||
C_CAN_IF2_COMREQ_REG,
|
||||
C_CAN_IF2_COMMSK_REG,
|
||||
C_CAN_IF2_MASK1_REG,
|
||||
C_CAN_IF2_MASK2_REG,
|
||||
C_CAN_IF2_ARB1_REG,
|
||||
C_CAN_IF2_ARB2_REG,
|
||||
C_CAN_IF2_MSGCTRL_REG,
|
||||
C_CAN_IF2_DATA1_REG,
|
||||
C_CAN_IF2_DATA2_REG,
|
||||
C_CAN_IF2_DATA3_REG,
|
||||
C_CAN_IF2_DATA4_REG,
|
||||
C_CAN_TXRQST1_REG,
|
||||
C_CAN_TXRQST2_REG,
|
||||
C_CAN_NEWDAT1_REG,
|
||||
C_CAN_NEWDAT2_REG,
|
||||
C_CAN_INTPND1_REG,
|
||||
C_CAN_INTPND2_REG,
|
||||
C_CAN_MSGVAL1_REG,
|
||||
C_CAN_MSGVAL2_REG,
|
||||
C_CAN_FUNCTION_REG,
|
||||
};
|
||||
|
||||
static const u16 reg_map_c_can[] = {
|
||||
[C_CAN_CTRL_REG] = 0x00,
|
||||
[C_CAN_STS_REG] = 0x02,
|
||||
[C_CAN_ERR_CNT_REG] = 0x04,
|
||||
[C_CAN_BTR_REG] = 0x06,
|
||||
[C_CAN_INT_REG] = 0x08,
|
||||
[C_CAN_TEST_REG] = 0x0A,
|
||||
[C_CAN_BRPEXT_REG] = 0x0C,
|
||||
[C_CAN_IF1_COMREQ_REG] = 0x10,
|
||||
[C_CAN_IF1_COMMSK_REG] = 0x12,
|
||||
[C_CAN_IF1_MASK1_REG] = 0x14,
|
||||
[C_CAN_IF1_MASK2_REG] = 0x16,
|
||||
[C_CAN_IF1_ARB1_REG] = 0x18,
|
||||
[C_CAN_IF1_ARB2_REG] = 0x1A,
|
||||
[C_CAN_IF1_MSGCTRL_REG] = 0x1C,
|
||||
[C_CAN_IF1_DATA1_REG] = 0x1E,
|
||||
[C_CAN_IF1_DATA2_REG] = 0x20,
|
||||
[C_CAN_IF1_DATA3_REG] = 0x22,
|
||||
[C_CAN_IF1_DATA4_REG] = 0x24,
|
||||
[C_CAN_IF2_COMREQ_REG] = 0x40,
|
||||
[C_CAN_IF2_COMMSK_REG] = 0x42,
|
||||
[C_CAN_IF2_MASK1_REG] = 0x44,
|
||||
[C_CAN_IF2_MASK2_REG] = 0x46,
|
||||
[C_CAN_IF2_ARB1_REG] = 0x48,
|
||||
[C_CAN_IF2_ARB2_REG] = 0x4A,
|
||||
[C_CAN_IF2_MSGCTRL_REG] = 0x4C,
|
||||
[C_CAN_IF2_DATA1_REG] = 0x4E,
|
||||
[C_CAN_IF2_DATA2_REG] = 0x50,
|
||||
[C_CAN_IF2_DATA3_REG] = 0x52,
|
||||
[C_CAN_IF2_DATA4_REG] = 0x54,
|
||||
[C_CAN_TXRQST1_REG] = 0x80,
|
||||
[C_CAN_TXRQST2_REG] = 0x82,
|
||||
[C_CAN_NEWDAT1_REG] = 0x90,
|
||||
[C_CAN_NEWDAT2_REG] = 0x92,
|
||||
[C_CAN_INTPND1_REG] = 0xA0,
|
||||
[C_CAN_INTPND2_REG] = 0xA2,
|
||||
[C_CAN_MSGVAL1_REG] = 0xB0,
|
||||
[C_CAN_MSGVAL2_REG] = 0xB2,
|
||||
};
|
||||
|
||||
static const u16 reg_map_d_can[] = {
|
||||
[C_CAN_CTRL_REG] = 0x00,
|
||||
[C_CAN_CTRL_EX_REG] = 0x02,
|
||||
[C_CAN_STS_REG] = 0x04,
|
||||
[C_CAN_ERR_CNT_REG] = 0x08,
|
||||
[C_CAN_BTR_REG] = 0x0C,
|
||||
[C_CAN_BRPEXT_REG] = 0x0E,
|
||||
[C_CAN_INT_REG] = 0x10,
|
||||
[C_CAN_TEST_REG] = 0x14,
|
||||
[C_CAN_FUNCTION_REG] = 0x18,
|
||||
[C_CAN_TXRQST1_REG] = 0x88,
|
||||
[C_CAN_TXRQST2_REG] = 0x8A,
|
||||
[C_CAN_NEWDAT1_REG] = 0x9C,
|
||||
[C_CAN_NEWDAT2_REG] = 0x9E,
|
||||
[C_CAN_INTPND1_REG] = 0xB0,
|
||||
[C_CAN_INTPND2_REG] = 0xB2,
|
||||
[C_CAN_MSGVAL1_REG] = 0xC4,
|
||||
[C_CAN_MSGVAL2_REG] = 0xC6,
|
||||
[C_CAN_IF1_COMREQ_REG] = 0x100,
|
||||
[C_CAN_IF1_COMMSK_REG] = 0x102,
|
||||
[C_CAN_IF1_MASK1_REG] = 0x104,
|
||||
[C_CAN_IF1_MASK2_REG] = 0x106,
|
||||
[C_CAN_IF1_ARB1_REG] = 0x108,
|
||||
[C_CAN_IF1_ARB2_REG] = 0x10A,
|
||||
[C_CAN_IF1_MSGCTRL_REG] = 0x10C,
|
||||
[C_CAN_IF1_DATA1_REG] = 0x110,
|
||||
[C_CAN_IF1_DATA2_REG] = 0x112,
|
||||
[C_CAN_IF1_DATA3_REG] = 0x114,
|
||||
[C_CAN_IF1_DATA4_REG] = 0x116,
|
||||
[C_CAN_IF2_COMREQ_REG] = 0x120,
|
||||
[C_CAN_IF2_COMMSK_REG] = 0x122,
|
||||
[C_CAN_IF2_MASK1_REG] = 0x124,
|
||||
[C_CAN_IF2_MASK2_REG] = 0x126,
|
||||
[C_CAN_IF2_ARB1_REG] = 0x128,
|
||||
[C_CAN_IF2_ARB2_REG] = 0x12A,
|
||||
[C_CAN_IF2_MSGCTRL_REG] = 0x12C,
|
||||
[C_CAN_IF2_DATA1_REG] = 0x130,
|
||||
[C_CAN_IF2_DATA2_REG] = 0x132,
|
||||
[C_CAN_IF2_DATA3_REG] = 0x134,
|
||||
[C_CAN_IF2_DATA4_REG] = 0x136,
|
||||
};
|
||||
|
||||
enum c_can_dev_id {
|
||||
BOSCH_C_CAN_PLATFORM,
|
||||
BOSCH_C_CAN,
|
||||
BOSCH_D_CAN,
|
||||
};
|
||||
|
||||
/* c_can private data structure */
|
||||
struct c_can_priv {
|
||||
struct can_priv can; /* must be the first member */
|
||||
struct napi_struct napi;
|
||||
struct net_device *dev;
|
||||
struct device *device;
|
||||
atomic_t tx_active;
|
||||
unsigned long tx_dir;
|
||||
int last_status;
|
||||
u16 (*read_reg) (const struct c_can_priv *priv, enum reg index);
|
||||
void (*write_reg) (const struct c_can_priv *priv, enum reg index, u16 val);
|
||||
u32 (*read_reg32) (const struct c_can_priv *priv, enum reg index);
|
||||
void (*write_reg32) (const struct c_can_priv *priv, enum reg index, u32 val);
|
||||
void __iomem *base;
|
||||
const u16 *regs;
|
||||
void *priv; /* for board-specific data */
|
||||
enum c_can_dev_id type;
|
||||
u32 __iomem *raminit_ctrlreg;
|
||||
int instance;
|
||||
void (*raminit) (const struct c_can_priv *priv, bool enable);
|
||||
u32 comm_rcv_high;
|
||||
u32 rxmasked;
|
||||
u32 dlc[C_CAN_MSG_OBJ_TX_NUM];
|
||||
};
|
||||
|
||||
struct net_device *alloc_c_can_dev(void);
|
||||
void free_c_can_dev(struct net_device *dev);
|
||||
int register_c_can_dev(struct net_device *dev);
|
||||
void unregister_c_can_dev(struct net_device *dev);
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
int c_can_power_up(struct net_device *dev);
|
||||
int c_can_power_down(struct net_device *dev);
|
||||
#endif
|
||||
|
||||
#endif /* C_CAN_H */
|
||||
293
drivers/net/can/c_can/c_can_pci.c
Normal file
293
drivers/net/can/c_can/c_can_pci.c
Normal file
|
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
* PCI bus driver for Bosch C_CAN/D_CAN controller
|
||||
*
|
||||
* Copyright (C) 2012 Federico Vaga <federico.vaga@gmail.com>
|
||||
*
|
||||
* Borrowed from c_can_platform.c
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public
|
||||
* License version 2. This program is licensed "as is" without any
|
||||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
#include <linux/can/dev.h>
|
||||
|
||||
#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 {
|
||||
/* Specify if is C_CAN or D_CAN */
|
||||
enum c_can_dev_id type;
|
||||
/* Set the register alignment in the memory */
|
||||
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);
|
||||
};
|
||||
|
||||
/*
|
||||
* 16-bit c_can registers can be arranged differently in the memory
|
||||
* architecture of different implementations. For example: 16-bit
|
||||
* registers can be aligned to a 16-bit boundary or 32-bit boundary etc.
|
||||
* Handle the same by providing a common read/write interface.
|
||||
*/
|
||||
static u16 c_can_pci_read_reg_aligned_to_16bit(const struct c_can_priv *priv,
|
||||
enum reg index)
|
||||
{
|
||||
return readw(priv->base + priv->regs[index]);
|
||||
}
|
||||
|
||||
static void c_can_pci_write_reg_aligned_to_16bit(const struct c_can_priv *priv,
|
||||
enum reg index, u16 val)
|
||||
{
|
||||
writew(val, priv->base + priv->regs[index]);
|
||||
}
|
||||
|
||||
static u16 c_can_pci_read_reg_aligned_to_32bit(const struct c_can_priv *priv,
|
||||
enum reg index)
|
||||
{
|
||||
return readw(priv->base + 2 * priv->regs[index]);
|
||||
}
|
||||
|
||||
static void c_can_pci_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
|
||||
enum reg index, u16 val)
|
||||
{
|
||||
writew(val, priv->base + 2 * priv->regs[index]);
|
||||
}
|
||||
|
||||
static u16 c_can_pci_read_reg_32bit(const 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(const struct c_can_priv *priv,
|
||||
enum reg index, u16 val)
|
||||
{
|
||||
iowrite32((u32)val, priv->base + 2 * priv->regs[index]);
|
||||
}
|
||||
|
||||
static u32 c_can_pci_read_reg32(const struct c_can_priv *priv, enum reg index)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = priv->read_reg(priv, index);
|
||||
val |= ((u32) priv->read_reg(priv, index + 1)) << 16;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void c_can_pci_write_reg32(const struct c_can_priv *priv, enum reg index,
|
||||
u32 val)
|
||||
{
|
||||
priv->write_reg(priv, index + 1, val >> 16);
|
||||
priv->write_reg(priv, index, val);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct c_can_pci_data *c_can_pci_data = (void *)ent->driver_data;
|
||||
struct c_can_priv *priv;
|
||||
struct net_device *dev;
|
||||
void __iomem *addr;
|
||||
int ret;
|
||||
|
||||
ret = pci_enable_device(pdev);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "pci_enable_device FAILED\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = pci_request_regions(pdev, KBUILD_MODNAME);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "pci_request_regions FAILED\n");
|
||||
goto out_disable_device;
|
||||
}
|
||||
|
||||
ret = pci_enable_msi(pdev);
|
||||
if (!ret) {
|
||||
dev_info(&pdev->dev, "MSI enabled\n");
|
||||
pci_set_master(pdev);
|
||||
}
|
||||
|
||||
addr = pci_iomap(pdev, c_can_pci_data->bar,
|
||||
pci_resource_len(pdev, c_can_pci_data->bar));
|
||||
if (!addr) {
|
||||
dev_err(&pdev->dev,
|
||||
"device has no PCI memory resources, "
|
||||
"failing adapter\n");
|
||||
ret = -ENOMEM;
|
||||
goto out_release_regions;
|
||||
}
|
||||
|
||||
/* allocate the c_can device */
|
||||
dev = alloc_c_can_dev();
|
||||
if (!dev) {
|
||||
ret = -ENOMEM;
|
||||
goto out_iounmap;
|
||||
}
|
||||
|
||||
priv = netdev_priv(dev);
|
||||
pci_set_drvdata(pdev, dev);
|
||||
SET_NETDEV_DEV(dev, &pdev->dev);
|
||||
|
||||
dev->irq = pdev->irq;
|
||||
priv->base = addr;
|
||||
|
||||
if (!c_can_pci_data->freq) {
|
||||
dev_err(&pdev->dev, "no clock frequency defined\n");
|
||||
ret = -ENODEV;
|
||||
goto out_free_c_can;
|
||||
} else {
|
||||
priv->can.clock.freq = c_can_pci_data->freq;
|
||||
}
|
||||
|
||||
/* Configure CAN type */
|
||||
switch (c_can_pci_data->type) {
|
||||
case BOSCH_C_CAN:
|
||||
priv->regs = reg_map_c_can;
|
||||
break;
|
||||
case BOSCH_D_CAN:
|
||||
priv->regs = reg_map_d_can;
|
||||
priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
goto out_free_c_can;
|
||||
}
|
||||
|
||||
priv->type = c_can_pci_data->type;
|
||||
|
||||
/* Configure access to registers */
|
||||
switch (c_can_pci_data->reg_align) {
|
||||
case C_CAN_REG_ALIGN_32:
|
||||
priv->read_reg = c_can_pci_read_reg_aligned_to_32bit;
|
||||
priv->write_reg = c_can_pci_write_reg_aligned_to_32bit;
|
||||
break;
|
||||
case C_CAN_REG_ALIGN_16:
|
||||
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->read_reg32 = c_can_pci_read_reg32;
|
||||
priv->write_reg32 = c_can_pci_write_reg32;
|
||||
|
||||
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",
|
||||
KBUILD_MODNAME, ret);
|
||||
goto out_free_c_can;
|
||||
}
|
||||
|
||||
dev_dbg(&pdev->dev, "%s device registered (regs=%p, irq=%d)\n",
|
||||
KBUILD_MODNAME, priv->regs, dev->irq);
|
||||
|
||||
return 0;
|
||||
|
||||
out_free_c_can:
|
||||
free_c_can_dev(dev);
|
||||
out_iounmap:
|
||||
pci_iounmap(pdev, addr);
|
||||
out_release_regions:
|
||||
pci_disable_msi(pdev);
|
||||
pci_clear_master(pdev);
|
||||
pci_release_regions(pdev);
|
||||
out_disable_device:
|
||||
pci_disable_device(pdev);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void c_can_pci_remove(struct pci_dev *pdev)
|
||||
{
|
||||
struct net_device *dev = pci_get_drvdata(pdev);
|
||||
struct c_can_priv *priv = netdev_priv(dev);
|
||||
|
||||
unregister_c_can_dev(dev);
|
||||
|
||||
free_c_can_dev(dev);
|
||||
|
||||
pci_iounmap(pdev, priv->base);
|
||||
pci_disable_msi(pdev);
|
||||
pci_clear_master(pdev);
|
||||
pci_release_regions(pdev);
|
||||
pci_disable_device(pdev);
|
||||
}
|
||||
|
||||
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) { \
|
||||
PCI_DEVICE(_vend, _dev), \
|
||||
.driver_data = (unsigned long)&_driverdata, \
|
||||
}
|
||||
|
||||
static const struct pci_device_id 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 = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.id_table = c_can_pci_tbl,
|
||||
.probe = c_can_pci_probe,
|
||||
.remove = c_can_pci_remove,
|
||||
};
|
||||
|
||||
module_pci_driver(c_can_pci_driver);
|
||||
|
||||
MODULE_AUTHOR("Federico Vaga <federico.vaga@gmail.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("PCI CAN bus driver for Bosch C_CAN/D_CAN controller");
|
||||
MODULE_DEVICE_TABLE(pci, c_can_pci_tbl);
|
||||
409
drivers/net/can/c_can/c_can_platform.c
Normal file
409
drivers/net/can/c_can/c_can_platform.c
Normal file
|
|
@ -0,0 +1,409 @@
|
|||
/*
|
||||
* Platform CAN bus driver for Bosch C_CAN controller
|
||||
*
|
||||
* Copyright (C) 2010 ST Microelectronics
|
||||
* Bhupesh Sharma <bhupesh.sharma@st.com>
|
||||
*
|
||||
* Borrowed heavily from the C_CAN driver originally written by:
|
||||
* Copyright (C) 2007
|
||||
* - Sascha Hauer, Marc Kleine-Budde, Pengutronix <s.hauer@pengutronix.de>
|
||||
* - Simon Kallweit, intefo AG <simon.kallweit@intefo.ch>
|
||||
*
|
||||
* Bosch C_CAN controller is compliant to CAN protocol version 2.0 part A and B.
|
||||
* Bosch C_CAN user manual can be obtained from:
|
||||
* http://www.semiconductors.bosch.de/media/en/pdf/ipmodules_1/c_can/
|
||||
* users_manual_c_can.pdf
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public
|
||||
* License version 2. This program is licensed "as is" without any
|
||||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_device.h>
|
||||
|
||||
#include <linux/can/dev.h>
|
||||
|
||||
#include "c_can.h"
|
||||
|
||||
#define CAN_RAMINIT_START_MASK(i) (0x001 << (i))
|
||||
#define CAN_RAMINIT_DONE_MASK(i) (0x100 << (i))
|
||||
#define CAN_RAMINIT_ALL_MASK(i) (0x101 << (i))
|
||||
#define DCAN_RAM_INIT_BIT (1 << 3)
|
||||
static DEFINE_SPINLOCK(raminit_lock);
|
||||
/*
|
||||
* 16-bit c_can registers can be arranged differently in the memory
|
||||
* architecture of different implementations. For example: 16-bit
|
||||
* registers can be aligned to a 16-bit boundary or 32-bit boundary etc.
|
||||
* Handle the same by providing a common read/write interface.
|
||||
*/
|
||||
static u16 c_can_plat_read_reg_aligned_to_16bit(const struct c_can_priv *priv,
|
||||
enum reg index)
|
||||
{
|
||||
return readw(priv->base + priv->regs[index]);
|
||||
}
|
||||
|
||||
static void c_can_plat_write_reg_aligned_to_16bit(const struct c_can_priv *priv,
|
||||
enum reg index, u16 val)
|
||||
{
|
||||
writew(val, priv->base + priv->regs[index]);
|
||||
}
|
||||
|
||||
static u16 c_can_plat_read_reg_aligned_to_32bit(const struct c_can_priv *priv,
|
||||
enum reg index)
|
||||
{
|
||||
return readw(priv->base + 2 * priv->regs[index]);
|
||||
}
|
||||
|
||||
static void c_can_plat_write_reg_aligned_to_32bit(const struct c_can_priv *priv,
|
||||
enum reg index, u16 val)
|
||||
{
|
||||
writew(val, priv->base + 2 * priv->regs[index]);
|
||||
}
|
||||
|
||||
static void c_can_hw_raminit_wait_ti(const struct c_can_priv *priv, u32 mask,
|
||||
u32 val)
|
||||
{
|
||||
/* We look only at the bits of our instance. */
|
||||
val &= mask;
|
||||
while ((readl(priv->raminit_ctrlreg) & mask) != val)
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
static void c_can_hw_raminit_ti(const struct c_can_priv *priv, bool enable)
|
||||
{
|
||||
u32 mask = CAN_RAMINIT_ALL_MASK(priv->instance);
|
||||
u32 ctrl;
|
||||
|
||||
spin_lock(&raminit_lock);
|
||||
|
||||
ctrl = readl(priv->raminit_ctrlreg);
|
||||
/* We clear the done and start bit first. The start bit is
|
||||
* looking at the 0 -> transition, but is not self clearing;
|
||||
* And we clear the init done bit as well.
|
||||
*/
|
||||
ctrl &= ~CAN_RAMINIT_START_MASK(priv->instance);
|
||||
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
|
||||
writel(ctrl, priv->raminit_ctrlreg);
|
||||
ctrl &= ~CAN_RAMINIT_DONE_MASK(priv->instance);
|
||||
c_can_hw_raminit_wait_ti(priv, mask, ctrl);
|
||||
|
||||
if (enable) {
|
||||
/* Set start bit and wait for the done bit. */
|
||||
ctrl |= CAN_RAMINIT_START_MASK(priv->instance);
|
||||
writel(ctrl, priv->raminit_ctrlreg);
|
||||
ctrl |= CAN_RAMINIT_DONE_MASK(priv->instance);
|
||||
c_can_hw_raminit_wait_ti(priv, mask, ctrl);
|
||||
}
|
||||
spin_unlock(&raminit_lock);
|
||||
}
|
||||
|
||||
static u32 c_can_plat_read_reg32(const struct c_can_priv *priv, enum reg index)
|
||||
{
|
||||
u32 val;
|
||||
|
||||
val = priv->read_reg(priv, index);
|
||||
val |= ((u32) priv->read_reg(priv, index + 1)) << 16;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static void c_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index,
|
||||
u32 val)
|
||||
{
|
||||
priv->write_reg(priv, index + 1, val >> 16);
|
||||
priv->write_reg(priv, index, val);
|
||||
}
|
||||
|
||||
static u32 d_can_plat_read_reg32(const struct c_can_priv *priv, enum reg index)
|
||||
{
|
||||
return readl(priv->base + priv->regs[index]);
|
||||
}
|
||||
|
||||
static void d_can_plat_write_reg32(const struct c_can_priv *priv, enum reg index,
|
||||
u32 val)
|
||||
{
|
||||
writel(val, priv->base + priv->regs[index]);
|
||||
}
|
||||
|
||||
static void c_can_hw_raminit_wait(const struct c_can_priv *priv, u32 mask)
|
||||
{
|
||||
while (priv->read_reg32(priv, C_CAN_FUNCTION_REG) & mask)
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
static void c_can_hw_raminit(const struct c_can_priv *priv, bool enable)
|
||||
{
|
||||
u32 ctrl;
|
||||
|
||||
ctrl = priv->read_reg32(priv, C_CAN_FUNCTION_REG);
|
||||
ctrl &= ~DCAN_RAM_INIT_BIT;
|
||||
priv->write_reg32(priv, C_CAN_FUNCTION_REG, ctrl);
|
||||
c_can_hw_raminit_wait(priv, ctrl);
|
||||
|
||||
if (enable) {
|
||||
ctrl |= DCAN_RAM_INIT_BIT;
|
||||
priv->write_reg32(priv, C_CAN_FUNCTION_REG, ctrl);
|
||||
c_can_hw_raminit_wait(priv, ctrl);
|
||||
}
|
||||
}
|
||||
|
||||
static struct platform_device_id c_can_id_table[] = {
|
||||
[BOSCH_C_CAN_PLATFORM] = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.driver_data = BOSCH_C_CAN,
|
||||
},
|
||||
[BOSCH_C_CAN] = {
|
||||
.name = "c_can",
|
||||
.driver_data = BOSCH_C_CAN,
|
||||
},
|
||||
[BOSCH_D_CAN] = {
|
||||
.name = "d_can",
|
||||
.driver_data = BOSCH_D_CAN,
|
||||
}, {
|
||||
}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(platform, c_can_id_table);
|
||||
|
||||
static const struct of_device_id c_can_of_table[] = {
|
||||
{ .compatible = "bosch,c_can", .data = &c_can_id_table[BOSCH_C_CAN] },
|
||||
{ .compatible = "bosch,d_can", .data = &c_can_id_table[BOSCH_D_CAN] },
|
||||
{ /* sentinel */ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, c_can_of_table);
|
||||
|
||||
static int c_can_plat_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret;
|
||||
void __iomem *addr;
|
||||
struct net_device *dev;
|
||||
struct c_can_priv *priv;
|
||||
const struct of_device_id *match;
|
||||
const struct platform_device_id *id;
|
||||
struct resource *mem, *res;
|
||||
int irq;
|
||||
struct clk *clk;
|
||||
|
||||
if (pdev->dev.of_node) {
|
||||
match = of_match_device(c_can_of_table, &pdev->dev);
|
||||
if (!match) {
|
||||
dev_err(&pdev->dev, "Failed to find matching dt id\n");
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
id = match->data;
|
||||
} else {
|
||||
id = platform_get_device_id(pdev);
|
||||
}
|
||||
|
||||
/* get the appropriate clk */
|
||||
clk = devm_clk_get(&pdev->dev, NULL);
|
||||
if (IS_ERR(clk)) {
|
||||
ret = PTR_ERR(clk);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* get the platform data */
|
||||
irq = platform_get_irq(pdev, 0);
|
||||
if (irq <= 0) {
|
||||
ret = -ENODEV;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
addr = devm_ioremap_resource(&pdev->dev, mem);
|
||||
if (IS_ERR(addr)) {
|
||||
ret = PTR_ERR(addr);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* allocate the c_can device */
|
||||
dev = alloc_c_can_dev();
|
||||
if (!dev) {
|
||||
ret = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
priv = netdev_priv(dev);
|
||||
switch (id->driver_data) {
|
||||
case BOSCH_C_CAN:
|
||||
priv->regs = reg_map_c_can;
|
||||
switch (mem->flags & IORESOURCE_MEM_TYPE_MASK) {
|
||||
case IORESOURCE_MEM_32BIT:
|
||||
priv->read_reg = c_can_plat_read_reg_aligned_to_32bit;
|
||||
priv->write_reg = c_can_plat_write_reg_aligned_to_32bit;
|
||||
priv->read_reg32 = c_can_plat_read_reg32;
|
||||
priv->write_reg32 = c_can_plat_write_reg32;
|
||||
break;
|
||||
case IORESOURCE_MEM_16BIT:
|
||||
default:
|
||||
priv->read_reg = c_can_plat_read_reg_aligned_to_16bit;
|
||||
priv->write_reg = c_can_plat_write_reg_aligned_to_16bit;
|
||||
priv->read_reg32 = c_can_plat_read_reg32;
|
||||
priv->write_reg32 = c_can_plat_write_reg32;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BOSCH_D_CAN:
|
||||
priv->regs = reg_map_d_can;
|
||||
priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
|
||||
priv->read_reg = c_can_plat_read_reg_aligned_to_16bit;
|
||||
priv->write_reg = c_can_plat_write_reg_aligned_to_16bit;
|
||||
priv->read_reg32 = d_can_plat_read_reg32;
|
||||
priv->write_reg32 = d_can_plat_write_reg32;
|
||||
|
||||
if (pdev->dev.of_node)
|
||||
priv->instance = of_alias_get_id(pdev->dev.of_node, "d_can");
|
||||
else
|
||||
priv->instance = pdev->id;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
||||
/* Not all D_CAN modules have a separate register for the D_CAN
|
||||
* RAM initialization. Use default RAM init bit in D_CAN module
|
||||
* if not specified in DT.
|
||||
*/
|
||||
if (!res) {
|
||||
priv->raminit = c_can_hw_raminit;
|
||||
break;
|
||||
}
|
||||
|
||||
priv->raminit_ctrlreg = devm_ioremap(&pdev->dev, res->start,
|
||||
resource_size(res));
|
||||
if (!priv->raminit_ctrlreg || priv->instance < 0)
|
||||
dev_info(&pdev->dev, "control memory is not used for raminit\n");
|
||||
else
|
||||
priv->raminit = c_can_hw_raminit_ti;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
goto exit_free_device;
|
||||
}
|
||||
|
||||
dev->irq = irq;
|
||||
priv->base = addr;
|
||||
priv->device = &pdev->dev;
|
||||
priv->can.clock.freq = clk_get_rate(clk);
|
||||
priv->priv = clk;
|
||||
priv->type = id->driver_data;
|
||||
|
||||
platform_set_drvdata(pdev, dev);
|
||||
SET_NETDEV_DEV(dev, &pdev->dev);
|
||||
|
||||
ret = register_c_can_dev(dev);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
|
||||
KBUILD_MODNAME, ret);
|
||||
goto exit_free_device;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "%s device registered (regs=%p, irq=%d)\n",
|
||||
KBUILD_MODNAME, priv->base, dev->irq);
|
||||
return 0;
|
||||
|
||||
exit_free_device:
|
||||
free_c_can_dev(dev);
|
||||
exit:
|
||||
dev_err(&pdev->dev, "probe failed\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int c_can_plat_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct net_device *dev = platform_get_drvdata(pdev);
|
||||
|
||||
unregister_c_can_dev(dev);
|
||||
|
||||
free_c_can_dev(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
static int c_can_suspend(struct platform_device *pdev, pm_message_t state)
|
||||
{
|
||||
int ret;
|
||||
struct net_device *ndev = platform_get_drvdata(pdev);
|
||||
struct c_can_priv *priv = netdev_priv(ndev);
|
||||
|
||||
if (priv->type != BOSCH_D_CAN) {
|
||||
dev_warn(&pdev->dev, "Not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (netif_running(ndev)) {
|
||||
netif_stop_queue(ndev);
|
||||
netif_device_detach(ndev);
|
||||
}
|
||||
|
||||
ret = c_can_power_down(ndev);
|
||||
if (ret) {
|
||||
netdev_err(ndev, "failed to enter power down mode\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
priv->can.state = CAN_STATE_SLEEPING;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int c_can_resume(struct platform_device *pdev)
|
||||
{
|
||||
int ret;
|
||||
struct net_device *ndev = platform_get_drvdata(pdev);
|
||||
struct c_can_priv *priv = netdev_priv(ndev);
|
||||
|
||||
if (priv->type != BOSCH_D_CAN) {
|
||||
dev_warn(&pdev->dev, "Not supported\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = c_can_power_up(ndev);
|
||||
if (ret) {
|
||||
netdev_err(ndev, "Still in power down mode\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
priv->can.state = CAN_STATE_ERROR_ACTIVE;
|
||||
|
||||
if (netif_running(ndev)) {
|
||||
netif_device_attach(ndev);
|
||||
netif_start_queue(ndev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#define c_can_suspend NULL
|
||||
#define c_can_resume NULL
|
||||
#endif
|
||||
|
||||
static struct platform_driver c_can_plat_driver = {
|
||||
.driver = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = c_can_of_table,
|
||||
},
|
||||
.probe = c_can_plat_probe,
|
||||
.remove = c_can_plat_remove,
|
||||
.suspend = c_can_suspend,
|
||||
.resume = c_can_resume,
|
||||
.id_table = c_can_id_table,
|
||||
};
|
||||
|
||||
module_platform_driver(c_can_plat_driver);
|
||||
|
||||
MODULE_AUTHOR("Bhupesh Sharma <bhupesh.sharma@st.com>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("Platform CAN bus driver for Bosch C_CAN controller");
|
||||
Loading…
Add table
Add a link
Reference in a new issue