From: Evgeny Boger <boger@wirenboard.com> To: Chen-Yu Tsai <wens@csie.org>, linux-sunxi@lists.linux.dev, Maxime Ripard <mripard@kernel.org> Cc: Evgeny Boger <boger@wirenboard.com>, Lee Jones <lee.jones@linaro.org>, Rob Herring <robh+dt@kernel.org>, devicetree@vger.kernel.org, Jernej Skrabec <jernej.skrabec@gmail.com>, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] iio: adc: sun4i-gpadc-iio: no temp sensor on R40 Date: Fri, 19 Nov 2021 22:14:54 +0300 [thread overview] Message-ID: <20211119191456.510435-2-boger@wirenboard.com> (raw) In-Reply-To: <20211119191456.510435-1-boger@wirenboard.com> R40 SoC has touchscreen controller also serving as general-purpose ADC. The hardware is very similar to A31, except that R40 has separate calibrated thermal sensor IP (handled by sun8i_thermal). Despite the temperature sensor in the RTP is never mentioned in the R40 family user manuals, it appears to be working. However, it's not very useful as it lacks calibration data and there is another fully functioning temperature sensor anyway. This patch disables the temperature sensor in RTP/GPADC IP on R40. The reason for disabling the temperature sensor is that the IP needs to be switched back and forth between RTP and GPADC modes for temperature measurements. Not only this introduces delays, but it also disturbs external circuitry by injecting current into ADC inputs. Signed-off-by: Evgeny Boger <boger@wirenboard.com> --- drivers/iio/adc/sun4i-gpadc-iio.c | 32 +++++++++++++++++++++++-------- drivers/mfd/sun4i-gpadc.c | 17 ++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 2d393a4dfff6..e63a45c092ab 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -53,6 +53,7 @@ struct gpadc_data { unsigned int tp_adc_select; unsigned int (*adc_chan_select)(unsigned int chan); unsigned int adc_chan_mask; + bool has_temp_sensor; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -62,6 +63,7 @@ static const struct gpadc_data sun4i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = true, }; static const struct gpadc_data sun5i_gpadc_data = { @@ -71,6 +73,7 @@ static const struct gpadc_data sun5i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = true, }; static const struct gpadc_data sun6i_gpadc_data = { @@ -80,12 +83,24 @@ static const struct gpadc_data sun6i_gpadc_data = { .tp_adc_select = SUN6I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun6i_gpadc_chan_select, .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = true, +}; + +static const struct gpadc_data sun8i_r40_gpadc_data = { + .temp_offset = -1623, + .temp_scale = 167, + .tp_mode_en = SUN6I_GPADC_CTRL1_TP_MODE_EN, + .tp_adc_select = SUN6I_GPADC_CTRL1_TP_ADC_SELECT, + .adc_chan_select = &sun6i_gpadc_chan_select, + .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = false, }; static const struct gpadc_data sun8i_a33_gpadc_data = { .temp_offset = -1662, .temp_scale = 162, .tp_mode_en = SUN8I_GPADC_CTRL1_CHOP_TEMP_EN, + .has_temp_sensor = true, }; struct sun4i_gpadc_iio { @@ -499,7 +514,7 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, void __iomem *base; int ret; - info->data = of_device_get_match_data(&pdev->dev); + info->data = (struct gpadc_data *)of_device_get_match_data(&pdev->dev); if (!info->data) return -ENODEV; @@ -519,7 +534,7 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, return ret; } - if (IS_ENABLED(CONFIG_THERMAL_OF)) + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) info->sensor_device = &pdev->dev; return 0; @@ -552,7 +567,7 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, * that choice to the user. */ - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { /* * This driver is a child of an MFD which has a node in the DT * but not its children, because of DT backward compatibility @@ -575,7 +590,7 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, indio_dev->channels = sun4i_gpadc_channels_no_temp; } - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { ret = sun4i_irq_init(pdev, "TEMP_DATA_PENDING", sun4i_gpadc_temp_data_irq_handler, "temp_data", &info->temp_data_irq, @@ -590,7 +605,7 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, if (ret < 0) return ret; - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { ret = iio_map_array_register(indio_dev, sun4i_gpadc_hwmon_maps); if (ret < 0) { dev_err(&pdev->dev, @@ -636,7 +651,7 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) pm_runtime_set_suspended(&pdev->dev); pm_runtime_enable(&pdev->dev); - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { info->tzd = thermal_zone_of_sensor_register(info->sensor_device, 0, info, &sun4i_ts_tz_ops); @@ -661,7 +676,7 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) return 0; err_map: - if (!info->no_irq && IS_ENABLED(CONFIG_THERMAL_OF)) + if (!info->no_irq && IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) iio_map_array_unregister(indio_dev); pm_runtime_put(&pdev->dev); @@ -678,7 +693,7 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); - if (!IS_ENABLED(CONFIG_THERMAL_OF)) + if (!IS_ENABLED(CONFIG_THERMAL_OF) || !info->data->has_temp_sensor) return 0; thermal_zone_of_sensor_unregister(info->sensor_device, info->tzd); @@ -693,6 +708,7 @@ static const struct platform_device_id sun4i_gpadc_id[] = { { "sun4i-a10-gpadc-iio", (kernel_ulong_t)&sun4i_gpadc_data }, { "sun5i-a13-gpadc-iio", (kernel_ulong_t)&sun5i_gpadc_data }, { "sun6i-a31-gpadc-iio", (kernel_ulong_t)&sun6i_gpadc_data }, + { "sun8i-r40-gpadc-iio", (kernel_ulong_t)&sun8i_r40_gpadc_data }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(platform, sun4i_gpadc_id); diff --git a/drivers/mfd/sun4i-gpadc.c b/drivers/mfd/sun4i-gpadc.c index cfe14d9bf6dc..293acad52e5a 100644 --- a/drivers/mfd/sun4i-gpadc.c +++ b/drivers/mfd/sun4i-gpadc.c @@ -17,6 +17,7 @@ #define ARCH_SUN4I_A10 0 #define ARCH_SUN5I_A13 1 #define ARCH_SUN6I_A31 2 +#define ARCH_SUN8I_R40 3 static const struct resource adc_resources[] = { DEFINE_RES_IRQ_NAMED(SUN4I_GPADC_IRQ_FIFO_DATA, "FIFO_DATA_PENDING"), @@ -69,6 +70,15 @@ static struct mfd_cell sun6i_gpadc_cells[] = { { .name = "iio_hwmon" }, }; +static struct mfd_cell sun8i_r40_gpadc_cells[] = { + { + .name = "sun8i-r40-gpadc-iio", + .resources = adc_resources, + .num_resources = ARRAY_SIZE(adc_resources), + }, + { .name = "iio_hwmon" }, +}; + static const struct regmap_config sun4i_gpadc_regmap_config = { .reg_bits = 32, .val_bits = 32, @@ -86,6 +96,9 @@ static const struct of_device_id sun4i_gpadc_of_match[] = { }, { .compatible = "allwinner,sun6i-a31-ts", .data = (void *)ARCH_SUN6I_A31, + }, { + .compatible = "allwinner,sun8i-r40-ts", + .data = (void *)ARCH_SUN8I_R40, }, { /* sentinel */ } }; @@ -117,6 +130,10 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) cells = sun6i_gpadc_cells; size = ARRAY_SIZE(sun6i_gpadc_cells); break; + case ARCH_SUN8I_R40: + cells = sun8i_r40_gpadc_cells; + size = ARRAY_SIZE(sun8i_r40_gpadc_cells); + break; default: return -EINVAL; } -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Evgeny Boger <boger@wirenboard.com> To: Chen-Yu Tsai <wens@csie.org>, linux-sunxi@lists.linux.dev, Maxime Ripard <mripard@kernel.org> Cc: Evgeny Boger <boger@wirenboard.com>, Lee Jones <lee.jones@linaro.org>, Rob Herring <robh+dt@kernel.org>, devicetree@vger.kernel.org, Jernej Skrabec <jernej.skrabec@gmail.com>, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] iio: adc: sun4i-gpadc-iio: no temp sensor on R40 Date: Fri, 19 Nov 2021 22:14:54 +0300 [thread overview] Message-ID: <20211119191456.510435-2-boger@wirenboard.com> (raw) In-Reply-To: <20211119191456.510435-1-boger@wirenboard.com> R40 SoC has touchscreen controller also serving as general-purpose ADC. The hardware is very similar to A31, except that R40 has separate calibrated thermal sensor IP (handled by sun8i_thermal). Despite the temperature sensor in the RTP is never mentioned in the R40 family user manuals, it appears to be working. However, it's not very useful as it lacks calibration data and there is another fully functioning temperature sensor anyway. This patch disables the temperature sensor in RTP/GPADC IP on R40. The reason for disabling the temperature sensor is that the IP needs to be switched back and forth between RTP and GPADC modes for temperature measurements. Not only this introduces delays, but it also disturbs external circuitry by injecting current into ADC inputs. Signed-off-by: Evgeny Boger <boger@wirenboard.com> --- drivers/iio/adc/sun4i-gpadc-iio.c | 32 +++++++++++++++++++++++-------- drivers/mfd/sun4i-gpadc.c | 17 ++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index 2d393a4dfff6..e63a45c092ab 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -53,6 +53,7 @@ struct gpadc_data { unsigned int tp_adc_select; unsigned int (*adc_chan_select)(unsigned int chan); unsigned int adc_chan_mask; + bool has_temp_sensor; }; static const struct gpadc_data sun4i_gpadc_data = { @@ -62,6 +63,7 @@ static const struct gpadc_data sun4i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = true, }; static const struct gpadc_data sun5i_gpadc_data = { @@ -71,6 +73,7 @@ static const struct gpadc_data sun5i_gpadc_data = { .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun4i_gpadc_chan_select, .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = true, }; static const struct gpadc_data sun6i_gpadc_data = { @@ -80,12 +83,24 @@ static const struct gpadc_data sun6i_gpadc_data = { .tp_adc_select = SUN6I_GPADC_CTRL1_TP_ADC_SELECT, .adc_chan_select = &sun6i_gpadc_chan_select, .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = true, +}; + +static const struct gpadc_data sun8i_r40_gpadc_data = { + .temp_offset = -1623, + .temp_scale = 167, + .tp_mode_en = SUN6I_GPADC_CTRL1_TP_MODE_EN, + .tp_adc_select = SUN6I_GPADC_CTRL1_TP_ADC_SELECT, + .adc_chan_select = &sun6i_gpadc_chan_select, + .adc_chan_mask = SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, + .has_temp_sensor = false, }; static const struct gpadc_data sun8i_a33_gpadc_data = { .temp_offset = -1662, .temp_scale = 162, .tp_mode_en = SUN8I_GPADC_CTRL1_CHOP_TEMP_EN, + .has_temp_sensor = true, }; struct sun4i_gpadc_iio { @@ -499,7 +514,7 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, void __iomem *base; int ret; - info->data = of_device_get_match_data(&pdev->dev); + info->data = (struct gpadc_data *)of_device_get_match_data(&pdev->dev); if (!info->data) return -ENODEV; @@ -519,7 +534,7 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, return ret; } - if (IS_ENABLED(CONFIG_THERMAL_OF)) + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) info->sensor_device = &pdev->dev; return 0; @@ -552,7 +567,7 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, * that choice to the user. */ - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { /* * This driver is a child of an MFD which has a node in the DT * but not its children, because of DT backward compatibility @@ -575,7 +590,7 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, indio_dev->channels = sun4i_gpadc_channels_no_temp; } - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { ret = sun4i_irq_init(pdev, "TEMP_DATA_PENDING", sun4i_gpadc_temp_data_irq_handler, "temp_data", &info->temp_data_irq, @@ -590,7 +605,7 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, if (ret < 0) return ret; - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { ret = iio_map_array_register(indio_dev, sun4i_gpadc_hwmon_maps); if (ret < 0) { dev_err(&pdev->dev, @@ -636,7 +651,7 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) pm_runtime_set_suspended(&pdev->dev); pm_runtime_enable(&pdev->dev); - if (IS_ENABLED(CONFIG_THERMAL_OF)) { + if (IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) { info->tzd = thermal_zone_of_sensor_register(info->sensor_device, 0, info, &sun4i_ts_tz_ops); @@ -661,7 +676,7 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) return 0; err_map: - if (!info->no_irq && IS_ENABLED(CONFIG_THERMAL_OF)) + if (!info->no_irq && IS_ENABLED(CONFIG_THERMAL_OF) && info->data->has_temp_sensor) iio_map_array_unregister(indio_dev); pm_runtime_put(&pdev->dev); @@ -678,7 +693,7 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); - if (!IS_ENABLED(CONFIG_THERMAL_OF)) + if (!IS_ENABLED(CONFIG_THERMAL_OF) || !info->data->has_temp_sensor) return 0; thermal_zone_of_sensor_unregister(info->sensor_device, info->tzd); @@ -693,6 +708,7 @@ static const struct platform_device_id sun4i_gpadc_id[] = { { "sun4i-a10-gpadc-iio", (kernel_ulong_t)&sun4i_gpadc_data }, { "sun5i-a13-gpadc-iio", (kernel_ulong_t)&sun5i_gpadc_data }, { "sun6i-a31-gpadc-iio", (kernel_ulong_t)&sun6i_gpadc_data }, + { "sun8i-r40-gpadc-iio", (kernel_ulong_t)&sun8i_r40_gpadc_data }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(platform, sun4i_gpadc_id); diff --git a/drivers/mfd/sun4i-gpadc.c b/drivers/mfd/sun4i-gpadc.c index cfe14d9bf6dc..293acad52e5a 100644 --- a/drivers/mfd/sun4i-gpadc.c +++ b/drivers/mfd/sun4i-gpadc.c @@ -17,6 +17,7 @@ #define ARCH_SUN4I_A10 0 #define ARCH_SUN5I_A13 1 #define ARCH_SUN6I_A31 2 +#define ARCH_SUN8I_R40 3 static const struct resource adc_resources[] = { DEFINE_RES_IRQ_NAMED(SUN4I_GPADC_IRQ_FIFO_DATA, "FIFO_DATA_PENDING"), @@ -69,6 +70,15 @@ static struct mfd_cell sun6i_gpadc_cells[] = { { .name = "iio_hwmon" }, }; +static struct mfd_cell sun8i_r40_gpadc_cells[] = { + { + .name = "sun8i-r40-gpadc-iio", + .resources = adc_resources, + .num_resources = ARRAY_SIZE(adc_resources), + }, + { .name = "iio_hwmon" }, +}; + static const struct regmap_config sun4i_gpadc_regmap_config = { .reg_bits = 32, .val_bits = 32, @@ -86,6 +96,9 @@ static const struct of_device_id sun4i_gpadc_of_match[] = { }, { .compatible = "allwinner,sun6i-a31-ts", .data = (void *)ARCH_SUN6I_A31, + }, { + .compatible = "allwinner,sun8i-r40-ts", + .data = (void *)ARCH_SUN8I_R40, }, { /* sentinel */ } }; @@ -117,6 +130,10 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) cells = sun6i_gpadc_cells; size = ARRAY_SIZE(sun6i_gpadc_cells); break; + case ARCH_SUN8I_R40: + cells = sun8i_r40_gpadc_cells; + size = ARRAY_SIZE(sun8i_r40_gpadc_cells); + break; default: return -EINVAL; } -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-11-19 19:15 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-19 19:14 [PATCH 0/3] Enable RTP (GPADC) controller on Allwinner R40 Evgeny Boger 2021-11-19 19:14 ` Evgeny Boger 2021-11-19 19:14 ` Evgeny Boger [this message] 2021-11-19 19:14 ` [PATCH 1/3] iio: adc: sun4i-gpadc-iio: no temp sensor on R40 Evgeny Boger 2021-11-22 9:11 ` Maxime Ripard 2021-11-22 9:11 ` Maxime Ripard 2021-11-22 12:41 ` Jonathan Cameron 2021-11-22 12:41 ` Jonathan Cameron 2022-01-11 13:13 ` Evgeny Boger 2022-01-11 13:13 ` Evgeny Boger 2022-01-15 15:41 ` Jonathan Cameron 2022-01-15 15:41 ` Jonathan Cameron 2022-01-17 9:00 ` Lee Jones 2022-01-17 9:00 ` Lee Jones 2021-11-19 19:14 ` [PATCH 2/3] dt-bindings: iio: adc: new compatible for Allwinner R40 RTP controller Evgeny Boger 2021-11-19 19:14 ` Evgeny Boger 2021-11-22 9:10 ` Maxime Ripard 2021-11-22 9:10 ` Maxime Ripard 2021-11-30 1:46 ` Rob Herring 2021-11-30 1:46 ` Rob Herring 2021-11-19 19:14 ` [PATCH 3/3] ARM: dts: sun8i: r40: add rtp node Evgeny Boger 2021-11-19 19:14 ` Evgeny Boger
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211119191456.510435-2-boger@wirenboard.com \ --to=boger@wirenboard.com \ --cc=devicetree@vger.kernel.org \ --cc=jernej.skrabec@gmail.com \ --cc=lee.jones@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-sunxi@lists.linux.dev \ --cc=mripard@kernel.org \ --cc=robh+dt@kernel.org \ --cc=wens@csie.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.