297297#define LOCK_TIMEOUT_NS 100000000
298298#define BCM2835_MAX_FB_RATE 1750000000u
299299
300+ /*
301+ * Names of clocks used within the driver that need to be replaced
302+ * with an external parent's name. This array is in the order that
303+ * the clocks node in the DT references external clocks.
304+ */
305+ static const char * const cprman_parent_names [] = {
306+ "xosc" ,
307+ "dsi0_byte" ,
308+ "dsi0_ddr2" ,
309+ "dsi0_ddr" ,
310+ "dsi1_byte" ,
311+ "dsi1_ddr2" ,
312+ "dsi1_ddr" ,
313+ };
314+
300315struct bcm2835_cprman {
301316 struct device * dev ;
302317 void __iomem * regs ;
303318 spinlock_t regs_lock ; /* spinlock for all clocks */
304- const char * osc_name ;
319+
320+ /*
321+ * Real names of cprman clock parents looked up through
322+ * of_clk_get_parent_name(), which will be used in the
323+ * parent_names[] arrays for clock registration.
324+ */
325+ const char * real_parent_names [ARRAY_SIZE (cprman_parent_names )];
305326
306327 /* Must be last */
307328 struct clk_hw_onecell_data onecell ;
@@ -907,6 +928,9 @@ static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock,
907928 const struct bcm2835_clock_data * data = clock -> data ;
908929 u64 temp ;
909930
931+ if (data -> int_bits == 0 && data -> frac_bits == 0 )
932+ return parent_rate ;
933+
910934 /*
911935 * The divisor is a 12.12 fixed point field, but only some of
912936 * the bits are populated in any given clock.
@@ -930,7 +954,12 @@ static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw,
930954 struct bcm2835_clock * clock = bcm2835_clock_from_hw (hw );
931955 struct bcm2835_cprman * cprman = clock -> cprman ;
932956 const struct bcm2835_clock_data * data = clock -> data ;
933- u32 div = cprman_read (cprman , data -> div_reg );
957+ u32 div ;
958+
959+ if (data -> int_bits == 0 && data -> frac_bits == 0 )
960+ return parent_rate ;
961+
962+ div = cprman_read (cprman , data -> div_reg );
934963
935964 return bcm2835_clock_rate_from_divisor (clock , parent_rate , div );
936965}
@@ -1209,7 +1238,7 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
12091238 memset (& init , 0 , sizeof (init ));
12101239
12111240 /* All of the PLLs derive from the external oscillator. */
1212- init .parent_names = & cprman -> osc_name ;
1241+ init .parent_names = & cprman -> real_parent_names [ 0 ] ;
12131242 init .num_parents = 1 ;
12141243 init .name = data -> name ;
12151244 init .ops = & bcm2835_pll_clk_ops ;
@@ -1295,18 +1324,22 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
12951324 struct bcm2835_clock * clock ;
12961325 struct clk_init_data init ;
12971326 const char * parents [1 << CM_SRC_BITS ];
1298- size_t i ;
1327+ size_t i , j ;
12991328 int ret ;
13001329
13011330 /*
1302- * Replace our "xosc" references with the oscillator's
1303- * actual name.
1331+ * Replace our strings referencing parent clocks with the
1332+ * actual clock-output- name of the parent .
13041333 */
13051334 for (i = 0 ; i < data -> num_mux_parents ; i ++ ) {
1306- if (strcmp (data -> parents [i ], "xosc" ) == 0 )
1307- parents [i ] = cprman -> osc_name ;
1308- else
1309- parents [i ] = data -> parents [i ];
1335+ parents [i ] = data -> parents [i ];
1336+
1337+ for (j = 0 ; j < ARRAY_SIZE (cprman_parent_names ); j ++ ) {
1338+ if (strcmp (parents [i ], cprman_parent_names [j ]) == 0 ) {
1339+ parents [i ] = cprman -> real_parent_names [j ];
1340+ break ;
1341+ }
1342+ }
13101343 }
13111344
13121345 memset (& init , 0 , sizeof (init ));
@@ -1441,6 +1474,47 @@ static const char *const bcm2835_clock_vpu_parents[] = {
14411474 .parents = bcm2835_clock_vpu_parents, \
14421475 __VA_ARGS__)
14431476
1477+ /*
1478+ * DSI parent clocks. The DSI byte/DDR/DDR2 clocks come from the DSI
1479+ * analog PHY. The _inv variants are generated internally to cprman,
1480+ * but we don't use them so they aren't hooked up.
1481+ */
1482+ static const char * const bcm2835_clock_dsi0_parents [] = {
1483+ "gnd" ,
1484+ "xosc" ,
1485+ "testdebug0" ,
1486+ "testdebug1" ,
1487+ "dsi0_ddr" ,
1488+ "dsi0_ddr_inv" ,
1489+ "dsi0_ddr2" ,
1490+ "dsi0_ddr2_inv" ,
1491+ "dsi0_byte" ,
1492+ "dsi0_byte_inv" ,
1493+ };
1494+
1495+ static const char * const bcm2835_clock_dsi1_parents [] = {
1496+ "gnd" ,
1497+ "xosc" ,
1498+ "testdebug0" ,
1499+ "testdebug1" ,
1500+ "dsi1_ddr" ,
1501+ "dsi1_ddr_inv" ,
1502+ "dsi1_ddr2" ,
1503+ "dsi1_ddr2_inv" ,
1504+ "dsi1_byte" ,
1505+ "dsi1_byte_inv" ,
1506+ };
1507+
1508+ #define REGISTER_DSI0_CLK (...) REGISTER_CLK( \
1509+ .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi0_parents), \
1510+ .parents = bcm2835_clock_dsi0_parents, \
1511+ __VA_ARGS__)
1512+
1513+ #define REGISTER_DSI1_CLK (...) REGISTER_CLK( \
1514+ .num_mux_parents = ARRAY_SIZE(bcm2835_clock_dsi1_parents), \
1515+ .parents = bcm2835_clock_dsi1_parents, \
1516+ __VA_ARGS__)
1517+
14441518/*
14451519 * the real definition of all the pll, pll_dividers and clocks
14461520 * these make use of the above REGISTER_* macros
@@ -1904,6 +1978,18 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
19041978 .div_reg = CM_DSI1EDIV ,
19051979 .int_bits = 4 ,
19061980 .frac_bits = 8 ),
1981+ [BCM2835_CLOCK_DSI0P ] = REGISTER_DSI0_CLK (
1982+ .name = "dsi0p" ,
1983+ .ctl_reg = CM_DSI0PCTL ,
1984+ .div_reg = CM_DSI0PDIV ,
1985+ .int_bits = 0 ,
1986+ .frac_bits = 0 ),
1987+ [BCM2835_CLOCK_DSI1P ] = REGISTER_DSI1_CLK (
1988+ .name = "dsi1p" ,
1989+ .ctl_reg = CM_DSI1PCTL ,
1990+ .div_reg = CM_DSI1PDIV ,
1991+ .int_bits = 0 ,
1992+ .frac_bits = 0 ),
19071993
19081994 /* the gates */
19091995
@@ -1962,8 +2048,19 @@ static int bcm2835_clk_probe(struct platform_device *pdev)
19622048 if (IS_ERR (cprman -> regs ))
19632049 return PTR_ERR (cprman -> regs );
19642050
1965- cprman -> osc_name = of_clk_get_parent_name (dev -> of_node , 0 );
1966- if (!cprman -> osc_name )
2051+ memcpy (cprman -> real_parent_names , cprman_parent_names ,
2052+ sizeof (cprman_parent_names ));
2053+ of_clk_parent_fill (dev -> of_node , cprman -> real_parent_names ,
2054+ ARRAY_SIZE (cprman_parent_names ));
2055+
2056+ /*
2057+ * Make sure the external oscillator has been registered.
2058+ *
2059+ * The other (DSI) clocks are not present on older device
2060+ * trees, which we still need to support for backwards
2061+ * compatibility.
2062+ */
2063+ if (!cprman -> real_parent_names [0 ])
19672064 return - ENODEV ;
19682065
19692066 platform_set_drvdata (pdev , cprman );
0 commit comments