Modify

Opened 4 years ago

Last modified 3 years ago

#14309 assigned defect

gpio_free() / pinctrl doesnt work for ralink trunk

Reported by: info@… Owned by: blogic
Priority: normal Milestone: Chaos Calmer 15.05
Component: kernel Version: Trunk
Keywords: Cc:

Description

there seems to be a missing link between gpio_free and pinctrl_free_gpio()
It just request a GPIO and freeing it at module unload. Reloading the module generates error (pin already used)
Here is the according dmesg: (Carambola1 with RT3052 using actual trunk 38333)

insmod gpio-test
[ 3814.150000] GPIO Test: requesting GPIO 12
[ 3814.150000] rt2880-pinmux pinctrl.1: request pin 12 (io12) for pio:12
rmmod gpio-test
[ 3825.000000] GPIO Test: freeing GPIO 12
insmod gpio-test # again
[ 3832.250000] GPIO Test: requesting GPIO 12
[ 3832.250000] rt2880-pinmux pinctrl.1: request pin 12 (io12) for pio:12
[ 3832.250000] rt2880-pinmux pinctrl.1: pin io12 already requested by pio:12; cannot claim for pio:12
[ 3832.260000] rt2880-pinmux pinctrl.1: pin-12 (pio:12) status -22
[ 3832.270000] GPIO Test: didn't get 12

Here is the code:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/gpio.h>

#define DRV_NAME "GPIO Test"
#define PFX DRV_NAME ": "
#define GPIO_TEST_PIN 12

static int __init mymodule_init(void) {
    int err;
    printk (KERN_INFO PFX "requesting GPIO %d\n", GPIO_TEST_PIN);
    err = gpio_request(GPIO_TEST_PIN, "GPIO TEST");
    if (err ) {
        printk (KERN_ERR PFX "didn't get %d\n", GPIO_TEST_PIN);
        return -1;
    }
    return 0;
}

static void __exit mymodule_exit(void) {
   printk (KERN_INFO PFX "freeing GPIO %d\n", GPIO_TEST_PIN);
   gpio_free(GPIO_TEST_PIN);
   return;
}

module_init(mymodule_init);
module_exit(mymodule_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mister X");

Attachments (1)

ralink_gpio_fix_free.patch (725 bytes) - added by schildt 3 years ago.
Fix pin release (tested on WRTNode)

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years ago by florian

  • Owner changed from developers to blogic
  • Status changed from new to assigned

comment:2 Changed 4 years ago by anonymous

My RT5350 board WiFi led does not light estimate is for this reason

comment:3 Changed 4 years ago by anonymous

r39131 hadn't fix it.

Changed 3 years ago by schildt

Fix pin release (tested on WRTNode)

comment:4 Changed 3 years ago by schildt

The attached patch offers the "glue code", fixing the unexport/release of a pin

It is still against the old 3.10 OpenWRT kernel for ramips, but I guess it should work with the newer kernel too.

Actually to test, no kernel module is needed. In trunk the sequence

echo 17 > /sys/class/gpio/export
echo 17 > /sys/class/gpio/unexport
echo 17 > /sys/class/gpio/export

fails at the second export as described in this ticket. With this patch it works.

Last edited 3 years ago by schildt (previous) (diff)

comment:5 Changed 3 years ago by info@…

fixed with changeset 42788 - thx !

Add Comment

Modify Ticket

Action
as assigned .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.