Lines Matching refs:desc
79 return &chip->desc[gpio - chip->base]; in gpio_to_desc()
101 return &chip->desc[hwnum]; in gpiochip_get_desc()
109 int desc_to_gpio(const struct gpio_desc *desc) in desc_to_gpio() argument
111 return desc->chip->base + (desc - &desc->chip->desc[0]); in desc_to_gpio()
120 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) in gpiod_to_chip() argument
122 return desc ? desc->chip : NULL; in gpiod_to_chip()
158 int gpiod_get_direction(struct gpio_desc *desc) in gpiod_get_direction() argument
164 chip = gpiod_to_chip(desc); in gpiod_get_direction()
165 offset = gpio_chip_hwgpio(desc); in gpiod_get_direction()
174 clear_bit(FLAG_IS_OUT, &desc->flags); in gpiod_get_direction()
178 set_bit(FLAG_IS_OUT, &desc->flags); in gpiod_get_direction()
269 struct gpio_desc *desc = &descs[id]; in gpiochip_add() local
271 desc->chip = chip; in gpiochip_add()
279 desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; in gpiochip_add()
282 chip->desc = descs; in gpiochip_add()
310 chip->desc = NULL; in gpiochip_add()
344 if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) in gpiochip_remove()
348 chip->desc[id].chip = NULL; in gpiochip_remove()
353 kfree(chip->desc); in gpiochip_remove()
354 chip->desc = NULL; in gpiochip_remove()
778 static int __gpiod_request(struct gpio_desc *desc, const char *label) in __gpiod_request() argument
780 struct gpio_chip *chip = desc->chip; in __gpiod_request()
790 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) { in __gpiod_request()
791 desc_set_label(desc, label ? : "?"); in __gpiod_request()
801 status = chip->request(chip, gpio_chip_hwgpio(desc)); in __gpiod_request()
805 desc_set_label(desc, NULL); in __gpiod_request()
806 clear_bit(FLAG_REQUESTED, &desc->flags); in __gpiod_request()
813 gpiod_get_direction(desc); in __gpiod_request()
821 int gpiod_request(struct gpio_desc *desc, const char *label) in gpiod_request() argument
826 if (!desc) { in gpiod_request()
831 chip = desc->chip; in gpiod_request()
836 status = __gpiod_request(desc, label); in gpiod_request()
843 gpiod_dbg(desc, "%s: status %d\n", __func__, status); in gpiod_request()
848 static bool __gpiod_free(struct gpio_desc *desc) in __gpiod_free() argument
856 gpiod_unexport(desc); in __gpiod_free()
860 chip = desc->chip; in __gpiod_free()
861 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) { in __gpiod_free()
865 chip->free(chip, gpio_chip_hwgpio(desc)); in __gpiod_free()
868 desc_set_label(desc, NULL); in __gpiod_free()
869 clear_bit(FLAG_ACTIVE_LOW, &desc->flags); in __gpiod_free()
870 clear_bit(FLAG_REQUESTED, &desc->flags); in __gpiod_free()
871 clear_bit(FLAG_OPEN_DRAIN, &desc->flags); in __gpiod_free()
872 clear_bit(FLAG_OPEN_SOURCE, &desc->flags); in __gpiod_free()
873 clear_bit(FLAG_IS_HOGGED, &desc->flags); in __gpiod_free()
881 void gpiod_free(struct gpio_desc *desc) in gpiod_free() argument
883 if (desc && __gpiod_free(desc)) in gpiod_free()
884 module_put(desc->chip->owner); in gpiod_free()
904 struct gpio_desc *desc; in gpiochip_is_requested() local
909 desc = &chip->desc[offset]; in gpiochip_is_requested()
911 if (test_bit(FLAG_REQUESTED, &desc->flags) == 0) in gpiochip_is_requested()
913 return desc->label; in gpiochip_is_requested()
931 struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); in gpiochip_request_own_desc() local
934 if (IS_ERR(desc)) { in gpiochip_request_own_desc()
936 return desc; in gpiochip_request_own_desc()
939 err = __gpiod_request(desc, label); in gpiochip_request_own_desc()
943 return desc; in gpiochip_request_own_desc()
954 void gpiochip_free_own_desc(struct gpio_desc *desc) in gpiochip_free_own_desc() argument
956 if (desc) in gpiochip_free_own_desc()
957 __gpiod_free(desc); in gpiochip_free_own_desc()
979 int gpiod_direction_input(struct gpio_desc *desc) in gpiod_direction_input() argument
984 if (!desc || !desc->chip) { in gpiod_direction_input()
989 chip = desc->chip; in gpiod_direction_input()
991 gpiod_warn(desc, in gpiod_direction_input()
997 status = chip->direction_input(chip, gpio_chip_hwgpio(desc)); in gpiod_direction_input()
999 clear_bit(FLAG_IS_OUT, &desc->flags); in gpiod_direction_input()
1001 trace_gpio_direction(desc_to_gpio(desc), 1, status); in gpiod_direction_input()
1007 static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) in _gpiod_direction_output_raw() argument
1013 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { in _gpiod_direction_output_raw()
1014 gpiod_err(desc, in _gpiod_direction_output_raw()
1021 if (value && test_bit(FLAG_OPEN_DRAIN, &desc->flags)) in _gpiod_direction_output_raw()
1022 return gpiod_direction_input(desc); in _gpiod_direction_output_raw()
1025 if (!value && test_bit(FLAG_OPEN_SOURCE, &desc->flags)) in _gpiod_direction_output_raw()
1026 return gpiod_direction_input(desc); in _gpiod_direction_output_raw()
1028 chip = desc->chip; in _gpiod_direction_output_raw()
1030 gpiod_warn(desc, in _gpiod_direction_output_raw()
1036 status = chip->direction_output(chip, gpio_chip_hwgpio(desc), value); in _gpiod_direction_output_raw()
1038 set_bit(FLAG_IS_OUT, &desc->flags); in _gpiod_direction_output_raw()
1039 trace_gpio_value(desc_to_gpio(desc), 0, value); in _gpiod_direction_output_raw()
1040 trace_gpio_direction(desc_to_gpio(desc), 0, status); in _gpiod_direction_output_raw()
1055 int gpiod_direction_output_raw(struct gpio_desc *desc, int value) in gpiod_direction_output_raw() argument
1057 if (!desc || !desc->chip) { in gpiod_direction_output_raw()
1061 return _gpiod_direction_output_raw(desc, value); in gpiod_direction_output_raw()
1077 int gpiod_direction_output(struct gpio_desc *desc, int value) in gpiod_direction_output() argument
1079 if (!desc || !desc->chip) { in gpiod_direction_output()
1083 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_direction_output()
1085 return _gpiod_direction_output_raw(desc, value); in gpiod_direction_output()
1097 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) in gpiod_set_debounce() argument
1101 if (!desc || !desc->chip) { in gpiod_set_debounce()
1106 chip = desc->chip; in gpiod_set_debounce()
1108 gpiod_dbg(desc, in gpiod_set_debounce()
1114 return chip->set_debounce(chip, gpio_chip_hwgpio(desc), debounce); in gpiod_set_debounce()
1124 int gpiod_is_active_low(const struct gpio_desc *desc) in gpiod_is_active_low() argument
1126 return test_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_is_active_low()
1152 static bool _gpiod_get_raw_value(const struct gpio_desc *desc) in _gpiod_get_raw_value() argument
1158 chip = desc->chip; in _gpiod_get_raw_value()
1159 offset = gpio_chip_hwgpio(desc); in _gpiod_get_raw_value()
1161 trace_gpio_value(desc_to_gpio(desc), 1, value); in _gpiod_get_raw_value()
1175 int gpiod_get_raw_value(const struct gpio_desc *desc) in gpiod_get_raw_value() argument
1177 if (!desc) in gpiod_get_raw_value()
1180 WARN_ON(desc->chip->can_sleep); in gpiod_get_raw_value()
1181 return _gpiod_get_raw_value(desc); in gpiod_get_raw_value()
1195 int gpiod_get_value(const struct gpio_desc *desc) in gpiod_get_value() argument
1198 if (!desc) in gpiod_get_value()
1201 WARN_ON(desc->chip->can_sleep); in gpiod_get_value()
1203 value = _gpiod_get_raw_value(desc); in gpiod_get_value()
1204 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_value()
1216 static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value) in _gpio_set_open_drain_value() argument
1219 struct gpio_chip *chip = desc->chip; in _gpio_set_open_drain_value()
1220 int offset = gpio_chip_hwgpio(desc); in _gpio_set_open_drain_value()
1225 clear_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_drain_value()
1229 set_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_drain_value()
1231 trace_gpio_direction(desc_to_gpio(desc), value, err); in _gpio_set_open_drain_value()
1233 gpiod_err(desc, in _gpio_set_open_drain_value()
1243 static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value) in _gpio_set_open_source_value() argument
1246 struct gpio_chip *chip = desc->chip; in _gpio_set_open_source_value()
1247 int offset = gpio_chip_hwgpio(desc); in _gpio_set_open_source_value()
1252 set_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_source_value()
1256 clear_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_source_value()
1258 trace_gpio_direction(desc_to_gpio(desc), !value, err); in _gpio_set_open_source_value()
1260 gpiod_err(desc, in _gpio_set_open_source_value()
1265 static void _gpiod_set_raw_value(struct gpio_desc *desc, bool value) in _gpiod_set_raw_value() argument
1269 chip = desc->chip; in _gpiod_set_raw_value()
1270 trace_gpio_value(desc_to_gpio(desc), 0, value); in _gpiod_set_raw_value()
1271 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) in _gpiod_set_raw_value()
1272 _gpio_set_open_drain_value(desc, value); in _gpiod_set_raw_value()
1273 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) in _gpiod_set_raw_value()
1274 _gpio_set_open_source_value(desc, value); in _gpiod_set_raw_value()
1276 chip->set(chip, gpio_chip_hwgpio(desc), value); in _gpiod_set_raw_value()
1328 struct gpio_desc *desc = desc_array[i]; in gpiod_set_array_priv() local
1329 int hwgpio = gpio_chip_hwgpio(desc); in gpiod_set_array_priv()
1332 if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_array_priv()
1334 trace_gpio_value(desc_to_gpio(desc), 0, value); in gpiod_set_array_priv()
1339 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { in gpiod_set_array_priv()
1340 _gpio_set_open_drain_value(desc,value); in gpiod_set_array_priv()
1341 } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { in gpiod_set_array_priv()
1342 _gpio_set_open_source_value(desc, value); in gpiod_set_array_priv()
1372 void gpiod_set_raw_value(struct gpio_desc *desc, int value) in gpiod_set_raw_value() argument
1374 if (!desc) in gpiod_set_raw_value()
1377 WARN_ON(desc->chip->can_sleep); in gpiod_set_raw_value()
1378 _gpiod_set_raw_value(desc, value); in gpiod_set_raw_value()
1393 void gpiod_set_value(struct gpio_desc *desc, int value) in gpiod_set_value() argument
1395 if (!desc) in gpiod_set_value()
1398 WARN_ON(desc->chip->can_sleep); in gpiod_set_value()
1399 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_value()
1401 _gpiod_set_raw_value(desc, value); in gpiod_set_value()
1452 int gpiod_cansleep(const struct gpio_desc *desc) in gpiod_cansleep() argument
1454 if (!desc) in gpiod_cansleep()
1456 return desc->chip->can_sleep; in gpiod_cansleep()
1467 int gpiod_to_irq(const struct gpio_desc *desc) in gpiod_to_irq() argument
1472 if (!desc) in gpiod_to_irq()
1474 chip = desc->chip; in gpiod_to_irq()
1475 offset = gpio_chip_hwgpio(desc); in gpiod_to_irq()
1493 if (test_bit(FLAG_IS_OUT, &chip->desc[offset].flags)) { in gpiochip_lock_as_irq()
1500 set_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); in gpiochip_lock_as_irq()
1518 clear_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); in gpiochip_unlock_as_irq()
1531 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) in gpiod_get_raw_value_cansleep() argument
1534 if (!desc) in gpiod_get_raw_value_cansleep()
1536 return _gpiod_get_raw_value(desc); in gpiod_get_raw_value_cansleep()
1549 int gpiod_get_value_cansleep(const struct gpio_desc *desc) in gpiod_get_value_cansleep() argument
1554 if (!desc) in gpiod_get_value_cansleep()
1557 value = _gpiod_get_raw_value(desc); in gpiod_get_value_cansleep()
1558 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_value_cansleep()
1575 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) in gpiod_set_raw_value_cansleep() argument
1578 if (!desc) in gpiod_set_raw_value_cansleep()
1580 _gpiod_set_raw_value(desc, value); in gpiod_set_raw_value_cansleep()
1594 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) in gpiod_set_value_cansleep() argument
1597 if (!desc) in gpiod_set_value_cansleep()
1600 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_value_cansleep()
1602 _gpiod_set_raw_value(desc, value); in gpiod_set_value_cansleep()
1669 struct gpio_desc *desc; in of_find_gpio() local
1680 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, in of_find_gpio()
1682 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER)) in of_find_gpio()
1686 if (IS_ERR(desc)) in of_find_gpio()
1687 return desc; in of_find_gpio()
1692 return desc; in of_find_gpio()
1701 struct gpio_desc *desc; in acpi_find_gpio() local
1715 desc = acpi_get_gpiod_by_index(adev, propname, idx, &info); in acpi_find_gpio()
1716 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER)) in acpi_find_gpio()
1721 if (IS_ERR(desc)) { in acpi_find_gpio()
1722 desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); in acpi_find_gpio()
1723 if (IS_ERR(desc)) in acpi_find_gpio()
1724 return desc; in acpi_find_gpio()
1730 return desc; in acpi_find_gpio()
1768 struct gpio_desc *desc = ERR_PTR(-ENOENT); in gpiod_find() local
1774 return desc; in gpiod_find()
1802 desc = gpiochip_get_desc(chip, p->chip_hwnum); in gpiod_find()
1805 return desc; in gpiod_find()
1808 return desc; in gpiod_find()
1923 static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, in gpiod_configure_flags() argument
1929 set_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_configure_flags()
1931 set_bit(FLAG_OPEN_DRAIN, &desc->flags); in gpiod_configure_flags()
1933 set_bit(FLAG_OPEN_SOURCE, &desc->flags); in gpiod_configure_flags()
1943 status = gpiod_direction_output(desc, in gpiod_configure_flags()
1946 status = gpiod_direction_input(desc); in gpiod_configure_flags()
1970 struct gpio_desc *desc = NULL; in __gpiod_get_index() local
1980 desc = of_find_gpio(dev, con_id, idx, &lookupflags); in __gpiod_get_index()
1983 desc = acpi_find_gpio(dev, con_id, idx, &lookupflags); in __gpiod_get_index()
1991 if (!desc || desc == ERR_PTR(-ENOENT)) { in __gpiod_get_index()
1993 desc = gpiod_find(dev, con_id, idx, &lookupflags); in __gpiod_get_index()
1996 if (IS_ERR(desc)) { in __gpiod_get_index()
1998 return desc; in __gpiod_get_index()
2001 status = gpiod_request(desc, con_id); in __gpiod_get_index()
2005 status = gpiod_configure_flags(desc, con_id, lookupflags, flags); in __gpiod_get_index()
2008 gpiod_put(desc); in __gpiod_get_index()
2012 return desc; in __gpiod_get_index()
2033 struct gpio_desc *desc = ERR_PTR(-ENODEV); in fwnode_get_named_gpiod() local
2043 desc = of_get_named_gpiod_flags(of_node(fwnode), propname, 0, in fwnode_get_named_gpiod()
2045 if (!IS_ERR(desc)) in fwnode_get_named_gpiod()
2050 desc = acpi_get_gpiod_by_index(acpi_node(fwnode), propname, 0, in fwnode_get_named_gpiod()
2052 if (!IS_ERR(desc)) in fwnode_get_named_gpiod()
2056 if (IS_ERR(desc)) in fwnode_get_named_gpiod()
2057 return desc; in fwnode_get_named_gpiod()
2059 ret = gpiod_request(desc, NULL); in fwnode_get_named_gpiod()
2065 set_bit(FLAG_ACTIVE_LOW, &desc->flags); in fwnode_get_named_gpiod()
2067 return desc; in fwnode_get_named_gpiod()
2088 struct gpio_desc *desc; in __gpiod_get_index_optional() local
2090 desc = gpiod_get_index(dev, con_id, index, flags); in __gpiod_get_index_optional()
2091 if (IS_ERR(desc)) { in __gpiod_get_index_optional()
2092 if (PTR_ERR(desc) == -ENOENT) in __gpiod_get_index_optional()
2096 return desc; in __gpiod_get_index_optional()
2108 int gpiod_hog(struct gpio_desc *desc, const char *name, in gpiod_hog() argument
2116 chip = gpiod_to_chip(desc); in gpiod_hog()
2117 hwnum = gpio_chip_hwgpio(desc); in gpiod_hog()
2125 status = gpiod_configure_flags(desc, name, lflags, dflags); in gpiod_hog()
2128 gpiochip_free_own_desc(desc); in gpiod_hog()
2133 set_bit(FLAG_IS_HOGGED, &desc->flags); in gpiod_hog()
2136 desc_to_gpio(desc), name, in gpiod_hog()
2155 if (test_bit(FLAG_IS_HOGGED, &chip->desc[id].flags)) in gpiochip_free_hogs()
2156 gpiochip_free_own_desc(&chip->desc[id]); in gpiochip_free_hogs()
2176 struct gpio_desc *desc; in gpiod_get_array() local
2184 descs = kzalloc(sizeof(*descs) + sizeof(descs->desc[0]) * count, in gpiod_get_array()
2190 desc = gpiod_get_index(dev, con_id, descs->ndescs, flags); in gpiod_get_array()
2191 if (IS_ERR(desc)) { in gpiod_get_array()
2193 return ERR_CAST(desc); in gpiod_get_array()
2195 descs->desc[descs->ndescs] = desc; in gpiod_get_array()
2232 void gpiod_put(struct gpio_desc *desc) in gpiod_put() argument
2234 gpiod_free(desc); in gpiod_put()
2247 gpiod_put(descs->desc[i]); in gpiod_put_array()
2259 struct gpio_desc *gdesc = &chip->desc[0]; in gpiolib_dbg_show()