@@ -415,10 +415,14 @@ static ssize_t upisnd_element_pin_show(struct kobject *kobj, struct kobj_attribu
415415 char * buf );
416416static ssize_t upisnd_element_pin_name_show (struct kobject * kobj , struct kobj_attribute * attr ,
417417 char * buf );
418+ static ssize_t upisnd_element_pin_pull_show (struct kobject * kobj , struct kobj_attribute * attr ,
419+ char * buf );
418420static ssize_t upisnd_element_pin_b_show (struct kobject * kobj , struct kobj_attribute * attr ,
419421 char * buf );
420422static ssize_t upisnd_element_pin_b_name_show (struct kobject * kobj , struct kobj_attribute * attr ,
421423 char * buf );
424+ static ssize_t upisnd_element_pin_b_pull_show (struct kobject * kobj , struct kobj_attribute * attr ,
425+ char * buf );
422426static ssize_t upisnd_element_activity_type_show (struct kobject * kobj , struct kobj_attribute * attr ,
423427 char * buf );
424428static ssize_t upisnd_element_gpio_export (struct kobject * kobj , struct kobj_attribute * attr ,
@@ -446,10 +450,14 @@ static struct kobj_attribute upisnd_element_pin_attr = __ATTR(pin, 0444, upisnd_
446450 NULL );
447451static struct kobj_attribute upisnd_element_pin_name_attr = __ATTR (pin_name , 0444 ,
448452 upisnd_element_pin_name_show , NULL );
453+ static struct kobj_attribute upisnd_element_pin_pull_attr = __ATTR (pin_pull , 0444 ,
454+ upisnd_element_pin_pull_show , NULL );
449455static struct kobj_attribute upisnd_element_pin_b_attr = __ATTR (pin_b , 0444 ,
450456 upisnd_element_pin_b_show , NULL );
451457static struct kobj_attribute upisnd_element_pin_b_name_attr = __ATTR (pin_b_name , 0444 ,
452458 upisnd_element_pin_b_name_show , NULL );
459+ static struct kobj_attribute upisnd_element_pin_b_pull_attr = __ATTR (pin_b_pull , 0444 ,
460+ upisnd_element_pin_b_pull_show , NULL );
453461static struct kobj_attribute upisnd_element_activity_type_attr = __ATTR (activity_type , 0444 ,
454462 upisnd_element_activity_type_show , NULL );
455463static struct kobj_attribute upisnd_element_gpio_export_attr = __ATTR (gpio_export , 0220 , NULL ,
@@ -468,8 +476,10 @@ static struct attribute *upisnd_element_attrs[] = {
468476 & upisnd_element_direction_attr .attr ,
469477 & upisnd_element_pin_attr .attr ,
470478 & upisnd_element_pin_name_attr .attr ,
479+ & upisnd_element_pin_pull_attr .attr ,
471480 & upisnd_element_pin_b_attr .attr ,
472481 & upisnd_element_pin_b_name_attr .attr ,
482+ & upisnd_element_pin_b_pull_attr .attr ,
473483 & upisnd_element_activity_type_attr .attr ,
474484 & upisnd_element_gpio_export_attr .attr ,
475485 & upisnd_element_gpio_unexport_attr .attr ,
@@ -491,7 +501,8 @@ static umode_t upisnd_element_attr_is_visible(struct kobject *kobj, struct attri
491501 case UPISND_ELEMENT_TYPE_ENCODER :
492502 if (attr == & upisnd_element_value_mode_attr .attr ||
493503 attr == & upisnd_element_pin_b_attr .attr ||
494- attr == & upisnd_element_pin_b_name_attr .attr )
504+ attr == & upisnd_element_pin_b_name_attr .attr ||
505+ attr == & upisnd_element_pin_b_pull_attr .attr )
495506 return attr -> mode ;
496507 fallthrough ;
497508 case UPISND_ELEMENT_TYPE_ANALOG_IN :
@@ -522,6 +533,14 @@ static umode_t upisnd_element_attr_is_visible(struct kobject *kobj, struct attri
522533 return 0444 ;
523534 }
524535 return attr -> mode ;
536+ } else if (attr == & upisnd_element_pin_pull_attr .attr ) {
537+ if (t == UPISND_ELEMENT_TYPE_GPIO ) {
538+ if (upisnd_setup_get_gpio_dir (instance -> gpio .pin_configs
539+ [element -> gpio_pins [0 ]].setup ) == UPISND_PIN_DIR_INPUT )
540+ return attr -> mode ;
541+ } else if (t == UPISND_ELEMENT_TYPE_ENCODER ) {
542+ return attr -> mode ;
543+ }
525544 }
526545 break ;
527546 case UPISND_ELEMENT_TYPE_ACTIVITY :
@@ -535,7 +554,7 @@ static umode_t upisnd_element_attr_is_visible(struct kobject *kobj, struct attri
535554
536555 if (attr == & upisnd_element_type_attr .attr ||
537556 attr == & upisnd_element_pin_attr .attr ||
538- attr == & upisnd_element_pin_name_attr .attr )
557+ attr == & upisnd_element_pin_name_attr .attr )
539558 return attr -> mode ;
540559
541560 return 0 ;
@@ -1524,6 +1543,55 @@ static ssize_t upisnd_element_pin_name_show(struct kobject *kobj, struct kobj_at
15241543 return - EINVAL ;
15251544}
15261545
1546+ static const char * upisnd_pin_pull_to_string (enum upisnd_pin_pull_e pull )
1547+ {
1548+ switch (pull ) {
1549+ case UPISND_PIN_PULL_NONE :
1550+ return "pull_none" ;
1551+ case UPISND_PIN_PULL_DOWN :
1552+ return "pull_down" ;
1553+ case UPISND_PIN_PULL_UP :
1554+ return "pull_up" ;
1555+ default :
1556+ return NULL ;
1557+ }
1558+ }
1559+
1560+ static ssize_t upisnd_element_pin_pull_show (struct kobject * kobj , struct kobj_attribute * attr ,
1561+ char * buf )
1562+ {
1563+ struct upisnd_element * element = to_element (kobj );
1564+
1565+ struct upisnd_config * cfg = to_config (kobj -> parent -> parent );
1566+ struct upisnd_instance * instance = cfg -> instance ;
1567+
1568+ enum upisnd_element_type_e t = UPISND_ELEMENT_TYPE_NONE ;
1569+
1570+ if (element -> gpio_pins [0 ] != UPISND_PIN_INVALID )
1571+ t = upisnd_setup_get_element_type (instance -> gpio .pin_configs [element -> gpio_pins [0 ]]
1572+ .setup );
1573+
1574+ if (t == UPISND_ELEMENT_TYPE_GPIO ) {
1575+ if (upisnd_setup_get_gpio_dir (instance -> gpio .pin_configs [element -> gpio_pins [0 ]]
1576+ .setup ) != UPISND_PIN_DIR_INPUT )
1577+ return - EINVAL ;
1578+ } else if (t != UPISND_ELEMENT_TYPE_ENCODER ) {
1579+ return - EINVAL ;
1580+ }
1581+
1582+ enum upisnd_pin_pull_e pull = upisnd_setup_get_gpio_pull (
1583+ instance -> gpio .pin_configs [element -> gpio_pins [0 ]].setup );
1584+
1585+ switch (pull ) {
1586+ case UPISND_PIN_PULL_NONE :
1587+ case UPISND_PIN_PULL_DOWN :
1588+ case UPISND_PIN_PULL_UP :
1589+ return sprintf (buf , "%s\n" , upisnd_pin_pull_to_string (pull ));
1590+ default :
1591+ return 0 ;
1592+ }
1593+ }
1594+
15271595static ssize_t upisnd_element_pin_b_show (struct kobject * kobj , struct kobj_attribute * attr ,
15281596 char * buf )
15291597{
@@ -1546,6 +1614,36 @@ static ssize_t upisnd_element_pin_b_name_show(struct kobject *kobj, struct kobj_
15461614 return - EINVAL ;
15471615}
15481616
1617+ static ssize_t upisnd_element_pin_b_pull_show (struct kobject * kobj , struct kobj_attribute * attr ,
1618+ char * buf )
1619+ {
1620+ struct upisnd_element * element = to_element (kobj );
1621+
1622+ struct upisnd_config * cfg = to_config (kobj -> parent -> parent );
1623+ struct upisnd_instance * instance = cfg -> instance ;
1624+
1625+ enum upisnd_element_type_e t = UPISND_ELEMENT_TYPE_NONE ;
1626+
1627+ if (element -> gpio_pins [0 ] != UPISND_PIN_INVALID )
1628+ t = upisnd_setup_get_element_type (instance -> gpio .pin_configs [element -> gpio_pins [0 ]]
1629+ .setup );
1630+
1631+ if (t != UPISND_ELEMENT_TYPE_ENCODER )
1632+ return - EINVAL ;
1633+
1634+ enum upisnd_pin_pull_e pull = upisnd_setup_get_encoder_pin_b_pull (
1635+ instance -> gpio .pin_configs [element -> gpio_pins [0 ]].setup );
1636+
1637+ switch (pull ) {
1638+ case UPISND_PIN_PULL_NONE :
1639+ case UPISND_PIN_PULL_DOWN :
1640+ case UPISND_PIN_PULL_UP :
1641+ return sprintf (buf , "%s\n" , upisnd_pin_pull_to_string (pull ));
1642+ default :
1643+ return 0 ;
1644+ }
1645+ }
1646+
15491647static ssize_t upisnd_element_activity_type_show (struct kobject * kobj , struct kobj_attribute * attr ,
15501648 char * buf )
15511649{
0 commit comments