aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/via/hw.c
diff options
context:
space:
mode:
authorFlorian Tobias Schandinat <FlorianSchandinat@gmx.de>2011-03-24 09:30:09 -0400
committerFlorian Tobias Schandinat <FlorianSchandinat@gmx.de>2011-03-24 09:30:09 -0400
commit2c536f84c19c73ab1e3411bf1596ff85c4a23783 (patch)
treebe4b08114f4b5a35805017c1852377136615043b /drivers/video/via/hw.c
parentc5593d26aea3aba2a7703a0b5d74b4ea8b726889 (diff)
viafb: split clock and PLL code to an extra file
This patch is a huge move operation with some rename and introduces an interface to still use the functions. This should be a step in the right direction to reuse the code whenever possible but cleanly separate code that differs on different platform and keeping the complexity as low as possible. pll_config was renamed to via_pll_config to keep the naming scheme. Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Diffstat (limited to 'drivers/video/via/hw.c')
-rw-r--r--drivers/video/via/hw.c288
1 files changed, 14 insertions, 274 deletions
diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 712348df0f84..f1eff0b4831f 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/via-core.h> 22#include <linux/via-core.h>
23#include "global.h" 23#include "global.h"
24#include "via_clock.h"
24 25
25static struct pll_limit cle266_pll_limits[] = { 26static struct pll_limit cle266_pll_limits[] = {
26 {19, 19, 4, 0}, 27 {19, 19, 4, 0},
@@ -484,6 +485,9 @@ static struct via_device_mapping device_mapping[] = {
484 {VIA_LVDS2, "LVDS2"} 485 {VIA_LVDS2, "LVDS2"}
485}; 486};
486 487
488/* structure with function pointers to support clock control */
489static struct via_clock clock;
490
487static void load_fix_bit_crtc_reg(void); 491static void load_fix_bit_crtc_reg(void);
488static void __devinit init_gfx_chip_info(int chip_type); 492static void __devinit init_gfx_chip_info(int chip_type);
489static void __devinit init_tmds_chip_info(void); 493static void __devinit init_tmds_chip_info(void);
@@ -1409,230 +1413,10 @@ void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active)
1409 1413
1410} 1414}
1411 1415
1412static void set_primary_clock_state(u8 state) 1416static struct via_pll_config get_pll_config(struct pll_limit *limits, int size,
1413{
1414 u8 value;
1415
1416 switch (state) {
1417 case VIA_STATE_ON:
1418 value = 0x20;
1419 break;
1420 case VIA_STATE_OFF:
1421 value = 0x00;
1422 break;
1423 default:
1424 return;
1425 }
1426
1427 via_write_reg_mask(VIASR, 0x1B, value, 0x30);
1428}
1429
1430static void set_secondary_clock_state(u8 state)
1431{
1432 u8 value;
1433
1434 switch (state) {
1435 case VIA_STATE_ON:
1436 value = 0x80;
1437 break;
1438 case VIA_STATE_OFF:
1439 value = 0x00;
1440 break;
1441 default:
1442 return;
1443 }
1444
1445 via_write_reg_mask(VIASR, 0x1B, value, 0xC0);
1446}
1447
1448static void set_primary_pll_state(u8 state)
1449{
1450 u8 value;
1451
1452 switch (state) {
1453 case VIA_STATE_ON:
1454 value = 0x20;
1455 break;
1456 case VIA_STATE_OFF:
1457 value = 0x00;
1458 break;
1459 default:
1460 return;
1461 }
1462
1463 via_write_reg_mask(VIASR, 0x2D, value, 0x30);
1464}
1465
1466static void set_secondary_pll_state(u8 state)
1467{
1468 u8 value;
1469
1470 switch (state) {
1471 case VIA_STATE_ON:
1472 value = 0x08;
1473 break;
1474 case VIA_STATE_OFF:
1475 value = 0x00;
1476 break;
1477 default:
1478 return;
1479 }
1480
1481 via_write_reg_mask(VIASR, 0x2D, value, 0x0C);
1482}
1483
1484static u32 cle266_encode_pll(struct pll_config pll)
1485{
1486 return (pll.multiplier << 8)
1487 | (pll.rshift << 6)
1488 | pll.divisor;
1489}
1490
1491static u32 k800_encode_pll(struct pll_config pll)
1492{
1493 return ((pll.divisor - 2) << 16)
1494 | (pll.rshift << 10)
1495 | (pll.multiplier - 2);
1496}
1497
1498static u32 vx855_encode_pll(struct pll_config pll)
1499{
1500 return (pll.divisor << 16)
1501 | (pll.rshift << 10)
1502 | pll.multiplier;
1503}
1504
1505static inline void cle266_set_primary_pll_encoded(u32 data)
1506{
1507 via_write_reg_mask(VIASR, 0x40, 0x02, 0x02); /* enable reset */
1508 via_write_reg(VIASR, 0x46, data & 0xFF);
1509 via_write_reg(VIASR, 0x47, (data >> 8) & 0xFF);
1510 via_write_reg_mask(VIASR, 0x40, 0x00, 0x02); /* disable reset */
1511}
1512
1513static inline void k800_set_primary_pll_encoded(u32 data)
1514{
1515 via_write_reg_mask(VIASR, 0x40, 0x02, 0x02); /* enable reset */
1516 via_write_reg(VIASR, 0x44, data & 0xFF);
1517 via_write_reg(VIASR, 0x45, (data >> 8) & 0xFF);
1518 via_write_reg(VIASR, 0x46, (data >> 16) & 0xFF);
1519 via_write_reg_mask(VIASR, 0x40, 0x00, 0x02); /* disable reset */
1520}
1521
1522static inline void cle266_set_secondary_pll_encoded(u32 data)
1523{
1524 via_write_reg_mask(VIASR, 0x40, 0x04, 0x04); /* enable reset */
1525 via_write_reg(VIASR, 0x44, data & 0xFF);
1526 via_write_reg(VIASR, 0x45, (data >> 8) & 0xFF);
1527 via_write_reg_mask(VIASR, 0x40, 0x00, 0x04); /* disable reset */
1528}
1529
1530static inline void k800_set_secondary_pll_encoded(u32 data)
1531{
1532 via_write_reg_mask(VIASR, 0x40, 0x04, 0x04); /* enable reset */
1533 via_write_reg(VIASR, 0x4A, data & 0xFF);
1534 via_write_reg(VIASR, 0x4B, (data >> 8) & 0xFF);
1535 via_write_reg(VIASR, 0x4C, (data >> 16) & 0xFF);
1536 via_write_reg_mask(VIASR, 0x40, 0x00, 0x04); /* disable reset */
1537}
1538
1539static void cle266_set_primary_pll(struct pll_config config)
1540{
1541 cle266_set_primary_pll_encoded(cle266_encode_pll(config));
1542}
1543
1544static void k800_set_primary_pll(struct pll_config config)
1545{
1546 k800_set_primary_pll_encoded(k800_encode_pll(config));
1547}
1548
1549static void vx855_set_primary_pll(struct pll_config config)
1550{
1551 k800_set_primary_pll_encoded(vx855_encode_pll(config));
1552}
1553
1554static void cle266_set_secondary_pll(struct pll_config config)
1555{
1556 cle266_set_secondary_pll_encoded(cle266_encode_pll(config));
1557}
1558
1559static void k800_set_secondary_pll(struct pll_config config)
1560{
1561 k800_set_secondary_pll_encoded(k800_encode_pll(config));
1562}
1563
1564static void vx855_set_secondary_pll(struct pll_config config)
1565{
1566 k800_set_secondary_pll_encoded(vx855_encode_pll(config));
1567}
1568
1569enum via_clksrc {
1570 VIA_CLKSRC_X1 = 0,
1571 VIA_CLKSRC_TVX1,
1572 VIA_CLKSRC_TVPLL,
1573 VIA_CLKSRC_DVP1TVCLKR,
1574 VIA_CLKSRC_CAP0,
1575 VIA_CLKSRC_CAP1,
1576};
1577
1578static inline u8 set_clock_source_common(enum via_clksrc source, bool use_pll)
1579{
1580 u8 data = 0;
1581
1582 switch (source) {
1583 case VIA_CLKSRC_X1:
1584 data = 0x00;
1585 break;
1586 case VIA_CLKSRC_TVX1:
1587 data = 0x02;
1588 break;
1589 case VIA_CLKSRC_TVPLL:
1590 data = 0x04; /* 0x06 should be the same */
1591 break;
1592 case VIA_CLKSRC_DVP1TVCLKR:
1593 data = 0x0A;
1594 break;
1595 case VIA_CLKSRC_CAP0:
1596 data = 0xC;
1597 break;
1598 case VIA_CLKSRC_CAP1:
1599 data = 0x0E;
1600 break;
1601 }
1602
1603 if (!use_pll)
1604 data |= 1;
1605
1606 return data;
1607}
1608
1609static void set_primary_clock_source(enum via_clksrc source, bool use_pll)
1610{
1611 u8 data = set_clock_source_common(source, use_pll) << 4;
1612 via_write_reg_mask(VIACR, 0x6C, data, 0xF0);
1613}
1614
1615static void set_secondary_clock_source(enum via_clksrc source, bool use_pll)
1616{
1617 u8 data = set_clock_source_common(source, use_pll);
1618 via_write_reg_mask(VIACR, 0x6C, data, 0x0F);
1619}
1620
1621static inline u32 get_pll_internal_frequency(u32 ref_freq,
1622 struct pll_config pll)
1623{
1624 return ref_freq / pll.divisor * pll.multiplier;
1625}
1626
1627static inline u32 get_pll_output_frequency(u32 ref_freq, struct pll_config pll)
1628{
1629 return get_pll_internal_frequency(ref_freq, pll)>>pll.rshift;
1630}
1631
1632static struct pll_config get_pll_config(struct pll_limit *limits, int size,
1633 int clk) 1417 int clk)
1634{ 1418{
1635 struct pll_config cur, up, down, best = {0, 1, 0}; 1419 struct via_pll_config cur, up, down, best = {0, 1, 0};
1636 const u32 f0 = 14318180; /* X1 frequency */ 1420 const u32 f0 = 14318180; /* X1 frequency */
1637 int i, f; 1421 int i, f;
1638 1422
@@ -1662,9 +1446,9 @@ static struct pll_config get_pll_config(struct pll_limit *limits, int size,
1662 return best; 1446 return best;
1663} 1447}
1664 1448
1665static struct pll_config get_best_pll_config(int clk) 1449static struct via_pll_config get_best_pll_config(int clk)
1666{ 1450{
1667 struct pll_config config; 1451 struct via_pll_config config;
1668 1452
1669 switch (viaparinfo->chip_info->gfx_chip_name) { 1453 switch (viaparinfo->chip_info->gfx_chip_name) {
1670 case UNICHROME_CLE266: 1454 case UNICHROME_CLE266:
@@ -1700,57 +1484,12 @@ static struct pll_config get_best_pll_config(int clk)
1700/* Set VCLK*/ 1484/* Set VCLK*/
1701void viafb_set_vclock(u32 clk, int set_iga) 1485void viafb_set_vclock(u32 clk, int set_iga)
1702{ 1486{
1703 struct pll_config config = get_best_pll_config(clk); 1487 struct via_pll_config config = get_best_pll_config(clk);
1704 1488
1705 if (set_iga == IGA1) { 1489 if (set_iga == IGA1)
1706 /* Change D,N FOR VCLK */ 1490 clock.set_primary_pll(config);
1707 switch (viaparinfo->chip_info->gfx_chip_name) { 1491 if (set_iga == IGA2)
1708 case UNICHROME_CLE266: 1492 clock.set_secondary_pll(config);
1709 case UNICHROME_K400:
1710 cle266_set_primary_pll(config);
1711 break;
1712 case UNICHROME_K800:
1713 case UNICHROME_PM800:
1714 case UNICHROME_CN700:
1715 case UNICHROME_CX700:
1716 case UNICHROME_CN750:
1717 case UNICHROME_K8M890:
1718 case UNICHROME_P4M890:
1719 case UNICHROME_P4M900:
1720 case UNICHROME_VX800:
1721 k800_set_primary_pll(config);
1722 break;
1723 case UNICHROME_VX855:
1724 case UNICHROME_VX900:
1725 vx855_set_primary_pll(config);
1726 break;
1727 }
1728 }
1729
1730 if (set_iga == IGA2) {
1731 /* Change D,N FOR LCK */
1732 switch (viaparinfo->chip_info->gfx_chip_name) {
1733 case UNICHROME_CLE266:
1734 case UNICHROME_K400:
1735 cle266_set_secondary_pll(config);
1736 break;
1737 case UNICHROME_K800:
1738 case UNICHROME_PM800:
1739 case UNICHROME_CN700:
1740 case UNICHROME_CX700:
1741 case UNICHROME_CN750:
1742 case UNICHROME_K8M890:
1743 case UNICHROME_P4M890:
1744 case UNICHROME_P4M900:
1745 case UNICHROME_VX800:
1746 k800_set_secondary_pll(config);
1747 break;
1748 case UNICHROME_VX855:
1749 case UNICHROME_VX900:
1750 vx855_set_secondary_pll(config);
1751 break;
1752 }
1753 }
1754 1493
1755 /* Fire! */ 1494 /* Fire! */
1756 via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */ 1495 via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
@@ -2059,6 +1798,7 @@ void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
2059 1798
2060void __devinit viafb_init_chip_info(int chip_type) 1799void __devinit viafb_init_chip_info(int chip_type)
2061{ 1800{
1801 via_clock_init(&clock, chip_type);
2062 init_gfx_chip_info(chip_type); 1802 init_gfx_chip_info(chip_type);
2063 init_tmds_chip_info(); 1803 init_tmds_chip_info();
2064 init_lvds_chip_info(); 1804 init_lvds_chip_info();