~ubuntu-branches/ubuntu/precise/linux-linaro-u8500/precise

« back to all changes in this revision

Viewing changes to arch/arm/mach-tegra/tegra2_clocks.c

  • Committer: Bazaar Package Importer
  • Author(s): John Rigby, Upstream Fixes, Andy Green, John Rigby
  • Date: 2011-04-14 12:16:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110414121606-b77podkyqgr2oix7
Tags: 2.6.38-1002.3
[ Upstream Fixes ]

* MUSB: shutdown: Make sure block is awake before doing shutdown
  - LP: #745737
* Fixed gpio polarity of gpio USB-phy reset.
  - LP: #747639

[ Andy Green ]

* LINARO: SAUCE: disable CONFIG_OMAP_RESET_CLOCKS
  - LP: #752900

[ John Rigby ]

* Rebase to new upstreams:
  Linux v2.6.38.1
  linaro-linux-2.6.38-upstream-29Mar2011
  Ubuntu-2.6.38-7.35
* SAUCE: OMAP4: clock: wait for module to become accessible on
  a clk enable
  - LP: #745737
* Rebase to new upstreams:
  Linux v2.6.38.2
  linaro-linux-2.6.38-upstream-5Apr2011
  Ubuntu-2.6.38-8.41
  - LP: #732842
* Update configs for device tree, dvfs and lttng
* LINARO: add building of dtb's
* LINARO: SAUCE: Disable lowest operating freqs on omap34xx
  - LP: #732912

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <linux/spinlock.h>
24
24
#include <linux/delay.h>
25
25
#include <linux/io.h>
26
 
#include <linux/hrtimer.h>
27
26
#include <linux/clkdev.h>
 
27
#include <linux/clk.h>
28
28
 
29
29
#include <mach/iomap.h>
 
30
#include <mach/suspend.h>
30
31
 
31
32
#include "clock.h"
32
33
#include "fuse.h"
33
 
#include "tegra2_dvfs.h"
 
34
#include "tegra2_emc.h"
34
35
 
35
36
#define RST_DEVICES                     0x004
36
37
#define RST_DEVICES_SET                 0x300
51
52
#define OSC_CTRL_OSC_FREQ_19_2MHZ       (1<<30)
52
53
#define OSC_CTRL_OSC_FREQ_12MHZ         (2<<30)
53
54
#define OSC_CTRL_OSC_FREQ_26MHZ         (3<<30)
54
 
#define OSC_CTRL_MASK                   0x3f2
 
55
#define OSC_CTRL_MASK                   (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
55
56
 
56
57
#define OSC_FREQ_DET                    0x58
57
58
#define OSC_FREQ_DET_TRIG               (1<<31)
73
74
#define PERIPH_CLK_SOURCE_DIVU16_MASK   0xFFFF
74
75
#define PERIPH_CLK_SOURCE_DIV_SHIFT     0
75
76
 
 
77
#define SDMMC_CLK_INT_FB_SEL            (1 << 23)
 
78
#define SDMMC_CLK_INT_FB_DLY_SHIFT      16
 
79
#define SDMMC_CLK_INT_FB_DLY_MASK       (0xF << SDMMC_CLK_INT_FB_DLY_SHIFT)
 
80
 
76
81
#define PLL_BASE                        0x0
77
82
#define PLL_BASE_BYPASS                 (1<<31)
78
83
#define PLL_BASE_ENABLE                 (1<<30)
79
84
#define PLL_BASE_REF_ENABLE             (1<<29)
80
85
#define PLL_BASE_OVERRIDE               (1<<28)
81
 
#define PLL_BASE_LOCK                   (1<<27)
82
86
#define PLL_BASE_DIVP_MASK              (0x7<<20)
83
87
#define PLL_BASE_DIVP_SHIFT             20
84
88
#define PLL_BASE_DIVN_MASK              (0x3FF<<8)
93
97
#define PLL_OUT_RESET_DISABLE           (1<<0)
94
98
 
95
99
#define PLL_MISC(c)                     (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
96
 
#define PLL_MISC_LOCK_ENABLE(c)         (((c)->flags & PLLU) ? (1<<22) : (1<<18))
97
100
 
98
101
#define PLL_MISC_DCCON_SHIFT            20
99
102
#define PLL_MISC_CPCON_SHIFT            8
111
114
 
112
115
#define PLLE_MISC_READY                 (1 << 15)
113
116
 
114
 
#define PERIPH_CLK_TO_ENB_REG(c)        ((c->clk_num / 32) * 4)
115
 
#define PERIPH_CLK_TO_ENB_SET_REG(c)    ((c->clk_num / 32) * 8)
116
 
#define PERIPH_CLK_TO_ENB_BIT(c)        (1 << (c->clk_num % 32))
 
117
#define PERIPH_CLK_TO_ENB_REG(c)        ((c->u.periph.clk_num / 32) * 4)
 
118
#define PERIPH_CLK_TO_ENB_SET_REG(c)    ((c->u.periph.clk_num / 32) * 8)
 
119
#define PERIPH_CLK_TO_ENB_BIT(c)        (1 << (c->u.periph.clk_num % 32))
117
120
 
118
121
#define SUPER_CLK_MUX                   0x00
119
122
#define SUPER_STATE_SHIFT               28
134
137
#define BUS_CLK_DISABLE                 (1<<3)
135
138
#define BUS_CLK_DIV_MASK                0x3
136
139
 
 
140
#define PMC_CTRL                        0x0
 
141
 #define PMC_CTRL_BLINK_ENB             (1 << 7)
 
142
 
 
143
#define PMC_DPD_PADS_ORIDE              0x1c
 
144
 #define PMC_DPD_PADS_ORIDE_BLINK_ENB   (1 << 20)
 
145
 
 
146
#define PMC_BLINK_TIMER_DATA_ON_SHIFT   0
 
147
#define PMC_BLINK_TIMER_DATA_ON_MASK    0x7fff
 
148
#define PMC_BLINK_TIMER_ENB             (1 << 15)
 
149
#define PMC_BLINK_TIMER_DATA_OFF_SHIFT  16
 
150
#define PMC_BLINK_TIMER_DATA_OFF_MASK   0xffff
 
151
 
137
152
static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
 
153
static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
 
154
 
 
155
/*
 
156
 * Some clocks share a register with other clocks.  Any clock op that
 
157
 * non-atomically modifies a register used by another clock must lock
 
158
 * clock_register_lock first.
 
159
 */
 
160
static DEFINE_SPINLOCK(clock_register_lock);
 
161
 
 
162
/*
 
163
 * Some peripheral clocks share an enable bit, so refcount the enable bits
 
164
 * in registers CLK_ENABLE_L, CLK_ENABLE_H, and CLK_ENABLE_U
 
165
 */
 
166
static int tegra_periph_clk_enable_refcount[3 * 32];
138
167
 
139
168
#define clk_writel(value, reg) \
140
169
        __raw_writel(value, (u32)reg_clk_base + (reg))
141
170
#define clk_readl(reg) \
142
171
        __raw_readl((u32)reg_clk_base + (reg))
 
172
#define pmc_writel(value, reg) \
 
173
        __raw_writel(value, (u32)reg_pmc_base + (reg))
 
174
#define pmc_readl(reg) \
 
175
        __raw_readl((u32)reg_pmc_base + (reg))
143
176
 
144
177
unsigned long clk_measure_input_freq(void)
145
178
{
245
278
        .disable        = tegra2_clk_m_disable,
246
279
};
247
280
 
 
281
void tegra2_periph_reset_assert(struct clk *c)
 
282
{
 
283
        BUG_ON(!c->ops->reset);
 
284
        c->ops->reset(c, true);
 
285
}
 
286
 
 
287
void tegra2_periph_reset_deassert(struct clk *c)
 
288
{
 
289
        BUG_ON(!c->ops->reset);
 
290
        c->ops->reset(c, false);
 
291
}
 
292
 
248
293
/* super clock functions */
249
294
/* "super clocks" on tegra have two-stage muxes and a clock skipping
250
295
 * super divider.  We will ignore the clock skipping divider, since we
303
348
                        val |= sel->value << shift;
304
349
 
305
350
                        if (c->refcnt)
306
 
                                clk_enable_locked(p);
 
351
                                clk_enable(p);
307
352
 
308
353
                        clk_writel(val, c->reg);
309
354
 
310
355
                        if (c->refcnt && c->parent)
311
 
                                clk_disable_locked(c->parent);
 
356
                                clk_disable(c->parent);
312
357
 
313
358
                        clk_reparent(c, p);
314
359
                        return 0;
317
362
        return -EINVAL;
318
363
}
319
364
 
 
365
/*
 
366
 * Super clocks have "clock skippers" instead of dividers.  Dividing using
 
367
 * a clock skipper does not allow the voltage to be scaled down, so instead
 
368
 * adjust the rate of the parent clock.  This requires that the parent of a
 
369
 * super clock have no other children, otherwise the rate will change
 
370
 * underneath the other children.
 
371
 */
 
372
static int tegra2_super_clk_set_rate(struct clk *c, unsigned long rate)
 
373
{
 
374
        return clk_set_rate(c->parent, rate);
 
375
}
 
376
 
320
377
static struct clk_ops tegra_super_ops = {
321
378
        .init                   = tegra2_super_clk_init,
322
379
        .enable                 = tegra2_super_clk_enable,
323
380
        .disable                = tegra2_super_clk_disable,
324
381
        .set_parent             = tegra2_super_clk_set_parent,
 
382
        .set_rate               = tegra2_super_clk_set_rate,
325
383
};
326
384
 
327
385
/* virtual cpu clock functions */
351
409
static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
352
410
{
353
411
        int ret;
354
 
        ret = clk_set_parent_locked(c->parent, c->backup);
 
412
        /*
 
413
         * Take an extra reference to the main pll so it doesn't turn
 
414
         * off when we move the cpu off of it
 
415
         */
 
416
        clk_enable(c->u.cpu.main);
 
417
 
 
418
        ret = clk_set_parent(c->parent, c->u.cpu.backup);
355
419
        if (ret) {
356
 
                pr_err("Failed to switch cpu to clock %s\n", c->backup->name);
357
 
                return ret;
 
420
                pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.backup->name);
 
421
                goto out;
358
422
        }
359
423
 
360
 
        ret = clk_set_rate_locked(c->main, rate);
 
424
        if (rate == clk_get_rate(c->u.cpu.backup))
 
425
                goto out;
 
426
 
 
427
        ret = clk_set_rate(c->u.cpu.main, rate);
361
428
        if (ret) {
362
429
                pr_err("Failed to change cpu pll to %lu\n", rate);
363
 
                return ret;
 
430
                goto out;
364
431
        }
365
432
 
366
 
        ret = clk_set_parent_locked(c->parent, c->main);
 
433
        ret = clk_set_parent(c->parent, c->u.cpu.main);
367
434
        if (ret) {
368
 
                pr_err("Failed to switch cpu to clock %s\n", c->main->name);
369
 
                return ret;
 
435
                pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.main->name);
 
436
                goto out;
370
437
        }
371
438
 
372
 
        return 0;
 
439
out:
 
440
        clk_disable(c->u.cpu.main);
 
441
        return ret;
373
442
}
374
443
 
375
444
static struct clk_ops tegra_cpu_ops = {
379
448
        .set_rate = tegra2_cpu_clk_set_rate,
380
449
};
381
450
 
 
451
/* virtual cop clock functions. Used to acquire the fake 'cop' clock to
 
452
 * reset the COP block (i.e. AVP) */
 
453
static void tegra2_cop_clk_reset(struct clk *c, bool assert)
 
454
{
 
455
        unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
 
456
 
 
457
        pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
 
458
        clk_writel(1 << 1, reg);
 
459
}
 
460
 
 
461
static struct clk_ops tegra_cop_ops = {
 
462
        .reset    = tegra2_cop_clk_reset,
 
463
};
 
464
 
382
465
/* bus clock functions */
383
466
static void tegra2_bus_clk_init(struct clk *c)
384
467
{
390
473
 
391
474
static int tegra2_bus_clk_enable(struct clk *c)
392
475
{
393
 
        u32 val = clk_readl(c->reg);
 
476
        u32 val;
 
477
        unsigned long flags;
 
478
 
 
479
        spin_lock_irqsave(&clock_register_lock, flags);
 
480
 
 
481
        val = clk_readl(c->reg);
394
482
        val &= ~(BUS_CLK_DISABLE << c->reg_shift);
395
483
        clk_writel(val, c->reg);
 
484
 
 
485
        spin_unlock_irqrestore(&clock_register_lock, flags);
 
486
 
396
487
        return 0;
397
488
}
398
489
 
399
490
static void tegra2_bus_clk_disable(struct clk *c)
400
491
{
401
 
        u32 val = clk_readl(c->reg);
 
492
        u32 val;
 
493
        unsigned long flags;
 
494
 
 
495
        spin_lock_irqsave(&clock_register_lock, flags);
 
496
 
 
497
        val = clk_readl(c->reg);
402
498
        val |= BUS_CLK_DISABLE << c->reg_shift;
403
499
        clk_writel(val, c->reg);
 
500
 
 
501
        spin_unlock_irqrestore(&clock_register_lock, flags);
404
502
}
405
503
 
406
504
static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
407
505
{
408
 
        u32 val = clk_readl(c->reg);
409
 
        unsigned long parent_rate = c->parent->rate;
 
506
        u32 val;
 
507
        unsigned long parent_rate = clk_get_rate(c->parent);
 
508
        unsigned long flags;
 
509
        int ret = -EINVAL;
410
510
        int i;
 
511
 
 
512
        spin_lock_irqsave(&clock_register_lock, flags);
 
513
 
 
514
        val = clk_readl(c->reg);
411
515
        for (i = 1; i <= 4; i++) {
412
516
                if (rate == parent_rate / i) {
413
517
                        val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
415
519
                        clk_writel(val, c->reg);
416
520
                        c->div = i;
417
521
                        c->mul = 1;
418
 
                        return 0;
 
522
                        ret = 0;
 
523
                        break;
419
524
                }
420
525
        }
421
 
        return -EINVAL;
 
526
 
 
527
        spin_unlock_irqrestore(&clock_register_lock, flags);
 
528
 
 
529
        return ret;
422
530
}
423
531
 
424
532
static struct clk_ops tegra_bus_ops = {
428
536
        .set_rate               = tegra2_bus_clk_set_rate,
429
537
};
430
538
 
 
539
/* Blink output functions */
 
540
 
 
541
static void tegra2_blink_clk_init(struct clk *c)
 
542
{
 
543
        u32 val;
 
544
 
 
545
        val = pmc_readl(PMC_CTRL);
 
546
        c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
 
547
        c->mul = 1;
 
548
        val = pmc_readl(c->reg);
 
549
 
 
550
        if (val & PMC_BLINK_TIMER_ENB) {
 
551
                unsigned int on_off;
 
552
 
 
553
                on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
 
554
                        PMC_BLINK_TIMER_DATA_ON_MASK;
 
555
                val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
 
556
                val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
 
557
                on_off += val;
 
558
                /* each tick in the blink timer is 4 32KHz clocks */
 
559
                c->div = on_off * 4;
 
560
        } else {
 
561
                c->div = 1;
 
562
        }
 
563
}
 
564
 
 
565
static int tegra2_blink_clk_enable(struct clk *c)
 
566
{
 
567
        u32 val;
 
568
 
 
569
        val = pmc_readl(PMC_DPD_PADS_ORIDE);
 
570
        pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
 
571
 
 
572
        val = pmc_readl(PMC_CTRL);
 
573
        pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
 
574
 
 
575
        return 0;
 
576
}
 
577
 
 
578
static void tegra2_blink_clk_disable(struct clk *c)
 
579
{
 
580
        u32 val;
 
581
 
 
582
        val = pmc_readl(PMC_CTRL);
 
583
        pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
 
584
 
 
585
        val = pmc_readl(PMC_DPD_PADS_ORIDE);
 
586
        pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
 
587
}
 
588
 
 
589
static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate)
 
590
{
 
591
        unsigned long parent_rate = clk_get_rate(c->parent);
 
592
        if (rate >= parent_rate) {
 
593
                c->div = 1;
 
594
                pmc_writel(0, c->reg);
 
595
        } else {
 
596
                unsigned int on_off;
 
597
                u32 val;
 
598
 
 
599
                on_off = DIV_ROUND_UP(parent_rate / 8, rate);
 
600
                c->div = on_off * 8;
 
601
 
 
602
                val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
 
603
                        PMC_BLINK_TIMER_DATA_ON_SHIFT;
 
604
                on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
 
605
                on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
 
606
                val |= on_off;
 
607
                val |= PMC_BLINK_TIMER_ENB;
 
608
                pmc_writel(val, c->reg);
 
609
        }
 
610
 
 
611
        return 0;
 
612
}
 
613
 
 
614
static struct clk_ops tegra_blink_clk_ops = {
 
615
        .init                   = &tegra2_blink_clk_init,
 
616
        .enable                 = &tegra2_blink_clk_enable,
 
617
        .disable                = &tegra2_blink_clk_disable,
 
618
        .set_rate               = &tegra2_blink_clk_set_rate,
 
619
};
 
620
 
431
621
/* PLL Functions */
432
622
static int tegra2_pll_clk_wait_for_lock(struct clk *c)
433
623
{
434
 
        ktime_t before;
435
 
 
436
 
        before = ktime_get();
437
 
 
438
 
        while (!(clk_readl(c->reg + PLL_BASE) & PLL_BASE_LOCK)) {
439
 
                if (ktime_us_delta(ktime_get(), before) > 5000) {
440
 
                        pr_err("Timed out waiting for lock bit on pll %s",
441
 
                                c->name);
442
 
                        return -1;
443
 
                }
444
 
        }
 
624
        udelay(c->u.pll.lock_delay);
445
625
 
446
626
        return 0;
447
627
}
479
659
        val |= PLL_BASE_ENABLE;
480
660
        clk_writel(val, c->reg + PLL_BASE);
481
661
 
482
 
        val = clk_readl(c->reg + PLL_MISC(c));
483
 
        val |= PLL_MISC_LOCK_ENABLE(c);
484
 
        clk_writel(val, c->reg + PLL_MISC(c));
485
 
 
486
662
        tegra2_pll_clk_wait_for_lock(c);
487
663
 
488
664
        return 0;
502
678
{
503
679
        u32 val;
504
680
        unsigned long input_rate;
505
 
        const struct clk_pll_table *sel;
 
681
        const struct clk_pll_freq_table *sel;
506
682
 
507
683
        pr_debug("%s: %s %lu\n", __func__, c->name, rate);
508
 
        BUG_ON(c->refcnt != 0);
509
684
 
510
 
        input_rate = c->parent->rate;
511
 
        for (sel = c->pll_table; sel->input_rate != 0; sel++) {
 
685
        input_rate = clk_get_rate(c->parent);
 
686
        for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
512
687
                if (sel->input_rate == input_rate && sel->output_rate == rate) {
513
688
                        c->mul = sel->n;
514
689
                        c->div = sel->m * sel->p;
620
795
{
621
796
        u32 val;
622
797
        u32 new_val;
 
798
        unsigned long flags;
623
799
 
624
800
        pr_debug("%s: %s\n", __func__, c->name);
625
801
        if (c->flags & DIV_U71) {
 
802
                spin_lock_irqsave(&clock_register_lock, flags);
626
803
                val = clk_readl(c->reg);
627
804
                new_val = val >> c->reg_shift;
628
805
                new_val &= 0xFFFF;
632
809
                val &= ~(0xFFFF << c->reg_shift);
633
810
                val |= new_val << c->reg_shift;
634
811
                clk_writel(val, c->reg);
 
812
                spin_unlock_irqrestore(&clock_register_lock, flags);
635
813
                return 0;
636
814
        } else if (c->flags & DIV_2) {
637
815
                BUG_ON(!(c->flags & PLLD));
 
816
                spin_lock_irqsave(&clock_register_lock, flags);
638
817
                val = clk_readl(c->reg);
639
818
                val &= ~PLLD_MISC_DIV_RST;
640
819
                clk_writel(val, c->reg);
 
820
                spin_unlock_irqrestore(&clock_register_lock, flags);
641
821
                return 0;
642
822
        }
643
823
        return -EINVAL;
647
827
{
648
828
        u32 val;
649
829
        u32 new_val;
 
830
        unsigned long flags;
650
831
 
651
832
        pr_debug("%s: %s\n", __func__, c->name);
652
833
        if (c->flags & DIV_U71) {
 
834
                spin_lock_irqsave(&clock_register_lock, flags);
653
835
                val = clk_readl(c->reg);
654
836
                new_val = val >> c->reg_shift;
655
837
                new_val &= 0xFFFF;
659
841
                val &= ~(0xFFFF << c->reg_shift);
660
842
                val |= new_val << c->reg_shift;
661
843
                clk_writel(val, c->reg);
 
844
                spin_unlock_irqrestore(&clock_register_lock, flags);
662
845
        } else if (c->flags & DIV_2) {
663
846
                BUG_ON(!(c->flags & PLLD));
 
847
                spin_lock_irqsave(&clock_register_lock, flags);
664
848
                val = clk_readl(c->reg);
665
849
                val |= PLLD_MISC_DIV_RST;
666
850
                clk_writel(val, c->reg);
 
851
                spin_unlock_irqrestore(&clock_register_lock, flags);
667
852
        }
668
853
}
669
854
 
672
857
        u32 val;
673
858
        u32 new_val;
674
859
        int divider_u71;
 
860
        unsigned long parent_rate = clk_get_rate(c->parent);
 
861
        unsigned long flags;
 
862
 
675
863
        pr_debug("%s: %s %lu\n", __func__, c->name, rate);
676
864
        if (c->flags & DIV_U71) {
677
 
                divider_u71 = clk_div71_get_divider(c->parent->rate, rate);
 
865
                divider_u71 = clk_div71_get_divider(parent_rate, rate);
678
866
                if (divider_u71 >= 0) {
 
867
                        spin_lock_irqsave(&clock_register_lock, flags);
679
868
                        val = clk_readl(c->reg);
680
869
                        new_val = val >> c->reg_shift;
681
870
                        new_val &= 0xFFFF;
689
878
                        clk_writel(val, c->reg);
690
879
                        c->div = divider_u71 + 2;
691
880
                        c->mul = 2;
 
881
                        spin_unlock_irqrestore(&clock_register_lock, flags);
692
882
                        return 0;
693
883
                }
694
884
        } else if (c->flags & DIV_2) {
695
 
                if (c->parent->rate == rate * 2)
 
885
                if (parent_rate == rate * 2)
696
886
                        return 0;
697
887
        }
698
888
        return -EINVAL;
701
891
static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
702
892
{
703
893
        int divider;
 
894
        unsigned long parent_rate = clk_get_rate(c->parent);
704
895
        pr_debug("%s: %s %lu\n", __func__, c->name, rate);
705
896
 
706
897
        if (c->flags & DIV_U71) {
707
 
                divider = clk_div71_get_divider(c->parent->rate, rate);
 
898
                divider = clk_div71_get_divider(parent_rate, rate);
708
899
                if (divider < 0)
709
900
                        return divider;
710
 
                return c->parent->rate * 2 / (divider + 2);
 
901
                return DIV_ROUND_UP(parent_rate * 2, divider + 2);
711
902
        } else if (c->flags & DIV_2) {
712
 
                return c->parent->rate / 2;
 
903
                return DIV_ROUND_UP(parent_rate, 2);
713
904
        }
714
905
        return -EINVAL;
715
906
}
755
946
        }
756
947
 
757
948
        c->state = ON;
 
949
 
 
950
        if (!c->u.periph.clk_num)
 
951
                return;
 
952
 
758
953
        if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
759
954
                        PERIPH_CLK_TO_ENB_BIT(c)))
760
955
                c->state = OFF;
 
956
 
761
957
        if (!(c->flags & PERIPH_NO_RESET))
762
958
                if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
763
959
                                PERIPH_CLK_TO_ENB_BIT(c))
767
963
static int tegra2_periph_clk_enable(struct clk *c)
768
964
{
769
965
        u32 val;
 
966
        unsigned long flags;
 
967
        int refcount;
770
968
        pr_debug("%s on clock %s\n", __func__, c->name);
771
969
 
 
970
        if (!c->u.periph.clk_num)
 
971
                return 0;
 
972
 
 
973
        spin_lock_irqsave(&clock_register_lock, flags);
 
974
 
 
975
        refcount = tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++;
 
976
 
 
977
        if (refcount > 1)
 
978
                goto out;
 
979
 
772
980
        clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
773
981
                CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
774
982
        if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
781
989
                val |= 0x3 << 24;
782
990
                clk_writel(val, c->reg);
783
991
        }
 
992
 
 
993
out:
 
994
        spin_unlock_irqrestore(&clock_register_lock, flags);
 
995
 
784
996
        return 0;
785
997
}
786
998
 
787
999
static void tegra2_periph_clk_disable(struct clk *c)
788
1000
{
789
 
        pr_debug("%s on clock %s\n", __func__, c->name);
790
 
 
791
 
        clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
792
 
                CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
793
 
}
794
 
 
795
 
void tegra2_periph_reset_deassert(struct clk *c)
796
 
{
797
 
        pr_debug("%s on clock %s\n", __func__, c->name);
798
 
        if (!(c->flags & PERIPH_NO_RESET))
799
 
                clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
800
 
                        RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
801
 
}
802
 
 
803
 
void tegra2_periph_reset_assert(struct clk *c)
804
 
{
805
 
        pr_debug("%s on clock %s\n", __func__, c->name);
806
 
        if (!(c->flags & PERIPH_NO_RESET))
807
 
                clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
808
 
                        RST_DEVICES_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
809
 
}
810
 
 
 
1001
        unsigned long flags;
 
1002
 
 
1003
        pr_debug("%s on clock %s\n", __func__, c->name);
 
1004
 
 
1005
        if (!c->u.periph.clk_num)
 
1006
                return;
 
1007
 
 
1008
        spin_lock_irqsave(&clock_register_lock, flags);
 
1009
 
 
1010
        if (c->refcnt)
 
1011
                tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--;
 
1012
 
 
1013
        if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] == 0)
 
1014
                clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
 
1015
                        CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
 
1016
 
 
1017
        spin_unlock_irqrestore(&clock_register_lock, flags);
 
1018
}
 
1019
 
 
1020
static void tegra2_periph_clk_reset(struct clk *c, bool assert)
 
1021
{
 
1022
        unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
 
1023
 
 
1024
        pr_debug("%s %s on clock %s\n", __func__,
 
1025
                 assert ? "assert" : "deassert", c->name);
 
1026
 
 
1027
        BUG_ON(!c->u.periph.clk_num);
 
1028
 
 
1029
        if (!(c->flags & PERIPH_NO_RESET))
 
1030
                clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
 
1031
                           base + PERIPH_CLK_TO_ENB_SET_REG(c));
 
1032
}
811
1033
 
812
1034
static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
813
1035
{
821
1043
                        val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
822
1044
 
823
1045
                        if (c->refcnt)
824
 
                                clk_enable_locked(p);
 
1046
                                clk_enable(p);
825
1047
 
826
1048
                        clk_writel(val, c->reg);
827
1049
 
828
1050
                        if (c->refcnt && c->parent)
829
 
                                clk_disable_locked(c->parent);
 
1051
                                clk_disable(c->parent);
830
1052
 
831
1053
                        clk_reparent(c, p);
832
1054
                        return 0;
840
1062
{
841
1063
        u32 val;
842
1064
        int divider;
843
 
        pr_debug("%s: %lu\n", __func__, rate);
 
1065
        unsigned long parent_rate = clk_get_rate(c->parent);
 
1066
 
844
1067
        if (c->flags & DIV_U71) {
845
 
                divider = clk_div71_get_divider(c->parent->rate, rate);
 
1068
                divider = clk_div71_get_divider(parent_rate, rate);
846
1069
                if (divider >= 0) {
847
1070
                        val = clk_readl(c->reg);
848
1071
                        val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
853
1076
                        return 0;
854
1077
                }
855
1078
        } else if (c->flags & DIV_U16) {
856
 
                divider = clk_div16_get_divider(c->parent->rate, rate);
 
1079
                divider = clk_div16_get_divider(parent_rate, rate);
857
1080
                if (divider >= 0) {
858
1081
                        val = clk_readl(c->reg);
859
1082
                        val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
863
1086
                        c->mul = 1;
864
1087
                        return 0;
865
1088
                }
866
 
        } else if (c->parent->rate <= rate) {
 
1089
        } else if (parent_rate <= rate) {
867
1090
                c->div = 1;
868
1091
                c->mul = 1;
869
1092
                return 0;
875
1098
        unsigned long rate)
876
1099
{
877
1100
        int divider;
 
1101
        unsigned long parent_rate = clk_get_rate(c->parent);
878
1102
        pr_debug("%s: %s %lu\n", __func__, c->name, rate);
879
1103
 
880
1104
        if (c->flags & DIV_U71) {
881
 
                divider = clk_div71_get_divider(c->parent->rate, rate);
 
1105
                divider = clk_div71_get_divider(parent_rate, rate);
882
1106
                if (divider < 0)
883
1107
                        return divider;
884
1108
 
885
 
                return c->parent->rate * 2 / (divider + 2);
 
1109
                return DIV_ROUND_UP(parent_rate * 2, divider + 2);
886
1110
        } else if (c->flags & DIV_U16) {
887
 
                divider = clk_div16_get_divider(c->parent->rate, rate);
 
1111
                divider = clk_div16_get_divider(parent_rate, rate);
888
1112
                if (divider < 0)
889
1113
                        return divider;
890
 
                return c->parent->rate / (divider + 1);
 
1114
                return DIV_ROUND_UP(parent_rate, divider + 1);
891
1115
        }
892
1116
        return -EINVAL;
893
1117
}
899
1123
        .set_parent             = &tegra2_periph_clk_set_parent,
900
1124
        .set_rate               = &tegra2_periph_clk_set_rate,
901
1125
        .round_rate             = &tegra2_periph_clk_round_rate,
 
1126
        .reset                  = &tegra2_periph_clk_reset,
 
1127
};
 
1128
 
 
1129
/* The SDMMC controllers have extra bits in the clock source register that
 
1130
 * adjust the delay between the clock and data to compenstate for delays
 
1131
 * on the PCB. */
 
1132
void tegra2_sdmmc_tap_delay(struct clk *c, int delay)
 
1133
{
 
1134
        u32 reg;
 
1135
 
 
1136
        delay = clamp(delay, 0, 15);
 
1137
        reg = clk_readl(c->reg);
 
1138
        reg &= ~SDMMC_CLK_INT_FB_DLY_MASK;
 
1139
        reg |= SDMMC_CLK_INT_FB_SEL;
 
1140
        reg |= delay << SDMMC_CLK_INT_FB_DLY_SHIFT;
 
1141
        clk_writel(reg, c->reg);
 
1142
}
 
1143
 
 
1144
/* External memory controller clock ops */
 
1145
static void tegra2_emc_clk_init(struct clk *c)
 
1146
{
 
1147
        tegra2_periph_clk_init(c);
 
1148
        c->max_rate = clk_get_rate_locked(c);
 
1149
}
 
1150
 
 
1151
static long tegra2_emc_clk_round_rate(struct clk *c, unsigned long rate)
 
1152
{
 
1153
        long new_rate = rate;
 
1154
 
 
1155
        new_rate = tegra_emc_round_rate(new_rate);
 
1156
        if (new_rate < 0)
 
1157
                return c->max_rate;
 
1158
 
 
1159
        BUG_ON(new_rate != tegra2_periph_clk_round_rate(c, new_rate));
 
1160
 
 
1161
        return new_rate;
 
1162
}
 
1163
 
 
1164
static int tegra2_emc_clk_set_rate(struct clk *c, unsigned long rate)
 
1165
{
 
1166
        int ret;
 
1167
        /*
 
1168
         * The Tegra2 memory controller has an interlock with the clock
 
1169
         * block that allows memory shadowed registers to be updated,
 
1170
         * and then transfer them to the main registers at the same
 
1171
         * time as the clock update without glitches.
 
1172
         */
 
1173
        ret = tegra_emc_set_rate(rate);
 
1174
        if (ret < 0)
 
1175
                return ret;
 
1176
 
 
1177
        ret = tegra2_periph_clk_set_rate(c, rate);
 
1178
        udelay(1);
 
1179
 
 
1180
        return ret;
 
1181
}
 
1182
 
 
1183
static struct clk_ops tegra_emc_clk_ops = {
 
1184
        .init                   = &tegra2_emc_clk_init,
 
1185
        .enable                 = &tegra2_periph_clk_enable,
 
1186
        .disable                = &tegra2_periph_clk_disable,
 
1187
        .set_parent             = &tegra2_periph_clk_set_parent,
 
1188
        .set_rate               = &tegra2_emc_clk_set_rate,
 
1189
        .round_rate             = &tegra2_emc_clk_round_rate,
 
1190
        .reset                  = &tegra2_periph_clk_reset,
902
1191
};
903
1192
 
904
1193
/* Clock doubler ops */
907
1196
        c->mul = 2;
908
1197
        c->div = 1;
909
1198
        c->state = ON;
 
1199
 
 
1200
        if (!c->u.periph.clk_num)
 
1201
                return;
 
1202
 
910
1203
        if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
911
1204
                        PERIPH_CLK_TO_ENB_BIT(c)))
912
1205
                c->state = OFF;
914
1207
 
915
1208
static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
916
1209
{
917
 
        if (rate != 2 * c->parent->rate)
 
1210
        if (rate != 2 * clk_get_rate(c->parent))
918
1211
                return -EINVAL;
919
1212
        c->mul = 2;
920
1213
        c->div = 1;
928
1221
        .set_rate               = &tegra2_clk_double_set_rate,
929
1222
};
930
1223
 
 
1224
/* Audio sync clock ops */
931
1225
static void tegra2_audio_sync_clk_init(struct clk *c)
932
1226
{
933
1227
        int source;
964
1258
                        val |= sel->value;
965
1259
 
966
1260
                        if (c->refcnt)
967
 
                                clk_enable_locked(p);
 
1261
                                clk_enable(p);
968
1262
 
969
1263
                        clk_writel(val, c->reg);
970
1264
 
971
1265
                        if (c->refcnt && c->parent)
972
 
                                clk_disable_locked(c->parent);
 
1266
                                clk_disable(c->parent);
973
1267
 
974
1268
                        clk_reparent(c, p);
975
1269
                        return 0;
979
1273
        return -EINVAL;
980
1274
}
981
1275
 
982
 
static int tegra2_audio_sync_clk_set_rate(struct clk *c, unsigned long rate)
983
 
{
984
 
        unsigned long parent_rate;
985
 
        if (!c->parent) {
986
 
                pr_err("%s: clock has no parent\n", __func__);
987
 
                return -EINVAL;
988
 
        }
989
 
        parent_rate = c->parent->rate;
990
 
        if (rate != parent_rate) {
991
 
                pr_err("%s: %s/%ld differs from parent %s/%ld\n",
992
 
                        __func__,
993
 
                        c->name, rate,
994
 
                        c->parent->name, parent_rate);
995
 
                return -EINVAL;
996
 
        }
997
 
        c->rate = parent_rate;
998
 
        return 0;
999
 
}
1000
 
 
1001
1276
static struct clk_ops tegra_audio_sync_clk_ops = {
1002
1277
        .init       = tegra2_audio_sync_clk_init,
1003
1278
        .enable     = tegra2_audio_sync_clk_enable,
1004
1279
        .disable    = tegra2_audio_sync_clk_disable,
1005
 
        .set_rate   = tegra2_audio_sync_clk_set_rate,
1006
1280
        .set_parent = tegra2_audio_sync_clk_set_parent,
1007
1281
};
1008
1282
 
 
1283
/* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
 
1284
 
 
1285
static void tegra2_cdev_clk_init(struct clk *c)
 
1286
{
 
1287
        /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
 
1288
         * currently done in the pinmux code. */
 
1289
        c->state = ON;
 
1290
 
 
1291
        BUG_ON(!c->u.periph.clk_num);
 
1292
 
 
1293
        if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
 
1294
                        PERIPH_CLK_TO_ENB_BIT(c)))
 
1295
                c->state = OFF;
 
1296
}
 
1297
 
 
1298
static int tegra2_cdev_clk_enable(struct clk *c)
 
1299
{
 
1300
        BUG_ON(!c->u.periph.clk_num);
 
1301
 
 
1302
        clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
 
1303
                CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
 
1304
        return 0;
 
1305
}
 
1306
 
 
1307
static void tegra2_cdev_clk_disable(struct clk *c)
 
1308
{
 
1309
        BUG_ON(!c->u.periph.clk_num);
 
1310
 
 
1311
        clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
 
1312
                CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
 
1313
}
 
1314
 
 
1315
static struct clk_ops tegra_cdev_clk_ops = {
 
1316
        .init                   = &tegra2_cdev_clk_init,
 
1317
        .enable                 = &tegra2_cdev_clk_enable,
 
1318
        .disable                = &tegra2_cdev_clk_disable,
 
1319
};
 
1320
 
 
1321
/* shared bus ops */
 
1322
/*
 
1323
 * Some clocks may have multiple downstream users that need to request a
 
1324
 * higher clock rate.  Shared bus clocks provide a unique shared_bus_user
 
1325
 * clock to each user.  The frequency of the bus is set to the highest
 
1326
 * enabled shared_bus_user clock, with a minimum value set by the
 
1327
 * shared bus.
 
1328
 */
 
1329
static int tegra_clk_shared_bus_update(struct clk *bus)
 
1330
{
 
1331
        struct clk *c;
 
1332
        unsigned long rate = bus->min_rate;
 
1333
 
 
1334
        list_for_each_entry(c, &bus->shared_bus_list, u.shared_bus_user.node)
 
1335
                if (c->u.shared_bus_user.enabled)
 
1336
                        rate = max(c->u.shared_bus_user.rate, rate);
 
1337
 
 
1338
        if (rate == clk_get_rate_locked(bus))
 
1339
                return 0;
 
1340
 
 
1341
        return clk_set_rate_locked(bus, rate);
 
1342
};
 
1343
 
 
1344
static void tegra_clk_shared_bus_init(struct clk *c)
 
1345
{
 
1346
        unsigned long flags;
 
1347
 
 
1348
        c->max_rate = c->parent->max_rate;
 
1349
        c->u.shared_bus_user.rate = c->parent->max_rate;
 
1350
        c->state = OFF;
 
1351
        c->set = true;
 
1352
 
 
1353
        spin_lock_irqsave(&c->parent->spinlock, flags);
 
1354
 
 
1355
        list_add_tail(&c->u.shared_bus_user.node,
 
1356
                &c->parent->shared_bus_list);
 
1357
 
 
1358
        spin_unlock_irqrestore(&c->parent->spinlock, flags);
 
1359
}
 
1360
 
 
1361
static int tegra_clk_shared_bus_set_rate(struct clk *c, unsigned long rate)
 
1362
{
 
1363
        unsigned long flags;
 
1364
        int ret;
 
1365
 
 
1366
        rate = clk_round_rate(c->parent, rate);
 
1367
        if (rate < 0)
 
1368
                return rate;
 
1369
 
 
1370
        spin_lock_irqsave(&c->parent->spinlock, flags);
 
1371
 
 
1372
        c->u.shared_bus_user.rate = rate;
 
1373
        ret = tegra_clk_shared_bus_update(c->parent);
 
1374
 
 
1375
        spin_unlock_irqrestore(&c->parent->spinlock, flags);
 
1376
 
 
1377
        return ret;
 
1378
}
 
1379
 
 
1380
static long tegra_clk_shared_bus_round_rate(struct clk *c, unsigned long rate)
 
1381
{
 
1382
        return clk_round_rate(c->parent, rate);
 
1383
}
 
1384
 
 
1385
static int tegra_clk_shared_bus_enable(struct clk *c)
 
1386
{
 
1387
        unsigned long flags;
 
1388
        int ret;
 
1389
 
 
1390
        spin_lock_irqsave(&c->parent->spinlock, flags);
 
1391
 
 
1392
        c->u.shared_bus_user.enabled = true;
 
1393
        ret = tegra_clk_shared_bus_update(c->parent);
 
1394
 
 
1395
        spin_unlock_irqrestore(&c->parent->spinlock, flags);
 
1396
 
 
1397
        return ret;
 
1398
}
 
1399
 
 
1400
static void tegra_clk_shared_bus_disable(struct clk *c)
 
1401
{
 
1402
        unsigned long flags;
 
1403
        int ret;
 
1404
 
 
1405
        spin_lock_irqsave(&c->parent->spinlock, flags);
 
1406
 
 
1407
        c->u.shared_bus_user.enabled = false;
 
1408
        ret = tegra_clk_shared_bus_update(c->parent);
 
1409
        WARN_ON_ONCE(ret);
 
1410
 
 
1411
        spin_unlock_irqrestore(&c->parent->spinlock, flags);
 
1412
}
 
1413
 
 
1414
static struct clk_ops tegra_clk_shared_bus_ops = {
 
1415
        .init = tegra_clk_shared_bus_init,
 
1416
        .enable = tegra_clk_shared_bus_enable,
 
1417
        .disable = tegra_clk_shared_bus_disable,
 
1418
        .set_rate = tegra_clk_shared_bus_set_rate,
 
1419
        .round_rate = tegra_clk_shared_bus_round_rate,
 
1420
};
 
1421
 
 
1422
 
1009
1423
/* Clock definitions */
1010
1424
static struct clk tegra_clk_32k = {
1011
1425
        .name = "clk_32k",
1014
1428
        .max_rate = 32768,
1015
1429
};
1016
1430
 
1017
 
static struct clk_pll_table tegra_pll_s_table[] = {
 
1431
static struct clk_pll_freq_table tegra_pll_s_freq_table[] = {
1018
1432
        {32768, 12000000, 366, 1, 1, 0},
1019
1433
        {32768, 13000000, 397, 1, 1, 0},
1020
1434
        {32768, 19200000, 586, 1, 1, 0},
1026
1440
        .name      = "pll_s",
1027
1441
        .flags     = PLL_ALT_MISC_REG,
1028
1442
        .ops       = &tegra_pll_ops,
 
1443
        .parent    = &tegra_clk_32k,
 
1444
        .max_rate  = 26000000,
1029
1445
        .reg       = 0xf0,
1030
 
        .input_min = 32768,
1031
 
        .input_max = 32768,
1032
 
        .parent    = &tegra_clk_32k,
1033
 
        .cf_min    = 0, /* FIXME */
1034
 
        .cf_max    = 0, /* FIXME */
1035
 
        .vco_min   = 12000000,
1036
 
        .vco_max   = 26000000,
1037
 
        .pll_table = tegra_pll_s_table,
1038
 
        .max_rate  = 26000000,
 
1446
        .u.pll = {
 
1447
                .input_min = 32768,
 
1448
                .input_max = 32768,
 
1449
                .cf_min    = 0, /* FIXME */
 
1450
                .cf_max    = 0, /* FIXME */
 
1451
                .vco_min   = 12000000,
 
1452
                .vco_max   = 26000000,
 
1453
                .freq_table = tegra_pll_s_freq_table,
 
1454
                .lock_delay = 300,
 
1455
        },
1039
1456
};
1040
1457
 
1041
1458
static struct clk_mux_sel tegra_clk_m_sel[] = {
1043
1460
        { .input = &tegra_pll_s,  .value = 1},
1044
1461
        { 0, 0},
1045
1462
};
 
1463
 
1046
1464
static struct clk tegra_clk_m = {
1047
1465
        .name      = "clk_m",
1048
1466
        .flags     = ENABLE_ON_INIT,
1049
1467
        .ops       = &tegra_clk_m_ops,
1050
1468
        .inputs    = tegra_clk_m_sel,
1051
1469
        .reg       = 0x1fc,
1052
 
        .reg_mask  = (1<<28),
1053
1470
        .reg_shift = 28,
1054
1471
        .max_rate  = 26000000,
1055
1472
};
1056
1473
 
1057
 
static struct clk_pll_table tegra_pll_c_table[] = {
 
1474
static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
1058
1475
        { 0, 0, 0, 0, 0, 0 },
1059
1476
};
1060
1477
 
1063
1480
        .flags     = PLL_HAS_CPCON,
1064
1481
        .ops       = &tegra_pll_ops,
1065
1482
        .reg       = 0x80,
1066
 
        .input_min = 2000000,
1067
 
        .input_max = 31000000,
1068
1483
        .parent    = &tegra_clk_m,
1069
 
        .cf_min    = 1000000,
1070
 
        .cf_max    = 6000000,
1071
 
        .vco_min   = 20000000,
1072
 
        .vco_max   = 1400000000,
1073
 
        .pll_table = tegra_pll_c_table,
1074
1484
        .max_rate  = 600000000,
 
1485
        .u.pll = {
 
1486
                .input_min = 2000000,
 
1487
                .input_max = 31000000,
 
1488
                .cf_min    = 1000000,
 
1489
                .cf_max    = 6000000,
 
1490
                .vco_min   = 20000000,
 
1491
                .vco_max   = 1400000000,
 
1492
                .freq_table = tegra_pll_c_freq_table,
 
1493
                .lock_delay = 300,
 
1494
        },
1075
1495
};
1076
1496
 
1077
1497
static struct clk tegra_pll_c_out1 = {
1084
1504
        .max_rate  = 600000000,
1085
1505
};
1086
1506
 
1087
 
static struct clk_pll_table tegra_pll_m_table[] = {
 
1507
static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
1088
1508
        { 12000000, 666000000, 666, 12, 1, 8},
1089
1509
        { 13000000, 666000000, 666, 13, 1, 8},
1090
1510
        { 19200000, 666000000, 555, 16, 1, 8},
1101
1521
        .flags     = PLL_HAS_CPCON,
1102
1522
        .ops       = &tegra_pll_ops,
1103
1523
        .reg       = 0x90,
1104
 
        .input_min = 2000000,
1105
 
        .input_max = 31000000,
1106
1524
        .parent    = &tegra_clk_m,
1107
 
        .cf_min    = 1000000,
1108
 
        .cf_max    = 6000000,
1109
 
        .vco_min   = 20000000,
1110
 
        .vco_max   = 1200000000,
1111
 
        .pll_table = tegra_pll_m_table,
1112
1525
        .max_rate  = 800000000,
 
1526
        .u.pll = {
 
1527
                .input_min = 2000000,
 
1528
                .input_max = 31000000,
 
1529
                .cf_min    = 1000000,
 
1530
                .cf_max    = 6000000,
 
1531
                .vco_min   = 20000000,
 
1532
                .vco_max   = 1200000000,
 
1533
                .freq_table = tegra_pll_m_freq_table,
 
1534
                .lock_delay = 300,
 
1535
        },
1113
1536
};
1114
1537
 
1115
1538
static struct clk tegra_pll_m_out1 = {
1122
1545
        .max_rate  = 600000000,
1123
1546
};
1124
1547
 
1125
 
static struct clk_pll_table tegra_pll_p_table[] = {
 
1548
static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
1126
1549
        { 12000000, 216000000, 432, 12, 2, 8},
1127
1550
        { 13000000, 216000000, 432, 13, 2, 8},
1128
1551
        { 19200000, 216000000, 90,   4, 2, 1},
1139
1562
        .flags     = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1140
1563
        .ops       = &tegra_pll_ops,
1141
1564
        .reg       = 0xa0,
1142
 
        .input_min = 2000000,
1143
 
        .input_max = 31000000,
1144
1565
        .parent    = &tegra_clk_m,
1145
 
        .cf_min    = 1000000,
1146
 
        .cf_max    = 6000000,
1147
 
        .vco_min   = 20000000,
1148
 
        .vco_max   = 1400000000,
1149
 
        .pll_table = tegra_pll_p_table,
1150
1566
        .max_rate  = 432000000,
 
1567
        .u.pll = {
 
1568
                .input_min = 2000000,
 
1569
                .input_max = 31000000,
 
1570
                .cf_min    = 1000000,
 
1571
                .cf_max    = 6000000,
 
1572
                .vco_min   = 20000000,
 
1573
                .vco_max   = 1400000000,
 
1574
                .freq_table = tegra_pll_p_freq_table,
 
1575
                .lock_delay = 300,
 
1576
        },
1151
1577
};
1152
1578
 
1153
1579
static struct clk tegra_pll_p_out1 = {
1190
1616
        .max_rate  = 432000000,
1191
1617
};
1192
1618
 
1193
 
static struct clk_pll_table tegra_pll_a_table[] = {
 
1619
static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
1194
1620
        { 28800000, 56448000, 49, 25, 1, 1},
1195
1621
        { 28800000, 73728000, 64, 25, 1, 1},
1196
 
        { 28800000, 11289600, 49, 25, 1, 1},
1197
 
        { 28800000, 12288000, 64, 25, 1, 1},
1198
1622
        { 28800000, 24000000,  5,  6, 1, 1},
1199
1623
        { 0, 0, 0, 0, 0, 0 },
1200
1624
};
1204
1628
        .flags     = PLL_HAS_CPCON,
1205
1629
        .ops       = &tegra_pll_ops,
1206
1630
        .reg       = 0xb0,
1207
 
        .input_min = 2000000,
1208
 
        .input_max = 31000000,
1209
1631
        .parent    = &tegra_pll_p_out1,
1210
 
        .cf_min    = 1000000,
1211
 
        .cf_max    = 6000000,
1212
 
        .vco_min   = 20000000,
1213
 
        .vco_max   = 1400000000,
1214
 
        .pll_table = tegra_pll_a_table,
1215
 
        .max_rate  = 56448000,
 
1632
        .max_rate  = 73728000,
 
1633
        .u.pll = {
 
1634
                .input_min = 2000000,
 
1635
                .input_max = 31000000,
 
1636
                .cf_min    = 1000000,
 
1637
                .cf_max    = 6000000,
 
1638
                .vco_min   = 20000000,
 
1639
                .vco_max   = 1400000000,
 
1640
                .freq_table = tegra_pll_a_freq_table,
 
1641
                .lock_delay = 300,
 
1642
        },
1216
1643
};
1217
1644
 
1218
1645
static struct clk tegra_pll_a_out0 = {
1222
1649
        .parent    = &tegra_pll_a,
1223
1650
        .reg       = 0xb4,
1224
1651
        .reg_shift = 0,
1225
 
        .max_rate  = 56448000,
 
1652
        .max_rate  = 73728000,
1226
1653
};
1227
1654
 
1228
 
static struct clk_pll_table tegra_pll_d_table[] = {
 
1655
static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
 
1656
        { 12000000, 216000000, 216, 12, 1, 4},
 
1657
        { 13000000, 216000000, 216, 13, 1, 4},
 
1658
        { 19200000, 216000000, 135, 12, 1, 3},
 
1659
        { 26000000, 216000000, 216, 26, 1, 4},
 
1660
 
 
1661
        { 12000000, 594000000, 594, 12, 1, 8},
 
1662
        { 13000000, 594000000, 594, 13, 1, 8},
 
1663
        { 19200000, 594000000, 495, 16, 1, 8},
 
1664
        { 26000000, 594000000, 594, 26, 1, 8},
 
1665
 
1229
1666
        { 12000000, 1000000000, 1000, 12, 1, 12},
1230
1667
        { 13000000, 1000000000, 1000, 13, 1, 12},
1231
1668
        { 19200000, 1000000000, 625,  12, 1, 8},
1232
1669
        { 26000000, 1000000000, 1000, 26, 1, 12},
 
1670
 
1233
1671
        { 0, 0, 0, 0, 0, 0 },
1234
1672
};
1235
1673
 
1238
1676
        .flags     = PLL_HAS_CPCON | PLLD,
1239
1677
        .ops       = &tegra_pll_ops,
1240
1678
        .reg       = 0xd0,
1241
 
        .input_min = 2000000,
1242
 
        .input_max = 40000000,
1243
1679
        .parent    = &tegra_clk_m,
1244
 
        .cf_min    = 1000000,
1245
 
        .cf_max    = 6000000,
1246
 
        .vco_min   = 40000000,
1247
 
        .vco_max   = 1000000000,
1248
 
        .pll_table = tegra_pll_d_table,
1249
1680
        .max_rate  = 1000000000,
 
1681
        .u.pll = {
 
1682
                .input_min = 2000000,
 
1683
                .input_max = 40000000,
 
1684
                .cf_min    = 1000000,
 
1685
                .cf_max    = 6000000,
 
1686
                .vco_min   = 40000000,
 
1687
                .vco_max   = 1000000000,
 
1688
                .freq_table = tegra_pll_d_freq_table,
 
1689
                .lock_delay = 1000,
 
1690
        },
1250
1691
};
1251
1692
 
1252
1693
static struct clk tegra_pll_d_out0 = {
1257
1698
        .max_rate  = 500000000,
1258
1699
};
1259
1700
 
1260
 
static struct clk_pll_table tegra_pll_u_table[] = {
 
1701
static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
1261
1702
        { 12000000, 480000000, 960, 12, 2, 0},
1262
1703
        { 13000000, 480000000, 960, 13, 2, 0},
1263
1704
        { 19200000, 480000000, 200, 4,  2, 0},
1270
1711
        .flags     = PLLU,
1271
1712
        .ops       = &tegra_pll_ops,
1272
1713
        .reg       = 0xc0,
1273
 
        .input_min = 2000000,
1274
 
        .input_max = 40000000,
1275
1714
        .parent    = &tegra_clk_m,
1276
 
        .cf_min    = 1000000,
1277
 
        .cf_max    = 6000000,
1278
 
        .vco_min   = 480000000,
1279
 
        .vco_max   = 960000000,
1280
 
        .pll_table = tegra_pll_u_table,
1281
1715
        .max_rate  = 480000000,
 
1716
        .u.pll = {
 
1717
                .input_min = 2000000,
 
1718
                .input_max = 40000000,
 
1719
                .cf_min    = 1000000,
 
1720
                .cf_max    = 6000000,
 
1721
                .vco_min   = 480000000,
 
1722
                .vco_max   = 960000000,
 
1723
                .freq_table = tegra_pll_u_freq_table,
 
1724
                .lock_delay = 1000,
 
1725
        },
1282
1726
};
1283
1727
 
1284
 
static struct clk_pll_table tegra_pll_x_table[] = {
 
1728
static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
1285
1729
        /* 1 GHz */
1286
1730
        { 12000000, 1000000000, 1000, 12, 1, 12},
1287
1731
        { 13000000, 1000000000, 1000, 13, 1, 12},
1307
1751
        { 26000000, 760000000,  760,  26, 1, 12},
1308
1752
 
1309
1753
        /* 608 MHz */
1310
 
        { 12000000, 608000000,  760,  12, 1, 12},
1311
 
        { 13000000, 608000000,  760,  13, 1, 12},
 
1754
        { 12000000, 608000000,  608,  12, 1, 12},
 
1755
        { 13000000, 608000000,  608,  13, 1, 12},
1312
1756
        { 19200000, 608000000,  380,  12, 1, 8},
1313
 
        { 26000000, 608000000,  760,  26, 1, 12},
 
1757
        { 26000000, 608000000,  608,  26, 1, 12},
1314
1758
 
1315
1759
        /* 456 MHz */
1316
1760
        { 12000000, 456000000,  456,  12, 1, 12},
1332
1776
        .flags     = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
1333
1777
        .ops       = &tegra_pllx_ops,
1334
1778
        .reg       = 0xe0,
1335
 
        .input_min = 2000000,
1336
 
        .input_max = 31000000,
1337
1779
        .parent    = &tegra_clk_m,
1338
 
        .cf_min    = 1000000,
1339
 
        .cf_max    = 6000000,
1340
 
        .vco_min   = 20000000,
1341
 
        .vco_max   = 1200000000,
1342
 
        .pll_table = tegra_pll_x_table,
1343
1780
        .max_rate  = 1000000000,
 
1781
        .u.pll = {
 
1782
                .input_min = 2000000,
 
1783
                .input_max = 31000000,
 
1784
                .cf_min    = 1000000,
 
1785
                .cf_max    = 6000000,
 
1786
                .vco_min   = 20000000,
 
1787
                .vco_max   = 1200000000,
 
1788
                .freq_table = tegra_pll_x_freq_table,
 
1789
                .lock_delay = 300,
 
1790
        },
1344
1791
};
1345
1792
 
1346
 
static struct clk_pll_table tegra_pll_e_table[] = {
 
1793
static struct clk_pll_freq_table tegra_pll_e_freq_table[] = {
1347
1794
        { 12000000, 100000000,  200,  24, 1, 0 },
1348
1795
        { 0, 0, 0, 0, 0, 0 },
1349
1796
};
1352
1799
        .name      = "pll_e",
1353
1800
        .flags     = PLL_ALT_MISC_REG,
1354
1801
        .ops       = &tegra_plle_ops,
1355
 
        .input_min = 12000000,
1356
 
        .input_max = 12000000,
 
1802
        .parent    = &tegra_clk_m,
 
1803
        .reg       = 0xe8,
1357
1804
        .max_rate  = 100000000,
1358
 
        .parent    = &tegra_clk_m,
1359
 
        .reg       = 0xe8,
1360
 
        .pll_table = tegra_pll_e_table,
 
1805
        .u.pll = {
 
1806
                .input_min = 12000000,
 
1807
                .input_max = 12000000,
 
1808
                .freq_table = tegra_pll_e_freq_table,
 
1809
        },
1361
1810
};
1362
1811
 
1363
1812
static struct clk tegra_clk_d = {
1364
1813
        .name      = "clk_d",
1365
1814
        .flags     = PERIPH_NO_RESET,
1366
1815
        .ops       = &tegra_clk_double_ops,
1367
 
        .clk_num   = 90,
1368
1816
        .reg       = 0x34,
1369
1817
        .reg_shift = 12,
1370
1818
        .parent    = &tegra_clk_m,
1371
1819
        .max_rate  = 52000000,
 
1820
        .u.periph  = {
 
1821
                .clk_num = 90,
 
1822
        },
 
1823
};
 
1824
 
 
1825
/* dap_mclk1, belongs to the cdev1 pingroup. */
 
1826
static struct clk tegra_clk_cdev1 = {
 
1827
        .name      = "cdev1",
 
1828
        .ops       = &tegra_cdev_clk_ops,
 
1829
        .rate      = 26000000,
 
1830
        .max_rate  = 26000000,
 
1831
        .u.periph  = {
 
1832
                .clk_num = 94,
 
1833
        },
 
1834
};
 
1835
 
 
1836
/* dap_mclk2, belongs to the cdev2 pingroup. */
 
1837
static struct clk tegra_clk_cdev2 = {
 
1838
        .name      = "cdev2",
 
1839
        .ops       = &tegra_cdev_clk_ops,
 
1840
        .rate      = 26000000,
 
1841
        .max_rate  = 26000000,
 
1842
        .u.periph  = {
 
1843
                .clk_num   = 93,
 
1844
        },
1372
1845
};
1373
1846
 
1374
1847
/* initialized before peripheral clocks */
1394
1867
        .name      = "audio",
1395
1868
        .inputs    = mux_audio_sync_clk,
1396
1869
        .reg       = 0x38,
1397
 
        .max_rate  = 24000000,
 
1870
        .max_rate  = 73728000,
1398
1871
        .ops       = &tegra_audio_sync_clk_ops
1399
1872
};
1400
1873
 
1403
1876
        .flags     = PERIPH_NO_RESET,
1404
1877
        .max_rate  = 48000000,
1405
1878
        .ops       = &tegra_clk_double_ops,
1406
 
        .clk_num   = 89,
1407
1879
        .reg       = 0x34,
1408
1880
        .reg_shift = 8,
1409
1881
        .parent    = &tegra_clk_audio,
 
1882
        .u.periph = {
 
1883
                .clk_num = 89,
 
1884
        },
1410
1885
};
1411
1886
 
1412
1887
struct clk_lookup tegra_audio_clk_lookups[] = {
1478
1953
        .inputs = mux_sclk,
1479
1954
        .reg    = 0x28,
1480
1955
        .ops    = &tegra_super_ops,
1481
 
        .max_rate = 600000000,
 
1956
        .max_rate = 240000000,
 
1957
        .min_rate = 120000000,
1482
1958
};
1483
1959
 
1484
1960
static struct clk tegra_clk_virtual_cpu = {
1485
1961
        .name      = "cpu",
1486
1962
        .parent    = &tegra_clk_cclk,
1487
 
        .main      = &tegra_pll_x,
1488
 
        .backup    = &tegra_clk_m,
1489
1963
        .ops       = &tegra_cpu_ops,
1490
1964
        .max_rate  = 1000000000,
1491
 
        .dvfs      = &tegra_dvfs_virtual_cpu_dvfs,
 
1965
        .u.cpu = {
 
1966
                .main      = &tegra_pll_x,
 
1967
                .backup    = &tegra_pll_p,
 
1968
        },
 
1969
};
 
1970
 
 
1971
static struct clk tegra_clk_cop = {
 
1972
        .name      = "cop",
 
1973
        .parent    = &tegra_clk_sclk,
 
1974
        .ops       = &tegra_cop_ops,
 
1975
        .max_rate  = 240000000,
1492
1976
};
1493
1977
 
1494
1978
static struct clk tegra_clk_hclk = {
1508
1992
        .reg            = 0x30,
1509
1993
        .reg_shift      = 0,
1510
1994
        .ops            = &tegra_bus_ops,
1511
 
        .max_rate       = 108000000,
 
1995
        .max_rate       = 120000000,
 
1996
};
 
1997
 
 
1998
static struct clk tegra_clk_blink = {
 
1999
        .name           = "blink",
 
2000
        .parent         = &tegra_clk_32k,
 
2001
        .reg            = 0x40,
 
2002
        .ops            = &tegra_blink_clk_ops,
 
2003
        .max_rate       = 32768,
1512
2004
};
1513
2005
 
1514
2006
static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1587
2079
        { 0, 0},
1588
2080
};
1589
2081
 
 
2082
static struct clk_mux_sel mux_pclk[] = {
 
2083
        { .input = &tegra_clk_pclk, .value = 0},
 
2084
        { 0, 0},
 
2085
};
 
2086
 
 
2087
static struct clk tegra_clk_emc = {
 
2088
        .name = "emc",
 
2089
        .ops = &tegra_emc_clk_ops,
 
2090
        .reg = 0x19c,
 
2091
        .max_rate = 800000000,
 
2092
        .inputs = mux_pllm_pllc_pllp_clkm,
 
2093
        .flags = MUX | DIV_U71 | PERIPH_EMC_ENB,
 
2094
        .u.periph = {
 
2095
                .clk_num = 57,
 
2096
        },
 
2097
};
 
2098
 
1590
2099
#define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
1591
2100
        {                                               \
1592
2101
                .name      = _name,                     \
1595
2104
                        .con_id    = _con,              \
1596
2105
                },                                      \
1597
2106
                .ops       = &tegra_periph_clk_ops,     \
1598
 
                .clk_num   = _clk_num,                  \
1599
2107
                .reg       = _reg,                      \
1600
2108
                .inputs    = _inputs,                   \
1601
2109
                .flags     = _flags,                    \
1602
2110
                .max_rate  = _max,                      \
1603
 
        }
1604
 
 
1605
 
struct clk tegra_periph_clks[] = {
 
2111
                .u.periph = {                           \
 
2112
                        .clk_num   = _clk_num,          \
 
2113
                },                                      \
 
2114
        }
 
2115
 
 
2116
#define SHARED_CLK(_name, _dev, _con, _parent)          \
 
2117
        {                                               \
 
2118
                .name      = _name,                     \
 
2119
                .lookup    = {                          \
 
2120
                        .dev_id    = _dev,              \
 
2121
                        .con_id    = _con,              \
 
2122
                },                                      \
 
2123
                .ops       = &tegra_clk_shared_bus_ops, \
 
2124
                .parent = _parent,                      \
 
2125
        }
 
2126
 
 
2127
struct clk tegra_list_clks[] = {
 
2128
        PERIPH_CLK("apbdma",    "tegra-dma",            NULL,   34,     0,      108000000, mux_pclk,                    0),
1606
2129
        PERIPH_CLK("rtc",       "rtc-tegra",            NULL,   4,      0,      32768,     mux_clk_32k,                 PERIPH_NO_RESET),
1607
2130
        PERIPH_CLK("timer",     "timer",                NULL,   5,      0,      26000000,  mux_clk_m,                   0),
1608
 
        PERIPH_CLK("i2s1",      "i2s.0",                NULL,   11,     0x100,  26000000,  mux_pllaout0_audio2x_pllp_clkm,      MUX | DIV_U71),
1609
 
        PERIPH_CLK("i2s2",      "i2s.1",                NULL,   18,     0x104,  26000000,  mux_pllaout0_audio2x_pllp_clkm,      MUX | DIV_U71),
1610
 
        /* FIXME: spdif has 2 clocks but 1 enable */
 
2131
        PERIPH_CLK("i2s1",      "tegra-i2s.0",          NULL,   11,     0x100,  26000000,  mux_pllaout0_audio2x_pllp_clkm,      MUX | DIV_U71),
 
2132
        PERIPH_CLK("i2s2",      "tegra-i2s.1",          NULL,   18,     0x104,  26000000,  mux_pllaout0_audio2x_pllp_clkm,      MUX | DIV_U71),
1611
2133
        PERIPH_CLK("spdif_out", "spdif_out",            NULL,   10,     0x108,  100000000, mux_pllaout0_audio2x_pllp_clkm,      MUX | DIV_U71),
1612
2134
        PERIPH_CLK("spdif_in",  "spdif_in",             NULL,   10,     0x10c,  100000000, mux_pllp_pllc_pllm,          MUX | DIV_U71),
1613
2135
        PERIPH_CLK("pwm",       "pwm",                  NULL,   17,     0x110,  432000000, mux_pllp_pllc_audio_clkm_clk32,      MUX | DIV_U71),
1620
2142
        PERIPH_CLK("sbc4",      "spi_tegra.3",          NULL,   68,     0x1b4,  160000000, mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71),
1621
2143
        PERIPH_CLK("ide",       "ide",                  NULL,   25,     0x144,  100000000, mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* requires min voltage */
1622
2144
        PERIPH_CLK("ndflash",   "tegra_nand",           NULL,   13,     0x160,  164000000, mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage */
1623
 
        /* FIXME: vfir shares an enable with uartb */
1624
2145
        PERIPH_CLK("vfir",      "vfir",                 NULL,   7,      0x168,  72000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71),
1625
2146
        PERIPH_CLK("sdmmc1",    "sdhci-tegra.0",        NULL,   14,     0x150,  52000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage */
1626
2147
        PERIPH_CLK("sdmmc2",    "sdhci-tegra.1",        NULL,   9,      0x154,  52000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage */
1627
2148
        PERIPH_CLK("sdmmc3",    "sdhci-tegra.2",        NULL,   69,     0x1bc,  52000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage */
1628
 
        PERIPH_CLK("sdmmc4",    "sdhci-tegra.3",        NULL,   15,     0x160,  52000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage */
1629
 
        PERIPH_CLK("vde",       "vde",                  NULL,   61,     0x1c8,  250000000, mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage and process_id */
 
2149
        PERIPH_CLK("sdmmc4",    "sdhci-tegra.3",        NULL,   15,     0x164,  52000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage */
 
2150
        PERIPH_CLK("vcp",       "tegra-avp",            "vcp",  29,     0,      250000000, mux_clk_m,                   0),
 
2151
        PERIPH_CLK("bsea",      "tegra-avp",            "bsea", 62,     0,      250000000, mux_clk_m,                   0),
 
2152
        PERIPH_CLK("bsev",      "tegra-aes",            "bsev", 63,     0,      250000000, mux_clk_m,                   0),
 
2153
        PERIPH_CLK("vde",       "tegra-avp",            "vde",  61,     0x1c8,  250000000, mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* scales with voltage and process_id */
1630
2154
        PERIPH_CLK("csite",     "csite",                NULL,   73,     0x1d4,  144000000, mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71), /* max rate ??? */
1631
2155
        /* FIXME: what is la? */
1632
2156
        PERIPH_CLK("la",        "la",                   NULL,   76,     0x1f8,  26000000,  mux_pllp_pllc_pllm_clkm,     MUX | DIV_U71),
1641
2165
        PERIPH_CLK("i2c2_i2c",  "tegra-i2c.1",          "i2c",  0,      0,      72000000,  mux_pllp_out3,                       0),
1642
2166
        PERIPH_CLK("i2c3_i2c",  "tegra-i2c.2",          "i2c",  0,      0,      72000000,  mux_pllp_out3,                       0),
1643
2167
        PERIPH_CLK("dvc_i2c",   "tegra-i2c.3",          "i2c",  0,      0,      72000000,  mux_pllp_out3,                       0),
1644
 
        PERIPH_CLK("uarta",     "uart.0",               NULL,   6,      0x178,  216000000, mux_pllp_pllc_pllm_clkm,     MUX),
1645
 
        PERIPH_CLK("uartb",     "uart.1",               NULL,   7,      0x17c,  216000000, mux_pllp_pllc_pllm_clkm,     MUX),
1646
 
        PERIPH_CLK("uartc",     "uart.2",               NULL,   55,     0x1a0,  216000000, mux_pllp_pllc_pllm_clkm,     MUX),
1647
 
        PERIPH_CLK("uartd",     "uart.3",               NULL,   65,     0x1c0,  216000000, mux_pllp_pllc_pllm_clkm,     MUX),
1648
 
        PERIPH_CLK("uarte",     "uart.4",               NULL,   66,     0x1c4,  216000000, mux_pllp_pllc_pllm_clkm,     MUX),
 
2168
        PERIPH_CLK("uarta",     "uart.0",               NULL,   6,      0x178,  600000000, mux_pllp_pllc_pllm_clkm,     MUX),
 
2169
        PERIPH_CLK("uartb",     "uart.1",               NULL,   7,      0x17c,  600000000, mux_pllp_pllc_pllm_clkm,     MUX),
 
2170
        PERIPH_CLK("uartc",     "uart.2",               NULL,   55,     0x1a0,  600000000, mux_pllp_pllc_pllm_clkm,     MUX),
 
2171
        PERIPH_CLK("uartd",     "uart.3",               NULL,   65,     0x1c0,  600000000, mux_pllp_pllc_pllm_clkm,     MUX),
 
2172
        PERIPH_CLK("uarte",     "uart.4",               NULL,   66,     0x1c4,  600000000, mux_pllp_pllc_pllm_clkm,     MUX),
1649
2173
        PERIPH_CLK("3d",        "3d",                   NULL,   24,     0x158,  300000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71 | PERIPH_MANUAL_RESET), /* scales with voltage and process_id */
1650
2174
        PERIPH_CLK("2d",        "2d",                   NULL,   21,     0x15c,  300000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71), /* scales with voltage and process_id */
1651
 
        /* FIXME: vi and vi_sensor share an enable */
1652
 
        PERIPH_CLK("vi",        "vi",                   NULL,   20,     0x148,  150000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71), /* scales with voltage and process_id */
1653
 
        PERIPH_CLK("vi_sensor", "vi_sensor",            NULL,   20,     0x1a8,  150000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71 | PERIPH_NO_RESET), /* scales with voltage and process_id */
 
2175
        PERIPH_CLK("vi",        "tegra_camera",         "vi",   20,     0x148,  150000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71), /* scales with voltage and process_id */
 
2176
        PERIPH_CLK("vi_sensor", "tegra_camera",         "vi_sensor",    20,     0x1a8,  150000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71 | PERIPH_NO_RESET), /* scales with voltage and process_id */
1654
2177
        PERIPH_CLK("epp",       "epp",                  NULL,   19,     0x16c,  300000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71), /* scales with voltage and process_id */
1655
2178
        PERIPH_CLK("mpe",       "mpe",                  NULL,   60,     0x170,  250000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71), /* scales with voltage and process_id */
1656
2179
        PERIPH_CLK("host1x",    "host1x",               NULL,   28,     0x180,  166000000, mux_pllm_pllc_pllp_plla,     MUX | DIV_U71), /* scales with voltage and process_id */
1657
 
        /* FIXME: cve and tvo share an enable   */
1658
2180
        PERIPH_CLK("cve",       "cve",                  NULL,   49,     0x140,  250000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* requires min voltage */
1659
2181
        PERIPH_CLK("tvo",       "tvo",                  NULL,   49,     0x188,  250000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* requires min voltage */
1660
 
        PERIPH_CLK("hdmi",      "hdmi",                 NULL,   51,     0x18c,  148500000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* requires min voltage */
 
2182
        PERIPH_CLK("hdmi",      "hdmi",                 NULL,   51,     0x18c,  600000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* requires min voltage */
1661
2183
        PERIPH_CLK("tvdac",     "tvdac",                NULL,   53,     0x194,  250000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* requires min voltage */
1662
 
        PERIPH_CLK("disp1",     "tegrafb.0",            NULL,   27,     0x138,  190000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* scales with voltage and process_id */
1663
 
        PERIPH_CLK("disp2",     "tegrafb.1",            NULL,   26,     0x13c,  190000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* scales with voltage and process_id */
 
2184
        PERIPH_CLK("disp1",     "tegradc.0",            NULL,   27,     0x138,  600000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* scales with voltage and process_id */
 
2185
        PERIPH_CLK("disp2",     "tegradc.1",            NULL,   26,     0x13c,  600000000, mux_pllp_plld_pllc_clkm,     MUX | DIV_U71), /* scales with voltage and process_id */
1664
2186
        PERIPH_CLK("usbd",      "fsl-tegra-udc",        NULL,   22,     0,      480000000, mux_clk_m,                   0), /* requires min voltage */
1665
2187
        PERIPH_CLK("usb2",      "tegra-ehci.1",         NULL,   58,     0,      480000000, mux_clk_m,                   0), /* requires min voltage */
1666
2188
        PERIPH_CLK("usb3",      "tegra-ehci.2",         NULL,   59,     0,      480000000, mux_clk_m,                   0), /* requires min voltage */
1667
 
        PERIPH_CLK("emc",       "emc",                  NULL,   57,     0x19c,  800000000, mux_pllm_pllc_pllp_clkm,     MUX | DIV_U71 | PERIPH_EMC_ENB),
1668
2189
        PERIPH_CLK("dsi",       "dsi",                  NULL,   48,     0,      500000000, mux_plld,                    0), /* scales with voltage */
1669
 
        PERIPH_CLK("csi",       "csi",                  NULL,   52,     0,      72000000,  mux_pllp_out3,               0),
1670
 
        PERIPH_CLK("isp",       "isp",                  NULL,   23,     0,      150000000, mux_clk_m,                   0), /* same frequency as VI */
1671
 
        PERIPH_CLK("csus",      "csus",                 NULL,   92,     0,      150000000, mux_clk_m,                   PERIPH_NO_RESET),
 
2190
        PERIPH_CLK("csi",       "tegra_camera",         "csi",  52,     0,      72000000,  mux_pllp_out3,               0),
 
2191
        PERIPH_CLK("isp",       "tegra_camera",         "isp",  23,     0,      150000000, mux_clk_m,                   0), /* same frequency as VI */
 
2192
        PERIPH_CLK("csus",      "tegra_camera",         "csus", 92,     0,      150000000, mux_clk_m,                   PERIPH_NO_RESET),
1672
2193
        PERIPH_CLK("pex",       NULL,                   "pex",  70,     0,      26000000,  mux_clk_m,                   PERIPH_MANUAL_RESET),
1673
2194
        PERIPH_CLK("afi",       NULL,                   "afi",  72,     0,      26000000,  mux_clk_m,                   PERIPH_MANUAL_RESET),
1674
2195
        PERIPH_CLK("pcie_xclk", NULL,             "pcie_xclk",  74,     0,      26000000,  mux_clk_m,                   PERIPH_MANUAL_RESET),
 
2196
 
 
2197
        SHARED_CLK("avp.sclk",  "tegra-avp",            "sclk", &tegra_clk_sclk),
 
2198
        SHARED_CLK("avp.emc",   "tegra-avp",            "emc",  &tegra_clk_emc),
 
2199
        SHARED_CLK("cpu.emc",   "cpu",                  "emc",  &tegra_clk_emc),
 
2200
        SHARED_CLK("disp1.emc", "tegradc.0",            "emc",  &tegra_clk_emc),
 
2201
        SHARED_CLK("disp2.emc", "tegradc.1",            "emc",  &tegra_clk_emc),
 
2202
        SHARED_CLK("hdmi.emc",  "hdmi",                 "emc",  &tegra_clk_emc),
 
2203
        SHARED_CLK("host.emc",  "tegra_grhost",         "emc",  &tegra_clk_emc),
 
2204
        SHARED_CLK("usbd.emc",  "fsl-tegra-udc",        "emc",  &tegra_clk_emc),
 
2205
        SHARED_CLK("usb1.emc",  "tegra-ehci.0",         "emc",  &tegra_clk_emc),
 
2206
        SHARED_CLK("usb2.emc",  "tegra-ehci.1",         "emc",  &tegra_clk_emc),
 
2207
        SHARED_CLK("usb3.emc",  "tegra-ehci.2",         "emc",  &tegra_clk_emc),
1675
2208
};
1676
2209
 
1677
2210
#define CLK_DUPLICATE(_name, _dev, _con)                \
1693
2226
        CLK_DUPLICATE("uartc",  "tegra_uart.2", NULL),
1694
2227
        CLK_DUPLICATE("uartd",  "tegra_uart.3", NULL),
1695
2228
        CLK_DUPLICATE("uarte",  "tegra_uart.4", NULL),
1696
 
        CLK_DUPLICATE("host1x", "tegrafb.0", "host1x"),
1697
 
        CLK_DUPLICATE("host1x", "tegrafb.1", "host1x"),
 
2229
        CLK_DUPLICATE("usbd", "utmip-pad", NULL),
1698
2230
        CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
 
2231
        CLK_DUPLICATE("usbd", "tegra-otg", NULL),
 
2232
        CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
 
2233
        CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
 
2234
        CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
 
2235
        CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
 
2236
        CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
 
2237
        CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
 
2238
        CLK_DUPLICATE("host1x", "tegra_grhost", "host1x"),
 
2239
        CLK_DUPLICATE("2d", "tegra_grhost", "gr2d"),
 
2240
        CLK_DUPLICATE("3d", "tegra_grhost", "gr3d"),
 
2241
        CLK_DUPLICATE("epp", "tegra_grhost", "epp"),
 
2242
        CLK_DUPLICATE("mpe", "tegra_grhost", "mpe"),
 
2243
        CLK_DUPLICATE("cop", "tegra-avp", "cop"),
 
2244
        CLK_DUPLICATE("vde", "tegra-aes", "vde"),
1699
2245
};
1700
2246
 
1701
2247
#define CLK(dev, con, ck)       \
1705
2251
                .clk = ck,      \
1706
2252
        }
1707
2253
 
1708
 
struct clk_lookup tegra_clk_lookups[] = {
1709
 
        /* external root sources */
1710
 
        CLK(NULL,       "32k_clk",      &tegra_clk_32k),
1711
 
        CLK(NULL,       "pll_s",        &tegra_pll_s),
1712
 
        CLK(NULL,       "clk_m",        &tegra_clk_m),
1713
 
        CLK(NULL,       "pll_m",        &tegra_pll_m),
1714
 
        CLK(NULL,       "pll_m_out1",   &tegra_pll_m_out1),
1715
 
        CLK(NULL,       "pll_c",        &tegra_pll_c),
1716
 
        CLK(NULL,       "pll_c_out1",   &tegra_pll_c_out1),
1717
 
        CLK(NULL,       "pll_p",        &tegra_pll_p),
1718
 
        CLK(NULL,       "pll_p_out1",   &tegra_pll_p_out1),
1719
 
        CLK(NULL,       "pll_p_out2",   &tegra_pll_p_out2),
1720
 
        CLK(NULL,       "pll_p_out3",   &tegra_pll_p_out3),
1721
 
        CLK(NULL,       "pll_p_out4",   &tegra_pll_p_out4),
1722
 
        CLK(NULL,       "pll_a",        &tegra_pll_a),
1723
 
        CLK(NULL,       "pll_a_out0",   &tegra_pll_a_out0),
1724
 
        CLK(NULL,       "pll_d",        &tegra_pll_d),
1725
 
        CLK(NULL,       "pll_d_out0",   &tegra_pll_d_out0),
1726
 
        CLK(NULL,       "pll_u",        &tegra_pll_u),
1727
 
        CLK(NULL,       "pll_x",        &tegra_pll_x),
1728
 
        CLK(NULL,       "pll_e",        &tegra_pll_e),
1729
 
        CLK(NULL,       "cclk",         &tegra_clk_cclk),
1730
 
        CLK(NULL,       "sclk",         &tegra_clk_sclk),
1731
 
        CLK(NULL,       "hclk",         &tegra_clk_hclk),
1732
 
        CLK(NULL,       "pclk",         &tegra_clk_pclk),
1733
 
        CLK(NULL,       "clk_d",        &tegra_clk_d),
1734
 
        CLK(NULL,       "cpu",          &tegra_clk_virtual_cpu),
 
2254
struct clk *tegra_ptr_clks[] = {
 
2255
        &tegra_clk_32k,
 
2256
        &tegra_pll_s,
 
2257
        &tegra_clk_m,
 
2258
        &tegra_pll_m,
 
2259
        &tegra_pll_m_out1,
 
2260
        &tegra_pll_c,
 
2261
        &tegra_pll_c_out1,
 
2262
        &tegra_pll_p,
 
2263
        &tegra_pll_p_out1,
 
2264
        &tegra_pll_p_out2,
 
2265
        &tegra_pll_p_out3,
 
2266
        &tegra_pll_p_out4,
 
2267
        &tegra_pll_a,
 
2268
        &tegra_pll_a_out0,
 
2269
        &tegra_pll_d,
 
2270
        &tegra_pll_d_out0,
 
2271
        &tegra_pll_u,
 
2272
        &tegra_pll_x,
 
2273
        &tegra_pll_e,
 
2274
        &tegra_clk_cclk,
 
2275
        &tegra_clk_sclk,
 
2276
        &tegra_clk_hclk,
 
2277
        &tegra_clk_pclk,
 
2278
        &tegra_clk_d,
 
2279
        &tegra_clk_cdev1,
 
2280
        &tegra_clk_cdev2,
 
2281
        &tegra_clk_virtual_cpu,
 
2282
        &tegra_clk_blink,
 
2283
        &tegra_clk_cop,
 
2284
        &tegra_clk_emc,
1735
2285
};
1736
2286
 
 
2287
static void tegra2_init_one_clock(struct clk *c)
 
2288
{
 
2289
        clk_init(c);
 
2290
        INIT_LIST_HEAD(&c->shared_bus_list);
 
2291
        if (!c->lookup.dev_id && !c->lookup.con_id)
 
2292
                c->lookup.con_id = c->name;
 
2293
        c->lookup.clk = c;
 
2294
        clkdev_add(&c->lookup);
 
2295
}
 
2296
 
1737
2297
void __init tegra2_init_clocks(void)
1738
2298
{
1739
2299
        int i;
1740
 
        struct clk_lookup *cl;
1741
2300
        struct clk *c;
1742
 
        struct clk_duplicate *cd;
1743
 
 
1744
 
        for (i = 0; i < ARRAY_SIZE(tegra_clk_lookups); i++) {
1745
 
                cl = &tegra_clk_lookups[i];
1746
 
                clk_init(cl->clk);
1747
 
                clkdev_add(cl);
1748
 
        }
1749
 
 
1750
 
        for (i = 0; i < ARRAY_SIZE(tegra_periph_clks); i++) {
1751
 
                c = &tegra_periph_clks[i];
1752
 
                cl = &c->lookup;
1753
 
                cl->clk = c;
1754
 
 
1755
 
                clk_init(cl->clk);
1756
 
                clkdev_add(cl);
1757
 
        }
 
2301
 
 
2302
        for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
 
2303
                tegra2_init_one_clock(tegra_ptr_clks[i]);
 
2304
 
 
2305
        for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
 
2306
                tegra2_init_one_clock(&tegra_list_clks[i]);
1758
2307
 
1759
2308
        for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
1760
 
                cd = &tegra_clk_duplicates[i];
1761
 
                c = tegra_get_clock_by_name(cd->name);
1762
 
                if (c) {
1763
 
                        cl = &cd->lookup;
1764
 
                        cl->clk = c;
1765
 
                        clkdev_add(cl);
1766
 
                } else {
 
2309
                c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
 
2310
                if (!c) {
1767
2311
                        pr_err("%s: Unknown duplicate clock %s\n", __func__,
1768
 
                                cd->name);
 
2312
                                tegra_clk_duplicates[i].name);
 
2313
                        continue;
1769
2314
                }
 
2315
 
 
2316
                tegra_clk_duplicates[i].lookup.clk = c;
 
2317
                clkdev_add(&tegra_clk_duplicates[i].lookup);
1770
2318
        }
1771
2319
 
1772
2320
        init_audio_sync_clock_mux();
1774
2322
 
1775
2323
#ifdef CONFIG_PM
1776
2324
static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
1777
 
                           PERIPH_CLK_SOURCE_NUM + 3];
 
2325
                           PERIPH_CLK_SOURCE_NUM + 22];
1778
2326
 
1779
2327
void tegra_clk_suspend(void)
1780
2328
{
1782
2330
        u32 *ctx = clk_rst_suspend;
1783
2331
 
1784
2332
        *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
 
2333
        *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
 
2334
        *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
 
2335
        *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
 
2336
        *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
 
2337
        *ctx++ = clk_readl(tegra_pll_s.reg + PLL_BASE);
 
2338
        *ctx++ = clk_readl(tegra_pll_s.reg + PLL_MISC(&tegra_pll_s));
 
2339
        *ctx++ = clk_readl(tegra_pll_d.reg + PLL_BASE);
 
2340
        *ctx++ = clk_readl(tegra_pll_d.reg + PLL_MISC(&tegra_pll_d));
 
2341
        *ctx++ = clk_readl(tegra_pll_u.reg + PLL_BASE);
 
2342
        *ctx++ = clk_readl(tegra_pll_u.reg + PLL_MISC(&tegra_pll_u));
 
2343
 
 
2344
        *ctx++ = clk_readl(tegra_pll_m_out1.reg);
 
2345
        *ctx++ = clk_readl(tegra_pll_a_out0.reg);
 
2346
        *ctx++ = clk_readl(tegra_pll_c_out1.reg);
 
2347
 
 
2348
        *ctx++ = clk_readl(tegra_clk_cclk.reg);
 
2349
        *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
 
2350
 
 
2351
        *ctx++ = clk_readl(tegra_clk_sclk.reg);
 
2352
        *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
 
2353
        *ctx++ = clk_readl(tegra_clk_pclk.reg);
 
2354
 
 
2355
        *ctx++ = clk_readl(tegra_clk_audio.reg);
1785
2356
 
1786
2357
        for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
1787
2358
                        off += 4) {
1800
2371
 
1801
2372
        *ctx++ = clk_readl(MISC_CLK_ENB);
1802
2373
        *ctx++ = clk_readl(CLK_MASK_ARM);
 
2374
 
 
2375
        BUG_ON(ctx - clk_rst_suspend != ARRAY_SIZE(clk_rst_suspend));
1803
2376
}
1804
2377
 
1805
2378
void tegra_clk_resume(void)
1812
2385
        val |= *ctx++;
1813
2386
        clk_writel(val, OSC_CTRL);
1814
2387
 
 
2388
        clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
 
2389
        clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
 
2390
        clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
 
2391
        clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
 
2392
        clk_writel(*ctx++, tegra_pll_s.reg + PLL_BASE);
 
2393
        clk_writel(*ctx++, tegra_pll_s.reg + PLL_MISC(&tegra_pll_s));
 
2394
        clk_writel(*ctx++, tegra_pll_d.reg + PLL_BASE);
 
2395
        clk_writel(*ctx++, tegra_pll_d.reg + PLL_MISC(&tegra_pll_d));
 
2396
        clk_writel(*ctx++, tegra_pll_u.reg + PLL_BASE);
 
2397
        clk_writel(*ctx++, tegra_pll_u.reg + PLL_MISC(&tegra_pll_u));
 
2398
        udelay(1000);
 
2399
 
 
2400
        clk_writel(*ctx++, tegra_pll_m_out1.reg);
 
2401
        clk_writel(*ctx++, tegra_pll_a_out0.reg);
 
2402
        clk_writel(*ctx++, tegra_pll_c_out1.reg);
 
2403
 
 
2404
        clk_writel(*ctx++, tegra_clk_cclk.reg);
 
2405
        clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
 
2406
 
 
2407
        clk_writel(*ctx++, tegra_clk_sclk.reg);
 
2408
        clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
 
2409
        clk_writel(*ctx++, tegra_clk_pclk.reg);
 
2410
 
 
2411
        clk_writel(*ctx++, tegra_clk_audio.reg);
 
2412
 
1815
2413
        /* enable all clocks before configuring clock sources */
1816
2414
        clk_writel(0xbffffff9ul, CLK_OUT_ENB);
1817
2415
        clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);