gpio: mockup: improve the user-space testing interface
Subsystems (3)
v4 cover gpio: mockup: improve the user-space testing interface
From: Bartosz Golaszewski <[email protected]>
Hi Marc,
another try at the irq_sim stuff. This time I added a notifier chain to irq_sim and made gpio-mockup register a notifier block. This way interested users will get notified about a type config change.
v1 -> v2:
- instead of providing the irq_sim_get_type() helper, move the irq type logic into the simulator and provide a helper that allows users to specify the type of the fired interrupt
v2 -> v3:
- switch back to having irq_sim_type() and put the line state logic into the GPIO testing module
v3- > v4:
- drop irq_sim_get_type() and use a notifier chain instead so that any change in type configuration can be pushed out to interested users
- change the locking mechanism in gpio-mockup to a spinlock as we can't take a mutex when a hardirq-safe spinlock in irq_desc is being held when the irq_set_type() callback is called
- refuse to set any other type than falling or rising edge in irq_set_config
Bartosz Golaszewski (7):
irq/irq_sim: add a notifier chain
gpio: mockup: add locking
gpio: mockup: implement get_multiple()
gpio: mockup: don't create the debugfs link named after the label
gpio: mockup: change the type of 'offset' to unsigned int
gpio: mockup: change the signature of unlocked get/set helpers
gpio: mockup: rework debugfs interface
drivers/gpio/gpio-mockup.c | 215 ++++++++++++++++++++++++++++++++----- include/linux/irq_sim.h | 22 +++- kernel/irq/irq_sim.c | 40 +++++++ 3 files changed, 246 insertions(+), 31 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/7 irq/irq_sim: add a notifier chain
From: Bartosz Golaszewski <[email protected]>
Provide a helper allowing users to register a notifier block with a simulator. For now the only event we're notifying about is a change in type configuration.
This is required by the gpio-mockup module which wants to track the state of GPIO lines and simulate rising and falling edge interrupts.
--- include/linux/irq_sim.h | 22 ++++++++++++++++++---- kernel/irq/irq_sim.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-)
include/linux/irq_sim.h +18 -4
@@ -8,12 +8,21 @@#include <linux/irq_work.h> #include <linux/device.h> +#include <linux/notifier.h> /* * Provides a framework for allocating simulated interrupts which can be * requested like normal irqs and enqueued from process context. */ +#define IRQ_SIM_TYPE_CHANGED 1 + +/* Passed to notifier callbacks when type changes. */ +struct irq_sim_irq_type { +unsigned int offset; +unsigned int type; +}; +struct irq_sim_work_ctx {struct irq_work work;unsigned long *pending;
@@ -22,13 +31,16 @@ struct irq_sim_work_ctx {struct irq_sim_irq_ctx {int irqnum;bool enabled; +struct irq_sim *parent; +struct irq_sim_irq_type type; };struct irq_sim { -struct irq_sim_work_ctx work_ctx; -int irq_base; -unsigned int irq_count; -struct irq_sim_irq_ctx *irqs; +struct irq_sim_work_ctx work_ctx; +int irq_base; +unsigned int irq_count; +struct irq_sim_irq_ctx *irqs; +struct atomic_notifier_head notifier; };int irq_sim_init (struct irq_sim *sim,unsigned int num_irqs);
@@ -37,5 +49,7 @@ int devm_irq_sim_init(struct device *dev, struct irq_sim *sim,void irq_sim_fini (struct irq_sim *sim);void irq_sim_fire (struct irq_sim *sim,unsigned int offset);int irq_sim_irqnum (struct irq_sim *sim,unsigned int offset); +int irq_sim_notifier_register (struct irq_sim *sim, +struct notifier_block *nb);#endif /* _LINUX_IRQ_SIM_H */
kernel/irq/irq_sim.c +40 -0
@@ -25,10 +25,34 @@ static void irq_sim_irqunmask(struct irq_data *data) irq_ctx->enabled = true; } +static int irq_sim_set_type (struct irq_data *data,unsigned int type) +{ +struct irq_sim_irq_ctx *irq_ctx =irq_data_get_irq_chip_data (data); +struct irq_sim *sim = irq_ctx->parent; +int rv; + +/* Only support rising and falling edge types. */ +if (type & ~IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ; + + irq_ctx->type.type = type; + + rv =atomic_notifier_call_chain (&sim->notifier, +IRQ_SIM_TYPE_CHANGED , + &irq_ctx->type); +if (rv <0 ) { +pr_err ("%s: error calling the type notifier chain\n" , __func__); +return rv; + } + +return 0 ; +} +static struct irq_chip irq_sim_irqchip = { .name ="irq_sim" , .irq_mask = irq_sim_irqmask, .irq_unmask = irq_sim_irqunmask, + .irq_set_type = irq_sim_set_type, };static void irq_sim_handle_irq (struct irq_work *work)
@@ -83,7 +107,9 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)for (i =0 ; i < num_irqs; i++) { sim->irqs[i].irqnum = sim->irq_base + i; + sim->irqs[i].parent = sim; sim->irqs[i].enabled = false; + sim->irqs[i].type.offset = i;irq_set_chip (sim->irq_base + i, &irq_sim_irqchip);irq_set_chip_data (sim->irq_base + i, &sim->irqs[i]);irq_set_handler (sim->irq_base + i, &handle_simple_irq);
@@ -91,6 +117,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); } +ATOMIC_INIT_NOTIFIER_HEAD (&sim->notifier);init_irq_work (&sim->work_ctx.work, irq_sim_handle_irq); sim->irq_count = num_irqs;
@@ -180,3 +207,16 @@ int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset)return sim->irqs[offset].irqnum; }EXPORT_SYMBOL_GPL (irq_sim_irqnum); + +/** +* irq_sim_notifier_register - Subscribe for interrupt simulator events. +* +* @sim: The interrupt simulator object. +* @nb: Notifier block. +*/ +int irq_sim_notifier_register (struct irq_sim *sim, +struct notifier_block *nb) +{ +return atomic_notifier_chain_register (&sim->notifier, nb); +} +EXPORT_SYMBOL_GPL (irq_sim_notifier_register);
Signature · 1 line
2.20.1
PATCH v4 2/7 gpio: mockup: add locking
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
While no user reported any race condition problems with gpio-mockup, let's be on the safe side and use a spinlock when performing any changes on the dummy chip structures. We're using a spinlock because a subsequent patch will register an irq_sim notifier which holds the irq_desc lock and if using a mutex we'd get the "HARDIRQ-safe -> HARDIRQ-unsafe" lockdep error.
--- drivers/gpio/gpio-mockup.c | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mockup.c +43 -7
@@ -54,6 +54,7 @@ struct gpio_mockup_chip {struct gpio_mockup_line_status *lines;struct irq_sim irqsim;struct dentry *dbg_dir; +spinlock_t lock; };struct gpio_mockup_dbgfs_private {
@@ -82,29 +83,53 @@ static int gpio_mockup_range_ngpio(unsigned int index)return gpio_mockup_ranges[index *2 +1 ]; } -static int gpio_mockup_get (struct gpio_chip *gc,unsigned int offset) +static int __gpio_mockup_get (struct gpio_chip *gc,unsigned int offset) {struct gpio_mockup_chip *chip =gpiochip_get_data (gc);return chip->lines[offset].value; } -static void gpio_mockup_set (struct gpio_chip *gc, -unsigned int offset,int value) +static int gpio_mockup_get (struct gpio_chip *gc,unsigned int offset) +{ +struct gpio_mockup_chip *chip =gpiochip_get_data (gc); +int val; + +spin_lock (&chip->lock); + val =__gpio_mockup_get (gc, offset); +spin_unlock (&chip->lock); + +return val; +} + +static void __gpio_mockup_set (struct gpio_chip *gc, +unsigned int offset,int value) {struct gpio_mockup_chip *chip =gpiochip_get_data (gc); chip->lines[offset].value = !!value; } +static void gpio_mockup_set (struct gpio_chip *gc, +unsigned int offset,int value) +{ +struct gpio_mockup_chip *chip =gpiochip_get_data (gc); + +spin_lock (&chip->lock); +__gpio_mockup_set (gc, offset, value); +spin_unlock (&chip->lock); +} +static void gpio_mockup_set_multiple (struct gpio_chip *gc,unsigned long *mask,unsigned long *bits) { +struct gpio_mockup_chip *chip =gpiochip_get_data (gc);unsigned int bit; +spin_lock (&chip->lock);for_each_set_bit (bit, mask, gc->ngpio) -gpio_mockup_set (gc, bit,test_bit (bit, bits)); - +__gpio_mockup_set (gc, bit,test_bit (bit, bits)); +spin_unlock (&chip->lock); } static int gpio_mockup_dirout(struct gpio_chip *gc,
@@ -112,8 +137,10 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, {struct gpio_mockup_chip *chip =gpiochip_get_data (gc); -gpio_mockup_set (gc, offset, value); +spin_lock (&chip->lock); chip->lines[offset].dir =GPIO_MOCKUP_DIR_OUT ; +__gpio_mockup_set (gc, offset, value); +spin_unlock (&chip->lock);return 0 ; }
@@ -122,7 +149,9 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) {struct gpio_mockup_chip *chip =gpiochip_get_data (gc); +spin_lock (&chip->lock); chip->lines[offset].dir =GPIO_MOCKUP_DIR_IN ; +spin_unlock (&chip->lock);return 0 ; }
@@ -130,8 +159,13 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset)static int gpio_mockup_get_direction (struct gpio_chip *gc,unsigned int offset) {struct gpio_mockup_chip *chip =gpiochip_get_data (gc); +int direction; -return !chip->lines[offset].dir; +spin_lock (&chip->lock); + direction = !chip->lines[offset].dir; +spin_unlock (&chip->lock); + +return direction; }static int gpio_mockup_to_irq (struct gpio_chip *gc,unsigned int offset)
@@ -283,6 +317,8 @@ static int gpio_mockup_probe(struct platform_device *pdev)return -ENOMEM ; } +spin_lock_init (&chip->lock); + gc = &chip->gc; gc->base = base; gc->ngpio = ngpio;
Signature · 1 line
2.20.1
PATCH v4 3/7 gpio: mockup: implement get_multiple()
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
We already support set_multiple(). Implement get_multiple() as well.
--- drivers/gpio/gpio-mockup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/gpio/gpio-mockup.c +17 -0
@@ -102,6 +102,22 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset)return val; } +static int gpio_mockup_get_multiple (struct gpio_chip *gc, +unsigned long *mask,unsigned long *bits) +{ +struct gpio_mockup_chip *chip =gpiochip_get_data (gc); +unsigned int bit, val; + +spin_lock (&chip->lock); +for_each_set_bit (bit, mask, gc->ngpio) { + val =__gpio_mockup_get (gc, bit); +__assign_bit (bit, bits, val); + } +spin_unlock (&chip->lock); + +return 0 ; +} +static void __gpio_mockup_set (struct gpio_chip *gc,unsigned int offset,int value) {
@@ -327,6 +343,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->parent = dev; gc->get = gpio_mockup_get; gc->set = gpio_mockup_set; + gc->get_multiple = gpio_mockup_get_multiple; gc->set_multiple = gpio_mockup_set_multiple; gc->direction_output = gpio_mockup_dirout; gc->direction_input = gpio_mockup_dirin;
Signature · 1 line
2.20.1
PATCH v4 4/7 gpio: mockup: don't create the debugfs link named after the label
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
User-space tests no longer use it and we're breaking the interface anyway.
--- drivers/gpio/gpio-mockup.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpio/gpio-mockup.c +1 -5
@@ -234,7 +234,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, struct gpio_mockup_chip *chip) {struct gpio_mockup_dbgfs_private *priv; -struct dentry *evfile, *link; +struct dentry *evfile;struct gpio_chip *gc;const char *devname;char *name;
@@ -247,10 +247,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev,if (IS_ERR_OR_NULL (chip->dbg_dir)) goto err; - link =debugfs_create_symlink (gc->label, gpio_mockup_dbg_dir, devname); -if (IS_ERR_OR_NULL (link)) - goto err; -for (i =0 ; i < gc->ngpio; i++) { name =devm_kasprintf (dev,GFP_KERNEL ,"%d" , i);if (!name)
Signature · 1 line
2.20.1
PATCH v4 5/7 gpio: mockup: change the type of 'offset' to unsigned int
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
This field can never be negative.
--- drivers/gpio/gpio-mockup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mockup.c +1 -1
@@ -60,7 +60,7 @@ struct gpio_mockup_chip {struct gpio_mockup_dbgfs_private {struct gpio_mockup_chip *chip;struct gpio_desc *desc; -int offset; +unsigned int offset; };static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES ];
Signature · 1 line
2.20.1
PATCH v4 6/7 gpio: mockup: change the signature of unlocked get/set helpers
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
The unlocked variants only get called from places where we already have the pointer to the underlying gpio_mockup_chip structure, so take it as parameter instead of struct gpio_chip.
--- drivers/gpio/gpio-mockup.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/gpio/gpio-mockup.c +8 -11
@@ -83,10 +83,9 @@ static int gpio_mockup_range_ngpio(unsigned int index)return gpio_mockup_ranges[index *2 +1 ]; } -static int __gpio_mockup_get (struct gpio_chip *gc,unsigned int offset) +static int __gpio_mockup_get (struct gpio_mockup_chip *chip, +unsigned int offset) { -struct gpio_mockup_chip *chip =gpiochip_get_data (gc); -return chip->lines[offset].value; }
@@ -96,7 +95,7 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset)int val;spin_lock (&chip->lock); - val =__gpio_mockup_get (gc, offset); + val =__gpio_mockup_get (chip, offset);spin_unlock (&chip->lock);return val;
@@ -110,7 +109,7 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc,spin_lock (&chip->lock);for_each_set_bit (bit, mask, gc->ngpio) { - val =__gpio_mockup_get (gc, bit); + val =__gpio_mockup_get (chip, bit);__assign_bit (bit, bits, val); }spin_unlock (&chip->lock);
@@ -118,11 +117,9 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc,return 0 ; } -static void __gpio_mockup_set (struct gpio_chip *gc, +static void __gpio_mockup_set (struct gpio_mockup_chip *chip,unsigned int offset,int value) { -struct gpio_mockup_chip *chip =gpiochip_get_data (gc); - chip->lines[offset].value = !!value; }
@@ -132,7 +129,7 @@ static void gpio_mockup_set(struct gpio_chip *gc,struct gpio_mockup_chip *chip =gpiochip_get_data (gc);spin_lock (&chip->lock); -__gpio_mockup_set (gc, offset, value); +__gpio_mockup_set (chip, offset, value);spin_unlock (&chip->lock); }
@@ -144,7 +141,7 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc,spin_lock (&chip->lock);for_each_set_bit (bit, mask, gc->ngpio) -__gpio_mockup_set (gc, bit,test_bit (bit, bits)); +__gpio_mockup_set (chip, bit,test_bit (bit, bits));spin_unlock (&chip->lock); }
@@ -155,7 +152,7 @@ static int gpio_mockup_dirout(struct gpio_chip *gc,spin_lock (&chip->lock); chip->lines[offset].dir =GPIO_MOCKUP_DIR_OUT ; -__gpio_mockup_set (gc, offset, value); +__gpio_mockup_set (chip, offset, value);spin_unlock (&chip->lock);return 0 ;
Signature · 1 line
2.20.1
PATCH v4 7/7 gpio: mockup: rework debugfs interface
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Modify the way the debugfs interface works in gpio-mockup. Introduce the concept of dummy pull config which will keep the mockup lines in known state. The pull values can be modified by writing to the debugfs files corresponding to lines. Lines in input mode always report the current pull value, lines in output mode change the line value but it will revert back to the one specified by current pull when released.
--- drivers/gpio/gpio-mockup.c | 143 +++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 14 deletions(-)
drivers/gpio/gpio-mockup.c +129 -14
@@ -47,6 +47,8 @@ enum {struct gpio_mockup_line_status {int dir;int value; +int pull; +int irq_type; };struct gpio_mockup_chip {
@@ -55,6 +57,7 @@ struct gpio_mockup_chip {struct irq_sim irqsim;struct dentry *dbg_dir;spinlock_t lock; +struct notifier_block nb; };struct gpio_mockup_dbgfs_private {
@@ -73,6 +76,11 @@ module_param_named(gpio_mockup_named_lines,static struct dentry *gpio_mockup_dbg_dir; +static struct gpio_mockup_chip *to_gpio_mockup_chip (struct notifier_block *nb) +{ + return container_of(nb, struct gpio_mockup_chip, nb); +} +static int gpio_mockup_range_base (unsigned int index) {return gpio_mockup_ranges[index *2 ];
@@ -188,15 +196,72 @@ static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset)return irq_sim_irqnum (&chip->irqsim, offset); } -static ssize_t gpio_mockup_event_write (struct file *file, -const char __user *usr_buf, -size_t size,loff_t *ppos) +static void gpio_mockup_free (struct gpio_chip *gc,unsigned int offset) +{ +struct gpio_mockup_chip *chip =gpiochip_get_data (gc); + +__gpio_mockup_set (chip, offset, chip->lines[offset].pull); +} + +static int gpio_mockup_irq_type_changed (struct notifier_block *nb, +unsigned long event,void *data) +{ +struct gpio_mockup_chip *chip =to_gpio_mockup_chip (nb); +struct irq_sim_irq_type *irq_type = data; + +if (event !=IRQ_SIM_TYPE_CHANGED ) +return NOTIFY_DONE ; + +/* FIXME: add locking once we switch to spinlocks */ + chip->lines[irq_type->offset].irq_type = irq_type->type; + +return NOTIFY_OK ; +} + +static ssize_t gpio_mockup_debugfs_read (struct file *file, +char __user *usr_buf, +size_t size,loff_t *ppos) +{ +struct gpio_mockup_dbgfs_private *priv; +struct gpio_mockup_chip *chip; +struct seq_file *sfile; +struct gpio_chip *gc; +char buf[3 ]; +int val, rv; + +if (*ppos !=0 ) +return 0 ; + + sfile = file->private_data; + priv = sfile->private; + chip = priv->chip; + gc = &chip->gc; + + val =gpio_mockup_get (gc, priv->offset); +snprintf (buf,sizeof (buf),"%d\n" , val); + + rv =copy_to_user (usr_buf, buf,sizeof (buf)); +if (rv) +return rv; + +return sizeof (buf) -1 ; +} + +static ssize_t gpio_mockup_debugfs_write (struct file *file, +const char __user *usr_buf, +size_t size,loff_t *ppos) {struct gpio_mockup_dbgfs_private *priv;struct gpio_mockup_chip *chip;struct seq_file *sfile;struct gpio_desc *desc; -int rv, val; +unsigned int irq_type; +struct gpio_chip *gc; +struct irq_sim *sim; +int rv, val, curr; + +if (*ppos !=0 ) +return -EINVAL ; rv =kstrtoint_from_user (usr_buf, size,0 , &val);if (rv)
@@ -206,24 +271,68 @@ static ssize_t gpio_mockup_event_write(struct file *file, sfile = file->private_data; priv = sfile->private; - desc = priv->desc; chip = priv->chip; + gc = &chip->gc; + desc = &gc->gpiodev->descs[priv->offset]; + sim = &chip->irqsim; + +spin_lock (&chip->lock); -gpiod_set_value_cansleep (desc, val); -irq_sim_fire (&chip->irqsim, priv->offset); +if (test_bit (FLAG_REQUESTED , &desc->flags) && + !test_bit (FLAG_IS_OUT , &desc->flags)) { + curr =__gpio_mockup_get (chip, priv->offset); +if (curr == val) + goto out; + + irq_type = chip->lines[priv->offset].irq_type; +if ((val ==1 && (irq_type &IRQ_TYPE_EDGE_RISING )) || + (val ==0 && (irq_type &IRQ_TYPE_EDGE_FALLING ))) +irq_sim_fire (&chip->irqsim, priv->offset); + } + +/* Change the value unless we're actively driving the line. */ +if (!test_bit (FLAG_REQUESTED , &desc->flags) || + !test_bit (FLAG_IS_OUT , &desc->flags)) +__gpio_mockup_set (chip, priv->offset, val); + +out: + chip->lines[priv->offset].pull = val; +spin_unlock (&chip->lock);return size; } -static int gpio_mockup_event_open (struct inode *inode,struct file *file) +static int gpio_mockup_debugfs_open (struct inode *inode,struct file *file) {return single_open (file,NULL , inode->i_private); } -static const struct file_operations gpio_mockup_event_ops = { +/* +* Each mockup chip is represented by a directory named after the chip's device +* name under /sys/kernel/debug/gpio-mockup/. Each line is represented by +* a file using the line's offset as the name under the chip's directory. +* +* Reading from the line's file yields the current *value*, writing to the +* line's file changes the current *pull*. Default pull for mockup lines is +* down. +* +* Examples: +* - when a line pulled down is requested in output mode and driven high, its +* value will return to 0 once it's released +* - when the line is requested in output mode and driven high, writing 0 to +* the corresponding debugfs file will change the pull to down but the +* reported value will still be 1 until the line is released +* - line requested in input mode always reports the same value as its pull +* configuration +* - when the line is requested in input mode and monitored for events, writing +* the same value to the debugfs file will be a noop, while writing the +* opposite value will generate a dummy interrupt with an appropriate edge +*/ +static const struct file_operations gpio_mockup_debugfs_ops = { .owner =THIS_MODULE , - .open = gpio_mockup_event_open, - .write = gpio_mockup_event_write, + .open = gpio_mockup_debugfs_open, + .read = gpio_mockup_debugfs_read, + .write = gpio_mockup_debugfs_write, .llseek = no_llseek, };
@@ -258,7 +367,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, priv->desc = &gc->gpiodev->descs[i]; evfile =debugfs_create_file (name,0200 , chip->dbg_dir, priv, - &gpio_mockup_event_ops); + &gpio_mockup_debugfs_ops);if (IS_ERR_OR_NULL (evfile)) goto err; }
@@ -266,7 +375,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev,return ; err: -dev_err (dev,"error creating debugfs event files\n" ); +dev_err (dev,"error creating debugfs files\n" ); } static int gpio_mockup_name_lines(struct device *dev,
@@ -342,6 +451,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->direction_input = gpio_mockup_dirin; gc->get_direction = gpio_mockup_get_direction; gc->to_irq = gpio_mockup_to_irq; + gc->free = gpio_mockup_free; chip->lines =devm_kcalloc (dev, gc->ngpio,sizeof (*chip->lines),GFP_KERNEL );
@@ -358,6 +468,11 @@ static int gpio_mockup_probe(struct platform_device *pdev)if (rv <0 )return rv; + chip->nb.notifier_call = gpio_mockup_irq_type_changed; + rv =irq_sim_notifier_register (&chip->irqsim, &chip->nb); +if (rv) +return rv; + rv =devm_gpiochip_add_data (dev, &chip->gc, chip);if (rv)return rv;
@@ -415,7 +530,7 @@ static int __init gpio_mockup_init(void)return -EINVAL ; } - gpio_mockup_dbg_dir =debugfs_create_dir ("gpio-mockup-event" ,NULL ); + gpio_mockup_dbg_dir =debugfs_create_dir ("gpio-mockup" ,NULL );if (IS_ERR_OR_NULL (gpio_mockup_dbg_dir))gpio_mockup_err ("error creating debugfs directory\n" );
Signature · 1 line
2.20.1
czw., 14 lut 2019 o 14:42 Bartosz Golaszewski <[email protected]> napisał(a):
Quoted 35 lines
From: Bartosz Golaszewski <[email protected]>
Hi Marc,
another try at the
irq_simstuff. This time I added a notifier chain toirq_simand made gpio-mockup register a notifier block. This way interested users will get notified about a type config change.v1 -> v2:
- instead of providing theirq_sim_get_type()helper, move the irq type logic into the simulator and provide a helper that allows users to specify the type of the fired interruptv2 -> v3:
- switch back to havingirq_sim_type()and put the line state logic into the GPIO testing modulev3- > v4:
- dropirq_sim_get_type()and use a notifier chain instead so that any change in type configuration can be pushed out to interested users
- change the locking mechanism in gpio-mockup to a spinlock as we can't take a mutex when a hardirq-safe spinlock inirq_descis being held when theirq_set_type()callback is called
- refuse to set any other type than falling or rising edge inirq_set_configBartosz Golaszewski (7):
irq/irq_sim: add a notifier chain
gpio: mockup: add locking
gpio: mockup: implementget_multiple()
gpio: mockup: don't create the debugfs link named after the label
gpio: mockup: change the type of 'offset' to unsigned int
gpio: mockup: change the signature of unlocked get/set helpers
gpio: mockup: rework debugfs interface
Quoted 8 lines
drivers/gpio/gpio-mockup.c | 215 ++++++++++++++++++++++++++++++++----- include/linux/irq_sim.h | 22 +++- kernel/irq/irq_sim.c | 40 +++++++ 3 files changed, 246 insertions(+), 31 deletions(-)--
2.20.1
Since this really is overkill, I sent v5 in which I simple store the trigger type by calling irqd_set_trigger_type().
Superseded by v5.
Bartosz