summaryrefslogtreecommitdiffstats
path: root/drivers/clk/bcm
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2017-01-17 15:31:57 -0500
committerStephen Boyd <sboyd@codeaurora.org>2017-01-20 19:22:56 -0500
commit3f9195811d8d829556c4cd88d3f9e56a80d5ba60 (patch)
treeba8508034d16a071e54647cff5b54c60ca452d30 /drivers/clk/bcm
parent8a39e9fa578229fd4604266c6ebb1a3a77d7994c (diff)
clk: bcm2835: Add leaf clock measurement support, disabled by default
This proved incredibly useful during debugging of the DSI driver, to see if our clocks were running at rate we requested. Let's leave it here for the next person interacting with clocks on the platform (and so that hopefully we can just hook it up to debugfs some day). Signed-off-by: Eric Anholt <eric@anholt.net> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Diffstat (limited to 'drivers/clk/bcm')
-rw-r--r--drivers/clk/bcm/clk-bcm2835.c144
1 files changed, 119 insertions, 25 deletions
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index 2e7423d8f5bb..025853870619 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -39,6 +39,7 @@
39#include <linux/clk.h> 39#include <linux/clk.h>
40#include <linux/clk/bcm2835.h> 40#include <linux/clk/bcm2835.h>
41#include <linux/debugfs.h> 41#include <linux/debugfs.h>
42#include <linux/delay.h>
42#include <linux/module.h> 43#include <linux/module.h>
43#include <linux/of.h> 44#include <linux/of.h>
44#include <linux/platform_device.h> 45#include <linux/platform_device.h>
@@ -98,7 +99,8 @@
98#define CM_SMIDIV 0x0b4 99#define CM_SMIDIV 0x0b4
99/* no definition for 0x0b8 and 0x0bc */ 100/* no definition for 0x0b8 and 0x0bc */
100#define CM_TCNTCTL 0x0c0 101#define CM_TCNTCTL 0x0c0
101#define CM_TCNTDIV 0x0c4 102# define CM_TCNT_SRC1_SHIFT 12
103#define CM_TCNTCNT 0x0c4
102#define CM_TECCTL 0x0c8 104#define CM_TECCTL 0x0c8
103#define CM_TECDIV 0x0cc 105#define CM_TECDIV 0x0cc
104#define CM_TD0CTL 0x0d0 106#define CM_TD0CTL 0x0d0
@@ -338,6 +340,61 @@ static inline u32 cprman_read(struct bcm2835_cprman *cprman, u32 reg)
338 return readl(cprman->regs + reg); 340 return readl(cprman->regs + reg);
339} 341}
340 342
343/* Does a cycle of measuring a clock through the TCNT clock, which may
344 * source from many other clocks in the system.
345 */
346static unsigned long bcm2835_measure_tcnt_mux(struct bcm2835_cprman *cprman,
347 u32 tcnt_mux)
348{
349 u32 osccount = 19200; /* 1ms */
350 u32 count;
351 ktime_t timeout;
352
353 spin_lock(&cprman->regs_lock);
354
355 cprman_write(cprman, CM_TCNTCTL, CM_KILL);
356
357 cprman_write(cprman, CM_TCNTCTL,
358 (tcnt_mux & CM_SRC_MASK) |
359 (tcnt_mux >> CM_SRC_BITS) << CM_TCNT_SRC1_SHIFT);
360
361 cprman_write(cprman, CM_OSCCOUNT, osccount);
362
363 /* do a kind delay at the start */
364 mdelay(1);
365
366 /* Finish off whatever is left of OSCCOUNT */
367 timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
368 while (cprman_read(cprman, CM_OSCCOUNT)) {
369 if (ktime_after(ktime_get(), timeout)) {
370 dev_err(cprman->dev, "timeout waiting for OSCCOUNT\n");
371 count = 0;
372 goto out;
373 }
374 cpu_relax();
375 }
376
377 /* Wait for BUSY to clear. */
378 timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
379 while (cprman_read(cprman, CM_TCNTCTL) & CM_BUSY) {
380 if (ktime_after(ktime_get(), timeout)) {
381 dev_err(cprman->dev, "timeout waiting for !BUSY\n");
382 count = 0;
383 goto out;
384 }
385 cpu_relax();
386 }
387
388 count = cprman_read(cprman, CM_TCNTCNT);
389
390 cprman_write(cprman, CM_TCNTCTL, 0);
391
392out:
393 spin_unlock(&cprman->regs_lock);
394
395 return count * 1000;
396}
397
341static int bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base, 398static int bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base,
342 struct debugfs_reg32 *regs, size_t nregs, 399 struct debugfs_reg32 *regs, size_t nregs,
343 struct dentry *dentry) 400 struct dentry *dentry)
@@ -473,6 +530,8 @@ struct bcm2835_clock_data {
473 530
474 bool is_vpu_clock; 531 bool is_vpu_clock;
475 bool is_mash_clock; 532 bool is_mash_clock;
533
534 u32 tcnt_mux;
476}; 535};
477 536
478struct bcm2835_gate_data { 537struct bcm2835_gate_data {
@@ -1008,6 +1067,17 @@ static int bcm2835_clock_on(struct clk_hw *hw)
1008 CM_GATE); 1067 CM_GATE);
1009 spin_unlock(&cprman->regs_lock); 1068 spin_unlock(&cprman->regs_lock);
1010 1069
1070 /* Debug code to measure the clock once it's turned on to see
1071 * if it's ticking at the rate we expect.
1072 */
1073 if (data->tcnt_mux && false) {
1074 dev_info(cprman->dev,
1075 "clk %s: rate %ld, measure %ld\n",
1076 data->name,
1077 clk_hw_get_rate(hw),
1078 bcm2835_measure_tcnt_mux(cprman, data->tcnt_mux));
1079 }
1080
1011 return 0; 1081 return 0;
1012} 1082}
1013 1083
@@ -1765,7 +1835,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1765 .ctl_reg = CM_OTPCTL, 1835 .ctl_reg = CM_OTPCTL,
1766 .div_reg = CM_OTPDIV, 1836 .div_reg = CM_OTPDIV,
1767 .int_bits = 4, 1837 .int_bits = 4,
1768 .frac_bits = 0), 1838 .frac_bits = 0,
1839 .tcnt_mux = 6),
1769 /* 1840 /*
1770 * Used for a 1Mhz clock for the system clocksource, and also used 1841 * Used for a 1Mhz clock for the system clocksource, and also used
1771 * bythe watchdog timer and the camera pulse generator. 1842 * bythe watchdog timer and the camera pulse generator.
@@ -1799,13 +1870,15 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1799 .ctl_reg = CM_H264CTL, 1870 .ctl_reg = CM_H264CTL,
1800 .div_reg = CM_H264DIV, 1871 .div_reg = CM_H264DIV,
1801 .int_bits = 4, 1872 .int_bits = 4,
1802 .frac_bits = 8), 1873 .frac_bits = 8,
1874 .tcnt_mux = 1),
1803 [BCM2835_CLOCK_ISP] = REGISTER_VPU_CLK( 1875 [BCM2835_CLOCK_ISP] = REGISTER_VPU_CLK(
1804 .name = "isp", 1876 .name = "isp",
1805 .ctl_reg = CM_ISPCTL, 1877 .ctl_reg = CM_ISPCTL,
1806 .div_reg = CM_ISPDIV, 1878 .div_reg = CM_ISPDIV,
1807 .int_bits = 4, 1879 .int_bits = 4,
1808 .frac_bits = 8), 1880 .frac_bits = 8,
1881 .tcnt_mux = 2),
1809 1882
1810 /* 1883 /*
1811 * Secondary SDRAM clock. Used for low-voltage modes when the PLL 1884 * Secondary SDRAM clock. Used for low-voltage modes when the PLL
@@ -1816,13 +1889,15 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1816 .ctl_reg = CM_SDCCTL, 1889 .ctl_reg = CM_SDCCTL,
1817 .div_reg = CM_SDCDIV, 1890 .div_reg = CM_SDCDIV,
1818 .int_bits = 6, 1891 .int_bits = 6,
1819 .frac_bits = 0), 1892 .frac_bits = 0,
1893 .tcnt_mux = 3),
1820 [BCM2835_CLOCK_V3D] = REGISTER_VPU_CLK( 1894 [BCM2835_CLOCK_V3D] = REGISTER_VPU_CLK(
1821 .name = "v3d", 1895 .name = "v3d",
1822 .ctl_reg = CM_V3DCTL, 1896 .ctl_reg = CM_V3DCTL,
1823 .div_reg = CM_V3DDIV, 1897 .div_reg = CM_V3DDIV,
1824 .int_bits = 4, 1898 .int_bits = 4,
1825 .frac_bits = 8), 1899 .frac_bits = 8,
1900 .tcnt_mux = 4),
1826 /* 1901 /*
1827 * VPU clock. This doesn't have an enable bit, since it drives 1902 * VPU clock. This doesn't have an enable bit, since it drives
1828 * the bus for everything else, and is special so it doesn't need 1903 * the bus for everything else, and is special so it doesn't need
@@ -1836,7 +1911,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1836 .int_bits = 12, 1911 .int_bits = 12,
1837 .frac_bits = 8, 1912 .frac_bits = 8,
1838 .flags = CLK_IS_CRITICAL, 1913 .flags = CLK_IS_CRITICAL,
1839 .is_vpu_clock = true), 1914 .is_vpu_clock = true,
1915 .tcnt_mux = 5),
1840 1916
1841 /* clocks with per parent mux */ 1917 /* clocks with per parent mux */
1842 [BCM2835_CLOCK_AVEO] = REGISTER_PER_CLK( 1918 [BCM2835_CLOCK_AVEO] = REGISTER_PER_CLK(
@@ -1844,19 +1920,22 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1844 .ctl_reg = CM_AVEOCTL, 1920 .ctl_reg = CM_AVEOCTL,
1845 .div_reg = CM_AVEODIV, 1921 .div_reg = CM_AVEODIV,
1846 .int_bits = 4, 1922 .int_bits = 4,
1847 .frac_bits = 0), 1923 .frac_bits = 0,
1924 .tcnt_mux = 38),
1848 [BCM2835_CLOCK_CAM0] = REGISTER_PER_CLK( 1925 [BCM2835_CLOCK_CAM0] = REGISTER_PER_CLK(
1849 .name = "cam0", 1926 .name = "cam0",
1850 .ctl_reg = CM_CAM0CTL, 1927 .ctl_reg = CM_CAM0CTL,
1851 .div_reg = CM_CAM0DIV, 1928 .div_reg = CM_CAM0DIV,
1852 .int_bits = 4, 1929 .int_bits = 4,
1853 .frac_bits = 8), 1930 .frac_bits = 8,
1931 .tcnt_mux = 14),
1854 [BCM2835_CLOCK_CAM1] = REGISTER_PER_CLK( 1932 [BCM2835_CLOCK_CAM1] = REGISTER_PER_CLK(
1855 .name = "cam1", 1933 .name = "cam1",
1856 .ctl_reg = CM_CAM1CTL, 1934 .ctl_reg = CM_CAM1CTL,
1857 .div_reg = CM_CAM1DIV, 1935 .div_reg = CM_CAM1DIV,
1858 .int_bits = 4, 1936 .int_bits = 4,
1859 .frac_bits = 8), 1937 .frac_bits = 8,
1938 .tcnt_mux = 15),
1860 [BCM2835_CLOCK_DFT] = REGISTER_PER_CLK( 1939 [BCM2835_CLOCK_DFT] = REGISTER_PER_CLK(
1861 .name = "dft", 1940 .name = "dft",
1862 .ctl_reg = CM_DFTCTL, 1941 .ctl_reg = CM_DFTCTL,
@@ -1868,7 +1947,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1868 .ctl_reg = CM_DPICTL, 1947 .ctl_reg = CM_DPICTL,
1869 .div_reg = CM_DPIDIV, 1948 .div_reg = CM_DPIDIV,
1870 .int_bits = 4, 1949 .int_bits = 4,
1871 .frac_bits = 8), 1950 .frac_bits = 8,
1951 .tcnt_mux = 17),
1872 1952
1873 /* Arasan EMMC clock */ 1953 /* Arasan EMMC clock */
1874 [BCM2835_CLOCK_EMMC] = REGISTER_PER_CLK( 1954 [BCM2835_CLOCK_EMMC] = REGISTER_PER_CLK(
@@ -1876,7 +1956,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1876 .ctl_reg = CM_EMMCCTL, 1956 .ctl_reg = CM_EMMCCTL,
1877 .div_reg = CM_EMMCDIV, 1957 .div_reg = CM_EMMCDIV,
1878 .int_bits = 4, 1958 .int_bits = 4,
1879 .frac_bits = 8), 1959 .frac_bits = 8,
1960 .tcnt_mux = 39),
1880 1961
1881 /* General purpose (GPIO) clocks */ 1962 /* General purpose (GPIO) clocks */
1882 [BCM2835_CLOCK_GP0] = REGISTER_PER_CLK( 1963 [BCM2835_CLOCK_GP0] = REGISTER_PER_CLK(
@@ -1885,7 +1966,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1885 .div_reg = CM_GP0DIV, 1966 .div_reg = CM_GP0DIV,
1886 .int_bits = 12, 1967 .int_bits = 12,
1887 .frac_bits = 12, 1968 .frac_bits = 12,
1888 .is_mash_clock = true), 1969 .is_mash_clock = true,
1970 .tcnt_mux = 20),
1889 [BCM2835_CLOCK_GP1] = REGISTER_PER_CLK( 1971 [BCM2835_CLOCK_GP1] = REGISTER_PER_CLK(
1890 .name = "gp1", 1972 .name = "gp1",
1891 .ctl_reg = CM_GP1CTL, 1973 .ctl_reg = CM_GP1CTL,
@@ -1893,7 +1975,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1893 .int_bits = 12, 1975 .int_bits = 12,
1894 .frac_bits = 12, 1976 .frac_bits = 12,
1895 .flags = CLK_IS_CRITICAL, 1977 .flags = CLK_IS_CRITICAL,
1896 .is_mash_clock = true), 1978 .is_mash_clock = true,
1979 .tcnt_mux = 21),
1897 [BCM2835_CLOCK_GP2] = REGISTER_PER_CLK( 1980 [BCM2835_CLOCK_GP2] = REGISTER_PER_CLK(
1898 .name = "gp2", 1981 .name = "gp2",
1899 .ctl_reg = CM_GP2CTL, 1982 .ctl_reg = CM_GP2CTL,
@@ -1908,40 +1991,46 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1908 .ctl_reg = CM_HSMCTL, 1991 .ctl_reg = CM_HSMCTL,
1909 .div_reg = CM_HSMDIV, 1992 .div_reg = CM_HSMDIV,
1910 .int_bits = 4, 1993 .int_bits = 4,
1911 .frac_bits = 8), 1994 .frac_bits = 8,
1995 .tcnt_mux = 22),
1912 [BCM2835_CLOCK_PCM] = REGISTER_PER_CLK( 1996 [BCM2835_CLOCK_PCM] = REGISTER_PER_CLK(
1913 .name = "pcm", 1997 .name = "pcm",
1914 .ctl_reg = CM_PCMCTL, 1998 .ctl_reg = CM_PCMCTL,
1915 .div_reg = CM_PCMDIV, 1999 .div_reg = CM_PCMDIV,
1916 .int_bits = 12, 2000 .int_bits = 12,
1917 .frac_bits = 12, 2001 .frac_bits = 12,
1918 .is_mash_clock = true), 2002 .is_mash_clock = true,
2003 .tcnt_mux = 23),
1919 [BCM2835_CLOCK_PWM] = REGISTER_PER_CLK( 2004 [BCM2835_CLOCK_PWM] = REGISTER_PER_CLK(
1920 .name = "pwm", 2005 .name = "pwm",
1921 .ctl_reg = CM_PWMCTL, 2006 .ctl_reg = CM_PWMCTL,
1922 .div_reg = CM_PWMDIV, 2007 .div_reg = CM_PWMDIV,
1923 .int_bits = 12, 2008 .int_bits = 12,
1924 .frac_bits = 12, 2009 .frac_bits = 12,
1925 .is_mash_clock = true), 2010 .is_mash_clock = true,
2011 .tcnt_mux = 24),
1926 [BCM2835_CLOCK_SLIM] = REGISTER_PER_CLK( 2012 [BCM2835_CLOCK_SLIM] = REGISTER_PER_CLK(
1927 .name = "slim", 2013 .name = "slim",
1928 .ctl_reg = CM_SLIMCTL, 2014 .ctl_reg = CM_SLIMCTL,
1929 .div_reg = CM_SLIMDIV, 2015 .div_reg = CM_SLIMDIV,
1930 .int_bits = 12, 2016 .int_bits = 12,
1931 .frac_bits = 12, 2017 .frac_bits = 12,
1932 .is_mash_clock = true), 2018 .is_mash_clock = true,
2019 .tcnt_mux = 25),
1933 [BCM2835_CLOCK_SMI] = REGISTER_PER_CLK( 2020 [BCM2835_CLOCK_SMI] = REGISTER_PER_CLK(
1934 .name = "smi", 2021 .name = "smi",
1935 .ctl_reg = CM_SMICTL, 2022 .ctl_reg = CM_SMICTL,
1936 .div_reg = CM_SMIDIV, 2023 .div_reg = CM_SMIDIV,
1937 .int_bits = 4, 2024 .int_bits = 4,
1938 .frac_bits = 8), 2025 .frac_bits = 8,
2026 .tcnt_mux = 27),
1939 [BCM2835_CLOCK_UART] = REGISTER_PER_CLK( 2027 [BCM2835_CLOCK_UART] = REGISTER_PER_CLK(
1940 .name = "uart", 2028 .name = "uart",
1941 .ctl_reg = CM_UARTCTL, 2029 .ctl_reg = CM_UARTCTL,
1942 .div_reg = CM_UARTDIV, 2030 .div_reg = CM_UARTDIV,
1943 .int_bits = 10, 2031 .int_bits = 10,
1944 .frac_bits = 12), 2032 .frac_bits = 12,
2033 .tcnt_mux = 28),
1945 2034
1946 /* TV encoder clock. Only operating frequency is 108Mhz. */ 2035 /* TV encoder clock. Only operating frequency is 108Mhz. */
1947 [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK( 2036 [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK(
@@ -1954,7 +2043,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1954 * Allow rate change propagation only on PLLH_AUX which is 2043 * Allow rate change propagation only on PLLH_AUX which is
1955 * assigned index 7 in the parent array. 2044 * assigned index 7 in the parent array.
1956 */ 2045 */
1957 .set_rate_parent = BIT(7)), 2046 .set_rate_parent = BIT(7),
2047 .tcnt_mux = 29),
1958 2048
1959 /* dsi clocks */ 2049 /* dsi clocks */
1960 [BCM2835_CLOCK_DSI0E] = REGISTER_PER_CLK( 2050 [BCM2835_CLOCK_DSI0E] = REGISTER_PER_CLK(
@@ -1962,25 +2052,29 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
1962 .ctl_reg = CM_DSI0ECTL, 2052 .ctl_reg = CM_DSI0ECTL,
1963 .div_reg = CM_DSI0EDIV, 2053 .div_reg = CM_DSI0EDIV,
1964 .int_bits = 4, 2054 .int_bits = 4,
1965 .frac_bits = 8), 2055 .frac_bits = 8,
2056 .tcnt_mux = 18),
1966 [BCM2835_CLOCK_DSI1E] = REGISTER_PER_CLK( 2057 [BCM2835_CLOCK_DSI1E] = REGISTER_PER_CLK(
1967 .name = "dsi1e", 2058 .name = "dsi1e",
1968 .ctl_reg = CM_DSI1ECTL, 2059 .ctl_reg = CM_DSI1ECTL,
1969 .div_reg = CM_DSI1EDIV, 2060 .div_reg = CM_DSI1EDIV,
1970 .int_bits = 4, 2061 .int_bits = 4,
1971 .frac_bits = 8), 2062 .frac_bits = 8,
2063 .tcnt_mux = 19),
1972 [BCM2835_CLOCK_DSI0P] = REGISTER_DSI0_CLK( 2064 [BCM2835_CLOCK_DSI0P] = REGISTER_DSI0_CLK(
1973 .name = "dsi0p", 2065 .name = "dsi0p",
1974 .ctl_reg = CM_DSI0PCTL, 2066 .ctl_reg = CM_DSI0PCTL,
1975 .div_reg = CM_DSI0PDIV, 2067 .div_reg = CM_DSI0PDIV,
1976 .int_bits = 0, 2068 .int_bits = 0,
1977 .frac_bits = 0), 2069 .frac_bits = 0,
2070 .tcnt_mux = 12),
1978 [BCM2835_CLOCK_DSI1P] = REGISTER_DSI1_CLK( 2071 [BCM2835_CLOCK_DSI1P] = REGISTER_DSI1_CLK(
1979 .name = "dsi1p", 2072 .name = "dsi1p",
1980 .ctl_reg = CM_DSI1PCTL, 2073 .ctl_reg = CM_DSI1PCTL,
1981 .div_reg = CM_DSI1PDIV, 2074 .div_reg = CM_DSI1PDIV,
1982 .int_bits = 0, 2075 .int_bits = 0,
1983 .frac_bits = 0), 2076 .frac_bits = 0,
2077 .tcnt_mux = 13),
1984 2078
1985 /* the gates */ 2079 /* the gates */
1986 2080