History

iio: at91_adc: remove usage of iio_priv_to_dev() helper

We may want to get rid of the iio_priv_to_dev() helper. The reason is that we will hide some of the members of the iio_dev structure (to prevent drivers from accessing them directly), and that will also mean hiding the implementation of the iio_priv_to_dev() helper inside the IIO core. Hiding the implementation of iio_priv_to_dev() implies that some fast-paths may not be fast anymore, so a general idea is to try to get rid of the iio_priv_to_dev() altogether. The iio_priv() helper won't be affected by the rework, as the iio_dev struct will keep a reference to the private information. For this driver, not using iio_priv_to_dev(), means reworking some paths to pass the iio device and using iio_priv() to access the private information.

Alexandru Ardelean committed 6 years ago

Commit 044d4061 parent 07b6c9d1 file · +15 −15Browse files

Unified · Split

drivers/iio/adc/at91_adc.c+15−15
@@ -287,13 +287,13 @@ static void handle_adc_eoc_trigger(int irq, struct iio_dev *idev) · 286 unmodified lines
287287 }
288288 }
289289
290−static int at91_ts_sample(struct at91_adc_state *st)
290+static int at91_ts_sample(struct iio_dev *idev)
291291 {
292+ struct at91_adc_state *st = iio_priv(idev);
292293 unsigned int xscale, yscale, reg, z1, z2;
293294 unsigned int x, y, pres, xpos, ypos;
294295 unsigned int rxp = 1;
295296 unsigned int factor = 1000;
296− struct iio_dev *idev = iio_priv_to_dev(st);
297297
298298 unsigned int xyz_mask_bits = st->res;
299299 unsigned int xyz_mask = (1 << xyz_mask_bits) - 1;
@@ -449,7 +449,7 @@ static irqreturn_t at91_adc_9x5_interrupt(int irq, void *private) · 149 unmodified lines
449449
450450 if (status & AT91_ADC_ISR_PENS) {
451451 /* validate data by pen contact */
452− at91_ts_sample(st);
452+ at91_ts_sample(idev);
453453 } else {
454454 /* triggered by event that is no pen contact, just read
455455 * them to clean the interrupt and discard all.
@@ -737,10 +737,10 @@ static int at91_adc_read_raw(struct iio_dev *idev, · 281 unmodified lines
737737 return -EINVAL;
738738 }
739739
740−static int at91_adc_of_get_resolution(struct at91_adc_state *st,
740+static int at91_adc_of_get_resolution(struct iio_dev *idev,
741741 struct platform_device *pdev)
742742 {
743− struct iio_dev *idev = iio_priv_to_dev(st);
743+ struct at91_adc_state *st = iio_priv(idev);
744744 struct device_node *np = pdev->dev.of_node;
745745 int count, i, ret = 0;
746746 char *res_name, *s;
@@ -866,10 +866,10 @@ static int at91_adc_probe_dt_ts(struct device_node *node, · 119 unmodified lines
866866 }
867867 }
868868
869−static int at91_adc_probe_dt(struct at91_adc_state *st,
869+static int at91_adc_probe_dt(struct iio_dev *idev,
870870 struct platform_device *pdev)
871871 {
872− struct iio_dev *idev = iio_priv_to_dev(st);
872+ struct at91_adc_state *st = iio_priv(idev);
873873 struct device_node *node = pdev->dev.of_node;
874874 struct device_node *trig_node;
875875 int i = 0, ret;
@@ -910,7 +910,7 @@ static int at91_adc_probe_dt(struct at91_adc_state *st, · 34 unmodified lines
910910 }
911911 st->vref_mv = prop;
912912
913− ret = at91_adc_of_get_resolution(st, pdev);
913+ ret = at91_adc_of_get_resolution(idev, pdev);
914914 if (ret)
915915 goto error_ret;
916916
@@ -1010,9 +1010,9 @@ static void atmel_ts_close(struct input_dev *dev) · 93 unmodified lines
10101010 at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN);
10111011 }
10121012
1013−static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz)
1013+static int at91_ts_hw_init(struct iio_dev *idev, u32 adc_clk_khz)
10141014 {
1015− struct iio_dev *idev = iio_priv_to_dev(st);
1015+ struct at91_adc_state *st = iio_priv(idev);
10161016 u32 reg = 0;
10171017 u32 tssctim = 0;
10181018 int i = 0;
@@ -1085,11 +1085,11 @@ static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz) · 66 unmodified lines
10851085 return 0;
10861086 }
10871087
1088−static int at91_ts_register(struct at91_adc_state *st,
1088+static int at91_ts_register(struct iio_dev *idev,
10891089 struct platform_device *pdev)
10901090 {
1091+ struct at91_adc_state *st = iio_priv(idev);
10911092 struct input_dev *input;
1092− struct iio_dev *idev = iio_priv_to_dev(st);
10931093 int ret;
10941094
10951095 input = input_allocate_device();
@@ -1161,7 +1161,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 65 unmodified lines
11611161 st = iio_priv(idev);
11621162
11631163 if (pdev->dev.of_node)
1164− ret = at91_adc_probe_dt(st, pdev);
1164+ ret = at91_adc_probe_dt(idev, pdev);
11651165 else
11661166 ret = at91_adc_probe_pdata(st, pdev);
11671167
@@ -1300,11 +1300,11 @@ static int at91_adc_probe(struct platform_device *pdev) · 132 unmodified lines
13001300 goto error_disable_adc_clk;
13011301 }
13021302 } else {
1303− ret = at91_ts_register(st, pdev);
1303+ ret = at91_ts_register(idev, pdev);
13041304 if (ret)
13051305 goto error_disable_adc_clk;
13061306
1307− at91_ts_hw_init(st, adc_clk_khz);
1307+ at91_ts_hw_init(idev, adc_clk_khz);
13081308 }
13091309
13101310 ret = iio_device_register(idev);