From: Maxime Ripard <maxime.ripard@free-electrons.com> To: linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: thomas@free-electrons.com, patrice.vilchez@atmel.com, nicolas.ferre@atmel.com, plagnioj@jcrosoft.com Subject: [PATCH 6/9] IIO: AT91: Add DT support to at91_adc driver Date: Wed, 9 May 2012 11:06:03 +0200 [thread overview] Message-ID: <1336554366-16957-7-git-send-email-maxime.ripard@free-electrons.com> (raw) In-Reply-To: <1336554366-16957-1-git-send-email-maxime.ripard@free-electrons.com> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> --- .../devicetree/bindings/arm/atmel-adc.txt | 65 ++++++++++ drivers/iio/adc/at91_adc.c | 133 +++++++++++++++++++- 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/arm/atmel-adc.txt diff --git a/Documentation/devicetree/bindings/arm/atmel-adc.txt b/Documentation/devicetree/bindings/arm/atmel-adc.txt new file mode 100644 index 0000000..da2b67d --- /dev/null +++ b/Documentation/devicetree/bindings/arm/atmel-adc.txt @@ -0,0 +1,65 @@ +* AT91's Analog to Digital Converter (ADC) + +Required properties: + - compatible: Should be "atmel,at91-adc" + - reg: Should contain ADC registers location and length + - interrupts: Should contain the IRQ line for the ADC + - atmel,adc-channel-base: Address of the first channel data register + - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this + device + - atmel,adc-drdy-mask: Mask of the DRDY interruption in the ADC + - atmel,adc-num-channels: Number of channels available in the ADC + - atmel,adc-startup-time: Startup Time of the ADC in microseconds as + defined in the datasheet + - atmel,adc-status-register: Address of the Interrupt Status Register + - atmel,adc-trigger-register: Address of the Trigger Register + - atmel,adc-vref: Reference voltage in millivolts for the conversions + +Optional properties: + - atmel,adc-use-external: Boolean to enable of external triggers + +Optional trigger Nodes: + - Required properties: + * trigger-name: Name of the trigger exposed to the user + * trigger-value: Value to put in the Trigger register + to activate this trigger + - Optional properties: + * trigger-external: Is the trigger an external trigger? + +Examples: +adc0: adc@fffb0000 { + compatible = "atmel,at91-adc"; + reg = <0xfffb0000 0x100>; + interrupts = <20 4>; + atmel,adc-channel-base = <0x30>; + atmel,adc-channels-used = <0xff>; + atmel,adc-drdy-mask = <0x10000>; + atmel,adc-num-channels = <8>; + atmel,adc-startup-time = <40>; + atmel,adc-status-register = <0x1c>; + atmel,adc-trigger-register = <0x08>; + atmel,adc-use-external; + atmel,adc-vref = <3300>; + + trigger@0 { + trigger-name = "external-rising"; + trigger-value = <0x1>; + trigger-external; + }; + trigger@1 { + trigger-name = "external-falling"; + trigger-value = <0x2>; + trigger-external; + }; + + trigger@2 { + trigger-name = "external-any"; + trigger-value = <0x3>; + trigger-external; + }; + + trigger@3 { + trigger-name = "continuous"; + trigger-value = <0x6>; + }; +}; diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index febad23..35892fa 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -15,6 +15,8 @@ #include <linux/jiffies.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/sched.h> #include <linux/slab.h> @@ -416,6 +418,124 @@ static int at91_adc_read_raw(struct iio_dev *idev, return -EINVAL; } +static int at91_adc_probe_dt(struct at91_adc_state *st, + struct platform_device *pdev) +{ + struct iio_dev *idev = iio_priv_to_dev(st); + struct device_node *node = pdev->dev.of_node; + struct device_node *trig_node; + int i = 0, ret; + u32 prop; + + if (!node) + return -EINVAL; + + st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); + st->use_external = true; + + if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) { + dev_err(&idev->dev, "Missing adc-channels-used property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->channels_mask = prop; + + if (of_property_read_u32(node, "atmel,adc-num-channels", &prop)) { + dev_err(&idev->dev, "Missing adc-num-channels property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->num_channels = prop; + + if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) { + dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->startup_time = prop; + + + if (of_property_read_u32(node, "atmel,adc-vref", &prop)) { + dev_err(&idev->dev, "Missing adc-vref property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->vref_mv = prop; + + st->registers = devm_kzalloc(&idev->dev, + sizeof(struct at91_adc_reg_desc), + GFP_KERNEL); + if (!st->registers) { + dev_err(&idev->dev, "Could not allocate register memory.\n"); + ret = -ENOMEM; + goto error_ret; + } + + if (of_property_read_u32(node, "atmel,adc-channel-base", &prop)) { + dev_err(&idev->dev, "Missing adc-channel-base property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->channel_base = prop; + + if (of_property_read_u32(node, "atmel,adc-drdy-mask", &prop)) { + dev_err(&idev->dev, "Missing adc-drdy-mask property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->drdy_mask = prop; + + if (of_property_read_u32(node, "atmel,adc-status-register", &prop)) { + dev_err(&idev->dev, "Missing adc-status-register property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->status_register = prop; + + if (of_property_read_u32(node, "atmel,adc-trigger-register", &prop)) { + dev_err(&idev->dev, "Missing adc-trigger-register property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->trigger_register = prop; + + st->trigger_number = of_get_child_count(node); + st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number * + sizeof(struct at91_adc_trigger), + GFP_KERNEL); + if (!st->trigger_list) { + dev_err(&idev->dev, "Could not allocate trigger list memory.\n"); + ret = -ENOMEM; + goto error_ret; + } + + for_each_child_of_node(node, trig_node) { + struct at91_adc_trigger *trig = st->trigger_list + i; + const char* name; + + if (of_property_read_string(node, "trigger-name", &name)) { + dev_err(&idev->dev, "Missing trigger-name property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + trig->name = name; + + if (of_property_read_u32(node, "trigger-value", &prop)) { + dev_err(&idev->dev, "Missing trigger-value property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + trig->value = prop; + trig->is_external = of_property_read_bool(node, "trigger-external"); + i++; + } + + return 0; + +error_ret: + return ret; +} + static int at91_adc_probe_pdata(struct at91_adc_state *st, struct platform_device *pdev) { @@ -457,7 +577,11 @@ static int __devinit at91_adc_probe(struct platform_device *pdev) st = iio_priv(idev); - ret = at91_adc_probe_pdata(st, pdev); + if (pdev->dev.of_node) + ret = at91_adc_probe_dt(st, pdev); + else + ret = at91_adc_probe_pdata(st, pdev); + if (ret) { dev_err(&pdev->dev, "No platform data available.\n"); ret = -EINVAL; @@ -659,11 +783,18 @@ static int __devexit at91_adc_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id at91_adc_dt_ids[] = { + { .compatible = "atmel,at91sam9g20-adc" }, + {}, +}; +MODULE_DEVICE_TABLE(of, at91_adc_dt_ids); + static struct platform_driver at91_adc_driver = { .probe = at91_adc_probe, .remove = __devexit_p(at91_adc_remove), .driver = { .name = "at91_adc", + .of_match_table = of_match_ptr(at91_adc_dt_ids), }, }; -- 1.7.9.5
WARNING: multiple messages have this Message-ID (diff)
From: maxime.ripard@free-electrons.com (Maxime Ripard) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 6/9] IIO: AT91: Add DT support to at91_adc driver Date: Wed, 9 May 2012 11:06:03 +0200 [thread overview] Message-ID: <1336554366-16957-7-git-send-email-maxime.ripard@free-electrons.com> (raw) In-Reply-To: <1336554366-16957-1-git-send-email-maxime.ripard@free-electrons.com> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> --- .../devicetree/bindings/arm/atmel-adc.txt | 65 ++++++++++ drivers/iio/adc/at91_adc.c | 133 +++++++++++++++++++- 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/arm/atmel-adc.txt diff --git a/Documentation/devicetree/bindings/arm/atmel-adc.txt b/Documentation/devicetree/bindings/arm/atmel-adc.txt new file mode 100644 index 0000000..da2b67d --- /dev/null +++ b/Documentation/devicetree/bindings/arm/atmel-adc.txt @@ -0,0 +1,65 @@ +* AT91's Analog to Digital Converter (ADC) + +Required properties: + - compatible: Should be "atmel,at91-adc" + - reg: Should contain ADC registers location and length + - interrupts: Should contain the IRQ line for the ADC + - atmel,adc-channel-base: Address of the first channel data register + - atmel,adc-channels-used: Bitmask of the channels muxed and enable for this + device + - atmel,adc-drdy-mask: Mask of the DRDY interruption in the ADC + - atmel,adc-num-channels: Number of channels available in the ADC + - atmel,adc-startup-time: Startup Time of the ADC in microseconds as + defined in the datasheet + - atmel,adc-status-register: Address of the Interrupt Status Register + - atmel,adc-trigger-register: Address of the Trigger Register + - atmel,adc-vref: Reference voltage in millivolts for the conversions + +Optional properties: + - atmel,adc-use-external: Boolean to enable of external triggers + +Optional trigger Nodes: + - Required properties: + * trigger-name: Name of the trigger exposed to the user + * trigger-value: Value to put in the Trigger register + to activate this trigger + - Optional properties: + * trigger-external: Is the trigger an external trigger? + +Examples: +adc0: adc at fffb0000 { + compatible = "atmel,at91-adc"; + reg = <0xfffb0000 0x100>; + interrupts = <20 4>; + atmel,adc-channel-base = <0x30>; + atmel,adc-channels-used = <0xff>; + atmel,adc-drdy-mask = <0x10000>; + atmel,adc-num-channels = <8>; + atmel,adc-startup-time = <40>; + atmel,adc-status-register = <0x1c>; + atmel,adc-trigger-register = <0x08>; + atmel,adc-use-external; + atmel,adc-vref = <3300>; + + trigger at 0 { + trigger-name = "external-rising"; + trigger-value = <0x1>; + trigger-external; + }; + trigger at 1 { + trigger-name = "external-falling"; + trigger-value = <0x2>; + trigger-external; + }; + + trigger at 2 { + trigger-name = "external-any"; + trigger-value = <0x3>; + trigger-external; + }; + + trigger at 3 { + trigger-name = "continuous"; + trigger-value = <0x6>; + }; +}; diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index febad23..35892fa 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c @@ -15,6 +15,8 @@ #include <linux/jiffies.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/sched.h> #include <linux/slab.h> @@ -416,6 +418,124 @@ static int at91_adc_read_raw(struct iio_dev *idev, return -EINVAL; } +static int at91_adc_probe_dt(struct at91_adc_state *st, + struct platform_device *pdev) +{ + struct iio_dev *idev = iio_priv_to_dev(st); + struct device_node *node = pdev->dev.of_node; + struct device_node *trig_node; + int i = 0, ret; + u32 prop; + + if (!node) + return -EINVAL; + + st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers"); + st->use_external = true; + + if (of_property_read_u32(node, "atmel,adc-channels-used", &prop)) { + dev_err(&idev->dev, "Missing adc-channels-used property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->channels_mask = prop; + + if (of_property_read_u32(node, "atmel,adc-num-channels", &prop)) { + dev_err(&idev->dev, "Missing adc-num-channels property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->num_channels = prop; + + if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) { + dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->startup_time = prop; + + + if (of_property_read_u32(node, "atmel,adc-vref", &prop)) { + dev_err(&idev->dev, "Missing adc-vref property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->vref_mv = prop; + + st->registers = devm_kzalloc(&idev->dev, + sizeof(struct at91_adc_reg_desc), + GFP_KERNEL); + if (!st->registers) { + dev_err(&idev->dev, "Could not allocate register memory.\n"); + ret = -ENOMEM; + goto error_ret; + } + + if (of_property_read_u32(node, "atmel,adc-channel-base", &prop)) { + dev_err(&idev->dev, "Missing adc-channel-base property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->channel_base = prop; + + if (of_property_read_u32(node, "atmel,adc-drdy-mask", &prop)) { + dev_err(&idev->dev, "Missing adc-drdy-mask property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->drdy_mask = prop; + + if (of_property_read_u32(node, "atmel,adc-status-register", &prop)) { + dev_err(&idev->dev, "Missing adc-status-register property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->status_register = prop; + + if (of_property_read_u32(node, "atmel,adc-trigger-register", &prop)) { + dev_err(&idev->dev, "Missing adc-trigger-register property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + st->registers->trigger_register = prop; + + st->trigger_number = of_get_child_count(node); + st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number * + sizeof(struct at91_adc_trigger), + GFP_KERNEL); + if (!st->trigger_list) { + dev_err(&idev->dev, "Could not allocate trigger list memory.\n"); + ret = -ENOMEM; + goto error_ret; + } + + for_each_child_of_node(node, trig_node) { + struct at91_adc_trigger *trig = st->trigger_list + i; + const char* name; + + if (of_property_read_string(node, "trigger-name", &name)) { + dev_err(&idev->dev, "Missing trigger-name property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + trig->name = name; + + if (of_property_read_u32(node, "trigger-value", &prop)) { + dev_err(&idev->dev, "Missing trigger-value property in the DT.\n"); + ret = -EINVAL; + goto error_ret; + } + trig->value = prop; + trig->is_external = of_property_read_bool(node, "trigger-external"); + i++; + } + + return 0; + +error_ret: + return ret; +} + static int at91_adc_probe_pdata(struct at91_adc_state *st, struct platform_device *pdev) { @@ -457,7 +577,11 @@ static int __devinit at91_adc_probe(struct platform_device *pdev) st = iio_priv(idev); - ret = at91_adc_probe_pdata(st, pdev); + if (pdev->dev.of_node) + ret = at91_adc_probe_dt(st, pdev); + else + ret = at91_adc_probe_pdata(st, pdev); + if (ret) { dev_err(&pdev->dev, "No platform data available.\n"); ret = -EINVAL; @@ -659,11 +783,18 @@ static int __devexit at91_adc_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id at91_adc_dt_ids[] = { + { .compatible = "atmel,at91sam9g20-adc" }, + {}, +}; +MODULE_DEVICE_TABLE(of, at91_adc_dt_ids); + static struct platform_driver at91_adc_driver = { .probe = at91_adc_probe, .remove = __devexit_p(at91_adc_remove), .driver = { .name = "at91_adc", + .of_match_table = of_match_ptr(at91_adc_dt_ids), }, }; -- 1.7.9.5
next prev parent reply other threads:[~2012-05-09 9:06 UTC|newest] Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-05-09 9:05 [PATCHv3] Add ADC driver for Atmel G20, G45 and X5 boards Maxime Ripard 2012-05-09 9:05 ` Maxime Ripard 2012-05-09 9:05 ` [PATCH 1/9] ARM: AT91: Add platform data for the AT91 ADCs Maxime Ripard 2012-05-09 9:05 ` Maxime Ripard 2012-05-09 13:04 ` Jonathan Cameron 2012-05-09 13:04 ` Jonathan Cameron 2012-05-09 9:05 ` [PATCH 2/9] ARM: AT91: IIO: Add AT91 ADC driver Maxime Ripard 2012-05-09 9:05 ` Maxime Ripard 2012-05-09 9:06 ` [PATCH 3/9] ARM: AT91: Add the ADC to the sam9g20ek board Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard 2012-05-09 9:06 ` [PATCH 4/9] IIO: AT91: ADC: Add support for the AT91SAM9M10G45-EK board Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard 2012-05-09 9:06 ` [PATCH 5/9] Add clocks for X5 boards Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard [this message] 2012-05-09 9:06 ` [PATCH 6/9] IIO: AT91: Add DT support to at91_adc driver Maxime Ripard 2012-05-09 9:06 ` [PATCH 7/9] Add ADC driver to the at91sam9g45 dtsi Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard 2012-05-09 9:06 ` [PATCH 8/9] Add ADC driver to the at91sam9x5 dtsi Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard 2012-05-09 9:06 ` [PATCH 9/9] Add DTSI for the G20 SoC Maxime Ripard 2012-05-09 9:06 ` Maxime Ripard 2012-05-09 14:18 ` [PATCHv3] Add ADC driver for Atmel G20, G45 and X5 boards Nicolas Ferre 2012-05-09 14:18 ` Nicolas Ferre 2012-05-09 14:46 ` Arnd Bergmann 2012-05-09 14:46 ` Arnd Bergmann 2012-05-09 14:40 ` Arnd Bergmann 2012-05-09 14:40 ` Arnd Bergmann 2012-05-10 8:32 ` Maxime Ripard 2012-05-10 8:32 ` Maxime Ripard 2012-05-10 8:50 ` Nicolas Ferre 2012-05-10 8:50 ` Nicolas Ferre 2012-05-10 13:28 ` Arnd Bergmann 2012-05-10 13:28 ` Arnd Bergmann 2012-05-11 7:54 ` Maxime Ripard 2012-05-11 7:54 ` Maxime Ripard 2012-05-11 12:26 ` Jonathan Cameron 2012-05-11 12:26 ` Jonathan Cameron 2012-05-09 13:01 [PATCHv4] " Maxime Ripard 2012-05-09 13:02 ` [PATCH 6/9] IIO: AT91: Add DT support to at91_adc driver Maxime Ripard 2012-05-09 13:02 ` Maxime Ripard 2012-05-10 8:04 ` Jonathan Cameron 2012-05-10 8:04 ` Jonathan Cameron 2012-05-11 13:35 [PATCHv5] Add ADC driver for Atmel G20, G45 and X5 boards Maxime Ripard 2012-05-11 13:35 ` [PATCH 6/9] IIO: AT91: Add DT support to at91_adc driver Maxime Ripard 2012-05-11 13:35 ` Maxime Ripard
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=1336554366-16957-7-git-send-email-maxime.ripard@free-electrons.com \ --to=maxime.ripard@free-electrons.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-iio@vger.kernel.org \ --cc=nicolas.ferre@atmel.com \ --cc=patrice.vilchez@atmel.com \ --cc=plagnioj@jcrosoft.com \ --cc=thomas@free-electrons.com \ /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.