Release 4.16 drivers/iio/dummy/iio_dummy_evgen.c
/**
* Copyright (c) 2011 Jonathan Cameron
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* Companion module to the iio simple dummy example driver.
* The purpose of this is to generate 'fake' event interrupts thus
* allowing that driver's code to be as close as possible to that of
* a normal driver talking to hardware. The approach used here
* is not intended to be general and just happens to work for this
* particular use case.
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/mutex.h>
#include <linux/module.h>
#include <linux/sysfs.h>
#include "iio_dummy_evgen.h"
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/irq_sim.h>
/* Fiddly bit of faking and irq without hardware */
#define IIO_EVENTGEN_NO 10
/**
* @regs: irq regs we are faking
* @lock: protect the evgen state
* @inuse: mask of which irqs are connected
* @irq_sim: interrupt simulator
* @base: base of irq range
*/
struct iio_dummy_eventgen {
struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
struct mutex lock;
bool inuse[IIO_EVENTGEN_NO];
struct irq_sim irq_sim;
int base;
};
/* We can only ever have one instance of this 'device' */
static struct iio_dummy_eventgen *iio_evgen;
static int iio_dummy_evgen_create(void)
{
int ret;
iio_evgen = kzalloc(sizeof(*iio_evgen), GFP_KERNEL);
if (!iio_evgen)
return -ENOMEM;
ret = irq_sim_init(&iio_evgen->irq_sim, IIO_EVENTGEN_NO);
if (ret < 0) {
kfree(iio_evgen);
return ret;
}
iio_evgen->base = irq_sim_irqnum(&iio_evgen->irq_sim, 0);
mutex_init(&iio_evgen->lock);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 65 | 75.58% | 1 | 20.00% |
Bartosz Golaszewski | 13 | 15.12% | 2 | 40.00% |
Cristina Opriceana | 8 | 9.30% | 2 | 40.00% |
Total | 86 | 100.00% | 5 | 100.00% |
/**
* iio_dummy_evgen_get_irq() - get an evgen provided irq for a device
*
* This function will give a free allocated irq to a client device.
* That irq can then be caused to 'fire' by using the associated sysfs file.
*/
int iio_dummy_evgen_get_irq(void)
{
int i, ret = 0;
if (!iio_evgen)
return -ENODEV;
mutex_lock(&iio_evgen->lock);
for (i = 0; i < IIO_EVENTGEN_NO; i++) {
if (!iio_evgen->inuse[i]) {
ret = irq_sim_irqnum(&iio_evgen->irq_sim, i);
iio_evgen->inuse[i] = true;
break;
}
}
mutex_unlock(&iio_evgen->lock);
if (i == IIO_EVENTGEN_NO)
return -ENOMEM;
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 83 | 82.18% | 1 | 20.00% |
Sasha Levin | 8 | 7.92% | 1 | 20.00% |
Bartosz Golaszewski | 8 | 7.92% | 1 | 20.00% |
Cristina Opriceana | 1 | 0.99% | 1 | 20.00% |
Lars-Peter Clausen | 1 | 0.99% | 1 | 20.00% |
Total | 101 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_irq);
/**
* iio_dummy_evgen_release_irq() - give the irq back.
* @irq: irq being returned to the pool
*
* Used by client driver instances to give the irqs back when they disconnect
*/
void iio_dummy_evgen_release_irq(int irq)
{
mutex_lock(&iio_evgen->lock);
iio_evgen->inuse[irq - iio_evgen->base] = false;
mutex_unlock(&iio_evgen->lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 36 | 97.30% | 1 | 50.00% |
Vladimirs Ambrosovs | 1 | 2.70% | 1 | 50.00% |
Total | 37 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
{
return &iio_evgen->regs[irq - iio_evgen->base];
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Baluta | 23 | 100.00% | 1 | 100.00% |
Total | 23 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
static void iio_dummy_evgen_free(void)
{
irq_sim_fini(&iio_evgen->irq_sim);
kfree(iio_evgen);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 18 | 85.71% | 1 | 50.00% |
Bartosz Golaszewski | 3 | 14.29% | 1 | 50.00% |
Total | 21 | 100.00% | 2 | 100.00% |
static void iio_evgen_release(struct device *dev)
{
iio_dummy_evgen_free();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 14 | 100.00% | 1 | 100.00% |
Total | 14 | 100.00% | 1 | 100.00% |
static ssize_t iio_evgen_poke(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t len)
{
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
unsigned long event;
int ret;
ret = kstrtoul(buf, 10, &event);
if (ret)
return ret;
iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
iio_evgen->regs[this_attr->address].reg_data = event;
irq_sim_fire(&iio_evgen->irq_sim, this_attr->address);
return len;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Baluta | 54 | 52.43% | 1 | 25.00% |
Jonathan Cameron | 42 | 40.78% | 1 | 25.00% |
Bartosz Golaszewski | 5 | 4.85% | 1 | 25.00% |
Cristina Opriceana | 2 | 1.94% | 1 | 25.00% |
Total | 103 | 100.00% | 4 | 100.00% |
static IIO_DEVICE_ATTR(poke_ev0, S_IWUSR, NULL, &iio_evgen_poke, 0);
static IIO_DEVICE_ATTR(poke_ev1, S_IWUSR, NULL, &iio_evgen_poke, 1);
static IIO_DEVICE_ATTR(poke_ev2, S_IWUSR, NULL, &iio_evgen_poke, 2);
static IIO_DEVICE_ATTR(poke_ev3, S_IWUSR, NULL, &iio_evgen_poke, 3);
static IIO_DEVICE_ATTR(poke_ev4, S_IWUSR, NULL, &iio_evgen_poke, 4);
static IIO_DEVICE_ATTR(poke_ev5, S_IWUSR, NULL, &iio_evgen_poke, 5);
static IIO_DEVICE_ATTR(poke_ev6, S_IWUSR, NULL, &iio_evgen_poke, 6);
static IIO_DEVICE_ATTR(poke_ev7, S_IWUSR, NULL, &iio_evgen_poke, 7);
static IIO_DEVICE_ATTR(poke_ev8, S_IWUSR, NULL, &iio_evgen_poke, 8);
static IIO_DEVICE_ATTR(poke_ev9, S_IWUSR, NULL, &iio_evgen_poke, 9);
static struct attribute *iio_evgen_attrs[] = {
&iio_dev_attr_poke_ev0.dev_attr.attr,
&iio_dev_attr_poke_ev1.dev_attr.attr,
&iio_dev_attr_poke_ev2.dev_attr.attr,
&iio_dev_attr_poke_ev3.dev_attr.attr,
&iio_dev_attr_poke_ev4.dev_attr.attr,
&iio_dev_attr_poke_ev5.dev_attr.attr,
&iio_dev_attr_poke_ev6.dev_attr.attr,
&iio_dev_attr_poke_ev7.dev_attr.attr,
&iio_dev_attr_poke_ev8.dev_attr.attr,
&iio_dev_attr_poke_ev9.dev_attr.attr,
NULL,
};
static const struct attribute_group iio_evgen_group = {
.attrs = iio_evgen_attrs,
};
static const struct attribute_group *iio_evgen_groups[] = {
&iio_evgen_group,
NULL
};
static struct device iio_evgen_dev = {
.bus = &iio_bus_type,
.groups = iio_evgen_groups,
.release = &iio_evgen_release,
};
static __init int iio_dummy_evgen_init(void)
{
int ret = iio_dummy_evgen_create();
if (ret < 0)
return ret;
device_initialize(&iio_evgen_dev);
dev_set_name(&iio_evgen_dev, "iio_evgen");
return device_add(&iio_evgen_dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 45 | 100.00% | 1 | 100.00% |
Total | 45 | 100.00% | 1 | 100.00% |
module_init(iio_dummy_evgen_init);
static __exit void iio_dummy_evgen_exit(void)
{
device_unregister(&iio_evgen_dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 15 | 100.00% | 1 | 100.00% |
Total | 15 | 100.00% | 1 | 100.00% |
module_exit(iio_dummy_evgen_exit);
MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
MODULE_DESCRIPTION("IIO dummy driver");
MODULE_LICENSE("GPL v2");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jonathan Cameron | 690 | 81.56% | 3 | 27.27% |
Daniel Baluta | 89 | 10.52% | 1 | 9.09% |
Bartosz Golaszewski | 42 | 4.96% | 2 | 18.18% |
Cristina Opriceana | 15 | 1.77% | 2 | 18.18% |
Sasha Levin | 8 | 0.95% | 1 | 9.09% |
Vladimirs Ambrosovs | 1 | 0.12% | 1 | 9.09% |
Lars-Peter Clausen | 1 | 0.12% | 1 | 9.09% |
Total | 846 | 100.00% | 11 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.