aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/memory
diff options
context:
space:
mode:
authorRobert ABEL <rabel@cit-ec.uni-bielefeld.de>2015-02-27 10:56:53 -0500
committerRoger Quadros <rogerq@ti.com>2015-03-06 05:39:48 -0500
commit2e67690137f3a7bac660edd548f8846709c55381 (patch)
tree33262ac06753bd02df92a27fe520f24761dd1847 /drivers/memory
parentf585070b91950a0269eb20f497cceeee0aeefe0e (diff)
ARM OMAP2+ GPMC: calculate GPMCFCLKDIVIDER based on WAITMONITORINGTIME
The WAITMONITORINGTIME is expressed as a number of GPMC_CLK clock cycles, even though the access is defined as asynchronous, and no GPMC_CLK clock is provided to the external device. Still, GPMCFCLKDIVIDER is used as a divider for the GPMC clock, so it must be programmed to define the correct WAITMONITORINGTIME delay. Calculate GPMCFCLKDIVIDER independent of gpmc,sync-clk-ps in DT for pure asynchronous accesses, i.e. both read and write asynchronous. Signed-off-by: Robert ABEL <rabel@cit-ec.uni-bielefeld.de> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Roger Quadros <rogerq@ti.com>
Diffstat (limited to 'drivers/memory')
-rw-r--r--drivers/memory/omap-gpmc.c86
1 files changed, 79 insertions, 7 deletions
diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c
index 5c36ff397b73..768bab233196 100644
--- a/drivers/memory/omap-gpmc.c
+++ b/drivers/memory/omap-gpmc.c
@@ -138,7 +138,9 @@
138#define GPMC_CONFIG1_PAGE_LEN(val) ((val & 3) << 23) 138#define GPMC_CONFIG1_PAGE_LEN(val) ((val & 3) << 23)
139#define GPMC_CONFIG1_WAIT_READ_MON (1 << 22) 139#define GPMC_CONFIG1_WAIT_READ_MON (1 << 22)
140#define GPMC_CONFIG1_WAIT_WRITE_MON (1 << 21) 140#define GPMC_CONFIG1_WAIT_WRITE_MON (1 << 21)
141#define GPMC_CONFIG1_WAIT_MON_IIME(val) ((val & 3) << 18) 141#define GPMC_CONFIG1_WAIT_MON_TIME(val) ((val & 3) << 18)
142/** WAITMONITORINGTIME Max Ticks */
143#define GPMC_CONFIG1_WAITMONITORINGTIME_MAX 2
142#define GPMC_CONFIG1_WAIT_PIN_SEL(val) ((val & 3) << 16) 144#define GPMC_CONFIG1_WAIT_PIN_SEL(val) ((val & 3) << 16)
143#define GPMC_CONFIG1_DEVICESIZE(val) ((val & 3) << 12) 145#define GPMC_CONFIG1_DEVICESIZE(val) ((val & 3) << 12)
144#define GPMC_CONFIG1_DEVICESIZE_16 GPMC_CONFIG1_DEVICESIZE(1) 146#define GPMC_CONFIG1_DEVICESIZE_16 GPMC_CONFIG1_DEVICESIZE(1)
@@ -525,13 +527,48 @@ static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit,
525 t->field, #field) < 0) \ 527 t->field, #field) < 0) \
526 return -1 528 return -1
527 529
530/**
531 * gpmc_calc_waitmonitoring_divider - calculate proper GPMCFCLKDIVIDER based on WAITMONITORINGTIME
532 * WAITMONITORINGTIME will be _at least_ as long as desired, i.e.
533 * read --> don't sample bus too early
534 * write --> data is longer on bus
535 *
536 * Formula:
537 * gpmc_clk_div + 1 = ceil(ceil(waitmonitoringtime_ns / gpmc_fclk_ns)
538 * / waitmonitoring_ticks)
539 * WAITMONITORINGTIME resulting in 0 or 1 tick with div = 1 are caught by
540 * div <= 0 check.
541 *
542 * @wait_monitoring: WAITMONITORINGTIME in ns.
543 * @return: -1 on failure to scale, else proper divider > 0.
544 */
545static int gpmc_calc_waitmonitoring_divider(unsigned int wait_monitoring)
546{
547
548 int div = gpmc_ns_to_ticks(wait_monitoring);
549
550 div += GPMC_CONFIG1_WAITMONITORINGTIME_MAX - 1;
551 div /= GPMC_CONFIG1_WAITMONITORINGTIME_MAX;
552
553 if (div > 4)
554 return -1;
555 if (div <= 0)
556 div = 1;
557
558 return div;
559
560}
561
562/**
563 * gpmc_calc_divider - calculate GPMC_FCLK divider for sync_clk GPMC_CLK period.
564 * @sync_clk: GPMC_CLK period in ps.
565 * @return: Returns at least 1 if GPMC_FCLK can be divided to GPMC_CLK.
566 * Else, returns -1.
567 */
528int gpmc_calc_divider(unsigned int sync_clk) 568int gpmc_calc_divider(unsigned int sync_clk)
529{ 569{
530 int div; 570 int div = gpmc_ps_to_ticks(sync_clk);
531 u32 l;
532 571
533 l = sync_clk + (gpmc_get_fclk_period() - 1);
534 div = l / gpmc_get_fclk_period();
535 if (div > 4) 572 if (div > 4)
536 return -1; 573 return -1;
537 if (div <= 0) 574 if (div <= 0)
@@ -540,7 +577,15 @@ int gpmc_calc_divider(unsigned int sync_clk)
540 return div; 577 return div;
541} 578}
542 579
543int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t) 580/**
581 * gpmc_cs_set_timings - program timing parameters for Chip Select Region.
582 * @cs: Chip Select Region.
583 * @t: GPMC timing parameters.
584 * @s: GPMC timing settings.
585 * @return: 0 on success, -1 on error.
586 */
587int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t,
588 const struct gpmc_settings *s)
544{ 589{
545 int div; 590 int div;
546 u32 l; 591 u32 l;
@@ -550,6 +595,33 @@ int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t)
550 if (div < 0) 595 if (div < 0)
551 return div; 596 return div;
552 597
598 /*
599 * See if we need to change the divider for waitmonitoringtime.
600 *
601 * Calculate GPMCFCLKDIVIDER independent of gpmc,sync-clk-ps in DT for
602 * pure asynchronous accesses, i.e. both read and write asynchronous.
603 * However, only do so if WAITMONITORINGTIME is actually used, i.e.
604 * either WAITREADMONITORING or WAITWRITEMONITORING is set.
605 *
606 * This statement must not change div to scale async WAITMONITORINGTIME
607 * to protect mixed synchronous and asynchronous accesses.
608 *
609 * We raise an error later if WAITMONITORINGTIME does not fit.
610 */
611 if (!s->sync_read && !s->sync_write &&
612 (s->wait_on_read || s->wait_on_write)
613 ) {
614
615 div = gpmc_calc_waitmonitoring_divider(t->wait_monitoring);
616 if (div < 0) {
617 pr_err("%s: waitmonitoringtime %3d ns too large for greatest gpmcfclkdivider.\n",
618 __func__,
619 t->wait_monitoring
620 );
621 return -1;
622 }
623 }
624
553 GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on); 625 GPMC_SET_ONE(GPMC_CS_CONFIG2, 0, 3, cs_on);
554 GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off); 626 GPMC_SET_ONE(GPMC_CS_CONFIG2, 8, 12, cs_rd_off);
555 GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off); 627 GPMC_SET_ONE(GPMC_CS_CONFIG2, 16, 20, cs_wr_off);
@@ -1810,7 +1882,7 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
1810 if (ret < 0) 1882 if (ret < 0)
1811 goto err; 1883 goto err;
1812 1884
1813 ret = gpmc_cs_set_timings(cs, &gpmc_t); 1885 ret = gpmc_cs_set_timings(cs, &gpmc_t, &gpmc_s);
1814 if (ret) { 1886 if (ret) {
1815 dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n", 1887 dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n",
1816 child->name); 1888 child->name);