Lines Matching refs:desc

44 	struct gpio_desc	*desc = dev_get_drvdata(dev);  in gpio_direction_show()  local
49 if (!test_bit(FLAG_EXPORT, &desc->flags)) { in gpio_direction_show()
52 gpiod_get_direction(desc); in gpio_direction_show()
54 test_bit(FLAG_IS_OUT, &desc->flags) in gpio_direction_show()
65 struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_direction_store() local
70 if (!test_bit(FLAG_EXPORT, &desc->flags)) in gpio_direction_store()
73 status = gpiod_direction_output_raw(desc, 1); in gpio_direction_store()
75 status = gpiod_direction_output_raw(desc, 0); in gpio_direction_store()
77 status = gpiod_direction_input(desc); in gpio_direction_store()
91 struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_value_show() local
96 if (!test_bit(FLAG_EXPORT, &desc->flags)) in gpio_value_show()
99 status = sprintf(buf, "%d\n", gpiod_get_value_cansleep(desc)); in gpio_value_show()
108 struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_value_store() local
113 if (!test_bit(FLAG_EXPORT, &desc->flags)) in gpio_value_store()
115 else if (!test_bit(FLAG_IS_OUT, &desc->flags)) in gpio_value_store()
122 gpiod_set_value_cansleep(desc, value); in gpio_value_store()
142 static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, in gpio_setup_irq() argument
149 if ((desc->flags & GPIO_TRIGGER_MASK) == gpio_flags) in gpio_setup_irq()
152 irq = gpiod_to_irq(desc); in gpio_setup_irq()
156 id = desc->flags >> ID_SHIFT; in gpio_setup_irq()
161 desc->flags &= ~GPIO_TRIGGER_MASK; in gpio_setup_irq()
164 gpiochip_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); in gpio_setup_irq()
171 irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? in gpio_setup_irq()
174 irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? in gpio_setup_irq()
189 desc->flags &= GPIO_FLAGS_MASK; in gpio_setup_irq()
190 desc->flags |= (unsigned long)id << ID_SHIFT; in gpio_setup_irq()
192 if (desc->flags >> ID_SHIFT != id) { in gpio_setup_irq()
203 ret = gpiochip_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); in gpio_setup_irq()
205 gpiod_warn(desc, "failed to flag the GPIO for IRQ\n"); in gpio_setup_irq()
209 desc->flags |= gpio_flags; in gpio_setup_irq()
214 desc->flags &= GPIO_FLAGS_MASK; in gpio_setup_irq()
235 const struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_edge_show() local
240 if (!test_bit(FLAG_EXPORT, &desc->flags)) in gpio_edge_show()
247 if ((desc->flags & GPIO_TRIGGER_MASK) in gpio_edge_show()
262 struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_edge_store() local
274 if (!test_bit(FLAG_EXPORT, &desc->flags)) in gpio_edge_store()
277 status = gpio_setup_irq(desc, dev, trigger_types[i].flags); in gpio_edge_store()
289 static int sysfs_set_active_low(struct gpio_desc *desc, struct device *dev, in sysfs_set_active_low() argument
294 if (!!test_bit(FLAG_ACTIVE_LOW, &desc->flags) == !!value) in sysfs_set_active_low()
298 set_bit(FLAG_ACTIVE_LOW, &desc->flags); in sysfs_set_active_low()
300 clear_bit(FLAG_ACTIVE_LOW, &desc->flags); in sysfs_set_active_low()
303 if (dev != NULL && (!!test_bit(FLAG_TRIG_RISE, &desc->flags) ^ in sysfs_set_active_low()
304 !!test_bit(FLAG_TRIG_FALL, &desc->flags))) { in sysfs_set_active_low()
305 unsigned long trigger_flags = desc->flags & GPIO_TRIGGER_MASK; in sysfs_set_active_low()
307 gpio_setup_irq(desc, dev, 0); in sysfs_set_active_low()
308 status = gpio_setup_irq(desc, dev, trigger_flags); in sysfs_set_active_low()
317 const struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_active_low_show() local
322 if (!test_bit(FLAG_EXPORT, &desc->flags)) in gpio_active_low_show()
326 !!test_bit(FLAG_ACTIVE_LOW, &desc->flags)); in gpio_active_low_show()
336 struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_active_low_store() local
341 if (!test_bit(FLAG_EXPORT, &desc->flags)) { in gpio_active_low_store()
348 status = sysfs_set_active_low(desc, dev, value != 0); in gpio_active_low_store()
363 struct gpio_desc *desc = dev_get_drvdata(dev); in gpio_is_visible() local
365 bool show_direction = test_bit(FLAG_SYSFS_DIR, &desc->flags); in gpio_is_visible()
371 if (gpiod_to_irq(desc) < 0) in gpio_is_visible()
373 if (!show_direction && test_bit(FLAG_IS_OUT, &desc->flags)) in gpio_is_visible()
451 struct gpio_desc *desc; in export_store() local
458 desc = gpio_to_desc(gpio); in export_store()
460 if (!desc) { in export_store()
470 status = gpiod_request(desc, "sysfs"); in export_store()
476 status = gpiod_export(desc, true); in export_store()
478 gpiod_free(desc); in export_store()
480 set_bit(FLAG_SYSFS, &desc->flags); in export_store()
493 struct gpio_desc *desc; in unexport_store() local
500 desc = gpio_to_desc(gpio); in unexport_store()
502 if (!desc) { in unexport_store()
513 if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) { in unexport_store()
515 gpiod_free(desc); in unexport_store()
552 int gpiod_export(struct gpio_desc *desc, bool direction_may_change) in gpiod_export() argument
567 if (!desc) { in gpiod_export()
572 chip = desc->chip; in gpiod_export()
583 if (!test_bit(FLAG_REQUESTED, &desc->flags) || in gpiod_export()
584 test_bit(FLAG_EXPORT, &desc->flags)) { in gpiod_export()
586 gpiod_dbg(desc, "%s: unavailable (requested=%d, exported=%d)\n", in gpiod_export()
588 test_bit(FLAG_REQUESTED, &desc->flags), in gpiod_export()
589 test_bit(FLAG_EXPORT, &desc->flags)); in gpiod_export()
594 if (desc->chip->direction_input && desc->chip->direction_output && in gpiod_export()
596 set_bit(FLAG_SYSFS_DIR, &desc->flags); in gpiod_export()
601 offset = gpio_chip_hwgpio(desc); in gpiod_export()
602 if (desc->chip->names && desc->chip->names[offset]) in gpiod_export()
603 ioname = desc->chip->names[offset]; in gpiod_export()
605 dev = device_create_with_groups(&gpio_class, desc->chip->dev, in gpiod_export()
606 MKDEV(0, 0), desc, gpio_groups, in gpiod_export()
608 desc_to_gpio(desc)); in gpiod_export()
614 set_bit(FLAG_EXPORT, &desc->flags); in gpiod_export()
620 gpiod_dbg(desc, "%s: status %d\n", __func__, status); in gpiod_export()
642 struct gpio_desc *desc) in gpiod_export_link() argument
646 if (!desc) { in gpiod_export_link()
653 if (test_bit(FLAG_EXPORT, &desc->flags)) { in gpiod_export_link()
656 tdev = class_find_device(&gpio_class, NULL, desc, match_export); in gpiod_export_link()
669 gpiod_dbg(desc, "%s: status %d\n", __func__, status); in gpiod_export_link()
687 int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value) in gpiod_sysfs_set_active_low() argument
692 if (!desc) { in gpiod_sysfs_set_active_low()
699 if (test_bit(FLAG_EXPORT, &desc->flags)) { in gpiod_sysfs_set_active_low()
700 dev = class_find_device(&gpio_class, NULL, desc, match_export); in gpiod_sysfs_set_active_low()
707 status = sysfs_set_active_low(desc, dev, value); in gpiod_sysfs_set_active_low()
713 gpiod_dbg(desc, "%s: status %d\n", __func__, status); in gpiod_sysfs_set_active_low()
725 void gpiod_unexport(struct gpio_desc *desc) in gpiod_unexport() argument
730 if (!desc) { in gpiod_unexport()
737 if (test_bit(FLAG_EXPORT, &desc->flags)) { in gpiod_unexport()
739 dev = class_find_device(&gpio_class, NULL, desc, match_export); in gpiod_unexport()
741 gpio_setup_irq(desc, dev, 0); in gpiod_unexport()
742 clear_bit(FLAG_SYSFS_DIR, &desc->flags); in gpiod_unexport()
743 clear_bit(FLAG_EXPORT, &desc->flags); in gpiod_unexport()
756 gpiod_dbg(desc, "%s: status %d\n", __func__, status); in gpiod_unexport()
795 struct gpio_desc *desc; in gpiochip_unexport() local
815 desc = &chip->desc[i]; in gpiochip_unexport()
816 if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) in gpiochip_unexport()
817 gpiod_free(desc); in gpiochip_unexport()