forked from Minki/linux
69927fccd9
This patch adds the support for D_CAN controller driver to the existing C_CAN driver. Bosch D_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B. Bosch D_CAN user manual can be obtained from: http://www.semiconductors.bosch.de/media/en/pdf/ ipmodules_1/can/d_can_users_manual_111.pdf A new array is added for accessing the d_can registers, according to d_can controller register space. Current D_CAN implementation has following limitations, this is done to avoid large changes to the C_CAN driver. 1. Message objects are limited to 32, 16 for RX and 16 for TX. C_CAN IP supports upto 32 message objects but in case of D_CAN we can configure upto 128 message objects. 2. Using two 16bit reads/writes for accessing the 32bit D_CAN registers. 3. These patches have been tested on little endian machine, there might be some hidden endian-related issues due to the nature of the accesses (32-bit registers accessed as 2 16-bit registers). However, I do not have a big-endian D_CAN implementation to confirm. Signed-off-by: AnilKumar Ch <anilkumar@ti.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
235 lines
5.7 KiB
C
235 lines
5.7 KiB
C
/*
|
|
* 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/can/dev.h>
|
|
|
|
#include "c_can.h"
|
|
|
|
/*
|
|
* 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(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(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(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(struct c_can_priv *priv,
|
|
enum reg index, u16 val)
|
|
{
|
|
writew(val, priv->base + 2 * priv->regs[index]);
|
|
}
|
|
|
|
static int __devinit c_can_plat_probe(struct platform_device *pdev)
|
|
{
|
|
int ret;
|
|
void __iomem *addr;
|
|
struct net_device *dev;
|
|
struct c_can_priv *priv;
|
|
const struct platform_device_id *id;
|
|
struct resource *mem;
|
|
int irq;
|
|
#ifdef CONFIG_HAVE_CLK
|
|
struct clk *clk;
|
|
|
|
/* get the appropriate clk */
|
|
clk = clk_get(&pdev->dev, NULL);
|
|
if (IS_ERR(clk)) {
|
|
dev_err(&pdev->dev, "no clock defined\n");
|
|
ret = -ENODEV;
|
|
goto exit;
|
|
}
|
|
#endif
|
|
|
|
/* get the platform data */
|
|
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
irq = platform_get_irq(pdev, 0);
|
|
if (!mem || irq <= 0) {
|
|
ret = -ENODEV;
|
|
goto exit_free_clk;
|
|
}
|
|
|
|
if (!request_mem_region(mem->start, resource_size(mem),
|
|
KBUILD_MODNAME)) {
|
|
dev_err(&pdev->dev, "resource unavailable\n");
|
|
ret = -ENODEV;
|
|
goto exit_free_clk;
|
|
}
|
|
|
|
addr = ioremap(mem->start, resource_size(mem));
|
|
if (!addr) {
|
|
dev_err(&pdev->dev, "failed to map can port\n");
|
|
ret = -ENOMEM;
|
|
goto exit_release_mem;
|
|
}
|
|
|
|
/* allocate the c_can device */
|
|
dev = alloc_c_can_dev();
|
|
if (!dev) {
|
|
ret = -ENOMEM;
|
|
goto exit_iounmap;
|
|
}
|
|
|
|
priv = netdev_priv(dev);
|
|
id = platform_get_device_id(pdev);
|
|
switch (id->driver_data) {
|
|
case C_CAN_DEVTYPE:
|
|
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;
|
|
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;
|
|
break;
|
|
}
|
|
break;
|
|
case D_CAN_DEVTYPE:
|
|
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;
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
goto exit_free_device;
|
|
}
|
|
|
|
dev->irq = irq;
|
|
priv->base = addr;
|
|
#ifdef CONFIG_HAVE_CLK
|
|
priv->can.clock.freq = clk_get_rate(clk);
|
|
priv->priv = clk;
|
|
#endif
|
|
|
|
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:
|
|
platform_set_drvdata(pdev, NULL);
|
|
free_c_can_dev(dev);
|
|
exit_iounmap:
|
|
iounmap(addr);
|
|
exit_release_mem:
|
|
release_mem_region(mem->start, resource_size(mem));
|
|
exit_free_clk:
|
|
#ifdef CONFIG_HAVE_CLK
|
|
clk_put(clk);
|
|
exit:
|
|
#endif
|
|
dev_err(&pdev->dev, "probe failed\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int __devexit c_can_plat_remove(struct platform_device *pdev)
|
|
{
|
|
struct net_device *dev = platform_get_drvdata(pdev);
|
|
struct c_can_priv *priv = netdev_priv(dev);
|
|
struct resource *mem;
|
|
|
|
unregister_c_can_dev(dev);
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
free_c_can_dev(dev);
|
|
iounmap(priv->base);
|
|
|
|
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
release_mem_region(mem->start, resource_size(mem));
|
|
|
|
#ifdef CONFIG_HAVE_CLK
|
|
clk_put(priv->priv);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct platform_device_id c_can_id_table[] = {
|
|
{
|
|
.name = KBUILD_MODNAME,
|
|
.driver_data = C_CAN_DEVTYPE,
|
|
}, {
|
|
.name = "c_can",
|
|
.driver_data = C_CAN_DEVTYPE,
|
|
}, {
|
|
.name = "d_can",
|
|
.driver_data = D_CAN_DEVTYPE,
|
|
}, {
|
|
}
|
|
};
|
|
|
|
static struct platform_driver c_can_plat_driver = {
|
|
.driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = c_can_plat_probe,
|
|
.remove = __devexit_p(c_can_plat_remove),
|
|
.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");
|