52
52
#define PLL_CONFIG_CTL_U1 (p ) ((p)->offset + (p)->regs[PLL_OFF_CONFIG_CTL_U1])
53
53
#define PLL_TEST_CTL (p ) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL])
54
54
#define PLL_TEST_CTL_U (p ) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U])
55
+ #define PLL_TEST_CTL_U1 (p ) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U1])
55
56
#define PLL_STATUS (p ) ((p)->offset + (p)->regs[PLL_OFF_STATUS])
56
57
#define PLL_OPMODE (p ) ((p)->offset + (p)->regs[PLL_OFF_OPMODE])
57
58
#define PLL_FRAC (p ) ((p)->offset + (p)->regs[PLL_OFF_FRAC])
@@ -116,6 +117,22 @@ const u8 clk_alpha_pll_regs[][PLL_OFF_MAX_REGS] = {
116
117
[PLL_OFF_ALPHA_VAL ] = 0x40 ,
117
118
[PLL_OFF_CAL_VAL ] = 0x44 ,
118
119
},
120
+ [CLK_ALPHA_PLL_TYPE_LUCID ] = {
121
+ [PLL_OFF_L_VAL ] = 0x04 ,
122
+ [PLL_OFF_CAL_L_VAL ] = 0x08 ,
123
+ [PLL_OFF_USER_CTL ] = 0x0c ,
124
+ [PLL_OFF_USER_CTL_U ] = 0x10 ,
125
+ [PLL_OFF_USER_CTL_U1 ] = 0x14 ,
126
+ [PLL_OFF_CONFIG_CTL ] = 0x18 ,
127
+ [PLL_OFF_CONFIG_CTL_U ] = 0x1c ,
128
+ [PLL_OFF_CONFIG_CTL_U1 ] = 0x20 ,
129
+ [PLL_OFF_TEST_CTL ] = 0x24 ,
130
+ [PLL_OFF_TEST_CTL_U ] = 0x28 ,
131
+ [PLL_OFF_TEST_CTL_U1 ] = 0x2c ,
132
+ [PLL_OFF_STATUS ] = 0x30 ,
133
+ [PLL_OFF_OPMODE ] = 0x38 ,
134
+ [PLL_OFF_ALPHA_VAL ] = 0x40 ,
135
+ },
119
136
};
120
137
EXPORT_SYMBOL_GPL (clk_alpha_pll_regs );
121
138
@@ -139,6 +156,10 @@ EXPORT_SYMBOL_GPL(clk_alpha_pll_regs);
139
156
#define PLL_OUT_MASK 0x7
140
157
#define PLL_RATE_MARGIN 500
141
158
159
+ /* LUCID PLL specific settings and offsets */
160
+ #define LUCID_PLL_CAL_VAL 0x44
161
+ #define LUCID_PCAL_DONE BIT(26)
162
+
142
163
#define pll_alpha_width (p ) \
143
164
((PLL_ALPHA_VAL_U(p) - PLL_ALPHA_VAL(p) == 4) ? \
144
165
ALPHA_REG_BITWIDTH : ALPHA_REG_16BIT_WIDTH)
@@ -1370,3 +1391,175 @@ const struct clk_ops clk_alpha_pll_postdiv_fabia_ops = {
1370
1391
.set_rate = clk_alpha_pll_postdiv_fabia_set_rate ,
1371
1392
};
1372
1393
EXPORT_SYMBOL_GPL (clk_alpha_pll_postdiv_fabia_ops );
1394
+
1395
+ /**
1396
+ * clk_lucid_pll_configure - configure the lucid pll
1397
+ *
1398
+ * @pll: clk alpha pll
1399
+ * @regmap: register map
1400
+ * @config: configuration to apply for pll
1401
+ */
1402
+ void clk_lucid_pll_configure (struct clk_alpha_pll * pll , struct regmap * regmap ,
1403
+ const struct alpha_pll_config * config )
1404
+ {
1405
+ if (config -> l )
1406
+ regmap_write (regmap , PLL_L_VAL (pll ), config -> l );
1407
+
1408
+ regmap_write (regmap , PLL_CAL_L_VAL (pll ), LUCID_PLL_CAL_VAL );
1409
+
1410
+ if (config -> alpha )
1411
+ regmap_write (regmap , PLL_ALPHA_VAL (pll ), config -> alpha );
1412
+
1413
+ if (config -> config_ctl_val )
1414
+ regmap_write (regmap , PLL_CONFIG_CTL (pll ),
1415
+ config -> config_ctl_val );
1416
+
1417
+ if (config -> config_ctl_hi_val )
1418
+ regmap_write (regmap , PLL_CONFIG_CTL_U (pll ),
1419
+ config -> config_ctl_hi_val );
1420
+
1421
+ if (config -> config_ctl_hi1_val )
1422
+ regmap_write (regmap , PLL_CONFIG_CTL_U1 (pll ),
1423
+ config -> config_ctl_hi1_val );
1424
+
1425
+ if (config -> user_ctl_val )
1426
+ regmap_write (regmap , PLL_USER_CTL (pll ),
1427
+ config -> user_ctl_val );
1428
+
1429
+ if (config -> user_ctl_hi_val )
1430
+ regmap_write (regmap , PLL_USER_CTL_U (pll ),
1431
+ config -> user_ctl_hi_val );
1432
+
1433
+ if (config -> user_ctl_hi1_val )
1434
+ regmap_write (regmap , PLL_USER_CTL_U1 (pll ),
1435
+ config -> user_ctl_hi1_val );
1436
+
1437
+ if (config -> test_ctl_val )
1438
+ regmap_write (regmap , PLL_TEST_CTL (pll ),
1439
+ config -> test_ctl_val );
1440
+
1441
+ if (config -> test_ctl_hi_val )
1442
+ regmap_write (regmap , PLL_TEST_CTL_U (pll ),
1443
+ config -> test_ctl_hi_val );
1444
+
1445
+ if (config -> test_ctl_hi1_val )
1446
+ regmap_write (regmap , PLL_TEST_CTL_U1 (pll ),
1447
+ config -> test_ctl_hi1_val );
1448
+
1449
+ regmap_update_bits (regmap , PLL_MODE (pll ), PLL_UPDATE_BYPASS ,
1450
+ PLL_UPDATE_BYPASS );
1451
+
1452
+ /* Disable PLL output */
1453
+ regmap_update_bits (regmap , PLL_MODE (pll ), PLL_OUTCTRL , 0 );
1454
+
1455
+ /* Set operation mode to OFF */
1456
+ regmap_write (regmap , PLL_OPMODE (pll ), PLL_STANDBY );
1457
+
1458
+ /* Place the PLL in STANDBY mode */
1459
+ regmap_update_bits (regmap , PLL_MODE (pll ), PLL_RESET_N , PLL_RESET_N );
1460
+ }
1461
+ EXPORT_SYMBOL_GPL (clk_lucid_pll_configure );
1462
+
1463
+ /*
1464
+ * The Lucid PLL requires a power-on self-calibration which happens when the
1465
+ * PLL comes out of reset. Calibrate in case it is not completed.
1466
+ */
1467
+ static int alpha_pll_lucid_prepare (struct clk_hw * hw )
1468
+ {
1469
+ struct clk_alpha_pll * pll = to_clk_alpha_pll (hw );
1470
+ u32 regval ;
1471
+ int ret ;
1472
+
1473
+ /* Return early if calibration is not needed. */
1474
+ regmap_read (pll -> clkr .regmap , PLL_STATUS (pll ), & regval );
1475
+ if (regval & LUCID_PCAL_DONE )
1476
+ return 0 ;
1477
+
1478
+ /* On/off to calibrate */
1479
+ ret = clk_trion_pll_enable (hw );
1480
+ if (!ret )
1481
+ clk_trion_pll_disable (hw );
1482
+
1483
+ return ret ;
1484
+ }
1485
+
1486
+ static int alpha_pll_lucid_set_rate (struct clk_hw * hw , unsigned long rate ,
1487
+ unsigned long prate )
1488
+ {
1489
+ struct clk_alpha_pll * pll = to_clk_alpha_pll (hw );
1490
+ unsigned long rrate ;
1491
+ u32 regval , l , alpha_width = pll_alpha_width (pll );
1492
+ u64 a ;
1493
+ int ret ;
1494
+
1495
+ rrate = alpha_pll_round_rate (rate , prate , & l , & a , alpha_width );
1496
+
1497
+ /*
1498
+ * Due to a limited number of bits for fractional rate programming, the
1499
+ * rounded up rate could be marginally higher than the requested rate.
1500
+ */
1501
+ if (rrate > (rate + PLL_RATE_MARGIN ) || rrate < rate ) {
1502
+ pr_err ("Call set rate on the PLL with rounded rates!\n" );
1503
+ return - EINVAL ;
1504
+ }
1505
+
1506
+ regmap_write (pll -> clkr .regmap , PLL_L_VAL (pll ), l );
1507
+ regmap_write (pll -> clkr .regmap , PLL_ALPHA_VAL (pll ), a );
1508
+
1509
+ /* Latch the PLL input */
1510
+ ret = regmap_update_bits (pll -> clkr .regmap , PLL_MODE (pll ),
1511
+ PLL_UPDATE , PLL_UPDATE );
1512
+ if (ret )
1513
+ return ret ;
1514
+
1515
+ /* Wait for 2 reference cycles before checking the ACK bit. */
1516
+ udelay (1 );
1517
+ regmap_read (pll -> clkr .regmap , PLL_MODE (pll ), & regval );
1518
+ if (!(regval & ALPHA_PLL_ACK_LATCH )) {
1519
+ pr_err ("Lucid PLL latch failed. Output may be unstable!\n" );
1520
+ return - EINVAL ;
1521
+ }
1522
+
1523
+ /* Return the latch input to 0 */
1524
+ ret = regmap_update_bits (pll -> clkr .regmap , PLL_MODE (pll ),
1525
+ PLL_UPDATE , 0 );
1526
+ if (ret )
1527
+ return ret ;
1528
+
1529
+ if (clk_hw_is_enabled (hw )) {
1530
+ ret = wait_for_pll_enable_lock (pll );
1531
+ if (ret )
1532
+ return ret ;
1533
+ }
1534
+
1535
+ /* Wait for PLL output to stabilize */
1536
+ udelay (100 );
1537
+ return 0 ;
1538
+ }
1539
+
1540
+ const struct clk_ops clk_alpha_pll_lucid_ops = {
1541
+ .prepare = alpha_pll_lucid_prepare ,
1542
+ .enable = clk_trion_pll_enable ,
1543
+ .disable = clk_trion_pll_disable ,
1544
+ .is_enabled = clk_trion_pll_is_enabled ,
1545
+ .recalc_rate = clk_trion_pll_recalc_rate ,
1546
+ .round_rate = clk_alpha_pll_round_rate ,
1547
+ .set_rate = alpha_pll_lucid_set_rate ,
1548
+ };
1549
+ EXPORT_SYMBOL_GPL (clk_alpha_pll_lucid_ops );
1550
+
1551
+ const struct clk_ops clk_alpha_pll_fixed_lucid_ops = {
1552
+ .enable = clk_trion_pll_enable ,
1553
+ .disable = clk_trion_pll_disable ,
1554
+ .is_enabled = clk_trion_pll_is_enabled ,
1555
+ .recalc_rate = clk_trion_pll_recalc_rate ,
1556
+ .round_rate = clk_alpha_pll_round_rate ,
1557
+ };
1558
+ EXPORT_SYMBOL_GPL (clk_alpha_pll_fixed_lucid_ops );
1559
+
1560
+ const struct clk_ops clk_alpha_pll_postdiv_lucid_ops = {
1561
+ .recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate ,
1562
+ .round_rate = clk_alpha_pll_postdiv_fabia_round_rate ,
1563
+ .set_rate = clk_alpha_pll_postdiv_fabia_set_rate ,
1564
+ };
1565
+ EXPORT_SYMBOL_GPL (clk_alpha_pll_postdiv_lucid_ops );
0 commit comments