From: nicolas.ferre@atmel.com (Nicolas Ferre)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 06/12] at91: smc: Adds helper functions to validate and clip the smc timings.
Date: Wed, 15 Jan 2014 10:44:32 +0100 [thread overview]
Message-ID: <52D65880.10301@atmel.com> (raw)
In-Reply-To: <1389270709-32662-7-git-send-email-jjhiblot@traphandler.com>
On 09/01/2014 13:31, Jean-Jacques Hiblot :
> This patchs implememnts 2 functions to help with the configuration of a
> chip-select's timing:
> * sam9_smc_check_cs_configuration : checks that the values would fit in the
> registers.
> * sam9_smc_clip_cs_configuration : clip the values to their maximum.
>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
> ---
> arch/arm/mach-at91/include/mach/at91sam9_smc.h | 2 +
> arch/arm/mach-at91/sam9_smc.c | 77 ++++++++++++++++++++++++++
> 2 files changed, 79 insertions(+)
>
> diff --git a/arch/arm/mach-at91/include/mach/at91sam9_smc.h b/arch/arm/mach-at91/include/mach/at91sam9_smc.h
> index c3e29311..615ac56 100644
> --- a/arch/arm/mach-at91/include/mach/at91sam9_smc.h
> +++ b/arch/arm/mach-at91/include/mach/at91sam9_smc.h
> @@ -47,6 +47,8 @@ extern void sam9_smc_read_mode(int id, int cs, struct sam9_smc_config *config);
> extern void sam9_smc_write_mode(int id, int cs, struct sam9_smc_config *config);
> extern void sam9_smc_cs_read(void __iomem *, struct sam9_smc_config *config);
> extern void sam9_smc_cs_configure(void __iomem *, struct sam9_smc_config *cfg);
> +extern int sam9_smc_check_cs_configuration(struct sam9_smc_config *config);
> +extern void sam9_smc_clip_cs_configuration(struct sam9_smc_config *config);
> #endif
>
> #define AT91_SMC_SETUP 0x00 /* Setup Register for CS n */
> diff --git a/arch/arm/mach-at91/sam9_smc.c b/arch/arm/mach-at91/sam9_smc.c
> index d7a6156..fe3c492 100644
> --- a/arch/arm/mach-at91/sam9_smc.c
> +++ b/arch/arm/mach-at91/sam9_smc.c
> @@ -23,6 +23,83 @@
>
> static void __iomem *smc_base_addr[2];
>
> +static int count_trailing_zeroes(u32 x)
Don't we have something generic for this?
Check include/asm-generic/bitops/count_zeros.h
> +{
> + int ret = 0;
> + if (!(x & 0xFFFF)) {
> + ret += 16;
> + x = x >> 16;
> + }
> + if (!(x & 0xFF)) {
> + ret += 8;
> + x = x >> 8;
> + }
> + if (!(x & 0xF)) {
> + ret += 4;
> + x = x >> 4;
> + }
> + if (!(x & 0x3)) {
> + ret += 2;
> + x = x >> 2;
> + }
> + if (!(x & 0x1)) {
> + ret += 1;
> + x = x >> 1;
> + }
> + if (!(x & 0x1))
> + ret += 1;
> +
> + return ret;
> +}
> +
> +
> +#define __CHECK_CFG(config, x, y) do {\
> + if (x##_(config->y) > x) {\
> + pr_debug("error: %s (0x%x) is out of range\n", #y,\
> + config->y >> count_trailing_zeroes(x));\
> + return -EINVAL;\
> + } \
> + } while (0)
I do not like the use of macro for this. You can convert them to
functions and it would increase readability. I am pretty confident that
gcc will optimize it so that is won't impact performance.
> +int sam9_smc_check_cs_configuration(struct sam9_smc_config *config)
> +{
> + __CHECK_CFG(config, AT91_SMC_NWESETUP, nwe_setup);
> + __CHECK_CFG(config, AT91_SMC_NCS_WRSETUP, ncs_write_setup);
> + __CHECK_CFG(config, AT91_SMC_NRDSETUP, nrd_setup);
> + __CHECK_CFG(config, AT91_SMC_NCS_RDSETUP, ncs_read_setup);
> + __CHECK_CFG(config, AT91_SMC_NWEPULSE, nwe_pulse);
> + __CHECK_CFG(config, AT91_SMC_NCS_WRPULSE, ncs_write_pulse);
> + __CHECK_CFG(config, AT91_SMC_NRDPULSE, nrd_pulse);
> + __CHECK_CFG(config, AT91_SMC_NCS_RDPULSE, ncs_read_pulse);
> + __CHECK_CFG(config, AT91_SMC_NWECYCLE, write_cycle);
> + __CHECK_CFG(config, AT91_SMC_NRDCYCLE, read_cycle);
> + __CHECK_CFG(config, AT91_SMC_TDF, tdf_cycles);
> + return 0;
> +}
> +
> +#define __CLIP_CFG(config, x, y) do {\
> + if (x##_(config->y) > x) {\
> + config->y = x >> count_trailing_zeroes(x);\
> + pr_debug("clipping %s to %d\n", #y, config->y);\
> + } \
> + } while (0)
Ditto.
> +
> +void sam9_smc_clip_cs_configuration(struct sam9_smc_config *config)
> +{
> + __CLIP_CFG(config, AT91_SMC_NWESETUP, nwe_setup);
> + __CLIP_CFG(config, AT91_SMC_NCS_WRSETUP, ncs_write_setup);
> + __CLIP_CFG(config, AT91_SMC_NRDSETUP, nrd_setup);
> + __CLIP_CFG(config, AT91_SMC_NCS_RDSETUP, ncs_read_setup);
> + __CLIP_CFG(config, AT91_SMC_NWEPULSE, nwe_pulse);
> + __CLIP_CFG(config, AT91_SMC_NCS_WRPULSE, ncs_write_pulse);
> + __CLIP_CFG(config, AT91_SMC_NRDPULSE, nrd_pulse);
> + __CLIP_CFG(config, AT91_SMC_NCS_RDPULSE, ncs_read_pulse);
> + __CLIP_CFG(config, AT91_SMC_NWECYCLE, write_cycle);
> + __CLIP_CFG(config, AT91_SMC_NRDCYCLE, read_cycle);
> + __CLIP_CFG(config, AT91_SMC_TDF, tdf_cycles);
> +
> +}
> +
> static void sam9_smc_cs_write_mode(void __iomem *base,
> struct sam9_smc_config *config)
> {
>
--
Nicolas Ferre
WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Ferre <nicolas.ferre@atmel.com>
To: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
Cc: <b.brezillon@overkiz.com>, <arnd@arndb.de>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 06/12] at91: smc: Adds helper functions to validate and clip the smc timings.
Date: Wed, 15 Jan 2014 10:44:32 +0100 [thread overview]
Message-ID: <52D65880.10301@atmel.com> (raw)
In-Reply-To: <1389270709-32662-7-git-send-email-jjhiblot@traphandler.com>
On 09/01/2014 13:31, Jean-Jacques Hiblot :
> This patchs implememnts 2 functions to help with the configuration of a
> chip-select's timing:
> * sam9_smc_check_cs_configuration : checks that the values would fit in the
> registers.
> * sam9_smc_clip_cs_configuration : clip the values to their maximum.
>
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
> ---
> arch/arm/mach-at91/include/mach/at91sam9_smc.h | 2 +
> arch/arm/mach-at91/sam9_smc.c | 77 ++++++++++++++++++++++++++
> 2 files changed, 79 insertions(+)
>
> diff --git a/arch/arm/mach-at91/include/mach/at91sam9_smc.h b/arch/arm/mach-at91/include/mach/at91sam9_smc.h
> index c3e29311..615ac56 100644
> --- a/arch/arm/mach-at91/include/mach/at91sam9_smc.h
> +++ b/arch/arm/mach-at91/include/mach/at91sam9_smc.h
> @@ -47,6 +47,8 @@ extern void sam9_smc_read_mode(int id, int cs, struct sam9_smc_config *config);
> extern void sam9_smc_write_mode(int id, int cs, struct sam9_smc_config *config);
> extern void sam9_smc_cs_read(void __iomem *, struct sam9_smc_config *config);
> extern void sam9_smc_cs_configure(void __iomem *, struct sam9_smc_config *cfg);
> +extern int sam9_smc_check_cs_configuration(struct sam9_smc_config *config);
> +extern void sam9_smc_clip_cs_configuration(struct sam9_smc_config *config);
> #endif
>
> #define AT91_SMC_SETUP 0x00 /* Setup Register for CS n */
> diff --git a/arch/arm/mach-at91/sam9_smc.c b/arch/arm/mach-at91/sam9_smc.c
> index d7a6156..fe3c492 100644
> --- a/arch/arm/mach-at91/sam9_smc.c
> +++ b/arch/arm/mach-at91/sam9_smc.c
> @@ -23,6 +23,83 @@
>
> static void __iomem *smc_base_addr[2];
>
> +static int count_trailing_zeroes(u32 x)
Don't we have something generic for this?
Check include/asm-generic/bitops/count_zeros.h
> +{
> + int ret = 0;
> + if (!(x & 0xFFFF)) {
> + ret += 16;
> + x = x >> 16;
> + }
> + if (!(x & 0xFF)) {
> + ret += 8;
> + x = x >> 8;
> + }
> + if (!(x & 0xF)) {
> + ret += 4;
> + x = x >> 4;
> + }
> + if (!(x & 0x3)) {
> + ret += 2;
> + x = x >> 2;
> + }
> + if (!(x & 0x1)) {
> + ret += 1;
> + x = x >> 1;
> + }
> + if (!(x & 0x1))
> + ret += 1;
> +
> + return ret;
> +}
> +
> +
> +#define __CHECK_CFG(config, x, y) do {\
> + if (x##_(config->y) > x) {\
> + pr_debug("error: %s (0x%x) is out of range\n", #y,\
> + config->y >> count_trailing_zeroes(x));\
> + return -EINVAL;\
> + } \
> + } while (0)
I do not like the use of macro for this. You can convert them to
functions and it would increase readability. I am pretty confident that
gcc will optimize it so that is won't impact performance.
> +int sam9_smc_check_cs_configuration(struct sam9_smc_config *config)
> +{
> + __CHECK_CFG(config, AT91_SMC_NWESETUP, nwe_setup);
> + __CHECK_CFG(config, AT91_SMC_NCS_WRSETUP, ncs_write_setup);
> + __CHECK_CFG(config, AT91_SMC_NRDSETUP, nrd_setup);
> + __CHECK_CFG(config, AT91_SMC_NCS_RDSETUP, ncs_read_setup);
> + __CHECK_CFG(config, AT91_SMC_NWEPULSE, nwe_pulse);
> + __CHECK_CFG(config, AT91_SMC_NCS_WRPULSE, ncs_write_pulse);
> + __CHECK_CFG(config, AT91_SMC_NRDPULSE, nrd_pulse);
> + __CHECK_CFG(config, AT91_SMC_NCS_RDPULSE, ncs_read_pulse);
> + __CHECK_CFG(config, AT91_SMC_NWECYCLE, write_cycle);
> + __CHECK_CFG(config, AT91_SMC_NRDCYCLE, read_cycle);
> + __CHECK_CFG(config, AT91_SMC_TDF, tdf_cycles);
> + return 0;
> +}
> +
> +#define __CLIP_CFG(config, x, y) do {\
> + if (x##_(config->y) > x) {\
> + config->y = x >> count_trailing_zeroes(x);\
> + pr_debug("clipping %s to %d\n", #y, config->y);\
> + } \
> + } while (0)
Ditto.
> +
> +void sam9_smc_clip_cs_configuration(struct sam9_smc_config *config)
> +{
> + __CLIP_CFG(config, AT91_SMC_NWESETUP, nwe_setup);
> + __CLIP_CFG(config, AT91_SMC_NCS_WRSETUP, ncs_write_setup);
> + __CLIP_CFG(config, AT91_SMC_NRDSETUP, nrd_setup);
> + __CLIP_CFG(config, AT91_SMC_NCS_RDSETUP, ncs_read_setup);
> + __CLIP_CFG(config, AT91_SMC_NWEPULSE, nwe_pulse);
> + __CLIP_CFG(config, AT91_SMC_NCS_WRPULSE, ncs_write_pulse);
> + __CLIP_CFG(config, AT91_SMC_NRDPULSE, nrd_pulse);
> + __CLIP_CFG(config, AT91_SMC_NCS_RDPULSE, ncs_read_pulse);
> + __CLIP_CFG(config, AT91_SMC_NWECYCLE, write_cycle);
> + __CLIP_CFG(config, AT91_SMC_NRDCYCLE, read_cycle);
> + __CLIP_CFG(config, AT91_SMC_TDF, tdf_cycles);
> +
> +}
> +
> static void sam9_smc_cs_write_mode(void __iomem *base,
> struct sam9_smc_config *config)
> {
>
--
Nicolas Ferre
next prev parent reply other threads:[~2014-01-15 9:44 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-09 12:31 [PATCH v2 00/12] Device Tree support for the at91sam9261ek Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 12:31 ` [PATCH v2 01/12] at91: dt: Add at91sam9261 dt SoC support Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-14 17:01 ` Nicolas Ferre
2014-01-14 17:01 ` Nicolas Ferre
2014-01-15 10:08 ` Jean-Jacques Hiblot
2014-01-15 10:08 ` Jean-Jacques Hiblot
2014-01-15 10:14 ` Nicolas Ferre
2014-01-15 10:14 ` Nicolas Ferre
2014-01-15 11:31 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-15 11:31 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-09 12:31 ` [PATCH v2 02/12] at91: dt: sam9261: Basic Device Tree support for the at91sam9261ek Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-14 17:06 ` Nicolas Ferre
2014-01-14 17:06 ` Nicolas Ferre
2014-01-09 12:31 ` [PATCH v2 03/12] at91: dt: sam9261: Added support for the lcd display Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 17:07 ` boris brezillon
2014-01-09 17:07 ` boris brezillon
2014-01-15 11:27 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-15 11:27 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-14 17:09 ` Nicolas Ferre
2014-01-14 17:09 ` Nicolas Ferre
2014-01-09 12:31 ` [PATCH v2 04/12] at91: smc: export sam9_smc_cs_read and sam9_smc_cs_configure Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 12:31 ` [PATCH v2 05/12] at91: smc: Increased the size of tdf_cycles in struct sam9_smc_config Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 12:31 ` [PATCH v2 06/12] at91: smc: Adds helper functions to validate and clip the smc timings Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-15 9:44 ` Nicolas Ferre [this message]
2014-01-15 9:44 ` Nicolas Ferre
2014-01-15 9:54 ` Jean-Jacques Hiblot
2014-01-15 9:54 ` Jean-Jacques Hiblot
2014-01-15 10:18 ` Nicolas Ferre
2014-01-15 10:18 ` Nicolas Ferre
2014-01-09 12:31 ` [PATCH v2 07/12] at91: dt: smc: Added smc bus driver Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 16:59 ` boris brezillon
2014-01-09 16:59 ` boris brezillon
2014-01-09 21:04 ` Jean-Jacques Hiblot
2014-01-09 21:04 ` Jean-Jacques Hiblot
2014-01-10 11:01 ` Jean-Jacques Hiblot
2014-01-10 11:01 ` Jean-Jacques Hiblot
2014-01-10 11:08 ` Jean-Jacques Hiblot
2014-01-10 11:08 ` Jean-Jacques Hiblot
2014-01-11 8:06 ` boris brezillon
2014-01-11 8:06 ` boris brezillon
2014-01-14 14:20 ` Jean-Jacques Hiblot
2014-01-14 14:20 ` Jean-Jacques Hiblot
2014-01-14 15:01 ` Nicolas Ferre
2014-01-14 15:01 ` Nicolas Ferre
2014-02-07 8:42 ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-07 8:42 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-09 12:31 ` [PATCH v2 08/12] at91: sam9261: Add a clock definition for the smc Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 12:31 ` [PATCH v2 09/12] at91: dt: sam9261: Pinmux DT entries for the SMC/EBI interface Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-15 11:25 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-15 11:25 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-09 12:31 ` [PATCH v2 10/12] at91: dt: sam9261: Add an entry in the DT for the SMC/EBI bus driver Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 12:31 ` [PATCH v2 11/12] at91: dt: sam9261: moved the NAND under the smc node Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-09 12:31 ` [PATCH v2 12/12] at91: dt: sam9261: Added DM9000 in the device tree Jean-Jacques Hiblot
2014-01-09 12:31 ` Jean-Jacques Hiblot
2014-01-15 11:23 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-15 11:23 ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-14 16:54 ` [PATCH v2 00/12] Device Tree support for the at91sam9261ek Nicolas Ferre
2014-01-14 16:54 ` Nicolas Ferre
2014-01-15 8:34 ` Jean-Jacques Hiblot
2014-01-15 8:34 ` Jean-Jacques Hiblot
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=52D65880.10301@atmel.com \
--to=nicolas.ferre@atmel.com \
--cc=linux-arm-kernel@lists.infradead.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: link
Be 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.