Add support for STM32F4 Digital to Analog Converter variant into
existing STM32 DAC driver.
Introduce compatible associated with configuration data.
BTW, fix error message in driver probe (minor).
Fabrice Gasnier (4):
dt-bindings: iio: stm32-dac: add support for STM32F4
iio: dac: stm32: fix error message
iio: dac: stm32: add support for stm32f4
ARM: dts: stm32: Add DAC support on stm32f429
.../devicetree/bindings/iio/dac/st,stm32-dac.txt | 4 ++-
arch/arm/boot/dts/stm32f429.dtsi | 25 ++++++++++++++
drivers/iio/dac/stm32-dac-core.c | 38 ++++++++++++++++++----
drivers/iio/dac/stm32-dac.c | 2 +-
4 files changed, 60 insertions(+), 9 deletions(-)
--
1.9.1
Introduce new compatible to support STM32F4 DAC (Digital-To-Analog
converter) variant.
Signed-off-by: Fabrice Gasnier <[email protected]>
---
Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
index bcee71f..bf2925c 100644
--- a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
+++ b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
@@ -10,7 +10,9 @@ current.
Contents of a stm32 dac root node:
-----------------------------------
Required properties:
-- compatible: Must be "st,stm32h7-dac-core".
+- compatible: Should be one of:
+ "st,stm32f4-dac-core"
+ "st,stm32h7-dac-core"
- reg: Offset and length of the device's register set.
- clocks: Must contain an entry for pclk (which feeds the peripheral bus
interface)
--
1.9.1
Fix error message, there's no 'st,dac-channel' property, but 'reg'
(see https://lkml.org/lkml/2017/4/3/567).
Signed-off-by: Fabrice Gasnier <[email protected]>
---
drivers/iio/dac/stm32-dac.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
index 50f8ec0..c1864e8 100644
--- a/drivers/iio/dac/stm32-dac.c
+++ b/drivers/iio/dac/stm32-dac.c
@@ -268,7 +268,7 @@ static int stm32_dac_chan_of_init(struct iio_dev *indio_dev)
break;
}
if (i >= ARRAY_SIZE(stm32_dac_channels)) {
- dev_err(&indio_dev->dev, "Invalid st,dac-channel\n");
+ dev_err(&indio_dev->dev, "Invalid reg property\n");
return -EINVAL;
}
--
1.9.1
Add support for DAC (Digital to Analog Converter) to STM32F429.
STM32F429 DAC has two output channels.
Signed-off-by: Fabrice Gasnier <[email protected]>
---
arch/arm/boot/dts/stm32f429.dtsi | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
index b2a2b5c..f15f633 100644
--- a/arch/arm/boot/dts/stm32f429.dtsi
+++ b/arch/arm/boot/dts/stm32f429.dtsi
@@ -354,6 +354,31 @@
status = "disabled";
};
+ dac: dac@40007400 {
+ compatible = "st,stm32f4-dac-core";
+ reg = <0x40007400 0x400>;
+ resets = <&rcc STM32F4_APB1_RESET(DAC)>;
+ clocks = <&rcc 0 STM32F4_APB1_CLOCK(DAC)>;
+ clock-names = "pclk";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+
+ dac1: dac@1 {
+ compatible = "st,stm32-dac";
+ #io-channels-cells = <1>;
+ reg = <1>;
+ status = "disabled";
+ };
+
+ dac2: dac@2 {
+ compatible = "st,stm32-dac";
+ #io-channels-cells = <1>;
+ reg = <2>;
+ status = "disabled";
+ };
+ };
+
usart7: serial@40007800 {
compatible = "st,stm32-usart", "st,stm32-uart";
reg = <0x40007800 0x400>;
--
1.9.1
This adds support for STM32F4 Digital-To-Analog converter.
Add compatible configuration data to handle hfsel (not present
in stm32f4).
Signed-off-by: Fabrice Gasnier <[email protected]>
---
drivers/iio/dac/stm32-dac-core.c | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/dac/stm32-dac-core.c b/drivers/iio/dac/stm32-dac-core.c
index 75e4878..32701be 100644
--- a/drivers/iio/dac/stm32-dac-core.c
+++ b/drivers/iio/dac/stm32-dac-core.c
@@ -42,6 +42,14 @@ struct stm32_dac_priv {
struct stm32_dac_common common;
};
+/**
+ * struct stm32_dac_cfg - DAC configuration
+ * @has_hfsel: DAC has high frequency control
+ */
+struct stm32_dac_cfg {
+ bool has_hfsel;
+};
+
static struct stm32_dac_priv *to_stm32_dac_priv(struct stm32_dac_common *com)
{
return container_of(com, struct stm32_dac_priv, common);
@@ -57,6 +65,7 @@ static struct stm32_dac_priv *to_stm32_dac_priv(struct stm32_dac_common *com)
static int stm32_dac_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ const struct stm32_dac_cfg *cfg;
struct stm32_dac_priv *priv;
struct regmap *regmap;
struct resource *res;
@@ -69,6 +78,8 @@ static int stm32_dac_probe(struct platform_device *pdev)
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
+ cfg = (const struct stm32_dac_cfg *)
+ of_match_device(dev->driver->of_match_table, dev)->data;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mmio = devm_ioremap_resource(dev, res);
@@ -121,12 +132,16 @@ static int stm32_dac_probe(struct platform_device *pdev)
reset_control_deassert(priv->rst);
}
- /* When clock speed is higher than 80MHz, set HFSEL */
- priv->common.hfsel = (clk_get_rate(priv->pclk) > 80000000UL);
- ret = regmap_update_bits(regmap, STM32_DAC_CR, STM32H7_DAC_CR_HFSEL,
- priv->common.hfsel ? STM32H7_DAC_CR_HFSEL : 0);
- if (ret)
- goto err_pclk;
+ if (cfg && cfg->has_hfsel) {
+ /* When clock speed is higher than 80MHz, set HFSEL */
+ priv->common.hfsel = (clk_get_rate(priv->pclk) > 80000000UL);
+ ret = regmap_update_bits(regmap, STM32_DAC_CR,
+ STM32H7_DAC_CR_HFSEL,
+ priv->common.hfsel ?
+ STM32H7_DAC_CR_HFSEL : 0);
+ if (ret)
+ goto err_pclk;
+ }
platform_set_drvdata(pdev, &priv->common);
@@ -158,8 +173,17 @@ static int stm32_dac_remove(struct platform_device *pdev)
return 0;
}
+static const struct stm32_dac_cfg stm32h7_dac_cfg = {
+ .has_hfsel = true,
+};
+
static const struct of_device_id stm32_dac_of_match[] = {
- { .compatible = "st,stm32h7-dac-core", },
+ {
+ .compatible = "st,stm32f4-dac-core",
+ }, {
+ .compatible = "st,stm32h7-dac-core",
+ .data = (void *)&stm32h7_dac_cfg,
+ },
{},
};
MODULE_DEVICE_TABLE(of, stm32_dac_of_match);
--
1.9.1
On Mon, 10 Jul 2017 15:23:57 +0200
Fabrice Gasnier <[email protected]> wrote:
> Introduce new compatible to support STM32F4 DAC (Digital-To-Analog
> converter) variant.
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to ignore it.
Simple addition of a supported part so, whilst welcome review
from Rob / Mark isn't really necessary I think.
Jonathan
> ---
> Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
> index bcee71f..bf2925c 100644
> --- a/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
> +++ b/Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt
> @@ -10,7 +10,9 @@ current.
> Contents of a stm32 dac root node:
> -----------------------------------
> Required properties:
> -- compatible: Must be "st,stm32h7-dac-core".
> +- compatible: Should be one of:
> + "st,stm32f4-dac-core"
> + "st,stm32h7-dac-core"
> - reg: Offset and length of the device's register set.
> - clocks: Must contain an entry for pclk (which feeds the peripheral bus
> interface)
On Mon, 10 Jul 2017 15:23:58 +0200
Fabrice Gasnier <[email protected]> wrote:
> Fix error message, there's no 'st,dac-channel' property, but 'reg'
> (see https://lkml.org/lkml/2017/4/3/567).
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
Applied.
Thanks,
Joanthan
> ---
> drivers/iio/dac/stm32-dac.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/dac/stm32-dac.c b/drivers/iio/dac/stm32-dac.c
> index 50f8ec0..c1864e8 100644
> --- a/drivers/iio/dac/stm32-dac.c
> +++ b/drivers/iio/dac/stm32-dac.c
> @@ -268,7 +268,7 @@ static int stm32_dac_chan_of_init(struct iio_dev *indio_dev)
> break;
> }
> if (i >= ARRAY_SIZE(stm32_dac_channels)) {
> - dev_err(&indio_dev->dev, "Invalid st,dac-channel\n");
> + dev_err(&indio_dev->dev, "Invalid reg property\n");
> return -EINVAL;
> }
>
On Mon, 10 Jul 2017 15:23:59 +0200
Fabrice Gasnier <[email protected]> wrote:
> This adds support for STM32F4 Digital-To-Analog converter.
> Add compatible configuration data to handle hfsel (not present
> in stm32f4).
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
Hmm. I thought for a bit on whether I wanted to see data for the other
part as well to act as documentation.
Whilst that would have been fine, I came to the conclusion this is fine
as well.
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to time out on (not sure what is going on there
at the moment but 0day has been struggling for a few days!)
Jonathan
> ---
> drivers/iio/dac/stm32-dac-core.c | 38 +++++++++++++++++++++++++++++++-------
> 1 file changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/dac/stm32-dac-core.c b/drivers/iio/dac/stm32-dac-core.c
> index 75e4878..32701be 100644
> --- a/drivers/iio/dac/stm32-dac-core.c
> +++ b/drivers/iio/dac/stm32-dac-core.c
> @@ -42,6 +42,14 @@ struct stm32_dac_priv {
> struct stm32_dac_common common;
> };
>
> +/**
> + * struct stm32_dac_cfg - DAC configuration
> + * @has_hfsel: DAC has high frequency control
> + */
> +struct stm32_dac_cfg {
> + bool has_hfsel;
> +};
> +
> static struct stm32_dac_priv *to_stm32_dac_priv(struct stm32_dac_common *com)
> {
> return container_of(com, struct stm32_dac_priv, common);
> @@ -57,6 +65,7 @@ static struct stm32_dac_priv *to_stm32_dac_priv(struct stm32_dac_common *com)
> static int stm32_dac_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> + const struct stm32_dac_cfg *cfg;
> struct stm32_dac_priv *priv;
> struct regmap *regmap;
> struct resource *res;
> @@ -69,6 +78,8 @@ static int stm32_dac_probe(struct platform_device *pdev)
> priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> if (!priv)
> return -ENOMEM;
> + cfg = (const struct stm32_dac_cfg *)
> + of_match_device(dev->driver->of_match_table, dev)->data;
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> mmio = devm_ioremap_resource(dev, res);
> @@ -121,12 +132,16 @@ static int stm32_dac_probe(struct platform_device *pdev)
> reset_control_deassert(priv->rst);
> }
>
> - /* When clock speed is higher than 80MHz, set HFSEL */
> - priv->common.hfsel = (clk_get_rate(priv->pclk) > 80000000UL);
> - ret = regmap_update_bits(regmap, STM32_DAC_CR, STM32H7_DAC_CR_HFSEL,
> - priv->common.hfsel ? STM32H7_DAC_CR_HFSEL : 0);
> - if (ret)
> - goto err_pclk;
> + if (cfg && cfg->has_hfsel) {
> + /* When clock speed is higher than 80MHz, set HFSEL */
> + priv->common.hfsel = (clk_get_rate(priv->pclk) > 80000000UL);
> + ret = regmap_update_bits(regmap, STM32_DAC_CR,
> + STM32H7_DAC_CR_HFSEL,
> + priv->common.hfsel ?
> + STM32H7_DAC_CR_HFSEL : 0);
> + if (ret)
> + goto err_pclk;
> + }
>
> platform_set_drvdata(pdev, &priv->common);
>
> @@ -158,8 +173,17 @@ static int stm32_dac_remove(struct platform_device *pdev)
> return 0;
> }
>
> +static const struct stm32_dac_cfg stm32h7_dac_cfg = {
> + .has_hfsel = true,
> +};
> +
> static const struct of_device_id stm32_dac_of_match[] = {
> - { .compatible = "st,stm32h7-dac-core", },
> + {
> + .compatible = "st,stm32f4-dac-core",
> + }, {
> + .compatible = "st,stm32h7-dac-core",
> + .data = (void *)&stm32h7_dac_cfg,
> + },
> {},
> };
> MODULE_DEVICE_TABLE(of, stm32_dac_of_match);
On Mon, 10 Jul 2017 15:24:00 +0200
Fabrice Gasnier <[email protected]> wrote:
> Add support for DAC (Digital to Analog Converter) to STM32F429.
> STM32F429 DAC has two output channels.
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
Driver support is working it's way towards mainline, though will be
next merge window now so no real rush on this one!
Acked-by: Joanthan Cameron <[email protected]>
> ---
> arch/arm/boot/dts/stm32f429.dtsi | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
> index b2a2b5c..f15f633 100644
> --- a/arch/arm/boot/dts/stm32f429.dtsi
> +++ b/arch/arm/boot/dts/stm32f429.dtsi
> @@ -354,6 +354,31 @@
> status = "disabled";
> };
>
> + dac: dac@40007400 {
> + compatible = "st,stm32f4-dac-core";
> + reg = <0x40007400 0x400>;
> + resets = <&rcc STM32F4_APB1_RESET(DAC)>;
> + clocks = <&rcc 0 STM32F4_APB1_CLOCK(DAC)>;
> + clock-names = "pclk";
> + #address-cells = <1>;
> + #size-cells = <0>;
> + status = "disabled";
> +
> + dac1: dac@1 {
> + compatible = "st,stm32-dac";
> + #io-channels-cells = <1>;
> + reg = <1>;
> + status = "disabled";
> + };
> +
> + dac2: dac@2 {
> + compatible = "st,stm32-dac";
> + #io-channels-cells = <1>;
> + reg = <2>;
> + status = "disabled";
> + };
> + };
> +
> usart7: serial@40007800 {
> compatible = "st,stm32-usart", "st,stm32-uart";
> reg = <0x40007800 0x400>;
On Mon, Jul 10, 2017 at 03:23:57PM +0200, Fabrice Gasnier wrote:
> Introduce new compatible to support STM32F4 DAC (Digital-To-Analog
> converter) variant.
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
> ---
> Documentation/devicetree/bindings/iio/dac/st,stm32-dac.txt | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Acked-by: Rob Herring <[email protected]>
Hi,
On 07/10/2017 03:24 PM, Fabrice Gasnier wrote:
> Add support for DAC (Digital to Analog Converter) to STM32F429.
> STM32F429 DAC has two output channels.
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
> ---
> arch/arm/boot/dts/stm32f429.dtsi | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
> index b2a2b5c..f15f633 100644
> --- a/arch/arm/boot/dts/stm32f429.dtsi
> +++ b/arch/arm/boot/dts/stm32f429.dtsi
> @@ -354,6 +354,31 @@
> status = "disabled";
> };
>
> + dac: dac@40007400 {
> + compatible = "st,stm32f4-dac-core";
> + reg = <0x40007400 0x400>;
> + resets = <&rcc STM32F4_APB1_RESET(DAC)>;
> + clocks = <&rcc 0 STM32F4_APB1_CLOCK(DAC)>;
> + clock-names = "pclk";
> + #address-cells = <1>;
> + #size-cells = <0>;
> + status = "disabled";
> +
> + dac1: dac@1 {
> + compatible = "st,stm32-dac";
> + #io-channels-cells = <1>;
> + reg = <1>;
> + status = "disabled";
> + };
> +
> + dac2: dac@2 {
> + compatible = "st,stm32-dac";
> + #io-channels-cells = <1>;
> + reg = <2>;
> + status = "disabled";
> + };
> + };
> +
> usart7: serial@40007800 {
> compatible = "st,stm32-usart", "st,stm32-uart";
> reg = <0x40007800 0x400>;
>
Applied on stm32-dt-for-v4.14 branch.
Thanks
Alex