[U-Boot] [PATCH 001/080] mpc8308rdb: Fix style violation

Fix a indention style violation in the freescale MPC8308RDB SDRAM code.
Signed-off-by: Mario Six mario.six@gdsys.cc --- board/freescale/mpc8308rdb/sdram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/board/freescale/mpc8308rdb/sdram.c b/board/freescale/mpc8308rdb/sdram.c index 81e155a401..cea248f724 100644 --- a/board/freescale/mpc8308rdb/sdram.c +++ b/board/freescale/mpc8308rdb/sdram.c @@ -34,7 +34,7 @@ static long fixed_sdram(void) u32 msize_log2 = __ilog2(msize);
out_be32(&im->sysconf.ddrlaw[0].bar, - CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000); + CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000); out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1)); out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);

Fix whitespace style violations in the MPC83xx SPD-SDRAM code.
Signed-off-by: Mario Six mario.six@gdsys.cc --- arch/powerpc/cpu/mpc83xx/spd_sdram.c | 134 +++++++++++++++++------------------ 1 file changed, 67 insertions(+), 67 deletions(-)
diff --git a/arch/powerpc/cpu/mpc83xx/spd_sdram.c b/arch/powerpc/cpu/mpc83xx/spd_sdram.c index 21ab0153fc..48814a09f2 100644 --- a/arch/powerpc/cpu/mpc83xx/spd_sdram.c +++ b/arch/powerpc/cpu/mpc83xx/spd_sdram.c @@ -160,12 +160,13 @@ long int spd_sdram()
/* Read SPD parameters with I2C */ CONFIG_SYS_READ_SPD(SPD_EEPROM_ADDRESS, SPD_EEPROM_OFFSET, - SPD_EEPROM_ADDR_LEN, (uchar *) &spd, sizeof(spd)); + SPD_EEPROM_ADDR_LEN, (uchar *)&spd, sizeof(spd)); #ifdef SPD_DEBUG spd_debug(&spd); #endif /* Check the memory type */ - if (spd.mem_type != SPD_MEMTYPE_DDR && spd.mem_type != SPD_MEMTYPE_DDR2) { + if (spd.mem_type != SPD_MEMTYPE_DDR && + spd.mem_type != SPD_MEMTYPE_DDR2) { debug("DDR: Module mem type is %02X\n", spd.mem_type); return 0; } @@ -185,14 +186,14 @@ long int spd_sdram() /* Check if the number of row of the module is in the range of DDRC */ if (spd.nrow_addr < 12 || spd.nrow_addr > 15) { printf("DDR: Row number is out of range of DDRC, row=%02X\n", - spd.nrow_addr); + spd.nrow_addr); return 0; }
/* Check if the number of col of the module is in the range of DDRC */ if (spd.ncol_addr < 8 || spd.ncol_addr > 11) { printf("DDR: Col number is out of range of DDRC, col=%02X\n", - spd.ncol_addr); + spd.ncol_addr); return 0; }
@@ -223,22 +224,22 @@ long int spd_sdram() | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) | ((spd.nrow_addr - 12) << 8) - | (spd.ncol_addr - 8) ); + | (spd.ncol_addr - 8)); debug("\n"); - debug("cs0_bnds = 0x%08x\n",ddr->csbnds[0].csbnds); - debug("cs0_config = 0x%08x\n",ddr->cs_config[0]); + debug("cs0_bnds = 0x%08x\n", ddr->csbnds[0].csbnds); + debug("cs0_config = 0x%08x\n", ddr->cs_config[0]);
if (n_ranks == 2) { - ddr->csbnds[1].csbnds = ( (banksize(spd.row_dens) >> 8) - | ((banksize(spd.row_dens) >> 23) - 1) ); ddr->cs_config[1] = ( 1<<31 + ddr->csbnds[1].csbnds = ((banksize(spd.row_dens) >> 8) + | ((banksize(spd.row_dens) >> 23) - 1)); | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) | ((spd.nrow_addr - 12) << 8) - | (spd.ncol_addr - 8) ); - debug("cs1_bnds = 0x%08x\n",ddr->csbnds[1].csbnds); - debug("cs1_config = 0x%08x\n",ddr->cs_config[1]); + | (spd.ncol_addr - 8)); + debug("cs1_bnds = 0x%08x\n", ddr->csbnds[1].csbnds); + debug("cs1_config = 0x%08x\n", ddr->cs_config[1]); }
#else @@ -248,22 +249,22 @@ long int spd_sdram() | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) | ((spd.nrow_addr - 12) << 8) - | (spd.ncol_addr - 8) ); + | (spd.ncol_addr - 8)); debug("\n"); - debug("cs2_bnds = 0x%08x\n",ddr->csbnds[2].csbnds); - debug("cs2_config = 0x%08x\n",ddr->cs_config[2]); + debug("cs2_bnds = 0x%08x\n", ddr->csbnds[2].csbnds); + debug("cs2_config = 0x%08x\n", ddr->cs_config[2]);
if (n_ranks == 2) { - ddr->csbnds[3].csbnds = ( (banksize(spd.row_dens) >> 8) - | ((banksize(spd.row_dens) >> 23) - 1) ); ddr->cs_config[3] = ( 1<<31 + ddr->csbnds[3].csbnds = ((banksize(spd.row_dens) >> 8) + | ((banksize(spd.row_dens) >> 23) - 1)); | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) | ((spd.nrow_addr - 12) << 8) - | (spd.ncol_addr - 8) ); - debug("cs3_bnds = 0x%08x\n",ddr->csbnds[3].csbnds); - debug("cs3_config = 0x%08x\n",ddr->cs_config[3]); + | (spd.ncol_addr - 8)); + debug("cs3_bnds = 0x%08x\n", ddr->csbnds[3].csbnds); + debug("cs3_config = 0x%08x\n", ddr->cs_config[3]); } #endif
@@ -304,19 +305,19 @@ long int spd_sdram() * 5.0 5 1001 */ caslat = __ilog2(spd.cas_lat); - if ((spd.mem_type == SPD_MEMTYPE_DDR) - && (caslat > 6)) { + if (spd.mem_type == SPD_MEMTYPE_DDR && + caslat > 6) { printf("DDR I: Invalid SPD CAS Latency: 0x%x.\n", spd.cas_lat); return 0; - } else if (spd.mem_type == SPD_MEMTYPE_DDR2 - && (caslat < 2 || caslat > 5)) { + } else if (spd.mem_type == SPD_MEMTYPE_DDR2 && + (caslat < 2 || caslat > 5)) { printf("DDR II: Invalid SPD CAS Latency: 0x%x.\n", spd.cas_lat); return 0; } debug("DDR: caslat SPD bit is %d\n", caslat);
- max_bus_clk = 1000 *10 / (((spd.clk_cycle & 0xF0) >> 4) * 10 + max_bus_clk = 1000 * 10 / (((spd.clk_cycle & 0xF0) >> 4) * 10 + (spd.clk_cycle & 0x0f)); max_data_rate = max_bus_clk * 2;
@@ -332,7 +333,7 @@ long int spd_sdram() caslat = 4; if (ddrc_clk <= 460 && ddrc_clk > 350) effective_data_rate = 400; - else if (ddrc_clk <=350 && ddrc_clk > 280) + else if (ddrc_clk <= 350 && ddrc_clk > 280) effective_data_rate = 333; else if (ddrc_clk <= 280 && ddrc_clk > 230) effective_data_rate = 266; @@ -395,7 +396,7 @@ long int spd_sdram() if (ddrc_clk <= 350 && ddrc_clk > 280) { /* DDR controller clk at 280~350 */ printf("DDR: DDR controller freq is more than " - "max data rate of the module\n"); + "max data rate of the module\n"); return 0; } else if (ddrc_clk <= 280 && ddrc_clk > 230) { /* DDR controller clk at 230~280 */ @@ -411,7 +412,7 @@ long int spd_sdram() if (ddrc_clk <= 350 && ddrc_clk > 230) { /* DDR controller clk at 230~350 */ printf("DDR: DDR controller freq is more than " - "max data rate of the module\n"); + "max data rate of the module\n"); return 0; } else if (ddrc_clk <= 230 && ddrc_clk > 90) { /* DDR controller clk at 90~230 */ @@ -427,7 +428,7 @@ long int spd_sdram() * Errata DDR6 work around: input enable 2 cycles earlier. * including MPC834x Rev1.0/1.1 and MPC8360 Rev1.1/1.2. */ - if(PVR_MAJ(pvr) <= 1 && spd.mem_type == SPD_MEMTYPE_DDR){ + if (PVR_MAJ(pvr) <= 1 && spd.mem_type == SPD_MEMTYPE_DDR) { if (caslat == 2) ddr->debug_reg = 0x201c0000; /* CL=2 */ else if (caslat == 3) @@ -528,11 +529,11 @@ long int spd_sdram() trfc_low = (trfc_clk - 8) & 0xf;
ddr->timing_cfg_1 = - (((picos_to_clk(spd.trp * 250) & 0x07) << 28 ) | /* PRETOACT */ - ((picos_to_clk(spd.tras * 1000) & 0x0f ) << 24 ) | /* ACTTOPRE */ - (trcd_clk << 20 ) | /* ACTTORW */ - (caslat_ctrl << 16 ) | /* CASLAT */ - (trfc_low << 12 ) | /* REFEC */ + (((picos_to_clk(spd.trp * 250) & 0x07) << 28) | /* PRETOACT */ + ((picos_to_clk(spd.tras * 1000) & 0x0f) << 24) | /* ACTTOPRE */ + (trcd_clk << 20) | /* ACTTORW */ + (caslat_ctrl << 16) | /* CASLAT */ + (trfc_low << 12) | /* REFEC */ ((twr_clk & 0x07) << 8) | /* WRRREC */ ((picos_to_clk(spd.trrd * 250) & 0x07) << 4) | /* ACTTOACT */ ((twtr_clk & 0x07) << 0) /* WRTORD */ @@ -704,33 +705,33 @@ long int spd_sdram() debug("DDR: sdram_mode2 = 0x%08x\n", ddr->sdram_mode2);
switch (spd.refresh) { - case 0x00: - case 0x80: - refresh_clk = picos_to_clk(15625000); - break; - case 0x01: - case 0x81: - refresh_clk = picos_to_clk(3900000); - break; - case 0x02: - case 0x82: - refresh_clk = picos_to_clk(7800000); - break; - case 0x03: - case 0x83: - refresh_clk = picos_to_clk(31300000); - break; - case 0x04: - case 0x84: - refresh_clk = picos_to_clk(62500000); - break; - case 0x05: - case 0x85: - refresh_clk = picos_to_clk(125000000); - break; - default: - refresh_clk = 0x512; - break; + case 0x00: + case 0x80: + refresh_clk = picos_to_clk(15625000); + break; + case 0x01: + case 0x81: + refresh_clk = picos_to_clk(3900000); + break; + case 0x02: + case 0x82: + refresh_clk = picos_to_clk(7800000); + break; + case 0x03: + case 0x83: + refresh_clk = picos_to_clk(31300000); + break; + case 0x04: + case 0x84: + refresh_clk = picos_to_clk(62500000); + break; + case 0x05: + case 0x85: + refresh_clk = picos_to_clk(125000000); + break; + default: + refresh_clk = 0x512; + break; }
/* @@ -823,7 +824,7 @@ long int spd_sdram() debug("DDR:err_disable=0x%08x\n", ddr->err_disable); debug("DDR:err_sbe=0x%08x\n", ddr->err_sbe); #endif - debug(" DDRC ECC mode: %s\n", ddrc_ecc_enable ? "ON":"OFF"); + debug(" DDRC ECC mode: %s\n", ddrc_ecc_enable ? "ON" : "OFF");
#if defined(CONFIG_DDR_2T_TIMING) /* @@ -866,7 +867,7 @@ static __inline__ unsigned long get_tbms (void) tmp = (unsigned long long)(tbu1); tmp = (tmp << 32); tmp += (unsigned long long)(tbl); - ms = tmp/(tbclk/1000); + ms = tmp / (tbclk / 1000);
return ms; } @@ -877,7 +878,7 @@ static __inline__ unsigned long get_tbms (void) void ddr_enable_ecc(unsigned int dram_size) { volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; - volatile ddr83xx_t *ddr= &immap->ddr; + volatile ddr83xx_t *ddr = &immap->ddr; unsigned long t_start, t_end; register u64 *p; register uint size; @@ -893,9 +894,8 @@ void ddr_enable_ecc(unsigned int dram_size) #else debug("ddr init: CPU FP write method\n"); size = dram_size; - for (p = 0; p < (u64*)(size); p++) { - ppcDWstore((u32*)p, pattern); - } + for (p = 0; p < (u64 *)(size); p++) + ppcDWstore((u32 *)p, pattern); __asm__ __volatile__ ("sync"); #endif

Dear Mario,
In message 20170929125238.26226-2-mario.six@gdsys.cc you wrote:
Fix whitespace style violations in the MPC83xx SPD-SDRAM code.
...
ddr->csbnds[1].csbnds = ( (banksize(spd.row_dens) >> 8)
ddr->cs_config[1] = ( 1<<31| ((banksize(spd.row_dens) >> 23) - 1) );
ddr->csbnds[1].csbnds = ((banksize(spd.row_dens) >> 8)
| ((banksize(spd.row_dens) >> 23) - 1)); | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) | ((spd.nrow_addr - 12) << 8)
This looks as if you were changing the code, and not only whitespace ?
I would expect that this does not even compile!
Which sort of testing did you give to this patch series?
Best regards,
Wolfgang Denk

Hi Wolfgang,
On Fri, Sep 29, 2017 at 4:03 PM, Wolfgang Denk wd@denx.de wrote:
Dear Mario,
In message 20170929125238.26226-2-mario.six@gdsys.cc you wrote:
Fix whitespace style violations in the MPC83xx SPD-SDRAM code.
...
ddr->csbnds[1].csbnds = ( (banksize(spd.row_dens) >> 8)
| ((banksize(spd.row_dens) >> 23) - 1) ); ddr->cs_config[1] = ( 1<<31
ddr->csbnds[1].csbnds = ((banksize(spd.row_dens) >> 8)
| ((banksize(spd.row_dens) >> 23) - 1)); | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) | ((spd.nrow_addr - 12) << 8)
This looks as if you were changing the code, and not only whitespace ?
I would expect that this does not even compile!
Argh, something went wrong when I split the commits; this and the next commit were originally a single commit, but I split them in order to be more readable (the next commit fixes the order of the lines again).
Which sort of testing did you give to this patch series?
I tested the final, and some of the larger patches using buildman, but not these ones. I'll put the entire series through the wringer for v2. Terribly sorry for that.
Best regards,
Wolfgang Denk
Best regards,
Mario

Fix style violations in the MPC83xx SPD-SDRAM code and make the code more readable.
Signed-off-by: Mario Six mario.six@gdsys.cc --- arch/powerpc/cpu/mpc83xx/spd_sdram.c | 49 ++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
diff --git a/arch/powerpc/cpu/mpc83xx/spd_sdram.c b/arch/powerpc/cpu/mpc83xx/spd_sdram.c index 48814a09f2..f9c41cbeb7 100644 --- a/arch/powerpc/cpu/mpc83xx/spd_sdram.c +++ b/arch/powerpc/cpu/mpc83xx/spd_sdram.c @@ -172,11 +172,10 @@ long int spd_sdram() }
/* Check the number of physical bank */ - if (spd.mem_type == SPD_MEMTYPE_DDR) { + if (spd.mem_type == SPD_MEMTYPE_DDR) n_ranks = spd.nrows; - } else { + else n_ranks = (spd.nrows & 0x7) + 1; - }
if (n_ranks > 2) { printf("DDR: The number of physical bank is %02X\n", n_ranks); @@ -201,10 +200,9 @@ long int spd_sdram() /* * Adjust DDR II IO voltage biasing. It just makes it work. */ - if(spd.mem_type == SPD_MEMTYPE_DDR2) { + if (spd.mem_type == SPD_MEMTYPE_DDR2) immap->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; - } - udelay(50000); + mdelay(50); #endif
/* @@ -212,14 +210,13 @@ long int spd_sdram() */ odt_rd_cfg = 0; /* Never assert ODT */ odt_wr_cfg = 0; /* Never assert ODT */ - if (spd.mem_type == SPD_MEMTYPE_DDR2) { + if (spd.mem_type == SPD_MEMTYPE_DDR2) odt_wr_cfg = 1; /* Assert ODT on writes to CSn */ - }
/* Setup DDR chip select register */ #ifdef CONFIG_SYS_83XX_DDR_USES_CS0 ddr->csbnds[0].csbnds = (banksize(spd.row_dens) >> 24) - 1; - ddr->cs_config[0] = ( 1 << 31 + ddr->cs_config[0] = (BIT(31) | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) @@ -230,9 +227,9 @@ long int spd_sdram() debug("cs0_config = 0x%08x\n", ddr->cs_config[0]);
if (n_ranks == 2) { - ddr->cs_config[1] = ( 1<<31 ddr->csbnds[1].csbnds = ((banksize(spd.row_dens) >> 8) | ((banksize(spd.row_dens) >> 23) - 1)); + ddr->cs_config[1] = (BIT(31) | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) @@ -244,7 +241,7 @@ long int spd_sdram()
#else ddr->csbnds[2].csbnds = (banksize(spd.row_dens) >> 24) - 1; - ddr->cs_config[2] = ( 1 << 31 + ddr->cs_config[2] = (BIT(31) | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) @@ -255,9 +252,9 @@ long int spd_sdram() debug("cs2_config = 0x%08x\n", ddr->cs_config[2]);
if (n_ranks == 2) { - ddr->cs_config[3] = ( 1<<31 ddr->csbnds[3].csbnds = ((banksize(spd.row_dens) >> 8) | ((banksize(spd.row_dens) >> 23) - 1)); + ddr->cs_config[3] = (BIT(31) | (odt_rd_cfg << 20) | (odt_wr_cfg << 16) | ((spd.nbanks == 8 ? 1 : 0) << 14) @@ -445,11 +442,10 @@ long int spd_sdram() * Convert caslat clocks to DDR controller value. * Force caslat_ctrl to be DDR Controller field-sized. */ - if (spd.mem_type == SPD_MEMTYPE_DDR) { + if (spd.mem_type == SPD_MEMTYPE_DDR) caslat_ctrl = (caslat + 1) & 0x07; - } else { + else caslat_ctrl = (2 * caslat - 1) & 0x0f; - }
debug("DDR: effective data rate is %d MHz\n", effective_data_rate); debug("DDR: caslat SPD bit is %d, controller field is 0x%x\n", @@ -547,13 +543,12 @@ long int spd_sdram() * add_lat + caslat must be >= 4 */ add_lat = 0; - if (spd.mem_type == SPD_MEMTYPE_DDR2 - && (odt_wr_cfg || odt_rd_cfg) - && (caslat < 4)) { + if (spd.mem_type == SPD_MEMTYPE_DDR2 && + (odt_wr_cfg || odt_rd_cfg) && + caslat < 4) { add_lat = 4 - caslat; - if ((add_lat + caslat) < 4) { + if ((add_lat + caslat) < 4) add_lat = 0; - } }
/* @@ -652,7 +647,7 @@ long int spd_sdram() debug(" without ECC\n");
/* Burst length is always 4 for 64 bit data bus, 8 for 32 bit data bus, - Burst type is sequential + * Burst type is sequential */ if (spd.mem_type == SPD_MEMTYPE_DDR) { switch (caslat) { @@ -685,9 +680,9 @@ long int spd_sdram()
ddr->sdram_mode = (0 - | (1 << (16 + 10)) /* DQS Differential disable */ + | BIT(16 + 10) /* DQS Differential disable */ #ifdef CONFIG_SYS_DDR_MODE_WEAK - | (1 << (16 + 1)) /* weak driver (~60%) */ + | BIT(16 + 1) /* weak driver (~60%) */ #endif | (add_lat << (16 + 3)) /* Additive Latency in EMRS1 */ | (mode_odt_enable << 16) /* ODT Enable in EMRS1 */ @@ -746,9 +741,8 @@ long int spd_sdram() */ odt_cfg = 0; #ifndef CONFIG_NEVER_ASSERT_ODT_TO_CPU - if (odt_rd_cfg | odt_wr_cfg) { + if (odt_rd_cfg | odt_wr_cfg) odt_cfg = 0x2; /* ODT to IOs during reads */ - } #endif if (spd.mem_type == SPD_MEMTYPE_DDR2) { ddr->sdram_cfg2 = (0 @@ -816,7 +810,8 @@ long int spd_sdram() /* disable error detection */ ddr->err_disable = ~ECC_ERROR_ENABLE; /* set single bit error threshold to maximum value, - * reset counter to zero */ + * reset counter to zero + */ ddr->err_sbe = (255 << ECC_ERROR_MAN_SBET_SHIFT) | (0 << ECC_ERROR_MAN_SBEC_SHIFT); } @@ -847,7 +842,7 @@ long int spd_sdram() * Use timebase counter, get_timer() is not available * at this point of initialization yet. */ -static __inline__ unsigned long get_tbms (void) +static inline unsigned long get_tbms (void) { unsigned long tbl; unsigned long tbu1, tbu2;

There are some typos in the documentation of some functions in read.h; fix those.
Signed-off-by: Mario Six mario.six@gdsys.cc --- include/dm/read.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/dm/read.h b/include/dm/read.h index 8114037e97..d2f47a678f 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -255,7 +255,7 @@ int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, * This walks back up the tree to find the closest #address-cells property * which controls the given node. * - * @dev: devioe to check + * @dev: device to check * @return number of address cells this node uses */ int dev_read_addr_cells(struct udevice *dev); @@ -266,7 +266,7 @@ int dev_read_addr_cells(struct udevice *dev); * This walks back up the tree to find the closest #size-cells property * which controls the given node. * - * @dev: devioe to check + * @dev: device to check * @return number of size cells this node uses */ int dev_read_size_cells(struct udevice *dev); @@ -276,7 +276,7 @@ int dev_read_size_cells(struct udevice *dev); * * This function matches fdt_address_cells(). * - * @dev: devioe to check + * @dev: device to check * @return number of address cells this node uses */ int dev_read_simple_addr_cells(struct udevice *dev); @@ -286,7 +286,7 @@ int dev_read_simple_addr_cells(struct udevice *dev); * * This function matches fdt_size_cells(). * - * @dev: devioe to check + * @dev: device to check * @return number of size cells this node uses */ int dev_read_simple_size_cells(struct udevice *dev);

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
There are some typos in the documentation of some functions in read.h; fix those.
Signed-off-by: Mario Six mario.six@gdsys.cc
include/dm/read.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Fix some whitespace-related style violations in fdtdec.c.
Signed-off-by: Mario Six mario.six@gdsys.cc --- lib/fdtdec.c | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-)
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 107a892e79..f354a1f9af 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -80,8 +80,9 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id) }
fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node, - const char *prop_name, int index, int na, int ns, - fdt_size_t *sizep, bool translate) + const char *prop_name, int index, int na, + int ns, fdt_size_t *sizep, + bool translate) { const fdt32_t *prop, *prop_end; const fdt32_t *prop_addr, *prop_size, *prop_after_size; @@ -135,8 +136,9 @@ fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node, }
fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent, - int node, const char *prop_name, int index, fdt_size_t *sizep, - bool translate) + int node, const char *prop_name, + int index, fdt_size_t *sizep, + bool translate) { int na, ns;
@@ -161,8 +163,9 @@ fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent, }
fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node, - const char *prop_name, int index, fdt_size_t *sizep, - bool translate) + const char *prop_name, int index, + fdt_size_t *sizep, + bool translate) { int parent;
@@ -179,7 +182,7 @@ fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node, }
fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, - const char *prop_name, fdt_size_t *sizep) + const char *prop_name, fdt_size_t *sizep) { int ns = sizep ? (sizeof(fdt_size_t) / sizeof(fdt32_t)) : 0;
@@ -188,15 +191,14 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, ns, sizep, false); }
-fdt_addr_t fdtdec_get_addr(const void *blob, int node, - const char *prop_name) +fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name) { return fdtdec_get_addr_size(blob, node, prop_name, NULL); }
#if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI) int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, - const char *prop_name, struct fdt_pci_addr *addr) + const char *prop_name, struct fdt_pci_addr *addr) { const u32 *cell; int len; @@ -305,7 +307,7 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, #endif
uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, - uint64_t default_val) + uint64_t default_val) { const uint64_t *cell64; int length; @@ -346,14 +348,13 @@ enum fdt_compat_id fdtdec_lookup(const void *blob, int node) return COMPAT_UNKNOWN; }
-int fdtdec_next_compatible(const void *blob, int node, - enum fdt_compat_id id) +int fdtdec_next_compatible(const void *blob, int node, enum fdt_compat_id id) { return fdt_node_offset_by_compatible(blob, node, compat_names[id]); }
int fdtdec_next_compatible_subnode(const void *blob, int node, - enum fdt_compat_id id, int *depthp) + enum fdt_compat_id id, int *depthp) { do { node = fdt_next_node(blob, node, depthp); @@ -367,8 +368,8 @@ int fdtdec_next_compatible_subnode(const void *blob, int node, return -FDT_ERR_NOTFOUND; }
-int fdtdec_next_alias(const void *blob, const char *name, - enum fdt_compat_id id, int *upto) +int fdtdec_next_alias(const void *blob, const char *name, enum fdt_compat_id id, + int *upto) { #define MAX_STR_LEN 20 char str[MAX_STR_LEN + 20]; @@ -390,7 +391,8 @@ int fdtdec_next_alias(const void *blob, const char *name, }
int fdtdec_find_aliases_for_id(const void *blob, const char *name, - enum fdt_compat_id id, int *node_list, int maxcount) + enum fdt_compat_id id, int *node_list, + int maxcount) { memset(node_list, '\0', sizeof(*node_list) * maxcount);
@@ -399,7 +401,8 @@ int fdtdec_find_aliases_for_id(const void *blob, const char *name,
/* TODO: Can we tighten this code up a little? */ int fdtdec_add_aliases_for_id(const void *blob, const char *name, - enum fdt_compat_id id, int *node_list, int maxcount) + enum fdt_compat_id id, int *node_list, + int maxcount) { int name_len = strlen(name); int nodes[maxcount]; @@ -426,7 +429,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name, } if (node >= 0) debug("%s: warning: maxcount exceeded with alias '%s'\n", - __func__, name); + __func__, name);
/* Now find all the aliases */ for (offset = fdt_first_property_offset(blob, alias_node); @@ -449,7 +452,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name, number = simple_strtoul(path + name_len, NULL, 10); if (number < 0 || number >= maxcount) { debug("%s: warning: alias '%s' is out of range\n", - __func__, path); + __func__, path); continue; }
@@ -495,7 +498,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name, if (!node_list[i]) { for (; j < maxcount; j++) if (nodes[j] && - fdtdec_get_is_enabled(blob, nodes[j])) + fdtdec_get_is_enabled(blob, nodes[j])) break;
/* Have we run out of nodes to add? */ @@ -638,7 +641,8 @@ int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) * @return pointer to cell, which is only valid if err == 0 */ static const void *get_prop_check_min_len(const void *blob, int node, - const char *prop_name, int min_len, int *err) + const char *prop_name, int min_len, + int *err) { const void *cell; int len; @@ -655,7 +659,7 @@ static const void *get_prop_check_min_len(const void *blob, int node, }
int fdtdec_get_int_array(const void *blob, int node, const char *prop_name, - u32 *array, int count) + u32 *array, int count) { const u32 *cell; int i, err = 0; @@ -847,7 +851,7 @@ int fdtdec_get_child_count(const void *blob, int node) }
int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, - u8 *array, int count) + u8 *array, int count) { const u8 *cell; int err; @@ -859,7 +863,7 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, }
const u8 *fdtdec_locate_byte_array(const void *blob, int node, - const char *prop_name, int count) + const char *prop_name, int count) { const u8 *cell; int err; @@ -871,7 +875,7 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node, }
int fdtdec_get_config_int(const void *blob, const char *prop_name, - int default_val) + int default_val) { int config_node;

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Fix some whitespace-related style violations in fdtdec.c.
Signed-off-by: Mario Six mario.six@gdsys.cc
lib/fdtdec.c | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Fix some style violations in fdtdec.c, and reduce the scope of some variables.
Signed-off-by: Mario Six mario.six@gdsys.cc --- lib/fdtdec.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index f354a1f9af..b291c155a9 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -230,10 +230,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, addr->phys_mid = fdt32_to_cpu(cell[1]); addr->phys_lo = fdt32_to_cpu(cell[1]); break; - } else { - cell += (FDT_PCI_ADDR_CELLS + - FDT_PCI_SIZE_CELLS); } + + cell += (FDT_PCI_ADDR_CELLS + + FDT_PCI_SIZE_CELLS); }
if (i == num) { @@ -242,10 +242,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, }
return 0; - } else { - ret = -EINVAL; }
+ ret = -EINVAL; + fail: debug("(not found)\n"); return ret; @@ -262,11 +262,9 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
end = list + len; while (list < end) { - char *s; - len = strlen(list); if (len >= strlen("pciVVVV,DDDD")) { - s = strstr(list, "pci"); + char *s = strstr(list, "pci");
/* * check if the string is something like pciVVVV,DDDD.RR @@ -296,7 +294,7 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
/* extract the bar number from fdt_pci_addr */ barnum = addr->phys_hi & 0xff; - if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS)) + if (barnum < PCI_BASE_ADDRESS_0 || barnum > PCI_CARDBUS_CIS) return -EINVAL;
barnum = (barnum - PCI_BASE_ADDRESS_0) / 4; @@ -332,7 +330,7 @@ int fdtdec_get_is_enabled(const void *blob, int node) */ cell = fdt_getprop(blob, node, "status", NULL); if (cell) - return 0 == strcmp(cell, "okay"); + return strcmp(cell, "okay") == 0; return 1; }
@@ -342,8 +340,8 @@ enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
/* Search our drivers */ for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++) - if (0 == fdt_node_check_compatible(blob, node, - compat_names[id])) + if (fdt_node_check_compatible(blob, node, + compat_names[id]) == 0) return id; return COMPAT_UNKNOWN; } @@ -662,12 +660,14 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name, u32 *array, int count) { const u32 *cell; - int i, err = 0; + int err = 0;
debug("%s: %s\n", __func__, prop_name); cell = get_prop_check_min_len(blob, node, prop_name, sizeof(u32) * count, &err); if (!err) { + int i; + for (i = 0; i < count; i++) array[i] = fdt32_to_cpu(cell[i]); } @@ -972,7 +972,8 @@ int fdt_get_resource(const void *fdt, int node, const char *property,
while (ptr + na + ns <= end) { if (i == index) { - res->start = res->end = fdtdec_get_number(ptr, na); + res->start = fdtdec_get_number(ptr, na); + res->end = res->start; res->end += fdtdec_get_number(&ptr[na], ns) - 1; return 0; } @@ -1224,7 +1225,7 @@ int fdtdec_setup(void) # elif defined CONFIG_FIT_EMBED gd->fdt_blob = locate_dtb_in_fit(&_end);
- if (gd->fdt_blob == NULL || gd->fdt_blob <= ((void *)&_end)) { + if (!gd->fdt_blob || gd->fdt_blob <= ((void *)&_end)) { puts("Failed to find proper dtb in embedded FIT Image\n"); return -1; }

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Fix some style violations in fdtdec.c, and reduce the scope of some variables.
Signed-off-by: Mario Six mario.six@gdsys.cc
lib/fdtdec.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

There are some style violations in ofnode.c; fix those.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/core/ofnode.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index c6ca13fabf..a59e40aa97 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -296,7 +296,8 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, int ret;
ret = of_parse_phandle_with_args(ofnode_to_np(node), - list_name, cells_name, index, &args); + list_name, cells_name, index, + &args); if (ret) return ret; ofnode_from_of_phandle_args(&args, out_args); @@ -305,8 +306,9 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name, int ret;
ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, - ofnode_to_offset(node), list_name, cells_name, - cell_count, index, &args); + ofnode_to_offset(node), + list_name, cells_name, + cell_count, index, &args); if (ret) return ret; ofnode_from_fdtdec_phandle_args(&args, out_args); @@ -532,10 +534,10 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, addr->phys_mid = fdt32_to_cpu(cell[1]); addr->phys_lo = fdt32_to_cpu(cell[1]); break; - } else { - cell += (FDT_PCI_ADDR_CELLS + - FDT_PCI_SIZE_CELLS); } + + cell += (FDT_PCI_ADDR_CELLS + + FDT_PCI_SIZE_CELLS); }
if (i == num) { @@ -544,10 +546,10 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, }
return 0; - } else { - ret = -EINVAL; }
+ ret = -EINVAL; + fail: debug("(not found)\n"); return ret;

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
There are some style violations in ofnode.c; fix those.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/core/ofnode.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

There are some whitespace-related style violations in read.c; fix those.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/core/read.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/core/read.c b/drivers/core/read.c index eacf1716fd..2766d228a6 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -65,7 +65,7 @@ void *dev_read_addr_ptr(struct udevice *dev) }
fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property, - fdt_size_t *sizep) + fdt_size_t *sizep) { return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); } @@ -76,7 +76,7 @@ const char *dev_read_name(struct udevice *dev) }
int dev_read_stringlist_search(struct udevice *dev, const char *property, - const char *string) + const char *string) { return ofnode_stringlist_search(dev_ofnode(dev), property, string); } @@ -93,9 +93,8 @@ int dev_read_string_count(struct udevice *dev, const char *propname) }
int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, - const char *cells_name, int cell_count, - int index, - struct ofnode_phandle_args *out_args) + const char *cells_name, int cell_count, + int index, struct ofnode_phandle_args *out_args) { return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, cells_name, cell_count, index,

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
There are some whitespace-related style violations in read.c; fix those.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/core/read.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/core/ofnode.c | 8 ++++++++ drivers/core/read.c | 5 +++++ include/dm/ofnode.h | 13 +++++++++++++ include/dm/read.h | 17 +++++++++++++++++ 4 files changed, 43 insertions(+)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index a59e40aa97..7f2c98614e 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -642,3 +642,11 @@ int ofnode_read_resource_byname(ofnode node, const char *name,
return ofnode_read_resource(node, index, res); } + +u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr) +{ + if (ofnode_is_np(node)) + return of_translate_address(ofnode_to_np(node), in_addr); + else + return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr); +} diff --git a/drivers/core/read.c b/drivers/core/read.c index 2766d228a6..f35ff57246 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -187,3 +187,8 @@ int dev_read_resource_byname(struct udevice *dev, const char *name, { return ofnode_read_resource_byname(dev_ofnode(dev), name, res); } + +u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) +{ + return ofnode_translate_address(dev_ofnode(dev), in_addr); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 79374b8f91..92ffeebf16 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -652,4 +652,17 @@ int ofnode_read_resource_byname(ofnode node, const char *name, ofnode_valid(node); \ node = ofnode_next_subnode(node))
+/** + * ofnode_translate_address() - Tranlate a device-tree address + * + * Translate an address from the device-tree into a CPU physical address. This + * function walks up the tree and applies the various bus mappings along the + * way. + * + * @ofnode: Device tree node giving the context in which to translate the + * address + * @in_addr: pointer to the address to translate + * @return the translated address; OF_BAD_ADDR on error + */ +u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr); #endif diff --git a/include/dm/read.h b/include/dm/read.h index d2f47a678f..d88a6c547e 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -410,6 +410,18 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res); int dev_read_resource_byname(struct udevice *dev, const char *name, struct resource *res);
+/** + * dev_translate_address() - Tranlate a device-tree address + * + * Translate an address from the device-tree into a CPU physical address. This + * function walks up the tree and applies the various bus mappings along the + * way. + * + * @dev: device giving the context in which to translate the address + * @in_addr: pointer to the address to translate + * @return the translated address; OF_BAD_ADDR on error + */ +u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
static inline int dev_read_u32_default(struct udevice *dev, @@ -582,6 +594,11 @@ static inline int dev_read_resource_byname(struct udevice *dev, return ofnode_read_resource_byname(dev_ofnode(dev), name, res); }
+static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) +{ + return ofnode_translate_address(dev_ofnode(dev), in_addr); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */
/**

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/core/ofnode.c | 8 ++++++++ drivers/core/read.c | 5 +++++ include/dm/ofnode.h | 13 +++++++++++++ include/dm/read.h | 17 +++++++++++++++++ 4 files changed, 43 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Judging from its name and parameters, device_is_compatible looks like it is compatible with a live device tree, but it actually isn't.
Make is compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/core/device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/core/device.c b/drivers/core/device.c index 5463d1ffa5..23de6a6246 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -17,6 +17,7 @@ #include <dm/device.h> #include <dm/device-internal.h> #include <dm/lists.h> +#include <dm/of_access.h> #include <dm/pinctrl.h> #include <dm/platdata.h> #include <dm/read.h> @@ -702,8 +703,12 @@ int device_set_name(struct udevice *dev, const char *name) bool device_is_compatible(struct udevice *dev, const char *compat) { const void *fdt = gd->fdt_blob; + ofnode node = dev_ofnode(dev);
- return !fdt_node_check_compatible(fdt, dev_of_offset(dev), compat); + if (ofnode_is_np(node)) + return of_device_is_compatible(ofnode_to_np(node), compat, NULL, NULL); + else + return !fdt_node_check_compatible(fdt, ofnode_to_offset(node), compat); }
bool of_machine_is_compatible(const char *compat)

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Judging from its name and parameters, device_is_compatible looks like it is compatible with a live device tree, but it actually isn't.
Make is compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/core/device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

checkpatch.pl complains that the clk_ops structures used in clk-uclass.c ought to be static, so we mark them as static.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/clk/clk-uclass.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 83ba13374c..32be2e85c5 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -15,9 +15,9 @@
DECLARE_GLOBAL_DATA_PTR;
-static inline struct clk_ops *clk_dev_ops(struct udevice *dev) +static inline const struct clk_ops *clk_dev_ops(struct udevice *dev) { - return (struct clk_ops *)dev->driver->ops; + return (const struct clk_ops *)dev->driver->ops; }
#if CONFIG_IS_ENABLED(OF_CONTROL) @@ -60,7 +60,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) int ret; struct ofnode_phandle_args args; struct udevice *dev_clk; - struct clk_ops *ops; + const struct clk_ops *ops;
debug("%s(dev=%p, index=%d, clk=%p)\n", __func__, dev, index, clk);
@@ -68,7 +68,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) clk->dev = NULL;
ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0, - index, &args); + index, &args); if (ret) { debug("%s: fdtdec_parse_phandle_with_args failed: err=%d\n", __func__, ret); @@ -142,7 +142,7 @@ int clk_release_all(struct clk *clk, int count)
int clk_request(struct udevice *dev, struct clk *clk) { - struct clk_ops *ops = clk_dev_ops(dev); + const struct clk_ops *ops = clk_dev_ops(dev);
debug("%s(dev=%p, clk=%p)\n", __func__, dev, clk);
@@ -156,7 +156,7 @@ int clk_request(struct udevice *dev, struct clk *clk)
int clk_free(struct clk *clk) { - struct clk_ops *ops = clk_dev_ops(clk->dev); + const struct clk_ops *ops = clk_dev_ops(clk->dev);
debug("%s(clk=%p)\n", __func__, clk);
@@ -168,7 +168,7 @@ int clk_free(struct clk *clk)
ulong clk_get_rate(struct clk *clk) { - struct clk_ops *ops = clk_dev_ops(clk->dev); + const struct clk_ops *ops = clk_dev_ops(clk->dev);
debug("%s(clk=%p)\n", __func__, clk);
@@ -180,7 +180,7 @@ ulong clk_get_rate(struct clk *clk)
ulong clk_set_rate(struct clk *clk, ulong rate) { - struct clk_ops *ops = clk_dev_ops(clk->dev); + const struct clk_ops *ops = clk_dev_ops(clk->dev);
debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
@@ -192,7 +192,7 @@ ulong clk_set_rate(struct clk *clk, ulong rate)
int clk_enable(struct clk *clk) { - struct clk_ops *ops = clk_dev_ops(clk->dev); + const struct clk_ops *ops = clk_dev_ops(clk->dev);
debug("%s(clk=%p)\n", __func__, clk);
@@ -204,7 +204,7 @@ int clk_enable(struct clk *clk)
int clk_disable(struct clk *clk) { - struct clk_ops *ops = clk_dev_ops(clk->dev); + const struct clk_ops *ops = clk_dev_ops(clk->dev);
debug("%s(clk=%p)\n", __func__, clk);

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
checkpatch.pl complains that the clk_ops structures used in clk-uclass.c ought to be static, so we mark them as static.
Do you mean static, or const?
Otherwise:
Reviewed-by: Simon Glass sjg@chromium.org
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/clk/clk-uclass.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 83ba13374c..32be2e85c5 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -15,9 +15,9 @@
DECLARE_GLOBAL_DATA_PTR;
-static inline struct clk_ops *clk_dev_ops(struct udevice *dev) +static inline const struct clk_ops *clk_dev_ops(struct udevice *dev) {
return (struct clk_ops *)dev->driver->ops;
return (const struct clk_ops *)dev->driver->ops;
}
#if CONFIG_IS_ENABLED(OF_CONTROL) @@ -60,7 +60,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) int ret; struct ofnode_phandle_args args; struct udevice *dev_clk;
struct clk_ops *ops;
const struct clk_ops *ops; debug("%s(dev=%p, index=%d, clk=%p)\n", __func__, dev, index, clk);
@@ -68,7 +68,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk) clk->dev = NULL;
ret = dev_read_phandle_with_args(dev, "clocks", "#clock-cells", 0,
index, &args);
index, &args); if (ret) { debug("%s: fdtdec_parse_phandle_with_args failed: err=%d\n", __func__, ret);
@@ -142,7 +142,7 @@ int clk_release_all(struct clk *clk, int count)
int clk_request(struct udevice *dev, struct clk *clk) {
struct clk_ops *ops = clk_dev_ops(dev);
const struct clk_ops *ops = clk_dev_ops(dev); debug("%s(dev=%p, clk=%p)\n", __func__, dev, clk);
@@ -156,7 +156,7 @@ int clk_request(struct udevice *dev, struct clk *clk)
int clk_free(struct clk *clk) {
struct clk_ops *ops = clk_dev_ops(clk->dev);
const struct clk_ops *ops = clk_dev_ops(clk->dev); debug("%s(clk=%p)\n", __func__, clk);
@@ -168,7 +168,7 @@ int clk_free(struct clk *clk)
ulong clk_get_rate(struct clk *clk) {
struct clk_ops *ops = clk_dev_ops(clk->dev);
const struct clk_ops *ops = clk_dev_ops(clk->dev); debug("%s(clk=%p)\n", __func__, clk);
@@ -180,7 +180,7 @@ ulong clk_get_rate(struct clk *clk)
ulong clk_set_rate(struct clk *clk, ulong rate) {
struct clk_ops *ops = clk_dev_ops(clk->dev);
const struct clk_ops *ops = clk_dev_ops(clk->dev); debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
@@ -192,7 +192,7 @@ ulong clk_set_rate(struct clk *clk, ulong rate)
int clk_enable(struct clk *clk) {
struct clk_ops *ops = clk_dev_ops(clk->dev);
const struct clk_ops *ops = clk_dev_ops(clk->dev); debug("%s(clk=%p)\n", __func__, clk);
@@ -204,7 +204,7 @@ int clk_enable(struct clk *clk)
int clk_disable(struct clk *clk) {
struct clk_ops *ops = clk_dev_ops(clk->dev);
const struct clk_ops *ops = clk_dev_ops(clk->dev); debug("%s(clk=%p)\n", __func__, clk);
-- 2.11.0

Hi Simon,
On Mon, Oct 9, 2017 at 6:46 AM, Simon Glass sjg@chromium.org wrote:
On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
checkpatch.pl complains that the clk_ops structures used in clk-uclass.c ought to be static, so we mark them as static.
Do you mean static, or const?
I meant const; I'll fix the commit message and text in v2.
Otherwise:
Reviewed-by: Simon Glass sjg@chromium.org
Best regards,
Mario

Fix a mis-indented function call in clk_fixed_rate.c
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/clk/clk_fixed_rate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clk_fixed_rate.c b/drivers/clk/clk_fixed_rate.c index 63565b6ed8..9dd6bc5726 100644 --- a/drivers/clk/clk_fixed_rate.c +++ b/drivers/clk/clk_fixed_rate.c @@ -31,8 +31,8 @@ const struct clk_ops clk_fixed_rate_ops = { static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev) { #if !CONFIG_IS_ENABLED(OF_PLATDATA) - to_clk_fixed_rate(dev)->fixed_rate = dev_read_u32_default(dev, - "clock-frequency", 0); + to_clk_fixed_rate(dev)->fixed_rate = + dev_read_u32_default(dev, "clock-frequency", 0); #endif
return 0;

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Fix a mis-indented function call in clk_fixed_rate.c
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/clk/clk_fixed_rate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

The clk uclass was converted to support a live device tree recently, hence the global data pointer declarations are no longer needed.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/clk/clk-uclass.c | 2 -- drivers/clk/clk_fixed_rate.c | 2 -- 2 files changed, 4 deletions(-)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 32be2e85c5..fbea72091b 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -13,8 +13,6 @@ #include <dt-structs.h> #include <errno.h>
-DECLARE_GLOBAL_DATA_PTR; - static inline const struct clk_ops *clk_dev_ops(struct udevice *dev) { return (const struct clk_ops *)dev->driver->ops; diff --git a/drivers/clk/clk_fixed_rate.c b/drivers/clk/clk_fixed_rate.c index 9dd6bc5726..c9a9f0a20b 100644 --- a/drivers/clk/clk_fixed_rate.c +++ b/drivers/clk/clk_fixed_rate.c @@ -8,8 +8,6 @@ #include <clk-uclass.h> #include <dm.h>
-DECLARE_GLOBAL_DATA_PTR; - struct clk_fixed_rate { unsigned long fixed_rate; };

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
The clk uclass was converted to support a live device tree recently, hence the global data pointer declarations are no longer needed.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/clk/clk-uclass.c | 2 -- drivers/clk/clk_fixed_rate.c | 2 -- 2 files changed, 4 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

This patch fixes a printf specifier style violation, reduces the scope of a variable, and turns a void pointer that is used with pointer arithmetic into a u8 pointer.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/spi/spi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 7d81fbd7f8..dea8dcda5b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -12,7 +12,7 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) { if (wordlen == 0 || wordlen > 32) { - printf("spi: invalid wordlen %d\n", wordlen); + printf("spi: invalid wordlen %u\n", wordlen); return -1; }
@@ -24,11 +24,12 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen) void *spi_do_alloc_slave(int offset, int size, unsigned int bus, unsigned int cs) { - struct spi_slave *slave; - void *ptr; + u8 *ptr;
ptr = malloc(size); if (ptr) { + struct spi_slave *slave; + memset(ptr, '\0', size); slave = (struct spi_slave *)(ptr + offset); slave->bus = bus;

0efc024 ("spi_flash: Add spi_flash_probe_fdt() to locate SPI by FDT node") added a helper function spi_base_setup_slave_fdt to to set up a SPI slave from a given FDT blob. The only user was the exynos SPI driver.
But commit 73186c9 ("dm: exynos: Convert SPI to driver model") removed the use of this function, hence rendering it obsolete.
Remove this function, as well as the CONFIG_OF_SPI option, which guarded only this function.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/spi/spi.c | 20 -------------------- include/spi.h | 14 -------------- scripts/config_whitelist.txt | 1 - 3 files changed, 35 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index dea8dcda5b..45e73d28e4 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -39,23 +39,3 @@ void *spi_do_alloc_slave(int offset, int size, unsigned int bus,
return ptr; } - -#ifdef CONFIG_OF_SPI -struct spi_slave *spi_base_setup_slave_fdt(const void *blob, int busnum, - int node) -{ - int cs, max_hz, mode = 0; - - cs = fdtdec_get_int(blob, node, "reg", -1); - max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", 100000); - if (fdtdec_get_bool(blob, node, "spi-cpol")) - mode |= SPI_CPOL; - if (fdtdec_get_bool(blob, node, "spi-cpha")) - mode |= SPI_CPHA; - if (fdtdec_get_bool(blob, node, "spi-cs-high")) - mode |= SPI_CS_HIGH; - if (fdtdec_get_bool(blob, node, "spi-half-duplex")) - mode |= SPI_PREAMBLE; - return spi_setup_slave(busnum, cs, max_hz, mode); -} -#endif diff --git a/include/spi.h b/include/spi.h index 8c4b882c54..9c69cd7e87 100644 --- a/include/spi.h +++ b/include/spi.h @@ -328,20 +328,6 @@ static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte) */ struct spi_slave *spi_setup_slave_fdt(const void *blob, int slave_node, int spi_node); - -/** - * spi_base_setup_slave_fdt() - helper function to set up a SPI slace - * - * This decodes SPI properties from the slave node to determine the - * chip select and SPI parameters. - * - * @blob: Device tree blob - * @busnum: Bus number to use - * @node: Device tree node for the SPI bus - */ -struct spi_slave *spi_base_setup_slave_fdt(const void *blob, int busnum, - int node); - #ifdef CONFIG_DM_SPI
/** diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index db5d88b4b5..0dbe8986a6 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -1614,7 +1614,6 @@ CONFIG_NUM_PAMU CONFIG_ODROID_REV_AIN CONFIG_OFF_PADCONF CONFIG_OF_ -CONFIG_OF_SPI CONFIG_OF_SPI_FLASH CONFIG_OF_STDOUT_PATH CONFIG_OMAP_EHCI_PHY1_RESET_GPIO

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
0efc024 ("spi_flash: Add spi_flash_probe_fdt() to locate SPI by FDT node") added a helper function spi_base_setup_slave_fdt to to set up a SPI slave from a given FDT blob. The only user was the exynos SPI driver.
But commit 73186c9 ("dm: exynos: Convert SPI to driver model") removed the use of this function, hence rendering it obsolete.
Remove this function, as well as the CONFIG_OF_SPI option, which guarded only this function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/spi/spi.c | 20 -------------------- include/spi.h | 14 -------------- scripts/config_whitelist.txt | 1 - 3 files changed, 35 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Sep 29, 2017 at 6:21 PM, Mario Six mario.six@gdsys.cc wrote:
0efc024 ("spi_flash: Add spi_flash_probe_fdt() to locate SPI by FDT node") added a helper function spi_base_setup_slave_fdt to to set up a SPI slave from a given FDT blob. The only user was the exynos SPI driver.
But commit 73186c9 ("dm: exynos: Convert SPI to driver model") removed the use of this function, hence rendering it obsolete.
Remove this function, as well as the CONFIG_OF_SPI option, which guarded only this function.
Signed-off-by: Mario Six mario.six@gdsys.cc
Reviewed-by: Jagan Teki jagan@openedev.com
thanks!

Commit ba45756 ("dm: x86: spi: Convert ICH SPI driver to driver model") removed the last usage of the spi_flash_probe_fdt function, rendering it obsolete.
This patch removes the function.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/spi/sf_probe.c | 13 ------------- include/spi_flash.h | 12 ------------ 2 files changed, 25 deletions(-)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 7b296378d2..e25513b77a 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -87,19 +87,6 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, return spi_flash_probe_tail(bus); }
-#ifdef CONFIG_OF_SPI_FLASH -struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node, - int spi_node) -{ - struct spi_slave *bus; - - bus = spi_setup_slave_fdt(blob, slave_node, spi_node); - if (!bus) - return NULL; - return spi_flash_probe_tail(bus); -} -#endif - void spi_flash_free(struct spi_flash *flash) { #ifdef CONFIG_SPI_FLASH_MTD diff --git a/include/spi_flash.h b/include/spi_flash.h index be2fe3f84c..f3c4e83424 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -194,18 +194,6 @@ void sandbox_sf_unbind_emul(struct sandbox_state *state, int busnum, int cs); struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int spi_mode);
-/** - * Set up a new SPI flash from an fdt node - * - * @param blob Device tree blob - * @param slave_node Pointer to this SPI slave node in the device tree - * @param spi_node Cached pointer to the SPI interface this node belongs - * to - * @return 0 if ok, -1 on error - */ -struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node, - int spi_node); - void spi_flash_free(struct spi_flash *flash);
static inline int spi_flash_read(struct spi_flash *flash, u32 offset,

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Commit ba45756 ("dm: x86: spi: Convert ICH SPI driver to driver model") removed the last usage of the spi_flash_probe_fdt function, rendering it obsolete.
This patch removes the function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/mtd/spi/sf_probe.c | 13 ------------- include/spi_flash.h | 12 ------------ 2 files changed, 25 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Sep 29, 2017 at 6:21 PM, Mario Six mario.six@gdsys.cc wrote:
Commit ba45756 ("dm: x86: spi: Convert ICH SPI driver to driver model") removed the last usage of the spi_flash_probe_fdt function, rendering it obsolete.
This patch removes the function.
Signed-off-by: Mario Six mario.six@gdsys.cc
Reviewed-by: Jagan Teki jagan@openedev.com
thanks!

A previous patch removed the spi_flash_probe_fdt function, which contained the last call of the spi_setup_slave_fdt function, which is now equally obsolete.
This patch removes the function.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/spi/spi-uclass.c | 16 ---------------- include/spi.h | 13 ------------- 2 files changed, 29 deletions(-)
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index e06a603ab1..6db0eb02b4 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -348,22 +348,6 @@ err: }
/* Compatibility function - to be removed */ -struct spi_slave *spi_setup_slave_fdt(const void *blob, int node, - int bus_node) -{ - struct udevice *bus, *dev; - int ret; - - ret = uclass_get_device_by_of_offset(UCLASS_SPI, bus_node, &bus); - if (ret) - return NULL; - ret = device_get_child_by_of_offset(bus, node, &dev); - if (ret) - return NULL; - return dev_get_parent_priv(dev); -} - -/* Compatibility function - to be removed */ struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, unsigned int speed, unsigned int mode) { diff --git a/include/spi.h b/include/spi.h index 9c69cd7e87..ebaf2e5f3a 100644 --- a/include/spi.h +++ b/include/spi.h @@ -315,19 +315,6 @@ static inline int spi_w8r8(struct spi_slave *slave, unsigned char byte) return ret < 0 ? ret : din[1]; }
-/** - * Set up a SPI slave for a particular device tree node - * - * This calls spi_setup_slave() with the correct bus number. Call - * spi_free_slave() to free it later. - * - * @param blob: Device tree blob - * @param slave_node: Slave node to use - * @param spi_node: SPI peripheral node to use - * @return pointer to new spi_slave structure - */ -struct spi_slave *spi_setup_slave_fdt(const void *blob, int slave_node, - int spi_node); #ifdef CONFIG_DM_SPI
/**

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
A previous patch removed the spi_flash_probe_fdt function, which contained the last call of the spi_setup_slave_fdt function, which is now equally obsolete.
This patch removes the function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/spi/spi-uclass.c | 16 ---------------- include/spi.h | 13 ------------- 2 files changed, 29 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Sep 29, 2017 at 6:21 PM, Mario Six mario.six@gdsys.cc wrote:
A previous patch removed the spi_flash_probe_fdt function, which contained the last call of the spi_setup_slave_fdt function, which is now equally obsolete.
This patch removes the function.
Signed-off-by: Mario Six mario.six@gdsys.cc
Reviewed-by: Jagan Teki jagan@openedev.com
thanks!

Previous patches removed the last usages of this config variable, so that it is now obsolete.
This patch removes it from the whitelist.
Signed-off-by: Mario Six mario.six@gdsys.cc --- scripts/config_whitelist.txt | 1 - 1 file changed, 1 deletion(-)
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index 0dbe8986a6..f8236beef5 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -1614,7 +1614,6 @@ CONFIG_NUM_PAMU CONFIG_ODROID_REV_AIN CONFIG_OFF_PADCONF CONFIG_OF_ -CONFIG_OF_SPI_FLASH CONFIG_OF_STDOUT_PATH CONFIG_OMAP_EHCI_PHY1_RESET_GPIO CONFIG_OMAP_EHCI_PHY2_RESET_GPIO

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Previous patches removed the last usages of this config variable, so that it is now obsolete.
This patch removes it from the whitelist.
Signed-off-by: Mario Six mario.six@gdsys.cc
scripts/config_whitelist.txt | 1 - 1 file changed, 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Sep 29, 2017 at 6:21 PM, Mario Six mario.six@gdsys.cc wrote:
Previous patches removed the last usages of this config variable, so that it is now obsolete.
This patch removes it from the whitelist.
Signed-off-by: Mario Six mario.six@gdsys.cc
Reviewed-by: Jagan Teki jagan@openedev.com
thanks!

Fix two indention-related style violations.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/spi/sf_probe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index e25513b77a..68009a6328 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -77,7 +77,7 @@ static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus) }
struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode) + unsigned int max_hz, unsigned int spi_mode) { struct spi_slave *bus;
@@ -107,7 +107,7 @@ static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len, }
static int spi_flash_std_write(struct udevice *dev, u32 offset, size_t len, - const void *buf) + const void *buf) { struct spi_flash *flash = dev_get_uclass_priv(dev);

Remove a superfluous newline, and reduce the scope of a variable.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/spi/spi-uclass.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 6db0eb02b4..15d90a54a1 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -50,7 +50,6 @@ int dm_spi_claim_bus(struct udevice *dev) struct dm_spi_bus *spi = dev_get_uclass_priv(bus); struct spi_slave *slave = dev_get_parent_priv(dev); int speed; - int ret;
speed = slave->max_hz; if (spi->max_hz) { @@ -62,7 +61,8 @@ int dm_spi_claim_bus(struct udevice *dev) if (!speed) speed = 100000; if (speed != slave->speed) { - ret = spi_set_speed_mode(bus, speed, slave->mode); + int ret = spi_set_speed_mode(bus, speed, slave->mode); + if (ret) return ret; slave->speed = speed; @@ -129,7 +129,6 @@ static int spi_post_probe(struct udevice *bus) #if defined(CONFIG_NEEDS_MANUAL_RELOC) struct dm_spi_ops *ops = spi_get_ops(bus);
- if (ops->claim_bus) ops->claim_bus += gd->reloc_off; if (ops->release_bus)

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Remove a superfluous newline, and reduce the scope of a variable.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/spi/spi-uclass.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Sep 29, 2017 at 6:21 PM, Mario Six mario.six@gdsys.cc wrote:
Remove a superfluous newline, and reduce the scope of a variable.
Signed-off-by: Mario Six mario.six@gdsys.cc
Reviewed-by: Jagan Teki jagan@openedev.com
thanks!

spi_flash_probe_tail is now only called from spi_flash_probe, hence we can merge its body into spi_flash_probe.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/spi/sf_probe.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 68009a6328..09143d7868 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -55,10 +55,16 @@ err_read_id: }
#ifndef CONFIG_DM_SPI_FLASH -static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus) +struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, + unsigned int max_hz, unsigned int spi_mode) { + struct spi_slave *bus; struct spi_flash *flash;
+ bus = spi_setup_slave(busnum, cs, max_hz, spi_mode); + if (!bus) + return NULL; + /* Allocate space if needed (not used by sf-uclass */ flash = calloc(1, sizeof(*flash)); if (!flash) { @@ -76,17 +82,6 @@ static struct spi_flash *spi_flash_probe_tail(struct spi_slave *bus) return flash; }
-struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode) -{ - struct spi_slave *bus; - - bus = spi_setup_slave(busnum, cs, max_hz, spi_mode); - if (!bus) - return NULL; - return spi_flash_probe_tail(bus); -} - void spi_flash_free(struct spi_flash *flash) { #ifdef CONFIG_SPI_FLASH_MTD

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
spi_flash_probe_tail is now only called from spi_flash_probe, hence we can merge its body into spi_flash_probe.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/mtd/spi/sf_probe.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/net/tsec.c | 72 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 35 deletions(-)
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index 18e7a83d0f..aa261845f3 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -74,11 +74,11 @@ static void tsec_configure_serdes(struct tsec_private *priv) * to the register offset used for external PHY accesses */ tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa), - 0, TBI_ANA, TBIANA_SETTINGS); + 0, TBI_ANA, TBIANA_SETTINGS); tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa), - 0, TBI_TBICON, TBICON_CLK_SELECT); + 0, TBI_TBICON, TBICON_CLK_SELECT); tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa), - 0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS); + 0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS); }
#ifdef CONFIG_MCAST_TFTP @@ -116,7 +116,7 @@ static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int set) whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */ whichreg = result >> 29; /* the 3 MSB = which reg to set it in */
- value = 1 << (31-whichbit); + value = BIT(31 - whichbit);
if (set) setbits_be32(®s->hash.gaddr0 + whichreg, value); @@ -171,7 +171,6 @@ static void init_registers(struct tsec __iomem *regs)
out_be32(®s->attr, ATTR_INIT_SETTINGS); out_be32(®s->attreli, ATTRELI_INIT_SETTINGS); - }
/* @@ -222,8 +221,8 @@ static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) out_be32(®s->maccfg2, maccfg2);
printf("Speed: %d, %s duplex%s\n", phydev->speed, - (phydev->duplex) ? "full" : "half", - (phydev->port == PORT_FIBRE) ? ", fiber mode" : ""); + (phydev->duplex) ? "full" : "half", + (phydev->port == PORT_FIBRE) ? ", fiber mode" : ""); }
/* @@ -240,7 +239,7 @@ static int tsec_send(struct udevice *dev, void *packet, int length) { struct tsec_private *priv = (struct tsec_private *)dev->priv; struct tsec __iomem *regs = priv->regs; - uint16_t status; + u16 status; int result = 0; int i;
@@ -287,7 +286,7 @@ static int tsec_recv(struct eth_device *dev)
while (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) { int length = in_be16(&priv->rxbd[priv->rx_idx].length); - uint16_t status = in_be16(&priv->rxbd[priv->rx_idx].status); + u16 status = in_be16(&priv->rxbd[priv->rx_idx].status); uchar *packet = net_rx_packets[priv->rx_idx];
/* Send the packet up if there were no errors */ @@ -323,8 +322,8 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
if (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) { int length = in_be16(&priv->rxbd[priv->rx_idx].length); - uint16_t status = in_be16(&priv->rxbd[priv->rx_idx].status); - uint32_t buf; + u16 status = in_be16(&priv->rxbd[priv->rx_idx].status); + u32 buf;
/* Send the packet up if there were no errors */ if (!(status & RXBD_STATS)) { @@ -347,7 +346,7 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp) static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length) { struct tsec_private *priv = (struct tsec_private *)dev->priv; - uint16_t status; + u16 status;
out_be16(&priv->rxbd[priv->rx_idx].length, 0);
@@ -427,7 +426,8 @@ void redundant_init(struct tsec_private *priv) clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
do { - uint16_t status; + u16 status; + tsec_send(priv->dev, (void *)pkt, sizeof(pkt));
/* Wait for buffer to be received */ @@ -478,7 +478,7 @@ void redundant_init(struct tsec_private *priv) static void startup_tsec(struct tsec_private *priv) { struct tsec __iomem *regs = priv->regs; - uint16_t status; + u16 status; int i;
/* reset the indices to zero */ @@ -532,7 +532,7 @@ static void startup_tsec(struct tsec_private *priv) * This allows U-Boot to find the first active controller. */ #ifndef CONFIG_DM_ETH -static int tsec_init(struct eth_device *dev, bd_t * bd) +static int tsec_init(struct eth_device *dev, bd_t *bd) #else static int tsec_init(struct udevice *dev) #endif @@ -616,22 +616,23 @@ static phy_interface_t tsec_get_interface(struct tsec_private *priv) }
if (ecntrl & ECNTRL_REDUCED_MODE) { + phy_interface_t interface; + if (ecntrl & ECNTRL_REDUCED_MII_MODE) return PHY_INTERFACE_MODE_RMII; - else { - phy_interface_t interface = priv->interface; - - /* - * This isn't autodetected, so it must - * be set by the platform code. - */ - if ((interface == PHY_INTERFACE_MODE_RGMII_ID) || - (interface == PHY_INTERFACE_MODE_RGMII_TXID) || - (interface == PHY_INTERFACE_MODE_RGMII_RXID)) - return interface; - - return PHY_INTERFACE_MODE_RGMII; - } + + interface = priv->interface; + + /* + * This isn't autodetected, so it must + * be set by the platform code. + */ + if (interface == PHY_INTERFACE_MODE_RGMII_ID || + interface == PHY_INTERFACE_MODE_RGMII_TXID || + interface == PHY_INTERFACE_MODE_RGMII_RXID) + return interface; + + return PHY_INTERFACE_MODE_RGMII; }
if (priv->flags & TSEC_GIGABIT) @@ -691,16 +692,16 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info) int i; struct tsec_private *priv;
- dev = (struct eth_device *)malloc(sizeof *dev); + dev = (struct eth_device *)malloc(sizeof(*dev));
- if (NULL == dev) + if (!dev) return 0;
- memset(dev, 0, sizeof *dev); + memset(dev, 0, sizeof(*dev));
priv = (struct tsec_private *)malloc(sizeof(*priv));
- if (NULL == priv) + if (!priv) { return 0;
priv->regs = tsec_info->regs; @@ -747,10 +748,11 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info) int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num) { int i; - int ret, count = 0; + int count = 0;
for (i = 0; i < num; i++) { - ret = tsec_initialize(bis, &tsecs[i]); + int ret = tsec_initialize(bis, &tsecs[i]); + if (ret > 0) count += ret; }

tsec_initialize allocates a private driver structure using malloc. Should the memory allocation of this private structure fail, the function execution is aborted with a return 0, but the previously allocated device structure is never freed, hence leaked.
Free the device structure in the error case.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/net/tsec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index aa261845f3..44140fb037 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -702,7 +702,9 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info) priv = (struct tsec_private *)malloc(sizeof(*priv));
if (!priv) { + free(dev); return 0; + }
priv->regs = tsec_info->regs; priv->phyregs_sgmii = tsec_info->miiregs_sgmii;

Make the tsec ethernet driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/net/tsec.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index 44140fb037..3eb09e93b2 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -20,8 +20,6 @@ #include <asm/processor.h> #include <asm/io.h>
-DECLARE_GLOBAL_DATA_PTR; - #ifndef CONFIG_DM_ETH /* Default initializations for TSEC controllers. */
@@ -779,45 +777,42 @@ int tsec_probe(struct udevice *dev) struct tsec_private *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_platdata(dev); struct fsl_pq_mdio_info mdio_info; - int offset = 0; - int reg; + struct ofnode_phandle_args phandle_args; + ofnode parent; const char *phy_mode; int ret;
- pdata->iobase = (phys_addr_t)devfdt_get_addr(dev); + pdata->iobase = (phys_addr_t)dev_read_addr(dev); priv->regs = (struct tsec *)pdata->iobase;
- offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev), - "phy-handle"); - if (offset > 0) { - reg = fdtdec_get_int(gd->fdt_blob, offset, "reg", 0); - priv->phyaddr = reg; - } else { + if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, + &phandle_args)) { debug("phy-handle does not exist under tsec %s\n", dev->name); return -ENOENT; + } else { + int reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); + priv->phyaddr = reg; }
- offset = fdt_parent_offset(gd->fdt_blob, offset); - if (offset > 0) { - reg = fdtdec_get_int(gd->fdt_blob, offset, "reg", 0); + parent = ofnode_get_parent(phandle_args.node); + if (ofnode_valid(parent)) { + int reg = ofnode_read_u32_default(parent, "reg", 0); priv->phyregs_sgmii = (struct tsec_mii_mng *)(reg + 0x520); } else { debug("No parent node for PHY?\n"); return -ENOENT; }
- offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev), - "tbi-handle"); - if (offset > 0) { - reg = fdtdec_get_int(gd->fdt_blob, offset, "reg", - CONFIG_SYS_TBIPA_VALUE); - priv->tbiaddr = reg; - } else { + if (dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0, + &phandle_args)) { priv->tbiaddr = CONFIG_SYS_TBIPA_VALUE; + } else { + int reg = ofnode_read_u32_default(phandle_args.node, "reg", + CONFIG_SYS_TBIPA_VALUE); + priv->tbiaddr = reg; }
- phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), - "phy-connection-type", NULL); + phy_mode = dev_read_prop(dev, "phy-connection-type", NULL); if (phy_mode) pdata->phy_interface = phy_get_interface_by_name(phy_mode); if (pdata->phy_interface == -1) {

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Make the tsec ethernet driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/net/tsec.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Fix some style violations in the fsl_i2c I2C driver, and use shorter type names for variables in some cases.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/i2c/fsl_i2c.c | 111 +++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 55 deletions(-)
diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c index ff3dc25927..d957cf6286 100644 --- a/drivers/i2c/fsl_i2c.c +++ b/drivers/i2c/fsl_i2c.c @@ -116,10 +116,10 @@ static const struct { * * The return value is the actual bus speed that is set. */ -static unsigned int set_i2c_bus_speed(const struct fsl_i2c_base *base, - unsigned int i2c_clk, unsigned int speed) +static uint set_i2c_bus_speed(const struct fsl_i2c_base *base, + uint i2c_clk, uint speed) { - unsigned short divider = min(i2c_clk / speed, (unsigned int)USHRT_MAX); + ushort divider = min(i2c_clk / speed, (uint)USHRT_MAX);
/* * We want to choose an FDR/DFSR that generates an I2C bus speed that @@ -130,8 +130,8 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c_base *base, #ifdef __PPC__ u8 dfsr, fdr = 0x31; /* Default if no FDR found */ /* a, b and dfsr matches identifiers A,B and C respectively in AN2919 */ - unsigned short a, b, ga, gb; - unsigned long c_div, est_div; + ushort a, b, ga, gb; + ulong c_div, est_div;
#ifdef CONFIG_FSL_I2C_CUSTOM_DFSR dfsr = CONFIG_FSL_I2C_CUSTOM_DFSR; @@ -151,18 +151,21 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c_base *base, for (ga = 0x4, a = 10; a <= 30; ga++, a += 2) { for (gb = 0; gb < 8; gb++) { b = 16 << gb; - c_div = b * (a + ((3*dfsr)/b)*2); - if ((c_div > divider) && (c_div < est_div)) { - unsigned short bin_gb, bin_ga; + c_div = b * (a + ((3 * dfsr) / b) * 2); + if (c_div > divider && c_div < est_div) { + ushort bin_gb, bin_ga;
est_div = c_div; bin_gb = gb << 2; bin_ga = (ga & 0x3) | ((ga & 0x4) << 3); fdr = bin_gb | bin_ga; speed = i2c_clk / est_div; - debug("FDR:0x%.2x, div:%ld, ga:0x%x, gb:0x%x, " - "a:%d, b:%d, speed:%d\n", - fdr, est_div, ga, gb, a, b, speed); + + debug("FDR: 0x%.2x, ", fdr); + debug("div: %ld, ", est_div); + debug("ga: 0x%x, gb: 0x%x, ", ga, gb); + debug("a: %d, b: %d, speed: %d\n", a, b, speed); + /* Condition 2 not accounted for */ debug("Tr <= %d ns\n", (b - 3 * dfsr) * 1000000 / @@ -174,13 +177,13 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c_base *base, if (a == 24) a += 4; } - debug("divider:%d, est_div:%ld, DFSR:%d\n", divider, est_div, dfsr); - debug("FDR:0x%.2x, speed:%d\n", fdr, speed); + debug("divider: %d, est_div: %ld, DFSR: %d\n", divider, est_div, dfsr); + debug("FDR: 0x%.2x, speed: %d\n", fdr, speed); #endif writeb(dfsr, &base->dfsrr); /* set default filter */ writeb(fdr, &base->fdr); /* set bus speed */ #else - unsigned int i; + uint i;
for (i = 0; i < ARRAY_SIZE(fsl_i2c_speed_map); i++) if (fsl_i2c_speed_map[i].divider >= divider) { @@ -197,7 +200,7 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c_base *base, }
#ifndef CONFIG_DM_I2C -static unsigned int get_i2c_clock(int bus) +static uint get_i2c_clock(int bus) { if (bus) return gd->arch.i2c2_clk; /* I2C2 clock */ @@ -211,10 +214,11 @@ static int fsl_i2c_fixup(const struct fsl_i2c_base *base) const unsigned long long timeout = usec2ticks(CONFIG_I2C_MBB_TIMEOUT); unsigned long long timeval = 0; int ret = -1; - unsigned int flags = 0; + uint flags = 0;
#ifdef CONFIG_SYS_FSL_ERRATUM_I2C_A004447 - unsigned int svr = get_svr(); + uint svr = get_svr(); + if ((SVR_SOC_VER(svr) == SVR_8548 && IS_SVR_REV(svr, 3, 1)) || (SVR_REV(svr) <= CONFIG_SYS_FSL_A004447_SVR_REV)) flags = I2C_CR_BIT6; @@ -263,7 +267,7 @@ static void __i2c_init(const struct fsl_i2c_base *base, int speed, int /* Call board specific i2c bus reset routine before accessing the * environment, which might be in a chip on that bus. For details * about this problem see doc/I2C_Edge_Conditions. - */ + */ i2c_init_board(); #endif writeb(0, &base->cr); /* stop I2C controller */ @@ -286,8 +290,7 @@ static void __i2c_init(const struct fsl_i2c_base *base, int speed, int } }
-static int -i2c_wait4bus(const struct fsl_i2c_base *base) +static int i2c_wait4bus(const struct fsl_i2c_base *base) { unsigned long long timeval = get_ticks(); const unsigned long long timeout = usec2ticks(CONFIG_I2C_MBB_TIMEOUT); @@ -300,8 +303,7 @@ i2c_wait4bus(const struct fsl_i2c_base *base) return 0; }
-static inline int -i2c_wait(const struct fsl_i2c_base *base, int write) +static inline int i2c_wait(const struct fsl_i2c_base *base, int write) { u32 csr; unsigned long long timeval = get_ticks(); @@ -317,29 +319,29 @@ i2c_wait(const struct fsl_i2c_base *base, int write) writeb(0x0, &base->sr);
if (csr & I2C_SR_MAL) { - debug("i2c_wait: MAL\n"); + debug("%s: MAL\n", __func__); return -1; }
if (!(csr & I2C_SR_MCF)) { - debug("i2c_wait: unfinished\n"); + debug("%s: unfinished\n", __func__); return -1; }
if (write == I2C_WRITE_BIT && (csr & I2C_SR_RXAK)) { - debug("i2c_wait: No RXACK\n"); + debug("%s: No RXACK\n", __func__); return -1; }
return 0; } while ((get_ticks() - timeval) < timeout);
- debug("i2c_wait: timed out\n"); + debug("%s: timed out\n", __func__); return -1; }
-static inline int -i2c_write_addr(const struct fsl_i2c_base *base, u8 dev, u8 dir, int rsta) +static inline int i2c_write_addr(const struct fsl_i2c_base *base, u8 dev, + u8 dir, int rsta) { writeb(I2C_CR_MEN | I2C_CR_MSTA | I2C_CR_MTX | (rsta ? I2C_CR_RSTA : 0), @@ -353,8 +355,8 @@ i2c_write_addr(const struct fsl_i2c_base *base, u8 dev, u8 dir, int rsta) return 1; }
-static inline int -__i2c_write_data(const struct fsl_i2c_base *base, u8 *data, int length) +static inline int __i2c_write_data(const struct fsl_i2c_base *base, u8 *data, + int length) { int i;
@@ -368,8 +370,8 @@ __i2c_write_data(const struct fsl_i2c_base *base, u8 *data, int length) return i; }
-static inline int -__i2c_read_data(const struct fsl_i2c_base *base, u8 *data, int length) +static inline int __i2c_read_data(const struct fsl_i2c_base *base, u8 *data, + int length) { int i;
@@ -399,9 +401,8 @@ __i2c_read_data(const struct fsl_i2c_base *base, u8 *data, int length) return i; }
-static int -__i2c_read(const struct fsl_i2c_base *base, u8 chip_addr, u8 *offset, int olen, - u8 *data, int dlen) +static int __i2c_read(const struct fsl_i2c_base *base, u8 chip_addr, u8 *offset, + int olen, u8 *data, int dlen) { int ret = -1; /* signal error */
@@ -447,9 +448,8 @@ __i2c_read(const struct fsl_i2c_base *base, u8 chip_addr, u8 *offset, int olen, return -1; }
-static int -__i2c_write(const struct fsl_i2c_base *base, u8 chip_addr, u8 *offset, int olen, - u8 *data, int dlen) +static int __i2c_write(const struct fsl_i2c_base *base, u8 chip_addr, + u8 *offset, int olen, u8 *data, int dlen) { int ret = -1; /* signal error */
@@ -471,10 +471,9 @@ __i2c_write(const struct fsl_i2c_base *base, u8 chip_addr, u8 *offset, int olen, return -1; }
-static int -__i2c_probe_chip(const struct fsl_i2c_base *base, uchar chip) +static int __i2c_probe_chip(const struct fsl_i2c_base *base, uchar chip) { - /* For unknow reason the controller will ACK when + /* For unknown reason the controller will ACK when * probing for a slave with the same address, so skip * it. */ @@ -484,8 +483,8 @@ __i2c_probe_chip(const struct fsl_i2c_base *base, uchar chip) return __i2c_read(base, chip, 0, 0, NULL, 0); }
-static unsigned int __i2c_set_bus_speed(const struct fsl_i2c_base *base, - unsigned int speed, int i2c_clk) +static uint __i2c_set_bus_speed(const struct fsl_i2c_base *base, + uint speed, int i2c_clk) { writeb(0, &base->cr); /* stop controller */ set_i2c_bus_speed(base, i2c_clk, speed); @@ -501,32 +500,30 @@ static void fsl_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd) get_i2c_clock(adap->hwadapnr), adap->hwadapnr); }
-static int -fsl_i2c_probe_chip(struct i2c_adapter *adap, uchar chip) +static int fsl_i2c_probe_chip(struct i2c_adapter *adap, uchar chip) { return __i2c_probe_chip(i2c_base[adap->hwadapnr], chip); }
-static int -fsl_i2c_read(struct i2c_adapter *adap, u8 chip_addr, uint offset, int olen, - u8 *data, int dlen) +static int fsl_i2c_read(struct i2c_adapter *adap, u8 chip_addr, uint offset, + int olen, u8 *data, int dlen) { u8 *o = (u8 *)&offset; + return __i2c_read(i2c_base[adap->hwadapnr], chip_addr, &o[4 - olen], olen, data, dlen); }
-static int -fsl_i2c_write(struct i2c_adapter *adap, u8 chip_addr, uint offset, int olen, - u8 *data, int dlen) +static int fsl_i2c_write(struct i2c_adapter *adap, u8 chip_addr, uint offset, + int olen, u8 *data, int dlen) { u8 *o = (u8 *)&offset; + return __i2c_write(i2c_base[adap->hwadapnr], chip_addr, &o[4 - olen], olen, data, dlen); }
-static unsigned int fsl_i2c_set_bus_speed(struct i2c_adapter *adap, - unsigned int speed) +static uint fsl_i2c_set_bus_speed(struct i2c_adapter *adap, uint speed) { return __i2c_set_bus_speed(i2c_base[adap->hwadapnr], speed, get_i2c_clock(adap->hwadapnr)); @@ -562,12 +559,14 @@ static int fsl_i2c_probe_chip(struct udevice *bus, u32 chip_addr, u32 chip_flags) { struct fsl_i2c_dev *dev = dev_get_priv(bus); + return __i2c_probe_chip(dev->base, chip_addr); }
-static int fsl_i2c_set_bus_speed(struct udevice *bus, unsigned int speed) +static int fsl_i2c_set_bus_speed(struct udevice *bus, uint speed) { struct fsl_i2c_dev *dev = dev_get_priv(bus); + return __i2c_set_bus_speed(dev->base, speed, dev->i2c_clk); }
@@ -600,6 +599,7 @@ static int fsl_i2c_ofdata_to_platdata(struct udevice *bus) static int fsl_i2c_probe(struct udevice *bus) { struct fsl_i2c_dev *dev = dev_get_priv(bus); + __i2c_init(dev->base, dev->speed, dev->slaveadd, dev->i2c_clk, dev->index); return 0; @@ -613,7 +613,8 @@ static int fsl_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) memset(&dummy, 0, sizeof(struct i2c_msg));
/* We expect either two messages (one with an offset and one with the - * actucal data) or one message (just data) */ + * actual data) or one message (just data) + */ if (nmsgs > 2 || nmsgs == 0) { debug("%s: Only one or two messages are supported.", __func__); return -1; -- 2.11.0

Hello Mario,
Am 29.09.2017 um 14:51 schrieb Mario Six:
Fix some style violations in the fsl_i2c I2C driver, and use shorter type names for variables in some cases.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/i2c/fsl_i2c.c | 111 +++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 55 deletions(-)
Reviewed-by: Heiko Schocherh@denx.de
bye, Heiko

Some functions in the fsl_i2c driver are declared as inline, even though they are quite large, which needlessly increases the size of the resulting binary.
This patch removes the inline declarations.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/i2c/fsl_i2c.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c index d957cf6286..a7f3ec472f 100644 --- a/drivers/i2c/fsl_i2c.c +++ b/drivers/i2c/fsl_i2c.c @@ -303,7 +303,7 @@ static int i2c_wait4bus(const struct fsl_i2c_base *base) return 0; }
-static inline int i2c_wait(const struct fsl_i2c_base *base, int write) +static int i2c_wait(const struct fsl_i2c_base *base, int write) { u32 csr; unsigned long long timeval = get_ticks(); @@ -340,8 +340,8 @@ static inline int i2c_wait(const struct fsl_i2c_base *base, int write) return -1; }
-static inline int i2c_write_addr(const struct fsl_i2c_base *base, u8 dev, - u8 dir, int rsta) +static int i2c_write_addr(const struct fsl_i2c_base *base, u8 dev, + u8 dir, int rsta) { writeb(I2C_CR_MEN | I2C_CR_MSTA | I2C_CR_MTX | (rsta ? I2C_CR_RSTA : 0), @@ -355,8 +355,8 @@ static inline int i2c_write_addr(const struct fsl_i2c_base *base, u8 dev, return 1; }
-static inline int __i2c_write_data(const struct fsl_i2c_base *base, u8 *data, - int length) +static int __i2c_write_data(const struct fsl_i2c_base *base, u8 *data, + int length) { int i;
@@ -370,8 +370,8 @@ static inline int __i2c_write_data(const struct fsl_i2c_base *base, u8 *data, return i; }
-static inline int __i2c_read_data(const struct fsl_i2c_base *base, u8 *data, - int length) +static int __i2c_read_data(const struct fsl_i2c_base *base, u8 *data, + int length) { int i;

Hello Mario,
Am 29.09.2017 um 14:51 schrieb Mario Six:
Some functions in the fsl_i2c driver are declared as inline, even though they are quite large, which needlessly increases the size of the resulting binary.
This patch removes the inline declarations.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/i2c/fsl_i2c.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Reviewed-by: Heiko Schocherh@denx.de
bye, Heiko

Make the fsl_i2c driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/i2c/fsl_i2c.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c index a7f3ec472f..cb0f5ea233 100644 --- a/drivers/i2c/fsl_i2c.c +++ b/drivers/i2c/fsl_i2c.c @@ -574,22 +574,18 @@ static int fsl_i2c_ofdata_to_platdata(struct udevice *bus) { struct fsl_i2c_dev *dev = dev_get_priv(bus); fdt_addr_t addr; - fdt_size_t size; - int node = dev_of_offset(bus);
- addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, node, "reg", 0, - &size, false); + addr = dev_read_u32_default(bus, "reg", -1);
- dev->base = map_sysmem(CONFIG_SYS_IMMR + addr, size); + dev->base = map_sysmem(CONFIG_SYS_IMMR + addr, sizeof(struct fsl_i2c_base));
if (!dev->base) return -ENOMEM;
- dev->index = fdtdec_get_int(gd->fdt_blob, node, "cell-index", -1); - dev->slaveadd = fdtdec_get_int(gd->fdt_blob, node, - "u-boot,i2c-slave-addr", 0x7f); - dev->speed = fdtdec_get_int(gd->fdt_blob, node, "clock-frequency", - 400000); + dev->index = dev_read_u32_default(bus, "cell-index", -1); + dev->slaveadd = dev_read_u32_default(bus, "u-boot,i2c-slave-addr", + 0x7f); + dev->speed = dev_read_u32_default(bus, "clock-frequency", 400000);
dev->i2c_clk = dev->index ? gd->arch.i2c2_clk : gd->arch.i2c1_clk;

Hello Mario,
Am 29.09.2017 um 14:51 schrieb Mario Six:
Make the fsl_i2c driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/i2c/fsl_i2c.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
Reviewed-by: Heiko Schocherh@denx.de
bye, Heiko

Fix some style violations in the pca953x_gpio driver.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/gpio/pca953x_gpio.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/gpio/pca953x_gpio.c b/drivers/gpio/pca953x_gpio.c index 4962f25230..9ad81fe2ba 100644 --- a/drivers/gpio/pca953x_gpio.c +++ b/drivers/gpio/pca953x_gpio.c @@ -123,7 +123,8 @@ static int pca953x_read_regs(struct udevice *dev, int reg, u8 *val) ret = dm_i2c_read(dev, reg << 1, val, info->bank_count); } else if (info->gpio_count == 40) { /* Auto increment */ - ret = dm_i2c_read(dev, (reg << 3) | 0x80, val, info->bank_count); + ret = dm_i2c_read(dev, (reg << 3) | 0x80, val, + info->bank_count); } else { dev_err(dev, "Unsupported now\n"); return -EINVAL; @@ -143,7 +144,7 @@ static int pca953x_is_output(struct udevice *dev, int offset) return !(info->reg_direction[bank] & (1 << off)); }
-static int pca953x_get_value(struct udevice *dev, unsigned offset) +static int pca953x_get_value(struct udevice *dev, uint offset) { int ret; u8 val = 0; @@ -157,8 +158,7 @@ static int pca953x_get_value(struct udevice *dev, unsigned offset) return (val >> off) & 0x1; }
-static int pca953x_set_value(struct udevice *dev, unsigned offset, - int value) +static int pca953x_set_value(struct udevice *dev, uint offset, int value) { struct pca953x_info *info = dev_get_platdata(dev); int bank = offset / BANK_SZ; @@ -180,7 +180,7 @@ static int pca953x_set_value(struct udevice *dev, unsigned offset, return 0; }
-static int pca953x_set_direction(struct udevice *dev, unsigned offset, int dir) +static int pca953x_set_direction(struct udevice *dev, uint offset, int dir) { struct pca953x_info *info = dev_get_platdata(dev); int bank = offset / BANK_SZ; @@ -202,13 +202,12 @@ static int pca953x_set_direction(struct udevice *dev, unsigned offset, int dir) return 0; }
-static int pca953x_direction_input(struct udevice *dev, unsigned offset) +static int pca953x_direction_input(struct udevice *dev, uint offset) { return pca953x_set_direction(dev, offset, PCA953X_DIRECTION_IN); }
-static int pca953x_direction_output(struct udevice *dev, unsigned offset, - int value) +static int pca953x_direction_output(struct udevice *dev, uint offset, int value) { /* Configure output value. */ pca953x_set_value(dev, offset, value); @@ -219,7 +218,7 @@ static int pca953x_direction_output(struct udevice *dev, unsigned offset, return 0; }
-static int pca953x_get_function(struct udevice *dev, unsigned offset) +static int pca953x_get_function(struct udevice *dev, uint offset) { if (pca953x_is_output(dev, offset)) return GPIOF_OUTPUT; @@ -231,7 +230,7 @@ static int pca953x_xlate(struct udevice *dev, struct gpio_desc *desc, struct ofnode_phandle_args *args) { desc->offset = args->args[0]; - desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0; + desc->flags = args->args[1] & (GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0);
return 0; } -- 2.11.0

Make the pca953x_gpio driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/gpio/pca953x_gpio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/gpio/pca953x_gpio.c b/drivers/gpio/pca953x_gpio.c index 9ad81fe2ba..05bc4049c2 100644 --- a/drivers/gpio/pca953x_gpio.c +++ b/drivers/gpio/pca953x_gpio.c @@ -50,8 +50,6 @@ enum { #define MAX_BANK 5 #define BANK_SZ 8
-DECLARE_GLOBAL_DATA_PTR; - /* * struct pca953x_info - Data for pca953x * @@ -264,7 +262,7 @@ static int pca953x_probe(struct udevice *dev) return -ENODEV; }
- addr = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), "reg", 0); + addr = dev_read_addr(dev); if (addr == 0) return -ENODEV;
-- 2.11.0

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Make the pca953x_gpio driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/gpio/pca953x_gpio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Clarify the computation precedence in two ternary operator constructions.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/serial/ns16550.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index c702304e79..6f9ce689cf 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -339,9 +339,9 @@ static int ns16550_serial_pending(struct udevice *dev, bool input) struct NS16550 *const com_port = dev_get_priv(dev);
if (input) - return serial_in(&com_port->lsr) & UART_LSR_DR ? 1 : 0; + return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0; else - return serial_in(&com_port->lsr) & UART_LSR_THRE ? 0 : 1; + return (serial_in(&com_port->lsr) & UART_LSR_THRE) ? 0 : 1; }
static int ns16550_serial_getc(struct udevice *dev)

On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
Clarify the computation precedence in two ternary operator constructions.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/serial/ns16550.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

The dev_read_addr function does not do any bus translations, and just returns the raw address read from the device tree, which makes the driver not work on systems that need bus translations to get the actual memory address of the device's register space.
Since the dev_read_addr function is widely used, we refrain from modifying it, and instead read the raw address from the device tree, and apply the bus translations using the recently introduced dev_translate_address function.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/serial/ns16550.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 6f9ce689cf..15d55dfd24 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -389,12 +389,13 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev) { struct ns16550_platdata *plat = dev->platdata; const u32 port_type = dev_get_driver_data(dev); - fdt_addr_t addr; + fdt32_t addr; struct clk clk; int err;
/* try Processor Local Bus device first */ - addr = dev_read_addr(dev); + addr = dev_read_u32_default(dev, "reg", 0); + addr = dev_translate_address(dev, &addr); #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI) if (addr == FDT_ADDR_T_NONE) { /* then try pci device */

Hi Mario,
On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
The dev_read_addr function does not do any bus translations, and just returns the raw address read from the device tree, which makes the driver not work on systems that need bus translations to get the actual memory address of the device's register space.
Aside from any current functionality, what is the correct thing for dev_read_addr() to do? I worry that the two parts (live/flat tree) might do different things.
In any case, we should not compound the problem if dev_read_addr() is wrong.
Since the dev_read_addr function is widely used, we refrain from modifying it, and instead read the raw address from the device tree, and apply the bus translations using the recently introduced dev_translate_address function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/serial/ns16550.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
REgards, Simon

(adding Philipp since he converted lots of drivers to livetree recently)
On Mon, Oct 9, 2017 at 6:48 AM, Simon Glass sjg@chromium.org wrote:
Hi Mario,
On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
The dev_read_addr function does not do any bus translations, and just returns the raw address read from the device tree, which makes the driver not work on systems that need bus translations to get the actual memory address of the device's register space.
Aside from any current functionality, what is the correct thing for dev_read_addr() to do? I worry that the two parts (live/flat tree) might do different things.
I took a closer look, and indeed, the two parts of dev_read_addr behave differently: dev_read_addr calls dev_read_addr_index, which calls either ofnode_get_addr_index when live tree is active, or devfdt_get_addr_index when it's not. devfdt_get_addr_index applies bus translations, but ofnode_get_addr_index returns the untranslated address using of_read_number (the else part doesn't run, since we have an active live tree if ofnode_get_addr_index was called).
We could fix this by running of_translate_address on the value returned by of_read_number, so that dev_get_addr would then always return a translated address.
But what I think is strange is that most live tree conversion patches (e.g. a9d3037 ("usb: dwc2: convert to livetree") or 4aac33f ("dm: mmc: fsl_esdhc: Update to support livetree")) simply replaced devfdt_get_addr (which does apply bus translations) with dev_read_addr (which does not apply bus translations in the live tree case). Shouldn't the converted driver have failed in the live tree case? Or were all drivers converted until now not depending on any bus translations?
In any case, we should not compound the problem if dev_read_addr() is wrong.
Since the dev_read_addr function is widely used, we refrain from modifying it, and instead read the raw address from the device tree, and apply the bus translations using the recently introduced dev_translate_address function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/serial/ns16550.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
REgards, Simon
Best regards,
Mario

On 9 Oct 2017, at 14:45, Mario Six mario.six@gdsys.cc wrote:
(adding Philipp since he converted lots of drivers to livetree recently)
On Mon, Oct 9, 2017 at 6:48 AM, Simon Glass sjg@chromium.org wrote:
Hi Mario,
On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
The dev_read_addr function does not do any bus translations, and just returns the raw address read from the device tree, which makes the driver not work on systems that need bus translations to get the actual memory address of the device's register space.
Aside from any current functionality, what is the correct thing for dev_read_addr() to do? I worry that the two parts (live/flat tree) might do different things.
I took a closer look, and indeed, the two parts of dev_read_addr behave differently: dev_read_addr calls dev_read_addr_index, which calls either ofnode_get_addr_index when live tree is active, or devfdt_get_addr_index when it's not. devfdt_get_addr_index applies bus translations, but ofnode_get_addr_index returns the untranslated address using of_read_number (the else part doesn't run, since we have an active live tree if ofnode_get_addr_index was called).
Good point. I would expect the livetree case to use translated addresses during runtime, as dev_read_addr_index calls either ofnode_get_addr_index or devfdt_get_addr_index.
In other words: are we missing an address translation from ofnode_get_addr_index or should the address retrieved via ofnode_get_addr_index have been translated by earlier processing?
We could fix this by running of_translate_address on the value returned by of_read_number, so that dev_get_addr would then always return a translated address.
But what I think is strange is that most live tree conversion patches (e.g. a9d3037 ("usb: dwc2: convert to livetree") or 4aac33f ("dm: mmc: fsl_esdhc: Update to support livetree")) simply replaced devfdt_get_addr (which does apply bus translations) with dev_read_addr (which does not apply bus translations in the live tree case). Shouldn't the converted driver have failed in the live tree case? Or were all drivers converted until now not depending on any bus translations?
In any case, we should not compound the problem if dev_read_addr() is wrong.
Since the dev_read_addr function is widely used, we refrain from modifying it, and instead read the raw address from the device tree, and apply the bus translations using the recently introduced dev_translate_address function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/serial/ns16550.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
REgards, Simon
Best regards,
Mario

Hi,
On 9 October 2017 at 06:55, Dr. Philipp Tomsich philipp.tomsich@theobroma-systems.com wrote:
On 9 Oct 2017, at 14:45, Mario Six mario.six@gdsys.cc wrote:
(adding Philipp since he converted lots of drivers to livetree recently)
On Mon, Oct 9, 2017 at 6:48 AM, Simon Glass sjg@chromium.org wrote:
Hi Mario,
On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
The dev_read_addr function does not do any bus translations, and just returns the raw address read from the device tree, which makes the driver not work on systems that need bus translations to get the actual memory address of the device's register space.
Aside from any current functionality, what is the correct thing for dev_read_addr() to do? I worry that the two parts (live/flat tree) might do different things.
I took a closer look, and indeed, the two parts of dev_read_addr behave differently: dev_read_addr calls dev_read_addr_index, which calls either ofnode_get_addr_index when live tree is active, or devfdt_get_addr_index when it's not. devfdt_get_addr_index applies bus translations, but ofnode_get_addr_index returns the untranslated address using of_read_number (the else part doesn't run, since we have an active live tree if ofnode_get_addr_index was called).
Good point. I would expect the livetree case to use translated addresses during runtime, as dev_read_addr_index calls either ofnode_get_addr_index or devfdt_get_addr_index.
In other words: are we missing an address translation from ofnode_get_addr_index or should the address retrieved via ofnode_get_addr_index have been translated by earlier processing?
Thank you both. Yes it seems like the right answer is to add the missing translation in. There is a CONFIG_OF_TRANSLATE which enables this. I think most boards don't use it, which is probably why there are no problems without it, but I think it is becoming more common as boards become more complex.
We could fix this by running of_translate_address on the value returned by of_read_number, so that dev_get_addr would then always return a translated address.
But what I think is strange is that most live tree conversion patches (e.g. a9d3037 ("usb: dwc2: convert to livetree") or 4aac33f ("dm: mmc: fsl_esdhc: Update to support livetree")) simply replaced devfdt_get_addr (which does apply bus translations) with dev_read_addr (which does not apply bus translations in the live tree case). Shouldn't the converted driver have failed in the live tree case? Or were all drivers converted until now not depending on any bus translations?
In any case, we should not compound the problem if dev_read_addr() is wrong.
Since the dev_read_addr function is widely used, we refrain from modifying it, and instead read the raw address from the device tree, and apply the bus translations using the recently introduced dev_translate_address function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/serial/ns16550.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
REgards, Simon
Best regards,
Mario
Regards, Simon

Hi,
On Mon, Oct 9, 2017 at 4:09 PM, Simon Glass sjg@chromium.org wrote:
Hi,
On 9 October 2017 at 06:55, Dr. Philipp Tomsich philipp.tomsich@theobroma-systems.com wrote:
On 9 Oct 2017, at 14:45, Mario Six mario.six@gdsys.cc wrote:
(adding Philipp since he converted lots of drivers to livetree recently)
On Mon, Oct 9, 2017 at 6:48 AM, Simon Glass sjg@chromium.org wrote:
Hi Mario,
On 29 September 2017 at 06:51, Mario Six mario.six@gdsys.cc wrote:
The dev_read_addr function does not do any bus translations, and just returns the raw address read from the device tree, which makes the driver not work on systems that need bus translations to get the actual memory address of the device's register space.
Aside from any current functionality, what is the correct thing for dev_read_addr() to do? I worry that the two parts (live/flat tree) might do different things.
I took a closer look, and indeed, the two parts of dev_read_addr behave differently: dev_read_addr calls dev_read_addr_index, which calls either ofnode_get_addr_index when live tree is active, or devfdt_get_addr_index when it's not. devfdt_get_addr_index applies bus translations, but ofnode_get_addr_index returns the untranslated address using of_read_number (the else part doesn't run, since we have an active live tree if ofnode_get_addr_index was called).
Good point. I would expect the livetree case to use translated addresses during runtime, as dev_read_addr_index calls either ofnode_get_addr_index or devfdt_get_addr_index.
In other words: are we missing an address translation from ofnode_get_addr_index or should the address retrieved via ofnode_get_addr_index have been translated by earlier processing?
Thank you both. Yes it seems like the right answer is to add the missing translation in. There is a CONFIG_OF_TRANSLATE which enables this. I think most boards don't use it, which is probably why there are no problems without it, but I think it is becoming more common as boards become more complex.
OK, I'll send a separate patch this week. Thanks for taking a look!
We could fix this by running of_translate_address on the value returned by of_read_number, so that dev_get_addr would then always return a translated address.
But what I think is strange is that most live tree conversion patches (e.g. a9d3037 ("usb: dwc2: convert to livetree") or 4aac33f ("dm: mmc: fsl_esdhc: Update to support livetree")) simply replaced devfdt_get_addr (which does apply bus translations) with dev_read_addr (which does not apply bus translations in the live tree case). Shouldn't the converted driver have failed in the live tree case? Or were all drivers converted until now not depending on any bus translations?
In any case, we should not compound the problem if dev_read_addr() is wrong.
Since the dev_read_addr function is widely used, we refrain from modifying it, and instead read the raw address from the device tree, and apply the bus translations using the recently introduced dev_translate_address function.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/serial/ns16550.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
REgards, Simon
Best regards,
Mario
Regards, Simon
Best regards,
Mario

The ppc4xx architecture was recently removed, and with it several old gdsys 44x boards, but some "debris" from these purged boards was left over.
This patch removes these remnants (mostly entries in Makefiles, some now superfluous data structures and some now obsolete config variables from the whitelist).
Signed-off-by: Mario Six mario.six@gdsys.cc --- board/gdsys/common/Makefile | 4 -- board/gdsys/common/miiphybb.c | 128 ------------------------------------------ include/gdsys_fpga.h | 96 ------------------------------- scripts/config_whitelist.txt | 10 ---- 4 files changed, 238 deletions(-) delete mode 100644 board/gdsys/common/miiphybb.c
diff --git a/board/gdsys/common/Makefile b/board/gdsys/common/Makefile index d4f0e70573..6f2fea207f 100644 --- a/board/gdsys/common/Makefile +++ b/board/gdsys/common/Makefile @@ -7,10 +7,6 @@
obj-$(CONFIG_SYS_FPGA_COMMON) += fpga.o obj-$(CONFIG_CMD_IOLOOP) += cmd_ioloop.o -obj-$(CONFIG_IO) += miiphybb.o -obj-$(CONFIG_IO64) += miiphybb.o -obj-$(CONFIG_IOCON) += osd.o mclink.o dp501.o phy.o ch7301.o -obj-$(CONFIG_DLVISION_10G) += osd.o dp501.o obj-$(CONFIG_CONTROLCENTERD) += dp501.o obj-$(CONFIG_HRCON) += osd.o mclink.o dp501.o phy.o ioep-fpga.o fanctrl.o obj-$(CONFIG_STRIDER) += mclink.o dp501.o phy.o ioep-fpga.o adv7611.o ch7301.o diff --git a/board/gdsys/common/miiphybb.c b/board/gdsys/common/miiphybb.c deleted file mode 100644 index 310562902b..0000000000 --- a/board/gdsys/common/miiphybb.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * (C) Copyright 2010 - * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include <common.h> -#include <miiphy.h> - -#include <asm/io.h> - -struct io_bb_pinset { - int mdio; - int mdc; -}; - -static int io_bb_mii_init(struct bb_miiphy_bus *bus) -{ - return 0; -} - -static int io_bb_mdio_active(struct bb_miiphy_bus *bus) -{ - struct io_bb_pinset *pins = bus->priv; - - out_be32((void *)GPIO0_TCR, - in_be32((void *)GPIO0_TCR) | pins->mdio); - - return 0; -} - -static int io_bb_mdio_tristate(struct bb_miiphy_bus *bus) -{ - struct io_bb_pinset *pins = bus->priv; - - out_be32((void *)GPIO0_TCR, - in_be32((void *)GPIO0_TCR) & ~pins->mdio); - - return 0; -} - -static int io_bb_set_mdio(struct bb_miiphy_bus *bus, int v) -{ - struct io_bb_pinset *pins = bus->priv; - - if (v) - out_be32((void *)GPIO0_OR, - in_be32((void *)GPIO0_OR) | pins->mdio); - else - out_be32((void *)GPIO0_OR, - in_be32((void *)GPIO0_OR) & ~pins->mdio); - - return 0; -} - -static int io_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) -{ - struct io_bb_pinset *pins = bus->priv; - - *v = ((in_be32((void *)GPIO0_IR) & pins->mdio) != 0); - - return 0; -} - -static int io_bb_set_mdc(struct bb_miiphy_bus *bus, int v) -{ - struct io_bb_pinset *pins = bus->priv; - - if (v) - out_be32((void *)GPIO0_OR, - in_be32((void *)GPIO0_OR) | pins->mdc); - else - out_be32((void *)GPIO0_OR, - in_be32((void *)GPIO0_OR) & ~pins->mdc); - - return 0; -} - -static int io_bb_delay(struct bb_miiphy_bus *bus) -{ - udelay(1); - - return 0; -} - -struct io_bb_pinset io_bb_pinsets[] = { - { - .mdio = CONFIG_SYS_MDIO_PIN, - .mdc = CONFIG_SYS_MDC_PIN, - }, -#ifdef CONFIG_SYS_GBIT_MII1_BUSNAME - { - .mdio = CONFIG_SYS_MDIO1_PIN, - .mdc = CONFIG_SYS_MDC1_PIN, - }, -#endif -}; - -struct bb_miiphy_bus bb_miiphy_buses[] = { - { - .name = CONFIG_SYS_GBIT_MII_BUSNAME, - .init = io_bb_mii_init, - .mdio_active = io_bb_mdio_active, - .mdio_tristate = io_bb_mdio_tristate, - .set_mdio = io_bb_set_mdio, - .get_mdio = io_bb_get_mdio, - .set_mdc = io_bb_set_mdc, - .delay = io_bb_delay, - .priv = &io_bb_pinsets[0], - }, -#ifdef CONFIG_SYS_GBIT_MII1_BUSNAME - { - .name = CONFIG_SYS_GBIT_MII1_BUSNAME, - .init = io_bb_mii_init, - .mdio_active = io_bb_mdio_active, - .mdio_tristate = io_bb_mdio_tristate, - .set_mdio = io_bb_set_mdio, - .get_mdio = io_bb_get_mdio, - .set_mdc = io_bb_set_mdc, - .delay = io_bb_delay, - .priv = &io_bb_pinsets[1], - }, -#endif -}; - -int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / - sizeof(bb_miiphy_buses[0]); diff --git a/include/gdsys_fpga.h b/include/gdsys_fpga.h index bb8e144e04..34d6eeb253 100644 --- a/include/gdsys_fpga.h +++ b/include/gdsys_fpga.h @@ -87,81 +87,6 @@ struct ihs_fpga { }; #endif
-#ifdef CONFIG_IO -struct ihs_fpga { - u16 reflection_low; /* 0x0000 */ - u16 versions; /* 0x0002 */ - u16 fpga_features; /* 0x0004 */ - u16 fpga_version; /* 0x0006 */ - u16 reserved_0[5]; /* 0x0008 */ - u16 quad_serdes_reset; /* 0x0012 */ - u16 reserved_1[8181]; /* 0x0014 */ - u16 reflection_high; /* 0x3ffe */ -}; -#endif - -#ifdef CONFIG_IO64 -struct ihs_fpga_channel { - u16 status_int; - u16 config_int; - u16 switch_connect_config; - u16 tx_destination; -}; - -struct ihs_fpga_hicb { - u16 status_int; - u16 config_int; -}; - -struct ihs_fpga { - u16 reflection_low; /* 0x0000 */ - u16 versions; /* 0x0002 */ - u16 fpga_features; /* 0x0004 */ - u16 fpga_version; /* 0x0006 */ - u16 reserved_0[5]; /* 0x0008 */ - u16 quad_serdes_reset; /* 0x0012 */ - u16 reserved_1[502]; /* 0x0014 */ - struct ihs_fpga_channel ch[32]; /* 0x0400 */ - struct ihs_fpga_channel hicb_ch[32]; /* 0x0500 */ - u16 reserved_2[7487]; /* 0x0580 */ - u16 reflection_high; /* 0x3ffe */ -}; -#endif - -#ifdef CONFIG_IOCON -struct ihs_fpga { - u16 reflection_low; /* 0x0000 */ - u16 versions; /* 0x0002 */ - u16 fpga_version; /* 0x0004 */ - u16 fpga_features; /* 0x0006 */ - u16 reserved_0[1]; /* 0x0008 */ - u16 top_interrupt; /* 0x000a */ - u16 reserved_1[4]; /* 0x000c */ - struct ihs_gpio gpio; /* 0x0014 */ - u16 mpc3w_control; /* 0x001a */ - u16 reserved_2[2]; /* 0x001c */ - struct ihs_io_ep ep; /* 0x0020 */ - u16 reserved_3[9]; /* 0x002e */ - struct ihs_i2c i2c0; /* 0x0040 */ - u16 reserved_4[10]; /* 0x004c */ - u16 mc_int; /* 0x0060 */ - u16 mc_int_en; /* 0x0062 */ - u16 mc_status; /* 0x0064 */ - u16 mc_control; /* 0x0066 */ - u16 mc_tx_data; /* 0x0068 */ - u16 mc_tx_address; /* 0x006a */ - u16 mc_tx_cmd; /* 0x006c */ - u16 mc_res; /* 0x006e */ - u16 mc_rx_cmd_status; /* 0x0070 */ - u16 mc_rx_data; /* 0x0072 */ - u16 reserved_5[69]; /* 0x0074 */ - u16 reflection_high; /* 0x00fe */ - struct ihs_osd osd0; /* 0x0100 */ - u16 reserved_6[889]; /* 0x010e */ - u16 videomem0[2048]; /* 0x0800 */ -}; -#endif - #if defined(CONFIG_HRCON) || defined(CONFIG_STRIDER_CON_DP) struct ihs_fpga { u16 reflection_low; /* 0x0000 */ @@ -271,25 +196,4 @@ struct ihs_fpga { }; #endif
-#ifdef CONFIG_DLVISION_10G -struct ihs_fpga { - u16 reflection_low; /* 0x0000 */ - u16 versions; /* 0x0002 */ - u16 fpga_version; /* 0x0004 */ - u16 fpga_features; /* 0x0006 */ - u16 reserved_0[10]; /* 0x0008 */ - u16 extended_interrupt; /* 0x001c */ - u16 reserved_1[29]; /* 0x001e */ - u16 mpc3w_control; /* 0x0058 */ - u16 reserved_2[3]; /* 0x005a */ - struct ihs_i2c i2c0; /* 0x0060 */ - u16 reserved_3[2]; /* 0x006c */ - struct ihs_i2c i2c1; /* 0x0070 */ - u16 reserved_4[194]; /* 0x007c */ - struct ihs_osd osd0; /* 0x0200 */ - u16 reserved_5[761]; /* 0x020e */ - u16 videomem0[2048]; /* 0x0800 */ -}; -#endif - #endif diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index f8236beef5..4a5561ff41 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -452,7 +452,6 @@ CONFIG_DISCONTIGMEM CONFIG_DISCOVER_PHY CONFIG_DISPLAY_AER_xxxx CONFIG_DISPLAY_BOARDINFO_LATE -CONFIG_DLVISION_10G CONFIG_DM9000_BASE CONFIG_DM9000_BYTE_SWAPPED CONFIG_DM9000_DEBUG @@ -1103,9 +1102,6 @@ CONFIG_INI_MAX_NAME CONFIG_INI_MAX_SECTION CONFIG_INTEGRITY CONFIG_INTERRUPTS -CONFIG_IO -CONFIG_IO64 -CONFIG_IOCON CONFIG_IODELAY_RECALIBRATION CONFIG_IOMUX_LPSR CONFIG_IOMUX_SHARE_CONF_REG @@ -3313,8 +3309,6 @@ CONFIG_SYS_GAFR2_L_VAL CONFIG_SYS_GAFR2_U_VAL CONFIG_SYS_GAFR3_L_VAL CONFIG_SYS_GAFR3_U_VAL -CONFIG_SYS_GBIT_MII1_BUSNAME -CONFIG_SYS_GBIT_MII_BUSNAME CONFIG_SYS_GBL_DATA_OFFSET CONFIG_SYS_GBL_DATA_SIZE CONFIG_SYS_GENERIC_BOARD @@ -3751,13 +3745,9 @@ CONFIG_SYS_MCKR_VAL CONFIG_SYS_MCLINK_MAX CONFIG_SYS_MCMEM0_VAL CONFIG_SYS_MCMEM1_VAL -CONFIG_SYS_MDC1_PIN CONFIG_SYS_MDCNFG_VAL -CONFIG_SYS_MDC_PIN CONFIG_SYS_MDIO1_OFFSET -CONFIG_SYS_MDIO1_PIN CONFIG_SYS_MDIO_BASE_ADDR -CONFIG_SYS_MDIO_PIN CONFIG_SYS_MDMRS_VAL CONFIG_SYS_MDREFR_VAL CONFIG_SYS_MECR_VAL

Fix some style violations (mostly wrong indentions) in the Marvell PHY driver.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/net/phy/marvell.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index b7f300e40f..5d9f50a436 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -134,7 +134,7 @@ static int m88e1xxx_parse_status(struct phy_device *phydev) mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_STATUS);
if ((mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) && - !(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) { + !(mii_reg & MIIM_88E1xxx_PHYSTAT_SPDDONE)) { int i = 0;
puts("Waiting for PHY realtime link"); @@ -150,10 +150,10 @@ static int m88e1xxx_parse_status(struct phy_device *phydev) putc('.'); udelay(1000); mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, - MIIM_88E1xxx_PHY_STATUS); + MIIM_88E1xxx_PHY_STATUS); } puts(" done\n"); - udelay(500000); /* another 500 ms (results in faster booting) */ + mdelay(500); /* another 500 ms (results in faster booting) */ } else { if (mii_reg & MIIM_88E1xxx_PHYSTAT_LINK) phydev->link = 1; @@ -201,9 +201,9 @@ static int m88e1111s_config(struct phy_device *phydev)
if (phy_interface_is_rgmii(phydev)) { reg = phy_read(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR); if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) || - (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) { + (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) { reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY); } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { reg &= ~MIIM_88E1111_TX_DELAY; @@ -214,10 +214,10 @@ static int m88e1111s_config(struct phy_device *phydev) }
phy_write(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
reg = phy_read(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK);
@@ -227,47 +227,47 @@ static int m88e1111s_config(struct phy_device *phydev) reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RGMII;
phy_write(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR, reg); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR, reg); }
if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { reg = phy_read(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_SR);
reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK); reg |= MIIM_88E1111_HWCFG_MODE_SGMII_NO_CLK; reg |= MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO;
phy_write(phydev, MDIO_DEVAD_NONE, - MIIM_88E1111_PHY_EXT_SR, reg); + MIIM_88E1111_PHY_EXT_SR, reg); }
if (phydev->interface == PHY_INTERFACE_MODE_RTBI) { reg = phy_read(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR); reg |= (MIIM_88E1111_RX_DELAY | MIIM_88E1111_TX_DELAY); phy_write(phydev, - MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg); + MDIO_DEVAD_NONE, MIIM_88E1111_PHY_EXT_CR, reg);
reg = phy_read(phydev, MDIO_DEVAD_NONE, - MIIM_88E1111_PHY_EXT_SR); + MIIM_88E1111_PHY_EXT_SR); reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK | MIIM_88E1111_HWCFG_FIBER_COPPER_RES); reg |= 0x7 | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO; phy_write(phydev, MDIO_DEVAD_NONE, - MIIM_88E1111_PHY_EXT_SR, reg); + MIIM_88E1111_PHY_EXT_SR, reg);
/* soft reset */ phy_reset(phydev);
reg = phy_read(phydev, MDIO_DEVAD_NONE, - MIIM_88E1111_PHY_EXT_SR); + MIIM_88E1111_PHY_EXT_SR); reg &= ~(MIIM_88E1111_HWCFG_MODE_MASK | - MIIM_88E1111_HWCFG_FIBER_COPPER_RES); + MIIM_88E1111_HWCFG_FIBER_COPPER_RES); reg |= MIIM_88E1111_HWCFG_MODE_COPPER_RTBI | MIIM_88E1111_HWCFG_FIBER_COPPER_AUTO; phy_write(phydev, MDIO_DEVAD_NONE, - MIIM_88E1111_PHY_EXT_SR, reg); + MIIM_88E1111_PHY_EXT_SR, reg); }
/* soft reset */ @@ -283,7 +283,7 @@ static int m88e1111s_config(struct phy_device *phydev) * m88e1518_phy_writebits - write bits to a register */ void m88e1518_phy_writebits(struct phy_device *phydev, - u8 reg_num, u16 offset, u16 len, u16 data) + u8 reg_num, u16 offset, u16 len, u16 data) { u16 reg, mask;
@@ -446,10 +446,10 @@ static int m88e1121_config(struct phy_device *phydev) /* Switch the page to access the led register */ pg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE); phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, - MIIM_88E1121_PHY_LED_PAGE); + MIIM_88E1121_PHY_LED_PAGE); /* Configure leds */ phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_LED_CTRL, - MIIM_88E1121_PHY_LED_DEF); + MIIM_88E1121_PHY_LED_DEF); /* Restore the page pointer */ phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1121_PHY_PAGE, pg);
@@ -472,7 +472,7 @@ static int m88e1145_config(struct phy_device *phydev) phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_CAL_OV, 0xa2da);
phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1xxx_PHY_SCR, - MIIM_88E1xxx_PHY_MDI_X_AUTO); + MIIM_88E1xxx_PHY_MDI_X_AUTO);
reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_EXT_CR); if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) @@ -499,7 +499,7 @@ static int m88e1145_startup(struct phy_device *phydev) return ret;
phy_write(phydev, MDIO_DEVAD_NONE, MIIM_88E1145_PHY_LED_CONTROL, - MIIM_88E1145_PHY_LED_DIRECT); + MIIM_88E1145_PHY_LED_DIRECT); return m88e1xxx_parse_status(phydev); }

Commit 68e6eca ("net: phy: marvell 88e151x: Fix handling of RGMII interface types") fixed the initialization of 88e151x phys, but made it so that interfaces of type PHY_INTERFACE_MODE_RGMII had both RX and TX delay bits cleared. The default (like in m88e1111s_config) is to have both bits set.
Hence, this patch changes the behavior in the PHY_INTERFACE_MODE_RGMII case so that both bits are set.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/net/phy/marvell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 5d9f50a436..8eddf70c68 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -357,7 +357,8 @@ static int m88e1518_config(struct phy_device *phydev)
reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_88E151x_PHY_MSCR); reg &= ~MIIM_88E151x_RGMII_RXTX_DELAY; - if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) + if (phydev->interface == PHY_INTERFACE_MODE_RGMII || + phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) reg |= MIIM_88E151x_RGMII_RXTX_DELAY; else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) reg |= MIIM_88E151x_RGMII_RX_DELAY;

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 428 ++++++++++++++++++++++++------------------------ 1 file changed, 214 insertions(+), 214 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 8a5babea7b..b3dda8bd4a 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -204,7 +204,7 @@ unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect) * create an address based on the offset and the port width */ static inline void * -flash_map (flash_info_t * info, flash_sect_t sect, uint offset) +flash_map(flash_info_t * info, flash_sect_t sect, uint offset) { unsigned int byte_offset = offset * info->portwidth;
@@ -247,17 +247,17 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) /*----------------------------------------------------------------------- * Debug support */ -static void print_longlong (char *str, unsigned long long data) +static void print_longlong(char *str, unsigned long long data) { int i; char *cp;
cp = (char *) &data; for (i = 0; i < 8; i++) - sprintf (&str[i * 2], "%2.2x", *cp++); + sprintf(&str[i * 2], "%2.2x", *cp++); }
-static void flash_printqry (struct cfi_qry *qry) +static void flash_printqry(struct cfi_qry *qry) { u8 *p = (u8 *)qry; int x, y; @@ -283,31 +283,31 @@ static void flash_printqry (struct cfi_qry *qry) /*----------------------------------------------------------------------- * read a character at a port width address */ -static inline uchar flash_read_uchar (flash_info_t * info, uint offset) +static inline uchar flash_read_uchar(flash_info_t * info, uint offset) { uchar *cp; uchar retval;
- cp = flash_map (info, 0, offset); + cp = flash_map(info, 0, offset); #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) retval = flash_read8(cp); #else retval = flash_read8(cp + info->portwidth - 1); #endif - flash_unmap (info, 0, offset, cp); + flash_unmap(info, 0, offset, cp); return retval; }
/*----------------------------------------------------------------------- * read a word at a port width address, assume 16bit bus */ -static inline ushort flash_read_word (flash_info_t * info, uint offset) +static inline ushort flash_read_word(flash_info_t * info, uint offset) { ushort *addr, retval;
- addr = flash_map (info, 0, offset); - retval = flash_read16 (addr); - flash_unmap (info, 0, offset, addr); + addr = flash_map(info, 0, offset); + retval = flash_read16(addr); + flash_unmap(info, 0, offset, addr); return retval; }
@@ -325,13 +325,13 @@ static ulong flash_read_long (flash_info_t * info, flash_sect_t sect, #ifdef DEBUG int x; #endif - addr = flash_map (info, sect, offset); + addr = flash_map(info, sect, offset);
#ifdef DEBUG - debug ("long addr is at %p info->portwidth = %d\n", addr, + debug("long addr is at %p info->portwidth = %d\n", addr, info->portwidth); for (x = 0; x < 4 * info->portwidth; x++) { - debug ("addr[%x] = 0x%x\n", x, flash_read8(addr + x)); + debug("addr[%x] = 0x%x\n", x, flash_read8(addr + x)); } #endif #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) @@ -360,22 +360,22 @@ static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, void *addr; cfiword_t cword;
- addr = flash_map (info, sect, offset); - flash_make_cmd (info, cmd, &cword); + addr = flash_map(info, sect, offset); + flash_make_cmd(info, cmd, &cword); switch (info->portwidth) { case FLASH_CFI_8BIT: - debug ("fwc addr %p cmd %x %x 8bit x %d bit\n", addr, cmd, + debug("fwc addr %p cmd %x %x 8bit x %d bit\n", addr, cmd, cword.w8, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); flash_write8(cword.w8, addr); break; case FLASH_CFI_16BIT: - debug ("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr, + debug("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr, cmd, cword.w16, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); flash_write16(cword.w16, addr); break; case FLASH_CFI_32BIT: - debug ("fwc addr %p cmd %x %8.8x 32bit x %d bit\n", addr, + debug("fwc addr %p cmd %x %8.8x 32bit x %d bit\n", addr, cmd, cword.w32, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); flash_write32(cword.w32, addr); @@ -385,9 +385,9 @@ static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, { char str[20];
- print_longlong (str, cword.w64); + print_longlong(str, cword.w64);
- debug ("fwrite addr %p cmd %x %s 64 bit x %d bit\n", + debug("fwrite addr %p cmd %x %s 64 bit x %d bit\n", addr, cmd, str, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); } @@ -402,36 +402,36 @@ static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, flash_unmap(info, sect, offset, addr); }
-static void flash_unlock_seq (flash_info_t * info, flash_sect_t sect) +static void flash_unlock_seq(flash_info_t * info, flash_sect_t sect) { - flash_write_cmd (info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START); - flash_write_cmd (info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK); + flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START); + flash_write_cmd(info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK); }
/*----------------------------------------------------------------------- */ -static int flash_isequal (flash_info_t * info, flash_sect_t sect, +static int flash_isequal(flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd) { void *addr; cfiword_t cword; int retval;
- addr = flash_map (info, sect, offset); - flash_make_cmd (info, cmd, &cword); + addr = flash_map(info, sect, offset); + flash_make_cmd(info, cmd, &cword);
- debug ("is= cmd %x(%c) addr %p ", cmd, cmd, addr); + debug("is= cmd %x(%c) addr %p ", cmd, cmd, addr); switch (info->portwidth) { case FLASH_CFI_8BIT: - debug ("is= %x %x\n", flash_read8(addr), cword.w8); + debug("is= %x %x\n", flash_read8(addr), cword.w8); retval = (flash_read8(addr) == cword.w8); break; case FLASH_CFI_16BIT: - debug ("is= %4.4x %4.4x\n", flash_read16(addr), cword.w16); + debug("is= %4.4x %4.4x\n", flash_read16(addr), cword.w16); retval = (flash_read16(addr) == cword.w16); break; case FLASH_CFI_32BIT: - debug ("is= %8.8x %8.8x\n", flash_read32(addr), cword.w32); + debug("is= %8.8x %8.8x\n", flash_read32(addr), cword.w32); retval = (flash_read32(addr) == cword.w32); break; case FLASH_CFI_64BIT: @@ -440,9 +440,9 @@ static int flash_isequal (flash_info_t * info, flash_sect_t sect, char str1[20]; char str2[20];
- print_longlong (str1, flash_read64(addr)); - print_longlong (str2, cword.w64); - debug ("is= %s %s\n", str1, str2); + print_longlong(str1, flash_read64(addr)); + print_longlong(str2, cword.w64); + debug("is= %s %s\n", str1, str2); } #endif retval = (flash_read64(addr) == cword.w64); @@ -458,15 +458,15 @@ static int flash_isequal (flash_info_t * info, flash_sect_t sect,
/*----------------------------------------------------------------------- */ -static int flash_isset (flash_info_t * info, flash_sect_t sect, +static int flash_isset(flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd) { void *addr; cfiword_t cword; int retval;
- addr = flash_map (info, sect, offset); - flash_make_cmd (info, cmd, &cword); + addr = flash_map(info, sect, offset); + flash_make_cmd(info, cmd, &cword); switch (info->portwidth) { case FLASH_CFI_8BIT: retval = ((flash_read8(addr) & cword.w8) == cword.w8); @@ -491,15 +491,15 @@ static int flash_isset (flash_info_t * info, flash_sect_t sect,
/*----------------------------------------------------------------------- */ -static int flash_toggle (flash_info_t * info, flash_sect_t sect, +static int flash_toggle(flash_info_t * info, flash_sect_t sect, uint offset, uchar cmd) { void *addr; cfiword_t cword; int retval;
- addr = flash_map (info, sect, offset); - flash_make_cmd (info, cmd, &cword); + addr = flash_map(info, sect, offset); + flash_make_cmd(info, cmd, &cword); switch (info->portwidth) { case FLASH_CFI_8BIT: retval = flash_read8(addr) != flash_read8(addr); @@ -529,7 +529,7 @@ static int flash_toggle (flash_info_t * info, flash_sect_t sect, * This routine checks the status of the chip and returns true if the * chip is busy. */ -static int flash_is_busy (flash_info_t * info, flash_sect_t sect) +static int flash_is_busy(flash_info_t * info, flash_sect_t sect) { int retval;
@@ -537,7 +537,7 @@ static int flash_is_busy (flash_info_t * info, flash_sect_t sect) case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: - retval = !flash_isset (info, sect, 0, FLASH_STATUS_DONE); + retval = !flash_isset(info, sect, 0, FLASH_STATUS_DONE); break; case CFI_CMDSET_AMD_STANDARD: case CFI_CMDSET_AMD_EXTENDED: @@ -545,12 +545,12 @@ static int flash_is_busy (flash_info_t * info, flash_sect_t sect) case CFI_CMDSET_AMD_LEGACY: #endif if (info->sr_supported) { - flash_write_cmd (info, sect, info->addr_unlock1, + flash_write_cmd(info, sect, info->addr_unlock1, FLASH_CMD_READ_STATUS); - retval = !flash_isset (info, sect, 0, + retval = !flash_isset(info, sect, 0, FLASH_STATUS_DONE); } else { - retval = flash_toggle (info, sect, 0, + retval = flash_toggle(info, sect, 0, AMD_STATUS_TOGGLE); }
@@ -558,7 +558,7 @@ static int flash_is_busy (flash_info_t * info, flash_sect_t sect) default: retval = 0; } - debug ("flash_is_busy: %d\n", retval); + debug("flash_is_busy: %d\n", retval); return retval; }
@@ -566,7 +566,7 @@ static int flash_is_busy (flash_info_t * info, flash_sect_t sect) * wait for XSR.7 to be set. Time out with an error if it does not. * This routine does not set the flash to read-array mode. */ -static int flash_status_check (flash_info_t * info, flash_sect_t sector, +static int flash_status_check(flash_info_t * info, flash_sect_t sector, ulong tout, char *prompt) { ulong start; @@ -582,18 +582,18 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector, #ifdef CONFIG_SYS_LOW_RES_TIMER reset_timer(); #endif - start = get_timer (0); + start = get_timer(0); WATCHDOG_RESET(); - while (flash_is_busy (info, sector)) { - if (get_timer (start) > tout) { - printf ("Flash %s timeout at address %lx data %lx\n", + while (flash_is_busy(info, sector)) { + if (get_timer(start) > tout) { + printf("Flash %s timeout at address %lx data %lx\n", prompt, info->start[sector], - flash_read_long (info, sector, 0)); - flash_write_cmd (info, sector, 0, info->cmd_reset); + flash_read_long(info, sector, 0)); + flash_write_cmd(info, sector, 0, info->cmd_reset); udelay(1); return ERR_TIMOUT; } - udelay (1); /* also triggers watchdog */ + udelay(1); /* also triggers watchdog */ } return ERR_OK; } @@ -604,12 +604,12 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector, * * This routine sets the flash to read-array mode. */ -static int flash_full_status_check (flash_info_t * info, flash_sect_t sector, +static int flash_full_status_check(flash_info_t * info, flash_sect_t sector, ulong tout, char *prompt) { int retcode;
- retcode = flash_status_check (info, sector, tout, prompt); + retcode = flash_status_check(info, sector, tout, prompt); switch (info->vendor) { case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_EXTENDED: @@ -617,27 +617,27 @@ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector, if ((retcode == ERR_OK) && !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { retcode = ERR_INVAL; - printf ("Flash %s error at address %lx\n", prompt, + printf("Flash %s error at address %lx\n", prompt, info->start[sector]); - if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS | + if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) { - puts ("Command Sequence Error.\n"); - } else if (flash_isset (info, sector, 0, + puts("Command Sequence Error.\n"); + } else if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS)) { - puts ("Block Erase Error.\n"); + puts("Block Erase Error.\n"); retcode = ERR_NOT_ERASED; - } else if (flash_isset (info, sector, 0, + } else if (flash_isset(info, sector, 0, FLASH_STATUS_PSLBS)) { - puts ("Locking Error\n"); + puts("Locking Error\n"); } - if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) { - puts ("Block locked.\n"); + if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) { + puts("Block locked.\n"); retcode = ERR_PROTECTED; } - if (flash_isset (info, sector, 0, FLASH_STATUS_VPENS)) - puts ("Vpp Low Error.\n"); + if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS)) + puts("Vpp Low Error.\n"); } - flash_write_cmd (info, sector, 0, info->cmd_reset); + flash_write_cmd(info, sector, 0, info->cmd_reset); udelay(1); break; default: @@ -709,7 +709,7 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst,
/*----------------------------------------------------------------------- */ -static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c) +static void flash_add_byte(flash_info_t * info, cfiword_t * cword, uchar c) { #if defined(__LITTLE_ENDIAN) && !defined(CONFIG_SYS_WRITE_SWAPPED_DATA) unsigned short w; @@ -755,7 +755,7 @@ static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c) * Loop through the sector table starting from the previously found sector. * Searches forwards or backwards, dependent on the passed address. */ -static flash_sect_t find_sector (flash_info_t * info, ulong addr) +static flash_sect_t find_sector(flash_info_t * info, ulong addr) { static flash_sect_t saved_sector; /* previously found sector */ static flash_info_t *saved_info; /* previously used flash bank */ @@ -781,7 +781,7 @@ static flash_sect_t find_sector (flash_info_t * info, ulong addr)
/*----------------------------------------------------------------------- */ -static int flash_write_cfiword (flash_info_t * info, ulong dest, +static int flash_write_cfiword(flash_info_t * info, ulong dest, cfiword_t cword) { void *dstaddr = (void *)dest; @@ -811,27 +811,27 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest, return ERR_NOT_ERASED;
/* Disable interrupts which might cause a timeout here */ - flag = disable_interrupts (); + flag = disable_interrupts();
switch (info->vendor) { case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_EXTENDED: case CFI_CMDSET_INTEL_STANDARD: - flash_write_cmd (info, 0, 0, FLASH_CMD_CLEAR_STATUS); - flash_write_cmd (info, 0, 0, FLASH_CMD_WRITE); + flash_write_cmd(info, 0, 0, FLASH_CMD_CLEAR_STATUS); + flash_write_cmd(info, 0, 0, FLASH_CMD_WRITE); break; case CFI_CMDSET_AMD_EXTENDED: case CFI_CMDSET_AMD_STANDARD: sect = find_sector(info, dest); - flash_unlock_seq (info, sect); - flash_write_cmd (info, sect, info->addr_unlock1, AMD_CMD_WRITE); + flash_unlock_seq(info, sect); + flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_WRITE); sect_found = 1; break; #ifdef CONFIG_FLASH_CFI_LEGACY case CFI_CMDSET_AMD_LEGACY: sect = find_sector(info, dest); - flash_unlock_seq (info, 0); - flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_WRITE); + flash_unlock_seq(info, 0); + flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_WRITE); sect_found = 1; break; #endif @@ -854,10 +854,10 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
/* re-enable interrupts if necessary */ if (flag) - enable_interrupts (); + enable_interrupts();
if (!sect_found) - sect = find_sector (info, dest); + sect = find_sector(info, dest);
if (use_flash_status_poll(info)) return flash_status_poll(info, &cword, dstaddr, @@ -869,7 +869,7 @@ static int flash_write_cfiword (flash_info_t * info, ulong dest,
#ifdef CONFIG_SYS_FLASH_USE_BUFFER_WRITE
-static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, +static int flash_write_cfibuffer(flash_info_t * info, ulong dest, uchar * cp, int len) { flash_sect_t sector; @@ -933,7 +933,7 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, }
src = cp; - sector = find_sector (info, dest); + sector = find_sector(info, dest);
switch (info->vendor) { case CFI_CMDSET_INTEL_PROG_REGIONS: @@ -941,17 +941,17 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, case CFI_CMDSET_INTEL_EXTENDED: write_cmd = (info->vendor == CFI_CMDSET_INTEL_PROG_REGIONS) ? FLASH_CMD_WRITE_BUFFER_PROG : FLASH_CMD_WRITE_TO_BUFFER; - flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS); - flash_write_cmd (info, sector, 0, FLASH_CMD_READ_STATUS); - flash_write_cmd (info, sector, 0, write_cmd); - retcode = flash_status_check (info, sector, + flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); + flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); + flash_write_cmd(info, sector, 0, write_cmd); + retcode = flash_status_check(info, sector, info->buffer_write_tout, "write to buffer"); if (retcode == ERR_OK) { /* reduce the number of loops by the width of * the port */ cnt = len >> shift; - flash_write_cmd (info, sector, 0, cnt - 1); + flash_write_cmd(info, sector, 0, cnt - 1); while (cnt-- > 0) { switch (info->portwidth) { case FLASH_CFI_8BIT: @@ -975,9 +975,9 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, goto out_unmap; } } - flash_write_cmd (info, sector, 0, + flash_write_cmd(info, sector, 0, FLASH_CMD_WRITE_BUFFER_CONFIRM); - retcode = flash_full_status_check ( + retcode = flash_full_status_check( info, sector, info->buffer_write_tout, "buffer write"); } @@ -1025,7 +1025,7 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, goto out_unmap; }
- flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM); + flash_write_cmd(info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM); if (use_flash_status_poll(info)) retcode = flash_status_poll(info, src - (1 << shift), dst - (1 << shift), @@ -1038,7 +1038,7 @@ static int flash_write_cfibuffer (flash_info_t * info, ulong dest, uchar * cp, break;
default: - debug ("Unknown Command Set\n"); + debug("Unknown Command Set\n"); retcode = ERR_INVAL; break; } @@ -1051,7 +1051,7 @@ out_unmap:
/*----------------------------------------------------------------------- */ -int flash_erase (flash_info_t * info, int s_first, int s_last) +int flash_erase(flash_info_t * info, int s_first, int s_last) { int rcode = 0; int prot; @@ -1059,11 +1059,11 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) int st;
if (info->flash_id != FLASH_MAN_CFI) { - puts ("Can't erase unknown flash type - aborted\n"); + puts("Can't erase unknown flash type - aborted\n"); return 1; } if ((s_first < 0) || (s_first > s_last)) { - puts ("- no sectors to erase\n"); + puts("- no sectors to erase\n"); return 1; }
@@ -1074,10 +1074,10 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) } } if (prot) { - printf ("- Warning: %d protected sectors will not be erased!\n", + printf("- Warning: %d protected sectors will not be erased!\n", prot); } else if (flash_verbose) { - putc ('\n'); + putc('\n'); }
@@ -1118,35 +1118,35 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: - flash_write_cmd (info, sect, 0, + flash_write_cmd(info, sect, 0, FLASH_CMD_CLEAR_STATUS); - flash_write_cmd (info, sect, 0, + flash_write_cmd(info, sect, 0, FLASH_CMD_BLOCK_ERASE); - flash_write_cmd (info, sect, 0, + flash_write_cmd(info, sect, 0, FLASH_CMD_ERASE_CONFIRM); break; case CFI_CMDSET_AMD_STANDARD: case CFI_CMDSET_AMD_EXTENDED: - flash_unlock_seq (info, sect); - flash_write_cmd (info, sect, + flash_unlock_seq(info, sect); + flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_ERASE_START); - flash_unlock_seq (info, sect); - flash_write_cmd (info, sect, 0, + flash_unlock_seq(info, sect); + flash_write_cmd(info, sect, 0, info->cmd_erase_sector); break; #ifdef CONFIG_FLASH_CFI_LEGACY case CFI_CMDSET_AMD_LEGACY: - flash_unlock_seq (info, 0); - flash_write_cmd (info, 0, info->addr_unlock1, + flash_unlock_seq(info, 0); + flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_ERASE_START); - flash_unlock_seq (info, 0); - flash_write_cmd (info, sect, 0, + flash_unlock_seq(info, 0); + flash_write_cmd(info, sect, 0, AMD_CMD_ERASE_SECTOR); break; #endif default: - debug ("Unkown flash vendor %d\n", + debug("Unkown flash vendor %d\n", info->vendor); break; } @@ -1166,12 +1166,12 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) if (st) rcode = 1; else if (flash_verbose) - putc ('.'); + putc('.'); } }
if (flash_verbose) - puts (" done\n"); + puts(" done\n");
return rcode; } @@ -1200,53 +1200,53 @@ static int sector_erased(flash_info_t *info, int i) } #endif /* CONFIG_SYS_FLASH_EMPTY_INFO */
-void flash_print_info (flash_info_t * info) +void flash_print_info(flash_info_t * info) { int i;
if (info->flash_id != FLASH_MAN_CFI) { - puts ("missing or unknown FLASH type\n"); + puts("missing or unknown FLASH type\n"); return; }
- printf ("%s flash (%d x %d)", + printf("%s flash (%d x %d)", info->name, (info->portwidth << 3), (info->chipwidth << 3)); if (info->size < 1024*1024) - printf (" Size: %ld kB in %d Sectors\n", + printf(" Size: %ld kB in %d Sectors\n", info->size >> 10, info->sector_count); else - printf (" Size: %ld MB in %d Sectors\n", + printf(" Size: %ld MB in %d Sectors\n", info->size >> 20, info->sector_count); - printf (" "); + printf(" "); switch (info->vendor) { case CFI_CMDSET_INTEL_PROG_REGIONS: - printf ("Intel Prog Regions"); + printf("Intel Prog Regions"); break; case CFI_CMDSET_INTEL_STANDARD: - printf ("Intel Standard"); + printf("Intel Standard"); break; case CFI_CMDSET_INTEL_EXTENDED: - printf ("Intel Extended"); + printf("Intel Extended"); break; case CFI_CMDSET_AMD_STANDARD: - printf ("AMD Standard"); + printf("AMD Standard"); break; case CFI_CMDSET_AMD_EXTENDED: - printf ("AMD Extended"); + printf("AMD Extended"); break; #ifdef CONFIG_FLASH_CFI_LEGACY case CFI_CMDSET_AMD_LEGACY: - printf ("AMD Legacy"); + printf("AMD Legacy"); break; #endif default: - printf ("Unknown (%d)", info->vendor); + printf("Unknown (%d)", info->vendor); break; } - printf (" command set, Manufacturer ID: 0x%02X, Device ID: 0x", + printf(" command set, Manufacturer ID: 0x%02X, Device ID: 0x", info->manufacturer_id); - printf (info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", + printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", info->device_id); if ((info->device_id & 0xff) == 0x7E) { printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", @@ -1254,17 +1254,17 @@ void flash_print_info (flash_info_t * info) } if ((info->vendor == CFI_CMDSET_AMD_STANDARD) && (info->legacy_unlock)) printf("\n Advanced Sector Protection (PPB) enabled"); - printf ("\n Erase timeout: %ld ms, write timeout: %ld ms\n", + printf("\n Erase timeout: %ld ms, write timeout: %ld ms\n", info->erase_blk_tout, info->write_tout); if (info->buffer_size > 1) { - printf (" Buffer write timeout: %ld ms, " + printf(" Buffer write timeout: %ld ms, " "buffer size: %d bytes\n", info->buffer_write_tout, info->buffer_size); }
- puts ("\n Sector Start Addresses:"); + puts("\n Sector Start Addresses:"); for (i = 0; i < info->sector_count; ++i) { if (ctrlc()) break; @@ -1272,17 +1272,17 @@ void flash_print_info (flash_info_t * info) putc('\n'); #ifdef CONFIG_SYS_FLASH_EMPTY_INFO /* print empty and read-only info */ - printf (" %08lX %c %s ", + printf(" %08lX %c %s ", info->start[i], sector_erased(info, i) ? 'E' : ' ', info->protect[i] ? "RO" : " "); #else /* ! CONFIG_SYS_FLASH_EMPTY_INFO */ - printf (" %08lX %s ", + printf(" %08lX %s ", info->start[i], info->protect[i] ? "RO" : " "); #endif } - putc ('\n'); + putc('\n'); return; }
@@ -1298,9 +1298,9 @@ void flash_print_info (flash_info_t * info) dots -= dots_sub; \ if ((scale > 0) && (dots <= 0)) { \ if ((digit % 5) == 0) \ - printf ("%d", digit / 5); \ + printf("%d", digit / 5); \ else \ - putc ('.'); \ + putc('.'); \ digit--; \ dots += scale; \ } \ @@ -1315,7 +1315,7 @@ void flash_print_info (flash_info_t * info) * 1 - write timeout * 2 - Flash not erased */ -int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) +int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt) { ulong wp; uchar *p; @@ -1347,16 +1347,16 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) cword.w32 = 0; p = (uchar *)wp; for (i = 0; i < aln; ++i) - flash_add_byte (info, &cword, flash_read8(p + i)); + flash_add_byte(info, &cword, flash_read8(p + i));
for (; (i < info->portwidth) && (cnt > 0); i++) { - flash_add_byte (info, &cword, *src++); + flash_add_byte(info, &cword, *src++); cnt--; } for (; (cnt == 0) && (i < info->portwidth); ++i) - flash_add_byte (info, &cword, flash_read8(p + i)); + flash_add_byte(info, &cword, flash_read8(p + i));
- rc = flash_write_cfiword (info, wp, cword); + rc = flash_write_cfiword(info, wp, cword); if (rc != 0) return rc;
@@ -1373,8 +1373,8 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) if (info->buffer_size == 1) { cword.w32 = 0; for (i = 0; i < info->portwidth; i++) - flash_add_byte (info, &cword, *src++); - if ((rc = flash_write_cfiword (info, wp, cword)) != 0) + flash_add_byte(info, &cword, *src++); + if ((rc = flash_write_cfiword(info, wp, cword)) != 0) return rc; wp += info->portwidth; cnt -= info->portwidth; @@ -1385,7 +1385,7 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) i = buffered_size - (wp % buffered_size); if (i > cnt) i = cnt; - if ((rc = flash_write_cfibuffer (info, wp, src, i)) != ERR_OK) + if ((rc = flash_write_cfibuffer(info, wp, src, i)) != ERR_OK) return rc; i -= i & (info->portwidth - 1); wp += i; @@ -1400,9 +1400,9 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) while (cnt >= info->portwidth) { cword.w32 = 0; for (i = 0; i < info->portwidth; i++) { - flash_add_byte (info, &cword, *src++); + flash_add_byte(info, &cword, *src++); } - if ((rc = flash_write_cfiword (info, wp, cword)) != 0) + if ((rc = flash_write_cfiword(info, wp, cword)) != 0) return rc; wp += info->portwidth; cnt -= info->portwidth; @@ -1423,13 +1423,13 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) cword.w32 = 0; p = (uchar *)wp; for (i = 0; (i < info->portwidth) && (cnt > 0); ++i) { - flash_add_byte (info, &cword, *src++); + flash_add_byte(info, &cword, *src++); --cnt; } for (; i < info->portwidth; ++i) - flash_add_byte (info, &cword, flash_read8(p + i)); + flash_add_byte(info, &cword, flash_read8(p + i));
- return flash_write_cfiword (info, wp, cword); + return flash_write_cfiword(info, wp, cword); }
static inline int manufact_match(flash_info_t *info, u32 manu) @@ -1475,7 +1475,7 @@ static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) return 0; }
-int flash_real_protect (flash_info_t * info, long sector, int prot) +int flash_real_protect(flash_info_t * info, long sector, int prot) { int retcode = 0;
@@ -1502,19 +1502,19 @@ int flash_real_protect (flash_info_t * info, long sector, int prot) /* U-Boot only checks the first byte */ if (manufact_match(info, ATM_MANUFACT)) { if (prot) { - flash_unlock_seq (info, 0); - flash_write_cmd (info, 0, + flash_unlock_seq(info, 0); + flash_write_cmd(info, 0, info->addr_unlock1, ATM_CMD_SOFTLOCK_START); - flash_unlock_seq (info, 0); - flash_write_cmd (info, sector, 0, + flash_unlock_seq(info, 0); + flash_write_cmd(info, sector, 0, ATM_CMD_LOCK_SECT); } else { - flash_write_cmd (info, 0, + flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_UNLOCK_START); if (info->device_id == ATM_ID_BV6416) - flash_write_cmd (info, sector, + flash_write_cmd(info, sector, 0, ATM_CMD_UNLOCK_SECT); } } @@ -1562,12 +1562,12 @@ int flash_real_protect (flash_info_t * info, long sector, int prot) break; #ifdef CONFIG_FLASH_CFI_LEGACY case CFI_CMDSET_AMD_LEGACY: - flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS); - flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT); + flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); + flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); if (prot) - flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET); + flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_SET); else - flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR); + flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_CLEAR); #endif };
@@ -1577,7 +1577,7 @@ int flash_real_protect (flash_info_t * info, long sector, int prot) */ flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); if ((retcode = - flash_full_status_check (info, sector, info->erase_blk_tout, + flash_full_status_check(info, sector, info->erase_blk_tout, prot ? "protect" : "unprotect")) == 0) {
info->protect[sector] = prot; @@ -1591,7 +1591,7 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)
for (i = 0; i < info->sector_count; i++) { if (info->protect[i]) - flash_real_protect (info, i, 1); + flash_real_protect(info, i, 1); } } } @@ -1601,17 +1601,17 @@ int flash_real_protect (flash_info_t * info, long sector, int prot) /*----------------------------------------------------------------------- * flash_read_user_serial - read the OneTimeProgramming cells */ -void flash_read_user_serial (flash_info_t * info, void *buffer, int offset, +void flash_read_user_serial(flash_info_t * info, void *buffer, int offset, int len) { uchar *src; uchar *dst;
dst = buffer; - src = flash_map (info, 0, FLASH_OFFSET_USER_PROTECTION); - flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID); - memcpy (dst, src + offset, len); - flash_write_cmd (info, 0, 0, info->cmd_reset); + src = flash_map(info, 0, FLASH_OFFSET_USER_PROTECTION); + flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); + memcpy(dst, src + offset, len); + flash_write_cmd(info, 0, 0, info->cmd_reset); udelay(1); flash_unmap(info, 0, FLASH_OFFSET_USER_PROTECTION, src); } @@ -1619,15 +1619,15 @@ void flash_read_user_serial (flash_info_t * info, void *buffer, int offset, /* * flash_read_factory_serial - read the device Id from the protection area */ -void flash_read_factory_serial (flash_info_t * info, void *buffer, int offset, +void flash_read_factory_serial(flash_info_t * info, void *buffer, int offset, int len) { uchar *src;
- src = flash_map (info, 0, FLASH_OFFSET_INTEL_PROTECTION); - flash_write_cmd (info, 0, 0, FLASH_CMD_READ_ID); - memcpy (buffer, src + offset, len); - flash_write_cmd (info, 0, 0, info->cmd_reset); + src = flash_map(info, 0, FLASH_OFFSET_INTEL_PROTECTION); + flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); + memcpy(buffer, src + offset, len); + flash_write_cmd(info, 0, 0, info->cmd_reset); udelay(1); flash_unmap(info, 0, FLASH_OFFSET_INTEL_PROTECTION, src); } @@ -1664,11 +1664,11 @@ static void cmdset_intel_read_jedec_ids(flash_info_t *info) udelay(1); flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); udelay(1000); /* some flash are slow to respond */ - info->manufacturer_id = flash_read_uchar (info, + info->manufacturer_id = flash_read_uchar(info, FLASH_OFFSET_MANUFACTURER_ID); info->device_id = (info->chipwidth == FLASH_CFI_16BIT) ? - flash_read_word (info, FLASH_OFFSET_DEVICE_ID) : - flash_read_uchar (info, FLASH_OFFSET_DEVICE_ID); + flash_read_word(info, FLASH_OFFSET_DEVICE_ID) : + flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID); flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); }
@@ -1682,7 +1682,7 @@ static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry) #ifdef CONFIG_SYS_FLASH_PROTECTION /* read legacy lock/unlock bit from intel flash */ if (info->ext_addr) { - info->legacy_unlock = flash_read_uchar (info, + info->legacy_unlock = flash_read_uchar(info, info->ext_addr + 5) & 0x08; } #endif @@ -1701,11 +1701,11 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info) flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); udelay(1000); /* some flash are slow to respond */
- manuId = flash_read_uchar (info, FLASH_OFFSET_MANUFACTURER_ID); + manuId = flash_read_uchar(info, FLASH_OFFSET_MANUFACTURER_ID); /* JEDEC JEP106Z specifies ID codes up to bank 7 */ while (manuId == FLASH_CONTINUATION_CODE && bankId < 0x800) { bankId += 0x100; - manuId = flash_read_uchar (info, + manuId = flash_read_uchar(info, bankId | FLASH_OFFSET_MANUFACTURER_ID); } info->manufacturer_id = manuId; @@ -1715,26 +1715,26 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info)
switch (info->chipwidth){ case FLASH_CFI_8BIT: - info->device_id = flash_read_uchar (info, + info->device_id = flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID); if (info->device_id == 0x7E) { /* AMD 3-byte (expanded) device ids */ - info->device_id2 = flash_read_uchar (info, + info->device_id2 = flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID2); info->device_id2 <<= 8; - info->device_id2 |= flash_read_uchar (info, + info->device_id2 |= flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID3); } break; case FLASH_CFI_16BIT: - info->device_id = flash_read_word (info, + info->device_id = flash_read_word(info, FLASH_OFFSET_DEVICE_ID); if ((info->device_id & 0xff) == 0x7E) { /* AMD 3-byte (expanded) device ids */ - info->device_id2 = flash_read_uchar (info, + info->device_id2 = flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID2); info->device_id2 <<= 8; - info->device_id2 |= flash_read_uchar (info, + info->device_id2 |= flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID3); } break; @@ -1765,7 +1765,7 @@ static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry) }
#ifdef CONFIG_FLASH_CFI_LEGACY -static void flash_read_jedec_ids (flash_info_t * info) +static void flash_read_jedec_ids(flash_info_t * info) { info->manufacturer_id = 0; info->device_id = 0; @@ -1860,7 +1860,7 @@ static inline int flash_detect_legacy(phys_addr_t base, int banknum) * detect if flash is compatible with the Common Flash Interface (CFI) * http://www.jedec.org/download/search/jesd68.pdf */ -static void flash_read_cfi (flash_info_t *info, void *buf, +static void flash_read_cfi(flash_info_t *info, void *buf, unsigned int start, size_t len) { u8 *p = buf; @@ -1884,7 +1884,7 @@ static void __flash_cmd_reset(flash_info_t *info) void flash_cmd_reset(flash_info_t *info) __attribute__((weak,alias("__flash_cmd_reset")));
-static int __flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) +static int __flash_detect_cfi(flash_info_t * info, struct cfi_qry *qry) { int cfi_offset;
@@ -1893,21 +1893,21 @@ static int __flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry)
for (cfi_offset = 0; cfi_offset < ARRAY_SIZE(flash_offset_cfi); cfi_offset++) { - flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset], + flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI); - if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q') - && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') - && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { + if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') + && flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') + && flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, sizeof(struct cfi_qry)); info->interface = le16_to_cpu(qry->interface_desc);
info->cfi_offset = flash_offset_cfi[cfi_offset]; - debug ("device interface is %d\n", + debug("device interface is %d\n", info->interface); - debug ("found port %d chip %d ", + debug("found port %d chip %d ", info->portwidth, info->chipwidth); - debug ("port %d bits chip %d bits\n", + debug("port %d bits chip %d bits\n", info->portwidth << CFI_FLASH_SHIFT_WIDTH, info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
@@ -1938,9 +1938,9 @@ static int __flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) return 0; }
-static int flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) +static int flash_detect_cfi(flash_info_t * info, struct cfi_qry *qry) { - debug ("flash detect cfi\n"); + debug("flash detect cfi\n");
for (info->portwidth = CONFIG_SYS_FLASH_CFI_WIDTH; info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) { @@ -1950,7 +1950,7 @@ static int flash_detect_cfi (flash_info_t * info, struct cfi_qry *qry) if (__flash_detect_cfi(info, qry)) return 1; } - debug ("not found\n"); + debug("not found\n"); return 0; }
@@ -2057,7 +2057,7 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) * The following code cannot be run from FLASH! * */ -ulong flash_get_size (phys_addr_t base, int banknum) +ulong flash_get_size(phys_addr_t base, int banknum) { flash_info_t *info = &flash_info[banknum]; int i, j; @@ -2081,20 +2081,20 @@ ulong flash_get_size (phys_addr_t base, int banknum)
info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE);
- if (flash_detect_cfi (info, &qry)) { + if (flash_detect_cfi(info, &qry)) { info->vendor = le16_to_cpu(get_unaligned(&(qry.p_id))); info->ext_addr = le16_to_cpu(get_unaligned(&(qry.p_adr))); num_erase_regions = qry.num_erase_regions;
if (info->ext_addr) { - info->cfi_version = (ushort) flash_read_uchar (info, + info->cfi_version = (ushort) flash_read_uchar(info, info->ext_addr + 3) << 8; - info->cfi_version |= (ushort) flash_read_uchar (info, + info->cfi_version |= (ushort) flash_read_uchar(info, info->ext_addr + 4); }
#ifdef DEBUG - flash_printqry (&qry); + flash_printqry(&qry); #endif
switch (info->vendor) { @@ -2139,11 +2139,11 @@ ulong flash_get_size (phys_addr_t base, int banknum) break; }
- debug ("manufacturer is %d\n", info->vendor); - debug ("manufacturer id is 0x%x\n", info->manufacturer_id); - debug ("device id is 0x%x\n", info->device_id); - debug ("device id2 is 0x%x\n", info->device_id2); - debug ("cfi version is 0x%04x\n", info->cfi_version); + debug("manufacturer is %d\n", info->vendor); + debug("manufacturer id is 0x%x\n", info->manufacturer_id); + debug("device id is 0x%x\n", info->device_id); + debug("device id2 is 0x%x\n", info->device_id2); + debug("cfi version is 0x%04x\n", info->cfi_version);
size_ratio = info->portwidth / info->chipwidth; /* if the chip is x8/x16 reduce the ratio by half */ @@ -2151,7 +2151,7 @@ ulong flash_get_size (phys_addr_t base, int banknum) && (info->chipwidth == FLASH_CFI_BY8)) { size_ratio >>= 1; } - debug ("size_ratio %d port %d bits chip %d bits\n", + debug("size_ratio %d port %d bits chip %d bits\n", size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); info->size = 1 << qry.dev_size; @@ -2162,12 +2162,12 @@ ulong flash_get_size (phys_addr_t base, int banknum) debug("[truncated from %ldMiB]", info->size >> 20); info->size = max_size; } - debug ("found %d erase regions\n", num_erase_regions); + debug("found %d erase regions\n", num_erase_regions); sect_cnt = 0; sector = base; for (i = 0; i < num_erase_regions; i++) { if (i > NUM_ERASE_REGIONS) { - printf ("%d erase regions found, only %d used\n", + printf("%d erase regions found, only %d used\n", num_erase_regions, NUM_ERASE_REGIONS); break; } @@ -2180,7 +2180,7 @@ ulong flash_get_size (phys_addr_t base, int banknum) tmp >>= 16; erase_region_size = (tmp & 0xffff) ? ((tmp & 0xffff) * 256) : 128; - debug ("erase_region_count = %d erase_region_size = %d\n", + debug("erase_region_count = %d erase_region_size = %d\n", erase_region_count, erase_region_size); for (j = 0; j < erase_region_count; j++) { if (sector - base >= info->size) @@ -2211,7 +2211,7 @@ ulong flash_get_size (phys_addr_t base, int banknum) flash_write_cmd(info, sect_cnt, 0, FLASH_CMD_READ_ID); info->protect[sect_cnt] = - flash_isset (info, sect_cnt, + flash_isset(info, sect_cnt, FLASH_OFFSET_PROTECT, FLASH_STATUS_PROTECT); flash_write_cmd(info, sect_cnt, 0, @@ -2268,7 +2268,7 @@ ulong flash_get_size (phys_addr_t base, int banknum) info->portwidth >>= 1; }
- flash_write_cmd (info, 0, 0, info->cmd_reset); + flash_write_cmd(info, 0, 0, info->cmd_reset); }
return (info->size); @@ -2356,7 +2356,7 @@ static void flash_protect_default(void) #endif }
-unsigned long flash_init (void) +unsigned long flash_init(void) { unsigned long size = 0; int i; @@ -2384,7 +2384,7 @@ unsigned long flash_init (void) size += flash_info[i].size; if (flash_info[i].flash_id == FLASH_UNKNOWN) { #ifndef CONFIG_SYS_FLASH_QUIET_TEST - printf ("## Unknown flash on Bank %d " + printf("## Unknown flash on Bank %d " "- Size = 0x%08lx = %ld MB\n", i+1, flash_info[i].size, flash_info[i].size >> 20); @@ -2416,7 +2416,7 @@ unsigned long flash_init (void) * unlock only one sector. This will * unlock all sectors. */ - flash_real_protect (&flash_info[i], 0, 0); + flash_real_protect(&flash_info[i], 0, 0);
flash_info[i].legacy_unlock = 1;
@@ -2430,7 +2430,7 @@ unsigned long flash_init (void) /* * No legancy unlocking -> unlock all sectors */ - flash_protect (FLAG_PROTECT_CLEAR, + flash_protect(FLAG_PROTECT_CLEAR, flash_info[i].start[0], flash_info[i].start[0] + flash_info[i].size - 1,

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index b3dda8bd4a..1b0eb3398c 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -204,7 +204,7 @@ unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect) * create an address based on the offset and the port width */ static inline void * -flash_map(flash_info_t * info, flash_sect_t sect, uint offset) +flash_map(flash_info_t *info, flash_sect_t sect, uint offset) { unsigned int byte_offset = offset * info->portwidth;
@@ -283,7 +283,7 @@ static void flash_printqry(struct cfi_qry *qry) /*----------------------------------------------------------------------- * read a character at a port width address */ -static inline uchar flash_read_uchar(flash_info_t * info, uint offset) +static inline uchar flash_read_uchar(flash_info_t *info, uint offset) { uchar *cp; uchar retval; @@ -301,7 +301,7 @@ static inline uchar flash_read_uchar(flash_info_t * info, uint offset) /*----------------------------------------------------------------------- * read a word at a port width address, assume 16bit bus */ -static inline ushort flash_read_word(flash_info_t * info, uint offset) +static inline ushort flash_read_word(flash_info_t *info, uint offset) { ushort *addr, retval;
@@ -316,7 +316,7 @@ static inline ushort flash_read_word(flash_info_t * info, uint offset) * read a long word by picking the least significant byte of each maximum * port size word. Swap for ppc format. */ -static ulong flash_read_long (flash_info_t * info, flash_sect_t sect, +static ulong flash_read_long (flash_info_t *info, flash_sect_t sect, uint offset) { uchar *addr; @@ -402,7 +402,7 @@ static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, flash_unmap(info, sect, offset, addr); }
-static void flash_unlock_seq(flash_info_t * info, flash_sect_t sect) +static void flash_unlock_seq(flash_info_t *info, flash_sect_t sect) { flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START); flash_write_cmd(info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK); @@ -410,7 +410,7 @@ static void flash_unlock_seq(flash_info_t * info, flash_sect_t sect)
/*----------------------------------------------------------------------- */ -static int flash_isequal(flash_info_t * info, flash_sect_t sect, +static int flash_isequal(flash_info_t *info, flash_sect_t sect, uint offset, uchar cmd) { void *addr; @@ -458,7 +458,7 @@ static int flash_isequal(flash_info_t * info, flash_sect_t sect,
/*----------------------------------------------------------------------- */ -static int flash_isset(flash_info_t * info, flash_sect_t sect, +static int flash_isset(flash_info_t *info, flash_sect_t sect, uint offset, uchar cmd) { void *addr; @@ -491,7 +491,7 @@ static int flash_isset(flash_info_t * info, flash_sect_t sect,
/*----------------------------------------------------------------------- */ -static int flash_toggle(flash_info_t * info, flash_sect_t sect, +static int flash_toggle(flash_info_t *info, flash_sect_t sect, uint offset, uchar cmd) { void *addr; @@ -529,7 +529,7 @@ static int flash_toggle(flash_info_t * info, flash_sect_t sect, * This routine checks the status of the chip and returns true if the * chip is busy. */ -static int flash_is_busy(flash_info_t * info, flash_sect_t sect) +static int flash_is_busy(flash_info_t *info, flash_sect_t sect) { int retval;
@@ -566,7 +566,7 @@ static int flash_is_busy(flash_info_t * info, flash_sect_t sect) * wait for XSR.7 to be set. Time out with an error if it does not. * This routine does not set the flash to read-array mode. */ -static int flash_status_check(flash_info_t * info, flash_sect_t sector, +static int flash_status_check(flash_info_t *info, flash_sect_t sector, ulong tout, char *prompt) { ulong start; @@ -604,7 +604,7 @@ static int flash_status_check(flash_info_t * info, flash_sect_t sector, * * This routine sets the flash to read-array mode. */ -static int flash_full_status_check(flash_info_t * info, flash_sect_t sector, +static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, ulong tout, char *prompt) { int retcode; @@ -709,7 +709,7 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst,
/*----------------------------------------------------------------------- */ -static void flash_add_byte(flash_info_t * info, cfiword_t * cword, uchar c) +static void flash_add_byte(flash_info_t *info, cfiword_t *cword, uchar c) { #if defined(__LITTLE_ENDIAN) && !defined(CONFIG_SYS_WRITE_SWAPPED_DATA) unsigned short w; @@ -755,7 +755,7 @@ static void flash_add_byte(flash_info_t * info, cfiword_t * cword, uchar c) * Loop through the sector table starting from the previously found sector. * Searches forwards or backwards, dependent on the passed address. */ -static flash_sect_t find_sector(flash_info_t * info, ulong addr) +static flash_sect_t find_sector(flash_info_t *info, ulong addr) { static flash_sect_t saved_sector; /* previously found sector */ static flash_info_t *saved_info; /* previously used flash bank */ @@ -781,7 +781,7 @@ static flash_sect_t find_sector(flash_info_t * info, ulong addr)
/*----------------------------------------------------------------------- */ -static int flash_write_cfiword(flash_info_t * info, ulong dest, +static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword) { void *dstaddr = (void *)dest; @@ -869,7 +869,7 @@ static int flash_write_cfiword(flash_info_t * info, ulong dest,
#ifdef CONFIG_SYS_FLASH_USE_BUFFER_WRITE
-static int flash_write_cfibuffer(flash_info_t * info, ulong dest, uchar * cp, +static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, int len) { flash_sect_t sector; @@ -1051,7 +1051,7 @@ out_unmap:
/*----------------------------------------------------------------------- */ -int flash_erase(flash_info_t * info, int s_first, int s_last) +int flash_erase(flash_info_t *info, int s_first, int s_last) { int rcode = 0; int prot; @@ -1200,7 +1200,7 @@ static int sector_erased(flash_info_t *info, int i) } #endif /* CONFIG_SYS_FLASH_EMPTY_INFO */
-void flash_print_info(flash_info_t * info) +void flash_print_info(flash_info_t *info) { int i;
@@ -1315,7 +1315,7 @@ void flash_print_info(flash_info_t * info) * 1 - write timeout * 2 - Flash not erased */ -int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt) +int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) { ulong wp; uchar *p; @@ -1475,7 +1475,7 @@ static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) return 0; }
-int flash_real_protect(flash_info_t * info, long sector, int prot) +int flash_real_protect(flash_info_t *info, long sector, int prot) { int retcode = 0;
@@ -1601,7 +1601,7 @@ int flash_real_protect(flash_info_t * info, long sector, int prot) /*----------------------------------------------------------------------- * flash_read_user_serial - read the OneTimeProgramming cells */ -void flash_read_user_serial(flash_info_t * info, void *buffer, int offset, +void flash_read_user_serial(flash_info_t *info, void *buffer, int offset, int len) { uchar *src; @@ -1619,7 +1619,7 @@ void flash_read_user_serial(flash_info_t * info, void *buffer, int offset, /* * flash_read_factory_serial - read the device Id from the protection area */ -void flash_read_factory_serial(flash_info_t * info, void *buffer, int offset, +void flash_read_factory_serial(flash_info_t *info, void *buffer, int offset, int len) { uchar *src; @@ -1765,7 +1765,7 @@ static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry) }
#ifdef CONFIG_FLASH_CFI_LEGACY -static void flash_read_jedec_ids(flash_info_t * info) +static void flash_read_jedec_ids(flash_info_t *info) { info->manufacturer_id = 0; info->device_id = 0; @@ -1884,7 +1884,7 @@ static void __flash_cmd_reset(flash_info_t *info) void flash_cmd_reset(flash_info_t *info) __attribute__((weak,alias("__flash_cmd_reset")));
-static int __flash_detect_cfi(flash_info_t * info, struct cfi_qry *qry) +static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) { int cfi_offset;
@@ -1938,7 +1938,7 @@ static int __flash_detect_cfi(flash_info_t * info, struct cfi_qry *qry) return 0; }
-static int flash_detect_cfi(flash_info_t * info, struct cfi_qry *qry) +static int flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) { debug("flash detect cfi\n");

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 1b0eb3398c..03bfb634cc 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -230,7 +230,7 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) uchar val; uchar *cp = (uchar *) cmdbuf;
- for (i = info->portwidth; i > 0; i--){ + for (i = info->portwidth; i > 0; i--) { cword_offset = (info->portwidth-i)%info->chipwidth; #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) cp_offset = info->portwidth - i; @@ -511,8 +511,8 @@ static int flash_toggle(flash_info_t *info, flash_sect_t sect, retval = flash_read32(addr) != flash_read32(addr); break; case FLASH_CFI_64BIT: - retval = ( (flash_read32( addr ) != flash_read32( addr )) || - (flash_read32(addr+4) != flash_read32(addr+4)) ); + retval = ((flash_read32(addr) != flash_read32(addr)) || + (flash_read32(addr+4) != flash_read32(addr+4))); break; default: retval = 0; @@ -1713,7 +1713,7 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info) lsbits = flash_read_uchar(info, FLASH_OFFSET_LOWER_SW_BITS); info->sr_supported = lsbits & BIT(0);
- switch (info->chipwidth){ + switch (info->chipwidth) { case FLASH_CFI_8BIT: info->device_id = flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID); @@ -1832,7 +1832,7 @@ static int flash_detect_legacy(phys_addr_t base, int banknum) } }
- switch(info->vendor) { + switch (info->vendor) { case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: @@ -1919,12 +1919,12 @@ static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) * modify the unlock address if we are * in compatibility mode */ - if ( /* x8/x16 in x8 mode */ - ((info->chipwidth == FLASH_CFI_BY8) && - (info->interface == FLASH_CFI_X8X16)) || - /* x16/x32 in x16 mode */ - ((info->chipwidth == FLASH_CFI_BY16) && - (info->interface == FLASH_CFI_X16X32))) + if (/* x8/x16 in x8 mode */ + ((info->chipwidth == FLASH_CFI_BY8) && + (info->interface == FLASH_CFI_X8X16)) || + /* x16/x32 in x16 mode */ + ((info->chipwidth == FLASH_CFI_BY16) && + (info->interface == FLASH_CFI_X16X32))) { info->addr_unlock1 = 0xaaa; info->addr_unlock2 = 0x555;

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 03bfb634cc..8c62648642 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -234,10 +234,10 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) cword_offset = (info->portwidth-i)%info->chipwidth; #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) cp_offset = info->portwidth - i; - val = *((uchar*)&cmd_le + cword_offset); + val = *((uchar *)&cmd_le + cword_offset); #else cp_offset = i - 1; - val = *((uchar*)&cmd + sizeof(u32) - cword_offset - 1); + val = *((uchar *)&cmd + sizeof(u32) - cword_offset - 1); #endif cp[cp_offset] = (cword_offset >= sizeof(u32)) ? 0x00 : val; }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 200 ++++++++++++++++++++++++------------------------ 1 file changed, 100 insertions(+), 100 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 8c62648642..a766facb2a 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1220,29 +1220,29 @@ void flash_print_info(flash_info_t *info) info->size >> 20, info->sector_count); printf(" "); switch (info->vendor) { - case CFI_CMDSET_INTEL_PROG_REGIONS: - printf("Intel Prog Regions"); - break; - case CFI_CMDSET_INTEL_STANDARD: - printf("Intel Standard"); - break; - case CFI_CMDSET_INTEL_EXTENDED: - printf("Intel Extended"); - break; - case CFI_CMDSET_AMD_STANDARD: - printf("AMD Standard"); - break; - case CFI_CMDSET_AMD_EXTENDED: - printf("AMD Extended"); - break; + case CFI_CMDSET_INTEL_PROG_REGIONS: + printf("Intel Prog Regions"); + break; + case CFI_CMDSET_INTEL_STANDARD: + printf("Intel Standard"); + break; + case CFI_CMDSET_INTEL_EXTENDED: + printf("Intel Extended"); + break; + case CFI_CMDSET_AMD_STANDARD: + printf("AMD Standard"); + break; + case CFI_CMDSET_AMD_EXTENDED: + printf("AMD Extended"); + break; #ifdef CONFIG_FLASH_CFI_LEGACY - case CFI_CMDSET_AMD_LEGACY: - printf("AMD Legacy"); - break; + case CFI_CMDSET_AMD_LEGACY: + printf("AMD Legacy"); + break; #endif - default: - printf("Unknown (%d)", info->vendor); - break; + default: + printf("Unknown (%d)", info->vendor); + break; } printf(" command set, Manufacturer ID: 0x%02X, Device ID: 0x", info->manufacturer_id); @@ -1480,94 +1480,94 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) int retcode = 0;
switch (info->vendor) { - case CFI_CMDSET_INTEL_PROG_REGIONS: - case CFI_CMDSET_INTEL_STANDARD: - case CFI_CMDSET_INTEL_EXTENDED: - if (!cfi_protect_bugfix(info, sector, prot)) { + case CFI_CMDSET_INTEL_PROG_REGIONS: + case CFI_CMDSET_INTEL_STANDARD: + case CFI_CMDSET_INTEL_EXTENDED: + if (!cfi_protect_bugfix(info, sector, prot)) { + flash_write_cmd(info, sector, 0, + FLASH_CMD_CLEAR_STATUS); + flash_write_cmd(info, sector, 0, + FLASH_CMD_PROTECT); + if (prot) flash_write_cmd(info, sector, 0, - FLASH_CMD_CLEAR_STATUS); + FLASH_CMD_PROTECT_SET); + else flash_write_cmd(info, sector, 0, - FLASH_CMD_PROTECT); - if (prot) - flash_write_cmd(info, sector, 0, - FLASH_CMD_PROTECT_SET); - else - flash_write_cmd(info, sector, 0, - FLASH_CMD_PROTECT_CLEAR); + FLASH_CMD_PROTECT_CLEAR);
+ } + break; + case CFI_CMDSET_AMD_EXTENDED: + case CFI_CMDSET_AMD_STANDARD: + /* U-Boot only checks the first byte */ + if (manufact_match(info, ATM_MANUFACT)) { + if (prot) { + flash_unlock_seq(info, 0); + flash_write_cmd(info, 0, + info->addr_unlock1, + ATM_CMD_SOFTLOCK_START); + flash_unlock_seq(info, 0); + flash_write_cmd(info, sector, 0, + ATM_CMD_LOCK_SECT); + } else { + flash_write_cmd(info, 0, + info->addr_unlock1, + AMD_CMD_UNLOCK_START); + if (info->device_id == ATM_ID_BV6416) + flash_write_cmd(info, sector, + 0, ATM_CMD_UNLOCK_SECT); } - break; - case CFI_CMDSET_AMD_EXTENDED: - case CFI_CMDSET_AMD_STANDARD: - /* U-Boot only checks the first byte */ - if (manufact_match(info, ATM_MANUFACT)) { - if (prot) { - flash_unlock_seq(info, 0); - flash_write_cmd(info, 0, - info->addr_unlock1, - ATM_CMD_SOFTLOCK_START); - flash_unlock_seq(info, 0); + } + if (info->legacy_unlock) { + int flag = disable_interrupts(); + int lock_flag; + + flash_unlock_seq(info, 0); + flash_write_cmd(info, 0, info->addr_unlock1, + AMD_CMD_SET_PPB_ENTRY); + lock_flag = flash_isset(info, sector, 0, 0x01); + if (prot) { + if (lock_flag) { flash_write_cmd(info, sector, 0, - ATM_CMD_LOCK_SECT); - } else { - flash_write_cmd(info, 0, - info->addr_unlock1, - AMD_CMD_UNLOCK_START); - if (info->device_id == ATM_ID_BV6416) - flash_write_cmd(info, sector, - 0, ATM_CMD_UNLOCK_SECT); + AMD_CMD_PPB_LOCK_BC1); + flash_write_cmd(info, sector, 0, + AMD_CMD_PPB_LOCK_BC2); } - } - if (info->legacy_unlock) { - int flag = disable_interrupts(); - int lock_flag; - - flash_unlock_seq(info, 0); - flash_write_cmd(info, 0, info->addr_unlock1, - AMD_CMD_SET_PPB_ENTRY); - lock_flag = flash_isset(info, sector, 0, 0x01); - if (prot) { - if (lock_flag) { - flash_write_cmd(info, sector, 0, - AMD_CMD_PPB_LOCK_BC1); - flash_write_cmd(info, sector, 0, - AMD_CMD_PPB_LOCK_BC2); - } - debug("sector %ld %slocked\n", sector, - lock_flag ? "" : "already "); - } else { - if (!lock_flag) { - debug("unlock %ld\n", sector); - flash_write_cmd(info, 0, 0, - AMD_CMD_PPB_UNLOCK_BC1); - flash_write_cmd(info, 0, 0, - AMD_CMD_PPB_UNLOCK_BC2); - } - debug("sector %ld %sunlocked\n", sector, - !lock_flag ? "" : "already "); + debug("sector %ld %slocked\n", sector, + lock_flag ? "" : "already "); + } else { + if (!lock_flag) { + debug("unlock %ld\n", sector); + flash_write_cmd(info, 0, 0, + AMD_CMD_PPB_UNLOCK_BC1); + flash_write_cmd(info, 0, 0, + AMD_CMD_PPB_UNLOCK_BC2); } - if (flag) - enable_interrupts(); - - if (flash_status_check(info, sector, - info->erase_blk_tout, - prot ? "protect" : "unprotect")) - printf("status check error\n"); - - flash_write_cmd(info, 0, 0, - AMD_CMD_SET_PPB_EXIT_BC1); - flash_write_cmd(info, 0, 0, - AMD_CMD_SET_PPB_EXIT_BC2); + debug("sector %ld %sunlocked\n", sector, + !lock_flag ? "" : "already "); } - break; + if (flag) + enable_interrupts(); + + if (flash_status_check(info, sector, + info->erase_blk_tout, + prot ? "protect" : "unprotect")) + printf("status check error\n"); + + flash_write_cmd(info, 0, 0, + AMD_CMD_SET_PPB_EXIT_BC1); + flash_write_cmd(info, 0, 0, + AMD_CMD_SET_PPB_EXIT_BC2); + } + break; #ifdef CONFIG_FLASH_CFI_LEGACY - case CFI_CMDSET_AMD_LEGACY: - flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); - flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); - if (prot) - flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_SET); - else - flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_CLEAR); + case CFI_CMDSET_AMD_LEGACY: + flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); + flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); + if (prot) + flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_SET); + else + flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_CLEAR); #endif };

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index a766facb2a..a28f5eaea9 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -231,7 +231,7 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) uchar *cp = (uchar *) cmdbuf;
for (i = info->portwidth; i > 0; i--) { - cword_offset = (info->portwidth-i)%info->chipwidth; + cword_offset = (info->portwidth - i) % info->chipwidth; #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) cp_offset = info->portwidth - i; val = *((uchar *)&cmd_le + cword_offset); @@ -252,7 +252,7 @@ static void print_longlong(char *str, unsigned long long data) int i; char *cp;
- cp = (char *) &data; + cp = (char *)&data; for (i = 0; i < 8; i++) sprintf(&str[i * 2], "%2.2x", *cp++); } @@ -512,7 +512,7 @@ static int flash_toggle(flash_info_t *info, flash_sect_t sect, break; case FLASH_CFI_64BIT: retval = ((flash_read32(addr) != flash_read32(addr)) || - (flash_read32(addr+4) != flash_read32(addr+4))); + (flash_read32(addr + 4) != flash_read32(addr + 4))); break; default: retval = 0; @@ -1212,7 +1212,7 @@ void flash_print_info(flash_info_t *info) printf("%s flash (%d x %d)", info->name, (info->portwidth << 3), (info->chipwidth << 3)); - if (info->size < 1024*1024) + if (info->size < 1024 * 1024) printf(" Size: %ld kB in %d Sectors\n", info->size >> 10, info->sector_count); else @@ -1882,7 +1882,7 @@ static void __flash_cmd_reset(flash_info_t *info) flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); } void flash_cmd_reset(flash_info_t *info) - __attribute__((weak,alias("__flash_cmd_reset"))); + __attribute__((weak, alias("__flash_cmd_reset")));
static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) { @@ -2029,7 +2029,7 @@ static void flash_fixup_sst(flash_info_t *info, struct cfi_qry *qry) if (info->device_id == 0x5D23 || /* SST39VF3201B */ info->device_id == 0x5C23) { /* SST39VF3202B */ /* set sector granularity to 4KB */ - info->cmd_erase_sector=0x50; + info->cmd_erase_sector = 0x50; } }
@@ -2087,9 +2087,9 @@ ulong flash_get_size(phys_addr_t base, int banknum) num_erase_regions = qry.num_erase_regions;
if (info->ext_addr) { - info->cfi_version = (ushort) flash_read_uchar(info, + info->cfi_version = (ushort)flash_read_uchar(info, info->ext_addr + 3) << 8; - info->cfi_version |= (ushort) flash_read_uchar(info, + info->cfi_version |= (ushort)flash_read_uchar(info, info->ext_addr + 4); }
@@ -2386,7 +2386,7 @@ unsigned long flash_init(void) #ifndef CONFIG_SYS_FLASH_QUIET_TEST printf("## Unknown flash on Bank %d " "- Size = 0x%08lx = %ld MB\n", - i+1, flash_info[i].size, + i + 1, flash_info[i].size, flash_info[i].size >> 20); #endif /* CONFIG_SYS_FLASH_QUIET_TEST */ }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index a28f5eaea9..1ccb05091d 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -269,6 +269,7 @@ static void flash_printqry(struct cfi_qry *qry) debug(" "); for (y = 0; y < 16; y++) { unsigned char c = p[x + y]; + if (c >= 0x20 && c <= 0x7e) debug("%c", c); else @@ -279,7 +280,6 @@ static void flash_printqry(struct cfi_qry *qry) } #endif
- /*----------------------------------------------------------------------- * read a character at a port width address */ @@ -311,7 +311,6 @@ static inline ushort flash_read_word(flash_info_t *info, uint offset) return retval; }
- /*----------------------------------------------------------------------- * read a long word by picking the least significant byte of each maximum * port size word. Swap for ppc format. @@ -356,7 +355,6 @@ static ulong flash_read_long (flash_info_t *info, flash_sect_t sect, static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, uint offset, u32 cmd) { - void *addr; cfiword_t cword;
@@ -1048,7 +1046,6 @@ out_unmap: } #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */
- /*----------------------------------------------------------------------- */ int flash_erase(flash_info_t *info, int s_first, int s_last) @@ -1080,7 +1077,6 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) putc('\n'); }
- for (sect = s_first; sect <= s_last; sect++) { if (ctrlc()) { printf("\n"); @@ -1154,6 +1150,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) if (use_flash_status_poll(info)) { cfiword_t cword; void *dest; + cword.w64 = 0xffffffffffffffffULL; dest = flash_map(info, sect, 0); st = flash_status_poll(info, &cword, dest, @@ -1494,7 +1491,6 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) else flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_CLEAR); - } break; case CFI_CMDSET_AMD_EXTENDED: @@ -1579,7 +1575,6 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) if ((retcode = flash_full_status_check(info, sector, info->erase_blk_tout, prot ? "protect" : "unprotect")) == 0) { - info->protect[sector] = prot;
/* @@ -1881,6 +1876,7 @@ static void __flash_cmd_reset(flash_info_t *info) udelay(1); flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); } + void flash_cmd_reset(flash_info_t *info) __attribute__((weak, alias("__flash_cmd_reset")));
@@ -2364,6 +2360,7 @@ unsigned long flash_init(void) #ifdef CONFIG_SYS_FLASH_PROTECTION /* read environment from EEPROM */ char s[64]; + env_get_f("unlock", s, sizeof(s)); #endif

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 1ccb05091d..06795fe754 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -329,9 +329,8 @@ static ulong flash_read_long (flash_info_t *info, flash_sect_t sect, #ifdef DEBUG debug("long addr is at %p info->portwidth = %d\n", addr, info->portwidth); - for (x = 0; x < 4 * info->portwidth; x++) { + for (x = 0; x < 4 * info->portwidth; x++) debug("addr[%x] = 0x%x\n", x, flash_read8(addr + x)); - } #endif #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) retval = ((flash_read8(addr) << 16) | @@ -1065,11 +1064,9 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) }
prot = 0; - for (sect = s_first; sect <= s_last; ++sect) { - if (info->protect[sect]) { + for (sect = s_first; sect <= s_last; ++sect) + if (info->protect[sect]) prot++; - } - } if (prot) { printf("- Warning: %d protected sectors will not be erased!\n", prot); @@ -1396,9 +1393,8 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) #else while (cnt >= info->portwidth) { cword.w32 = 0; - for (i = 0; i < info->portwidth; i++) { + for (i = 0; i < info->portwidth; i++) flash_add_byte(info, &cword, *src++); - } if ((rc = flash_write_cfiword(info, wp, cword)) != 0) return rc; wp += info->portwidth; @@ -1410,9 +1406,8 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) } #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */
- if (cnt == 0) { + if (cnt == 0) return (0); - }
/* * handle unaligned tail bytes

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 06795fe754..b73b72bcee 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -611,8 +611,8 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_EXTENDED: case CFI_CMDSET_INTEL_STANDARD: - if ((retcode == ERR_OK) - && !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { + if ((retcode == ERR_OK) && + !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { retcode = ERR_INVAL; printf("Flash %s error at address %lx\n", prompt, info->start[sector]); @@ -761,8 +761,8 @@ static flash_sect_t find_sector(flash_info_t *info, ulong addr) if ((info != saved_info) || (sector >= info->sector_count)) sector = 0;
- while ((info->start[sector] < addr) - && (sector < info->sector_count - 1)) + while ((info->start[sector] < addr) && + (sector < info->sector_count - 1)) sector++; while ((info->start[sector] > addr) && (sector > 0)) /* @@ -1435,8 +1435,8 @@ static inline int manufact_match(flash_info_t *info, u32 manu)
static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) { - if (manufact_match(info, INTEL_MANUFACT) - && info->device_id == NUMONYX_256MBIT) { + if (manufact_match(info, INTEL_MANUFACT) && + info->device_id == NUMONYX_256MBIT) { /* * see errata called * "Numonyx Axcell P33/P30 Specification Update" :) @@ -1801,8 +1801,8 @@ static int flash_detect_legacy(phys_addr_t base, int banknum) (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE); - if (info->portwidth == FLASH_CFI_8BIT - && info->interface == FLASH_CFI_X8X16) { + if (info->portwidth == FLASH_CFI_8BIT && + info->interface == FLASH_CFI_X8X16) { info->addr_unlock1 = 0x2AAA; info->addr_unlock2 = 0x5555; } else { @@ -1886,9 +1886,9 @@ static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) cfi_offset++) { flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI); - if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') - && flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') - && flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { + if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') && + flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && + flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, sizeof(struct cfi_qry)); info->interface = le16_to_cpu(qry->interface_desc); @@ -2138,8 +2138,8 @@ ulong flash_get_size(phys_addr_t base, int banknum)
size_ratio = info->portwidth / info->chipwidth; /* if the chip is x8/x16 reduce the ratio by half */ - if ((info->interface == FLASH_CFI_X8X16) - && (info->chipwidth == FLASH_CFI_BY8)) { + if ((info->interface == FLASH_CFI_X8X16) && + (info->chipwidth == FLASH_CFI_BY8)) { size_ratio >>= 1; } debug("size_ratio %d port %d bits chip %d bits\n",

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index b73b72bcee..2ec8f5a27b 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -555,7 +555,7 @@ static int flash_is_busy(flash_info_t *info, flash_sect_t sect) default: retval = 0; } - debug("flash_is_busy: %d\n", retval); + debug("%s: %d\n", __func__, retval); return retval; }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 2ec8f5a27b..5576092d8f 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -946,7 +946,8 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, "write to buffer"); if (retcode == ERR_OK) { /* reduce the number of loops by the width of - * the port */ + * the port + */ cnt = len >> shift; flash_write_cmd(info, sector, 0, cnt - 1); while (cnt-- > 0) { @@ -1787,7 +1788,8 @@ static int flash_detect_legacy(phys_addr_t base, int banknum)
if (board_flash_get_legacy(base, banknum, info)) { /* board code may have filled info completely. If not, we - use JEDEC ID probing. */ + * use JEDEC ID probing. + */ if (!info->vendor) { int modes[] = { CFI_CMDSET_AMD_STANDARD,

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 5576092d8f..229e0a8177 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -611,7 +611,7 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_EXTENDED: case CFI_CMDSET_INTEL_STANDARD: - if ((retcode == ERR_OK) && + if (retcode == ERR_OK && !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { retcode = ERR_INVAL; printf("Flash %s error at address %lx\n", prompt, @@ -758,7 +758,7 @@ static flash_sect_t find_sector(flash_info_t *info, ulong addr) static flash_info_t *saved_info; /* previously used flash bank */ flash_sect_t sector = saved_sector;
- if ((info != saved_info) || (sector >= info->sector_count)) + if (info != saved_info || sector >= info->sector_count) sector = 0;
while ((info->start[sector] < addr) && @@ -1059,7 +1059,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) puts("Can't erase unknown flash type - aborted\n"); return 1; } - if ((s_first < 0) || (s_first > s_last)) { + if (s_first < 0 || s_first > s_last) { puts("- no sectors to erase\n"); return 1; } @@ -1247,7 +1247,7 @@ void flash_print_info(flash_info_t *info) printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", info->device_id2); } - if ((info->vendor == CFI_CMDSET_AMD_STANDARD) && (info->legacy_unlock)) + if (info->vendor == CFI_CMDSET_AMD_STANDARD && info->legacy_unlock) printf("\n Advanced Sector Protection (PPB) enabled"); printf("\n Erase timeout: %ld ms, write timeout: %ld ms\n", info->erase_blk_tout, @@ -1291,7 +1291,7 @@ void flash_print_info(flash_info_t *info) #define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) \ if (flash_verbose) { \ dots -= dots_sub; \ - if ((scale > 0) && (dots <= 0)) { \ + if (scale > 0 && dots <= 0) { \ if ((digit % 5) == 0) \ printf("%d", digit / 5); \ else \ @@ -1577,7 +1577,7 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) * On some of Intel's flash chips (marked via legacy_unlock) * unprotect unprotects all locking. */ - if ((prot == 0) && (info->legacy_unlock)) { + if (prot == 0 && info->legacy_unlock) { flash_sect_t i;
for (i = 0; i < info->sector_count; i++) { @@ -1636,10 +1636,10 @@ static void cfi_reverse_geometry(struct cfi_qry *qry) u32 tmp;
for (i = 0, j = qry->num_erase_regions - 1; i < j; i++, j--) { - tmp = get_unaligned(&(qry->erase_region_info[i])); - put_unaligned(get_unaligned(&(qry->erase_region_info[j])), - &(qry->erase_region_info[i])); - put_unaligned(tmp, &(qry->erase_region_info[j])); + tmp = get_unaligned(&qry->erase_region_info[i]); + put_unaligned(get_unaligned(&qry->erase_region_info[j]), + &qry->erase_region_info[i]); + put_unaligned(tmp, &qry->erase_region_info[j]); } }
@@ -1913,11 +1913,11 @@ static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) * in compatibility mode */ if (/* x8/x16 in x8 mode */ - ((info->chipwidth == FLASH_CFI_BY8) && - (info->interface == FLASH_CFI_X8X16)) || + (info->chipwidth == FLASH_CFI_BY8 && + info->interface == FLASH_CFI_X8X16) || /* x16/x32 in x16 mode */ - ((info->chipwidth == FLASH_CFI_BY16) && - (info->interface == FLASH_CFI_X16X32))) + (info->chipwidth == FLASH_CFI_BY16 && + info->interface == FLASH_CFI_X16X32)) { info->addr_unlock1 = 0xaaa; info->addr_unlock2 = 0x555; @@ -2034,8 +2034,8 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) * There's an app note from Numonyx on this issue. * So adjust the buffer size for M29EW while operating in 8-bit mode */ - if (((qry->max_buf_write_size) > 0x8) && - (info->device_id == 0x7E) && + if (qry->max_buf_write_size > 0x8 && + info->device_id == 0x7E && (info->device_id2 == 0x2201 || info->device_id2 == 0x2301 || info->device_id2 == 0x2801 || @@ -2075,8 +2075,8 @@ ulong flash_get_size(phys_addr_t base, int banknum) info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE);
if (flash_detect_cfi(info, &qry)) { - info->vendor = le16_to_cpu(get_unaligned(&(qry.p_id))); - info->ext_addr = le16_to_cpu(get_unaligned(&(qry.p_adr))); + info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); + info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); num_erase_regions = qry.num_erase_regions;
if (info->ext_addr) { @@ -2140,8 +2140,8 @@ ulong flash_get_size(phys_addr_t base, int banknum)
size_ratio = info->portwidth / info->chipwidth; /* if the chip is x8/x16 reduce the ratio by half */ - if ((info->interface == FLASH_CFI_X8X16) && - (info->chipwidth == FLASH_CFI_BY8)) { + if (info->interface == FLASH_CFI_X8X16 && + info->chipwidth == FLASH_CFI_BY8) { size_ratio >>= 1; } debug("size_ratio %d port %d bits chip %d bits\n", @@ -2151,7 +2151,7 @@ ulong flash_get_size(phys_addr_t base, int banknum) /* multiply the size by the number of chips */ info->size *= size_ratio; max_size = cfi_flash_bank_size(banknum); - if (max_size && (info->size > max_size)) { + if (max_size && info->size > max_size) { debug("[truncated from %ldMiB]", info->size >> 20); info->size = max_size; } @@ -2166,7 +2166,7 @@ ulong flash_get_size(phys_addr_t base, int banknum) }
tmp = le32_to_cpu(get_unaligned( - &(qry.erase_region_info[i]))); + &qry.erase_region_info[i])); debug("erase region %u: 0x%08lx\n", i, tmp);
erase_region_count = (tmp & 0xffff) + 1; @@ -2255,8 +2255,8 @@ ulong flash_get_size(phys_addr_t base, int banknum) /* round up when converting to ms */ info->write_tout = (tmp + 999) / 1000; info->flash_id = FLASH_MAN_CFI; - if ((info->interface == FLASH_CFI_X8X16) && - (info->chipwidth == FLASH_CFI_BY8)) { + if (info->interface == FLASH_CFI_X8X16 && + info->chipwidth == FLASH_CFI_BY8) { /* XXX - Need to test on x8/x16 in parallel. */ info->portwidth >>= 1; }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 229e0a8177..2a165cb328 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1154,10 +1154,12 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) st = flash_status_poll(info, &cword, dest, info->erase_blk_tout, "erase"); flash_unmap(info, sect, 0, dest); - } else + } else { st = flash_full_status_check(info, sect, info->erase_blk_tout, "erase"); + } + if (st) rcode = 1; else if (flash_verbose)

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 2a165cb328..0d015a3863 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1140,7 +1140,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) break; #endif default: - debug("Unkown flash vendor %d\n", + debug("Unknown flash vendor %d\n", info->vendor); break; }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 0d015a3863..a82f5272c1 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1820,9 +1820,9 @@ static int flash_detect_legacy(phys_addr_t base, int banknum) info->device_id2); if (jedec_flash_match(info, info->start[0])) break; - else - unmap_physmem((void *)info->start[0], - info->portwidth); + + unmap_physmem((void *)info->start[0], + info->portwidth); } }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index a82f5272c1..cd89c666d6 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1919,8 +1919,7 @@ static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) info->interface == FLASH_CFI_X8X16) || /* x16/x32 in x16 mode */ (info->chipwidth == FLASH_CFI_BY16 && - info->interface == FLASH_CFI_X16X32)) - { + info->interface == FLASH_CFI_X16X32)) { info->addr_unlock1 = 0xaaa; info->addr_unlock2 = 0x555; }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index cd89c666d6..c47ba416b9 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1280,7 +1280,6 @@ void flash_print_info(flash_info_t *info) #endif } putc('\n'); - return; }
/*-----------------------------------------------------------------------

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index c47ba416b9..c597c621ca 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -179,10 +179,10 @@ __maybe_weak u64 flash_read64(void *addr) static flash_info_t *flash_get_info(ulong base) { int i; - flash_info_t *info;
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) { - info = &flash_info[i]; + flash_info_t *info = &flash_info[i]; + if (info->size && info->start[0] <= base && base <= info->start[0] + info->size - 1) return info; @@ -222,8 +222,6 @@ static inline void flash_unmap(flash_info_t *info, flash_sect_t sect, static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) { int i; - int cword_offset; - int cp_offset; #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) u32 cmd_le = cpu_to_le32(cmd); #endif @@ -231,9 +229,10 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) uchar *cp = (uchar *) cmdbuf;
for (i = info->portwidth; i > 0; i--) { - cword_offset = (info->portwidth - i) % info->chipwidth; + int cword_offset = (info->portwidth - i) % info->chipwidth; + int cp_offset = info->portwidth - i; #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) - cp_offset = info->portwidth - i; + val = *((uchar *)&cmd_le + cword_offset); #else cp_offset = i - 1; @@ -2053,16 +2052,10 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) ulong flash_get_size(phys_addr_t base, int banknum) { flash_info_t *info = &flash_info[banknum]; - int i, j; flash_sect_t sect_cnt; phys_addr_t sector; - unsigned long tmp; - int size_ratio; uchar num_erase_regions; - int erase_region_size; - int erase_region_count; struct cfi_qry qry; - unsigned long max_size;
memset(&qry, 0, sizeof(qry));
@@ -2075,6 +2068,11 @@ ulong flash_get_size(phys_addr_t base, int banknum) info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE);
if (flash_detect_cfi(info, &qry)) { + int i; + int size_ratio; + unsigned long max_size; + unsigned long tmp; + info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); num_erase_regions = qry.num_erase_regions; @@ -2159,6 +2157,10 @@ ulong flash_get_size(phys_addr_t base, int banknum) sect_cnt = 0; sector = base; for (i = 0; i < num_erase_regions; i++) { + int j; + int erase_region_size; + int erase_region_count; + if (i > NUM_ERASE_REGIONS) { printf("%d erase regions found, only %d used\n", num_erase_regions, NUM_ERASE_REGIONS);

2017-09-29 21:52 GMT+09:00 Mario Six mario.six@gdsys.cc:
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/mtd/cfi_flash.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index c47ba416b9..c597c621ca 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -179,10 +179,10 @@ __maybe_weak u64 flash_read64(void *addr) static flash_info_t *flash_get_info(ulong base) { int i;
flash_info_t *info; for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
info = &flash_info[i];
flash_info_t *info = &flash_info[i];
if (info->size && info->start[0] <= base && base <= info->start[0] + info->size - 1) return info;
@@ -222,8 +222,6 @@ static inline void flash_unmap(flash_info_t *info, flash_sect_t sect, static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) { int i;
int cword_offset;
int cp_offset;
#if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) u32 cmd_le = cpu_to_le32(cmd); #endif @@ -231,9 +229,10 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) uchar *cp = (uchar *) cmdbuf;
for (i = info->portwidth; i > 0; i--) {
cword_offset = (info->portwidth - i) % info->chipwidth;
int cword_offset = (info->portwidth - i) % info->chipwidth;
int cp_offset = info->portwidth - i;
#if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA)
cp_offset = info->portwidth - i;
val = *((uchar *)&cmd_le + cword_offset);
#else cp_offset = i - 1; @@ -2053,16 +2052,10 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) ulong flash_get_size(phys_addr_t base, int banknum) { flash_info_t *info = &flash_info[banknum];
int i, j; flash_sect_t sect_cnt; phys_addr_t sector;
unsigned long tmp;
int size_ratio; uchar num_erase_regions;
int erase_region_size;
int erase_region_count; struct cfi_qry qry;
unsigned long max_size; memset(&qry, 0, sizeof(qry));
@@ -2075,6 +2068,11 @@ ulong flash_get_size(phys_addr_t base, int banknum) info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE);
if (flash_detect_cfi(info, &qry)) {
int i;
int size_ratio;
unsigned long max_size;
unsigned long tmp;
info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); num_erase_regions = qry.num_erase_regions;
@@ -2159,6 +2157,10 @@ ulong flash_get_size(phys_addr_t base, int banknum) sect_cnt = 0; sector = base; for (i = 0; i < num_erase_regions; i++) {
int j;
int erase_region_size;
int erase_region_count;
if (i > NUM_ERASE_REGIONS) { printf("%d erase regions found, only %d used\n", num_erase_regions, NUM_ERASE_REGIONS);
--
Are these changes necessary?
Looks like your personal preference to me.

Hi Masahiro,
On Fri, Sep 29, 2017 at 7:10 PM, Masahiro Yamada yamada.masahiro@socionext.com wrote:
2017-09-29 21:52 GMT+09:00 Mario Six mario.six@gdsys.cc:
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/mtd/cfi_flash.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index c47ba416b9..c597c621ca 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -179,10 +179,10 @@ __maybe_weak u64 flash_read64(void *addr) static flash_info_t *flash_get_info(ulong base) { int i;
flash_info_t *info; for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
info = &flash_info[i];
flash_info_t *info = &flash_info[i];
if (info->size && info->start[0] <= base && base <= info->start[0] + info->size - 1) return info;
@@ -222,8 +222,6 @@ static inline void flash_unmap(flash_info_t *info, flash_sect_t sect, static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) { int i;
int cword_offset;
int cp_offset;
#if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA) u32 cmd_le = cpu_to_le32(cmd); #endif @@ -231,9 +229,10 @@ static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) uchar *cp = (uchar *) cmdbuf;
for (i = info->portwidth; i > 0; i--) {
cword_offset = (info->portwidth - i) % info->chipwidth;
int cword_offset = (info->portwidth - i) % info->chipwidth;
int cp_offset = info->portwidth - i;
#if defined(__LITTLE_ENDIAN) || defined(CONFIG_SYS_WRITE_SWAPPED_DATA)
cp_offset = info->portwidth - i;
val = *((uchar *)&cmd_le + cword_offset);
#else cp_offset = i - 1; @@ -2053,16 +2052,10 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) ulong flash_get_size(phys_addr_t base, int banknum) { flash_info_t *info = &flash_info[banknum];
int i, j; flash_sect_t sect_cnt; phys_addr_t sector;
unsigned long tmp;
int size_ratio; uchar num_erase_regions;
int erase_region_size;
int erase_region_count; struct cfi_qry qry;
unsigned long max_size; memset(&qry, 0, sizeof(qry));
@@ -2075,6 +2068,11 @@ ulong flash_get_size(phys_addr_t base, int banknum) info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE);
if (flash_detect_cfi(info, &qry)) {
int i;
int size_ratio;
unsigned long max_size;
unsigned long tmp;
info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); num_erase_regions = qry.num_erase_regions;
@@ -2159,6 +2157,10 @@ ulong flash_get_size(phys_addr_t base, int banknum) sect_cnt = 0; sector = base; for (i = 0; i < num_erase_regions; i++) {
int j;
int erase_region_size;
int erase_region_count;
if (i > NUM_ERASE_REGIONS) { printf("%d erase regions found, only %d used\n", num_erase_regions, NUM_ERASE_REGIONS);
--
Are these changes necessary?
Looks like your personal preference to me.
Well, scope reduction of variables is a relatively common refactoring method (see, for example, chapter 10.4 of Code Complete, Second Edition). Also, the relatively commonly used CppCheck linter automatically finds these instances very often, which is how I found them.
But no, it is not strictly necessary; I can drop these patches for v2.
Best regards,
Mario

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index c597c621ca..bc7bd3036e 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1338,7 +1338,8 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) wp = (addr & ~(info->portwidth - 1));
/* handle unaligned start */ - if ((aln = addr - wp) != 0) { + aln = addr - wp; + if (aln != 0) { cword.w32 = 0; p = (uchar *)wp; for (i = 0; i < aln; ++i) @@ -1369,7 +1370,8 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) cword.w32 = 0; for (i = 0; i < info->portwidth; i++) flash_add_byte(info, &cword, *src++); - if ((rc = flash_write_cfiword(info, wp, cword)) != 0) + rc = flash_write_cfiword(info, wp, cword); + if (rc != 0) return rc; wp += info->portwidth; cnt -= info->portwidth; @@ -1380,7 +1382,8 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) i = buffered_size - (wp % buffered_size); if (i > cnt) i = cnt; - if ((rc = flash_write_cfibuffer(info, wp, src, i)) != ERR_OK) + rc = flash_write_cfibuffer(info, wp, src, i); + if (rc != ERR_OK) return rc; i -= i & (info->portwidth - 1); wp += i; @@ -1396,7 +1399,8 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) cword.w32 = 0; for (i = 0; i < info->portwidth; i++) flash_add_byte(info, &cword, *src++); - if ((rc = flash_write_cfiword(info, wp, cword)) != 0) + rc = flash_write_cfiword(info, wp, cword); + if (rc != 0) return rc; wp += info->portwidth; cnt -= info->portwidth; @@ -1568,9 +1572,9 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) * flash_full_status_check() to work correctly */ flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); - if ((retcode = - flash_full_status_check(info, sector, info->erase_blk_tout, - prot ? "protect" : "unprotect")) == 0) { + retcode = flash_full_status_check(info, sector, info->erase_blk_tout, + prot ? "protect" : "unprotect"); + if (retcode == 0) { info->protect[sector] = prot;
/*

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index bc7bd3036e..2ff1a97658 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -490,7 +490,7 @@ static int flash_isset(flash_info_t *info, flash_sect_t sect, static int flash_toggle(flash_info_t *info, flash_sect_t sect, uint offset, uchar cmd) { - void *addr; + u8 *addr; cfiword_t cword; int retval;
@@ -871,9 +871,9 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, flash_sect_t sector; int cnt; int retcode; - void *src = cp; - void *dst = (void *)dest; - void *dst2 = dst; + u8 *src = cp; + u8 *dst = (u8 *)dest; + u8 *dst2 = dst; int flag = 1; uint offset = 0; unsigned int shift;

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 2ff1a97658..b2857f372d 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1254,10 +1254,9 @@ void flash_print_info(flash_info_t *info) info->erase_blk_tout, info->write_tout); if (info->buffer_size > 1) { - printf(" Buffer write timeout: %ld ms, " - "buffer size: %d bytes\n", - info->buffer_write_tout, - info->buffer_size); + printf(" Buffer write timeout: %ld ms, ", + info->buffer_write_tout); + printf("buffer size: %d bytes\n", info->buffer_size); }
puts("\n Sector Start Addresses:"); @@ -2043,8 +2042,8 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) info->device_id2 == 0x2301 || info->device_id2 == 0x2801 || info->device_id2 == 0x4801)) { - debug("Adjusted buffer size on Numonyx flash" - " M29EW family in 8 bit mode\n"); + debug("Adjusted buffer size on Numonyx flash"); + debug(" M29EW family in 8 bit mode\n"); qry->max_buf_write_size = 0x8; } } @@ -2384,9 +2383,9 @@ unsigned long flash_init(void) size += flash_info[i].size; if (flash_info[i].flash_id == FLASH_UNKNOWN) { #ifndef CONFIG_SYS_FLASH_QUIET_TEST - printf("## Unknown flash on Bank %d " - "- Size = 0x%08lx = %ld MB\n", - i + 1, flash_info[i].size, + printf("## Unknown flash on Bank %d ", i + 1); + printf("- Size = 0x%08lx = %ld MB\n", + flash_info[i].size, flash_info[i].size >> 20); #endif /* CONFIG_SYS_FLASH_QUIET_TEST */ }

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index b2857f372d..dff8b73055 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -1686,8 +1686,8 @@ static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry)
static void cmdset_amd_read_jedec_ids(flash_info_t *info) { - ushort bankId = 0; - uchar manuId; + ushort bank_id = 0; + uchar manu_id; uchar lsbits;
flash_write_cmd(info, 0, 0, AMD_CMD_RESET); @@ -1695,14 +1695,14 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info) flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); udelay(1000); /* some flash are slow to respond */
- manuId = flash_read_uchar(info, FLASH_OFFSET_MANUFACTURER_ID); + manu_id = flash_read_uchar(info, FLASH_OFFSET_MANUFACTURER_ID); /* JEDEC JEP106Z specifies ID codes up to bank 7 */ - while (manuId == FLASH_CONTINUATION_CODE && bankId < 0x800) { - bankId += 0x100; - manuId = flash_read_uchar(info, - bankId | FLASH_OFFSET_MANUFACTURER_ID); + while (manu_id == FLASH_CONTINUATION_CODE && bank_id < 0x800) { + bank_id += 0x100; + manu_id = flash_read_uchar(info, + bank_id | FLASH_OFFSET_MANUFACTURER_ID); } - info->manufacturer_id = manuId; + info->manufacturer_id = manu_id;
lsbits = flash_read_uchar(info, FLASH_OFFSET_LOWER_SW_BITS); info->sr_supported = lsbits & BIT(0);

checkpatch.pl complains about the spelling of ERR_TIMOUT. Since the error is only used in a handful of files, we rename the error to ERR_TIMEOUT.
Signed-off-by: Mario Six mario.six@gdsys.cc --- board/cobra5272/flash.c | 2 +- common/flash.c | 4 ++-- drivers/mtd/cfi_flash.c | 4 ++-- drivers/mtd/dataflash.c | 2 +- drivers/mtd/pic32_flash.c | 6 +++--- include/dataflash.h | 2 +- include/flash.h | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/board/cobra5272/flash.c b/board/cobra5272/flash.c index 4fac6880f1..ca27b49a3b 100644 --- a/board/cobra5272/flash.c +++ b/board/cobra5272/flash.c @@ -216,7 +216,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) goto outahere; } if (chip1 == TMO) { - rc = ERR_TIMOUT; + rc = ERR_TIMEOUT; goto outahere; }
diff --git a/common/flash.c b/common/flash.c index 587ef60158..876677493f 100644 --- a/common/flash.c +++ b/common/flash.c @@ -112,7 +112,7 @@ addr2info (ulong addr) * and no protected sectors are hit. * Returns: * ERR_OK 0 - OK - * ERR_TIMOUT 1 - write timeout + * ERR_TIMEOUT 1 - write timeout * ERR_NOT_ERASED 2 - Flash not erased * ERR_PROTECTED 4 - target range includes protected sectors * ERR_INVAL 8 - target address not in Flash memory @@ -185,7 +185,7 @@ void flash_perror (int err) switch (err) { case ERR_OK: break; - case ERR_TIMOUT: + case ERR_TIMEOUT: puts ("Timeout writing to Flash\n"); break; case ERR_NOT_ERASED: diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index dff8b73055..93bf9ed539 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -587,7 +587,7 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector, flash_read_long(info, sector, 0)); flash_write_cmd(info, sector, 0, info->cmd_reset); udelay(1); - return ERR_TIMOUT; + return ERR_TIMEOUT; } udelay(1); /* also triggers watchdog */ } @@ -695,7 +695,7 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst, if (get_timer(start) > tout) { printf("Flash %s timeout at address %lx data %lx\n", prompt, (ulong)dst, (ulong)flash_read8(dst)); - return ERR_TIMOUT; + return ERR_TIMEOUT; } udelay(1); /* also triggers watchdog */ } diff --git a/drivers/mtd/dataflash.c b/drivers/mtd/dataflash.c index e961f518b0..09199ebeba 100644 --- a/drivers/mtd/dataflash.c +++ b/drivers/mtd/dataflash.c @@ -426,7 +426,7 @@ void dataflash_perror (int err) switch (err) { case ERR_OK: break; - case ERR_TIMOUT: + case ERR_TIMEOUT: printf("Timeout writing to DataFlash\n"); break; case ERR_PROTECTED: diff --git a/drivers/mtd/pic32_flash.c b/drivers/mtd/pic32_flash.c index e1a8d3bc4b..a6a5d1cc2e 100644 --- a/drivers/mtd/pic32_flash.c +++ b/drivers/mtd/pic32_flash.c @@ -69,7 +69,7 @@ static int flash_wait_till_busy(const char *func, ulong timeout) int ret = wait_for_bit(__func__, &nvm_regs_p->ctrl.raw, NVM_WR, false, timeout, false);
- return ret ? ERR_TIMOUT : ERR_OK; + return ret ? ERR_TIMEOUT : ERR_OK; }
static inline int flash_complete_operation(void) @@ -99,7 +99,7 @@ static inline int flash_complete_operation(void) * Erase flash sectors, returns: * ERR_OK - OK * ERR_INVAL - invalid sector arguments - * ERR_TIMOUT - write timeout + * ERR_TIMEOUT - write timeout * ERR_NOT_ERASED - Flash not erased * ERR_UNKNOWN_FLASH_VENDOR - incorrect flash */ @@ -217,7 +217,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong word) /* * Copy memory to flash, returns: * ERR_OK - OK - * ERR_TIMOUT - write timeout + * ERR_TIMEOUT - write timeout * ERR_NOT_ERASED - Flash not erased */ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) diff --git a/include/dataflash.h b/include/dataflash.h index c9f22200cf..68907251d1 100644 --- a/include/dataflash.h +++ b/include/dataflash.h @@ -29,7 +29,7 @@ * return codes from flash_write(): */ # define ERR_OK 0 -# define ERR_TIMOUT 1 +# define ERR_TIMEOUT 1 # define ERR_NOT_ERASED 2 # define ERR_PROTECTED 4 # define ERR_INVAL 8 diff --git a/include/flash.h b/include/flash.h index dc67cb2df6..1a4e879009 100644 --- a/include/flash.h +++ b/include/flash.h @@ -122,7 +122,7 @@ extern int jedec_flash_match(flash_info_t *info, ulong base); * return codes from flash_write(): */ #define ERR_OK 0 -#define ERR_TIMOUT 1 +#define ERR_TIMEOUT 1 #define ERR_NOT_ERASED 2 #define ERR_PROTECTED 4 #define ERR_INVAL 8

In a while loop in cfi_flash.c the array "start" is accessed at the index "sector" before the index variable "sector" is bounds-checked, which might lead to accesses beyond the bounds of the array.
Swap the order of the checks in the "&&" expression, so that the short-circuit evaluation prevents out-of-bounds array accesses.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 93bf9ed539..40a3544e5b 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -760,8 +760,8 @@ static flash_sect_t find_sector(flash_info_t *info, ulong addr) if (info != saved_info || sector >= info->sector_count) sector = 0;
- while ((info->start[sector] < addr) && - (sector < info->sector_count - 1)) + while ((sector < info->sector_count - 1) && + (info->start[sector] < addr)) sector++; while ((info->start[sector] > addr) && (sector > 0)) /*

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 40a3544e5b..e640a70d0f 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -175,7 +175,8 @@ __maybe_weak u64 flash_read64(void *addr)
/*----------------------------------------------------------------------- */ -#if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE) +#if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || \ + (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE) static flash_info_t *flash_get_info(ulong base) { int i; @@ -568,8 +569,9 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector, ulong start;
#if CONFIG_SYS_HZ != 1000 + /* Avoid overflow for large HZ */ if ((ulong)CONFIG_SYS_HZ > 100000) - tout *= (ulong)CONFIG_SYS_HZ / 1000; /* for a big HZ, avoid overflow */ + tout *= (ulong)CONFIG_SYS_HZ / 1000; else tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000); #endif @@ -660,8 +662,9 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst, int ready;
#if CONFIG_SYS_HZ != 1000 + /* Avoid overflow for large HZ */ if ((ulong)CONFIG_SYS_HZ > 100000) - tout *= (ulong)CONFIG_SYS_HZ / 1000; /* for a big HZ, avoid overflow */ + tout *= (ulong)CONFIG_SYS_HZ / 1000; else tout = DIV_ROUND_UP(tout * (ulong)CONFIG_SYS_HZ, 1000); #endif @@ -936,7 +939,8 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: write_cmd = (info->vendor == CFI_CMDSET_INTEL_PROG_REGIONS) ? - FLASH_CMD_WRITE_BUFFER_PROG : FLASH_CMD_WRITE_TO_BUFFER; + FLASH_CMD_WRITE_BUFFER_PROG : + FLASH_CMD_WRITE_TO_BUFFER; flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); flash_write_cmd(info, sector, 0, write_cmd); @@ -1151,7 +1155,8 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) cword.w64 = 0xffffffffffffffffULL; dest = flash_map(info, sect, 0); st = flash_status_poll(info, &cword, dest, - info->erase_blk_tout, "erase"); + info->erase_blk_tout, + "erase"); flash_unmap(info, sect, 0, dest); } else { st = flash_full_status_check(info, sect, @@ -1560,9 +1565,11 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); if (prot) - flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_SET); + flash_write_cmd(info, sector, 0, + FLASH_CMD_PROTECT_SET); else - flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_CLEAR); + flash_write_cmd(info, sector, 0, + FLASH_CMD_PROTECT_CLEAR); #endif };
@@ -1892,9 +1899,9 @@ static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI); if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') && - flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && - flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { - flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, + flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && + flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { + flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, sizeof(struct cfi_qry)); info->interface = le16_to_cpu(qry->interface_desc);
@@ -2178,8 +2185,8 @@ ulong flash_get_size(phys_addr_t base, int banknum) tmp >>= 16; erase_region_size = (tmp & 0xffff) ? ((tmp & 0xffff) * 256) : 128; - debug("erase_region_count = %d erase_region_size = %d\n", - erase_region_count, erase_region_size); + debug("erase_region_count = %d ", erase_region_count); + debug("erase_region_size = %d\n", erase_region_size); for (j = 0; j < erase_region_count; j++) { if (sector - base >= info->size) break;

Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 238 ++++++++++++++++++++++++------------------------ 1 file changed, 118 insertions(+), 120 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index e640a70d0f..7795d25825 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -213,7 +213,7 @@ flash_map(flash_info_t *info, flash_sect_t sect, uint offset) }
static inline void flash_unmap(flash_info_t *info, flash_sect_t sect, - unsigned int offset, void *addr) + unsigned int offset, void *addr) { }
@@ -328,7 +328,7 @@ static ulong flash_read_long (flash_info_t *info, flash_sect_t sect,
#ifdef DEBUG debug("long addr is at %p info->portwidth = %d\n", addr, - info->portwidth); + info->portwidth); for (x = 0; x < 4 * info->portwidth; x++) debug("addr[%x] = 0x%x\n", x, flash_read8(addr + x)); #endif @@ -362,19 +362,19 @@ static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, switch (info->portwidth) { case FLASH_CFI_8BIT: debug("fwc addr %p cmd %x %x 8bit x %d bit\n", addr, cmd, - cword.w8, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); + cword.w8, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); flash_write8(cword.w8, addr); break; case FLASH_CFI_16BIT: debug("fwc addr %p cmd %x %4.4x 16bit x %d bit\n", addr, - cmd, cword.w16, - info->chipwidth << CFI_FLASH_SHIFT_WIDTH); + cmd, cword.w16, + info->chipwidth << CFI_FLASH_SHIFT_WIDTH); flash_write16(cword.w16, addr); break; case FLASH_CFI_32BIT: debug("fwc addr %p cmd %x %8.8x 32bit x %d bit\n", addr, - cmd, cword.w32, - info->chipwidth << CFI_FLASH_SHIFT_WIDTH); + cmd, cword.w32, + info->chipwidth << CFI_FLASH_SHIFT_WIDTH); flash_write32(cword.w32, addr); break; case FLASH_CFI_64BIT: @@ -385,8 +385,8 @@ static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, print_longlong(str, cword.w64);
debug("fwrite addr %p cmd %x %s 64 bit x %d bit\n", - addr, cmd, str, - info->chipwidth << CFI_FLASH_SHIFT_WIDTH); + addr, cmd, str, + info->chipwidth << CFI_FLASH_SHIFT_WIDTH); } #endif flash_write64(cword.w64, addr); @@ -407,8 +407,8 @@ static void flash_unlock_seq(flash_info_t *info, flash_sect_t sect)
/*----------------------------------------------------------------------- */ -static int flash_isequal(flash_info_t *info, flash_sect_t sect, - uint offset, uchar cmd) +static int flash_isequal(flash_info_t *info, flash_sect_t sect, uint offset, + uchar cmd) { void *addr; cfiword_t cword; @@ -455,8 +455,8 @@ static int flash_isequal(flash_info_t *info, flash_sect_t sect,
/*----------------------------------------------------------------------- */ -static int flash_isset(flash_info_t *info, flash_sect_t sect, - uint offset, uchar cmd) +static int flash_isset(flash_info_t *info, flash_sect_t sect, uint offset, + uchar cmd) { void *addr; cfiword_t cword; @@ -488,8 +488,8 @@ static int flash_isset(flash_info_t *info, flash_sect_t sect,
/*----------------------------------------------------------------------- */ -static int flash_toggle(flash_info_t *info, flash_sect_t sect, - uint offset, uchar cmd) +static int flash_toggle(flash_info_t *info, flash_sect_t sect, uint offset, + uchar cmd) { u8 *addr; cfiword_t cword; @@ -543,12 +543,12 @@ static int flash_is_busy(flash_info_t *info, flash_sect_t sect) #endif if (info->sr_supported) { flash_write_cmd(info, sect, info->addr_unlock1, - FLASH_CMD_READ_STATUS); + FLASH_CMD_READ_STATUS); retval = !flash_isset(info, sect, 0, - FLASH_STATUS_DONE); + FLASH_STATUS_DONE); } else { retval = flash_toggle(info, sect, 0, - AMD_STATUS_TOGGLE); + AMD_STATUS_TOGGLE); }
break; @@ -564,7 +564,7 @@ static int flash_is_busy(flash_info_t *info, flash_sect_t sect) * This routine does not set the flash to read-array mode. */ static int flash_status_check(flash_info_t *info, flash_sect_t sector, - ulong tout, char *prompt) + ulong tout, char *prompt) { ulong start;
@@ -585,8 +585,8 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector, while (flash_is_busy(info, sector)) { if (get_timer(start) > tout) { printf("Flash %s timeout at address %lx data %lx\n", - prompt, info->start[sector], - flash_read_long(info, sector, 0)); + prompt, info->start[sector], + flash_read_long(info, sector, 0)); flash_write_cmd(info, sector, 0, info->cmd_reset); udelay(1); return ERR_TIMEOUT; @@ -603,7 +603,7 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector, * This routine sets the flash to read-array mode. */ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, - ulong tout, char *prompt) + ulong tout, char *prompt) { int retcode;
@@ -613,10 +613,10 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, case CFI_CMDSET_INTEL_EXTENDED: case CFI_CMDSET_INTEL_STANDARD: if (retcode == ERR_OK && - !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { + !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { retcode = ERR_INVAL; printf("Flash %s error at address %lx\n", prompt, - info->start[sector]); + info->start[sector]); if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) { puts("Command Sequence Error.\n"); @@ -764,7 +764,7 @@ static flash_sect_t find_sector(flash_info_t *info, ulong addr) sector = 0;
while ((sector < info->sector_count - 1) && - (info->start[sector] < addr)) + (info->start[sector] < addr)) sector++; while ((info->start[sector] > addr) && (sector > 0)) /* @@ -780,8 +780,7 @@ static flash_sect_t find_sector(flash_info_t *info, ulong addr)
/*----------------------------------------------------------------------- */ -static int flash_write_cfiword(flash_info_t *info, ulong dest, - cfiword_t cword) +static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword) { void *dstaddr = (void *)dest; int flag; @@ -869,7 +868,7 @@ static int flash_write_cfiword(flash_info_t *info, ulong dest, #ifdef CONFIG_SYS_FLASH_USE_BUFFER_WRITE
static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, - int len) + int len) { flash_sect_t sector; int cnt; @@ -945,8 +944,8 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); flash_write_cmd(info, sector, 0, write_cmd); retcode = flash_status_check(info, sector, - info->buffer_write_tout, - "write to buffer"); + info->buffer_write_tout, + "write to buffer"); if (retcode == ERR_OK) { /* reduce the number of loops by the width of * the port @@ -977,7 +976,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, } } flash_write_cmd(info, sector, 0, - FLASH_CMD_WRITE_BUFFER_CONFIRM); + FLASH_CMD_WRITE_BUFFER_CONFIRM); retcode = flash_full_status_check( info, sector, info->buffer_write_tout, "buffer write"); @@ -1073,7 +1072,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) prot++; if (prot) { printf("- Warning: %d protected sectors will not be erased!\n", - prot); + prot); } else if (flash_verbose) { putc('\n'); } @@ -1116,11 +1115,11 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) case CFI_CMDSET_INTEL_STANDARD: case CFI_CMDSET_INTEL_EXTENDED: flash_write_cmd(info, sect, 0, - FLASH_CMD_CLEAR_STATUS); + FLASH_CMD_CLEAR_STATUS); flash_write_cmd(info, sect, 0, - FLASH_CMD_BLOCK_ERASE); + FLASH_CMD_BLOCK_ERASE); flash_write_cmd(info, sect, 0, - FLASH_CMD_ERASE_CONFIRM); + FLASH_CMD_ERASE_CONFIRM); break; case CFI_CMDSET_AMD_STANDARD: case CFI_CMDSET_AMD_EXTENDED: @@ -1130,7 +1129,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) AMD_CMD_ERASE_START); flash_unlock_seq(info, sect); flash_write_cmd(info, sect, 0, - info->cmd_erase_sector); + info->cmd_erase_sector); break; #ifdef CONFIG_FLASH_CFI_LEGACY case CFI_CMDSET_AMD_LEGACY: @@ -1144,7 +1143,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) #endif default: debug("Unknown flash vendor %d\n", - info->vendor); + info->vendor); break; }
@@ -1211,14 +1210,14 @@ void flash_print_info(flash_info_t *info) }
printf("%s flash (%d x %d)", - info->name, - (info->portwidth << 3), (info->chipwidth << 3)); + info->name, + (info->portwidth << 3), (info->chipwidth << 3)); if (info->size < 1024 * 1024) printf(" Size: %ld kB in %d Sectors\n", - info->size >> 10, info->sector_count); + info->size >> 10, info->sector_count); else printf(" Size: %ld MB in %d Sectors\n", - info->size >> 20, info->sector_count); + info->size >> 20, info->sector_count); printf(" "); switch (info->vendor) { case CFI_CMDSET_INTEL_PROG_REGIONS: @@ -1246,21 +1245,20 @@ void flash_print_info(flash_info_t *info) break; } printf(" command set, Manufacturer ID: 0x%02X, Device ID: 0x", - info->manufacturer_id); + info->manufacturer_id); printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", - info->device_id); + info->device_id); if ((info->device_id & 0xff) == 0x7E) { printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", - info->device_id2); + info->device_id2); } if (info->vendor == CFI_CMDSET_AMD_STANDARD && info->legacy_unlock) printf("\n Advanced Sector Protection (PPB) enabled"); printf("\n Erase timeout: %ld ms, write timeout: %ld ms\n", - info->erase_blk_tout, - info->write_tout); + info->erase_blk_tout, info->write_tout); if (info->buffer_size > 1) { printf(" Buffer write timeout: %ld ms, ", - info->buffer_write_tout); + info->buffer_write_tout); printf("buffer size: %d bytes\n", info->buffer_size); }
@@ -1273,13 +1271,13 @@ void flash_print_info(flash_info_t *info) #ifdef CONFIG_SYS_FLASH_EMPTY_INFO /* print empty and read-only info */ printf(" %08lX %c %s ", - info->start[i], - sector_erased(info, i) ? 'E' : ' ', - info->protect[i] ? "RO" : " "); + info->start[i], + sector_erased(info, i) ? 'E' : ' ', + info->protect[i] ? "RO" : " "); #else /* ! CONFIG_SYS_FLASH_EMPTY_INFO */ printf(" %08lX %s ", - info->start[i], - info->protect[i] ? "RO" : " "); + info->start[i], + info->protect[i] ? "RO" : " "); #endif } putc('\n'); @@ -1445,7 +1443,7 @@ static inline int manufact_match(flash_info_t *info, u32 manu) static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) { if (manufact_match(info, INTEL_MANUFACT) && - info->device_id == NUMONYX_256MBIT) { + info->device_id == NUMONYX_256MBIT) { /* * see errata called * "Numonyx Axcell P33/P30 Specification Update" :) @@ -1486,15 +1484,15 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) case CFI_CMDSET_INTEL_EXTENDED: if (!cfi_protect_bugfix(info, sector, prot)) { flash_write_cmd(info, sector, 0, - FLASH_CMD_CLEAR_STATUS); + FLASH_CMD_CLEAR_STATUS); flash_write_cmd(info, sector, 0, - FLASH_CMD_PROTECT); + FLASH_CMD_PROTECT); if (prot) flash_write_cmd(info, sector, 0, - FLASH_CMD_PROTECT_SET); + FLASH_CMD_PROTECT_SET); else flash_write_cmd(info, sector, 0, - FLASH_CMD_PROTECT_CLEAR); + FLASH_CMD_PROTECT_CLEAR); } break; case CFI_CMDSET_AMD_EXTENDED: @@ -1515,7 +1513,7 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) AMD_CMD_UNLOCK_START); if (info->device_id == ATM_ID_BV6416) flash_write_cmd(info, sector, - 0, ATM_CMD_UNLOCK_SECT); + 0, ATM_CMD_UNLOCK_SECT); } } if (info->legacy_unlock) { @@ -1529,29 +1527,29 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) if (prot) { if (lock_flag) { flash_write_cmd(info, sector, 0, - AMD_CMD_PPB_LOCK_BC1); + AMD_CMD_PPB_LOCK_BC1); flash_write_cmd(info, sector, 0, - AMD_CMD_PPB_LOCK_BC2); + AMD_CMD_PPB_LOCK_BC2); } debug("sector %ld %slocked\n", sector, - lock_flag ? "" : "already "); + lock_flag ? "" : "already "); } else { if (!lock_flag) { debug("unlock %ld\n", sector); flash_write_cmd(info, 0, 0, - AMD_CMD_PPB_UNLOCK_BC1); + AMD_CMD_PPB_UNLOCK_BC1); flash_write_cmd(info, 0, 0, - AMD_CMD_PPB_UNLOCK_BC2); + AMD_CMD_PPB_UNLOCK_BC2); } debug("sector %ld %sunlocked\n", sector, - !lock_flag ? "" : "already "); + !lock_flag ? "" : "already "); } if (flag) enable_interrupts();
if (flash_status_check(info, sector, - info->erase_blk_tout, - prot ? "protect" : "unprotect")) + info->erase_blk_tout, + prot ? "protect" : "unprotect")) printf("status check error\n");
flash_write_cmd(info, 0, 0, @@ -1579,7 +1577,7 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) */ flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); retcode = flash_full_status_check(info, sector, info->erase_blk_tout, - prot ? "protect" : "unprotect"); + prot ? "protect" : "unprotect"); if (retcode == 0) { info->protect[sector] = prot;
@@ -1603,7 +1601,7 @@ int flash_real_protect(flash_info_t *info, long sector, int prot) * flash_read_user_serial - read the OneTimeProgramming cells */ void flash_read_user_serial(flash_info_t *info, void *buffer, int offset, - int len) + int len) { uchar *src; uchar *dst; @@ -1621,7 +1619,7 @@ void flash_read_user_serial(flash_info_t *info, void *buffer, int offset, * flash_read_factory_serial - read the device Id from the protection area */ void flash_read_factory_serial(flash_info_t *info, void *buffer, int offset, - int len) + int len) { uchar *src;
@@ -1666,7 +1664,7 @@ static void cmdset_intel_read_jedec_ids(flash_info_t *info) flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); udelay(1000); /* some flash are slow to respond */ info->manufacturer_id = flash_read_uchar(info, - FLASH_OFFSET_MANUFACTURER_ID); + FLASH_OFFSET_MANUFACTURER_ID); info->device_id = (info->chipwidth == FLASH_CFI_16BIT) ? flash_read_word(info, FLASH_OFFSET_DEVICE_ID) : flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID); @@ -1683,8 +1681,8 @@ static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry) #ifdef CONFIG_SYS_FLASH_PROTECTION /* read legacy lock/unlock bit from intel flash */ if (info->ext_addr) { - info->legacy_unlock = flash_read_uchar(info, - info->ext_addr + 5) & 0x08; + info->legacy_unlock = + flash_read_uchar(info, info->ext_addr + 5) & 0x08; } #endif
@@ -1707,7 +1705,7 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info) while (manu_id == FLASH_CONTINUATION_CODE && bank_id < 0x800) { bank_id += 0x100; manu_id = flash_read_uchar(info, - bank_id | FLASH_OFFSET_MANUFACTURER_ID); + bank_id | FLASH_OFFSET_MANUFACTURER_ID); } info->manufacturer_id = manu_id;
@@ -1717,11 +1715,11 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info) switch (info->chipwidth) { case FLASH_CFI_8BIT: info->device_id = flash_read_uchar(info, - FLASH_OFFSET_DEVICE_ID); + FLASH_OFFSET_DEVICE_ID); if (info->device_id == 0x7E) { /* AMD 3-byte (expanded) device ids */ info->device_id2 = flash_read_uchar(info, - FLASH_OFFSET_DEVICE_ID2); + FLASH_OFFSET_DEVICE_ID2); info->device_id2 <<= 8; info->device_id2 |= flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID3); @@ -1729,11 +1727,11 @@ static void cmdset_amd_read_jedec_ids(flash_info_t *info) break; case FLASH_CFI_16BIT: info->device_id = flash_read_word(info, - FLASH_OFFSET_DEVICE_ID); + FLASH_OFFSET_DEVICE_ID); if ((info->device_id & 0xff) == 0x7E) { /* AMD 3-byte (expanded) device ids */ info->device_id2 = flash_read_uchar(info, - FLASH_OFFSET_DEVICE_ID2); + FLASH_OFFSET_DEVICE_ID2); info->device_id2 <<= 8; info->device_id2 |= flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID3); @@ -1814,7 +1812,7 @@ static int flash_detect_legacy(phys_addr_t base, int banknum) info->portwidth, MAP_NOCACHE); if (info->portwidth == FLASH_CFI_8BIT && - info->interface == FLASH_CFI_X8X16) { + info->interface == FLASH_CFI_X8X16) { info->addr_unlock1 = 0x2AAA; info->addr_unlock2 = 0x5555; } else { @@ -1823,9 +1821,9 @@ static int flash_detect_legacy(phys_addr_t base, int banknum) } flash_read_jedec_ids(info); debug("JEDEC PROBE: ID %x %x %x\n", - info->manufacturer_id, - info->device_id, - info->device_id2); + info->manufacturer_id, + info->device_id, + info->device_id2); if (jedec_flash_match(info, info->start[0])) break;
@@ -1862,8 +1860,8 @@ static inline int flash_detect_legacy(phys_addr_t base, int banknum) * detect if flash is compatible with the Common Flash Interface (CFI) * http://www.jedec.org/download/search/jesd68.pdf */ -static void flash_read_cfi(flash_info_t *info, void *buf, - unsigned int start, size_t len) +static void flash_read_cfi(flash_info_t *info, void *buf, unsigned int start, + size_t len) { u8 *p = buf; unsigned int i; @@ -1897,22 +1895,22 @@ static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) for (cfi_offset = 0; cfi_offset < ARRAY_SIZE(flash_offset_cfi); cfi_offset++) { flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], - FLASH_CMD_CFI); + FLASH_CMD_CFI); if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') && flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { - flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, - sizeof(struct cfi_qry)); + flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, + sizeof(struct cfi_qry)); info->interface = le16_to_cpu(qry->interface_desc);
info->cfi_offset = flash_offset_cfi[cfi_offset]; debug("device interface is %d\n", - info->interface); + info->interface); debug("found port %d chip %d ", - info->portwidth, info->chipwidth); + info->portwidth, info->chipwidth); debug("port %d bits chip %d bits\n", - info->portwidth << CFI_FLASH_SHIFT_WIDTH, - info->chipwidth << CFI_FLASH_SHIFT_WIDTH); + info->portwidth << CFI_FLASH_SHIFT_WIDTH, + info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
/* calculate command offsets as in the Linux driver */ info->addr_unlock1 = 0x555; @@ -2044,11 +2042,11 @@ static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) * So adjust the buffer size for M29EW while operating in 8-bit mode */ if (qry->max_buf_write_size > 0x8 && - info->device_id == 0x7E && - (info->device_id2 == 0x2201 || - info->device_id2 == 0x2301 || - info->device_id2 == 0x2801 || - info->device_id2 == 0x4801)) { + info->device_id == 0x7E && + (info->device_id2 == 0x2201 || + info->device_id2 == 0x2301 || + info->device_id2 == 0x2801 || + info->device_id2 == 0x4801)) { debug("Adjusted buffer size on Numonyx flash"); debug(" M29EW family in 8 bit mode\n"); qry->max_buf_write_size = 0x8; @@ -2110,7 +2108,7 @@ ulong flash_get_size(phys_addr_t base, int banknum) break; default: printf("CFI: Unknown command set 0x%x\n", - info->vendor); + info->vendor); /* * Unfortunately, this means we don't know how * to get the chip back to Read mode. Might @@ -2149,12 +2147,12 @@ ulong flash_get_size(phys_addr_t base, int banknum) size_ratio = info->portwidth / info->chipwidth; /* if the chip is x8/x16 reduce the ratio by half */ if (info->interface == FLASH_CFI_X8X16 && - info->chipwidth == FLASH_CFI_BY8) { + info->chipwidth == FLASH_CFI_BY8) { size_ratio >>= 1; } debug("size_ratio %d port %d bits chip %d bits\n", - size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH, - info->chipwidth << CFI_FLASH_SHIFT_WIDTH); + size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH, + info->chipwidth << CFI_FLASH_SHIFT_WIDTH); info->size = 1 << qry.dev_size; /* multiply the size by the number of chips */ info->size *= size_ratio; @@ -2173,7 +2171,7 @@ ulong flash_get_size(phys_addr_t base, int banknum)
if (i > NUM_ERASE_REGIONS) { printf("%d erase regions found, only %d used\n", - num_erase_regions, NUM_ERASE_REGIONS); + num_erase_regions, NUM_ERASE_REGIONS); break; }
@@ -2217,8 +2215,8 @@ ulong flash_get_size(phys_addr_t base, int banknum) FLASH_CMD_READ_ID); info->protect[sect_cnt] = flash_isset(info, sect_cnt, - FLASH_OFFSET_PROTECT, - FLASH_STATUS_PROTECT); + FLASH_OFFSET_PROTECT, + FLASH_STATUS_PROTECT); flash_write_cmd(info, sect_cnt, 0, FLASH_CMD_RESET); break; @@ -2328,25 +2326,25 @@ static void flash_protect_default(void) #if (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE) && \ (!defined(CONFIG_MONITOR_IS_IN_RAM)) flash_protect(FLAG_PROTECT_SET, - CONFIG_SYS_MONITOR_BASE, - CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, - flash_get_info(CONFIG_SYS_MONITOR_BASE)); + CONFIG_SYS_MONITOR_BASE, + CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, + flash_get_info(CONFIG_SYS_MONITOR_BASE)); #endif
/* Environment protection ON by default */ #ifdef CONFIG_ENV_IS_IN_FLASH flash_protect(FLAG_PROTECT_SET, - CONFIG_ENV_ADDR, - CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1, - flash_get_info(CONFIG_ENV_ADDR)); + CONFIG_ENV_ADDR, + CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1, + flash_get_info(CONFIG_ENV_ADDR)); #endif
/* Redundant environment protection ON by default */ #ifdef CONFIG_ENV_ADDR_REDUND flash_protect(FLAG_PROTECT_SET, - CONFIG_ENV_ADDR_REDUND, - CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1, - flash_get_info(CONFIG_ENV_ADDR_REDUND)); + CONFIG_ENV_ADDR_REDUND, + CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1, + flash_get_info(CONFIG_ENV_ADDR_REDUND)); #endif
#if defined(CONFIG_SYS_FLASH_AUTOPROTECT_LIST) @@ -2354,9 +2352,9 @@ static void flash_protect_default(void) debug("autoprotecting from %08lx to %08lx\n", apl[i].start, apl[i].start + apl[i].size - 1); flash_protect(FLAG_PROTECT_SET, - apl[i].start, - apl[i].start + apl[i].size - 1, - flash_get_info(apl[i].start)); + apl[i].start, + apl[i].start + apl[i].size - 1, + flash_get_info(apl[i].start)); } #endif } @@ -2392,8 +2390,8 @@ unsigned long flash_init(void) #ifndef CONFIG_SYS_FLASH_QUIET_TEST printf("## Unknown flash on Bank %d ", i + 1); printf("- Size = 0x%08lx = %ld MB\n", - flash_info[i].size, - flash_info[i].size >> 20); + flash_info[i].size, + flash_info[i].size >> 20); #endif /* CONFIG_SYS_FLASH_QUIET_TEST */ } #ifdef CONFIG_SYS_FLASH_PROTECTION @@ -2437,10 +2435,10 @@ unsigned long flash_init(void) * No legancy unlocking -> unlock all sectors */ flash_protect(FLAG_PROTECT_CLEAR, - flash_info[i].start[0], - flash_info[i].start[0] - + flash_info[i].size - 1, - &flash_info[i]); + flash_info[i].start[0], + flash_info[i].start[0] + + flash_info[i].size - 1, + &flash_info[i]); } } #endif /* CONFIG_SYS_FLASH_PROTECTION */

The variable cfi_flash_num_flash_banks is defined iff CONFIG_SYS_MAX_FLASH_BANKS_DETECT is defined, but it is used unconditionally in the function cfi_flash_init_dm. This leads to a undefined variable compile error when CONFIG_SYS_MAX_FLASH_BANKS_DETECT is not defined, but DM is enabled.
Fix this by always defining the cfi_flash_num_flash_banks variable.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 7795d25825..4415bcca24 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -91,6 +91,8 @@ static u16 cfi_flash_config_reg(int i)
#if defined(CONFIG_SYS_MAX_FLASH_BANKS_DETECT) int cfi_flash_num_flash_banks = CONFIG_SYS_MAX_FLASH_BANKS_DETECT; +#else +int cfi_flash_num_flash_banks; #endif
#ifdef CONFIG_CFI_FLASH /* for driver model */

Make the cfi_flash driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/mtd/cfi_flash.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 4415bcca24..accbd432e7 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -2457,27 +2457,28 @@ unsigned long flash_init(void) #ifdef CONFIG_CFI_FLASH /* for driver model */ static int cfi_flash_probe(struct udevice *dev) { - void *blob = (void *)gd->fdt_blob; - int node = dev_of_offset(dev); const fdt32_t *cell; - phys_addr_t addr; - int parent, addrc, sizec; + int addrc, sizec; int len, idx;
- parent = fdt_parent_offset(blob, node); - fdt_support_default_count_cells(blob, parent, &addrc, &sizec); - /* decode regs, there may be multiple reg tuples. */ - cell = fdt_getprop(blob, node, "reg", &len); + addrc = dev_read_addr_cells(dev); + sizec = dev_read_size_cells(dev); + + /* decode regs; there may be multiple reg tuples. */ + cell = dev_read_prop(dev, "reg", &len); if (!cell) return -ENOENT; idx = 0; len /= sizeof(fdt32_t); while (idx < len) { - addr = fdt_translate_address((void *)blob, - node, cell + idx); + phys_addr_t addr; + + addr = dev_translate_address(dev, cell + idx); + flash_info[cfi_flash_num_flash_banks].dev = dev; flash_info[cfi_flash_num_flash_banks].base = addr; cfi_flash_num_flash_banks++; + idx += addrc + sizec; } gd->bd->bi_flashstart = flash_info[0].base;

Fix some style violations in the MPC85XX GPIO driver.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/gpio/mpc85xx_gpio.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc85xx_gpio.c index cfeb6e7632..4566c091b7 100644 --- a/drivers/gpio/mpc85xx_gpio.c +++ b/drivers/gpio/mpc85xx_gpio.c @@ -34,11 +34,13 @@ struct mpc85xx_gpio_data { uint gpio_count; /* The GPDAT register cannot be used to determine the value of output * pins on MPC8572/MPC8536, so we shadow it and use the shadowed value - * for output pins */ + * for output pins + */ u32 dat_shadow; };
-inline u32 gpio_mask(unsigned gpio) { +inline u32 gpio_mask(uint gpio) +{ return (1U << (31 - (gpio))); }
@@ -92,7 +94,7 @@ static inline void mpc85xx_gpio_open_drain_off(struct ccsr_gpio *base, clrbits_be32(&base->gpodr, gpios); }
-static int mpc85xx_gpio_direction_input(struct udevice *dev, unsigned gpio) +static int mpc85xx_gpio_direction_input(struct udevice *dev, uint gpio) { struct mpc85xx_gpio_data *data = dev_get_priv(dev);
@@ -100,8 +102,7 @@ static int mpc85xx_gpio_direction_input(struct udevice *dev, unsigned gpio) return 0; }
-static int mpc85xx_gpio_set_value(struct udevice *dev, unsigned gpio, - int value) +static int mpc85xx_gpio_set_value(struct udevice *dev, uint gpio, int value) { struct mpc85xx_gpio_data *data = dev_get_priv(dev);
@@ -115,46 +116,46 @@ static int mpc85xx_gpio_set_value(struct udevice *dev, unsigned gpio, return 0; }
-static int mpc85xx_gpio_direction_output(struct udevice *dev, unsigned gpio, +static int mpc85xx_gpio_direction_output(struct udevice *dev, uint gpio, int value) { return mpc85xx_gpio_set_value(dev, gpio, value); }
-static int mpc85xx_gpio_get_value(struct udevice *dev, unsigned gpio) +static int mpc85xx_gpio_get_value(struct udevice *dev, uint gpio) { struct mpc85xx_gpio_data *data = dev_get_priv(dev);
if (!!mpc85xx_gpio_get_dir(data->base, gpio_mask(gpio))) { /* Output -> use shadowed value */ return !!(data->dat_shadow & gpio_mask(gpio)); - } else { - /* Input -> read value from GPDAT register */ - return !!mpc85xx_gpio_get_val(data->base, gpio_mask(gpio)); } + + /* Input -> read value from GPDAT register */ + return !!mpc85xx_gpio_get_val(data->base, gpio_mask(gpio)); }
-static int mpc85xx_gpio_get_open_drain(struct udevice *dev, unsigned gpio) +static int mpc85xx_gpio_get_open_drain(struct udevice *dev, uint gpio) { struct mpc85xx_gpio_data *data = dev_get_priv(dev);
return !!mpc85xx_gpio_open_drain_val(data->base, gpio_mask(gpio)); }
-static int mpc85xx_gpio_set_open_drain(struct udevice *dev, unsigned gpio, +static int mpc85xx_gpio_set_open_drain(struct udevice *dev, uint gpio, int value) { struct mpc85xx_gpio_data *data = dev_get_priv(dev);
- if (value) { + if (value) mpc85xx_gpio_open_drain_on(data->base, gpio_mask(gpio)); - } else { + else mpc85xx_gpio_open_drain_off(data->base, gpio_mask(gpio)); - } + return 0; }
-static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio) +static int mpc85xx_gpio_get_function(struct udevice *dev, uint gpio) { struct mpc85xx_gpio_data *data = dev_get_priv(dev); int dir; @@ -164,14 +165,15 @@ static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio) }
#if CONFIG_IS_ENABLED(OF_CONTROL) -static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) { +static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) +{ struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev); fdt_addr_t addr; fdt_size_t size;
addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, - dev_of_offset(dev), "reg", 0, &size, false); - + dev_of_offset(dev), + "reg", 0, &size, false); plat->addr = addr; plat->size = size; plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), @@ -229,7 +231,7 @@ static const struct dm_gpio_ops gpio_mpc85xx_ops = { .set_value = mpc85xx_gpio_set_value, .get_open_drain = mpc85xx_gpio_get_open_drain, .set_open_drain = mpc85xx_gpio_set_open_drain, - .get_function = mpc85xx_gpio_get_function, + .get_function = mpc85xx_gpio_get_function, };
static const struct udevice_id mpc85xx_gpio_ids[] = {

In preparation to making the MPC85xx GPIO driver useable for a broader range of SoCs, rename the driver file.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/gpio/Makefile | 2 +- drivers/gpio/{mpc85xx_gpio.c => mpc8xxx_gpio.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename drivers/gpio/{mpc85xx_gpio.c => mpc8xxx_gpio.c} (100%)
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 1396467ab6..38ff3773a1 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -37,7 +37,7 @@ obj-$(CONFIG_DA8XX_GPIO) += da8xx_gpio.o obj-$(CONFIG_DM644X_GPIO) += da8xx_gpio.o obj-$(CONFIG_ALTERA_PIO) += altera_pio.o obj-$(CONFIG_MPC83XX_GPIO) += mpc83xx_gpio.o -obj-$(CONFIG_MPC85XX_GPIO) += mpc85xx_gpio.o +obj-$(CONFIG_MPC85XX_GPIO) += mpc8xxx_gpio.o obj-$(CONFIG_SH_GPIO_PFC) += sh_pfc.o obj-$(CONFIG_OMAP_GPIO) += omap_gpio.o obj-$(CONFIG_DB8500_GPIO) += db8500_gpio.o diff --git a/drivers/gpio/mpc85xx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c similarity index 100% rename from drivers/gpio/mpc85xx_gpio.c rename to drivers/gpio/mpc8xxx_gpio.c

Rename the Kconfig option, structures (and their members), as well as functions of the mpc85xx driver to include mpc8xxx to reflect the more generic usage.
Signed-off-by: Mario Six mario.six@gdsys.cc --- arch/powerpc/include/asm/arch-mpc85xx/gpio.h | 2 +- drivers/gpio/Kconfig | 9 +-- drivers/gpio/Makefile | 2 +- drivers/gpio/mpc8xxx_gpio.c | 116 ++++++++++++++------------- 4 files changed, 64 insertions(+), 65 deletions(-)
diff --git a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h index 76faa22c8b..b2ba31e623 100644 --- a/arch/powerpc/include/asm/arch-mpc85xx/gpio.h +++ b/arch/powerpc/include/asm/arch-mpc85xx/gpio.h @@ -18,7 +18,7 @@ #include <asm/mpc85xx_gpio.h> #endif
-struct mpc85xx_gpio_plat { +struct mpc8xxx_gpio_plat { ulong addr; unsigned long size; uint ngpios; diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index ffeda9425a..19d862f608 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -263,11 +263,11 @@ config DM_PCA953X Now, max 24 bits chips and PCA953X compatible chips are supported
-config MPC85XX_GPIO - bool "Freescale MPC85XX GPIO driver" +config MPC8XXX_GPIO + bool "Freescale MPC8XXX GPIO driver" depends on DM_GPIO help - This driver supports the built-in GPIO controller of MPC85XX CPUs. + This driver supports the built-in GPIO controller of MPC8XXX CPUs. Each GPIO bank is identified by its own entry in the device tree, i.e.
@@ -285,7 +285,4 @@ config MPC85XX_GPIO Aside from the standard functions of input/output mode, and output value setting, the open-drain feature, which can configure individual GPIOs to work as open-drain outputs, is supported. - - The driver has been tested on MPC85XX, but it is likely that other - PowerQUICC III devices will work as well. endmenu diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 38ff3773a1..81c39187de 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -37,7 +37,7 @@ obj-$(CONFIG_DA8XX_GPIO) += da8xx_gpio.o obj-$(CONFIG_DM644X_GPIO) += da8xx_gpio.o obj-$(CONFIG_ALTERA_PIO) += altera_pio.o obj-$(CONFIG_MPC83XX_GPIO) += mpc83xx_gpio.o -obj-$(CONFIG_MPC85XX_GPIO) += mpc8xxx_gpio.o +obj-$(CONFIG_MPC8XXX_GPIO) += mpc8xxx_gpio.o obj-$(CONFIG_SH_GPIO_PFC) += sh_pfc.o obj-$(CONFIG_OMAP_GPIO) += omap_gpio.o obj-$(CONFIG_DB8500_GPIO) += db8500_gpio.o diff --git a/drivers/gpio/mpc8xxx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c index 4566c091b7..e4ebbc117c 100644 --- a/drivers/gpio/mpc8xxx_gpio.c +++ b/drivers/gpio/mpc8xxx_gpio.c @@ -25,7 +25,7 @@ struct ccsr_gpio { u32 gpicr; };
-struct mpc85xx_gpio_data { +struct mpc8xxx_gpio_data { /* The bank's register base in memory */ struct ccsr_gpio __iomem *base; /* The address of the registers; used to identify the bank */ @@ -44,130 +44,130 @@ inline u32 gpio_mask(uint gpio) return (1U << (31 - (gpio))); }
-static inline u32 mpc85xx_gpio_get_val(struct ccsr_gpio *base, u32 mask) +static inline u32 mpc8xxx_gpio_get_val(struct ccsr_gpio *base, u32 mask) { return in_be32(&base->gpdat) & mask; }
-static inline u32 mpc85xx_gpio_get_dir(struct ccsr_gpio *base, u32 mask) +static inline u32 mpc8xxx_gpio_get_dir(struct ccsr_gpio *base, u32 mask) { return in_be32(&base->gpdir) & mask; }
-static inline void mpc85xx_gpio_set_in(struct ccsr_gpio *base, u32 gpios) +static inline void mpc8xxx_gpio_set_in(struct ccsr_gpio *base, u32 gpios) { clrbits_be32(&base->gpdat, gpios); /* GPDIR register 0 -> input */ clrbits_be32(&base->gpdir, gpios); }
-static inline void mpc85xx_gpio_set_low(struct ccsr_gpio *base, u32 gpios) +static inline void mpc8xxx_gpio_set_low(struct ccsr_gpio *base, u32 gpios) { clrbits_be32(&base->gpdat, gpios); /* GPDIR register 1 -> output */ setbits_be32(&base->gpdir, gpios); }
-static inline void mpc85xx_gpio_set_high(struct ccsr_gpio *base, u32 gpios) +static inline void mpc8xxx_gpio_set_high(struct ccsr_gpio *base, u32 gpios) { setbits_be32(&base->gpdat, gpios); /* GPDIR register 1 -> output */ setbits_be32(&base->gpdir, gpios); }
-static inline int mpc85xx_gpio_open_drain_val(struct ccsr_gpio *base, u32 mask) +static inline int mpc8xxx_gpio_open_drain_val(struct ccsr_gpio *base, u32 mask) { return in_be32(&base->gpodr) & mask; }
-static inline void mpc85xx_gpio_open_drain_on(struct ccsr_gpio *base, u32 +static inline void mpc8xxx_gpio_open_drain_on(struct ccsr_gpio *base, u32 gpios) { /* GPODR register 1 -> open drain on */ setbits_be32(&base->gpodr, gpios); }
-static inline void mpc85xx_gpio_open_drain_off(struct ccsr_gpio *base, +static inline void mpc8xxx_gpio_open_drain_off(struct ccsr_gpio *base, u32 gpios) { /* GPODR register 0 -> open drain off (actively driven) */ clrbits_be32(&base->gpodr, gpios); }
-static int mpc85xx_gpio_direction_input(struct udevice *dev, uint gpio) +static int mpc8xxx_gpio_direction_input(struct udevice *dev, uint gpio) { - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
- mpc85xx_gpio_set_in(data->base, gpio_mask(gpio)); + mpc8xxx_gpio_set_in(data->base, gpio_mask(gpio)); return 0; }
-static int mpc85xx_gpio_set_value(struct udevice *dev, uint gpio, int value) +static int mpc8xxx_gpio_set_value(struct udevice *dev, uint gpio, int value) { - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
if (value) { data->dat_shadow |= gpio_mask(gpio); - mpc85xx_gpio_set_high(data->base, gpio_mask(gpio)); + mpc8xxx_gpio_set_high(data->base, gpio_mask(gpio)); } else { data->dat_shadow &= ~gpio_mask(gpio); - mpc85xx_gpio_set_low(data->base, gpio_mask(gpio)); + mpc8xxx_gpio_set_low(data->base, gpio_mask(gpio)); } return 0; }
-static int mpc85xx_gpio_direction_output(struct udevice *dev, uint gpio, +static int mpc8xxx_gpio_direction_output(struct udevice *dev, uint gpio, int value) { - return mpc85xx_gpio_set_value(dev, gpio, value); + return mpc8xxx_gpio_set_value(dev, gpio, value); }
-static int mpc85xx_gpio_get_value(struct udevice *dev, uint gpio) +static int mpc8xxx_gpio_get_value(struct udevice *dev, uint gpio) { - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
- if (!!mpc85xx_gpio_get_dir(data->base, gpio_mask(gpio))) { + if (!!mpc8xxx_gpio_get_dir(data->base, gpio_mask(gpio))) { /* Output -> use shadowed value */ return !!(data->dat_shadow & gpio_mask(gpio)); }
/* Input -> read value from GPDAT register */ - return !!mpc85xx_gpio_get_val(data->base, gpio_mask(gpio)); + return !!mpc8xxx_gpio_get_val(data->base, gpio_mask(gpio)); }
-static int mpc85xx_gpio_get_open_drain(struct udevice *dev, uint gpio) +static int mpc8xxx_gpio_get_open_drain(struct udevice *dev, uint gpio) { - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
- return !!mpc85xx_gpio_open_drain_val(data->base, gpio_mask(gpio)); + return !!mpc8xxx_gpio_open_drain_val(data->base, gpio_mask(gpio)); }
-static int mpc85xx_gpio_set_open_drain(struct udevice *dev, uint gpio, +static int mpc8xxx_gpio_set_open_drain(struct udevice *dev, uint gpio, int value) { - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev);
if (value) - mpc85xx_gpio_open_drain_on(data->base, gpio_mask(gpio)); + mpc8xxx_gpio_open_drain_on(data->base, gpio_mask(gpio)); else - mpc85xx_gpio_open_drain_off(data->base, gpio_mask(gpio)); + mpc8xxx_gpio_open_drain_off(data->base, gpio_mask(gpio));
return 0; }
-static int mpc85xx_gpio_get_function(struct udevice *dev, uint gpio) +static int mpc8xxx_gpio_get_function(struct udevice *dev, uint gpio) { - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev); int dir;
- dir = !!mpc85xx_gpio_get_dir(data->base, gpio_mask(gpio)); + dir = !!mpc8xxx_gpio_get_dir(data->base, gpio_mask(gpio)); return dir ? GPIOF_OUTPUT : GPIOF_INPUT; }
#if CONFIG_IS_ENABLED(OF_CONTROL) -static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) +static int mpc8xxx_gpio_ofdata_to_platdata(struct udevice *dev) { - struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev); + struct mpc8xxx_gpio_plat *plat = dev_get_platdata(dev); fdt_addr_t addr; fdt_size_t size;
@@ -183,10 +183,10 @@ static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) } #endif
-static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev) +static int mpc8xxx_gpio_platdata_to_priv(struct udevice *dev) { - struct mpc85xx_gpio_data *priv = dev_get_priv(dev); - struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev); + struct mpc8xxx_gpio_data *priv = dev_get_priv(dev); + struct mpc8xxx_gpio_plat *plat = dev_get_platdata(dev); unsigned long size = plat->size;
if (size == 0) @@ -201,16 +201,18 @@ static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev) priv->gpio_count = plat->ngpios; priv->dat_shadow = 0;
+ priv->type = driver_data; + return 0; }
-static int mpc85xx_gpio_probe(struct udevice *dev) +static int mpc8xxx_gpio_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - struct mpc85xx_gpio_data *data = dev_get_priv(dev); + struct mpc8xxx_gpio_data *data = dev_get_priv(dev); char name[32], *str;
- mpc85xx_gpio_platdata_to_priv(dev); + mpc8xxx_gpio_platdata_to_priv(dev);
snprintf(name, sizeof(name), "MPC@%lx_", data->addr); str = strdup(name); @@ -224,30 +226,30 @@ static int mpc85xx_gpio_probe(struct udevice *dev) return 0; }
-static const struct dm_gpio_ops gpio_mpc85xx_ops = { - .direction_input = mpc85xx_gpio_direction_input, - .direction_output = mpc85xx_gpio_direction_output, - .get_value = mpc85xx_gpio_get_value, - .set_value = mpc85xx_gpio_set_value, - .get_open_drain = mpc85xx_gpio_get_open_drain, - .set_open_drain = mpc85xx_gpio_set_open_drain, - .get_function = mpc85xx_gpio_get_function, +static const struct dm_gpio_ops gpio_mpc8xxx_ops = { + .direction_input = mpc8xxx_gpio_direction_input, + .direction_output = mpc8xxx_gpio_direction_output, + .get_value = mpc8xxx_gpio_get_value, + .set_value = mpc8xxx_gpio_set_value, + .get_open_drain = mpc8xxx_gpio_get_open_drain, + .set_open_drain = mpc8xxx_gpio_set_open_drain, + .get_function = mpc8xxx_gpio_get_function, };
-static const struct udevice_id mpc85xx_gpio_ids[] = { +static const struct udevice_id mpc8xxx_gpio_ids[] = { { .compatible = "fsl,pq3-gpio" }, { /* sentinel */ } };
-U_BOOT_DRIVER(gpio_mpc85xx) = { - .name = "gpio_mpc85xx", +U_BOOT_DRIVER(gpio_mpc8xxx) = { + .name = "gpio_mpc8xxx", .id = UCLASS_GPIO, - .ops = &gpio_mpc85xx_ops, + .ops = &gpio_mpc8xxx_ops, #if CONFIG_IS_ENABLED(OF_CONTROL) - .ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata, - .platdata_auto_alloc_size = sizeof(struct mpc85xx_gpio_plat), - .of_match = mpc85xx_gpio_ids, + .ofdata_to_platdata = mpc8xxx_gpio_ofdata_to_platdata, + .platdata_auto_alloc_size = sizeof(struct mpc8xxx_gpio_plat), + .of_match = mpc8xxx_gpio_ids, #endif - .probe = mpc85xx_gpio_probe, - .priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data), + .probe = mpc8xxx_gpio_probe, + .priv_auto_alloc_size = sizeof(struct mpc8xxx_gpio_data), };

Finally, make the mpc8xxx driver capable of handling more GPIO devices; this entails adding a special case for the MPC5121 SoC, and adding a set of new compatible strings.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/gpio/mpc8xxx_gpio.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/mpc8xxx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c index e4ebbc117c..0aa72ecd9f 100644 --- a/drivers/gpio/mpc8xxx_gpio.c +++ b/drivers/gpio/mpc8xxx_gpio.c @@ -11,8 +11,8 @@
#include <common.h> #include <dm.h> -#include <asm/gpio.h> #include <mapmem.h> +#include <asm/gpio.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -37,6 +37,12 @@ struct mpc8xxx_gpio_data { * for output pins */ u32 dat_shadow; + ulong type; +}; + +enum { + MPC8XXX_GPIO_TYPE, + MPC5121_GPIO_TYPE, };
inline u32 gpio_mask(uint gpio) @@ -119,6 +125,12 @@ static int mpc8xxx_gpio_set_value(struct udevice *dev, uint gpio, int value) static int mpc8xxx_gpio_direction_output(struct udevice *dev, uint gpio, int value) { + struct mpc8xxx_gpio_data *data = dev_get_priv(dev); + + /* GPIO 28..31 are input only on MPC5121 */ + if (data->type == MPC5121_GPIO_TYPE && gpio >= 28) + return -EINVAL; + return mpc8xxx_gpio_set_value(dev, gpio, value); }
@@ -188,6 +200,7 @@ static int mpc8xxx_gpio_platdata_to_priv(struct udevice *dev) struct mpc8xxx_gpio_data *priv = dev_get_priv(dev); struct mpc8xxx_gpio_plat *plat = dev_get_platdata(dev); unsigned long size = plat->size; + ulong driver_data = dev_get_driver_data(dev);
if (size == 0) size = 0x100; @@ -237,7 +250,13 @@ static const struct dm_gpio_ops gpio_mpc8xxx_ops = { };
static const struct udevice_id mpc8xxx_gpio_ids[] = { - { .compatible = "fsl,pq3-gpio" }, + { .compatible = "fsl,pq3-gpio", .data = MPC8XXX_GPIO_TYPE }, + { .compatible = "fsl,mpc8308-gpio", .data = MPC8XXX_GPIO_TYPE }, + { .compatible = "fsl,mpc8349-gpio", .data = MPC8XXX_GPIO_TYPE }, + { .compatible = "fsl,mpc8572-gpio", .data = MPC8XXX_GPIO_TYPE}, + { .compatible = "fsl,mpc8610-gpio", .data = MPC8XXX_GPIO_TYPE}, + { .compatible = "fsl,mpc5121-gpio", .data = MPC5121_GPIO_TYPE, }, + { .compatible = "fsl,qoriq-gpio", .data = MPC8XXX_GPIO_TYPE }, { /* sentinel */ } };

The MPC85xx GPIO driver was converted to handle a broader range of SoCs.
Prepare the MPC83xx code for usage of this driver.
Signed-off-by: Mario Six mario.six@gdsys.cc --- arch/powerpc/include/asm/arch-mpc83xx/gpio.h | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/powerpc/include/asm/arch-mpc83xx/gpio.h b/arch/powerpc/include/asm/arch-mpc83xx/gpio.h index 40ef2151b8..6ec4f00022 100644 --- a/arch/powerpc/include/asm/arch-mpc83xx/gpio.h +++ b/arch/powerpc/include/asm/arch-mpc83xx/gpio.h @@ -19,7 +19,15 @@
#define MAX_NUM_GPIOS (32 * MPC83XX_GPIO_CTRLRS)
+struct mpc8xxx_gpio_plat { + ulong addr; + unsigned long size; + uint ngpios; +}; + +#ifndef DM_GPIO void mpc83xx_gpio_init_f(void); void mpc83xx_gpio_init_r(void); +#endif /* DM_GPIO */
#endif /* MPC83XX_GPIO_H_ */

Make the MPC8xxx GPIO driver compatible with a live device tree.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/gpio/mpc8xxx_gpio.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/gpio/mpc8xxx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c index 0aa72ecd9f..326fd1672d 100644 --- a/drivers/gpio/mpc8xxx_gpio.c +++ b/drivers/gpio/mpc8xxx_gpio.c @@ -14,8 +14,6 @@ #include <mapmem.h> #include <asm/gpio.h>
-DECLARE_GLOBAL_DATA_PTR; - struct ccsr_gpio { u32 gpdir; u32 gpodr; @@ -181,15 +179,14 @@ static int mpc8xxx_gpio_ofdata_to_platdata(struct udevice *dev) { struct mpc8xxx_gpio_plat *plat = dev_get_platdata(dev); fdt_addr_t addr; - fdt_size_t size; + u32 reg[2]; + + dev_read_u32_array(dev, "reg", reg, 2); + addr = dev_translate_address(dev, reg);
- addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, - dev_of_offset(dev), - "reg", 0, &size, false); plat->addr = addr; - plat->size = size; - plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), - "ngpios", 32); + plat->size = reg[1]; + plat->ngpios = dev_read_u32_default(dev, "ngpios", 32);
return 0; } @@ -206,7 +203,7 @@ static int mpc8xxx_gpio_platdata_to_priv(struct udevice *dev) size = 0x100;
priv->addr = plat->addr; - priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size); + priv->base = map_sysmem(plat->addr, size);
if (!priv->base) return -ENOMEM;

Fix some style violations in the MDIO command.
Signed-off-by: Mario Six mario.six@gdsys.cc --- cmd/mdio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/cmd/mdio.c b/cmd/mdio.c index 21dc103736..3f11963006 100644 --- a/cmd/mdio.c +++ b/cmd/mdio.c @@ -14,7 +14,6 @@ #include <miiphy.h> #include <phy.h>
- static char last_op[2]; static uint last_data; static uint last_addr_lo; @@ -243,13 +242,13 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) case 'r': if (pos > 1) if (extract_reg_range(argv[pos--], &devadlo, &devadhi, - ®lo, ®hi)) + ®lo, ®hi)) return -1;
default: if (pos > 1) - if (extract_phy_range(&(argv[2]), pos - 1, &bus, - &phydev, &addrlo, &addrhi)) + if (extract_phy_range(&argv[2], pos - 1, &bus, + &phydev, &addrlo, &addrhi)) return -1;
break;

Fix some style violations in the board_f file.
Signed-off-by: Mario Six mario.six@gdsys.cc --- common/board_f.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/common/board_f.c b/common/board_f.c index 9220815441..953b8fb3e7 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -50,7 +50,7 @@ #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR #undef XTRN_DECLARE_GLOBAL_DATA_PTR #define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */ -DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR); +DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR); #else DECLARE_GLOBAL_DATA_PTR; #endif @@ -137,7 +137,7 @@ static int display_text_info(void) #endif
debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n", - text_base, bss_start, bss_end); + text_base, bss_start, bss_end); #endif
return 0; @@ -303,7 +303,7 @@ static int reserve_logbuffer(void) /* reserve kernel log buffer */ gd->relocaddr -= LOGBUFF_RESERVE; debug("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, - gd->relocaddr); + gd->relocaddr); #endif
return 0; @@ -428,7 +428,7 @@ static int reserve_malloc(void) { gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN; debug("Reserving %dk for malloc() at: %08lx\n", - TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); + TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp); return 0; }
@@ -458,7 +458,7 @@ static int reserve_global_data(void) gd->start_addr_sp -= sizeof(gd_t); gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t)); debug("Reserving %zu Bytes for Global Data at: %08lx\n", - sizeof(gd_t), gd->start_addr_sp); + sizeof(gd_t), gd->start_addr_sp); return 0; }

On 29 September 2017 at 06:52, Mario Six mario.six@gdsys.cc wrote:
Fix some style violations in the board_f file.
Signed-off-by: Mario Six mario.six@gdsys.cc
common/board_f.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Fix some style violations in the board_r file.
Signed-off-by: Mario Six mario.six@gdsys.cc --- common/board_r.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/common/board_r.c b/common/board_r.c index 94697e7bc1..a81addc005 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -161,9 +161,9 @@ static int initr_reloc_global_data(void) #endif #ifdef CONFIG_OF_EMBED /* - * The fdt_blob needs to be moved to new relocation address - * incase of FDT blob is embedded with in image - */ + * The fdt_blob needs to be moved to new relocation address + * incase of FDT blob is embedded with in image + */ gd->fdt_blob += gd->reloc_off; #endif #ifdef CONFIG_EFI_LOADER @@ -368,14 +368,16 @@ static int initr_flash(void) print_size(flash_size, ""); #ifdef CONFIG_SYS_FLASH_CHECKSUM /* - * Compute and print flash CRC if flashchecksum is set to 'y' - * - * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX - */ + * Compute and print flash CRC if flashchecksum is set to 'y' + * + * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX + */ if (env_get_yesno("flashchecksum") == 1) { + const uchar *flash_base = (const uchar *)CONFIG_SYS_FLASH_BASE; + printf(" CRC: %08X", crc32(0, - (const unsigned char *) CONFIG_SYS_FLASH_BASE, - flash_size)); + flash_base, + flash_size)); } #endif /* CONFIG_SYS_FLASH_CHECKSUM */ putc('\n'); @@ -392,7 +394,6 @@ static int initr_flash(void) update_flash_size(flash_size); #endif
- #if defined(CONFIG_OXC) || defined(CONFIG_RMU) /* flash mapped at end of memory map */ bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size; @@ -657,7 +658,7 @@ int initr_mem(void) /* Also take the logbuffer into account (pram is in kB) */ pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024; # endif - sprintf(memsz, "%ldk", (long int) ((gd->ram_size / 1024) - pram)); + sprintf(memsz, "%ldk", (long int)((gd->ram_size / 1024) - pram)); env_set("mem", memsz);
return 0; @@ -710,7 +711,7 @@ static init_fnc_t init_sequence_r[] = { initr_caches, /* Note: For Freescale LS2 SoCs, new MMU table is created in DDR. * A temporary mapping of IFC high region is since removed, - * so environmental variables in NOR flash is not availble + * so environmental variables in NOR flash is not available * until board_init() is called below to remap IFC to high * region. */ @@ -775,7 +776,7 @@ static init_fnc_t init_sequence_r[] = { #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT) /* * Do early PCI configuration _before_ the flash gets initialised, - * because PCU ressources are crucial for flash access on some boards. + * because PCU resources are crucial for flash access on some boards. */ initr_pci, #endif

On 29 September 2017 at 06:52, Mario Six mario.six@gdsys.cc wrote:
Fix some style violations in the board_r file.
Signed-off-by: Mario Six mario.six@gdsys.cc
common/board_r.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Fix some style violations in the gdsys MPC8308 board files, and make the code more readable.
Signed-off-by: Mario Six mario.six@gdsys.cc --- board/gdsys/mpc8308/hrcon.c | 55 ++++++++++++++++++++++--------------------- board/gdsys/mpc8308/mpc8308.c | 12 +++++----- board/gdsys/mpc8308/strider.c | 49 +++++++++++++++++++------------------- 3 files changed, 59 insertions(+), 57 deletions(-)
diff --git a/board/gdsys/mpc8308/hrcon.c b/board/gdsys/mpc8308/hrcon.c index 7e485074ce..55422b0a7f 100644 --- a/board/gdsys/mpc8308/hrcon.c +++ b/board/gdsys/mpc8308/hrcon.c @@ -38,11 +38,11 @@ DECLARE_GLOBAL_DATA_PTR; #define MAX_MUX_CHANNELS 2
enum { - MCFPGA_DONE = 1 << 0, - MCFPGA_INIT_N = 1 << 1, - MCFPGA_PROGRAM_N = 1 << 2, - MCFPGA_UPDATE_ENABLE_N = 1 << 3, - MCFPGA_RESET_N = 1 << 4, + MCFPGA_DONE = BIT(0), + MCFPGA_INIT_N = BIT(1), + MCFPGA_PROGRAM_N = BIT(2), + MCFPGA_UPDATE_ENABLE_N = BIT(3), + MCFPGA_RESET_N = BIT(4), };
enum { @@ -50,7 +50,7 @@ enum { GPIO_MDIO = 1 << 15, };
-unsigned int mclink_fpgacount; +uint mclink_fpgacount; struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
struct { @@ -110,7 +110,7 @@ int checkboard(void)
printf("HRCon %s", hw_type_cat ? "CAT" : "Fiber");
- if (s != NULL) { + if (s) { puts(", serial# "); puts(s); } @@ -123,12 +123,11 @@ int checkboard(void) int last_stage_init(void) { int slaves; - unsigned int k; - unsigned int mux_ch; - unsigned char mclink_controllers[] = { 0x3c, 0x3d, 0x3e }; + uint k; + uchar mclink_controllers[] = { 0x3c, 0x3d, 0x3e }; u16 fpga_features; bool hw_type_cat = pca9698_get_value(0x20, 20); - bool ch0_rgmii2_present = false; + bool ch0_rgmii2_present;
FPGA_GET_REG(0, fpga_features, &fpga_features);
@@ -140,16 +139,16 @@ int last_stage_init(void)
/* wait for FPGA done, then reset FPGA */ for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) { - unsigned int ctr = 0; + uint ctr = 0;
if (i2c_probe(mclink_controllers[k])) continue;
while (!(pca953x_get_val(mclink_controllers[k]) & MCFPGA_DONE)) { - udelay(100000); + mdelay(100); if (ctr++ > 5) { - printf("no done for mclink_controller %d\n", k); + printf("no done for mclink_controller %u\n", k); break; } } @@ -162,8 +161,10 @@ int last_stage_init(void) }
if (hw_type_cat) { + uint mux_ch; int retval; struct mii_dev *mdiodev = mdio_alloc(); + if (!mdiodev) return -ENOMEM; strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN); @@ -182,7 +183,7 @@ int last_stage_init(void) }
/* give slave-PLLs and Parade DP501 some time to be up and running */ - udelay(500000); + mdelay(500);
mclink_fpgacount = CONFIG_SYS_MCLINK_MAX; slaves = mclink_probe(); @@ -210,6 +211,7 @@ int last_stage_init(void) if (hw_type_cat) { int retval; struct mii_dev *mdiodev = mdio_alloc(); + if (!mdiodev) return -ENOMEM; strncpy(mdiodev->name, bb_miiphy_buses[k].name, @@ -236,17 +238,17 @@ int last_stage_init(void) * provide access to fpga gpios and controls (for I2C bitbang) * (these may look all too simple but make iocon.h much more readable) */ -void fpga_gpio_set(unsigned int bus, int pin) +void fpga_gpio_set(uint bus, int pin) { FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.set, pin); }
-void fpga_gpio_clear(unsigned int bus, int pin) +void fpga_gpio_clear(uint bus, int pin) { FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.clear, pin); }
-int fpga_gpio_get(unsigned int bus, int pin) +int fpga_gpio_get(uint bus, int pin) { u16 val;
@@ -255,7 +257,7 @@ int fpga_gpio_get(unsigned int bus, int pin) return val & pin; }
-void fpga_control_set(unsigned int bus, int pin) +void fpga_control_set(uint bus, int pin) { u16 val;
@@ -263,7 +265,7 @@ void fpga_control_set(unsigned int bus, int pin) FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val | pin); }
-void fpga_control_clear(unsigned int bus, int pin) +void fpga_control_clear(uint bus, int pin) { u16 val;
@@ -276,7 +278,7 @@ void mpc8308_init(void) pca9698_direction_output(0x20, 4, 1); }
-void mpc8308_set_fpga_reset(unsigned state) +void mpc8308_set_fpga_reset(uint state) { pca9698_set_value(0x20, 4, state ? 0 : 1); } @@ -288,11 +290,11 @@ void mpc8308_setup_hw(void) /* * set "startup-finished"-gpios */ - setbits_be32(&immr->gpio[0].dir, (1 << (31-11)) | (1 << (31-12))); - setbits_be32(&immr->gpio[0].dat, 1 << (31-12)); + setbits_be32(&immr->gpio[0].dir, (BIT(31 - 11) | BIT(31 - 12))); + setbits_be32(&immr->gpio[0].dat, BIT(31 - 12)); }
-int mpc8308_get_fpga_done(unsigned fpga) +int mpc8308_get_fpga_done(uint fpga) { return pca9698_get_value(0x20, 19); } @@ -370,7 +372,7 @@ int ft_board_setup(void *blob, bd_t *bd) */
struct fpga_mii { - unsigned fpga; + uint fpga; int mdio; } fpga_mii[] = { { 0, 1}, @@ -497,5 +499,4 @@ struct bb_miiphy_bus bb_miiphy_buses[] = { }, };
-int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / - sizeof(bb_miiphy_buses[0]); +int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); diff --git a/board/gdsys/mpc8308/mpc8308.c b/board/gdsys/mpc8308/mpc8308.c index 86b257f4de..0b1d4eab22 100644 --- a/board/gdsys/mpc8308/mpc8308.c +++ b/board/gdsys/mpc8308/mpc8308.c @@ -25,14 +25,14 @@
DECLARE_GLOBAL_DATA_PTR;
-int get_fpga_state(unsigned dev) +int get_fpga_state(uint dev) { return gd->arch.fpga_state[dev]; }
int board_early_init_f(void) { - unsigned k; + uint k;
for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) gd->arch.fpga_state[k] = 0; @@ -42,8 +42,8 @@ int board_early_init_f(void)
int board_early_init_r(void) { - unsigned k; - unsigned ctr; + uint k; + uint ctr;
for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) gd->arch.fpga_state[k] = 0; @@ -60,7 +60,7 @@ int board_early_init_r(void) for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k) { ctr = 0; while (!mpc8308_get_fpga_done(k)) { - udelay(100000); + mdelay(100); if (ctr++ > 5) { gd->arch.fpga_state[k] |= FPGA_STATE_DONE_FAILED; @@ -87,7 +87,7 @@ int board_early_init_r(void) if (val == REFLECTION_TESTPATTERN_INV) break;
- udelay(100000); + mdelay(100); if (ctr++ > 5) { gd->arch.fpga_state[k] |= FPGA_STATE_REFLECTION_FAILED; diff --git a/board/gdsys/mpc8308/strider.c b/board/gdsys/mpc8308/strider.c index fec691515d..898782a2e4 100644 --- a/board/gdsys/mpc8308/strider.c +++ b/board/gdsys/mpc8308/strider.c @@ -53,7 +53,7 @@ enum { GPIO_MDIO = 1 << 15, };
-unsigned int mclink_fpgacount; +uint mclink_fpgacount; struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
struct { @@ -113,7 +113,7 @@ int checkboard(void)
printf("Strider %s", hw_type_cat ? "CAT" : "Fiber");
- if (s != NULL) { + if (s) { puts(", serial# "); puts(s); } @@ -126,17 +126,17 @@ int checkboard(void) int last_stage_init(void) { int slaves; - unsigned int k; - unsigned int mux_ch; - unsigned char mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e }; + uint k; + uint mux_ch; + uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e }; #ifdef CONFIG_STRIDER_CPU - unsigned char mclink_controllers_dp[] = { 0x24, 0x25, 0x26 }; + uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 }; #endif bool hw_type_cat = pca9698_get_value(0x20, 18); #ifdef CONFIG_STRIDER_CON_DP bool is_dh = pca9698_get_value(0x20, 25); #endif - bool ch0_sgmii2_present = false; + bool ch0_sgmii2_present;
/* Turn on Analog Devices ADV7611 */ pca9698_direction_output(0x20, 8, 0); @@ -149,8 +149,8 @@ int last_stage_init(void)
/* wait for FPGA done, then reset FPGA */ for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) { - unsigned int ctr = 0; - unsigned char *mclink_controllers = mclink_controllers_dvi; + uint ctr = 0; + uchar *mclink_controllers = mclink_controllers_dvi;
#ifdef CONFIG_STRIDER_CPU if (i2c_probe(mclink_controllers[k])) { @@ -164,7 +164,7 @@ int last_stage_init(void) #endif while (!(pca953x_get_val(mclink_controllers[k]) & MCFPGA_DONE)) { - udelay(100000); + mdelay(100); if (ctr++ > 5) { printf("no done for mclink_controller %d\n", k); break; @@ -181,6 +181,7 @@ int last_stage_init(void) if (hw_type_cat) { int retval; struct mii_dev *mdiodev = mdio_alloc(); + if (!mdiodev) return -ENOMEM; strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN); @@ -199,7 +200,7 @@ int last_stage_init(void) }
/* give slave-PLLs and Parade DP501 some time to be up and running */ - udelay(500000); + mdelay(500);
mclink_fpgacount = CONFIG_SYS_MCLINK_MAX; slaves = mclink_probe(); @@ -238,7 +239,7 @@ int last_stage_init(void) for (k = 1; k <= slaves; ++k) FPGA_SET_REG(k, extended_control, 0x10); /* enable video */
- udelay(500000); + mdelay(500); #endif
for (k = 1; k <= slaves; ++k) { @@ -263,6 +264,7 @@ int last_stage_init(void) if (hw_type_cat) { int retval; struct mii_dev *mdiodev = mdio_alloc(); + if (!mdiodev) return -ENOMEM; strncpy(mdiodev->name, bb_miiphy_buses[k].name, @@ -289,17 +291,17 @@ int last_stage_init(void) * provide access to fpga gpios (for I2C bitbang) * (these may look all too simple but make iocon.h much more readable) */ -void fpga_gpio_set(unsigned int bus, int pin) +void fpga_gpio_set(uint bus, int pin) { FPGA_SET_REG(bus, gpio.set, pin); }
-void fpga_gpio_clear(unsigned int bus, int pin) +void fpga_gpio_clear(uint bus, int pin) { FPGA_SET_REG(bus, gpio.clear, pin); }
-int fpga_gpio_get(unsigned int bus, int pin) +int fpga_gpio_get(uint bus, int pin) { u16 val;
@@ -309,7 +311,7 @@ int fpga_gpio_get(unsigned int bus, int pin) }
#ifdef CONFIG_STRIDER_CON_DP -void fpga_control_set(unsigned int bus, int pin) +void fpga_control_set(uint bus, int pin) { u16 val;
@@ -317,7 +319,7 @@ void fpga_control_set(unsigned int bus, int pin) FPGA_SET_REG(bus, control, val | pin); }
-void fpga_control_clear(unsigned int bus, int pin) +void fpga_control_clear(uint bus, int pin) { u16 val;
@@ -331,7 +333,7 @@ void mpc8308_init(void) pca9698_direction_output(0x20, 26, 1); }
-void mpc8308_set_fpga_reset(unsigned state) +void mpc8308_set_fpga_reset(uint state) { pca9698_set_value(0x20, 26, state ? 0 : 1); } @@ -343,11 +345,11 @@ void mpc8308_setup_hw(void) /* * set "startup-finished"-gpios */ - setbits_be32(&immr->gpio[0].dir, (1 << (31-11)) | (1 << (31-12))); - setbits_be32(&immr->gpio[0].dat, 1 << (31-12)); + setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12)); + setbits_be32(&immr->gpio[0].dat, BIT(31 - 12)); }
-int mpc8308_get_fpga_done(unsigned fpga) +int mpc8308_get_fpga_done(uint fpga) { return pca9698_get_value(0x20, 20); } @@ -425,7 +427,7 @@ int ft_board_setup(void *blob, bd_t *bd) */
struct fpga_mii { - unsigned fpga; + uint fpga; int mdio; } fpga_mii[] = { { 0, 1}, @@ -552,5 +554,4 @@ struct bb_miiphy_bus bb_miiphy_buses[] = { }, };
-int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) / - sizeof(bb_miiphy_buses[0]); +int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);

Since gpio output status on MPC8xxx cannot be read back, it has to be buffered locally.
Signed-off-by: Dirk Eibach dirk.eibach@gdsys.cc Signed-off-by: Mario Six mario.six@gdsys.cc --- board/gdsys/mpc8308/hrcon.c | 4 ++-- board/gdsys/mpc8308/mpc8308.c | 19 +++++++++++++++++++ board/gdsys/mpc8308/mpc8308.h | 3 +++ board/gdsys/mpc8308/strider.c | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/board/gdsys/mpc8308/hrcon.c b/board/gdsys/mpc8308/hrcon.c index 55422b0a7f..b3017de911 100644 --- a/board/gdsys/mpc8308/hrcon.c +++ b/board/gdsys/mpc8308/hrcon.c @@ -290,8 +290,8 @@ void mpc8308_setup_hw(void) /* * set "startup-finished"-gpios */ - setbits_be32(&immr->gpio[0].dir, (BIT(31 - 11) | BIT(31 - 12))); - setbits_be32(&immr->gpio[0].dat, BIT(31 - 12)); + setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12)); + setbits_gpio0_out(BIT(31 - 12)); }
int mpc8308_get_fpga_done(uint fpga) diff --git a/board/gdsys/mpc8308/mpc8308.c b/board/gdsys/mpc8308/mpc8308.c index 0b1d4eab22..8d6a49f86a 100644 --- a/board/gdsys/mpc8308/mpc8308.c +++ b/board/gdsys/mpc8308/mpc8308.c @@ -25,6 +25,25 @@
DECLARE_GLOBAL_DATA_PTR;
+/* as gpio output status cannot be read back, we have to buffer it locally */ +u32 gpio0_out; + +void setbits_gpio0_out(u32 mask) +{ + immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; + + gpio0_out |= mask; + out_be32(&immr->gpio[0].dat, gpio0_out); +} + +void clrbits_gpio0_out(u32 mask) +{ + immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; + + gpio0_out &= ~mask; + out_be32(&immr->gpio[0].dat, gpio0_out); +} + int get_fpga_state(uint dev) { return gd->arch.fpga_state[dev]; diff --git a/board/gdsys/mpc8308/mpc8308.h b/board/gdsys/mpc8308/mpc8308.h index dc07d564eb..1e4f24fb2a 100644 --- a/board/gdsys/mpc8308/mpc8308.h +++ b/board/gdsys/mpc8308/mpc8308.h @@ -1,6 +1,9 @@ #ifndef __MPC8308_H_ #define __MPC8308_H_
+void setbits_gpio0_out(u32 mask); +void clrbits_gpio0_out(u32 mask); + /* functions to be provided by board implementation */ void mpc8308_init(void); void mpc8308_set_fpga_reset(unsigned state); diff --git a/board/gdsys/mpc8308/strider.c b/board/gdsys/mpc8308/strider.c index 898782a2e4..3ee5a4889d 100644 --- a/board/gdsys/mpc8308/strider.c +++ b/board/gdsys/mpc8308/strider.c @@ -346,7 +346,7 @@ void mpc8308_setup_hw(void) * set "startup-finished"-gpios */ setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12)); - setbits_be32(&immr->gpio[0].dat, BIT(31 - 12)); + setbits_gpio0_out(BIT(31 - 12)); }
int mpc8308_get_fpga_done(uint fpga)

From: Dirk Eibach dirk.eibach@gdsys.cc
The phy on the CON2 module needs a defined reset pulse of at least 10 ms to work reliably.
Signed-off-by: Dirk Eibach dirk.eibach@gdsys.cc Signed-off-by: Mario Six mario.six@gdsys.cc --- board/gdsys/mpc8308/hrcon.c | 30 ++++++++++++++++++++++++++++++ board/gdsys/mpc8308/strider.c | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
diff --git a/board/gdsys/mpc8308/hrcon.c b/board/gdsys/mpc8308/hrcon.c index b3017de911..b03328278e 100644 --- a/board/gdsys/mpc8308/hrcon.c +++ b/board/gdsys/mpc8308/hrcon.c @@ -58,6 +58,26 @@ struct { u8 addr; } hrcon_fans[] = CONFIG_HRCON_FANS;
+#ifdef CONFIG_HRCON_DH +struct { + u8 bus; + u8 addr; + u16 mask; +} rgmii2_reset[] = { { 0, 0x23, 0x0100}, + {10, 0x23, 0x0100}, + {11, 0x23, 0x0100}, + {12, 0x23, 0x0100} }; +#else +struct { + u8 bus; + u8 addr; + u16 mask; +} rgmii2_reset[] = { {0, 0x23, 0x0100}, + {6, 0x23, 0x0100}, + {7, 0x23, 0x0100}, + {8, 0x23, 0x0100} }; +#endif + int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data) { int res; @@ -160,6 +180,16 @@ int last_stage_init(void) MCFPGA_RESET_N); }
+ if (hw_type_cat && ch0_rgmii2_present) { + i2c_set_bus_num(rgmii2_reset[0].bus); + pca953x_set_val(rgmii2_reset[0].addr, rgmii2_reset[0].mask, 0); + pca953x_set_dir(rgmii2_reset[0].addr, rgmii2_reset[0].mask, 0); + mdelay(10); + pca953x_set_dir(rgmii2_reset[0].addr, rgmii2_reset[0].mask, + rgmii2_reset[0].mask); + i2c_set_bus_num(0); + } + if (hw_type_cat) { uint mux_ch; int retval; diff --git a/board/gdsys/mpc8308/strider.c b/board/gdsys/mpc8308/strider.c index 3ee5a4889d..c3f9c9a535 100644 --- a/board/gdsys/mpc8308/strider.c +++ b/board/gdsys/mpc8308/strider.c @@ -61,6 +61,17 @@ struct { u8 addr; } strider_fans[] = CONFIG_STRIDER_FANS;
+#if defined(CONFIG_STRIDER_CON) || defined(CONFIG_STRIDER_CON_DP) +struct { + u8 bus; + u8 addr; + u16 mask; +} sgmii2_reset[] = { { 0, 0x23, 0x0100}, + {10, 0x23, 0x0100}, + {11, 0x23, 0x0100}, + {12, 0x23, 0x0100} }; +#endif + int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data) { int res; @@ -178,6 +189,18 @@ int last_stage_init(void) MCFPGA_RESET_N); }
+#if defined(CONFIG_STRIDER_CON) || defined(CONFIG_STRIDER_CON_DP) + if (hw_type_cat && ch0_sgmii2_present) { + i2c_set_bus_num(sgmii2_reset[0].bus); + pca953x_set_val(sgmii2_reset[0].addr, sgmii2_reset[0].mask, 0); + pca953x_set_dir(sgmii2_reset[0].addr, sgmii2_reset[0].mask, 0); + mdelay(10); + pca953x_set_dir(sgmii2_reset[0].addr, sgmii2_reset[0].mask, + sgmii2_reset[0].mask); + i2c_set_bus_num(0); + } +#endif + if (hw_type_cat) { int retval; struct mii_dev *mdiodev = mdio_alloc(); @@ -261,6 +284,7 @@ int last_stage_init(void) ch7301_probe(k, false); dp501_probe(k, false); #endif + if (hw_type_cat) { int retval; struct mii_dev *mdiodev = mdio_alloc();

From: Dirk Eibach dirk.eibach@gdsys.cc
The initialization sequence described in the latest Release Notes MV-S302033-00 for the Marvell 88E1518 phy omits two register writes.
Use this new sequence for the setup of this phy.
Signed-off-by: Dirk Eibach dirk.eibach@gdsys.cc Signed-off-by: Mario Six mario.six@gdsys.cc --- board/gdsys/common/phy.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/board/gdsys/common/phy.c b/board/gdsys/common/phy.c index fb92658178..e45f923fed 100644 --- a/board/gdsys/common/phy.c +++ b/board/gdsys/common/phy.c @@ -46,8 +46,6 @@ struct mii_setupcmd fixup_88e1518[] = { { MIICMD_SET, 16, 0x214d }, { MIICMD_SET, 17, 0xcc0c }, { MIICMD_SET, 16, 0x2159 }, - { MIICMD_SET, 22, 0x00fb }, - { MIICMD_SET, 7, 0xc00d }, { MIICMD_SET, 22, 0x0000 }, };

Fix some style violations in the generic PHY management code.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/net/phy/phy.c | 82 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 33 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 5be51d73ce..0050a70075 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -27,7 +27,7 @@ DECLARE_GLOBAL_DATA_PTR; /* Generic PHY support and helper functions */
/** - * genphy_config_advert - sanitize and advertise auto-negotation parameters + * genphy_config_advert - sanitize and advertise auto-negotiation parameters * @phydev: target phy_device struct * * Description: Writes MII_ADVERTISE with the appropriate values, @@ -117,7 +117,6 @@ static int genphy_config_advert(struct phy_device *phydev) return changed; }
- /** * genphy_setup_forced - configures/forces speed/duplex from @phydev * @phydev: target phy_device struct @@ -130,14 +129,15 @@ static int genphy_setup_forced(struct phy_device *phydev) int err; int ctl = BMCR_ANRESTART;
- phydev->pause = phydev->asym_pause = 0; + phydev->pause = 0; + phydev->asym_pause = 0;
- if (SPEED_1000 == phydev->speed) + if (phydev->speed == SPEED_1000) ctl |= BMCR_SPEED1000; - else if (SPEED_100 == phydev->speed) + else if (phydev->speed == SPEED_100) ctl |= BMCR_SPEED100;
- if (DUPLEX_FULL == phydev->duplex) + if (phydev->duplex == DUPLEX_FULL) ctl |= BMCR_FULLDPLX;
err = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl); @@ -145,7 +145,6 @@ static int genphy_setup_forced(struct phy_device *phydev) return err; }
- /** * genphy_restart_aneg - Enable and Restart Autonegotiation * @phydev: target phy_device struct @@ -169,7 +168,6 @@ int genphy_restart_aneg(struct phy_device *phydev) return ctl; }
- /** * genphy_config_aneg - restart auto-negotiation or write BMCR * @phydev: target phy_device struct @@ -182,7 +180,7 @@ int genphy_config_aneg(struct phy_device *phydev) { int result;
- if (AUTONEG_ENABLE != phydev->autoneg) + if (phydev->autoneg != AUTONEG_ENABLE) return genphy_setup_forced(phydev);
result = genphy_config_advert(phydev); @@ -192,7 +190,8 @@ int genphy_config_aneg(struct phy_device *phydev)
if (result == 0) { /* Advertisment hasn't changed, but maybe aneg was never on to - * begin with? Or maybe phy was isolated? */ + * begin with? Or maybe phy was isolated? + */ int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
if (ctl < 0) @@ -203,7 +202,8 @@ int genphy_config_aneg(struct phy_device *phydev) }
/* Only restart aneg if we are advertising something different - * than we were before. */ + * than we were before. + */ if (result > 0) result = genphy_restart_aneg(phydev);
@@ -240,7 +240,7 @@ int genphy_update_link(struct phy_device *phydev) int i = 0;
printf("%s Waiting for PHY auto negotiation to complete", - phydev->dev->name); + phydev->dev->name); while (!(mii_reg & BMSR_ANEGCOMPLETE)) { /* * Timeout reached ? @@ -305,7 +305,8 @@ int genphy_parse_link(struct phy_device *phydev) */ gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000); if (gblpa < 0) { - debug("Could not read MII_STAT1000. Ignoring gigabit capability\n"); + debug("Could not read MII_STAT1000. "); + debug("Ignoring gigabit capability\n"); gblpa = 0; } gblpa &= phy_read(phydev, @@ -338,8 +339,9 @@ int genphy_parse_link(struct phy_device *phydev) if (lpa & LPA_100FULL) phydev->duplex = DUPLEX_FULL;
- } else if (lpa & LPA_10FULL) + } else if (lpa & LPA_10FULL) { phydev->duplex = DUPLEX_FULL; + }
/* * Extended status may indicate that the PHY supports @@ -574,7 +576,9 @@ static int phy_probe(struct phy_device *phydev) { int err = 0;
- phydev->advertising = phydev->supported = phydev->drv->features; + phydev->advertising = phydev->drv->features; + phydev->supported = phydev->drv->features; + phydev->mmds = phydev->drv->mmds;
if (phydev->drv->probe) @@ -594,7 +598,7 @@ static struct phy_driver *generic_for_interface(phy_interface_t interface) }
static struct phy_driver *get_phy_driver(struct phy_device *phydev, - phy_interface_t interface) + phy_interface_t interface) { struct list_head *entry; int phy_id = phydev->phy_id; @@ -617,11 +621,12 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr, struct phy_device *dev;
/* We allocate the device, and initialize the - * default values */ + * default values + */ dev = malloc(sizeof(*dev)); if (!dev) { printf("Failed to allocate PHY device for %s:%d\n", - bus->name, addr); + bus->name, addr); return NULL; }
@@ -660,7 +665,8 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) int phy_reg;
/* Grab the bits from PHYIR1, and put them - * in the upper half */ + * in the upper half + */ phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
if (phy_reg < 0) @@ -680,9 +686,11 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) }
static struct phy_device *create_phy_by_mask(struct mii_dev *bus, - unsigned phy_mask, int devad, phy_interface_t interface) + uint phy_mask, int devad, + phy_interface_t interface) { u32 phy_id = 0xffffffff; + while (phy_mask) { int addr = ffs(phy_mask) - 1; int r = get_phy_id(bus, addr, devad, &phy_id); @@ -695,11 +703,13 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus, }
static struct phy_device *search_for_existing_phy(struct mii_dev *bus, - unsigned phy_mask, phy_interface_t interface) + uint phy_mask, + phy_interface_t interface) { /* If we have one, return the existing device, with new interface */ while (phy_mask) { int addr = ffs(phy_mask) - 1; + if (bus->phymap[addr]) { bus->phymap[addr]->interface = interface; return bus->phymap[addr]; @@ -710,7 +720,8 @@ static struct phy_device *search_for_existing_phy(struct mii_dev *bus, }
static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, - unsigned phy_mask, phy_interface_t interface) + uint phy_mask, + phy_interface_t interface) { int i; struct phy_device *phydev; @@ -722,7 +733,7 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, /* Otherwise we have to try Clause 45 */ for (i = 0; i < 5; i++) { phydev = create_phy_by_mask(bus, phy_mask, - i ? i : MDIO_DEVAD_NONE, interface); + i ? i : MDIO_DEVAD_NONE, interface); if (IS_ERR(phydev)) return NULL; if (phydev) @@ -732,6 +743,7 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, debug("\n%s PHY: ", bus->name); while (phy_mask) { int addr = ffs(phy_mask) - 1; + debug("%d ", addr); phy_mask &= ~(1 << addr); } @@ -741,7 +753,8 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, }
/** - * get_phy_device - reads the specified PHY device and returns its @phy_device struct + * get_phy_device - reads the specified PHY device and returns its + * @phy_device struct * @bus: the target MII bus * @addr: PHY address on the MII bus * @@ -820,15 +833,15 @@ int miiphy_reset(const char *devname, unsigned char addr) return phy_reset(phydev); }
-struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask, - phy_interface_t interface) +struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, + phy_interface_t interface) { /* Reset the bus */ if (bus->reset) { bus->reset(bus);
/* Wait 15ms to make sure the PHY has come out of hard reset */ - udelay(15000); + mdelay(15); }
return get_phy_device_by_mask(bus, phy_mask, interface); @@ -844,8 +857,8 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) phy_reset(phydev); if (phydev->dev && phydev->dev != dev) { printf("%s:%d is connected to %s. Reconnecting to %s\n", - phydev->bus->name, phydev->addr, - phydev->dev->name, dev->name); + phydev->bus->name, phydev->addr, + phydev->dev->name, dev->name); } phydev->dev = dev; debug("%s connected to %s\n", dev->name, phydev->drv->name); @@ -853,20 +866,23 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
#ifdef CONFIG_DM_ETH struct phy_device *phy_connect(struct mii_dev *bus, int addr, - struct udevice *dev, phy_interface_t interface) + struct udevice *dev, + phy_interface_t interface) #else struct phy_device *phy_connect(struct mii_dev *bus, int addr, - struct eth_device *dev, phy_interface_t interface) + struct eth_device *dev, + phy_interface_t interface) #endif { struct phy_device *phydev = NULL; #ifdef CONFIG_PHY_FIXED int sn; const char *name; + sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev)); while (sn > 0) { name = fdt_get_name(gd->fdt_blob, sn, NULL); - if (name != NULL && strcmp(name, "fixed-link") == 0) { + if (name && strcmp(name, "fixed-link") == 0) { phydev = phy_device_create(bus, sn, PHY_FIXED_ID, interface); break; @@ -874,7 +890,7 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, sn = fdt_next_subnode(gd->fdt_blob, sn); } #endif - if (phydev == NULL) + if (!phydev) phydev = phy_find_by_mask(bus, 1 << addr, interface);
if (phydev)

On Fri, Sep 29, 2017 at 7:52 AM, Mario Six mario.six@gdsys.cc wrote:
Fix some style violations in the generic PHY management code.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/net/phy/phy.c | 82 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 33 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 5be51d73ce..0050a70075 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -27,7 +27,7 @@ DECLARE_GLOBAL_DATA_PTR; /* Generic PHY support and helper functions */
/**
- genphy_config_advert - sanitize and advertise auto-negotation parameters
- genphy_config_advert - sanitize and advertise auto-negotiation parameters
- @phydev: target phy_device struct
- Description: Writes MII_ADVERTISE with the appropriate values,
@@ -117,7 +117,6 @@ static int genphy_config_advert(struct phy_device *phydev) return changed; }
/**
- genphy_setup_forced - configures/forces speed/duplex from @phydev
- @phydev: target phy_device struct
@@ -130,14 +129,15 @@ static int genphy_setup_forced(struct phy_device *phydev) int err; int ctl = BMCR_ANRESTART;
phydev->pause = phydev->asym_pause = 0;
phydev->pause = 0;
phydev->asym_pause = 0;
if (SPEED_1000 == phydev->speed)
if (phydev->speed == SPEED_1000) ctl |= BMCR_SPEED1000;
else if (SPEED_100 == phydev->speed)
else if (phydev->speed == SPEED_100) ctl |= BMCR_SPEED100;
if (DUPLEX_FULL == phydev->duplex)
if (phydev->duplex == DUPLEX_FULL) ctl |= BMCR_FULLDPLX; err = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
@@ -145,7 +145,6 @@ static int genphy_setup_forced(struct phy_device *phydev) return err; }
/**
- genphy_restart_aneg - Enable and Restart Autonegotiation
- @phydev: target phy_device struct
@@ -169,7 +168,6 @@ int genphy_restart_aneg(struct phy_device *phydev) return ctl; }
/**
- genphy_config_aneg - restart auto-negotiation or write BMCR
- @phydev: target phy_device struct
@@ -182,7 +180,7 @@ int genphy_config_aneg(struct phy_device *phydev) { int result;
if (AUTONEG_ENABLE != phydev->autoneg)
if (phydev->autoneg != AUTONEG_ENABLE) return genphy_setup_forced(phydev); result = genphy_config_advert(phydev);
@@ -192,7 +190,8 @@ int genphy_config_aneg(struct phy_device *phydev)
if (result == 0) { /* Advertisment hasn't changed, but maybe aneg was never on to
Shouldn't this text start on the line after "/*" ?
* begin with? Or maybe phy was isolated? */
* begin with? Or maybe phy was isolated?
*/ int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR); if (ctl < 0)
@@ -203,7 +202,8 @@ int genphy_config_aneg(struct phy_device *phydev) }
/* Only restart aneg if we are advertising something different
Same here.
* than we were before. */
* than we were before.
*/ if (result > 0) result = genphy_restart_aneg(phydev);
@@ -240,7 +240,7 @@ int genphy_update_link(struct phy_device *phydev) int i = 0;
printf("%s Waiting for PHY auto negotiation to complete",
phydev->dev->name);
phydev->dev->name); while (!(mii_reg & BMSR_ANEGCOMPLETE)) { /* * Timeout reached ?
@@ -305,7 +305,8 @@ int genphy_parse_link(struct phy_device *phydev) */ gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000); if (gblpa < 0) {
debug("Could not read MII_STAT1000. Ignoring gigabit capability\n");
debug("Could not read MII_STAT1000. ");
debug("Ignoring gigabit capability\n"); gblpa = 0; } gblpa &= phy_read(phydev,
@@ -338,8 +339,9 @@ int genphy_parse_link(struct phy_device *phydev) if (lpa & LPA_100FULL) phydev->duplex = DUPLEX_FULL;
} else if (lpa & LPA_10FULL)
} else if (lpa & LPA_10FULL) { phydev->duplex = DUPLEX_FULL;
} /* * Extended status may indicate that the PHY supports
@@ -574,7 +576,9 @@ static int phy_probe(struct phy_device *phydev) { int err = 0;
phydev->advertising = phydev->supported = phydev->drv->features;
phydev->advertising = phydev->drv->features;
phydev->supported = phydev->drv->features;
phydev->mmds = phydev->drv->mmds; if (phydev->drv->probe)
@@ -594,7 +598,7 @@ static struct phy_driver *generic_for_interface(phy_interface_t interface) }
static struct phy_driver *get_phy_driver(struct phy_device *phydev,
phy_interface_t interface)
phy_interface_t interface)
{ struct list_head *entry; int phy_id = phydev->phy_id; @@ -617,11 +621,12 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr, struct phy_device *dev;
/* We allocate the device, and initialize the
Same here.
* default values */
* default values
*/ dev = malloc(sizeof(*dev)); if (!dev) { printf("Failed to allocate PHY device for %s:%d\n",
bus->name, addr);
bus->name, addr); return NULL; }
@@ -660,7 +665,8 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) int phy_reg;
/* Grab the bits from PHYIR1, and put them
Same here.
* in the upper half */
* in the upper half
*/ phy_reg = bus->read(bus, addr, devad, MII_PHYSID1); if (phy_reg < 0)
@@ -680,9 +686,11 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) }
static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
unsigned phy_mask, int devad, phy_interface_t interface)
uint phy_mask, int devad,
phy_interface_t interface)
{ u32 phy_id = 0xffffffff;
while (phy_mask) { int addr = ffs(phy_mask) - 1; int r = get_phy_id(bus, addr, devad, &phy_id);
@@ -695,11 +703,13 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus, }
static struct phy_device *search_for_existing_phy(struct mii_dev *bus,
unsigned phy_mask, phy_interface_t interface)
uint phy_mask,
phy_interface_t interface)
{ /* If we have one, return the existing device, with new interface */ while (phy_mask) { int addr = ffs(phy_mask) - 1;
if (bus->phymap[addr]) { bus->phymap[addr]->interface = interface; return bus->phymap[addr];
@@ -710,7 +720,8 @@ static struct phy_device *search_for_existing_phy(struct mii_dev *bus, }
static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
unsigned phy_mask, phy_interface_t interface)
uint phy_mask,
phy_interface_t interface)
{ int i; struct phy_device *phydev; @@ -722,7 +733,7 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, /* Otherwise we have to try Clause 45 */ for (i = 0; i < 5; i++) { phydev = create_phy_by_mask(bus, phy_mask,
i ? i : MDIO_DEVAD_NONE, interface);
i ? i : MDIO_DEVAD_NONE, interface); if (IS_ERR(phydev)) return NULL; if (phydev)
@@ -732,6 +743,7 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, debug("\n%s PHY: ", bus->name); while (phy_mask) { int addr = ffs(phy_mask) - 1;
debug("%d ", addr); phy_mask &= ~(1 << addr); }
@@ -741,7 +753,8 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, }
/**
- get_phy_device - reads the specified PHY device and returns its @phy_device struct
- get_phy_device - reads the specified PHY device and returns its
@phy_device struct
- @bus: the target MII bus
- @addr: PHY address on the MII bus
@@ -820,15 +833,15 @@ int miiphy_reset(const char *devname, unsigned char addr) return phy_reset(phydev); }
-struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
phy_interface_t interface)
+struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask,
phy_interface_t interface)
{ /* Reset the bus */ if (bus->reset) { bus->reset(bus);
/* Wait 15ms to make sure the PHY has come out of hard reset */
udelay(15000);
mdelay(15); } return get_phy_device_by_mask(bus, phy_mask, interface);
@@ -844,8 +857,8 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) phy_reset(phydev); if (phydev->dev && phydev->dev != dev) { printf("%s:%d is connected to %s. Reconnecting to %s\n",
phydev->bus->name, phydev->addr,
phydev->dev->name, dev->name);
phydev->bus->name, phydev->addr,
phydev->dev->name, dev->name); } phydev->dev = dev; debug("%s connected to %s\n", dev->name, phydev->drv->name);
@@ -853,20 +866,23 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
#ifdef CONFIG_DM_ETH struct phy_device *phy_connect(struct mii_dev *bus, int addr,
struct udevice *dev, phy_interface_t interface)
struct udevice *dev,
phy_interface_t interface)
#else struct phy_device *phy_connect(struct mii_dev *bus, int addr,
struct eth_device *dev, phy_interface_t interface)
struct eth_device *dev,
phy_interface_t interface)
#endif { struct phy_device *phydev = NULL; #ifdef CONFIG_PHY_FIXED int sn; const char *name;
sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev)); while (sn > 0) { name = fdt_get_name(gd->fdt_blob, sn, NULL);
if (name != NULL && strcmp(name, "fixed-link") == 0) {
if (name && strcmp(name, "fixed-link") == 0) { phydev = phy_device_create(bus, sn, PHY_FIXED_ID, interface); break;
@@ -874,7 +890,7 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, sn = fdt_next_subnode(gd->fdt_blob, sn); } #endif
if (phydev == NULL)
if (!phydev) phydev = phy_find_by_mask(bus, 1 << addr, interface); if (phydev)
-- 2.11.0

Prepare the function interface of the ihs_i2c driver for DM conversion in a future patch.
While we're at it, fix some style violations, and make the code more readable.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/i2c/ihs_i2c.c | 69 +++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 29 deletions(-)
diff --git a/drivers/i2c/ihs_i2c.c b/drivers/i2c/ihs_i2c.c index 29612e69fe..6fd016339c 100644 --- a/drivers/i2c/ihs_i2c.c +++ b/drivers/i2c/ihs_i2c.c @@ -11,6 +11,7 @@ #include <common.h> #include <i2c.h> #include <gdsys_fpga.h> +#include <asm/unaligned.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -41,30 +42,38 @@ DECLARE_GLOBAL_DATA_PTR; #endif
enum { - I2CINT_ERROR_EV = 1 << 13, - I2CINT_TRANSMIT_EV = 1 << 14, - I2CINT_RECEIVE_EV = 1 << 15, + I2CINT_ERROR_EV = BIT(13), + I2CINT_TRANSMIT_EV = BIT(14), + I2CINT_RECEIVE_EV = BIT(15), };
enum { + I2CMB_READ = 0 << 10, I2CMB_WRITE = 1 << 10, + I2CMB_1BYTE = 0 << 11, I2CMB_2BYTE = 1 << 11, + I2CMB_DONT_HOLD_BUS = 0 << 13, I2CMB_HOLD_BUS = 1 << 13, I2CMB_NATIVE = 2 << 14, };
+enum { + I2COP_WRITE = 0, + I2COP_READ = 1, +}; + static int wait_for_int(bool read) { u16 val; - unsigned int ctr = 0; + uint ctr = 0;
I2C_GET_REG(interrupt_status, &val); + /* Wait until error or receive/transmit interrupt was raised */ while (!(val & (I2CINT_ERROR_EV | (read ? I2CINT_RECEIVE_EV : I2CINT_TRANSMIT_EV)))) { udelay(10); - if (ctr++ > 5000) { + if (ctr++ > 5000) return 1; - } I2C_GET_REG(interrupt_status, &val); }
@@ -76,10 +85,12 @@ static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read, { u16 val;
+ /* Clear interrupt status */ I2C_SET_REG(interrupt_status, I2CINT_ERROR_EV | I2CINT_RECEIVE_EV | I2CINT_TRANSMIT_EV); I2C_GET_REG(interrupt_status, &val);
+ /* If we want to write and have data, write the bytes to the mailbox */ if (!read && len) { val = buffer[0];
@@ -98,6 +109,7 @@ static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read, if (wait_for_int(read)) return 1;
+ /* If we want to read, get the bytes from the mailbox */ if (read) { I2C_GET_REG(read_mailbox_ext, &val); buffer[0] = val & 0xff; @@ -108,55 +120,44 @@ static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read, return 0; }
-static int ihs_i2c_address(uchar chip, uint addr, int alen, bool hold_bus) +static int ihs_i2c_address(uchar chip, u8 *addr, int alen, bool hold_bus) { - int shift = (alen-1) * 8; - while (alen) { int transfer = min(alen, 2); - uchar buf[2]; bool is_last = alen <= transfer;
- buf[0] = addr >> shift; - if (alen > 1) - buf[1] = addr >> (shift - 8); - - if (ihs_i2c_transfer(chip, buf, transfer, false, + if (ihs_i2c_transfer(chip, addr, transfer, I2COP_WRITE, hold_bus ? false : is_last)) return 1;
- shift -= 16; alen -= transfer; }
return 0; }
-static int ihs_i2c_access(struct i2c_adapter *adap, uchar chip, uint addr, - int alen, uchar *buffer, int len, bool read) +static int ihs_i2c_access(struct i2c_adapter *adap, uchar chip, u8 *addr, + int alen, uchar *buffer, int len, int read) { - if (len <= 0) - return 1; - - if (ihs_i2c_address(chip, addr, alen, len)) + /* Don't hold the bus if length of data to send/receive is zero */ + if (len <= 0 || ihs_i2c_address(chip, addr, alen, len)) return 1;
while (len) { int transfer = min(len, 2); + bool is_last = len <= transfer;
if (ihs_i2c_transfer(chip, buffer, transfer, read, - len <= transfer)) - return 1; + is_last)) + return 2;
buffer += transfer; - addr += transfer; len -= transfer; }
return 0; }
- static void ihs_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr) { #ifdef CONFIG_SYS_I2C_INIT_BOARD @@ -173,7 +174,7 @@ static int ihs_i2c_probe(struct i2c_adapter *adap, uchar chip) { uchar buffer[2];
- if (ihs_i2c_transfer(chip, buffer, 0, true, true)) + if (ihs_i2c_transfer(chip, buffer, 0, I2COP_READ, true)) return 1;
return 0; @@ -182,13 +183,23 @@ static int ihs_i2c_probe(struct i2c_adapter *adap, uchar chip) static int ihs_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, int alen, uchar *buffer, int len) { - return ihs_i2c_access(adap, chip, addr, alen, buffer, len, true); + u8 addr_bytes[4]; + + put_unaligned_le32(addr, addr_bytes); + + return ihs_i2c_access(adap, chip, addr_bytes, alen, buffer, len, + I2COP_READ); }
static int ihs_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, int alen, uchar *buffer, int len) { - return ihs_i2c_access(adap, chip, addr, alen, buffer, len, false); + u8 addr_bytes[4]; + + put_unaligned_le32(addr, addr_bytes); + + return ihs_i2c_access(adap, chip, addr_bytes, alen, buffer, len, + I2COP_WRITE); }
static unsigned int ihs_i2c_set_bus_speed(struct i2c_adapter *adap,

Make the ihs_i2c driver DM-compatible; for legacy boards, the old functions are retained within #ifdefs.
No board uses the new DM driver yet; this patch only lays the foundation for future support.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/i2c/ihs_i2c.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/ihs_i2c.c b/drivers/i2c/ihs_i2c.c index 6fd016339c..c3fddb55f9 100644 --- a/drivers/i2c/ihs_i2c.c +++ b/drivers/i2c/ihs_i2c.c @@ -3,19 +3,39 @@ * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de * * SPDX-License-Identifier: GPL-2.0+ - * - * NOTE: This driver should be converted to driver model before June 2017. - * Please see doc/driver-model/i2c-howto.txt for instructions. */
#include <common.h> #include <i2c.h> +#ifdef CONFIG_DM_I2C +#include <dm.h> +#include <ihs_fpga.h> +#include "../misc/gdsys_soc.h" +#else #include <gdsys_fpga.h> +#endif #include <asm/unaligned.h>
+#ifdef CONFIG_DM_I2C +struct ihs_i2c_priv { + uint speed; + phys_addr_t addr; +}; + +enum { + REG_INTERRUPT_STATUS = 0x00, + REG_INTERRUPT_ENABLE_CONTROL = 0x02, + REG_WRITE_MAILBOX_EXT = 0x04, + REG_WRITE_MAILBOX = 0x06, + REG_READ_MAILBOX_EXT = 0x08, + REG_READ_MAILBOX = 0x0A, +}; + +#else /* !CONFIG_DM_I2C */ DECLARE_GLOBAL_DATA_PTR;
#ifdef CONFIG_SYS_I2C_IHS_DUAL + #define I2C_SET_REG(fld, val) \ do { \ if (I2C_ADAP_HWNR & 0x10) \ @@ -40,6 +60,7 @@ DECLARE_GLOBAL_DATA_PTR; #define I2C_GET_REG(fld, val) \ FPGA_GET_REG(I2C_ADAP_HWNR, i2c0.fld, val) #endif +#endif /* CONFIG_DM_I2C */
enum { I2CINT_ERROR_EV = BIT(13), @@ -62,33 +83,71 @@ enum { I2COP_READ = 1, };
+#ifdef CONFIG_DM_I2C +static int wait_for_int(struct udevice *dev, int read) +#else static int wait_for_int(bool read) +#endif { u16 val; uint ctr = 0; +#ifdef CONFIG_DM_I2C + struct ihs_i2c_priv *priv = dev_get_priv(dev); + struct udevice *fpga;
+ gdsys_soc_get_fpga(dev, &fpga); +#endif + +#ifdef CONFIG_DM_I2C + val = fpga_in_le16(fpga, + priv->addr + REG_INTERRUPT_STATUS); +#else I2C_GET_REG(interrupt_status, &val); +#endif /* Wait until error or receive/transmit interrupt was raised */ while (!(val & (I2CINT_ERROR_EV | (read ? I2CINT_RECEIVE_EV : I2CINT_TRANSMIT_EV)))) { udelay(10); if (ctr++ > 5000) return 1; +#ifdef CONFIG_DM_I2C + val = fpga_in_le16(fpga, + priv->addr + REG_INTERRUPT_STATUS); +#else I2C_GET_REG(interrupt_status, &val); +#endif }
return (val & I2CINT_ERROR_EV) ? 1 : 0; }
+#ifdef CONFIG_DM_I2C +static int ihs_i2c_transfer(struct udevice *dev, uchar chip, + uchar *buffer, int len, int read, bool is_last) +#else static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read, bool is_last) +#endif { u16 val; +#ifdef CONFIG_DM_I2C + struct ihs_i2c_priv *priv = dev_get_priv(dev); + struct udevice *fpga; + + gdsys_soc_get_fpga(dev, &fpga); +#endif
/* Clear interrupt status */ +#ifdef CONFIG_DM_I2C + fpga_out_le16(fpga, priv->addr + REG_INTERRUPT_STATUS, + I2CINT_ERROR_EV | I2CINT_RECEIVE_EV | I2CINT_TRANSMIT_EV); + val = fpga_in_le16(fpga, + priv->addr + REG_INTERRUPT_STATUS); +#else I2C_SET_REG(interrupt_status, I2CINT_ERROR_EV | I2CINT_RECEIVE_EV | I2CINT_TRANSMIT_EV); I2C_GET_REG(interrupt_status, &val); +#endif
/* If we want to write and have data, write the bytes to the mailbox */ if (!read && len) { @@ -96,22 +155,45 @@ static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read,
if (len > 1) val |= buffer[1] << 8; +#ifdef CONFIG_DM_I2C + fpga_out_le16(fpga, + priv->addr + REG_WRITE_MAILBOX_EXT, val); +#else I2C_SET_REG(write_mailbox_ext, val); +#endif }
+#ifdef CONFIG_DM_I2C + fpga_out_le16(fpga, priv->addr + REG_WRITE_MAILBOX, + I2CMB_NATIVE + | (read ? I2CMB_READ : I2CMB_WRITE) + | (chip << 1) + | ((len > 1) ? I2CMB_2BYTE : I2CMB_1BYTE) + | (!is_last ? I2CMB_HOLD_BUS : I2CMB_DONT_HOLD_BUS)); +#else I2C_SET_REG(write_mailbox, I2CMB_NATIVE | (read ? 0 : I2CMB_WRITE) | (chip << 1) | ((len > 1) ? I2CMB_2BYTE : 0) | (is_last ? 0 : I2CMB_HOLD_BUS)); +#endif
+#ifdef CONFIG_DM_I2C + if (wait_for_int(dev, read)) +#else if (wait_for_int(read)) +#endif return 1;
/* If we want to read, get the bytes from the mailbox */ if (read) { +#ifdef CONFIG_DM_I2C + val = fpga_in_le16(fpga, + priv->addr + REG_READ_MAILBOX_EXT); +#else I2C_GET_REG(read_mailbox_ext, &val); +#endif buffer[0] = val & 0xff; if (len > 1) buffer[1] = val >> 8; @@ -120,15 +202,25 @@ static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read, return 0; }
+#ifdef CONFIG_DM_I2C +static int ihs_i2c_address(struct udevice *dev, uchar chip, u8 *addr, int alen, bool hold_bus) +#else static int ihs_i2c_address(uchar chip, u8 *addr, int alen, bool hold_bus) +#endif { while (alen) { int transfer = min(alen, 2); bool is_last = alen <= transfer;
+#ifdef CONFIG_DM_I2C + if (ihs_i2c_transfer(dev, chip, addr, transfer, I2COP_WRITE, + hold_bus ? false : is_last)) + return 1; +#else if (ihs_i2c_transfer(chip, addr, transfer, I2COP_WRITE, hold_bus ? false : is_last)) return 1; +#endif
alen -= transfer; } @@ -136,20 +228,36 @@ static int ihs_i2c_address(uchar chip, u8 *addr, int alen, bool hold_bus) return 0; }
+#ifdef CONFIG_DM_I2C +static int ihs_i2c_access(struct udevice *dev, uchar chip, u8 *addr, + int alen, uchar *buffer, int len, int read) +#else static int ihs_i2c_access(struct i2c_adapter *adap, uchar chip, u8 *addr, int alen, uchar *buffer, int len, int read) +#endif { /* Don't hold the bus if length of data to send/receive is zero */ +#ifdef CONFIG_DM_I2C + if (len <= 0 || ihs_i2c_address(dev, chip, addr, alen, len)) + return 1; +#else if (len <= 0 || ihs_i2c_address(chip, addr, alen, len)) return 1; +#endif
while (len) { int transfer = min(len, 2); bool is_last = len <= transfer;
+#ifdef CONFIG_DM_I2C + if (ihs_i2c_transfer(dev, chip, buffer, transfer, read, + is_last)) + return 2; +#else if (ihs_i2c_transfer(chip, buffer, transfer, read, is_last)) return 2; +#endif
buffer += transfer; len -= transfer; @@ -158,6 +266,92 @@ static int ihs_i2c_access(struct i2c_adapter *adap, uchar chip, u8 *addr, return 0; }
+#ifdef CONFIG_DM_I2C + +int ihs_i2c_probe(struct udevice *bus) +{ + struct ihs_i2c_priv *priv = dev_get_priv(bus); + int addr; + + addr = dev_read_u32_default(bus, "reg", -1); + + priv->addr = addr; + + return 0; +} + +static int ihs_i2c_set_bus_speed(struct udevice *bus, uint speed) +{ + struct ihs_i2c_priv *priv = dev_get_priv(bus); + + if (speed != priv->speed && priv->speed != 0) + return 1; + + priv->speed = speed; + + return 0; +} + +static int ihs_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs) +{ + struct i2c_msg *dmsg, *omsg, dummy; + + memset(&dummy, 0, sizeof(struct i2c_msg)); + + /* We expect either two messages (one with an offset and one with the + * actucal data) or one message (just data) + */ + if (nmsgs > 2 || nmsgs == 0) { + debug("%s: Only one or two messages are supported.", __func__); + return -1; + } + + omsg = nmsgs == 1 ? &dummy : msg; + dmsg = nmsgs == 1 ? msg : msg + 1; + + if (dmsg->flags & I2C_M_RD) + return ihs_i2c_access(bus, dmsg->addr, omsg->buf, + omsg->len, dmsg->buf, dmsg->len, + I2COP_READ); + else + return ihs_i2c_access(bus, dmsg->addr, omsg->buf, + omsg->len, dmsg->buf, dmsg->len, + I2COP_WRITE); +} + +static int ihs_i2c_probe_chip(struct udevice *bus, u32 chip_addr, + u32 chip_flags) +{ + uchar buffer[2]; + + if (ihs_i2c_transfer(bus, chip_addr, buffer, 0, I2COP_READ, true)) + return 1; + + return 0; +} + +static const struct dm_i2c_ops ihs_i2c_ops = { + .xfer = ihs_i2c_xfer, + .probe_chip = ihs_i2c_probe_chip, + .set_bus_speed = ihs_i2c_set_bus_speed, +}; + +static const struct udevice_id ihs_i2c_ids[] = { + { .compatible = "gdsys,ihs_i2cmaster", }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(i2c_ihs) = { + .name = "i2c_ihs", + .id = UCLASS_I2C, + .of_match = ihs_i2c_ids, + .probe = ihs_i2c_probe, + .priv_auto_alloc_size = sizeof(struct ihs_i2c_priv), + .ops = &ihs_i2c_ops, +}; + +#else /* CONFIG_DM_I2C */ + static void ihs_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr) { #ifdef CONFIG_SYS_I2C_INIT_BOARD @@ -269,3 +463,4 @@ U_BOOT_I2C_ADAP_COMPLETE(ihs3_1, ihs_i2c_init, ihs_i2c_probe, CONFIG_SYS_I2C_IHS_SLAVE_3_1, 19) #endif #endif +#endif /* CONFIG_DM_I2C */ -- 2.11.0

Simplify the driver logic by extracting a common send_buffer method.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/i2c/ihs_i2c.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/drivers/i2c/ihs_i2c.c b/drivers/i2c/ihs_i2c.c index c3fddb55f9..0432ca0994 100644 --- a/drivers/i2c/ihs_i2c.c +++ b/drivers/i2c/ihs_i2c.c @@ -203,32 +203,48 @@ static int ihs_i2c_transfer(uchar chip, uchar *buffer, int len, bool read, }
#ifdef CONFIG_DM_I2C -static int ihs_i2c_address(struct udevice *dev, uchar chip, u8 *addr, int alen, bool hold_bus) +static int ihs_i2c_send_buffer(struct udevice *dev, uchar chip, u8 *data, int len, bool hold_bus, int read) #else -static int ihs_i2c_address(uchar chip, u8 *addr, int alen, bool hold_bus) +static int ihs_i2c_send_buffer(uchar chip, u8 *data, int len, bool hold_bus, + int read) #endif { - while (alen) { - int transfer = min(alen, 2); - bool is_last = alen <= transfer; + while (len) { + int transfer = min(len, 2); + bool is_last = len <= transfer;
#ifdef CONFIG_DM_I2C - if (ihs_i2c_transfer(dev, chip, addr, transfer, I2COP_WRITE, + if (ihs_i2c_transfer(dev, chip, data, transfer, read, hold_bus ? false : is_last)) return 1; #else - if (ihs_i2c_transfer(chip, addr, transfer, I2COP_WRITE, + if (ihs_i2c_transfer(chip, data, transfer, read, hold_bus ? false : is_last)) return 1; #endif
- alen -= transfer; + data += transfer; + len -= transfer; }
return 0; }
#ifdef CONFIG_DM_I2C +static int ihs_i2c_address(struct udevice *dev, uchar chip, u8 *addr, int alen, + bool hold_bus) +#else +static int ihs_i2c_address(uchar chip, u8 *addr, int alen, bool hold_bus) +#endif +{ +#ifdef CONFIG_DM_I2C + return ihs_i2c_send_buffer(dev, chip, addr, alen, hold_bus, I2COP_WRITE); +#else + return ihs_i2c_send_buffer(chip, addr, alen, hold_bus, I2COP_WRITE); +#endif +} + +#ifdef CONFIG_DM_I2C static int ihs_i2c_access(struct udevice *dev, uchar chip, u8 *addr, int alen, uchar *buffer, int len, int read) #else @@ -245,25 +261,11 @@ static int ihs_i2c_access(struct i2c_adapter *adap, uchar chip, u8 *addr, return 1; #endif
- while (len) { - int transfer = min(len, 2); - bool is_last = len <= transfer; - #ifdef CONFIG_DM_I2C - if (ihs_i2c_transfer(dev, chip, buffer, transfer, read, - is_last)) - return 2; + return ihs_i2c_send_buffer(dev, chip, buffer, len, false, read); #else - if (ihs_i2c_transfer(chip, buffer, transfer, read, - is_last)) - return 2; + return ihs_i2c_send_buffer(chip, buffer, len, false, read); #endif - - buffer += transfer; - len -= transfer; - } - - return 0; }
#ifdef CONFIG_DM_I2C

The Makefile entries in the clk driver directory were not alphabetically sorted. Correct this.
Signed-off-by: Mario Six mario.six@gdsys.cc --- drivers/clk/Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 83fe88ce9f..bb22416fb5 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -6,20 +6,20 @@ #
obj-$(CONFIG_$(SPL_TPL_)CLK) += clk-uclass.o clk_fixed_rate.o -obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ -obj-$(CONFIG_SANDBOX) += clk_sandbox.o -obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o -obj-$(CONFIG_MACH_PIC32) += clk_pic32.o -obj-$(CONFIG_CLK_RENESAS) += renesas/ -obj-$(CONFIG_CLK_ZYNQ) += clk_zynq.o -obj-$(CONFIG_CLK_ZYNQMP) += clk_zynqmp.o
obj-y += tegra/ -obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ -obj-$(CONFIG_CLK_EXYNOS) += exynos/ +obj-$(CONFIG_ARCH_ASPEED) += aspeed/ +obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_CLK_AT91) += at91/ obj-$(CONFIG_CLK_BCM6345) += clk_bcm6345.o obj-$(CONFIG_CLK_BOSTON) += clk_boston.o -obj-$(CONFIG_ARCH_ASPEED) += aspeed/ +obj-$(CONFIG_CLK_EXYNOS) += exynos/ +obj-$(CONFIG_CLK_RENESAS) += renesas/ +obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ +obj-$(CONFIG_CLK_ZYNQ) += clk_zynq.o +obj-$(CONFIG_CLK_ZYNQMP) += clk_zynqmp.o +obj-$(CONFIG_MACH_PIC32) += clk_pic32.o +obj-$(CONFIG_SANDBOX) += clk_sandbox.o +obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o obj-$(CONFIG_STM32F7) += clk_stm32f7.o obj-$(CONFIG_STM32H7) += clk_stm32h7.o -- 2.11.0

On 29 September 2017 at 06:52, Mario Six mario.six@gdsys.cc wrote:
The Makefile entries in the clk driver directory were not alphabetically sorted. Correct this.
Signed-off-by: Mario Six mario.six@gdsys.cc
drivers/clk/Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
participants (8)
-
Dr. Philipp Tomsich
-
Heiko Schocher
-
Jagan Teki
-
Joe Hershberger
-
Mario Six
-
Masahiro Yamada
-
Simon Glass
-
Wolfgang Denk