123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- /*
- * R8A7740 processor support
- *
- * Copyright (C) 2011 Renesas Solutions Corp.
- * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/io.h>
- #include <linux/sh_clk.h>
- #include <linux/clkdev.h>
- #include <mach/common.h>
- #include <mach/r8a7740.h>
- /*
- * | MDx | XTAL1/EXTAL1 | System | EXTALR |
- * Clock |-------+-----------------+ clock | 32.768 | RCLK
- * Mode | 2/1/0 | src MHz | source | KHz | source
- * -------+-------+-----------------+-----------+--------+----------
- * 0 | 0 0 0 | External 20~50 | XTAL1 | O | EXTALR
- * 1 | 0 0 1 | Crystal 20~30 | XTAL1 | O | EXTALR
- * 2 | 0 1 0 | External 40~50 | XTAL1 / 2 | O | EXTALR
- * 3 | 0 1 1 | Crystal 40~50 | XTAL1 / 2 | O | EXTALR
- * 4 | 1 0 0 | External 20~50 | XTAL1 | x | XTAL1 / 1024
- * 5 | 1 0 1 | Crystal 20~30 | XTAL1 | x | XTAL1 / 1024
- * 6 | 1 1 0 | External 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
- * 7 | 1 1 1 | Crystal 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
- */
- /* CPG registers */
- #define FRQCRA IOMEM(0xe6150000)
- #define FRQCRB IOMEM(0xe6150004)
- #define VCLKCR1 IOMEM(0xE6150008)
- #define VCLKCR2 IOMEM(0xE615000c)
- #define FRQCRC IOMEM(0xe61500e0)
- #define FSIACKCR IOMEM(0xe6150018)
- #define PLLC01CR IOMEM(0xe6150028)
- #define SUBCKCR IOMEM(0xe6150080)
- #define USBCKCR IOMEM(0xe615008c)
- #define MSTPSR0 IOMEM(0xe6150030)
- #define MSTPSR1 IOMEM(0xe6150038)
- #define MSTPSR2 IOMEM(0xe6150040)
- #define MSTPSR3 IOMEM(0xe6150048)
- #define MSTPSR4 IOMEM(0xe615004c)
- #define FSIBCKCR IOMEM(0xe6150090)
- #define HDMICKCR IOMEM(0xe6150094)
- #define SMSTPCR0 IOMEM(0xe6150130)
- #define SMSTPCR1 IOMEM(0xe6150134)
- #define SMSTPCR2 IOMEM(0xe6150138)
- #define SMSTPCR3 IOMEM(0xe615013c)
- #define SMSTPCR4 IOMEM(0xe6150140)
- #define FSIDIVA IOMEM(0xFE1F8000)
- #define FSIDIVB IOMEM(0xFE1F8008)
- /* Fixed 32 KHz root clock from EXTALR pin */
- static struct clk extalr_clk = {
- .rate = 32768,
- };
- /*
- * 25MHz default rate for the EXTAL1 root input clock.
- * If needed, reset this with clk_set_rate() from the platform code.
- */
- static struct clk extal1_clk = {
- .rate = 25000000,
- };
- /*
- * 48MHz default rate for the EXTAL2 root input clock.
- * If needed, reset this with clk_set_rate() from the platform code.
- */
- static struct clk extal2_clk = {
- .rate = 48000000,
- };
- /*
- * 27MHz default rate for the DV_CLKI root input clock.
- * If needed, reset this with clk_set_rate() from the platform code.
- */
- static struct clk dv_clk = {
- .rate = 27000000,
- };
- static unsigned long div_recalc(struct clk *clk)
- {
- return clk->parent->rate / (int)(clk->priv);
- }
- static struct sh_clk_ops div_clk_ops = {
- .recalc = div_recalc,
- };
- /* extal1 / 2 */
- static struct clk extal1_div2_clk = {
- .ops = &div_clk_ops,
- .priv = (void *)2,
- .parent = &extal1_clk,
- };
- /* extal1 / 1024 */
- static struct clk extal1_div1024_clk = {
- .ops = &div_clk_ops,
- .priv = (void *)1024,
- .parent = &extal1_clk,
- };
- /* extal1 / 2 / 1024 */
- static struct clk extal1_div2048_clk = {
- .ops = &div_clk_ops,
- .priv = (void *)1024,
- .parent = &extal1_div2_clk,
- };
- /* extal2 / 2 */
- static struct clk extal2_div2_clk = {
- .ops = &div_clk_ops,
- .priv = (void *)2,
- .parent = &extal2_clk,
- };
- static struct sh_clk_ops followparent_clk_ops = {
- .recalc = followparent_recalc,
- };
- /* Main clock */
- static struct clk system_clk = {
- .ops = &followparent_clk_ops,
- };
- static struct clk system_div2_clk = {
- .ops = &div_clk_ops,
- .priv = (void *)2,
- .parent = &system_clk,
- };
- /* r_clk */
- static struct clk r_clk = {
- .ops = &followparent_clk_ops,
- };
- /* PLLC0/PLLC1 */
- static unsigned long pllc01_recalc(struct clk *clk)
- {
- unsigned long mult = 1;
- if (__raw_readl(PLLC01CR) & (1 << 14))
- mult = ((__raw_readl(clk->enable_reg) >> 24) & 0x7f) + 1;
- return clk->parent->rate * mult;
- }
- static struct sh_clk_ops pllc01_clk_ops = {
- .recalc = pllc01_recalc,
- };
- static struct clk pllc0_clk = {
- .ops = &pllc01_clk_ops,
- .flags = CLK_ENABLE_ON_INIT,
- .parent = &system_clk,
- .enable_reg = (void __iomem *)FRQCRC,
- };
- static struct clk pllc1_clk = {
- .ops = &pllc01_clk_ops,
- .flags = CLK_ENABLE_ON_INIT,
- .parent = &system_div2_clk,
- .enable_reg = (void __iomem *)FRQCRA,
- };
- /* PLLC1 / 2 */
- static struct clk pllc1_div2_clk = {
- .ops = &div_clk_ops,
- .priv = (void *)2,
- .parent = &pllc1_clk,
- };
- /* USB clock */
- /*
- * USBCKCR is controlling usb24 clock
- * bit[7] : parent clock
- * bit[6] : clock divide rate
|