From 0ae16cbb40a2881f6dfbe00fcb023ee7b548bc5c Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 16 Sep 2014 20:21:42 +0200 Subject: fpga: altera: Clean up the printing and debug Clean up the printf() statements and get rid of the PRINTF() macro by replacing it with debug_cond(). Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Acked-by: Pavel Machek --- drivers/fpga/altera.c | 117 +++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 59 deletions(-) (limited to 'drivers') diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index 6e34a8e56e9..ed3f0c882f7 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -15,14 +15,8 @@ #include #include -/* Define FPGA_DEBUG to get debug printf's */ -/* #define FPGA_DEBUG */ - -#ifdef FPGA_DEBUG -#define PRINTF(fmt,args...) printf (fmt ,##args) -#else -#define PRINTF(fmt,args...) -#endif +/* Define FPGA_DEBUG to 1 to get debug printf's */ +#define FPGA_DEBUG 0 /* Local Static Functions */ static int altera_validate (Altera_desc * desc, const char *fn); @@ -32,36 +26,39 @@ int altera_load(Altera_desc *desc, const void *buf, size_t bsize) { int ret_val = FPGA_FAIL; /* assume a failure */ - if (!altera_validate (desc, (char *)__FUNCTION__)) { - printf ("%s: Invalid device descriptor\n", __FUNCTION__); + if (!altera_validate (desc, (char *)__func__)) { + printf("%s: Invalid device descriptor\n", __func__); } else { switch (desc->family) { case Altera_ACEX1K: case Altera_CYC2: #if defined(CONFIG_FPGA_ACEX1K) - PRINTF ("%s: Launching the ACEX1K Loader...\n", - __FUNCTION__); + debug_cond(FPGA_DEBUG, + "%s: Launching the ACEX1K Loader...\n", + __func__); ret_val = ACEX1K_load (desc, buf, bsize); #elif defined(CONFIG_FPGA_CYCLON2) - PRINTF ("%s: Launching the CYCLONE II Loader...\n", - __FUNCTION__); + debug_cond(FPGA_DEBUG, + "%s: Launching the CYCLONE II Loader...\n", + __func__); ret_val = CYC2_load (desc, buf, bsize); #else - printf ("%s: No support for ACEX1K devices.\n", - __FUNCTION__); + printf("%s: No support for ACEX1K devices.\n", + __func__); #endif break; #if defined(CONFIG_FPGA_STRATIX_II) case Altera_StratixII: - PRINTF ("%s: Launching the Stratix II Loader...\n", - __FUNCTION__); + debug_cond(FPGA_DEBUG, + "%s: Launching the Stratix II Loader...\n", + __func__); ret_val = StratixII_load (desc, buf, bsize); break; #endif default: - printf ("%s: Unsupported family type, %d\n", - __FUNCTION__, desc->family); + printf("%s: Unsupported family type, %d\n", + __func__, desc->family); } } @@ -72,31 +69,33 @@ int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) { int ret_val = FPGA_FAIL; /* assume a failure */ - if (!altera_validate (desc, (char *)__FUNCTION__)) { - printf ("%s: Invalid device descriptor\n", __FUNCTION__); + if (!altera_validate (desc, (char *)__func__)) { + printf("%s: Invalid device descriptor\n", __func__); } else { switch (desc->family) { case Altera_ACEX1K: #if defined(CONFIG_FPGA_ACEX) - PRINTF ("%s: Launching the ACEX1K Reader...\n", - __FUNCTION__); + debug_cond(FPGA_DEBUG, + "%s: Launching the ACEX1K Reader...\n", + __func__); ret_val = ACEX1K_dump (desc, buf, bsize); #else - printf ("%s: No support for ACEX1K devices.\n", - __FUNCTION__); + printf("%s: No support for ACEX1K devices.\n", + __func__); #endif break; #if defined(CONFIG_FPGA_STRATIX_II) case Altera_StratixII: - PRINTF ("%s: Launching the Stratix II Reader...\n", - __FUNCTION__); + debug_cond(FPGA_DEBUG, + "%s: Launching the Stratix II Reader...\n", + __func__); ret_val = StratixII_dump (desc, buf, bsize); break; #endif default: - printf ("%s: Unsupported family type, %d\n", - __FUNCTION__, desc->family); + printf("%s: Unsupported family type, %d\n", + __func__, desc->family); } } @@ -107,42 +106,42 @@ int altera_info( Altera_desc *desc ) { int ret_val = FPGA_FAIL; - if (altera_validate (desc, (char *)__FUNCTION__)) { - printf ("Family: \t"); + if (altera_validate (desc, (char *)__func__)) { + printf("Family: \t"); switch (desc->family) { case Altera_ACEX1K: - printf ("ACEX1K\n"); + printf("ACEX1K\n"); break; case Altera_CYC2: - printf ("CYCLON II\n"); + printf("CYCLON II\n"); break; case Altera_StratixII: - printf ("Stratix II\n"); + printf("Stratix II\n"); break; /* Add new family types here */ default: - printf ("Unknown family type, %d\n", desc->family); + printf("Unknown family type, %d\n", desc->family); } - printf ("Interface type:\t"); + printf("Interface type:\t"); switch (desc->iface) { case passive_serial: - printf ("Passive Serial (PS)\n"); + printf("Passive Serial (PS)\n"); break; case passive_parallel_synchronous: - printf ("Passive Parallel Synchronous (PPS)\n"); + printf("Passive Parallel Synchronous (PPS)\n"); break; case passive_parallel_asynchronous: - printf ("Passive Parallel Asynchronous (PPA)\n"); + printf("Passive Parallel Asynchronous (PPA)\n"); break; case passive_serial_asynchronous: - printf ("Passive Serial Asynchronous (PSA)\n"); + printf("Passive Serial Asynchronous (PSA)\n"); break; case altera_jtag_mode: /* Not used */ - printf ("JTAG Mode\n"); + printf("JTAG Mode\n"); break; case fast_passive_parallel: - printf ("Fast Passive Parallel (FPP)\n"); + printf("Fast Passive Parallel (FPP)\n"); break; case fast_passive_parallel_security: printf @@ -150,31 +149,31 @@ int altera_info( Altera_desc *desc ) break; /* Add new interface types here */ default: - printf ("Unsupported interface type, %d\n", desc->iface); + printf("Unsupported interface type, %d\n", desc->iface); } printf("Device Size: \t%zd bytes\n" - "Cookie: \t0x%x (%d)\n", - desc->size, desc->cookie, desc->cookie); + "Cookie: \t0x%x (%d)\n", + desc->size, desc->cookie, desc->cookie); if (desc->iface_fns) { - printf ("Device Function Table @ 0x%p\n", desc->iface_fns); + printf("Device Function Table @ 0x%p\n", desc->iface_fns); switch (desc->family) { case Altera_ACEX1K: case Altera_CYC2: #if defined(CONFIG_FPGA_ACEX1K) - ACEX1K_info (desc); + ACEX1K_info(desc); #elif defined(CONFIG_FPGA_CYCLON2) - CYC2_info (desc); + CYC2_info(desc); #else /* just in case */ - printf ("%s: No support for ACEX1K devices.\n", - __FUNCTION__); + printf("%s: No support for ACEX1K devices.\n", + __func__); #endif break; #if defined(CONFIG_FPGA_STRATIX_II) case Altera_StratixII: - StratixII_info (desc); + StratixII_info(desc); break; #endif /* Add new family types here */ @@ -183,12 +182,12 @@ int altera_info( Altera_desc *desc ) break; } } else { - printf ("No Device Function Table.\n"); + printf("No Device Function Table.\n"); } ret_val = FPGA_SUCCESS; } else { - printf ("%s: Invalid device descriptor\n", __FUNCTION__); + printf("%s: Invalid device descriptor\n", __func__); } return ret_val; @@ -208,17 +207,17 @@ static int altera_validate (Altera_desc * desc, const char *fn) if (desc->size) { ret_val = true; } else { - printf ("%s: NULL part size\n", fn); + printf("%s: NULL part size\n", fn); } } else { - printf ("%s: Invalid Interface type, %d\n", - fn, desc->iface); + printf("%s: Invalid Interface type, %d\n", + fn, desc->iface); } } else { - printf ("%s: Invalid family type, %d\n", fn, desc->family); + printf("%s: Invalid family type, %d\n", fn, desc->family); } } else { - printf ("%s: NULL descriptor!\n", fn); + printf("%s: NULL descriptor!\n", fn); } return ret_val; -- cgit v1.2.3 From 5561a841487fa246ebc6df17bed8eabfa33f3557 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 16 Sep 2014 20:26:07 +0200 Subject: fpga: altera: Clean up altera_validate function Boldly go, where no programmer has gone before and just clean up the indentation mayhem. No functional change. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek --- drivers/fpga/altera.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'drivers') diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index ed3f0c882f7..6394afe095a 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -195,32 +195,31 @@ int altera_info( Altera_desc *desc ) /* ------------------------------------------------------------------------- */ -static int altera_validate (Altera_desc * desc, const char *fn) +static int altera_validate(Altera_desc *desc, const char *fn) { - int ret_val = false; - - if (desc) { - if ((desc->family > min_altera_type) && - (desc->family < max_altera_type)) { - if ((desc->iface > min_altera_iface_type) && - (desc->iface < max_altera_iface_type)) { - if (desc->size) { - ret_val = true; - } else { - printf("%s: NULL part size\n", fn); - } - } else { - printf("%s: Invalid Interface type, %d\n", - fn, desc->iface); - } - } else { - printf("%s: Invalid family type, %d\n", fn, desc->family); - } - } else { + if (!desc) { printf("%s: NULL descriptor!\n", fn); + return false; } - return ret_val; + if ((desc->family < min_altera_type) || + (desc->family > max_altera_type)) { + printf("%s: Invalid family type, %d\n", fn, desc->family); + return false; + } + + if ((desc->iface < min_altera_iface_type) || + (desc->iface > max_altera_iface_type)) { + printf("%s: Invalid Interface type, %d\n", fn, desc->iface); + return false; + } + + if (!desc->size) { + printf("%s: NULL part size\n", fn); + return false; + } + + return true; } /* ------------------------------------------------------------------------- */ -- cgit v1.2.3 From 4a4c0a5e9a2b65711f733bc2178e506131b0693b Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 16 Sep 2014 20:29:24 +0200 Subject: fpga: altera: More indentation trimdown Further improve the indentation in the rest of the file, where the indentation is initially a bit less brutal. There is no functional change in this patch. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Acked-by: Pavel Machek --- drivers/fpga/altera.c | 238 +++++++++++++++++++++++++------------------------- 1 file changed, 120 insertions(+), 118 deletions(-) (limited to 'drivers') diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index 6394afe095a..b0f323fbef3 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -26,40 +26,41 @@ int altera_load(Altera_desc *desc, const void *buf, size_t bsize) { int ret_val = FPGA_FAIL; /* assume a failure */ - if (!altera_validate (desc, (char *)__func__)) { + if (!altera_validate(desc, (char *)__func__)) { printf("%s: Invalid device descriptor\n", __func__); - } else { - switch (desc->family) { - case Altera_ACEX1K: - case Altera_CYC2: + return FPGA_FAIL; + } + + switch (desc->family) { + case Altera_ACEX1K: + case Altera_CYC2: #if defined(CONFIG_FPGA_ACEX1K) - debug_cond(FPGA_DEBUG, - "%s: Launching the ACEX1K Loader...\n", - __func__); - ret_val = ACEX1K_load (desc, buf, bsize); + debug_cond(FPGA_DEBUG, + "%s: Launching the ACEX1K Loader...\n", + __func__); + ret_val = ACEX1K_load (desc, buf, bsize); #elif defined(CONFIG_FPGA_CYCLON2) - debug_cond(FPGA_DEBUG, - "%s: Launching the CYCLONE II Loader...\n", - __func__); - ret_val = CYC2_load (desc, buf, bsize); + debug_cond(FPGA_DEBUG, + "%s: Launching the CYCLONE II Loader...\n", + __func__); + ret_val = CYC2_load (desc, buf, bsize); #else - printf("%s: No support for ACEX1K devices.\n", - __func__); + printf("%s: No support for ACEX1K devices.\n", + __func__); #endif - break; + break; #if defined(CONFIG_FPGA_STRATIX_II) - case Altera_StratixII: - debug_cond(FPGA_DEBUG, - "%s: Launching the Stratix II Loader...\n", - __func__); - ret_val = StratixII_load (desc, buf, bsize); - break; + case Altera_StratixII: + debug_cond(FPGA_DEBUG, + "%s: Launching the Stratix II Loader...\n", + __func__); + ret_val = StratixII_load (desc, buf, bsize); + break; #endif - default: - printf("%s: Unsupported family type, %d\n", - __func__, desc->family); - } + default: + printf("%s: Unsupported family type, %d\n", + __func__, desc->family); } return ret_val; @@ -71,125 +72,126 @@ int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) if (!altera_validate (desc, (char *)__func__)) { printf("%s: Invalid device descriptor\n", __func__); - } else { - switch (desc->family) { - case Altera_ACEX1K: + return FPGA_FAIL; + } + + switch (desc->family) { + case Altera_ACEX1K: #if defined(CONFIG_FPGA_ACEX) - debug_cond(FPGA_DEBUG, - "%s: Launching the ACEX1K Reader...\n", - __func__); - ret_val = ACEX1K_dump (desc, buf, bsize); + debug_cond(FPGA_DEBUG, + "%s: Launching the ACEX1K Reader...\n", + __func__); + ret_val = ACEX1K_dump (desc, buf, bsize); #else - printf("%s: No support for ACEX1K devices.\n", - __func__); + printf("%s: No support for ACEX1K devices.\n", + __func__); #endif - break; + break; #if defined(CONFIG_FPGA_STRATIX_II) - case Altera_StratixII: - debug_cond(FPGA_DEBUG, - "%s: Launching the Stratix II Reader...\n", - __func__); - ret_val = StratixII_dump (desc, buf, bsize); - break; + case Altera_StratixII: + debug_cond(FPGA_DEBUG, + "%s: Launching the Stratix II Reader...\n", + __func__); + ret_val = StratixII_dump (desc, buf, bsize); + break; #endif - default: - printf("%s: Unsupported family type, %d\n", - __func__, desc->family); - } + default: + printf("%s: Unsupported family type, %d\n", + __func__, desc->family); } return ret_val; } -int altera_info( Altera_desc *desc ) +int altera_info(Altera_desc *desc) { int ret_val = FPGA_FAIL; - if (altera_validate (desc, (char *)__func__)) { - printf("Family: \t"); - switch (desc->family) { - case Altera_ACEX1K: - printf("ACEX1K\n"); - break; - case Altera_CYC2: - printf("CYCLON II\n"); - break; - case Altera_StratixII: - printf("Stratix II\n"); - break; - /* Add new family types here */ - default: - printf("Unknown family type, %d\n", desc->family); - } + if (!altera_validate (desc, (char *)__func__)) { + printf("%s: Invalid device descriptor\n", __func__); + return FPGA_FAIL; + } - printf("Interface type:\t"); - switch (desc->iface) { - case passive_serial: - printf("Passive Serial (PS)\n"); - break; - case passive_parallel_synchronous: - printf("Passive Parallel Synchronous (PPS)\n"); - break; - case passive_parallel_asynchronous: - printf("Passive Parallel Asynchronous (PPA)\n"); - break; - case passive_serial_asynchronous: - printf("Passive Serial Asynchronous (PSA)\n"); - break; - case altera_jtag_mode: /* Not used */ - printf("JTAG Mode\n"); - break; - case fast_passive_parallel: - printf("Fast Passive Parallel (FPP)\n"); - break; - case fast_passive_parallel_security: - printf - ("Fast Passive Parallel with Security (FPPS) \n"); - break; - /* Add new interface types here */ - default: - printf("Unsupported interface type, %d\n", desc->iface); - } + printf("Family: \t"); + switch (desc->family) { + case Altera_ACEX1K: + printf("ACEX1K\n"); + break; + case Altera_CYC2: + printf("CYCLON II\n"); + break; + case Altera_StratixII: + printf("Stratix II\n"); + break; + /* Add new family types here */ + default: + printf("Unknown family type, %d\n", desc->family); + } - printf("Device Size: \t%zd bytes\n" - "Cookie: \t0x%x (%d)\n", - desc->size, desc->cookie, desc->cookie); + printf("Interface type:\t"); + switch (desc->iface) { + case passive_serial: + printf("Passive Serial (PS)\n"); + break; + case passive_parallel_synchronous: + printf("Passive Parallel Synchronous (PPS)\n"); + break; + case passive_parallel_asynchronous: + printf("Passive Parallel Asynchronous (PPA)\n"); + break; + case passive_serial_asynchronous: + printf("Passive Serial Asynchronous (PSA)\n"); + break; + case altera_jtag_mode: /* Not used */ + printf("JTAG Mode\n"); + break; + case fast_passive_parallel: + printf("Fast Passive Parallel (FPP)\n"); + break; + case fast_passive_parallel_security: + printf("Fast Passive Parallel with Security (FPPS)\n"); + break; + /* Add new interface types here */ + default: + printf("Unsupported interface type, %d\n", desc->iface); + } + + printf("Device Size: \t%zd bytes\n" + "Cookie: \t0x%x (%d)\n", + desc->size, desc->cookie, desc->cookie); - if (desc->iface_fns) { - printf("Device Function Table @ 0x%p\n", desc->iface_fns); - switch (desc->family) { - case Altera_ACEX1K: - case Altera_CYC2: + if (desc->iface_fns) { + printf("Device Function Table @ 0x%p\n", desc->iface_fns); + switch (desc->family) { + case Altera_ACEX1K: + case Altera_CYC2: #if defined(CONFIG_FPGA_ACEX1K) - ACEX1K_info(desc); + ACEX1K_info(desc); #elif defined(CONFIG_FPGA_CYCLON2) - CYC2_info(desc); + CYC2_info(desc); #else - /* just in case */ - printf("%s: No support for ACEX1K devices.\n", - __func__); + /* just in case */ + printf("%s: No support for ACEX1K devices.\n", + __func__); #endif - break; + break; #if defined(CONFIG_FPGA_STRATIX_II) - case Altera_StratixII: - StratixII_info(desc); - break; + case Altera_StratixII: + StratixII_info(desc); + break; #endif - /* Add new family types here */ - default: - /* we don't need a message here - we give one up above */ - break; - } - } else { - printf("No Device Function Table.\n"); + /* Add new family types here */ + default: + /* we don't need a message here - we give one up above */ + break; } - - ret_val = FPGA_SUCCESS; } else { - printf("%s: Invalid device descriptor\n", __func__); + printf("No Device Function Table.\n"); } + ret_val = FPGA_SUCCESS; + return ret_val; } -- cgit v1.2.3 From 54c96b18a22a6ee5d5a67c057ed5d3812ac16b39 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 16 Sep 2014 20:32:51 +0200 Subject: fpga: altera: Move altera_validate to the top Move the function to the top of the file to avoid forward declaration. No functional change. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Acked-by: Pavel Machek --- drivers/fpga/altera.c | 58 +++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) (limited to 'drivers') diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index b0f323fbef3..9e9df505e52 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -19,7 +19,32 @@ #define FPGA_DEBUG 0 /* Local Static Functions */ -static int altera_validate (Altera_desc * desc, const char *fn); +static int altera_validate(Altera_desc *desc, const char *fn) +{ + if (!desc) { + printf("%s: NULL descriptor!\n", fn); + return false; + } + + if ((desc->family < min_altera_type) || + (desc->family > max_altera_type)) { + printf("%s: Invalid family type, %d\n", fn, desc->family); + return false; + } + + if ((desc->iface < min_altera_iface_type) || + (desc->iface > max_altera_iface_type)) { + printf("%s: Invalid Interface type, %d\n", fn, desc->iface); + return false; + } + + if (!desc->size) { + printf("%s: NULL part size\n", fn); + return false; + } + + return true; +} /* ------------------------------------------------------------------------- */ int altera_load(Altera_desc *desc, const void *buf, size_t bsize) @@ -194,34 +219,3 @@ int altera_info(Altera_desc *desc) return ret_val; } - -/* ------------------------------------------------------------------------- */ - -static int altera_validate(Altera_desc *desc, const char *fn) -{ - if (!desc) { - printf("%s: NULL descriptor!\n", fn); - return false; - } - - if ((desc->family < min_altera_type) || - (desc->family > max_altera_type)) { - printf("%s: Invalid family type, %d\n", fn, desc->family); - return false; - } - - if ((desc->iface < min_altera_iface_type) || - (desc->iface > max_altera_iface_type)) { - printf("%s: Invalid Interface type, %d\n", fn, desc->iface); - return false; - } - - if (!desc->size) { - printf("%s: NULL part size\n", fn); - return false; - } - - return true; -} - -/* ------------------------------------------------------------------------- */ -- cgit v1.2.3 From fda915a4cf171f4ef3077adbc7bc1680a140b0d6 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 16 Sep 2014 20:33:54 +0200 Subject: fpga: altera: Make altera_validate return normal values Make the function return either 0 or -EINVAL, that is, normal expected error codes and success codes instead of true/false nonsense. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Acked-by: Pavel Machek --- drivers/fpga/altera.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index 9e9df505e52..941e7c8933f 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -12,38 +12,38 @@ * Altera FPGA support */ #include +#include #include #include /* Define FPGA_DEBUG to 1 to get debug printf's */ #define FPGA_DEBUG 0 -/* Local Static Functions */ static int altera_validate(Altera_desc *desc, const char *fn) { if (!desc) { printf("%s: NULL descriptor!\n", fn); - return false; + return -EINVAL; } if ((desc->family < min_altera_type) || (desc->family > max_altera_type)) { printf("%s: Invalid family type, %d\n", fn, desc->family); - return false; + return -EINVAL; } if ((desc->iface < min_altera_iface_type) || (desc->iface > max_altera_iface_type)) { printf("%s: Invalid Interface type, %d\n", fn, desc->iface); - return false; + return -EINVAL; } if (!desc->size) { printf("%s: NULL part size\n", fn); - return false; + return -EINVAL; } - return true; + return 0; } /* ------------------------------------------------------------------------- */ @@ -51,7 +51,7 @@ int altera_load(Altera_desc *desc, const void *buf, size_t bsize) { int ret_val = FPGA_FAIL; /* assume a failure */ - if (!altera_validate(desc, (char *)__func__)) { + if (altera_validate(desc, (char *)__func__)) { printf("%s: Invalid device descriptor\n", __func__); return FPGA_FAIL; } @@ -95,7 +95,7 @@ int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) { int ret_val = FPGA_FAIL; /* assume a failure */ - if (!altera_validate (desc, (char *)__func__)) { + if (altera_validate(desc, (char *)__func__)) { printf("%s: Invalid device descriptor\n", __func__); return FPGA_FAIL; } @@ -133,7 +133,7 @@ int altera_info(Altera_desc *desc) { int ret_val = FPGA_FAIL; - if (!altera_validate (desc, (char *)__func__)) { + if (altera_validate (desc, (char *)__func__)) { printf("%s: Invalid device descriptor\n", __func__); return FPGA_FAIL; } -- cgit v1.2.3 From 2012f238bd4383904e898cfc26c9fd433af835aa Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 16 Sep 2014 21:17:51 +0200 Subject: fpga: altera: Turn the switches into table lookup Add a table of FPGA family with matching functions associated with it and make all the code just look up the family in that table and call the associated function instead of the horrible switch voodoo which was duplicated all over the place. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Acked-by: Pavel Machek --- drivers/fpga/altera.c | 171 ++++++++++++++++++-------------------------------- 1 file changed, 60 insertions(+), 111 deletions(-) (limited to 'drivers') diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index 941e7c8933f..fd2b4f0103d 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -19,6 +19,26 @@ /* Define FPGA_DEBUG to 1 to get debug printf's */ #define FPGA_DEBUG 0 +static const struct altera_fpga { + enum altera_family family; + const char *name; + int (*load)(Altera_desc *, const void *, size_t); + int (*dump)(Altera_desc *, const void *, size_t); + int (*info)(Altera_desc *); +} altera_fpga[] = { +#if defined(CONFIG_FPGA_ACEX1K) + { Altera_ACEX1K, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info }, + { Altera_CYC2, "ACEX1K", ACEX1K_load, ACEX1K_dump, ACEX1K_info }, +#elif defined(CONFIG_FPGA_CYCLON2) + { Altera_ACEX1K, "CycloneII", CYC2_load, CYC2_dump, CYC2_info }, + { Altera_CYC2, "CycloneII", CYC2_load, CYC2_dump, CYC2_info }, +#endif +#if defined(CONFIG_FPGA_STRATIX_II) + { Altera_StratixII, "StratixII", StratixII_load, + StratixII_dump, StratixII_info }, +#endif +}; + static int altera_validate(Altera_desc *desc, const char *fn) { if (!desc) { @@ -46,113 +66,65 @@ static int altera_validate(Altera_desc *desc, const char *fn) return 0; } -/* ------------------------------------------------------------------------- */ -int altera_load(Altera_desc *desc, const void *buf, size_t bsize) +static const struct altera_fpga * +altera_desc_to_fpga(Altera_desc *desc, const char *fn) { - int ret_val = FPGA_FAIL; /* assume a failure */ + int i; - if (altera_validate(desc, (char *)__func__)) { - printf("%s: Invalid device descriptor\n", __func__); - return FPGA_FAIL; + if (altera_validate(desc, fn)) { + printf("%s: Invalid device descriptor\n", fn); + return NULL; } - switch (desc->family) { - case Altera_ACEX1K: - case Altera_CYC2: -#if defined(CONFIG_FPGA_ACEX1K) - debug_cond(FPGA_DEBUG, - "%s: Launching the ACEX1K Loader...\n", - __func__); - ret_val = ACEX1K_load (desc, buf, bsize); -#elif defined(CONFIG_FPGA_CYCLON2) - debug_cond(FPGA_DEBUG, - "%s: Launching the CYCLONE II Loader...\n", - __func__); - ret_val = CYC2_load (desc, buf, bsize); -#else - printf("%s: No support for ACEX1K devices.\n", - __func__); -#endif - break; + for (i = 0; i < ARRAY_SIZE(altera_fpga); i++) { + if (desc->family == altera_fpga[i].family) + break; + } -#if defined(CONFIG_FPGA_STRATIX_II) - case Altera_StratixII: - debug_cond(FPGA_DEBUG, - "%s: Launching the Stratix II Loader...\n", - __func__); - ret_val = StratixII_load (desc, buf, bsize); - break; -#endif - default: - printf("%s: Unsupported family type, %d\n", - __func__, desc->family); + if (i == ARRAY_SIZE(altera_fpga)) { + printf("%s: Unsupported family type, %d\n", fn, desc->family); + return NULL; } - return ret_val; + return &altera_fpga[i]; } -int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) +int altera_load(Altera_desc *desc, const void *buf, size_t bsize) { - int ret_val = FPGA_FAIL; /* assume a failure */ + const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); - if (altera_validate(desc, (char *)__func__)) { - printf("%s: Invalid device descriptor\n", __func__); + if (!fpga) return FPGA_FAIL; - } - switch (desc->family) { - case Altera_ACEX1K: -#if defined(CONFIG_FPGA_ACEX) - debug_cond(FPGA_DEBUG, - "%s: Launching the ACEX1K Reader...\n", - __func__); - ret_val = ACEX1K_dump (desc, buf, bsize); -#else - printf("%s: No support for ACEX1K devices.\n", - __func__); -#endif - break; + debug_cond(FPGA_DEBUG, "%s: Launching the %s Loader...\n", + __func__, fpga->name); + if (fpga->load) + return fpga->load(desc, buf, bsize); + return 0; +} -#if defined(CONFIG_FPGA_STRATIX_II) - case Altera_StratixII: - debug_cond(FPGA_DEBUG, - "%s: Launching the Stratix II Reader...\n", - __func__); - ret_val = StratixII_dump (desc, buf, bsize); - break; -#endif - default: - printf("%s: Unsupported family type, %d\n", - __func__, desc->family); - } +int altera_dump(Altera_desc *desc, const void *buf, size_t bsize) +{ + const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); - return ret_val; + if (!fpga) + return FPGA_FAIL; + + debug_cond(FPGA_DEBUG, "%s: Launching the %s Reader...\n", + __func__, fpga->name); + if (fpga->dump) + return fpga->dump(desc, buf, bsize); + return 0; } int altera_info(Altera_desc *desc) { - int ret_val = FPGA_FAIL; + const struct altera_fpga *fpga = altera_desc_to_fpga(desc, __func__); - if (altera_validate (desc, (char *)__func__)) { - printf("%s: Invalid device descriptor\n", __func__); + if (!fpga) return FPGA_FAIL; - } - printf("Family: \t"); - switch (desc->family) { - case Altera_ACEX1K: - printf("ACEX1K\n"); - break; - case Altera_CYC2: - printf("CYCLON II\n"); - break; - case Altera_StratixII: - printf("Stratix II\n"); - break; - /* Add new family types here */ - default: - printf("Unknown family type, %d\n", desc->family); - } + printf("Family: \t%s\n", fpga->name); printf("Interface type:\t"); switch (desc->iface) { @@ -188,34 +160,11 @@ int altera_info(Altera_desc *desc) if (desc->iface_fns) { printf("Device Function Table @ 0x%p\n", desc->iface_fns); - switch (desc->family) { - case Altera_ACEX1K: - case Altera_CYC2: -#if defined(CONFIG_FPGA_ACEX1K) - ACEX1K_info(desc); -#elif defined(CONFIG_FPGA_CYCLON2) - CYC2_info(desc); -#else - /* just in case */ - printf("%s: No support for ACEX1K devices.\n", - __func__); -#endif - break; -#if defined(CONFIG_FPGA_STRATIX_II) - case Altera_StratixII: - StratixII_info(desc); - break; -#endif - /* Add new family types here */ - default: - /* we don't need a message here - we give one up above */ - break; - } + if (fpga->info) + fpga->info(desc); } else { printf("No Device Function Table.\n"); } - ret_val = FPGA_SUCCESS; - - return ret_val; + return FPGA_SUCCESS; } -- cgit v1.2.3 From f33c9305830d5f8b996a2aaea66591dc93143fe5 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 5 Sep 2014 12:49:48 +0200 Subject: mmc: dw_mmc: cleanups The dw_mmc driver was responding to errors with debug(). Change that to prinf()/puts() respectively so that any errors are immediately obvious. Also adjust english in comments. Signed-off-by: Pavel Machek Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Cc: Pantelis Antoniou Acked-by: Chin Liang See --- drivers/mmc/dw_mmc.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 0df30bc0453..785eed567c3 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -119,7 +119,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) { if (get_timer(start) > timeout) { - printf("Timeout on data busy\n"); + printf("%s: Timeout on data busy\n", __func__); return TIMEOUT; } } @@ -177,14 +177,24 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, } } - if (i == retry) + if (i == retry) { + printf("%s: Timeout.\n", __func__); return TIMEOUT; + } if (mask & DWMCI_INTMSK_RTO) { - debug("Response Timeout..\n"); + /* + * Timeout here is not necessarily fatal. (e)MMC cards + * will splat here when they receive CMD55 as they do + * not support this command and that is exactly the way + * to tell them apart from SD cards. Thus, this output + * below shall be debug(). eMMC cards also do not favor + * CMD8, please keep that in mind. + */ + debug("%s: Response Timeout.\n", __func__); return TIMEOUT; } else if (mask & DWMCI_INTMSK_RE) { - debug("Response Error..\n"); + printf("%s: Response Error.\n", __func__); return -1; } @@ -204,7 +214,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, do { mask = dwmci_readl(host, DWMCI_RINTSTS); if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) { - debug("DATA ERROR!\n"); + printf("%s: DATA ERROR!\n", __func__); return -1; } } while (!(mask & DWMCI_INTMSK_DTO)); @@ -232,16 +242,16 @@ static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) if ((freq == host->clock) || (freq == 0)) return 0; /* - * If host->get_mmc_clk didn't define, + * If host->get_mmc_clk isn't defined, * then assume that host->bus_hz is source clock value. - * host->bus_hz should be set from user. + * host->bus_hz should be set by user. */ if (host->get_mmc_clk) sclk = host->get_mmc_clk(host); else if (host->bus_hz) sclk = host->bus_hz; else { - printf("Didn't get source clock value..\n"); + printf("%s: Didn't get source clock value.\n", __func__); return -EINVAL; } @@ -260,7 +270,7 @@ static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) do { status = dwmci_readl(host, DWMCI_CMD); if (timeout-- < 0) { - printf("TIMEOUT error!!\n"); + printf("%s: Timeout!\n", __func__); return -ETIMEDOUT; } } while (status & DWMCI_CMD_START); @@ -275,7 +285,7 @@ static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) do { status = dwmci_readl(host, DWMCI_CMD); if (timeout-- < 0) { - printf("TIMEOUT error!!\n"); + printf("%s: Timeout!\n", __func__); return -ETIMEDOUT; } } while (status & DWMCI_CMD_START); @@ -290,7 +300,7 @@ static void dwmci_set_ios(struct mmc *mmc) struct dwmci_host *host = (struct dwmci_host *)mmc->priv; u32 ctype, regs; - debug("Buswidth = %d, clock: %d\n",mmc->bus_width, mmc->clock); + debug("Buswidth = %d, clock: %d\n", mmc->bus_width, mmc->clock); dwmci_setup_bus(host, mmc->clock); switch (mmc->bus_width) { @@ -329,7 +339,7 @@ static int dwmci_init(struct mmc *mmc) dwmci_writel(host, DWMCI_PWREN, 1); if (!dwmci_wait_reset(host, DWMCI_RESET_ALL)) { - debug("%s[%d] Fail-reset!!\n",__func__,__LINE__); + printf("%s[%d] Fail-reset!!\n", __func__, __LINE__); return -1; } -- cgit v1.2.3 From 58ec63d6bcbe392ebed83197c90dc743f3b9e701 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Tue, 9 Sep 2014 14:26:51 +0200 Subject: net: phy: Cleanup drivers/net/phy/micrel.c Old saying says that more than three exclamation marks in a row are sign of mental disease. Cleanup micrel.c. Signed-off-by: Pavel Machek Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Cc: Joe Hershberger Acked-by: Chin Liang See --- drivers/net/phy/micrel.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 5d7e3be52e0..507b9a368be 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -25,8 +25,7 @@ static struct phy_driver KSZ804_driver = { #ifndef CONFIG_PHY_MICREL_KSZ9021 /* * I can't believe Micrel used the exact same part number - * for the KSZ9021 - * Shame Micrel, Shame!!!!! + * for the KSZ9021. Shame Micrel, Shame! */ static struct phy_driver KS8721_driver = { .name = "Micrel KS8721BL", @@ -40,7 +39,7 @@ static struct phy_driver KS8721_driver = { #endif -/** +/* * KSZ9021 - KSZ9031 common */ @@ -69,8 +68,8 @@ static int ksz90xx_startup(struct phy_device *phydev) phydev->speed = SPEED_10; return 0; } -#ifdef CONFIG_PHY_MICREL_KSZ9021 +#ifdef CONFIG_PHY_MICREL_KSZ9021 /* * KSZ9021 */ -- cgit v1.2.3 From 4f68678b1941af7d75f391d1189c776fb434dc08 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 15 Sep 2014 00:50:37 +0200 Subject: net: dwc: Fix cache alignment issues Fix remaining cache alignment issues in the DWC Ethernet driver. Please note that the cache handling in the driver is making the code hideous and thus the next patch cleans that up. In order to make this change reviewable though, the cleanup is split from it. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Cc: Joe Hershberger Acked-by: Pavel Machek --- drivers/net/designware.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 7186e3b491e..aaf146d444d 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -303,7 +303,8 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length) /* Flush data to be sent */ flush_dcache_range((unsigned long)desc_p->dmamac_addr, - (unsigned long)desc_p->dmamac_addr + length); + (unsigned long)desc_p->dmamac_addr + + roundup(length, ARCH_DMA_MINALIGN)); #if defined(CONFIG_DW_ALTDESCRIPTOR) desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST; @@ -372,7 +373,8 @@ static int dw_eth_recv(struct eth_device *dev) /* Flush only status field - others weren't changed */ flush_dcache_range((unsigned long)&desc_p->txrx_status, (unsigned long)&desc_p->txrx_status + - sizeof(desc_p->txrx_status)); + roundup(sizeof(desc_p->txrx_status), + ARCH_DMA_MINALIGN)); /* Test the wrap-around condition. */ if (++desc_num >= CONFIG_RX_DESCR_NUM) -- cgit v1.2.3 From 96cec17d3cd22ca2251d6f7946409933a231ce6f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Mon, 15 Sep 2014 01:05:23 +0200 Subject: net: dwc: Make the cache handling less cryptic Add a few new variables to make the cache handling less cryptic. Add a variable for DMA and DATA descriptor start and end, so the correctness of the code is easier to inspect. Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Cc: Joe Hershberger Acked-by: Pavel Machek Acked-by: Chin Liang See --- drivers/net/designware.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'drivers') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index aaf146d444d..9ded8950b83 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -279,19 +279,21 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length) struct eth_dma_regs *dma_p = priv->dma_regs_p; u32 desc_num = priv->tx_currdescnum; struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num]; - + uint32_t desc_start = (uint32_t)desc_p; + uint32_t desc_end = desc_start + + roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); + uint32_t data_start = (uint32_t)desc_p->dmamac_addr; + uint32_t data_end = data_start + + roundup(length, ARCH_DMA_MINALIGN); /* * Strictly we only need to invalidate the "txrx_status" field * for the following check, but on some platforms we cannot - * invalidate only 4 bytes, so roundup to - * ARCH_DMA_MINALIGN. This is safe because the individual - * descriptors in the array are each aligned to - * ARCH_DMA_MINALIGN. + * invalidate only 4 bytes, so we flush the entire descriptor, + * which is 16 bytes in total. This is safe because the + * individual descriptors in the array are each aligned to + * ARCH_DMA_MINALIGN and padded appropriately. */ - invalidate_dcache_range( - (unsigned long)desc_p, - (unsigned long)desc_p + - roundup(sizeof(desc_p->txrx_status), ARCH_DMA_MINALIGN)); + invalidate_dcache_range(desc_start, desc_end); /* Check if the descriptor is owned by CPU */ if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) { @@ -299,12 +301,10 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length) return -1; } - memcpy((void *)desc_p->dmamac_addr, packet, length); + memcpy(desc_p->dmamac_addr, packet, length); /* Flush data to be sent */ - flush_dcache_range((unsigned long)desc_p->dmamac_addr, - (unsigned long)desc_p->dmamac_addr + - roundup(length, ARCH_DMA_MINALIGN)); + flush_dcache_range(data_start, data_end); #if defined(CONFIG_DW_ALTDESCRIPTOR) desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST; @@ -322,8 +322,7 @@ static int dw_eth_send(struct eth_device *dev, void *packet, int length) #endif /* Flush modified buffer descriptor */ - flush_dcache_range((unsigned long)desc_p, - (unsigned long)desc_p + sizeof(struct dmamacdescr)); + flush_dcache_range(desc_start, desc_end); /* Test the wrap-around condition. */ if (++desc_num >= CONFIG_TX_DESCR_NUM) @@ -343,11 +342,14 @@ static int dw_eth_recv(struct eth_device *dev) u32 status, desc_num = priv->rx_currdescnum; struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num]; int length = 0; + uint32_t desc_start = (uint32_t)desc_p; + uint32_t desc_end = desc_start + + roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); + uint32_t data_start = (uint32_t)desc_p->dmamac_addr; + uint32_t data_end; /* Invalidate entire buffer descriptor */ - invalidate_dcache_range((unsigned long)desc_p, - (unsigned long)desc_p + - sizeof(struct dmamacdescr)); + invalidate_dcache_range(desc_start, desc_end); status = desc_p->txrx_status; @@ -358,9 +360,8 @@ static int dw_eth_recv(struct eth_device *dev) DESC_RXSTS_FRMLENSHFT; /* Invalidate received data */ - invalidate_dcache_range((unsigned long)desc_p->dmamac_addr, - (unsigned long)desc_p->dmamac_addr + - roundup(length, ARCH_DMA_MINALIGN)); + data_end = data_start + roundup(length, ARCH_DMA_MINALIGN); + invalidate_dcache_range(data_start, data_end); NetReceive(desc_p->dmamac_addr, length); @@ -371,10 +372,7 @@ static int dw_eth_recv(struct eth_device *dev) desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA; /* Flush only status field - others weren't changed */ - flush_dcache_range((unsigned long)&desc_p->txrx_status, - (unsigned long)&desc_p->txrx_status + - roundup(sizeof(desc_p->txrx_status), - ARCH_DMA_MINALIGN)); + flush_dcache_range(desc_start, desc_end); /* Test the wrap-around condition. */ if (++desc_num >= CONFIG_RX_DESCR_NUM) -- cgit v1.2.3 From 498d1a62db4374c9d6223771bcbe8ae612a0f59f Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 8 Sep 2014 14:08:45 +0200 Subject: arm: socfpga: mmc: Pick the clock from clock manager Make the SoCFPGA MMC stub pick clock via the clock manager frequency accessors instead of hard-coding the frequency. Also fix calloc() misuse. Signed-off-by: Pavel Machek Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek Acked-by: Dinh Nguyen --- drivers/mmc/socfpga_dw_mmc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mmc/socfpga_dw_mmc.c b/drivers/mmc/socfpga_dw_mmc.c index 1f96382dea5..eb69aed9dfb 100644 --- a/drivers/mmc/socfpga_dw_mmc.c +++ b/drivers/mmc/socfpga_dw_mmc.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -44,12 +45,18 @@ static void socfpga_dwmci_clksel(struct dwmci_host *host) int socfpga_dwmmc_init(u32 regbase, int bus_width, int index) { struct dwmci_host *host; + unsigned long clk = cm_get_mmc_controller_clk_hz(); + + if (clk == 0) { + printf("%s: MMC clock is zero!", __func__); + return -EINVAL; + } /* calloc for zero init */ - host = calloc(sizeof(struct dwmci_host), 1); + host = calloc(1, sizeof(struct dwmci_host)); if (!host) { - printf("dwmci_host calloc fail!\n"); - return -1; + printf("%s: calloc() failed!\n", __func__); + return -ENOMEM; } host->name = "SOCFPGA DWMMC"; @@ -58,7 +65,7 @@ int socfpga_dwmmc_init(u32 regbase, int bus_width, int index) host->clksel = socfpga_dwmci_clksel; host->dev_index = index; /* fixed clock divide by 4 which due to the SDMMC wrapper */ - host->bus_hz = CONFIG_SOCFPGA_DWMMC_BUS_HZ; + host->bus_hz = clk; host->fifoth_val = MSIZE(0x2) | RX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2 - 1) | TX_WMARK(CONFIG_SOCFPGA_DWMMC_FIFO_DEPTH / 2); -- cgit v1.2.3 From 230fe9b202ff0ca396ad9a564816cc87d42daa6e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 8 Sep 2014 14:08:45 +0200 Subject: arm: socfpga: fpga: Add SoCFPGA FPGA programming interface Add code necessary to program the FPGA part of SoCFPGA from U-Boot with an RBF blob. This patch also integrates the code into the FPGA driver framework in U-Boot so it can be used via the 'fpga' command. Signed-off-by: Pavel Machek Signed-off-by: Marek Vasut Cc: Chin Liang See Cc: Dinh Nguyen Cc: Albert Aribaud Cc: Tom Rini Cc: Wolfgang Denk Cc: Pavel Machek V2: Move the not-CPU specific stuff into drivers/fpga/ and base this on the cleaned up altera FPGA support. --- drivers/fpga/Makefile | 1 + drivers/fpga/altera.c | 3 + drivers/fpga/socfpga.c | 301 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 drivers/fpga/socfpga.c (limited to 'drivers') diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile index dfb2e7fc760..6aa24d43590 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -17,4 +17,5 @@ obj-y += altera.o obj-$(CONFIG_FPGA_ACEX1K) += ACEX1K.o obj-$(CONFIG_FPGA_CYCLON2) += cyclon2.o obj-$(CONFIG_FPGA_STRATIX_II) += stratixII.o +obj-$(CONFIG_FPGA_SOCFPGA) += socfpga.o endif diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c index fd2b4f0103d..a5bfe5dce19 100644 --- a/drivers/fpga/altera.c +++ b/drivers/fpga/altera.c @@ -37,6 +37,9 @@ static const struct altera_fpga { { Altera_StratixII, "StratixII", StratixII_load, StratixII_dump, StratixII_info }, #endif +#if defined(CONFIG_FPGA_SOCFPGA) + { Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL }, +#endif }; static int altera_validate(Altera_desc *desc, const char *fn) diff --git a/drivers/fpga/socfpga.c b/drivers/fpga/socfpga.c new file mode 100644 index 00000000000..63b3566e3ed --- /dev/null +++ b/drivers/fpga/socfpga.c @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2012 Altera Corporation + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* Timeout count */ +#define FPGA_TIMEOUT_CNT 0x1000000 + +static struct socfpga_fpga_manager *fpgamgr_regs = + (struct socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS; +static struct socfpga_system_manager *sysmgr_regs = + (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS; + +/* Set CD ratio */ +static void fpgamgr_set_cd_ratio(unsigned long ratio) +{ + clrsetbits_le32(&fpgamgr_regs->ctrl, + 0x3 << FPGAMGRREGS_CTRL_CDRATIO_LSB, + (ratio & 0x3) << FPGAMGRREGS_CTRL_CDRATIO_LSB); +} + +static int fpgamgr_dclkcnt_set(unsigned long cnt) +{ + unsigned long i; + + /* Clear any existing done status */ + if (readl(&fpgamgr_regs->dclkstat)) + writel(0x1, &fpgamgr_regs->dclkstat); + + /* Write the dclkcnt */ + writel(cnt, &fpgamgr_regs->dclkcnt); + + /* Wait till the dclkcnt done */ + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) { + if (!readl(&fpgamgr_regs->dclkstat)) + continue; + + writel(0x1, &fpgamgr_regs->dclkstat); + return 0; + } + + return -ETIMEDOUT; +} + +/* Start the FPGA programming by initialize the FPGA Manager */ +static int fpgamgr_program_init(void) +{ + unsigned long msel, i; + + /* Get the MSEL value */ + msel = readl(&fpgamgr_regs->stat); + msel &= FPGAMGRREGS_STAT_MSEL_MASK; + msel >>= FPGAMGRREGS_STAT_MSEL_LSB; + + /* + * Set the cfg width + * If MSEL[3] = 1, cfg width = 32 bit + */ + if (msel & 0x8) { + setbits_le32(&fpgamgr_regs->ctrl, + FPGAMGRREGS_CTRL_CFGWDTH_MASK); + + /* To determine the CD ratio */ + /* MSEL[1:0] = 0, CD Ratio = 1 */ + if ((msel & 0x3) == 0x0) + fpgamgr_set_cd_ratio(CDRATIO_x1); + /* MSEL[1:0] = 1, CD Ratio = 4 */ + else if ((msel & 0x3) == 0x1) + fpgamgr_set_cd_ratio(CDRATIO_x4); + /* MSEL[1:0] = 2, CD Ratio = 8 */ + else if ((msel & 0x3) == 0x2) + fpgamgr_set_cd_ratio(CDRATIO_x8); + + } else { /* MSEL[3] = 0 */ + clrbits_le32(&fpgamgr_regs->ctrl, + FPGAMGRREGS_CTRL_CFGWDTH_MASK); + + /* To determine the CD ratio */ + /* MSEL[1:0] = 0, CD Ratio = 1 */ + if ((msel & 0x3) == 0x0) + fpgamgr_set_cd_ratio(CDRATIO_x1); + /* MSEL[1:0] = 1, CD Ratio = 2 */ + else if ((msel & 0x3) == 0x1) + fpgamgr_set_cd_ratio(CDRATIO_x2); + /* MSEL[1:0] = 2, CD Ratio = 4 */ + else if ((msel & 0x3) == 0x2) + fpgamgr_set_cd_ratio(CDRATIO_x4); + } + + /* To enable FPGA Manager configuration */ + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_NCE_MASK); + + /* To enable FPGA Manager drive over configuration line */ + setbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_EN_MASK); + + /* Put FPGA into reset phase */ + setbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_NCONFIGPULL_MASK); + + /* (1) wait until FPGA enter reset phase */ + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) { + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_RESETPHASE) + break; + } + + /* If not in reset state, return error */ + if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_RESETPHASE) { + puts("FPGA: Could not reset\n"); + return -1; + } + + /* Release FPGA from reset phase */ + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_NCONFIGPULL_MASK); + + /* (2) wait until FPGA enter configuration phase */ + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) { + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_CFGPHASE) + break; + } + + /* If not in configuration state, return error */ + if (fpgamgr_get_mode() != FPGAMGRREGS_MODE_CFGPHASE) { + puts("FPGA: Could not configure\n"); + return -2; + } + + /* Clear all interrupts in CB Monitor */ + writel(0xFFF, &fpgamgr_regs->gpio_porta_eoi); + + /* Enable AXI configuration */ + setbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_AXICFGEN_MASK); + + return 0; +} + +/* Write the RBF data to FPGA Manager */ +static void fpgamgr_program_write(const void *rbf_data, unsigned long rbf_size) +{ + uint32_t src = (uint32_t)rbf_data; + uint32_t dst = SOCFPGA_FPGAMGRDATA_ADDRESS; + + /* Number of loops for 32-byte long copying. */ + uint32_t loops32 = rbf_size / 32; + /* Number of loops for 4-byte long copying + trailing bytes */ + uint32_t loops4 = DIV_ROUND_UP(rbf_size % 32, 4); + + asm volatile( + "1: ldmia %0!, {r0-r7}\n" + " stmia %1!, {r0-r7}\n" + " sub %1, #32\n" + " subs %2, #1\n" + " bne 1b\n" + "2: ldr %2, [%0], #4\n" + " str %2, [%1]\n" + " subs %3, #1\n" + " bne 2b\n" + : "+r"(src), "+r"(dst), "+r"(loops32), "+r"(loops4) : + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "cc"); +} + +/* Ensure the FPGA entering config done */ +static int fpgamgr_program_poll_cd(void) +{ + const uint32_t mask = FPGAMGRREGS_MON_GPIO_EXT_PORTA_NS_MASK | + FPGAMGRREGS_MON_GPIO_EXT_PORTA_CD_MASK; + unsigned long reg, i; + + /* (3) wait until full config done */ + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) { + reg = readl(&fpgamgr_regs->gpio_ext_porta); + + /* Config error */ + if (!(reg & mask)) { + printf("FPGA: Configuration error.\n"); + return -3; + } + + /* Config done without error */ + if (reg & mask) + break; + } + + /* Timeout happened, return error */ + if (i == FPGA_TIMEOUT_CNT) { + printf("FPGA: Timeout waiting for program.\n"); + return -4; + } + + /* Disable AXI configuration */ + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_AXICFGEN_MASK); + + return 0; +} + +/* Ensure the FPGA entering init phase */ +static int fpgamgr_program_poll_initphase(void) +{ + unsigned long i; + + /* Additional clocks for the CB to enter initialization phase */ + if (fpgamgr_dclkcnt_set(0x4)) + return -5; + + /* (4) wait until FPGA enter init phase or user mode */ + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) { + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_INITPHASE) + break; + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_USERMODE) + break; + } + + /* If not in configuration state, return error */ + if (i == FPGA_TIMEOUT_CNT) + return -6; + + return 0; +} + +/* Ensure the FPGA entering user mode */ +static int fpgamgr_program_poll_usermode(void) +{ + unsigned long i; + + /* Additional clocks for the CB to exit initialization phase */ + if (fpgamgr_dclkcnt_set(0x5000)) + return -7; + + /* (5) wait until FPGA enter user mode */ + for (i = 0; i < FPGA_TIMEOUT_CNT; i++) { + if (fpgamgr_get_mode() == FPGAMGRREGS_MODE_USERMODE) + break; + } + /* If not in configuration state, return error */ + if (i == FPGA_TIMEOUT_CNT) + return -8; + + /* To release FPGA Manager drive over configuration line */ + clrbits_le32(&fpgamgr_regs->ctrl, FPGAMGRREGS_CTRL_EN_MASK); + + return 0; +} + +/* + * FPGA Manager to program the FPGA. This is the interface used by FPGA driver. + * Return 0 for sucess, non-zero for error. + */ +int socfpga_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size) +{ + unsigned long status; + + if ((uint32_t)rbf_data & 0x3) { + puts("FPGA: Unaligned data, realign to 32bit boundary.\n"); + return -EINVAL; + } + + /* Prior programming the FPGA, all bridges need to be shut off */ + + /* Disable all signals from hps peripheral controller to fpga */ + writel(0, &sysmgr_regs->fpgaintfgrp_module); + + /* Disable all signals from FPGA to HPS SDRAM */ +#define SDR_CTRLGRP_FPGAPORTRST_ADDRESS 0x5080 + writel(0, SOCFPGA_SDR_ADDRESS + SDR_CTRLGRP_FPGAPORTRST_ADDRESS); + + /* Disable all axi bridge (hps2fpga, lwhps2fpga & fpga2hps) */ + socfpga_bridges_reset(1); + + /* Unmap the bridges from NIC-301 */ + writel(0x1, SOCFPGA_L3REGS_ADDRESS); + + /* Initialize the FPGA Manager */ + status = fpgamgr_program_init(); + if (status) + return status; + + /* Write the RBF data to FPGA Manager */ + fpgamgr_program_write(rbf_data, rbf_size); + + /* Ensure the FPGA entering config done */ + status = fpgamgr_program_poll_cd(); + if (status) + return status; + + /* Ensure the FPGA entering init phase */ + status = fpgamgr_program_poll_initphase(); + if (status) + return status; + + /* Ensure the FPGA entering user mode */ + return fpgamgr_program_poll_usermode(); +} -- cgit v1.2.3