// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2011 Jonathan Cameron * * 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.
*/
/* Fiddly bit of faking and irq without hardware */ #define IIO_EVENTGEN_NO 10
/** * struct iio_dummy_eventgen - event generator specific state * @regs: irq regs we are faking * @lock: protect the evgen state * @inuse: mask of which irqs are connected * @irq_sim_domain: irq simulator domain
*/ struct iio_dummy_eventgen { struct iio_dummy_regs regs[IIO_EVENTGEN_NO]; struct mutex lock; bool inuse[IIO_EVENTGEN_NO]; struct irq_domain *irq_sim_domain;
};
/* We can only ever have one instance of this 'device' */ staticstruct iio_dummy_eventgen *iio_evgen;
staticint iio_dummy_evgen_create(void)
{ int ret;
iio_evgen = kzalloc(sizeof(*iio_evgen), GFP_KERNEL); if (!iio_evgen) return -ENOMEM;
iio_evgen->irq_sim_domain = irq_domain_create_sim(NULL,
IIO_EVENTGEN_NO); if (IS_ERR(iio_evgen->irq_sim_domain)) {
ret = PTR_ERR(iio_evgen->irq_sim_domain);
kfree(iio_evgen); return ret;
}
mutex_init(&iio_evgen->lock);
return 0;
}
/** * 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_create_mapping(iio_evgen->irq_sim_domain, i);
iio_evgen->inuse[i] = true; break;
}
}
mutex_unlock(&iio_evgen->lock); if (i == IIO_EVENTGEN_NO) return -ENOMEM;
/** * 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)
{ struct irq_data *irqd = irq_get_irq_data(irq);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.