From 3a069904282d621fc65ec37713f41f69ba63645f Mon Sep 17 00:00:00 2001 From: Fabrice Gasnier Date: Wed, 18 Oct 2017 13:39:27 +0200 Subject: iio: adc: stm32: add tim15 trigger Add TIM15_TRGO trigger that is now supported on STM32H7. Signed-off-by: Fabrice Gasnier Signed-off-by: Jonathan Cameron --- drivers/iio/adc/stm32-adc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/iio/adc') diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index 8b7c24780a8a..c9d96f935dba 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -531,6 +531,7 @@ static struct stm32_adc_trig_info stm32h7_adc_trigs[] = { { TIM2_TRGO, STM32_EXT11 }, { TIM4_TRGO, STM32_EXT12 }, { TIM6_TRGO, STM32_EXT13 }, + { TIM15_TRGO, STM32_EXT14 }, { TIM3_CH4, STM32_EXT15 }, { LPTIM1_OUT, STM32_EXT18 }, { LPTIM2_OUT, STM32_EXT19 }, -- cgit v1.2.3 From f66f18e99a253f5cf8c1cf7f2910b7ddcee92970 Mon Sep 17 00:00:00 2001 From: Fabrice Gasnier Date: Wed, 18 Oct 2017 13:40:12 +0200 Subject: iio: adc: stm32: add check on clock rate Add check on STM32 ADC clock rate to report an explicit error. This may avoid division by 0 later in stm32-adc driver. Signed-off-by: Fabrice Gasnier Signed-off-by: Jonathan Cameron --- drivers/iio/adc/stm32-adc-core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'drivers/iio/adc') diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c index 804198eb0eef..6aefef99f935 100644 --- a/drivers/iio/adc/stm32-adc-core.c +++ b/drivers/iio/adc/stm32-adc-core.c @@ -139,6 +139,11 @@ static int stm32f4_adc_clk_sel(struct platform_device *pdev, } rate = clk_get_rate(priv->aclk); + if (!rate) { + dev_err(&pdev->dev, "Invalid clock rate: 0\n"); + return -EINVAL; + } + for (i = 0; i < ARRAY_SIZE(stm32f4_pclk_div); i++) { if ((rate / stm32f4_pclk_div[i]) <= STM32F4_ADC_MAX_CLK_RATE) break; @@ -216,6 +221,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, * From spec: PLL output musn't exceed max rate */ rate = clk_get_rate(priv->aclk); + if (!rate) { + dev_err(&pdev->dev, "Invalid adc clock rate: 0\n"); + return -EINVAL; + } for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) { ckmode = stm32h7_adc_ckmodes_spec[i].ckmode; @@ -232,6 +241,10 @@ static int stm32h7_adc_clk_sel(struct platform_device *pdev, /* Synchronous clock modes (e.g. ckmode is 1, 2 or 3) */ rate = clk_get_rate(priv->bclk); + if (!rate) { + dev_err(&pdev->dev, "Invalid bus clock rate: 0\n"); + return -EINVAL; + } for (i = 0; i < ARRAY_SIZE(stm32h7_adc_ckmodes_spec); i++) { ckmode = stm32h7_adc_ckmodes_spec[i].ckmode; -- cgit v1.2.3 From 59dba8facb4ba20ffa6b6a1c76c41f3c662e075a Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 19 Oct 2017 15:46:22 +0200 Subject: iio: adc: adc12138: make array ch_to_mux static, makes object code smaller Don't populate const array ch_to_mux on the stack, instead make it static. Makes the object code smaller by over 200 bytes: Before: text data bss dec hex filename 12663 1648 128 14439 3867 drivers/iio/adc/ti-adc12138.o After text data bss dec hex filename 12353 1744 128 14225 3791 drivers/iio/adc/ti-adc12138.o (gcc version 7.2.0 x86_64) Signed-off-by: Colin Ian King Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-adc12138.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/iio/adc') diff --git a/drivers/iio/adc/ti-adc12138.c b/drivers/iio/adc/ti-adc12138.c index bf890244789a..703d68ae96b7 100644 --- a/drivers/iio/adc/ti-adc12138.c +++ b/drivers/iio/adc/ti-adc12138.c @@ -164,7 +164,7 @@ static int __adc12138_start_conv(struct adc12138 *adc, void *data, int len) { - const u8 ch_to_mux[] = { 0, 4, 1, 5, 2, 6, 3, 7 }; + static const u8 ch_to_mux[] = { 0, 4, 1, 5, 2, 6, 3, 7 }; u8 mode = (ch_to_mux[channel->channel] << 4) | (channel->differential ? 0 : 0x80); -- cgit v1.2.3 From 0d87a4aa376983a205b3920dc7a9b15d74110be9 Mon Sep 17 00:00:00 2001 From: Corentin Labbe Date: Fri, 20 Oct 2017 07:37:29 +0200 Subject: iio: adc: sun4i-gpadc: use of_device_get_match_data The usage of of_device_get_match_data reduce the code size a bit. Furthermore, it prevents an improbable dereference when of_match_device() return NULL. Signed-off-by: Corentin Labbe Signed-off-by: Jonathan Cameron --- drivers/iio/adc/sun4i-gpadc-iio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/iio/adc') diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index c4e70f1cad79..04d7147e0110 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -501,17 +501,15 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, struct iio_dev *indio_dev) { struct sun4i_gpadc_iio *info = iio_priv(indio_dev); - const struct of_device_id *of_dev; struct resource *mem; void __iomem *base; int ret; - of_dev = of_match_device(sun4i_gpadc_of_id, &pdev->dev); - if (!of_dev) + info->data = of_device_get_match_data(&pdev->dev); + if (!info->data) return -ENODEV; info->no_irq = true; - info->data = (struct gpadc_data *)of_dev->data; indio_dev->num_channels = ARRAY_SIZE(sun8i_a33_gpadc_channels); indio_dev->channels = sun8i_a33_gpadc_channels; -- cgit v1.2.3