Skip to content

add LibIIO drivers to 5.15.70 LTS kernel #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: socfpga-5.15.70-lts
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions arch/arm/configs/socfpga_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,10 @@ CONFIG_DETECT_HUNG_TASK=y
# CONFIG_SCHED_DEBUG is not set
CONFIG_FUNCTION_TRACER=y
CONFIG_DEBUG_USER=y
CONFIG_MATHWORKS_IP_CORE=y
CONFIG_MATHWORKS_GENERIC_OF=y
CONFIG_MWIPCORE=y
CONFIG_MWIPCORE_DMA_STREAMING=y
CONFIG_MWIPCORE_IIO_STREAMING=y
CONFIG_MWIPCORE_IIO_MM=y
CONFIG_MWIPCORE_IIO_SHAREDMEM=y
110 changes: 110 additions & 0 deletions drivers/misc/mathworks/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# mwgeneric driver configuration
#

menu "MathWorks IP Drivers"



config MATHWORKS_IP_CORE
tristate "MathWorks IP Drivers"
depends on (OF) || PCI
default m
help
Say Y here if you want to add support for the MathWorks IP
drivers

If unsure, say N.

To compile this driver as a module, choose M here:
the module will be called mathworks_ip_common

if MATHWORKS_IP_CORE

config MWIPCORE
tristate "Mathwork IP Core Driver"
depends on OF
default m
help
Say Y here if you want to add support for the MathWorks IP
core driver

If unsure, say N.

To compile this driver as a module, choose M here:
the module will be called mwipcore
if MWIPCORE

config MWIPCORE_DMA_STREAMING
tristate "MathWorks DMA Streaming Driver"
depends on DMADEVICES
default m
help
Enable support for MathWorks raw DMA-based implementation
of streaming DMA

If unsure, say N.

To compile this driver as a module, choose M here:
the module will be called mwipcore_dma_streaming

config MWIPCORE_IIO_STREAMING
tristate "MathWorks IIO Streaming Driver"
depends on DMADEVICES
depends on IIO
select IIO_BUFFER
select IIO_BUFFER_DMAENGINE
default m
help
Enable support for MathWorks IIO-based implementation of
streaming DMA

To compile this driver as a module, choose M here:
the module will be called mwipcore_iio_streaming

config MWIPCORE_IIO_MM
tristate "MathWorks IIO Memory Mapped Driver"
depends on DMADEVICES
depends on IIO
select IIO_BUFFER
select IIO_BUFFER_DMAENGINE
default m
help
Enable support for MathWorks IIO-based implementation of
memory mapped IO and DMA

To compile this driver as a module, choose M here:
the module will be called mwipcore_iio_mm

config MWIPCORE_IIO_SHAREDMEM
tristate "MathWorks IIO Shared Memory Driver"
depends on DMADEVICES
depends on IIO
select IIO_BUFFER
select IIO_BUFFER_DMAENGINE
default m
help
Enable support for MathWorks IIO-based implementation of
shared, random-access memory region

To compile this driver as a module, choose M here:
the module will be called mwipcore_iio_sharedregion

endif #if MWIPCORE

config MATHWORKS_GENERIC_OF
tristate "MathWorks Generic OF Driver"
depends on OF_ADDRESS && OF_IRQ
default m
help
Say Y here if you want to add support for the MathWorks
Generic OF driver

If unsure, say N.

To compile this driver as a module, choose M here:
the module will be called mathworks_generic_of

endif #if MWGENERIC
endmenu

19 changes: 19 additions & 0 deletions drivers/misc/mathworks/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Makefile for the AXI4 drivers.
#

obj-$(CONFIG_MATHWORKS_IP_CORE) += mathworks_ip_common.o
obj-$(CONFIG_MATHWORKS_GENERIC_OF) += mathworks_generic_of.o

obj-$(CONFIG_MWIPCORE) += mwipcore.o
obj-$(CONFIG_MWIPCORE_DMA_STREAMING) += mwipcore_dma_streaming.o
obj-$(CONFIG_MWIPCORE_IIO_STREAMING) += mwipcore_iio_streaming.o
obj-$(CONFIG_MWIPCORE_IIO_MM) += mwipcore_iio_mm.o
obj-$(CONFIG_MWIPCORE_IIO_SHAREDMEM) += mwipcore_iio_sharedmem.o

mwipcore_dma_streaming-objs := mw_stream_channel.o
mwipcore_iio_streaming-objs := mw_stream_iio_channel.o
mwipcore_iio_mm-objs := mw_mm_iio_channel.o
mwipcore_iio_sharedmem-objs := mw_sharedmem_iio_channel.o
mwipcore-objs := mathworks_ipcore.o

185 changes: 185 additions & 0 deletions drivers/misc/mathworks/mathworks_generic_of.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* MathWorks IP Generic OF Driver
*
* Copyright 2013-2016 The MathWorks, Inc
*
* Licensed under the GPL-2.
*/
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/i2c.h>
#include <linux/of_device.h>
#include <linux/of_platform.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>

#include <linux/mathworks/mathworks_ip.h>

#define ip_to_pdev(x) (container_of(x->dev, struct platform_device, dev))

#define DRIVER_NAME "mathworks_generic_of"

static void mwgen_of_unlink_i2c_device(struct mathworks_ip_info *thisIpcore){
sysfs_remove_link(&thisIpcore->char_device->kobj, "i2c_device");
}

static void mwgen_of_unlink_i2c_adapter(struct mathworks_ip_info *thisIpcore){
sysfs_remove_link(&thisIpcore->char_device->kobj, "i2c_adapter");
}

static int mathworks_generic_of_i2c_init(struct mathworks_ip_info *thisIpcore){
struct device_node *nodePointer = thisIpcore->dev->of_node;
struct device_node *slave_node;
int status;

slave_node = of_parse_phandle(nodePointer, "i2c-controller", 0);
if (slave_node) {
status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)of_node_put, slave_node);
if(status)
return status;

dev_info(thisIpcore->dev, "creating i2c link\n");

thisIpcore->i2c = of_find_i2c_device_by_node(slave_node);
if(thisIpcore->i2c == NULL){
dev_err(thisIpcore->dev, "could not find i2c device\n");
return -ENODEV;
}
status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)put_device, &thisIpcore->i2c->dev);
if(status)
return status;

dev_info(thisIpcore->dev, "Adding link to %s[%s]\n", thisIpcore->i2c->adapter->name, thisIpcore->i2c->name);

/* add a link to the i2c device */
status = sysfs_create_link(&thisIpcore->char_device->kobj, &thisIpcore->i2c->dev.kobj, "i2c_device");
if (status)
return status;
status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)mwgen_of_unlink_i2c_device, thisIpcore);
if(status)
return status;

/* add a link to the i2c bus */
status = sysfs_create_link(&thisIpcore->char_device->kobj, &thisIpcore->i2c->adapter->dev.kobj, "i2c_adapter");
if (status)
return status;
status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)mwgen_of_unlink_i2c_adapter, thisIpcore);
if(status)
return status;

} else {
thisIpcore->i2c = NULL;
}

return 0;
}

static int mathworks_generic_of_get_param(struct mathworks_ip_info *thisIpcore, void *arg)
{
struct mathworks_ip_param_info pinfo;
const void *paramData;
int len;

if( copy_from_user(&pinfo, (struct mathworks_ip_param_info *)arg, sizeof(struct mathworks_ip_param_info)) ) {
return -EACCES;
}

paramData = of_get_property(thisIpcore->dev->of_node,pinfo.name, &len);
pinfo.size = len;

/* Copy the struct back to user space */
if( copy_to_user((struct mathworks_ip_param_info*)arg, &pinfo, sizeof(struct mathworks_ip_param_info)) ) {
return -EACCES;
}

/* Copy any data to the user buf */
if (paramData) {
if( copy_to_user((void *)pinfo.buf, paramData, pinfo.size) ){
return -EACCES;
}
} else {
return -ENODEV;
}

return 0;
}

static void mathworks_generic_of_get_devname(struct mathworks_ip_info *thisIpcore,char *devname){
const char *of_devname = of_get_property(thisIpcore->dev->of_node,"mwgen,devname", NULL);

snprintf(devname,MATHWORKS_IP_DEVNAME_LEN, "%s", of_devname);
}

struct mathworks_ip_ops mw_of_ops = {
.get_devname = mathworks_generic_of_get_devname,
.get_param = mathworks_generic_of_get_param,
.fops = &mathworks_ip_common_fops,
};

static const struct of_device_id mathworks_generic_of_match[] = {
{ .compatible = "mathworks,mwgeneric-v1.00",},
{ .compatible = "mathworks,mathworks_ip-v1.00",},
{},

};

MODULE_DEVICE_TABLE(of, mathworks_generic_of_match);


static int mathworks_generic_of_probe(struct platform_device *pdev)
{
int status = 0;
struct mathworks_ip_info *thisIpcore;


thisIpcore = devm_mathworks_ip_of_init(pdev, THIS_MODULE, &mw_of_ops, false);
if (IS_ERR(thisIpcore))
return PTR_ERR(thisIpcore);

status = devm_mathworks_ip_register(thisIpcore);
if(status)
{
dev_err(&pdev->dev, "mwgeneric device registration failed: %d\n", status);
return status;
}

#if defined(CONFIG_I2C)
status = mathworks_generic_of_i2c_init(thisIpcore);
if (status){
dev_err(&pdev->dev, "Failed to link I2C nodes: %d\n", status);
return status;
}
#endif

return 0;
}


static int mathworks_generic_of_remove(struct platform_device *pdev)
{
struct mathworks_ip_info *thisIpcore = dev_get_drvdata(&pdev->dev);

dev_info(thisIpcore->dev, "free and release memory\n");

return 0;
}



static struct platform_driver mathworks_ip_driver = {
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = mathworks_generic_of_match,
},
.probe = mathworks_generic_of_probe,
.remove = mathworks_generic_of_remove,
};

module_platform_driver(mathworks_ip_driver);


MODULE_AUTHOR("MathWorks, Inc");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION(DRIVER_NAME ": MathWorks Generic OF driver");
MODULE_ALIAS(DRIVER_NAME);
Loading