如何从内核模块提供中断生成GPIO
我已经编写了一个(工作)内核模块,该模块使用返回struct gpio_chip
实例来指定应处理读取和写入的方式(使用模块提供的GPIO)。
static struct gpio_chip template_chip = {
.label = "my_module",
.owner = THIS_MODULE,
.get_direction = my_module_gpio_get_direction,
.direction_input = my_module_gpio_direction_in,
.get = my_module_gpio_get,
.direction_output = my_module_gpio_direction_out,
.set = my_module_gpio_set,
.to_irq = my_module_gpio_to_irq,
.can_sleep = true,
};
static int my_module_gpio_probe(struct platform_device *pdev)
{
struct my_module *my_module = dev_get_drvdata(pdev->dev.parent);
struct my_module_platform_data *pdata = dev_get_platdata(my_module->dev);
struct my_module_gpio_data *my_module_gpio;
int ret;
printk(KERN_INFO "my_module_gpio_probe\n");
my_module_gpio = devm_kzalloc(&pdev->dev, sizeof(*my_module_gpio), GFP_KERNEL);
if (my_module_gpio == NULL)
return -ENOMEM;
my_module_gpio->my_module = my_module;
my_module_gpio->gpio_chip = template_chip;
my_module_gpio->gpio_chip.ngpio = NUM_GPIOS;
my_module_gpio->gpio_chip.parent = &pdev->dev;
...
我现在希望我的(软件生成的)gpios能够产生当我的模块更改GPIO值时,中断。
我想支持旧的/sys/class/gpio
接口和新的Chardev接口。
在谷歌搜索时,我发现了许多消费中断内核模块中的示例。
我需要为制作中断我的模块的GPIO吗?
I've written a (working) kernel module which uses returns a struct gpio_chip
instance to specify how reads and writes (using the module-provided GPIOs) should be handled.
static struct gpio_chip template_chip = {
.label = "my_module",
.owner = THIS_MODULE,
.get_direction = my_module_gpio_get_direction,
.direction_input = my_module_gpio_direction_in,
.get = my_module_gpio_get,
.direction_output = my_module_gpio_direction_out,
.set = my_module_gpio_set,
.to_irq = my_module_gpio_to_irq,
.can_sleep = true,
};
static int my_module_gpio_probe(struct platform_device *pdev)
{
struct my_module *my_module = dev_get_drvdata(pdev->dev.parent);
struct my_module_platform_data *pdata = dev_get_platdata(my_module->dev);
struct my_module_gpio_data *my_module_gpio;
int ret;
printk(KERN_INFO "my_module_gpio_probe\n");
my_module_gpio = devm_kzalloc(&pdev->dev, sizeof(*my_module_gpio), GFP_KERNEL);
if (my_module_gpio == NULL)
return -ENOMEM;
my_module_gpio->my_module = my_module;
my_module_gpio->gpio_chip = template_chip;
my_module_gpio->gpio_chip.ngpio = NUM_GPIOS;
my_module_gpio->gpio_chip.parent = &pdev->dev;
...
I now want my (software generated) GPIOs to be able to produce an interrupt when my module changes the GPIO values.
I want to support both the old /sys/class/gpio
interface and the new chardev interface.
While googling, I've found lots of examples of how to consume interrupts in a kernel module.
What do I need to do to produce interrupts for my module's GPIOs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了测试内核内的GPIO库,已经创建了
gpio-sim
模块,该模块模拟了常规GPIO芯片可以执行的操作,包括中断生成。负责此的代码位于 <代码> gpio_sim_apply_pull() 。不要查看函数名称,因为它只是应用人造线的完整状态。
请注意,在较旧的内核中,出于类似目的,存在
gpio-mockup
驱动程序。In order to test GPIO library inside the kernel the
gpio-sim
module has been created which emulates what regular GPIO chip can do, including interrupt generation.The code responsible for that is located in the
gpio_sim_apply_pull()
. Don't look at the function name, because it just applies the full state of the artificial line.Note, that in the older kernels the
gpio-mockup
driver is present for the similar purposes.