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.
Unified · Split
| @@ -287,13 +287,13 @@ static void handle_adc_eoc_trigger(int irq, struct iio_dev *idev) · 286 unmodified lines | ||
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | −static int at91_ts_sample(struct at91_adc_state *st) | |
| 290 | +static int at91_ts_sample(struct iio_dev *idev) | |
| 291 | 291 | { |
| 292 | + struct at91_adc_state *st = iio_priv(idev); | |
| 292 | 293 | unsigned int xscale, yscale, reg, z1, z2; |
| 293 | 294 | unsigned int x, y, pres, xpos, ypos; |
| 294 | 295 | unsigned int rxp = 1; |
| 295 | 296 | unsigned int factor = 1000; |
| 296 | − struct iio_dev *idev = iio_priv_to_dev(st); | |
| 297 | 297 | |
| 298 | 298 | unsigned int xyz_mask_bits = st->res; |
| 299 | 299 | 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 | ||
| 449 | 449 | |
| 450 | 450 | if (status & AT91_ADC_ISR_PENS) { |
| 451 | 451 | /* validate data by pen contact */ |
| 452 | − at91_ts_sample(st); | |
| 452 | + at91_ts_sample(idev); | |
| 453 | 453 | } else { |
| 454 | 454 | /* triggered by event that is no pen contact, just read |
| 455 | 455 | * 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 | ||
| 737 | 737 | return -EINVAL; |
| 738 | 738 | } |
| 739 | 739 | |
| 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, | |
| 741 | 741 | struct platform_device *pdev) |
| 742 | 742 | { |
| 743 | − struct iio_dev *idev = iio_priv_to_dev(st); | |
| 743 | + struct at91_adc_state *st = iio_priv(idev); | |
| 744 | 744 | struct device_node *np = pdev->dev.of_node; |
| 745 | 745 | int count, i, ret = 0; |
| 746 | 746 | char *res_name, *s; |
| @@ -866,10 +866,10 @@ static int at91_adc_probe_dt_ts(struct device_node *node, · 119 unmodified lines | ||
| 866 | 866 | } |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | −static int at91_adc_probe_dt(struct at91_adc_state *st, | |
| 869 | +static int at91_adc_probe_dt(struct iio_dev *idev, | |
| 870 | 870 | struct platform_device *pdev) |
| 871 | 871 | { |
| 872 | − struct iio_dev *idev = iio_priv_to_dev(st); | |
| 872 | + struct at91_adc_state *st = iio_priv(idev); | |
| 873 | 873 | struct device_node *node = pdev->dev.of_node; |
| 874 | 874 | struct device_node *trig_node; |
| 875 | 875 | int i = 0, ret; |
| @@ -910,7 +910,7 @@ static int at91_adc_probe_dt(struct at91_adc_state *st, · 34 unmodified lines | ||
| 910 | 910 | } |
| 911 | 911 | st->vref_mv = prop; |
| 912 | 912 | |
| 913 | − ret = at91_adc_of_get_resolution(st, pdev); | |
| 913 | + ret = at91_adc_of_get_resolution(idev, pdev); | |
| 914 | 914 | if (ret) |
| 915 | 915 | goto error_ret; |
| 916 | 916 | |
| @@ -1010,9 +1010,9 @@ static void atmel_ts_close(struct input_dev *dev) · 93 unmodified lines | ||
| 1010 | 1010 | at91_adc_writel(st, AT91_ADC_IDR, AT91RL_ADC_IER_PEN); |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 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) | |
| 1014 | 1014 | { |
| 1015 | − struct iio_dev *idev = iio_priv_to_dev(st); | |
| 1015 | + struct at91_adc_state *st = iio_priv(idev); | |
| 1016 | 1016 | u32 reg = 0; |
| 1017 | 1017 | u32 tssctim = 0; |
| 1018 | 1018 | 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 | ||
| 1085 | 1085 | return 0; |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | −static int at91_ts_register(struct at91_adc_state *st, | |
| 1088 | +static int at91_ts_register(struct iio_dev *idev, | |
| 1089 | 1089 | struct platform_device *pdev) |
| 1090 | 1090 | { |
| 1091 | + struct at91_adc_state *st = iio_priv(idev); | |
| 1091 | 1092 | struct input_dev *input; |
| 1092 | − struct iio_dev *idev = iio_priv_to_dev(st); | |
| 1093 | 1093 | int ret; |
| 1094 | 1094 | |
| 1095 | 1095 | input = input_allocate_device(); |
| @@ -1161,7 +1161,7 @@ static int at91_adc_probe(struct platform_device *pdev) · 65 unmodified lines | ||
| 1161 | 1161 | st = iio_priv(idev); |
| 1162 | 1162 | |
| 1163 | 1163 | if (pdev->dev.of_node) |
| 1164 | − ret = at91_adc_probe_dt(st, pdev); | |
| 1164 | + ret = at91_adc_probe_dt(idev, pdev); | |
| 1165 | 1165 | else |
| 1166 | 1166 | ret = at91_adc_probe_pdata(st, pdev); |
| 1167 | 1167 | |
| @@ -1300,11 +1300,11 @@ static int at91_adc_probe(struct platform_device *pdev) · 132 unmodified lines | ||
| 1300 | 1300 | goto error_disable_adc_clk; |
| 1301 | 1301 | } |
| 1302 | 1302 | } else { |
| 1303 | − ret = at91_ts_register(st, pdev); | |
| 1303 | + ret = at91_ts_register(idev, pdev); | |
| 1304 | 1304 | if (ret) |
| 1305 | 1305 | goto error_disable_adc_clk; |
| 1306 | 1306 | |
| 1307 | − at91_ts_hw_init(st, adc_clk_khz); | |
| 1307 | + at91_ts_hw_init(idev, adc_clk_khz); | |
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | ret = iio_device_register(idev); |