@@ -1610,11 +1610,25 @@ static int ad7380_write_event_config(struct iio_dev *indio_dev,
1610
1610
return ret ;
1611
1611
}
1612
1612
1613
- static int ad7380_get_alert_th (struct ad7380_state * st ,
1613
+ static int ad7380_get_alert_th (struct iio_dev * indio_dev ,
1614
+ const struct iio_chan_spec * chan ,
1614
1615
enum iio_event_direction dir ,
1615
1616
int * val )
1616
1617
{
1617
- int ret , tmp ;
1618
+ struct ad7380_state * st = iio_priv (indio_dev );
1619
+ const struct iio_scan_type * scan_type ;
1620
+ int ret , tmp , shift ;
1621
+
1622
+ scan_type = iio_get_current_scan_type (indio_dev , chan );
1623
+ if (IS_ERR (scan_type ))
1624
+ return PTR_ERR (scan_type );
1625
+
1626
+ /*
1627
+ * The register value is 12-bits and is compared to the most significant
1628
+ * bits of raw value, therefore a shift is required to convert this to
1629
+ * the same scale as the raw value.
1630
+ */
1631
+ shift = scan_type -> realbits - 12 ;
1618
1632
1619
1633
switch (dir ) {
1620
1634
case IIO_EV_DIR_RISING :
@@ -1624,7 +1638,7 @@ static int ad7380_get_alert_th(struct ad7380_state *st,
1624
1638
if (ret )
1625
1639
return ret ;
1626
1640
1627
- * val = FIELD_GET (AD7380_ALERT_HIGH_TH , tmp );
1641
+ * val = FIELD_GET (AD7380_ALERT_HIGH_TH , tmp ) << shift ;
1628
1642
return IIO_VAL_INT ;
1629
1643
case IIO_EV_DIR_FALLING :
1630
1644
ret = regmap_read (st -> regmap ,
@@ -1633,7 +1647,7 @@ static int ad7380_get_alert_th(struct ad7380_state *st,
1633
1647
if (ret )
1634
1648
return ret ;
1635
1649
1636
- * val = FIELD_GET (AD7380_ALERT_LOW_TH , tmp );
1650
+ * val = FIELD_GET (AD7380_ALERT_LOW_TH , tmp ) << shift ;
1637
1651
return IIO_VAL_INT ;
1638
1652
default :
1639
1653
return - EINVAL ;
@@ -1647,15 +1661,14 @@ static int ad7380_read_event_value(struct iio_dev *indio_dev,
1647
1661
enum iio_event_info info ,
1648
1662
int * val , int * val2 )
1649
1663
{
1650
- struct ad7380_state * st = iio_priv (indio_dev );
1651
1664
int ret ;
1652
1665
1653
1666
switch (info ) {
1654
1667
case IIO_EV_INFO_VALUE :
1655
1668
if (!iio_device_claim_direct (indio_dev ))
1656
1669
return - EBUSY ;
1657
1670
1658
- ret = ad7380_get_alert_th (st , dir , val );
1671
+ ret = ad7380_get_alert_th (indio_dev , chan , dir , val );
1659
1672
1660
1673
iio_device_release_direct (indio_dev );
1661
1674
return ret ;
0 commit comments