Lines Matching refs:desc
29 static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc) in gpio_to_device() argument
41 desc->dev = dev; in gpio_to_device()
42 desc->offset = gpio - uc_priv->gpio_base; in gpio_to_device()
43 desc->flags = 0; in gpio_to_device()
52 int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc) in dm_gpio_lookup_name() argument
85 desc->dev = dev; in dm_gpio_lookup_name()
86 desc->offset = offset; in dm_gpio_lookup_name()
94 struct gpio_desc desc; in gpio_lookup_name() local
99 ret = dm_gpio_lookup_name(name, &desc); in gpio_lookup_name()
104 *devp = desc.dev; in gpio_lookup_name()
106 *offsetp = desc.offset; in gpio_lookup_name()
108 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(desc.dev); in gpio_lookup_name()
110 *gpiop = uc_priv->gpio_base + desc.offset; in gpio_lookup_name()
116 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, in gpio_xlate_offs_flags() argument
122 desc->offset = args->args[0]; in gpio_xlate_offs_flags()
128 desc->flags = GPIOD_ACTIVE_LOW; in gpio_xlate_offs_flags()
133 static int gpio_find_and_xlate(struct gpio_desc *desc, in gpio_find_and_xlate() argument
136 struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); in gpio_find_and_xlate()
139 return ops->xlate(desc->dev, desc, args); in gpio_find_and_xlate()
141 return gpio_xlate_offs_flags(desc->dev, desc, args); in gpio_find_and_xlate()
144 int dm_gpio_request(struct gpio_desc *desc, const char *label) in dm_gpio_request() argument
146 struct udevice *dev = desc->dev; in dm_gpio_request()
152 if (uc_priv->name[desc->offset]) in dm_gpio_request()
158 ret = gpio_get_ops(dev)->request(dev, desc->offset, label); in dm_gpio_request()
164 uc_priv->name[desc->offset] = str; in dm_gpio_request()
169 static int dm_gpio_requestf(struct gpio_desc *desc, const char *fmt, ...) in dm_gpio_requestf() argument
178 return dm_gpio_request(desc, buf); in dm_gpio_requestf()
180 return dm_gpio_request(desc, fmt); in dm_gpio_requestf()
198 struct gpio_desc desc; in gpio_request() local
201 ret = gpio_to_device(gpio, &desc); in gpio_request()
205 return dm_gpio_request(&desc, label); in gpio_request()
263 struct gpio_desc desc; in gpio_free() local
266 ret = gpio_to_device(gpio, &desc); in gpio_free()
270 return _dm_gpio_free(desc.dev, desc.offset); in gpio_free()
273 static int check_reserved(const struct gpio_desc *desc, const char *func) in check_reserved() argument
277 if (!dm_gpio_is_valid(desc)) in check_reserved()
280 uc_priv = dev_get_uclass_priv(desc->dev); in check_reserved()
281 if (!uc_priv->name[desc->offset]) { in check_reserved()
283 desc->dev->name, func, in check_reserved()
285 desc->offset); in check_reserved()
302 struct gpio_desc desc; in gpio_direction_input() local
305 ret = gpio_to_device(gpio, &desc); in gpio_direction_input()
308 ret = check_reserved(&desc, "dir_input"); in gpio_direction_input()
312 return gpio_get_ops(desc.dev)->direction_input(desc.dev, desc.offset); in gpio_direction_input()
326 struct gpio_desc desc; in gpio_direction_output() local
329 ret = gpio_to_device(gpio, &desc); in gpio_direction_output()
332 ret = check_reserved(&desc, "dir_output"); in gpio_direction_output()
336 return gpio_get_ops(desc.dev)->direction_output(desc.dev, in gpio_direction_output()
337 desc.offset, value); in gpio_direction_output()
340 int dm_gpio_get_value(const struct gpio_desc *desc) in dm_gpio_get_value() argument
345 ret = check_reserved(desc, "get_value"); in dm_gpio_get_value()
349 value = gpio_get_ops(desc->dev)->get_value(desc->dev, desc->offset); in dm_gpio_get_value()
351 return desc->flags & GPIOD_ACTIVE_LOW ? !value : value; in dm_gpio_get_value()
354 int dm_gpio_set_value(const struct gpio_desc *desc, int value) in dm_gpio_set_value() argument
358 ret = check_reserved(desc, "set_value"); in dm_gpio_set_value()
362 if (desc->flags & GPIOD_ACTIVE_LOW) in dm_gpio_set_value()
364 gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value); in dm_gpio_set_value()
368 int dm_gpio_get_open_drain(struct gpio_desc *desc) in dm_gpio_get_open_drain() argument
370 struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); in dm_gpio_get_open_drain()
373 ret = check_reserved(desc, "get_open_drain"); in dm_gpio_get_open_drain()
378 return ops->get_open_drain(desc->dev, desc->offset); in dm_gpio_get_open_drain()
383 int dm_gpio_set_open_drain(struct gpio_desc *desc, int value) in dm_gpio_set_open_drain() argument
385 struct dm_gpio_ops *ops = gpio_get_ops(desc->dev); in dm_gpio_set_open_drain()
388 ret = check_reserved(desc, "set_open_drain"); in dm_gpio_set_open_drain()
393 ret = ops->set_open_drain(desc->dev, desc->offset, value); in dm_gpio_set_open_drain()
400 int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) in dm_gpio_set_dir_flags() argument
402 struct udevice *dev = desc->dev; in dm_gpio_set_dir_flags()
406 ret = check_reserved(desc, "set_dir"); in dm_gpio_set_dir_flags()
415 ret = ops->direction_output(dev, desc->offset, value); in dm_gpio_set_dir_flags()
417 ret = ops->direction_input(dev, desc->offset); in dm_gpio_set_dir_flags()
425 desc->flags = flags; in dm_gpio_set_dir_flags()
430 int dm_gpio_set_dir(struct gpio_desc *desc) in dm_gpio_set_dir() argument
432 return dm_gpio_set_dir_flags(desc, desc->flags); in dm_gpio_set_dir()
448 struct gpio_desc desc; in gpio_get_value() local
450 ret = gpio_to_device(gpio, &desc); in gpio_get_value()
453 return dm_gpio_get_value(&desc); in gpio_get_value()
467 struct gpio_desc desc; in gpio_set_value() local
470 ret = gpio_to_device(gpio, &desc); in gpio_set_value()
473 return dm_gpio_set_value(&desc, value); in gpio_set_value()
646 struct gpio_desc *desc, int flags, bool add_index) in gpio_request_tail() argument
648 desc->dev = NULL; in gpio_request_tail()
649 desc->offset = 0; in gpio_request_tail()
650 desc->flags = 0; in gpio_request_tail()
655 &desc->dev); in gpio_request_tail()
660 ret = gpio_find_and_xlate(desc, args); in gpio_request_tail()
665 ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s", in gpio_request_tail()
672 ret = dm_gpio_set_dir_flags(desc, flags | desc->flags); in gpio_request_tail()
686 int index, struct gpio_desc *desc, in _gpio_request_by_name_nodev() argument
695 return gpio_request_tail(ret, node, &args, list_name, index, desc, in _gpio_request_by_name_nodev()
700 struct gpio_desc *desc, int flags) in gpio_request_by_name_nodev() argument
702 return _gpio_request_by_name_nodev(node, list_name, index, desc, flags, in gpio_request_by_name_nodev()
707 struct gpio_desc *desc, int flags) in gpio_request_by_name() argument
716 index, desc, flags, index > 0); in gpio_request_by_name()
720 struct gpio_desc *desc, int max_count, in gpio_request_list_by_name_nodev() argument
728 &desc[count], flags, true); in gpio_request_list_by_name_nodev()
739 gpio_free_list_nodev(desc, count - 1); in gpio_request_list_by_name_nodev()
745 struct gpio_desc *desc, int max_count, in gpio_request_list_by_name() argument
753 return gpio_request_list_by_name_nodev(dev_ofnode(dev), list_name, desc, in gpio_request_list_by_name()
772 int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc) in dm_gpio_free() argument
775 return _dm_gpio_free(desc->dev, desc->offset); in dm_gpio_free()
778 int gpio_free_list(struct udevice *dev, struct gpio_desc *desc, int count) in gpio_free_list() argument
784 dm_gpio_free(dev, &desc[i]); in gpio_free_list()
789 int gpio_free_list_nodev(struct gpio_desc *desc, int count) in gpio_free_list_nodev() argument
791 return gpio_free_list(NULL, desc, count); in gpio_free_list_nodev()
820 int gpio_get_number(const struct gpio_desc *desc) in gpio_get_number() argument
822 struct udevice *dev = desc->dev; in gpio_get_number()
829 return uc_priv->gpio_base + desc->offset; in gpio_get_number()