@@ -415,10 +415,14 @@ static ssize_t upisnd_element_pin_show(struct kobject *kobj, struct kobj_attribu
415
415
char * buf );
416
416
static ssize_t upisnd_element_pin_name_show (struct kobject * kobj , struct kobj_attribute * attr ,
417
417
char * buf );
418
+ static ssize_t upisnd_element_pin_pull_show (struct kobject * kobj , struct kobj_attribute * attr ,
419
+ char * buf );
418
420
static ssize_t upisnd_element_pin_b_show (struct kobject * kobj , struct kobj_attribute * attr ,
419
421
char * buf );
420
422
static ssize_t upisnd_element_pin_b_name_show (struct kobject * kobj , struct kobj_attribute * attr ,
421
423
char * buf );
424
+ static ssize_t upisnd_element_pin_b_pull_show (struct kobject * kobj , struct kobj_attribute * attr ,
425
+ char * buf );
422
426
static ssize_t upisnd_element_activity_type_show (struct kobject * kobj , struct kobj_attribute * attr ,
423
427
char * buf );
424
428
static 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_
446
450
NULL );
447
451
static struct kobj_attribute upisnd_element_pin_name_attr = __ATTR (pin_name , 0444 ,
448
452
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 );
449
455
static struct kobj_attribute upisnd_element_pin_b_attr = __ATTR (pin_b , 0444 ,
450
456
upisnd_element_pin_b_show , NULL );
451
457
static struct kobj_attribute upisnd_element_pin_b_name_attr = __ATTR (pin_b_name , 0444 ,
452
458
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 );
453
461
static struct kobj_attribute upisnd_element_activity_type_attr = __ATTR (activity_type , 0444 ,
454
462
upisnd_element_activity_type_show , NULL );
455
463
static struct kobj_attribute upisnd_element_gpio_export_attr = __ATTR (gpio_export , 0220 , NULL ,
@@ -468,8 +476,10 @@ static struct attribute *upisnd_element_attrs[] = {
468
476
& upisnd_element_direction_attr .attr ,
469
477
& upisnd_element_pin_attr .attr ,
470
478
& upisnd_element_pin_name_attr .attr ,
479
+ & upisnd_element_pin_pull_attr .attr ,
471
480
& upisnd_element_pin_b_attr .attr ,
472
481
& upisnd_element_pin_b_name_attr .attr ,
482
+ & upisnd_element_pin_b_pull_attr .attr ,
473
483
& upisnd_element_activity_type_attr .attr ,
474
484
& upisnd_element_gpio_export_attr .attr ,
475
485
& upisnd_element_gpio_unexport_attr .attr ,
@@ -491,7 +501,8 @@ static umode_t upisnd_element_attr_is_visible(struct kobject *kobj, struct attri
491
501
case UPISND_ELEMENT_TYPE_ENCODER :
492
502
if (attr == & upisnd_element_value_mode_attr .attr ||
493
503
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 )
495
506
return attr -> mode ;
496
507
fallthrough ;
497
508
case UPISND_ELEMENT_TYPE_ANALOG_IN :
@@ -522,6 +533,14 @@ static umode_t upisnd_element_attr_is_visible(struct kobject *kobj, struct attri
522
533
return 0444 ;
523
534
}
524
535
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
+ }
525
544
}
526
545
break ;
527
546
case UPISND_ELEMENT_TYPE_ACTIVITY :
@@ -535,7 +554,7 @@ static umode_t upisnd_element_attr_is_visible(struct kobject *kobj, struct attri
535
554
536
555
if (attr == & upisnd_element_type_attr .attr ||
537
556
attr == & upisnd_element_pin_attr .attr ||
538
- attr == & upisnd_element_pin_name_attr .attr )
557
+ attr == & upisnd_element_pin_name_attr .attr )
539
558
return attr -> mode ;
540
559
541
560
return 0 ;
@@ -1524,6 +1543,55 @@ static ssize_t upisnd_element_pin_name_show(struct kobject *kobj, struct kobj_at
1524
1543
return - EINVAL ;
1525
1544
}
1526
1545
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
+
1527
1595
static ssize_t upisnd_element_pin_b_show (struct kobject * kobj , struct kobj_attribute * attr ,
1528
1596
char * buf )
1529
1597
{
@@ -1546,6 +1614,36 @@ static ssize_t upisnd_element_pin_b_name_show(struct kobject *kobj, struct kobj_
1546
1614
return - EINVAL ;
1547
1615
}
1548
1616
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
+
1549
1647
static ssize_t upisnd_element_activity_type_show (struct kobject * kobj , struct kobj_attribute * attr ,
1550
1648
char * buf )
1551
1649
{
0 commit comments