Lines Matching refs:desc

34 static void gpio_desc_init(struct gpio_desc *desc,  in gpio_desc_init()  argument
38 desc->dev = dev; in gpio_desc_init()
39 desc->offset = offset; in gpio_desc_init()
40 desc->flags = 0; in gpio_desc_init()
54 static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc) in gpio_to_device() argument
66 gpio_desc_init(desc, dev, gpio - uc_priv->gpio_base); in gpio_to_device()
114 int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) in dm_gpio_lookup_name() argument
154 gpio_desc_init(desc, dev, offset); in dm_gpio_lookup_name()
162 struct gpio_desc desc; in gpio_lookup_name() local
167 ret = dm_gpio_lookup_name(name, &desc); in gpio_lookup_name()
172 *devp = desc.dev; in gpio_lookup_name()
174 *offsetp = desc.offset; in gpio_lookup_name()
176 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(desc.dev); in gpio_lookup_name()
178 *gpiop = uc_priv->gpio_base + desc.offset; in gpio_lookup_name()
184 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, in gpio_xlate_offs_flags() argument
190 desc->offset = args->args[0]; in gpio_xlate_offs_flags()
195 desc->flags = 0; in gpio_xlate_offs_flags()
197 desc->flags |= GPIOD_ACTIVE_LOW; in gpio_xlate_offs_flags()
206 desc->flags |= GPIOD_OPEN_DRAIN; in gpio_xlate_offs_flags()
208 desc->flags |= GPIOD_OPEN_SOURCE; in gpio_xlate_offs_flags()
212 desc->flags |= GPIOD_PULL_UP; in gpio_xlate_offs_flags()
215 desc->flags |= GPIOD_PULL_DOWN; in gpio_xlate_offs_flags()
220 static int gpio_find_and_xlate(struct gpio_desc *desc, in gpio_find_and_xlate() argument
223 struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); in gpio_find_and_xlate()
226 return ops->xlate(desc->dev, desc, args); in gpio_find_and_xlate()
228 return gpio_xlate_offs_flags(desc->dev, desc, args); in gpio_find_and_xlate()
323 int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc) in gpio_hog_lookup_name() argument
327 *desc = NULL; in gpio_hog_lookup_name()
332 *desc = &priv->gpiod; in gpio_hog_lookup_name()
348 int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc) in gpio_hog_lookup_name() argument
354 int dm_gpio_request(struct gpio_desc *desc, const char *label) in dm_gpio_request() argument
356 struct udevice *dev = desc->dev; in dm_gpio_request()
362 if (uc_priv->name[desc->offset]) in dm_gpio_request()
368 ret = gpio_get_ops(dev)->request(dev, desc->offset, label); in dm_gpio_request()
374 uc_priv->name[desc->offset] = str; in dm_gpio_request()
379 static int dm_gpio_requestf(struct gpio_desc *desc, const char *fmt, ...) in dm_gpio_requestf() argument
388 return dm_gpio_request(desc, buf); in dm_gpio_requestf()
390 return dm_gpio_request(desc, fmt); in dm_gpio_requestf()
408 struct gpio_desc desc; in gpio_request() local
411 ret = gpio_to_device(gpio, &desc); in gpio_request()
415 return dm_gpio_request(&desc, label); in gpio_request()
473 struct gpio_desc desc; in gpio_free() local
476 ret = gpio_to_device(gpio, &desc); in gpio_free()
480 return _dm_gpio_free(desc.dev, desc.offset); in gpio_free()
483 static int check_reserved(const struct gpio_desc *desc, const char *func) in check_reserved() argument
487 if (!dm_gpio_is_valid(desc)) in check_reserved()
490 uc_priv = dev_get_uclass_priv(desc->dev); in check_reserved()
491 if (!uc_priv->name[desc->offset]) { in check_reserved()
493 desc->dev->name, func, in check_reserved()
495 desc->offset); in check_reserved()
512 struct gpio_desc desc; in gpio_direction_input() local
515 ret = gpio_to_device(gpio, &desc); in gpio_direction_input()
518 ret = check_reserved(&desc, "dir_input"); in gpio_direction_input()
522 return gpio_get_ops(desc.dev)->direction_input(desc.dev, desc.offset); in gpio_direction_input()
536 struct gpio_desc desc; in gpio_direction_output() local
539 ret = gpio_to_device(gpio, &desc); in gpio_direction_output()
542 ret = check_reserved(&desc, "dir_output"); in gpio_direction_output()
546 return gpio_get_ops(desc.dev)->direction_output(desc.dev, in gpio_direction_output()
547 desc.offset, value); in gpio_direction_output()
550 static int _gpio_get_value(const struct gpio_desc *desc) in _gpio_get_value() argument
554 value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset); in _gpio_get_value()
556 return desc->flags & GPIOD_ACTIVE_LOW ? !value : value; in _gpio_get_value()
559 int dm_gpio_get_value(const struct gpio_desc *desc) in dm_gpio_get_value() argument
563 ret = check_reserved(desc, "get_value"); in dm_gpio_get_value()
567 return _gpio_get_value(desc); in dm_gpio_get_value()
570 int dm_gpio_set_value(const struct gpio_desc *desc, int value) in dm_gpio_set_value() argument
574 ret = check_reserved(desc, "set_value"); in dm_gpio_set_value()
578 if (desc->flags & GPIOD_ACTIVE_LOW) in dm_gpio_set_value()
585 if ((desc->flags & GPIOD_OPEN_DRAIN && value) || in dm_gpio_set_value()
586 (desc->flags & GPIOD_OPEN_SOURCE && !value)) in dm_gpio_set_value()
587 return gpio_get_ops(desc->dev)->direction_input(desc->dev, in dm_gpio_set_value()
588 desc->offset); in dm_gpio_set_value()
589 else if (desc->flags & GPIOD_OPEN_DRAIN || in dm_gpio_set_value()
590 desc->flags & GPIOD_OPEN_SOURCE) in dm_gpio_set_value()
591 return gpio_get_ops(desc->dev)->direction_output(desc->dev, in dm_gpio_set_value()
592 desc->offset, in dm_gpio_set_value()
595 gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value); in dm_gpio_set_value()
623 static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) in _dm_gpio_set_dir_flags() argument
625 struct udevice *dev = desc->dev; in _dm_gpio_set_dir_flags()
634 desc->dev->name, in _dm_gpio_set_dir_flags()
636 desc->offset, flags); in _dm_gpio_set_dir_flags()
643 ret = ops->set_dir_flags(dev, desc->offset, flags); in _dm_gpio_set_dir_flags()
646 ret = ops->direction_output(dev, desc->offset, in _dm_gpio_set_dir_flags()
649 ret = ops->direction_input(dev, desc->offset); in _dm_gpio_set_dir_flags()
655 desc->flags = flags; in _dm_gpio_set_dir_flags()
660 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) in dm_gpio_set_dir_flags() argument
664 ret = check_reserved(desc, "set_dir_flags"); in dm_gpio_set_dir_flags()
669 flags |= desc->flags; in dm_gpio_set_dir_flags()
670 ret = _dm_gpio_set_dir_flags(desc, flags); in dm_gpio_set_dir_flags()
675 int dm_gpio_set_dir(struct gpio_desc *desc) in dm_gpio_set_dir() argument
679 ret = check_reserved(desc, "set_dir"); in dm_gpio_set_dir()
683 return _dm_gpio_set_dir_flags(desc, desc->flags); in dm_gpio_set_dir()
686 int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags) in dm_gpio_get_dir_flags() argument
688 struct udevice *dev = desc->dev; in dm_gpio_get_dir_flags()
693 ret = check_reserved(desc, "get_dir_flags"); in dm_gpio_get_dir_flags()
699 ret = ops->get_dir_flags(dev, desc->offset, &dir_flags); in dm_gpio_get_dir_flags()
705 if (desc->flags & GPIOD_ACTIVE_LOW) in dm_gpio_get_dir_flags()
708 dir_flags |= (desc->flags & GPIOD_ACTIVE_LOW); in dm_gpio_get_dir_flags()
712 dir_flags = desc->flags; in dm_gpio_get_dir_flags()
715 if ((desc->flags & GPIOD_IS_OUT) && _gpio_get_value(desc)) in dm_gpio_get_dir_flags()
736 struct gpio_desc desc; in gpio_get_value() local
738 ret = gpio_to_device(gpio, &desc); in gpio_get_value()
741 return dm_gpio_get_value(&desc); in gpio_get_value()
755 struct gpio_desc desc; in gpio_set_value() local
758 ret = gpio_to_device(gpio, &desc); in gpio_set_value()
761 return dm_gpio_set_value(&desc, value); in gpio_set_value()
863 int gpio_get_acpi(const struct gpio_desc *desc, struct acpi_gpio *gpio) in gpio_get_acpi() argument
868 if (!dm_gpio_is_valid(desc)) { in gpio_get_acpi()
875 ops = gpio_get_ops(desc->dev); in gpio_get_acpi()
879 return ops->get_acpi(desc, gpio); in gpio_get_acpi()
987 struct gpio_desc *desc, int flags, in gpio_request_tail() argument
990 gpio_desc_init(desc, gpio_dev, 0); in gpio_request_tail()
994 if (!desc->dev) { in gpio_request_tail()
996 &desc->dev); in gpio_request_tail()
1003 ret = gpio_find_and_xlate(desc, args); in gpio_request_tail()
1008 ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s", in gpio_request_tail()
1014 ret = dm_gpio_set_dir_flags(desc, flags); in gpio_request_tail()
1028 int index, struct gpio_desc *desc, in _gpio_request_by_name_nodev() argument
1038 index, desc, flags, add_index, NULL); in _gpio_request_by_name_nodev()
1042 struct gpio_desc *desc, int flags) in gpio_request_by_name_nodev() argument
1044 return _gpio_request_by_name_nodev(node, list_name, index, desc, flags, in gpio_request_by_name_nodev()
1049 struct gpio_desc *desc, int flags) in gpio_request_by_name() argument
1059 index, desc, flags, index > 0, NULL); in gpio_request_by_name()
1063 struct gpio_desc *desc, int max_count, in gpio_request_list_by_name_nodev() argument
1071 &desc[count], flags, true); in gpio_request_list_by_name_nodev()
1082 gpio_free_list_nodev(desc, count - 1); in gpio_request_list_by_name_nodev()
1088 struct gpio_desc *desc, int max_count, in gpio_request_list_by_name() argument
1096 return gpio_request_list_by_name_nodev(dev_ofnode(dev), list_name, desc, in gpio_request_list_by_name()
1114 int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc) in dm_gpio_free() argument
1117 return _dm_gpio_free(desc->dev, desc->offset); in dm_gpio_free()
1120 int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count) in gpio_free_list() argument
1126 dm_gpio_free(dev, &desc[i]); in gpio_free_list()
1131 int gpio_free_list_nodev(struct gpio_desc *desc, int count) in gpio_free_list_nodev() argument
1133 return gpio_free_list(NULL, desc, count); in gpio_free_list_nodev()
1162 int gpio_get_number(const struct gpio_desc *desc) in gpio_get_number() argument
1164 struct udevice *dev = desc->dev; in gpio_get_number()
1171 return uc_priv->gpio_base + desc->offset; in gpio_get_number()
1201 int dtflags, struct gpio_desc *desc) in gpio_dev_request_index() argument
1210 return gpio_request_tail(0, nodename, &args, list_name, index, desc, in gpio_dev_request_index()
1228 struct gpio_desc *desc; in devm_gpiod_get_index() local
1241 desc = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc), in devm_gpiod_get_index()
1243 if (unlikely(!desc)) { in devm_gpiod_get_index()
1248 rc = gpio_request_by_name(dev, propname, index, desc, flags); in devm_gpiod_get_index()
1257 devres_add(dev, desc); in devm_gpiod_get_index()
1259 return desc; in devm_gpiod_get_index()
1267 struct gpio_desc *desc = devm_gpiod_get_index(dev, id, index, flags); in devm_gpiod_get_index_optional() local
1269 if (IS_ERR(desc)) in devm_gpiod_get_index_optional()
1272 return desc; in devm_gpiod_get_index_optional()
1275 void devm_gpiod_put(struct udevice *dev, struct gpio_desc *desc) in devm_gpiod_put() argument
1279 rc = devres_release(dev, devm_gpiod_release, devm_gpiod_match, desc); in devm_gpiod_put()