BigW Consortium Gitlab

Commit 4a9ce3c3 by Zahid Chowdhury Committed by David Frey

Support CAN IoT card

Rather than requiring a yocto re-build to support the CAN IoT card, the relevant kernel module code has been taken out of tree. For 9x15 based modules (wp75, wp85) use the modules in the can_9x15 directory. For 9x07 based modules (wp76, wp77), use the modules in the can_9x07 directory. The can_common/can_iot module instantiates an mcp251x device with the appropriate platform data for using the CAN IoT card in a mangOH Red.
parent f3a6f9ca
......@@ -14,8 +14,14 @@ requires:
{
kernelModules:
{
/*
* Due to a Legato bug in 18.05.1, this dependency has been
* temporarily disabled. It should be added back when the bug is
* fixed. The bug relates to modules that are depended on
* multiple times.
*/
#if ${MANGOH_KERNEL_LACKS_IIO} = 1
$CURDIR/../iio/iio-kfifo-buf
//$CURDIR/../iio/iio-kfifo-buf
#endif // MANGOH_KERNEL_LACKS_IIO
}
}
sources:
{
mcp251x.c
}
requires:
{
kernelModules:
{
$CURDIR/../can_common/can_iot
}
}
......@@ -7,6 +7,7 @@ requires:
{
kernelModules:
{
$CURDIR/can-dev
$CURDIR/../can_common/can_iot
$CURDIR/can-dev
}
}
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/irq.h>
#include <linux/can/platform/mcp251x.h>
#include <linux/gpio.h>
/* We assume that we are in the linux_kernel_modules dir on the mangOH src tree */
#include "../mangoh/mangoh_common.h"
/* For later if you need more early startup code for the MCP251x chip driver
static struct platform_driver can_iot_drv = {
.probe = can_iot_probe,
.remove = can_iot_remove,
.driver = {
.name = KBUILD_MODNAME,
.owner = THIS_MODULE,
},
};
static int can_iot_probe (struct platform_device *pdev){
return 0;
}
static void can_iot_remove(struct platform_device *pdev){
}
*/
static struct mcp251x_platform_data mcp2515_pdata = {
.oscillator_frequency = 16*1000*1000,
};
static struct spi_board_info mcp2515_board_info= {
.modalias = "mcp2515",
.platform_data = &mcp2515_pdata,
.max_speed_hz = 2*1000*1000,
.mode = SPI_MODE_0,
.bus_num = 0,
.chip_select = 0,
};
static struct spi_master *spi_master;
static struct spi_device *spi_device;
static int __init can_iot_init(void)
{
/* MCP251x needs us to allocate the GPIO irq it will request */
if ((gpio_request(CF3_GPIO42, "can_irq") == 0) &&
(gpio_direction_input(CF3_GPIO42) == 0)) {
gpio_export(CF3_GPIO42, 0);
irq_set_irq_type(gpio_to_irq(CF3_GPIO42), IRQ_TYPE_EDGE_FALLING);
} else
pr_err("can_iot_init: Could not allocate the gpio irq for MCP251x CAN bus interrupt\n");
mcp2515_board_info.irq = gpio_to_irq(CF3_GPIO42);
/* Hook into the SPI bus */
spi_master = spi_busnum_to_master(PRIMARY_SPI_BUS);
if (!spi_master)
pr_err("can_iot_init: No SPI Master on Primary SPI Bus\n");
spi_device = spi_new_device(spi_master, &mcp2515_board_info);
pr_info("can_iot_init: mcp2515 (gpio:%d irq:%d).\n",
CF3_GPIO42, mcp2515_board_info.irq);
/* platform_driver_register(&can_iot_drv); */
return 0;
}
static void __exit can_iot_remove (void)
{
gpio_unexport(CF3_GPIO42);
gpio_free(CF3_GPIO42);
spi_unregister_device(spi_device);
/* platform_driver_unregister(&can_iot_drv); */
}
module_init(can_iot_init);
module_exit(can_iot_remove);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sierra Wireless");
MODULE_DESCRIPTION("Platform data for MCP251x chip driver");
# It seems that taking the IoT card out of reset fails in the core
# mangOH driver - but placing things after user-space has fully started
# and through the SWI gpiolib-sysfs code works - TODO fix and move into
# the core driver so no shell script is needed.
# Thus, we remove the inserted chip driver and bring it back.
drv_file=`find /legato/systems/current/modules/ -name "*mcp251x.ko"`
drv=`basename $drv_file`
# remove the driver
rmmod $drv
# Take IoT card out of reset
echo 2 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio2/direction
echo 1 > /sys/class/gpio/gpio2/value
# Enable level shifter on the CAN IoT card
echo 13 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio13/direction
echo 1 > /sys/class/gpio/gpio13/value
# Bring driver back & iproute2 add in CAN
insmod $drv_file
ip link set can0 type can bitrate 125000 triple-sampling on
ifconfig can0 up
......@@ -124,6 +124,33 @@ kernelModules:
$CURDIR/linux_kernel_modules/mt7697q/mt7697q
$CURDIR/linux_kernel_modules/mt7697serial/mt7697serial
#endif // MANGOH_SUPPORT_MT7697_WIFI
/*
* CAN Bus
*
* wp85 kernels don't include any CAN bus in the Kernel config - thus, all the modules are out of
* tree.
*
* wp7xx kernels include the CAN bus in the Kernel config as a built-in module, but not the chip
* driver. Thus, only the chip driver is out of tree for wp7xx kernels.
*
* The CAN Bus is COMMENTED OUT by default, please uncomment to use and be sure to comment out
* spisvc below.
*/
/*
$CURDIR/linux_kernel_modules/can_common/can_iot
#if ${MANGOH_CAN_9X15} = 1
$CURDIR/linux_kernel_modules/can_9x15/can
$CURDIR/linux_kernel_modules/can_9x15/can-bcm
$CURDIR/linux_kernel_modules/can_9x15/can-raw
$CURDIR/linux_kernel_modules/can_9x15/can-dev
$CURDIR/linux_kernel_modules/can_9x15/vcan
$CURDIR/linux_kernel_modules/can_9x15/mcp251x
#else
$CURDIR/linux_kernel_modules/can_9x07/mcp251x
#endif // MANGOH_CAN_9X15
*/
#elif ${MANGOH_BOARD} = GREEN
$CURDIR/linux_kernel_modules/mangoh/mangoh_green_dv4
......
......@@ -30,5 +30,10 @@ buildVars:
* I2C bus containing the battery charger and battery gauge
*/
MANGOH_I2C_BUS_BATTERY = 2
/*
* CAN IOT card
*/
MANGOH_CAN_9X15 = 1
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment