|
@@ -8,13 +8,16 @@
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
#include <linux/debugfs.h>
|
|
|
+#include <linux/gpio.h>
|
|
|
#include <linux/io.h>
|
|
|
#include <linux/platform_device.h>
|
|
|
#include <linux/reset.h>
|
|
|
|
|
|
#include <soc/tegra/pmc.h>
|
|
|
|
|
|
+#include <drm/drm_atomic_helper.h>
|
|
|
#include <drm/drm_dp_helper.h>
|
|
|
+#include <drm/drm_panel.h>
|
|
|
|
|
|
#include "dc.h"
|
|
|
#include "drm.h"
|
|
@@ -258,18 +261,8 @@ static int tegra_sor_attach(struct tegra_sor *sor)
|
|
|
|
|
|
static int tegra_sor_wakeup(struct tegra_sor *sor)
|
|
|
{
|
|
|
- struct tegra_dc *dc = to_tegra_dc(sor->output.encoder.crtc);
|
|
|
unsigned long value, timeout;
|
|
|
|
|
|
- /* enable display controller outputs */
|
|
|
- value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
|
|
|
- value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
|
|
|
- PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
|
|
|
- tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
|
|
|
-
|
|
|
- tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
|
|
|
- tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
|
|
|
-
|
|
|
timeout = jiffies + msecs_to_jiffies(250);
|
|
|
|
|
|
/* wait for head to wake up */
|
|
@@ -482,202 +475,512 @@ static int tegra_sor_calc_config(struct tegra_sor *sor,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int tegra_output_sor_enable(struct tegra_output *output)
|
|
|
+static int tegra_sor_detach(struct tegra_sor *sor)
|
|
|
{
|
|
|
- struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
|
|
|
- struct drm_display_mode *mode = &dc->base.mode;
|
|
|
- unsigned int vbe, vse, hbe, hse, vbs, hbs, i;
|
|
|
- struct tegra_sor *sor = to_sor(output);
|
|
|
- struct tegra_sor_config config;
|
|
|
- struct drm_dp_link link;
|
|
|
- struct drm_dp_aux *aux;
|
|
|
- unsigned long value;
|
|
|
- int err = 0;
|
|
|
-
|
|
|
- mutex_lock(&sor->lock);
|
|
|
-
|
|
|
- if (sor->enabled)
|
|
|
- goto unlock;
|
|
|
+ unsigned long value, timeout;
|
|
|
|
|
|
- err = clk_prepare_enable(sor->clk);
|
|
|
- if (err < 0)
|
|
|
- goto unlock;
|
|
|
+ /* switch to safe mode */
|
|
|
+ value = tegra_sor_readl(sor, SOR_SUPER_STATE_1);
|
|
|
+ value &= ~SOR_SUPER_STATE_MODE_NORMAL;
|
|
|
+ tegra_sor_writel(sor, value, SOR_SUPER_STATE_1);
|
|
|
+ tegra_sor_super_update(sor);
|
|
|
|
|
|
- reset_control_deassert(sor->rst);
|
|
|
+ timeout = jiffies + msecs_to_jiffies(250);
|
|
|
|
|
|
- /* FIXME: properly convert to struct drm_dp_aux */
|
|
|
- aux = (struct drm_dp_aux *)sor->dpaux;
|
|
|
+ while (time_before(jiffies, timeout)) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_PWR);
|
|
|
+ if (value & SOR_PWR_MODE_SAFE)
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if (sor->dpaux) {
|
|
|
- err = tegra_dpaux_enable(sor->dpaux);
|
|
|
- if (err < 0)
|
|
|
- dev_err(sor->dev, "failed to enable DP: %d\n", err);
|
|
|
+ if ((value & SOR_PWR_MODE_SAFE) == 0)
|
|
|
+ return -ETIMEDOUT;
|
|
|
|
|
|
- err = drm_dp_link_probe(aux, &link);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to probe eDP link: %d\n",
|
|
|
- err);
|
|
|
- goto unlock;
|
|
|
- }
|
|
|
- }
|
|
|
+ /* go to sleep */
|
|
|
+ value = tegra_sor_readl(sor, SOR_SUPER_STATE_1);
|
|
|
+ value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK;
|
|
|
+ tegra_sor_writel(sor, value, SOR_SUPER_STATE_1);
|
|
|
+ tegra_sor_super_update(sor);
|
|
|
|
|
|
- err = clk_set_parent(sor->clk, sor->clk_safe);
|
|
|
- if (err < 0)
|
|
|
- dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
|
|
|
+ /* detach */
|
|
|
+ value = tegra_sor_readl(sor, SOR_SUPER_STATE_1);
|
|
|
+ value &= ~SOR_SUPER_STATE_ATTACHED;
|
|
|
+ tegra_sor_writel(sor, value, SOR_SUPER_STATE_1);
|
|
|
+ tegra_sor_super_update(sor);
|
|
|
|
|
|
- memset(&config, 0, sizeof(config));
|
|
|
- config.bits_per_pixel = output->connector.display_info.bpc * 3;
|
|
|
+ timeout = jiffies + msecs_to_jiffies(250);
|
|
|
|
|
|
- err = tegra_sor_calc_config(sor, mode, &config, &link);
|
|
|
- if (err < 0)
|
|
|
- dev_err(sor->dev, "failed to compute link configuration: %d\n",
|
|
|
- err);
|
|
|
+ while (time_before(jiffies, timeout)) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_TEST);
|
|
|
+ if ((value & SOR_TEST_ATTACHED) == 0)
|
|
|
+ break;
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
|
|
|
- value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
|
|
|
- value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
|
|
|
- tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
|
|
|
+ usleep_range(25, 100);
|
|
|
+ }
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value &= ~SOR_PLL_2_BANDGAP_POWERDOWN;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
- usleep_range(20, 100);
|
|
|
+ if ((value & SOR_TEST_ATTACHED) != 0)
|
|
|
+ return -ETIMEDOUT;
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_3);
|
|
|
- value |= SOR_PLL_3_PLL_VDD_MODE_V3_3;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_3);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
- value = SOR_PLL_0_ICHPMP(0xf) | SOR_PLL_0_VCOCAP_RST |
|
|
|
- SOR_PLL_0_PLLREG_LEVEL_V45 | SOR_PLL_0_RESISTOR_EXT;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
+static int tegra_sor_power_down(struct tegra_sor *sor)
|
|
|
+{
|
|
|
+ unsigned long value, timeout;
|
|
|
+ int err;
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value |= SOR_PLL_2_SEQ_PLLCAPPD;
|
|
|
- value &= ~SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE;
|
|
|
- value |= SOR_PLL_2_LVDS_ENABLE;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ value = tegra_sor_readl(sor, SOR_PWR);
|
|
|
+ value &= ~SOR_PWR_NORMAL_STATE_PU;
|
|
|
+ value |= SOR_PWR_TRIGGER;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PWR);
|
|
|
|
|
|
- value = SOR_PLL_1_TERM_COMPOUT | SOR_PLL_1_TMDS_TERM;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_1);
|
|
|
+ timeout = jiffies + msecs_to_jiffies(250);
|
|
|
|
|
|
- while (true) {
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- if ((value & SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE) == 0)
|
|
|
- break;
|
|
|
+ while (time_before(jiffies, timeout)) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_PWR);
|
|
|
+ if ((value & SOR_PWR_TRIGGER) == 0)
|
|
|
+ return 0;
|
|
|
|
|
|
- usleep_range(250, 1000);
|
|
|
+ usleep_range(25, 100);
|
|
|
}
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value &= ~SOR_PLL_2_POWERDOWN_OVERRIDE;
|
|
|
- value &= ~SOR_PLL_2_PORT_POWERDOWN;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ if ((value & SOR_PWR_TRIGGER) != 0)
|
|
|
+ return -ETIMEDOUT;
|
|
|
|
|
|
- /*
|
|
|
- * power up
|
|
|
- */
|
|
|
+ err = clk_set_parent(sor->clk, sor->clk_safe);
|
|
|
+ if (err < 0)
|
|
|
+ dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
|
|
|
|
|
|
- /* set safe link bandwidth (1.62 Gbps) */
|
|
|
- value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
|
|
|
- value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
|
|
|
- value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62;
|
|
|
- tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
|
|
|
+ value = tegra_sor_readl(sor, SOR_DP_PADCTL_0);
|
|
|
+ value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
|
|
|
+ SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2);
|
|
|
+ tegra_sor_writel(sor, value, SOR_DP_PADCTL_0);
|
|
|
|
|
|
- /* step 1 */
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value |= SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL_2_PORT_POWERDOWN |
|
|
|
- SOR_PLL_2_BANDGAP_POWERDOWN;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ /* stop lane sequencer */
|
|
|
+ value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP |
|
|
|
+ SOR_LANE_SEQ_CTL_POWER_STATE_DOWN;
|
|
|
+ tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_0);
|
|
|
- value |= SOR_PLL_0_VCOPD | SOR_PLL_0_POWER_OFF;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
+ timeout = jiffies + msecs_to_jiffies(250);
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_DP_PADCTL_0);
|
|
|
- value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
|
|
|
- tegra_sor_writel(sor, value, SOR_DP_PADCTL_0);
|
|
|
+ while (time_before(jiffies, timeout)) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
|
|
|
+ if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
|
|
|
+ break;
|
|
|
|
|
|
- /* step 2 */
|
|
|
- err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to power on I/O rail: %d\n", err);
|
|
|
- goto unlock;
|
|
|
+ usleep_range(25, 100);
|
|
|
}
|
|
|
|
|
|
- usleep_range(5, 100);
|
|
|
+ if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0)
|
|
|
+ return -ETIMEDOUT;
|
|
|
|
|
|
- /* step 3 */
|
|
|
value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value &= ~SOR_PLL_2_BANDGAP_POWERDOWN;
|
|
|
+ value |= SOR_PLL_2_PORT_POWERDOWN;
|
|
|
tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
|
|
|
usleep_range(20, 100);
|
|
|
|
|
|
- /* step 4 */
|
|
|
value = tegra_sor_readl(sor, SOR_PLL_0);
|
|
|
- value &= ~SOR_PLL_0_POWER_OFF;
|
|
|
- value &= ~SOR_PLL_0_VCOPD;
|
|
|
+ value |= SOR_PLL_0_POWER_OFF;
|
|
|
+ value |= SOR_PLL_0_VCOPD;
|
|
|
tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
|
|
|
value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value &= ~SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE;
|
|
|
+ value |= SOR_PLL_2_SEQ_PLLCAPPD;
|
|
|
+ value |= SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE;
|
|
|
tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
|
|
|
- usleep_range(200, 1000);
|
|
|
+ usleep_range(20, 100);
|
|
|
|
|
|
- /* step 5 */
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value &= ~SOR_PLL_2_PORT_POWERDOWN;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
- /* switch to DP clock */
|
|
|
- err = clk_set_parent(sor->clk, sor->clk_dp);
|
|
|
- if (err < 0)
|
|
|
- dev_err(sor->dev, "failed to set DP parent clock: %d\n", err);
|
|
|
+static int tegra_sor_crc_open(struct inode *inode, struct file *file)
|
|
|
+{
|
|
|
+ file->private_data = inode->i_private;
|
|
|
|
|
|
- /* power DP lanes */
|
|
|
- value = tegra_sor_readl(sor, SOR_DP_PADCTL_0);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
- if (link.num_lanes <= 2)
|
|
|
- value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2);
|
|
|
- else
|
|
|
- value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2;
|
|
|
+static int tegra_sor_crc_release(struct inode *inode, struct file *file)
|
|
|
+{
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
- if (link.num_lanes <= 1)
|
|
|
- value &= ~SOR_DP_PADCTL_PD_TXD_1;
|
|
|
- else
|
|
|
- value |= SOR_DP_PADCTL_PD_TXD_1;
|
|
|
+static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout)
|
|
|
+{
|
|
|
+ u32 value;
|
|
|
|
|
|
- if (link.num_lanes == 0)
|
|
|
- value &= ~SOR_DP_PADCTL_PD_TXD_0;
|
|
|
- else
|
|
|
- value |= SOR_DP_PADCTL_PD_TXD_0;
|
|
|
+ timeout = jiffies + msecs_to_jiffies(timeout);
|
|
|
|
|
|
- tegra_sor_writel(sor, value, SOR_DP_PADCTL_0);
|
|
|
+ while (time_before(jiffies, timeout)) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_CRC_A);
|
|
|
+ if (value & SOR_CRC_A_VALID)
|
|
|
+ return 0;
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_DP_LINKCTL_0);
|
|
|
- value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
|
|
|
- value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes);
|
|
|
- tegra_sor_writel(sor, value, SOR_DP_LINKCTL_0);
|
|
|
+ usleep_range(100, 200);
|
|
|
+ }
|
|
|
|
|
|
- /* start lane sequencer */
|
|
|
- value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
|
|
|
- SOR_LANE_SEQ_CTL_POWER_STATE_UP;
|
|
|
- tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
|
|
|
+ return -ETIMEDOUT;
|
|
|
+}
|
|
|
|
|
|
- while (true) {
|
|
|
- value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
|
|
|
- if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
|
|
|
- break;
|
|
|
+static ssize_t tegra_sor_crc_read(struct file *file, char __user *buffer,
|
|
|
+ size_t size, loff_t *ppos)
|
|
|
+{
|
|
|
+ struct tegra_sor *sor = file->private_data;
|
|
|
+ ssize_t num, err;
|
|
|
+ char buf[10];
|
|
|
+ u32 value;
|
|
|
|
|
|
- usleep_range(250, 1000);
|
|
|
- }
|
|
|
+ mutex_lock(&sor->lock);
|
|
|
|
|
|
- /* set link bandwidth */
|
|
|
- value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
|
|
|
- value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
|
|
|
- value |= drm_dp_link_rate_to_bw_code(link.rate) << 2;
|
|
|
- tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
|
|
|
+ if (!sor->enabled) {
|
|
|
+ err = -EAGAIN;
|
|
|
+ goto unlock;
|
|
|
+ }
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_STATE_1);
|
|
|
+ value &= ~SOR_STATE_ASY_CRC_MODE_MASK;
|
|
|
+ tegra_sor_writel(sor, value, SOR_STATE_1);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_CRC_CNTRL);
|
|
|
+ value |= SOR_CRC_CNTRL_ENABLE;
|
|
|
+ tegra_sor_writel(sor, value, SOR_CRC_CNTRL);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_TEST);
|
|
|
+ value &= ~SOR_TEST_CRC_POST_SERIALIZE;
|
|
|
+ tegra_sor_writel(sor, value, SOR_TEST);
|
|
|
+
|
|
|
+ err = tegra_sor_crc_wait(sor, 100);
|
|
|
+ if (err < 0)
|
|
|
+ goto unlock;
|
|
|
+
|
|
|
+ tegra_sor_writel(sor, SOR_CRC_A_RESET, SOR_CRC_A);
|
|
|
+ value = tegra_sor_readl(sor, SOR_CRC_B);
|
|
|
+
|
|
|
+ num = scnprintf(buf, sizeof(buf), "%08x\n", value);
|
|
|
+
|
|
|
+ err = simple_read_from_buffer(buffer, size, ppos, buf, num);
|
|
|
+
|
|
|
+unlock:
|
|
|
+ mutex_unlock(&sor->lock);
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+static const struct file_operations tegra_sor_crc_fops = {
|
|
|
+ .owner = THIS_MODULE,
|
|
|
+ .open = tegra_sor_crc_open,
|
|
|
+ .read = tegra_sor_crc_read,
|
|
|
+ .release = tegra_sor_crc_release,
|
|
|
+};
|
|
|
+
|
|
|
+static int tegra_sor_debugfs_init(struct tegra_sor *sor,
|
|
|
+ struct drm_minor *minor)
|
|
|
+{
|
|
|
+ struct dentry *entry;
|
|
|
+ int err = 0;
|
|
|
+
|
|
|
+ sor->debugfs = debugfs_create_dir("sor", minor->debugfs_root);
|
|
|
+ if (!sor->debugfs)
|
|
|
+ return -ENOMEM;
|
|
|
+
|
|
|
+ entry = debugfs_create_file("crc", 0644, sor->debugfs, sor,
|
|
|
+ &tegra_sor_crc_fops);
|
|
|
+ if (!entry) {
|
|
|
+ dev_err(sor->dev,
|
|
|
+ "cannot create /sys/kernel/debug/dri/%s/sor/crc\n",
|
|
|
+ minor->debugfs_root->d_name.name);
|
|
|
+ err = -ENOMEM;
|
|
|
+ goto remove;
|
|
|
+ }
|
|
|
+
|
|
|
+ return err;
|
|
|
+
|
|
|
+remove:
|
|
|
+ debugfs_remove(sor->debugfs);
|
|
|
+ sor->debugfs = NULL;
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+static void tegra_sor_debugfs_exit(struct tegra_sor *sor)
|
|
|
+{
|
|
|
+ debugfs_remove_recursive(sor->debugfs);
|
|
|
+ sor->debugfs = NULL;
|
|
|
+}
|
|
|
+
|
|
|
+static void tegra_sor_connector_dpms(struct drm_connector *connector, int mode)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+static enum drm_connector_status
|
|
|
+tegra_sor_connector_detect(struct drm_connector *connector, bool force)
|
|
|
+{
|
|
|
+ struct tegra_output *output = connector_to_output(connector);
|
|
|
+ struct tegra_sor *sor = to_sor(output);
|
|
|
+
|
|
|
+ if (sor->dpaux)
|
|
|
+ return tegra_dpaux_detect(sor->dpaux);
|
|
|
+
|
|
|
+ return connector_status_unknown;
|
|
|
+}
|
|
|
+
|
|
|
+static const struct drm_connector_funcs tegra_sor_connector_funcs = {
|
|
|
+ .dpms = tegra_sor_connector_dpms,
|
|
|
+ .reset = drm_atomic_helper_connector_reset,
|
|
|
+ .detect = tegra_sor_connector_detect,
|
|
|
+ .fill_modes = drm_helper_probe_single_connector_modes,
|
|
|
+ .destroy = tegra_output_connector_destroy,
|
|
|
+ .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
|
|
|
+ .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
|
|
|
+};
|
|
|
+
|
|
|
+static int tegra_sor_connector_get_modes(struct drm_connector *connector)
|
|
|
+{
|
|
|
+ struct tegra_output *output = connector_to_output(connector);
|
|
|
+ struct tegra_sor *sor = to_sor(output);
|
|
|
+ int err;
|
|
|
+
|
|
|
+ if (sor->dpaux)
|
|
|
+ tegra_dpaux_enable(sor->dpaux);
|
|
|
+
|
|
|
+ err = tegra_output_connector_get_modes(connector);
|
|
|
+
|
|
|
+ if (sor->dpaux)
|
|
|
+ tegra_dpaux_disable(sor->dpaux);
|
|
|
+
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+static enum drm_mode_status
|
|
|
+tegra_sor_connector_mode_valid(struct drm_connector *connector,
|
|
|
+ struct drm_display_mode *mode)
|
|
|
+{
|
|
|
+ return MODE_OK;
|
|
|
+}
|
|
|
+
|
|
|
+static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = {
|
|
|
+ .get_modes = tegra_sor_connector_get_modes,
|
|
|
+ .mode_valid = tegra_sor_connector_mode_valid,
|
|
|
+ .best_encoder = tegra_output_connector_best_encoder,
|
|
|
+};
|
|
|
+
|
|
|
+static const struct drm_encoder_funcs tegra_sor_encoder_funcs = {
|
|
|
+ .destroy = tegra_output_encoder_destroy,
|
|
|
+};
|
|
|
+
|
|
|
+static void tegra_sor_encoder_dpms(struct drm_encoder *encoder, int mode)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+static void tegra_sor_encoder_prepare(struct drm_encoder *encoder)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+static void tegra_sor_encoder_commit(struct drm_encoder *encoder)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+static void tegra_sor_encoder_mode_set(struct drm_encoder *encoder,
|
|
|
+ struct drm_display_mode *mode,
|
|
|
+ struct drm_display_mode *adjusted)
|
|
|
+{
|
|
|
+ struct tegra_output *output = encoder_to_output(encoder);
|
|
|
+ struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
|
|
|
+ unsigned int vbe, vse, hbe, hse, vbs, hbs, i;
|
|
|
+ struct tegra_sor *sor = to_sor(output);
|
|
|
+ struct tegra_sor_config config;
|
|
|
+ struct drm_dp_link link;
|
|
|
+ struct drm_dp_aux *aux;
|
|
|
+ unsigned long value;
|
|
|
+ int err = 0;
|
|
|
+
|
|
|
+ mutex_lock(&sor->lock);
|
|
|
+
|
|
|
+ if (sor->enabled)
|
|
|
+ goto unlock;
|
|
|
+
|
|
|
+ err = clk_prepare_enable(sor->clk);
|
|
|
+ if (err < 0)
|
|
|
+ goto unlock;
|
|
|
+
|
|
|
+ reset_control_deassert(sor->rst);
|
|
|
+
|
|
|
+ if (output->panel)
|
|
|
+ drm_panel_prepare(output->panel);
|
|
|
+
|
|
|
+ /* FIXME: properly convert to struct drm_dp_aux */
|
|
|
+ aux = (struct drm_dp_aux *)sor->dpaux;
|
|
|
+
|
|
|
+ if (sor->dpaux) {
|
|
|
+ err = tegra_dpaux_enable(sor->dpaux);
|
|
|
+ if (err < 0)
|
|
|
+ dev_err(sor->dev, "failed to enable DP: %d\n", err);
|
|
|
+
|
|
|
+ err = drm_dp_link_probe(aux, &link);
|
|
|
+ if (err < 0) {
|
|
|
+ dev_err(sor->dev, "failed to probe eDP link: %d\n",
|
|
|
+ err);
|
|
|
+ goto unlock;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = clk_set_parent(sor->clk, sor->clk_safe);
|
|
|
+ if (err < 0)
|
|
|
+ dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
|
|
|
+
|
|
|
+ memset(&config, 0, sizeof(config));
|
|
|
+ config.bits_per_pixel = output->connector.display_info.bpc * 3;
|
|
|
+
|
|
|
+ err = tegra_sor_calc_config(sor, mode, &config, &link);
|
|
|
+ if (err < 0)
|
|
|
+ dev_err(sor->dev, "failed to compute link configuration: %d\n",
|
|
|
+ err);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
|
|
|
+ value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
|
|
|
+ value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
|
|
|
+ tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value &= ~SOR_PLL_2_BANDGAP_POWERDOWN;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ usleep_range(20, 100);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_3);
|
|
|
+ value |= SOR_PLL_3_PLL_VDD_MODE_V3_3;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_3);
|
|
|
+
|
|
|
+ value = SOR_PLL_0_ICHPMP(0xf) | SOR_PLL_0_VCOCAP_RST |
|
|
|
+ SOR_PLL_0_PLLREG_LEVEL_V45 | SOR_PLL_0_RESISTOR_EXT;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value |= SOR_PLL_2_SEQ_PLLCAPPD;
|
|
|
+ value &= ~SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE;
|
|
|
+ value |= SOR_PLL_2_LVDS_ENABLE;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+
|
|
|
+ value = SOR_PLL_1_TERM_COMPOUT | SOR_PLL_1_TMDS_TERM;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_1);
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ if ((value & SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE) == 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ usleep_range(250, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value &= ~SOR_PLL_2_POWERDOWN_OVERRIDE;
|
|
|
+ value &= ~SOR_PLL_2_PORT_POWERDOWN;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * power up
|
|
|
+ */
|
|
|
+
|
|
|
+ /* set safe link bandwidth (1.62 Gbps) */
|
|
|
+ value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
|
|
|
+ value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
|
|
|
+ value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62;
|
|
|
+ tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
|
|
|
+
|
|
|
+ /* step 1 */
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value |= SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL_2_PORT_POWERDOWN |
|
|
|
+ SOR_PLL_2_BANDGAP_POWERDOWN;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_0);
|
|
|
+ value |= SOR_PLL_0_VCOPD | SOR_PLL_0_POWER_OFF;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_DP_PADCTL_0);
|
|
|
+ value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
|
|
|
+ tegra_sor_writel(sor, value, SOR_DP_PADCTL_0);
|
|
|
+
|
|
|
+ /* step 2 */
|
|
|
+ err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS);
|
|
|
+ if (err < 0) {
|
|
|
+ dev_err(sor->dev, "failed to power on I/O rail: %d\n", err);
|
|
|
+ goto unlock;
|
|
|
+ }
|
|
|
+
|
|
|
+ usleep_range(5, 100);
|
|
|
+
|
|
|
+ /* step 3 */
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value &= ~SOR_PLL_2_BANDGAP_POWERDOWN;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+
|
|
|
+ usleep_range(20, 100);
|
|
|
+
|
|
|
+ /* step 4 */
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_0);
|
|
|
+ value &= ~SOR_PLL_0_POWER_OFF;
|
|
|
+ value &= ~SOR_PLL_0_VCOPD;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value &= ~SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+
|
|
|
+ usleep_range(200, 1000);
|
|
|
+
|
|
|
+ /* step 5 */
|
|
|
+ value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
+ value &= ~SOR_PLL_2_PORT_POWERDOWN;
|
|
|
+ tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+
|
|
|
+ /* switch to DP clock */
|
|
|
+ err = clk_set_parent(sor->clk, sor->clk_dp);
|
|
|
+ if (err < 0)
|
|
|
+ dev_err(sor->dev, "failed to set DP parent clock: %d\n", err);
|
|
|
+
|
|
|
+ /* power DP lanes */
|
|
|
+ value = tegra_sor_readl(sor, SOR_DP_PADCTL_0);
|
|
|
+
|
|
|
+ if (link.num_lanes <= 2)
|
|
|
+ value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2);
|
|
|
+ else
|
|
|
+ value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2;
|
|
|
+
|
|
|
+ if (link.num_lanes <= 1)
|
|
|
+ value &= ~SOR_DP_PADCTL_PD_TXD_1;
|
|
|
+ else
|
|
|
+ value |= SOR_DP_PADCTL_PD_TXD_1;
|
|
|
+
|
|
|
+ if (link.num_lanes == 0)
|
|
|
+ value &= ~SOR_DP_PADCTL_PD_TXD_0;
|
|
|
+ else
|
|
|
+ value |= SOR_DP_PADCTL_PD_TXD_0;
|
|
|
+
|
|
|
+ tegra_sor_writel(sor, value, SOR_DP_PADCTL_0);
|
|
|
+
|
|
|
+ value = tegra_sor_readl(sor, SOR_DP_LINKCTL_0);
|
|
|
+ value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
|
|
|
+ value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes);
|
|
|
+ tegra_sor_writel(sor, value, SOR_DP_LINKCTL_0);
|
|
|
+
|
|
|
+ /* start lane sequencer */
|
|
|
+ value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
|
|
|
+ SOR_LANE_SEQ_CTL_POWER_STATE_UP;
|
|
|
+ tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
|
|
|
+ if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
|
|
|
+ break;
|
|
|
+
|
|
|
+ usleep_range(250, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* set link bandwidth */
|
|
|
+ value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
|
|
|
+ value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
|
|
|
+ value |= drm_dp_link_rate_to_bw_code(link.rate) << 2;
|
|
|
+ tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
|
|
|
|
|
|
/* set linkctl */
|
|
|
value = tegra_sor_readl(sor, SOR_DP_LINKCTL_0);
|
|
@@ -800,18 +1103,6 @@ static int tegra_output_sor_enable(struct tegra_output *output)
|
|
|
goto unlock;
|
|
|
}
|
|
|
|
|
|
- /* start display controller in continuous mode */
|
|
|
- value = tegra_dc_readl(dc, DC_CMD_STATE_ACCESS);
|
|
|
- value |= WRITE_MUX;
|
|
|
- tegra_dc_writel(dc, value, DC_CMD_STATE_ACCESS);
|
|
|
-
|
|
|
- tegra_dc_writel(dc, VSYNC_H_POSITION(1), DC_DISP_DISP_TIMING_OPTIONS);
|
|
|
- tegra_dc_writel(dc, DISP_CTRL_MODE_C_DISPLAY, DC_CMD_DISPLAY_COMMAND);
|
|
|
-
|
|
|
- value = tegra_dc_readl(dc, DC_CMD_STATE_ACCESS);
|
|
|
- value &= ~WRITE_MUX;
|
|
|
- tegra_dc_writel(dc, value, DC_CMD_STATE_ACCESS);
|
|
|
-
|
|
|
/*
|
|
|
* configure panel (24bpp, vsync-, hsync-, DP-A protocol, complete
|
|
|
* raster, associate with display controller)
|
|
@@ -863,186 +1154,74 @@ static int tegra_output_sor_enable(struct tegra_output *output)
|
|
|
tegra_sor_writel(sor, value, SOR_HEAD_STATE_2(0));
|
|
|
|
|
|
vbe = vse + (mode->vsync_start - mode->vdisplay);
|
|
|
- hbe = hse + (mode->hsync_start - mode->hdisplay);
|
|
|
-
|
|
|
- value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff);
|
|
|
- tegra_sor_writel(sor, value, SOR_HEAD_STATE_3(0));
|
|
|
-
|
|
|
- vbs = vbe + mode->vdisplay;
|
|
|
- hbs = hbe + mode->hdisplay;
|
|
|
-
|
|
|
- value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff);
|
|
|
- tegra_sor_writel(sor, value, SOR_HEAD_STATE_4(0));
|
|
|
-
|
|
|
- /* CSTM (LVDS, link A/B, upper) */
|
|
|
- value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B |
|
|
|
- SOR_CSTM_UPPER;
|
|
|
- tegra_sor_writel(sor, value, SOR_CSTM);
|
|
|
-
|
|
|
- /* PWM setup */
|
|
|
- err = tegra_sor_setup_pwm(sor, 250);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to setup PWM: %d\n", err);
|
|
|
- goto unlock;
|
|
|
- }
|
|
|
-
|
|
|
- value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
|
|
|
- value |= SOR_ENABLE;
|
|
|
- tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
|
|
|
-
|
|
|
- tegra_sor_update(sor);
|
|
|
-
|
|
|
- err = tegra_sor_attach(sor);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to attach SOR: %d\n", err);
|
|
|
- goto unlock;
|
|
|
- }
|
|
|
-
|
|
|
- err = tegra_sor_wakeup(sor);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to enable DC: %d\n", err);
|
|
|
- goto unlock;
|
|
|
- }
|
|
|
-
|
|
|
- sor->enabled = true;
|
|
|
-
|
|
|
-unlock:
|
|
|
- mutex_unlock(&sor->lock);
|
|
|
- return err;
|
|
|
-}
|
|
|
-
|
|
|
-static int tegra_sor_detach(struct tegra_sor *sor)
|
|
|
-{
|
|
|
- unsigned long value, timeout;
|
|
|
-
|
|
|
- /* switch to safe mode */
|
|
|
- value = tegra_sor_readl(sor, SOR_SUPER_STATE_1);
|
|
|
- value &= ~SOR_SUPER_STATE_MODE_NORMAL;
|
|
|
- tegra_sor_writel(sor, value, SOR_SUPER_STATE_1);
|
|
|
- tegra_sor_super_update(sor);
|
|
|
-
|
|
|
- timeout = jiffies + msecs_to_jiffies(250);
|
|
|
-
|
|
|
- while (time_before(jiffies, timeout)) {
|
|
|
- value = tegra_sor_readl(sor, SOR_PWR);
|
|
|
- if (value & SOR_PWR_MODE_SAFE)
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if ((value & SOR_PWR_MODE_SAFE) == 0)
|
|
|
- return -ETIMEDOUT;
|
|
|
-
|
|
|
- /* go to sleep */
|
|
|
- value = tegra_sor_readl(sor, SOR_SUPER_STATE_1);
|
|
|
- value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK;
|
|
|
- tegra_sor_writel(sor, value, SOR_SUPER_STATE_1);
|
|
|
- tegra_sor_super_update(sor);
|
|
|
-
|
|
|
- /* detach */
|
|
|
- value = tegra_sor_readl(sor, SOR_SUPER_STATE_1);
|
|
|
- value &= ~SOR_SUPER_STATE_ATTACHED;
|
|
|
- tegra_sor_writel(sor, value, SOR_SUPER_STATE_1);
|
|
|
- tegra_sor_super_update(sor);
|
|
|
-
|
|
|
- timeout = jiffies + msecs_to_jiffies(250);
|
|
|
-
|
|
|
- while (time_before(jiffies, timeout)) {
|
|
|
- value = tegra_sor_readl(sor, SOR_TEST);
|
|
|
- if ((value & SOR_TEST_ATTACHED) == 0)
|
|
|
- break;
|
|
|
-
|
|
|
- usleep_range(25, 100);
|
|
|
- }
|
|
|
-
|
|
|
- if ((value & SOR_TEST_ATTACHED) != 0)
|
|
|
- return -ETIMEDOUT;
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int tegra_sor_power_down(struct tegra_sor *sor)
|
|
|
-{
|
|
|
- unsigned long value, timeout;
|
|
|
- int err;
|
|
|
-
|
|
|
- value = tegra_sor_readl(sor, SOR_PWR);
|
|
|
- value &= ~SOR_PWR_NORMAL_STATE_PU;
|
|
|
- value |= SOR_PWR_TRIGGER;
|
|
|
- tegra_sor_writel(sor, value, SOR_PWR);
|
|
|
-
|
|
|
- timeout = jiffies + msecs_to_jiffies(250);
|
|
|
-
|
|
|
- while (time_before(jiffies, timeout)) {
|
|
|
- value = tegra_sor_readl(sor, SOR_PWR);
|
|
|
- if ((value & SOR_PWR_TRIGGER) == 0)
|
|
|
- return 0;
|
|
|
-
|
|
|
- usleep_range(25, 100);
|
|
|
- }
|
|
|
-
|
|
|
- if ((value & SOR_PWR_TRIGGER) != 0)
|
|
|
- return -ETIMEDOUT;
|
|
|
-
|
|
|
- err = clk_set_parent(sor->clk, sor->clk_safe);
|
|
|
- if (err < 0)
|
|
|
- dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
|
|
|
+ hbe = hse + (mode->hsync_start - mode->hdisplay);
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_DP_PADCTL_0);
|
|
|
- value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
|
|
|
- SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2);
|
|
|
- tegra_sor_writel(sor, value, SOR_DP_PADCTL_0);
|
|
|
+ value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff);
|
|
|
+ tegra_sor_writel(sor, value, SOR_HEAD_STATE_3(0));
|
|
|
|
|
|
- /* stop lane sequencer */
|
|
|
- value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP |
|
|
|
- SOR_LANE_SEQ_CTL_POWER_STATE_DOWN;
|
|
|
- tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
|
|
|
+ vbs = vbe + mode->vdisplay;
|
|
|
+ hbs = hbe + mode->hdisplay;
|
|
|
|
|
|
- timeout = jiffies + msecs_to_jiffies(250);
|
|
|
+ value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff);
|
|
|
+ tegra_sor_writel(sor, value, SOR_HEAD_STATE_4(0));
|
|
|
|
|
|
- while (time_before(jiffies, timeout)) {
|
|
|
- value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
|
|
|
- if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
|
|
|
- break;
|
|
|
+ /* CSTM (LVDS, link A/B, upper) */
|
|
|
+ value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B |
|
|
|
+ SOR_CSTM_UPPER;
|
|
|
+ tegra_sor_writel(sor, value, SOR_CSTM);
|
|
|
|
|
|
- usleep_range(25, 100);
|
|
|
+ /* PWM setup */
|
|
|
+ err = tegra_sor_setup_pwm(sor, 250);
|
|
|
+ if (err < 0) {
|
|
|
+ dev_err(sor->dev, "failed to setup PWM: %d\n", err);
|
|
|
+ goto unlock;
|
|
|
}
|
|
|
|
|
|
- if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0)
|
|
|
- return -ETIMEDOUT;
|
|
|
+ tegra_sor_update(sor);
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value |= SOR_PLL_2_PORT_POWERDOWN;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
|
|
|
+ value |= SOR_ENABLE;
|
|
|
+ tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
|
|
|
|
|
|
- usleep_range(20, 100);
|
|
|
+ tegra_dc_commit(dc);
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_0);
|
|
|
- value |= SOR_PLL_0_POWER_OFF;
|
|
|
- value |= SOR_PLL_0_VCOPD;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_0);
|
|
|
+ err = tegra_sor_attach(sor);
|
|
|
+ if (err < 0) {
|
|
|
+ dev_err(sor->dev, "failed to attach SOR: %d\n", err);
|
|
|
+ goto unlock;
|
|
|
+ }
|
|
|
|
|
|
- value = tegra_sor_readl(sor, SOR_PLL_2);
|
|
|
- value |= SOR_PLL_2_SEQ_PLLCAPPD;
|
|
|
- value |= SOR_PLL_2_SEQ_PLLCAPPD_ENFORCE;
|
|
|
- tegra_sor_writel(sor, value, SOR_PLL_2);
|
|
|
+ err = tegra_sor_wakeup(sor);
|
|
|
+ if (err < 0) {
|
|
|
+ dev_err(sor->dev, "failed to enable DC: %d\n", err);
|
|
|
+ goto unlock;
|
|
|
+ }
|
|
|
|
|
|
- usleep_range(20, 100);
|
|
|
+ if (output->panel)
|
|
|
+ drm_panel_enable(output->panel);
|
|
|
|
|
|
- return 0;
|
|
|
+ sor->enabled = true;
|
|
|
+
|
|
|
+unlock:
|
|
|
+ mutex_unlock(&sor->lock);
|
|
|
}
|
|
|
|
|
|
-static int tegra_output_sor_disable(struct tegra_output *output)
|
|
|
+static void tegra_sor_encoder_disable(struct drm_encoder *encoder)
|
|
|
{
|
|
|
- struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
|
|
|
+ struct tegra_output *output = encoder_to_output(encoder);
|
|
|
+ struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
|
|
|
struct tegra_sor *sor = to_sor(output);
|
|
|
- unsigned long value;
|
|
|
- int err = 0;
|
|
|
+ u32 value;
|
|
|
+ int err;
|
|
|
|
|
|
mutex_lock(&sor->lock);
|
|
|
|
|
|
if (!sor->enabled)
|
|
|
goto unlock;
|
|
|
|
|
|
+ if (output->panel)
|
|
|
+ drm_panel_disable(output->panel);
|
|
|
+
|
|
|
err = tegra_sor_detach(sor);
|
|
|
if (err < 0) {
|
|
|
dev_err(sor->dev, "failed to detach SOR: %d\n", err);
|
|
@@ -1057,31 +1236,11 @@ static int tegra_output_sor_disable(struct tegra_output *output)
|
|
|
* sure it's only executed when the output is attached to one.
|
|
|
*/
|
|
|
if (dc) {
|
|
|
- /*
|
|
|
- * XXX: We can't do this here because it causes the SOR to go
|
|
|
- * into an erroneous state and the output will look scrambled
|
|
|
- * the next time it is enabled. Presumably this is because we
|
|
|
- * should be doing this only on the next VBLANK. A possible
|
|
|
- * solution would be to queue a "power-off" event to trigger
|
|
|
- * this code to be run during the next VBLANK.
|
|
|
- */
|
|
|
- /*
|
|
|
- value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
|
|
|
- value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
|
|
|
- PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
|
|
|
- tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
|
|
|
- */
|
|
|
-
|
|
|
- value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
|
|
|
- value &= ~DISP_CTRL_MODE_MASK;
|
|
|
- tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
|
|
|
-
|
|
|
value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
|
|
|
value &= ~SOR_ENABLE;
|
|
|
tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
|
|
|
|
|
|
- tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
|
|
|
- tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
|
|
|
+ tegra_dc_commit(dc);
|
|
|
}
|
|
|
|
|
|
err = tegra_sor_power_down(sor);
|
|
@@ -1104,187 +1263,48 @@ static int tegra_output_sor_disable(struct tegra_output *output)
|
|
|
goto unlock;
|
|
|
}
|
|
|
|
|
|
- reset_control_assert(sor->rst);
|
|
|
+ if (output->panel)
|
|
|
+ drm_panel_unprepare(output->panel);
|
|
|
+
|
|
|
clk_disable_unprepare(sor->clk);
|
|
|
+ reset_control_assert(sor->rst);
|
|
|
|
|
|
sor->enabled = false;
|
|
|
|
|
|
unlock:
|
|
|
mutex_unlock(&sor->lock);
|
|
|
- return err;
|
|
|
}
|
|
|
|
|
|
-static int tegra_output_sor_setup_clock(struct tegra_output *output,
|
|
|
- struct clk *clk, unsigned long pclk,
|
|
|
- unsigned int *div)
|
|
|
+static int
|
|
|
+tegra_sor_encoder_atomic_check(struct drm_encoder *encoder,
|
|
|
+ struct drm_crtc_state *crtc_state,
|
|
|
+ struct drm_connector_state *conn_state)
|
|
|
{
|
|
|
+ struct tegra_output *output = encoder_to_output(encoder);
|
|
|
+ struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
|
|
|
+ unsigned long pclk = crtc_state->mode.clock * 1000;
|
|
|
struct tegra_sor *sor = to_sor(output);
|
|
|
int err;
|
|
|
|
|
|
- err = clk_set_parent(clk, sor->clk_parent);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to set parent clock: %d\n", err);
|
|
|
- return err;
|
|
|
- }
|
|
|
-
|
|
|
- err = clk_set_rate(sor->clk_parent, pclk);
|
|
|
+ err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent,
|
|
|
+ pclk, 0);
|
|
|
if (err < 0) {
|
|
|
- dev_err(sor->dev, "failed to set clock rate to %lu Hz\n", pclk);
|
|
|
+ dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
- *div = 0;
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int tegra_output_sor_check_mode(struct tegra_output *output,
|
|
|
- struct drm_display_mode *mode,
|
|
|
- enum drm_mode_status *status)
|
|
|
-{
|
|
|
- /*
|
|
|
- * FIXME: For now, always assume that the mode is okay.
|
|
|
- */
|
|
|
-
|
|
|
- *status = MODE_OK;
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static enum drm_connector_status
|
|
|
-tegra_output_sor_detect(struct tegra_output *output)
|
|
|
-{
|
|
|
- struct tegra_sor *sor = to_sor(output);
|
|
|
-
|
|
|
- if (sor->dpaux)
|
|
|
- return tegra_dpaux_detect(sor->dpaux);
|
|
|
-
|
|
|
- return connector_status_unknown;
|
|
|
-}
|
|
|
-
|
|
|
-static const struct tegra_output_ops sor_ops = {
|
|
|
- .enable = tegra_output_sor_enable,
|
|
|
- .disable = tegra_output_sor_disable,
|
|
|
- .setup_clock = tegra_output_sor_setup_clock,
|
|
|
- .check_mode = tegra_output_sor_check_mode,
|
|
|
- .detect = tegra_output_sor_detect,
|
|
|
-};
|
|
|
-
|
|
|
-static int tegra_sor_crc_open(struct inode *inode, struct file *file)
|
|
|
-{
|
|
|
- file->private_data = inode->i_private;
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int tegra_sor_crc_release(struct inode *inode, struct file *file)
|
|
|
-{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout)
|
|
|
-{
|
|
|
- u32 value;
|
|
|
-
|
|
|
- timeout = jiffies + msecs_to_jiffies(timeout);
|
|
|
-
|
|
|
- while (time_before(jiffies, timeout)) {
|
|
|
- value = tegra_sor_readl(sor, SOR_CRC_A);
|
|
|
- if (value & SOR_CRC_A_VALID)
|
|
|
- return 0;
|
|
|
-
|
|
|
- usleep_range(100, 200);
|
|
|
- }
|
|
|
-
|
|
|
- return -ETIMEDOUT;
|
|
|
-}
|
|
|
-
|
|
|
-static ssize_t tegra_sor_crc_read(struct file *file, char __user *buffer,
|
|
|
- size_t size, loff_t *ppos)
|
|
|
-{
|
|
|
- struct tegra_sor *sor = file->private_data;
|
|
|
- ssize_t num, err;
|
|
|
- char buf[10];
|
|
|
- u32 value;
|
|
|
-
|
|
|
- mutex_lock(&sor->lock);
|
|
|
-
|
|
|
- if (!sor->enabled) {
|
|
|
- err = -EAGAIN;
|
|
|
- goto unlock;
|
|
|
- }
|
|
|
-
|
|
|
- value = tegra_sor_readl(sor, SOR_STATE_1);
|
|
|
- value &= ~SOR_STATE_ASY_CRC_MODE_MASK;
|
|
|
- tegra_sor_writel(sor, value, SOR_STATE_1);
|
|
|
-
|
|
|
- value = tegra_sor_readl(sor, SOR_CRC_CNTRL);
|
|
|
- value |= SOR_CRC_CNTRL_ENABLE;
|
|
|
- tegra_sor_writel(sor, value, SOR_CRC_CNTRL);
|
|
|
-
|
|
|
- value = tegra_sor_readl(sor, SOR_TEST);
|
|
|
- value &= ~SOR_TEST_CRC_POST_SERIALIZE;
|
|
|
- tegra_sor_writel(sor, value, SOR_TEST);
|
|
|
-
|
|
|
- err = tegra_sor_crc_wait(sor, 100);
|
|
|
- if (err < 0)
|
|
|
- goto unlock;
|
|
|
-
|
|
|
- tegra_sor_writel(sor, SOR_CRC_A_RESET, SOR_CRC_A);
|
|
|
- value = tegra_sor_readl(sor, SOR_CRC_B);
|
|
|
-
|
|
|
- num = scnprintf(buf, sizeof(buf), "%08x\n", value);
|
|
|
-
|
|
|
- err = simple_read_from_buffer(buffer, size, ppos, buf, num);
|
|
|
-
|
|
|
-unlock:
|
|
|
- mutex_unlock(&sor->lock);
|
|
|
- return err;
|
|
|
-}
|
|
|
-
|
|
|
-static const struct file_operations tegra_sor_crc_fops = {
|
|
|
- .owner = THIS_MODULE,
|
|
|
- .open = tegra_sor_crc_open,
|
|
|
- .read = tegra_sor_crc_read,
|
|
|
- .release = tegra_sor_crc_release,
|
|
|
+static const struct drm_encoder_helper_funcs tegra_sor_encoder_helper_funcs = {
|
|
|
+ .dpms = tegra_sor_encoder_dpms,
|
|
|
+ .prepare = tegra_sor_encoder_prepare,
|
|
|
+ .commit = tegra_sor_encoder_commit,
|
|
|
+ .mode_set = tegra_sor_encoder_mode_set,
|
|
|
+ .disable = tegra_sor_encoder_disable,
|
|
|
+ .atomic_check = tegra_sor_encoder_atomic_check,
|
|
|
};
|
|
|
|
|
|
-static int tegra_sor_debugfs_init(struct tegra_sor *sor,
|
|
|
- struct drm_minor *minor)
|
|
|
-{
|
|
|
- struct dentry *entry;
|
|
|
- int err = 0;
|
|
|
-
|
|
|
- sor->debugfs = debugfs_create_dir("sor", minor->debugfs_root);
|
|
|
- if (!sor->debugfs)
|
|
|
- return -ENOMEM;
|
|
|
-
|
|
|
- entry = debugfs_create_file("crc", 0644, sor->debugfs, sor,
|
|
|
- &tegra_sor_crc_fops);
|
|
|
- if (!entry) {
|
|
|
- dev_err(sor->dev,
|
|
|
- "cannot create /sys/kernel/debug/dri/%s/sor/crc\n",
|
|
|
- minor->debugfs_root->d_name.name);
|
|
|
- err = -ENOMEM;
|
|
|
- goto remove;
|
|
|
- }
|
|
|
-
|
|
|
- return err;
|
|
|
-
|
|
|
-remove:
|
|
|
- debugfs_remove(sor->debugfs);
|
|
|
- sor->debugfs = NULL;
|
|
|
- return err;
|
|
|
-}
|
|
|
-
|
|
|
-static int tegra_sor_debugfs_exit(struct tegra_sor *sor)
|
|
|
-{
|
|
|
- debugfs_remove_recursive(sor->debugfs);
|
|
|
- sor->debugfs = NULL;
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
static int tegra_sor_init(struct host1x_client *client)
|
|
|
{
|
|
|
struct drm_device *drm = dev_get_drvdata(client->parent);
|
|
@@ -1294,17 +1314,32 @@ static int tegra_sor_init(struct host1x_client *client)
|
|
|
if (!sor->dpaux)
|
|
|
return -ENODEV;
|
|
|
|
|
|
- sor->output.type = TEGRA_OUTPUT_EDP;
|
|
|
-
|
|
|
sor->output.dev = sor->dev;
|
|
|
- sor->output.ops = &sor_ops;
|
|
|
+
|
|
|
+ drm_connector_init(drm, &sor->output.connector,
|
|
|
+ &tegra_sor_connector_funcs,
|
|
|
+ DRM_MODE_CONNECTOR_eDP);
|
|
|
+ drm_connector_helper_add(&sor->output.connector,
|
|
|
+ &tegra_sor_connector_helper_funcs);
|
|
|
+ sor->output.connector.dpms = DRM_MODE_DPMS_OFF;
|
|
|
+
|
|
|
+ drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs,
|
|
|
+ DRM_MODE_ENCODER_TMDS);
|
|
|
+ drm_encoder_helper_add(&sor->output.encoder,
|
|
|
+ &tegra_sor_encoder_helper_funcs);
|
|
|
+
|
|
|
+ drm_mode_connector_attach_encoder(&sor->output.connector,
|
|
|
+ &sor->output.encoder);
|
|
|
+ drm_connector_register(&sor->output.connector);
|
|
|
|
|
|
err = tegra_output_init(drm, &sor->output);
|
|
|
if (err < 0) {
|
|
|
- dev_err(sor->dev, "output setup failed: %d\n", err);
|
|
|
+ dev_err(client->dev, "failed to initialize output: %d\n", err);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
+ sor->output.encoder.possible_crtcs = 0x3;
|
|
|
+
|
|
|
if (IS_ENABLED(CONFIG_DEBUG_FS)) {
|
|
|
err = tegra_sor_debugfs_init(sor, drm->primary);
|
|
|
if (err < 0)
|
|
@@ -1319,6 +1354,20 @@ static int tegra_sor_init(struct host1x_client *client)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ err = clk_prepare_enable(sor->clk);
|
|
|
+ if (err < 0) {
|
|
|
+ dev_err(sor->dev, "failed to enable clock: %d\n", err);
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+
|
|
|
+ err = clk_prepare_enable(sor->clk_safe);
|
|
|
+ if (err < 0)
|
|
|
+ return err;
|
|
|
+
|
|
|
+ err = clk_prepare_enable(sor->clk_dp);
|
|
|
+ if (err < 0)
|
|
|
+ return err;
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -1327,11 +1376,7 @@ static int tegra_sor_exit(struct host1x_client *client)
|
|
|
struct tegra_sor *sor = host1x_client_to_sor(client);
|
|
|
int err;
|
|
|
|
|
|
- err = tegra_output_disable(&sor->output);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "output failed to disable: %d\n", err);
|
|
|
- return err;
|
|
|
- }
|
|
|
+ tegra_output_exit(&sor->output);
|
|
|
|
|
|
if (sor->dpaux) {
|
|
|
err = tegra_dpaux_detach(sor->dpaux);
|
|
@@ -1341,17 +1386,12 @@ static int tegra_sor_exit(struct host1x_client *client)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (IS_ENABLED(CONFIG_DEBUG_FS)) {
|
|
|
- err = tegra_sor_debugfs_exit(sor);
|
|
|
- if (err < 0)
|
|
|
- dev_err(sor->dev, "debugfs cleanup failed: %d\n", err);
|
|
|
- }
|
|
|
+ clk_disable_unprepare(sor->clk_safe);
|
|
|
+ clk_disable_unprepare(sor->clk_dp);
|
|
|
+ clk_disable_unprepare(sor->clk);
|
|
|
|
|
|
- err = tegra_output_exit(&sor->output);
|
|
|
- if (err < 0) {
|
|
|
- dev_err(sor->dev, "output cleanup failed: %d\n", err);
|
|
|
- return err;
|
|
|
- }
|
|
|
+ if (IS_ENABLED(CONFIG_DEBUG_FS))
|
|
|
+ tegra_sor_debugfs_exit(sor);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -1404,26 +1444,14 @@ static int tegra_sor_probe(struct platform_device *pdev)
|
|
|
if (IS_ERR(sor->clk_parent))
|
|
|
return PTR_ERR(sor->clk_parent);
|
|
|
|
|
|
- err = clk_prepare_enable(sor->clk_parent);
|
|
|
- if (err < 0)
|
|
|
- return err;
|
|
|
-
|
|
|
sor->clk_safe = devm_clk_get(&pdev->dev, "safe");
|
|
|
if (IS_ERR(sor->clk_safe))
|
|
|
return PTR_ERR(sor->clk_safe);
|
|
|
|
|
|
- err = clk_prepare_enable(sor->clk_safe);
|
|
|
- if (err < 0)
|
|
|
- return err;
|
|
|
-
|
|
|
sor->clk_dp = devm_clk_get(&pdev->dev, "dp");
|
|
|
if (IS_ERR(sor->clk_dp))
|
|
|
return PTR_ERR(sor->clk_dp);
|
|
|
|
|
|
- err = clk_prepare_enable(sor->clk_dp);
|
|
|
- if (err < 0)
|
|
|
- return err;
|
|
|
-
|
|
|
INIT_LIST_HEAD(&sor->client.list);
|
|
|
sor->client.ops = &sor_client_ops;
|
|
|
sor->client.dev = &pdev->dev;
|
|
@@ -1454,10 +1482,7 @@ static int tegra_sor_remove(struct platform_device *pdev)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
- clk_disable_unprepare(sor->clk_parent);
|
|
|
- clk_disable_unprepare(sor->clk_safe);
|
|
|
- clk_disable_unprepare(sor->clk_dp);
|
|
|
- clk_disable_unprepare(sor->clk);
|
|
|
+ tegra_output_remove(&sor->output);
|
|
|
|
|
|
return 0;
|
|
|
}
|