@@ -446,6 +446,7 @@ static const struct at91_adc_reg_layout sama7g5_layout = {
446446 * @osr_mask: oversampling ratio bitmask on EMR register
447447 * @osr_vals: available oversampling rates
448448 * @chan_realbits: realbits for registered channels
449+ * @temp_chan: temperature channel index
449450 * @temp_sensor: temperature sensor supported
450451 */
451452struct at91_adc_platform {
@@ -461,6 +462,7 @@ struct at91_adc_platform {
461462 unsigned int osr_mask ;
462463 unsigned int osr_vals ;
463464 unsigned int chan_realbits ;
465+ unsigned int temp_chan ;
464466 bool temp_sensor ;
465467};
466468
@@ -743,15 +745,23 @@ static const struct at91_adc_platform sama7g5_platform = {
743745 BIT (AT91_SAMA5D2_EMR_OSR_256SAMPLES ),
744746 .chan_realbits = 16 ,
745747 .temp_sensor = true,
748+ .temp_chan = AT91_SAMA7G5_ADC_TEMP_CHANNEL ,
746749};
747750
748751static int at91_adc_chan_xlate (struct iio_dev * indio_dev , int chan )
749752{
753+ struct at91_adc_state * st = iio_priv (indio_dev );
750754 int i ;
751755
752756 for (i = 0 ; i < indio_dev -> num_channels ; i ++ ) {
753- if (indio_dev -> channels [i ].scan_index == chan )
757+ if (indio_dev -> channels [i ].scan_index == chan ) {
758+ if (st -> soc_info .platform -> temp_sensor &&
759+ chan == st -> soc_info .platform -> temp_chan &&
760+ !st -> temp_st .init )
761+ return - EINVAL ;
762+
754763 return i ;
764+ }
755765 }
756766 return - EINVAL ;
757767}
@@ -2183,36 +2193,34 @@ static int at91_adc_buffer_and_trigger_init(struct device *dev,
21832193 return 0 ;
21842194}
21852195
2186- static int at91_adc_temp_sensor_init (struct iio_dev * indio_dev )
2196+ static void at91_adc_temp_sensor_init (struct at91_adc_state * st ,
2197+ struct device * dev )
21872198{
2188- struct at91_adc_state * st = iio_priv (indio_dev );
21892199 struct at91_adc_temp_sensor_clb * clb = & st -> soc_info .temp_sensor_clb ;
21902200 struct nvmem_cell * temp_calib ;
21912201 u32 * buf ;
21922202 size_t len ;
2193- int ret = 0 ;
21942203
21952204 if (!st -> soc_info .platform -> temp_sensor )
2196- return 0 ;
2205+ return ;
2206+
2207+ st -> temp_st .init = false;
21972208
21982209 /* Get the calibration data from NVMEM. */
2199- temp_calib = devm_nvmem_cell_get (indio_dev -> dev .parent ,
2200- "temperature_calib" );
2210+ temp_calib = devm_nvmem_cell_get (dev , "temperature_calib" );
22012211 if (IS_ERR (temp_calib )) {
2202- ret = PTR_ERR (temp_calib );
2203-
2204- if (ret == - ENOENT ) {
2205- st -> temp_st .init = false;
2206- return 0 ;
2207- }
2208- return ret ;
2212+ if (PTR_ERR (temp_calib ) != - ENOENT )
2213+ dev_err (dev , "Failed to get temperature_calib cell!\n" );
2214+ return ;
22092215 }
22102216
22112217 buf = nvmem_cell_read (temp_calib , & len );
2212- if (IS_ERR (buf ))
2213- return PTR_ERR (buf );
2218+ if (IS_ERR (buf )) {
2219+ dev_err (dev , "Failed to read calibration data!\n" );
2220+ return ;
2221+ }
22142222 if (len < AT91_ADC_TS_CLB_IDX_MAX * 4 ) {
2215- ret = - EINVAL ;
2223+ dev_err ( dev , "Invalid calibration data!\n" ) ;
22162224 goto free_buf ;
22172225 }
22182226
@@ -2226,7 +2234,6 @@ static int at91_adc_temp_sensor_init(struct iio_dev *indio_dev)
22262234
22272235free_buf :
22282236 kfree (buf );
2229- return ret ;
22302237}
22312238
22322239static int at91_adc_probe (struct platform_device * pdev )
@@ -2362,9 +2369,7 @@ static int at91_adc_probe(struct platform_device *pdev)
23622369 if (ret )
23632370 goto vref_disable ;
23642371
2365- ret = at91_adc_temp_sensor_init (indio_dev );
2366- if (ret )
2367- goto per_clk_disable_unprepare ;
2372+ at91_adc_temp_sensor_init (st , & pdev -> dev );
23682373
23692374 at91_adc_hw_init (indio_dev );
23702375
0 commit comments