196f60e37SRussell King /* 296f60e37SRussell King * Copyright (C) 2012 Russell King 396f60e37SRussell King * 496f60e37SRussell King * This program is free software; you can redistribute it and/or modify 596f60e37SRussell King * it under the terms of the GNU General Public License version 2 as 696f60e37SRussell King * published by the Free Software Foundation. 796f60e37SRussell King * 896f60e37SRussell King * Armada 510 (aka Dove) variant support 996f60e37SRussell King */ 1096f60e37SRussell King #include <linux/clk.h> 1196f60e37SRussell King #include <linux/io.h> 1296f60e37SRussell King #include <drm/drmP.h> 1396f60e37SRussell King #include <drm/drm_crtc_helper.h> 1496f60e37SRussell King #include "armada_crtc.h" 1596f60e37SRussell King #include "armada_drm.h" 1696f60e37SRussell King #include "armada_hw.h" 1796f60e37SRussell King 18*3ecea269SRussell King static int armada510_crtc_init(struct armada_crtc *dcrtc, struct device *dev) 1996f60e37SRussell King { 20*3ecea269SRussell King struct clk *clk; 2196f60e37SRussell King 22*3ecea269SRussell King clk = devm_clk_get(dev, "ext_ref_clk_1"); 23*3ecea269SRussell King if (IS_ERR(clk)) 24*3ecea269SRussell King return PTR_ERR(clk) == -ENOENT ? -EPROBE_DEFER : PTR_ERR(clk); 2596f60e37SRussell King 26*3ecea269SRussell King dcrtc->extclk[0] = clk; 2796f60e37SRussell King 2896f60e37SRussell King /* Lower the watermark so to eliminate jitter at higher bandwidths */ 2996f60e37SRussell King armada_updatel(0x20, (1 << 11) | 0xff, dcrtc->base + LCD_CFG_RDREG4F); 30*3ecea269SRussell King 3196f60e37SRussell King return 0; 3296f60e37SRussell King } 3396f60e37SRussell King 3496f60e37SRussell King /* 3596f60e37SRussell King * Armada510 specific SCLK register selection. 3696f60e37SRussell King * This gets called with sclk = NULL to test whether the mode is 3796f60e37SRussell King * supportable, and again with sclk != NULL to set the clocks up for 3896f60e37SRussell King * that. The former can return an error, but the latter is expected 3996f60e37SRussell King * not to. 4096f60e37SRussell King * 4196f60e37SRussell King * We currently are pretty rudimentary here, always selecting 4296f60e37SRussell King * EXT_REF_CLK_1 for LCD0 and erroring LCD1. This needs improvement! 4396f60e37SRussell King */ 4496f60e37SRussell King static int armada510_crtc_compute_clock(struct armada_crtc *dcrtc, 4596f60e37SRussell King const struct drm_display_mode *mode, uint32_t *sclk) 4696f60e37SRussell King { 47*3ecea269SRussell King struct clk *clk = dcrtc->extclk[0]; 4896f60e37SRussell King int ret; 4996f60e37SRussell King 5096f60e37SRussell King if (dcrtc->num == 1) 5196f60e37SRussell King return -EINVAL; 5296f60e37SRussell King 5396f60e37SRussell King if (IS_ERR(clk)) 5496f60e37SRussell King return PTR_ERR(clk); 5596f60e37SRussell King 5696f60e37SRussell King if (dcrtc->clk != clk) { 5796f60e37SRussell King ret = clk_prepare_enable(clk); 5896f60e37SRussell King if (ret) 5996f60e37SRussell King return ret; 6096f60e37SRussell King dcrtc->clk = clk; 6196f60e37SRussell King } 6296f60e37SRussell King 6396f60e37SRussell King if (sclk) { 6496f60e37SRussell King uint32_t rate, ref, div; 6596f60e37SRussell King 6696f60e37SRussell King rate = mode->clock * 1000; 6796f60e37SRussell King ref = clk_round_rate(clk, rate); 6896f60e37SRussell King div = DIV_ROUND_UP(ref, rate); 6996f60e37SRussell King if (div < 1) 7096f60e37SRussell King div = 1; 7196f60e37SRussell King 7296f60e37SRussell King clk_set_rate(clk, ref); 7396f60e37SRussell King *sclk = div | SCLK_510_EXTCLK1; 7496f60e37SRussell King } 7596f60e37SRussell King 7696f60e37SRussell King return 0; 7796f60e37SRussell King } 7896f60e37SRussell King 7996f60e37SRussell King const struct armada_variant armada510_ops = { 8096f60e37SRussell King .has_spu_adv_reg = true, 81662af0d8SRussell King .spu_adv_reg = ADV_HWC32ENABLE | ADV_HWC32ARGB | ADV_HWC32BLEND, 8296f60e37SRussell King .crtc_init = armada510_crtc_init, 8396f60e37SRussell King .crtc_compute_clock = armada510_crtc_compute_clock, 8496f60e37SRussell King }; 85