37
37
#include <linux/iio/consumer.h>
38
38
39
39
#include <linux/hwmon.h>
40
- #include <linux/hwmon-sysfs.h>
41
- #include <linux/thermal.h>
42
40
43
41
struct ntc_compensation {
44
42
int temp_c ;
@@ -588,55 +586,87 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
588
586
return - EINVAL ;
589
587
}
590
588
591
- static int ntc_read_temp (void * data , int * temp )
589
+ static int ntc_read (struct device * dev , enum hwmon_sensor_types type ,
590
+ u32 attr , int channel , long * val )
592
591
{
592
+ struct ntc_data * data = dev_get_drvdata (dev );
593
593
int ohm ;
594
594
595
- ohm = ntc_thermistor_get_ohm (data );
596
- if (ohm < 0 )
597
- return ohm ;
598
-
599
- * temp = get_temp_mc (data , ohm );
600
-
601
- return 0 ;
595
+ switch (type ) {
596
+ case hwmon_temp :
597
+ switch (attr ) {
598
+ case hwmon_temp_input :
599
+ ohm = ntc_thermistor_get_ohm (data );
600
+ if (ohm < 0 )
601
+ return ohm ;
602
+ * val = get_temp_mc (data , ohm );
603
+ return 0 ;
604
+ case hwmon_temp_type :
605
+ * val = 4 ;
606
+ return 0 ;
607
+ default :
608
+ break ;
609
+ }
610
+ break ;
611
+ default :
612
+ break ;
613
+ }
614
+ return - EINVAL ;
602
615
}
603
616
604
- static ssize_t ntc_type_show ( struct device * dev ,
605
- struct device_attribute * attr , char * buf )
617
+ static umode_t ntc_is_visible ( const void * data , enum hwmon_sensor_types type ,
618
+ u32 attr , int channel )
606
619
{
607
- return sprintf (buf , "4\n" );
620
+ if (type == hwmon_temp ) {
621
+ switch (attr ) {
622
+ case hwmon_temp_input :
623
+ case hwmon_temp_type :
624
+ return 0444 ;
625
+ default :
626
+ break ;
627
+ }
628
+ }
629
+ return 0 ;
608
630
}
609
631
610
- static ssize_t ntc_temp_show (struct device * dev ,
611
- struct device_attribute * attr , char * buf )
612
- {
613
- struct ntc_data * data = dev_get_drvdata (dev );
614
- int ohm ;
632
+ static const u32 ntc_chip_config [] = {
633
+ HWMON_C_REGISTER_TZ ,
634
+ 0
635
+ };
615
636
616
- ohm = ntc_thermistor_get_ohm (data );
617
- if (ohm < 0 )
618
- return ohm ;
637
+ static const struct hwmon_channel_info ntc_chip = {
638
+ .type = hwmon_chip ,
639
+ .config = ntc_chip_config ,
640
+ };
619
641
620
- return sprintf (buf , "%d\n" , get_temp_mc (data , ohm ));
621
- }
642
+ static const u32 ntc_temp_config [] = {
643
+ HWMON_T_INPUT , HWMON_T_TYPE ,
644
+ 0
645
+ };
622
646
623
- static SENSOR_DEVICE_ATTR_RO (temp1_type , ntc_type , 0 ) ;
624
- static SENSOR_DEVICE_ATTR_RO (temp1_input , ntc_temp , 0 ) ;
647
+ static const struct hwmon_channel_info ntc_temp = {
648
+ .type = hwmon_temp ,
649
+ .config = ntc_temp_config ,
650
+ };
625
651
626
- static struct attribute * ntc_attrs [] = {
627
- & sensor_dev_attr_temp1_type . dev_attr . attr ,
628
- & sensor_dev_attr_temp1_input . dev_attr . attr ,
629
- NULL ,
652
+ static const struct hwmon_channel_info * ntc_info [] = {
653
+ & ntc_chip ,
654
+ & ntc_temp ,
655
+ NULL
630
656
};
631
- ATTRIBUTE_GROUPS (ntc );
632
657
633
- static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = {
634
- .get_temp = ntc_read_temp ,
658
+ static const struct hwmon_ops ntc_hwmon_ops = {
659
+ .is_visible = ntc_is_visible ,
660
+ .read = ntc_read ,
661
+ };
662
+
663
+ static const struct hwmon_chip_info ntc_chip_info = {
664
+ .ops = & ntc_hwmon_ops ,
665
+ .info = ntc_info ,
635
666
};
636
667
637
668
static int ntc_thermistor_probe (struct platform_device * pdev )
638
669
{
639
- struct thermal_zone_device * tz ;
640
670
struct device * dev = & pdev -> dev ;
641
671
const struct of_device_id * of_id =
642
672
of_match_device (of_match_ptr (ntc_match ), dev );
@@ -697,8 +727,9 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
697
727
data -> comp = ntc_type [pdev_id -> driver_data ].comp ;
698
728
data -> n_comp = ntc_type [pdev_id -> driver_data ].n_comp ;
699
729
700
- hwmon_dev = devm_hwmon_device_register_with_groups (dev , pdev_id -> name ,
701
- data , ntc_groups );
730
+ hwmon_dev = devm_hwmon_device_register_with_info (dev , pdev_id -> name ,
731
+ data , & ntc_chip_info ,
732
+ NULL );
702
733
if (IS_ERR (hwmon_dev )) {
703
734
dev_err (dev , "unable to register as hwmon device.\n" );
704
735
return PTR_ERR (hwmon_dev );
@@ -707,11 +738,6 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
707
738
dev_info (dev , "Thermistor type: %s successfully probed.\n" ,
708
739
pdev_id -> name );
709
740
710
- tz = devm_thermal_zone_of_sensor_register (dev , 0 , data ,
711
- & ntc_of_thermal_ops );
712
- if (IS_ERR (tz ))
713
- dev_dbg (dev , "Failed to register to thermal fw.\n" );
714
-
715
741
return 0 ;
716
742
}
717
743
0 commit comments