Lines Matching refs:desc
78 return &chip->desc[gpio - chip->base]; in gpio_to_desc()
100 return &chip->desc[hwnum]; in gpiochip_get_desc()
108 int desc_to_gpio(const struct gpio_desc *desc) in desc_to_gpio() argument
110 return desc->chip->base + (desc - &desc->chip->desc[0]); in desc_to_gpio()
119 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) in gpiod_to_chip() argument
121 return desc ? desc->chip : NULL; in gpiod_to_chip()
157 int gpiod_get_direction(struct gpio_desc *desc) in gpiod_get_direction() argument
163 chip = gpiod_to_chip(desc); in gpiod_get_direction()
164 offset = gpio_chip_hwgpio(desc); in gpiod_get_direction()
173 clear_bit(FLAG_IS_OUT, &desc->flags); in gpiod_get_direction()
177 set_bit(FLAG_IS_OUT, &desc->flags); in gpiod_get_direction()
234 struct gpio_desc *gpio = &chip->desc[i]; in gpio_name_to_desc()
277 gc->desc[i].name = gc->names[i]; in gpiochip_set_desc_names()
330 struct gpio_desc *desc = &descs[id]; in gpiochip_add() local
332 desc->chip = chip; in gpiochip_add()
340 desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; in gpiochip_add()
343 chip->desc = descs; in gpiochip_add()
382 chip->desc = NULL; in gpiochip_add()
402 struct gpio_desc *desc; in gpiochip_remove() local
418 desc = &chip->desc[id]; in gpiochip_remove()
419 desc->chip = NULL; in gpiochip_remove()
420 if (test_bit(FLAG_REQUESTED, &desc->flags)) in gpiochip_remove()
429 kfree(chip->desc); in gpiochip_remove()
430 chip->desc = NULL; in gpiochip_remove()
891 static int __gpiod_request(struct gpio_desc *desc, const char *label) in __gpiod_request() argument
893 struct gpio_chip *chip = desc->chip; in __gpiod_request()
903 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) { in __gpiod_request()
904 desc_set_label(desc, label ? : "?"); in __gpiod_request()
914 status = chip->request(chip, gpio_chip_hwgpio(desc)); in __gpiod_request()
918 desc_set_label(desc, NULL); in __gpiod_request()
919 clear_bit(FLAG_REQUESTED, &desc->flags); in __gpiod_request()
926 gpiod_get_direction(desc); in __gpiod_request()
934 clear_bit(FLAG_ACTIVE_LOW, &desc->flags); in __gpiod_request()
935 clear_bit(FLAG_OPEN_DRAIN, &desc->flags); in __gpiod_request()
936 clear_bit(FLAG_OPEN_SOURCE, &desc->flags); in __gpiod_request()
942 int gpiod_request(struct gpio_desc *desc, const char *label) in gpiod_request() argument
947 if (!desc) { in gpiod_request()
952 chip = desc->chip; in gpiod_request()
957 status = __gpiod_request(desc, label); in gpiod_request()
964 gpiod_dbg(desc, "%s: status %d\n", __func__, status); in gpiod_request()
969 static bool __gpiod_free(struct gpio_desc *desc) in __gpiod_free() argument
977 gpiod_unexport(desc); in __gpiod_free()
981 chip = desc->chip; in __gpiod_free()
982 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) { in __gpiod_free()
986 chip->free(chip, gpio_chip_hwgpio(desc)); in __gpiod_free()
989 desc_set_label(desc, NULL); in __gpiod_free()
990 clear_bit(FLAG_ACTIVE_LOW, &desc->flags); in __gpiod_free()
991 clear_bit(FLAG_REQUESTED, &desc->flags); in __gpiod_free()
992 clear_bit(FLAG_OPEN_DRAIN, &desc->flags); in __gpiod_free()
993 clear_bit(FLAG_OPEN_SOURCE, &desc->flags); in __gpiod_free()
994 clear_bit(FLAG_IS_HOGGED, &desc->flags); in __gpiod_free()
1002 void gpiod_free(struct gpio_desc *desc) in gpiod_free() argument
1004 if (desc && __gpiod_free(desc)) in gpiod_free()
1005 module_put(desc->chip->owner); in gpiod_free()
1025 struct gpio_desc *desc; in gpiochip_is_requested() local
1030 desc = &chip->desc[offset]; in gpiochip_is_requested()
1032 if (test_bit(FLAG_REQUESTED, &desc->flags) == 0) in gpiochip_is_requested()
1034 return desc->label; in gpiochip_is_requested()
1052 struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); in gpiochip_request_own_desc() local
1055 if (IS_ERR(desc)) { in gpiochip_request_own_desc()
1057 return desc; in gpiochip_request_own_desc()
1060 err = __gpiod_request(desc, label); in gpiochip_request_own_desc()
1064 return desc; in gpiochip_request_own_desc()
1075 void gpiochip_free_own_desc(struct gpio_desc *desc) in gpiochip_free_own_desc() argument
1077 if (desc) in gpiochip_free_own_desc()
1078 __gpiod_free(desc); in gpiochip_free_own_desc()
1100 int gpiod_direction_input(struct gpio_desc *desc) in gpiod_direction_input() argument
1105 if (!desc || !desc->chip) { in gpiod_direction_input()
1110 chip = desc->chip; in gpiod_direction_input()
1112 gpiod_warn(desc, in gpiod_direction_input()
1118 status = chip->direction_input(chip, gpio_chip_hwgpio(desc)); in gpiod_direction_input()
1120 clear_bit(FLAG_IS_OUT, &desc->flags); in gpiod_direction_input()
1122 trace_gpio_direction(desc_to_gpio(desc), 1, status); in gpiod_direction_input()
1128 static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value) in _gpiod_direction_output_raw() argument
1134 if (test_bit(FLAG_USED_AS_IRQ, &desc->flags)) { in _gpiod_direction_output_raw()
1135 gpiod_err(desc, in _gpiod_direction_output_raw()
1142 if (value && test_bit(FLAG_OPEN_DRAIN, &desc->flags)) in _gpiod_direction_output_raw()
1143 return gpiod_direction_input(desc); in _gpiod_direction_output_raw()
1146 if (!value && test_bit(FLAG_OPEN_SOURCE, &desc->flags)) in _gpiod_direction_output_raw()
1147 return gpiod_direction_input(desc); in _gpiod_direction_output_raw()
1149 chip = desc->chip; in _gpiod_direction_output_raw()
1151 gpiod_warn(desc, in _gpiod_direction_output_raw()
1157 status = chip->direction_output(chip, gpio_chip_hwgpio(desc), value); in _gpiod_direction_output_raw()
1159 set_bit(FLAG_IS_OUT, &desc->flags); in _gpiod_direction_output_raw()
1160 trace_gpio_value(desc_to_gpio(desc), 0, value); in _gpiod_direction_output_raw()
1161 trace_gpio_direction(desc_to_gpio(desc), 0, status); in _gpiod_direction_output_raw()
1176 int gpiod_direction_output_raw(struct gpio_desc *desc, int value) in gpiod_direction_output_raw() argument
1178 if (!desc || !desc->chip) { in gpiod_direction_output_raw()
1182 return _gpiod_direction_output_raw(desc, value); in gpiod_direction_output_raw()
1198 int gpiod_direction_output(struct gpio_desc *desc, int value) in gpiod_direction_output() argument
1200 if (!desc || !desc->chip) { in gpiod_direction_output()
1204 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_direction_output()
1206 return _gpiod_direction_output_raw(desc, value); in gpiod_direction_output()
1218 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) in gpiod_set_debounce() argument
1222 if (!desc || !desc->chip) { in gpiod_set_debounce()
1227 chip = desc->chip; in gpiod_set_debounce()
1229 gpiod_dbg(desc, in gpiod_set_debounce()
1235 return chip->set_debounce(chip, gpio_chip_hwgpio(desc), debounce); in gpiod_set_debounce()
1245 int gpiod_is_active_low(const struct gpio_desc *desc) in gpiod_is_active_low() argument
1247 return test_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_is_active_low()
1273 static int _gpiod_get_raw_value(const struct gpio_desc *desc) in _gpiod_get_raw_value() argument
1279 chip = desc->chip; in _gpiod_get_raw_value()
1280 offset = gpio_chip_hwgpio(desc); in _gpiod_get_raw_value()
1289 trace_gpio_value(desc_to_gpio(desc), 1, value); in _gpiod_get_raw_value()
1303 int gpiod_get_raw_value(const struct gpio_desc *desc) in gpiod_get_raw_value() argument
1305 if (!desc) in gpiod_get_raw_value()
1308 WARN_ON(desc->chip->can_sleep); in gpiod_get_raw_value()
1309 return _gpiod_get_raw_value(desc); in gpiod_get_raw_value()
1323 int gpiod_get_value(const struct gpio_desc *desc) in gpiod_get_value() argument
1326 if (!desc) in gpiod_get_value()
1329 WARN_ON(desc->chip->can_sleep); in gpiod_get_value()
1331 value = _gpiod_get_raw_value(desc); in gpiod_get_value()
1335 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_value()
1347 static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value) in _gpio_set_open_drain_value() argument
1350 struct gpio_chip *chip = desc->chip; in _gpio_set_open_drain_value()
1351 int offset = gpio_chip_hwgpio(desc); in _gpio_set_open_drain_value()
1356 clear_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_drain_value()
1360 set_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_drain_value()
1362 trace_gpio_direction(desc_to_gpio(desc), value, err); in _gpio_set_open_drain_value()
1364 gpiod_err(desc, in _gpio_set_open_drain_value()
1374 static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value) in _gpio_set_open_source_value() argument
1377 struct gpio_chip *chip = desc->chip; in _gpio_set_open_source_value()
1378 int offset = gpio_chip_hwgpio(desc); in _gpio_set_open_source_value()
1383 set_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_source_value()
1387 clear_bit(FLAG_IS_OUT, &desc->flags); in _gpio_set_open_source_value()
1389 trace_gpio_direction(desc_to_gpio(desc), !value, err); in _gpio_set_open_source_value()
1391 gpiod_err(desc, in _gpio_set_open_source_value()
1396 static void _gpiod_set_raw_value(struct gpio_desc *desc, bool value) in _gpiod_set_raw_value() argument
1400 chip = desc->chip; in _gpiod_set_raw_value()
1401 trace_gpio_value(desc_to_gpio(desc), 0, value); in _gpiod_set_raw_value()
1402 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) in _gpiod_set_raw_value()
1403 _gpio_set_open_drain_value(desc, value); in _gpiod_set_raw_value()
1404 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) in _gpiod_set_raw_value()
1405 _gpio_set_open_source_value(desc, value); in _gpiod_set_raw_value()
1407 chip->set(chip, gpio_chip_hwgpio(desc), value); in _gpiod_set_raw_value()
1458 struct gpio_desc *desc = desc_array[i]; in gpiod_set_array_value_priv() local
1459 int hwgpio = gpio_chip_hwgpio(desc); in gpiod_set_array_value_priv()
1462 if (!raw && test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_array_value_priv()
1464 trace_gpio_value(desc_to_gpio(desc), 0, value); in gpiod_set_array_value_priv()
1469 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { in gpiod_set_array_value_priv()
1470 _gpio_set_open_drain_value(desc, value); in gpiod_set_array_value_priv()
1471 } else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { in gpiod_set_array_value_priv()
1472 _gpio_set_open_source_value(desc, value); in gpiod_set_array_value_priv()
1500 void gpiod_set_raw_value(struct gpio_desc *desc, int value) in gpiod_set_raw_value() argument
1502 if (!desc) in gpiod_set_raw_value()
1505 WARN_ON(desc->chip->can_sleep); in gpiod_set_raw_value()
1506 _gpiod_set_raw_value(desc, value); in gpiod_set_raw_value()
1521 void gpiod_set_value(struct gpio_desc *desc, int value) in gpiod_set_value() argument
1523 if (!desc) in gpiod_set_value()
1526 WARN_ON(desc->chip->can_sleep); in gpiod_set_value()
1527 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_value()
1529 _gpiod_set_raw_value(desc, value); in gpiod_set_value()
1582 int gpiod_cansleep(const struct gpio_desc *desc) in gpiod_cansleep() argument
1584 if (!desc) in gpiod_cansleep()
1586 return desc->chip->can_sleep; in gpiod_cansleep()
1597 int gpiod_to_irq(const struct gpio_desc *desc) in gpiod_to_irq() argument
1602 if (!desc) in gpiod_to_irq()
1604 chip = desc->chip; in gpiod_to_irq()
1605 offset = gpio_chip_hwgpio(desc); in gpiod_to_irq()
1623 if (test_bit(FLAG_IS_OUT, &chip->desc[offset].flags)) { in gpiochip_lock_as_irq()
1630 set_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); in gpiochip_lock_as_irq()
1648 clear_bit(FLAG_USED_AS_IRQ, &chip->desc[offset].flags); in gpiochip_unlock_as_irq()
1661 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) in gpiod_get_raw_value_cansleep() argument
1664 if (!desc) in gpiod_get_raw_value_cansleep()
1666 return _gpiod_get_raw_value(desc); in gpiod_get_raw_value_cansleep()
1679 int gpiod_get_value_cansleep(const struct gpio_desc *desc) in gpiod_get_value_cansleep() argument
1684 if (!desc) in gpiod_get_value_cansleep()
1687 value = _gpiod_get_raw_value(desc); in gpiod_get_value_cansleep()
1691 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_get_value_cansleep()
1708 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value) in gpiod_set_raw_value_cansleep() argument
1711 if (!desc) in gpiod_set_raw_value_cansleep()
1713 _gpiod_set_raw_value(desc, value); in gpiod_set_raw_value_cansleep()
1727 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) in gpiod_set_value_cansleep() argument
1730 if (!desc) in gpiod_set_value_cansleep()
1733 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) in gpiod_set_value_cansleep()
1735 _gpiod_set_raw_value(desc, value); in gpiod_set_value_cansleep()
1817 struct gpio_desc *desc; in of_find_gpio() local
1828 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, in of_find_gpio()
1830 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER)) in of_find_gpio()
1834 if (IS_ERR(desc)) in of_find_gpio()
1835 return desc; in of_find_gpio()
1847 return desc; in of_find_gpio()
1856 struct gpio_desc *desc; in acpi_find_gpio() local
1870 desc = acpi_get_gpiod_by_index(adev, propname, idx, &info); in acpi_find_gpio()
1871 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER)) in acpi_find_gpio()
1876 if (IS_ERR(desc)) { in acpi_find_gpio()
1877 desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); in acpi_find_gpio()
1878 if (IS_ERR(desc)) in acpi_find_gpio()
1879 return desc; in acpi_find_gpio()
1885 return desc; in acpi_find_gpio()
1923 struct gpio_desc *desc = ERR_PTR(-ENOENT); in gpiod_find() local
1929 return desc; in gpiod_find()
1957 desc = gpiochip_get_desc(chip, p->chip_hwnum); in gpiod_find()
1960 return desc; in gpiod_find()
1963 return desc; in gpiod_find()
2073 static void gpiod_parse_flags(struct gpio_desc *desc, unsigned long lflags) in gpiod_parse_flags() argument
2076 set_bit(FLAG_ACTIVE_LOW, &desc->flags); in gpiod_parse_flags()
2078 set_bit(FLAG_OPEN_DRAIN, &desc->flags); in gpiod_parse_flags()
2080 set_bit(FLAG_OPEN_SOURCE, &desc->flags); in gpiod_parse_flags()
2093 static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, in gpiod_configure_flags() argument
2106 status = gpiod_direction_output(desc, in gpiod_configure_flags()
2109 status = gpiod_direction_input(desc); in gpiod_configure_flags()
2133 struct gpio_desc *desc = NULL; in gpiod_get_index() local
2143 desc = of_find_gpio(dev, con_id, idx, &lookupflags); in gpiod_get_index()
2146 desc = acpi_find_gpio(dev, con_id, idx, &lookupflags); in gpiod_get_index()
2154 if (!desc || desc == ERR_PTR(-ENOENT)) { in gpiod_get_index()
2156 desc = gpiod_find(dev, con_id, idx, &lookupflags); in gpiod_get_index()
2159 if (IS_ERR(desc)) { in gpiod_get_index()
2161 return desc; in gpiod_get_index()
2164 gpiod_parse_flags(desc, lookupflags); in gpiod_get_index()
2166 status = gpiod_request(desc, con_id); in gpiod_get_index()
2170 status = gpiod_configure_flags(desc, con_id, flags); in gpiod_get_index()
2173 gpiod_put(desc); in gpiod_get_index()
2177 return desc; in gpiod_get_index()
2198 struct gpio_desc *desc = ERR_PTR(-ENODEV); in fwnode_get_named_gpiod() local
2209 desc = of_get_named_gpiod_flags(to_of_node(fwnode), propname, 0, in fwnode_get_named_gpiod()
2211 if (!IS_ERR(desc)) { in fwnode_get_named_gpiod()
2218 desc = acpi_node_get_gpiod(fwnode, propname, 0, &info); in fwnode_get_named_gpiod()
2219 if (!IS_ERR(desc)) in fwnode_get_named_gpiod()
2223 if (IS_ERR(desc)) in fwnode_get_named_gpiod()
2224 return desc; in fwnode_get_named_gpiod()
2227 set_bit(FLAG_ACTIVE_LOW, &desc->flags); in fwnode_get_named_gpiod()
2231 set_bit(FLAG_OPEN_DRAIN, &desc->flags); in fwnode_get_named_gpiod()
2233 set_bit(FLAG_OPEN_SOURCE, &desc->flags); in fwnode_get_named_gpiod()
2236 ret = gpiod_request(desc, NULL); in fwnode_get_named_gpiod()
2240 return desc; in fwnode_get_named_gpiod()
2261 struct gpio_desc *desc; in gpiod_get_index_optional() local
2263 desc = gpiod_get_index(dev, con_id, index, flags); in gpiod_get_index_optional()
2264 if (IS_ERR(desc)) { in gpiod_get_index_optional()
2265 if (PTR_ERR(desc) == -ENOENT) in gpiod_get_index_optional()
2269 return desc; in gpiod_get_index_optional()
2281 int gpiod_hog(struct gpio_desc *desc, const char *name, in gpiod_hog() argument
2289 chip = gpiod_to_chip(desc); in gpiod_hog()
2290 hwnum = gpio_chip_hwgpio(desc); in gpiod_hog()
2292 gpiod_parse_flags(desc, lflags); in gpiod_hog()
2301 status = gpiod_configure_flags(desc, name, dflags); in gpiod_hog()
2305 gpiochip_free_own_desc(desc); in gpiod_hog()
2310 set_bit(FLAG_IS_HOGGED, &desc->flags); in gpiod_hog()
2313 desc_to_gpio(desc), name, in gpiod_hog()
2332 if (test_bit(FLAG_IS_HOGGED, &chip->desc[id].flags)) in gpiochip_free_hogs()
2333 gpiochip_free_own_desc(&chip->desc[id]); in gpiochip_free_hogs()
2353 struct gpio_desc *desc; in gpiod_get_array() local
2361 descs = kzalloc(sizeof(*descs) + sizeof(descs->desc[0]) * count, in gpiod_get_array()
2367 desc = gpiod_get_index(dev, con_id, descs->ndescs, flags); in gpiod_get_array()
2368 if (IS_ERR(desc)) { in gpiod_get_array()
2370 return ERR_CAST(desc); in gpiod_get_array()
2372 descs->desc[descs->ndescs] = desc; in gpiod_get_array()
2409 void gpiod_put(struct gpio_desc *desc) in gpiod_put() argument
2411 gpiod_free(desc); in gpiod_put()
2424 gpiod_put(descs->desc[i]); in gpiod_put_array()
2436 struct gpio_desc *gdesc = &chip->desc[0]; in gpiolib_dbg_show()