Linux Audio

Check our new training course

Loading...
v6.13.7
  1/*
  2 * Copyright 2012 Red Hat Inc.
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the
  6 * "Software"), to deal in the Software without restriction, including
  7 * without limitation the rights to use, copy, modify, merge, publish,
  8 * distribute, sub license, and/or sell copies of the Software, and to
  9 * permit persons to whom the Software is furnished to do so, subject to
 10 * the following conditions:
 11 *
 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 19 *
 20 * The above copyright notice and this permission notice (including the
 21 * next paragraph) shall be included in all copies or substantial portions
 22 * of the Software.
 23 *
 24 */
 25/*
 26 * Authors: Dave Airlie <airlied@redhat.com>
 27 */
 28
 29#include <linux/of.h>
 30#include <linux/pci.h>
 31
 32#include <drm/drm_atomic_helper.h>
 33#include <drm/drm_drv.h>
 34#include <drm/drm_gem.h>
 35#include <drm/drm_managed.h>
 36
 37#include "ast_drv.h"
 38
 39static void ast_detect_widescreen(struct ast_device *ast)
 40{
 41	u8 jreg;
 42
 43	/* Check if we support wide screen */
 44	switch (AST_GEN(ast)) {
 45	case 1:
 46		ast->support_wide_screen = false;
 47		break;
 48	default:
 49		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
 50		if (!(jreg & 0x80))
 51			ast->support_wide_screen = true;
 52		else if (jreg & 0x01)
 53			ast->support_wide_screen = true;
 54		else {
 55			ast->support_wide_screen = false;
 56			if (ast->chip == AST1300)
 57				ast->support_wide_screen = true;
 58			if (ast->chip == AST1400)
 59				ast->support_wide_screen = true;
 60			if (ast->chip == AST2510)
 61				ast->support_wide_screen = true;
 62			if (IS_AST_GEN7(ast))
 63				ast->support_wide_screen = true;
 64		}
 65		break;
 66	}
 67}
 68
 69static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
 70{
 71	static const char * const info_str[] = {
 72		"analog VGA",
 73		"Sil164 TMDS transmitter",
 74		"DP501 DisplayPort transmitter",
 75		"ASPEED DisplayPort transmitter",
 76	};
 77
 78	struct drm_device *dev = &ast->base;
 79	u8 jreg, vgacrd1;
 80
 81	/*
 82	 * Several of the listed TX chips are not explicitly supported
 83	 * by the ast driver. If these exist in real-world devices, they
 84	 * are most likely reported as VGA or SIL164 outputs. We warn here
 85	 * to get bug reports for these devices. If none come in for some
 86	 * time, we can begin to fail device probing on these values.
 87	 */
 88	vgacrd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, AST_IO_VGACRD1_TX_TYPE_MASK);
 89	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_ITE66121_VBIOS,
 90		 "ITE IT66121 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
 91	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_CH7003_VBIOS,
 92		 "Chrontel CH7003 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
 93	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_ANX9807_VBIOS,
 94		 "Analogix ANX9807 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
 95
 96	/* Check 3rd Tx option (digital output afaik) */
 97	ast->tx_chip = AST_TX_NONE;
 98
 99	/*
100	 * VGACRA3 Enhanced Color Mode Register, check if DVO is already
101	 * enabled, in that case, assume we have a SIL164 TMDS transmitter
102	 *
103	 * Don't make that assumption if we the chip wasn't enabled and
104	 * is at power-on reset, otherwise we'll incorrectly "detect" a
105	 * SIL164 when there is none.
106	 */
107	if (!need_post) {
108		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xa3, 0xff);
109		if (jreg & 0x80)
110			ast->tx_chip = AST_TX_SIL164;
111	}
112
113	if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast) || IS_AST_GEN6(ast)) {
114		/*
115		 * On AST GEN4+, look the configuration set by the SoC in
116		 * the SOC scratch register #1 bits 11:8 (interestingly marked
117		 * as "reserved" in the spec)
118		 */
119		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1,
120					      AST_IO_VGACRD1_TX_TYPE_MASK);
121		switch (jreg) {
122		case AST_IO_VGACRD1_TX_SIL164_VBIOS:
123			ast->tx_chip = AST_TX_SIL164;
124			break;
125		case AST_IO_VGACRD1_TX_DP501_VBIOS:
126			ast->dp501_fw_addr = drmm_kzalloc(dev, 32*1024, GFP_KERNEL);
127			if (ast->dp501_fw_addr) {
128				/* backup firmware */
129				if (ast_backup_fw(ast, ast->dp501_fw_addr, 32*1024)) {
130					drmm_kfree(dev, ast->dp501_fw_addr);
131					ast->dp501_fw_addr = NULL;
132				}
133			}
134			fallthrough;
135		case AST_IO_VGACRD1_TX_FW_EMBEDDED_FW:
136			ast->tx_chip = AST_TX_DP501;
137		}
138	} else if (IS_AST_GEN7(ast)) {
139		if (ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, AST_IO_VGACRD1_TX_TYPE_MASK) ==
140		    AST_IO_VGACRD1_TX_ASTDP) {
141			int ret = ast_dp_launch(ast);
142
143			if (!ret)
144				ast->tx_chip = AST_TX_ASTDP;
145		}
146	}
147
148	drm_info(dev, "Using %s\n", info_str[ast->tx_chip]);
 
 
 
 
 
 
 
 
149}
150
151static int ast_get_dram_info(struct ast_device *ast)
152{
153	struct drm_device *dev = &ast->base;
154	struct device_node *np = dev->dev->of_node;
 
155	uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap;
156	uint32_t denum, num, div, ref_pll, dsel;
157
158	switch (ast->config_mode) {
159	case ast_use_dt:
160		/*
161		 * If some properties are missing, use reasonable
162		 * defaults for GEN5
163		 */
164		if (of_property_read_u32(np, "aspeed,mcr-configuration",
165					 &mcr_cfg))
166			mcr_cfg = 0x00000577;
167		if (of_property_read_u32(np, "aspeed,mcr-scu-mpll",
168					 &mcr_scu_mpll))
169			mcr_scu_mpll = 0x000050C0;
170		if (of_property_read_u32(np, "aspeed,mcr-scu-strap",
171					 &mcr_scu_strap))
172			mcr_scu_strap = 0;
173		break;
174	case ast_use_p2a:
175		ast_write32(ast, 0xf004, 0x1e6e0000);
176		ast_write32(ast, 0xf000, 0x1);
177		mcr_cfg = ast_read32(ast, 0x10004);
178		mcr_scu_mpll = ast_read32(ast, 0x10120);
179		mcr_scu_strap = ast_read32(ast, 0x10170);
180		break;
181	case ast_use_defaults:
182	default:
183		ast->dram_bus_width = 16;
184		ast->dram_type = AST_DRAM_1Gx16;
185		if (IS_AST_GEN6(ast))
186			ast->mclk = 800;
187		else
188			ast->mclk = 396;
189		return 0;
190	}
191
192	if (mcr_cfg & 0x40)
193		ast->dram_bus_width = 16;
194	else
195		ast->dram_bus_width = 32;
196
197	if (IS_AST_GEN6(ast)) {
198		switch (mcr_cfg & 0x03) {
199		case 0:
200			ast->dram_type = AST_DRAM_1Gx16;
201			break;
202		default:
203		case 1:
204			ast->dram_type = AST_DRAM_2Gx16;
205			break;
206		case 2:
207			ast->dram_type = AST_DRAM_4Gx16;
208			break;
209		case 3:
210			ast->dram_type = AST_DRAM_8Gx16;
211			break;
212		}
213	} else if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
214		switch (mcr_cfg & 0x03) {
215		case 0:
216			ast->dram_type = AST_DRAM_512Mx16;
217			break;
218		default:
219		case 1:
220			ast->dram_type = AST_DRAM_1Gx16;
221			break;
222		case 2:
223			ast->dram_type = AST_DRAM_2Gx16;
224			break;
225		case 3:
226			ast->dram_type = AST_DRAM_4Gx16;
227			break;
228		}
229	} else {
230		switch (mcr_cfg & 0x0c) {
231		case 0:
232		case 4:
233			ast->dram_type = AST_DRAM_512Mx16;
234			break;
235		case 8:
236			if (mcr_cfg & 0x40)
237				ast->dram_type = AST_DRAM_1Gx16;
238			else
239				ast->dram_type = AST_DRAM_512Mx32;
240			break;
241		case 0xc:
242			ast->dram_type = AST_DRAM_1Gx32;
243			break;
244		}
245	}
246
247	if (mcr_scu_strap & 0x2000)
248		ref_pll = 14318;
249	else
250		ref_pll = 12000;
251
252	denum = mcr_scu_mpll & 0x1f;
253	num = (mcr_scu_mpll & 0x3fe0) >> 5;
254	dsel = (mcr_scu_mpll & 0xc000) >> 14;
255	switch (dsel) {
256	case 3:
257		div = 0x4;
258		break;
259	case 2:
260	case 1:
261		div = 0x2;
262		break;
263	default:
264		div = 0x1;
265		break;
266	}
267	ast->mclk = ref_pll * (num + 2) / ((denum + 2) * (div * 1000));
268	return 0;
269}
270
271struct drm_device *ast_device_create(struct pci_dev *pdev,
272				     const struct drm_driver *drv,
273				     enum ast_chip chip,
274				     enum ast_config_mode config_mode,
275				     void __iomem *regs,
276				     void __iomem *ioregs,
277				     bool need_post)
278{
279	struct drm_device *dev;
280	struct ast_device *ast;
281	int ret;
282
283	ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);
284	if (IS_ERR(ast))
285		return ERR_CAST(ast);
286	dev = &ast->base;
287
288	ast->chip = chip;
289	ast->config_mode = config_mode;
290	ast->regs = regs;
291	ast->ioregs = ioregs;
292
293	ast_detect_widescreen(ast);
294	ast_detect_tx_chip(ast, need_post);
295
296	ret = ast_get_dram_info(ast);
297	if (ret)
298		return ERR_PTR(ret);
299
300	drm_info(dev, "dram MCLK=%u Mhz type=%d bus_width=%d\n",
301		 ast->mclk, ast->dram_type, ast->dram_bus_width);
302
303	if (need_post)
304		ast_post_gpu(ast);
305
306	ret = ast_mm_init(ast);
307	if (ret)
308		return ERR_PTR(ret);
309
310	/* map reserved buffer */
311	ast->dp501_fw_buf = NULL;
312	if (ast->vram_size < pci_resource_len(pdev, 0)) {
313		ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0);
314		if (!ast->dp501_fw_buf)
315			drm_info(dev, "failed to map reserved buffer!\n");
316	}
317
318	ret = ast_mode_config_init(ast);
319	if (ret)
320		return ERR_PTR(ret);
321
322	return dev;
323}
v6.9.4
  1/*
  2 * Copyright 2012 Red Hat Inc.
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the
  6 * "Software"), to deal in the Software without restriction, including
  7 * without limitation the rights to use, copy, modify, merge, publish,
  8 * distribute, sub license, and/or sell copies of the Software, and to
  9 * permit persons to whom the Software is furnished to do so, subject to
 10 * the following conditions:
 11 *
 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 19 *
 20 * The above copyright notice and this permission notice (including the
 21 * next paragraph) shall be included in all copies or substantial portions
 22 * of the Software.
 23 *
 24 */
 25/*
 26 * Authors: Dave Airlie <airlied@redhat.com>
 27 */
 28
 
 29#include <linux/pci.h>
 30
 31#include <drm/drm_atomic_helper.h>
 32#include <drm/drm_drv.h>
 33#include <drm/drm_gem.h>
 34#include <drm/drm_managed.h>
 35
 36#include "ast_drv.h"
 37
 38static void ast_detect_widescreen(struct ast_device *ast)
 39{
 40	u8 jreg;
 41
 42	/* Check if we support wide screen */
 43	switch (AST_GEN(ast)) {
 44	case 1:
 45		ast->support_wide_screen = false;
 46		break;
 47	default:
 48		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
 49		if (!(jreg & 0x80))
 50			ast->support_wide_screen = true;
 51		else if (jreg & 0x01)
 52			ast->support_wide_screen = true;
 53		else {
 54			ast->support_wide_screen = false;
 55			if (ast->chip == AST1300)
 56				ast->support_wide_screen = true;
 57			if (ast->chip == AST1400)
 58				ast->support_wide_screen = true;
 59			if (ast->chip == AST2510)
 60				ast->support_wide_screen = true;
 61			if (IS_AST_GEN7(ast))
 62				ast->support_wide_screen = true;
 63		}
 64		break;
 65	}
 66}
 67
 68static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
 69{
 
 
 
 
 
 
 
 70	struct drm_device *dev = &ast->base;
 71	u8 jreg;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 72
 73	/* Check 3rd Tx option (digital output afaik) */
 74	ast->tx_chip_types |= AST_TX_NONE_BIT;
 75
 76	/*
 77	 * VGACRA3 Enhanced Color Mode Register, check if DVO is already
 78	 * enabled, in that case, assume we have a SIL164 TMDS transmitter
 79	 *
 80	 * Don't make that assumption if we the chip wasn't enabled and
 81	 * is at power-on reset, otherwise we'll incorrectly "detect" a
 82	 * SIL164 when there is none.
 83	 */
 84	if (!need_post) {
 85		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xa3, 0xff);
 86		if (jreg & 0x80)
 87			ast->tx_chip_types = AST_TX_SIL164_BIT;
 88	}
 89
 90	if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast) || IS_AST_GEN6(ast)) {
 91		/*
 92		 * On AST GEN4+, look the configuration set by the SoC in
 93		 * the SOC scratch register #1 bits 11:8 (interestingly marked
 94		 * as "reserved" in the spec)
 95		 */
 96		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff);
 
 97		switch (jreg) {
 98		case 0x04:
 99			ast->tx_chip_types = AST_TX_SIL164_BIT;
100			break;
101		case 0x08:
102			ast->dp501_fw_addr = drmm_kzalloc(dev, 32*1024, GFP_KERNEL);
103			if (ast->dp501_fw_addr) {
104				/* backup firmware */
105				if (ast_backup_fw(dev, ast->dp501_fw_addr, 32*1024)) {
106					drmm_kfree(dev, ast->dp501_fw_addr);
107					ast->dp501_fw_addr = NULL;
108				}
109			}
110			fallthrough;
111		case 0x0c:
112			ast->tx_chip_types = AST_TX_DP501_BIT;
113		}
114	} else if (IS_AST_GEN7(ast)) {
115		if (ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xD1, TX_TYPE_MASK) ==
116		    ASTDP_DPMCU_TX) {
117			ast->tx_chip_types = AST_TX_ASTDP_BIT;
118			ast_dp_launch(&ast->base);
 
 
119		}
120	}
121
122	/* Print stuff for diagnostic purposes */
123	if (ast->tx_chip_types & AST_TX_NONE_BIT)
124		drm_info(dev, "Using analog VGA\n");
125	if (ast->tx_chip_types & AST_TX_SIL164_BIT)
126		drm_info(dev, "Using Sil164 TMDS transmitter\n");
127	if (ast->tx_chip_types & AST_TX_DP501_BIT)
128		drm_info(dev, "Using DP501 DisplayPort transmitter\n");
129	if (ast->tx_chip_types & AST_TX_ASTDP_BIT)
130		drm_info(dev, "Using ASPEED DisplayPort transmitter\n");
131}
132
133static int ast_get_dram_info(struct drm_device *dev)
134{
 
135	struct device_node *np = dev->dev->of_node;
136	struct ast_device *ast = to_ast_device(dev);
137	uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap;
138	uint32_t denum, num, div, ref_pll, dsel;
139
140	switch (ast->config_mode) {
141	case ast_use_dt:
142		/*
143		 * If some properties are missing, use reasonable
144		 * defaults for GEN5
145		 */
146		if (of_property_read_u32(np, "aspeed,mcr-configuration",
147					 &mcr_cfg))
148			mcr_cfg = 0x00000577;
149		if (of_property_read_u32(np, "aspeed,mcr-scu-mpll",
150					 &mcr_scu_mpll))
151			mcr_scu_mpll = 0x000050C0;
152		if (of_property_read_u32(np, "aspeed,mcr-scu-strap",
153					 &mcr_scu_strap))
154			mcr_scu_strap = 0;
155		break;
156	case ast_use_p2a:
157		ast_write32(ast, 0xf004, 0x1e6e0000);
158		ast_write32(ast, 0xf000, 0x1);
159		mcr_cfg = ast_read32(ast, 0x10004);
160		mcr_scu_mpll = ast_read32(ast, 0x10120);
161		mcr_scu_strap = ast_read32(ast, 0x10170);
162		break;
163	case ast_use_defaults:
164	default:
165		ast->dram_bus_width = 16;
166		ast->dram_type = AST_DRAM_1Gx16;
167		if (IS_AST_GEN6(ast))
168			ast->mclk = 800;
169		else
170			ast->mclk = 396;
171		return 0;
172	}
173
174	if (mcr_cfg & 0x40)
175		ast->dram_bus_width = 16;
176	else
177		ast->dram_bus_width = 32;
178
179	if (IS_AST_GEN6(ast)) {
180		switch (mcr_cfg & 0x03) {
181		case 0:
182			ast->dram_type = AST_DRAM_1Gx16;
183			break;
184		default:
185		case 1:
186			ast->dram_type = AST_DRAM_2Gx16;
187			break;
188		case 2:
189			ast->dram_type = AST_DRAM_4Gx16;
190			break;
191		case 3:
192			ast->dram_type = AST_DRAM_8Gx16;
193			break;
194		}
195	} else if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
196		switch (mcr_cfg & 0x03) {
197		case 0:
198			ast->dram_type = AST_DRAM_512Mx16;
199			break;
200		default:
201		case 1:
202			ast->dram_type = AST_DRAM_1Gx16;
203			break;
204		case 2:
205			ast->dram_type = AST_DRAM_2Gx16;
206			break;
207		case 3:
208			ast->dram_type = AST_DRAM_4Gx16;
209			break;
210		}
211	} else {
212		switch (mcr_cfg & 0x0c) {
213		case 0:
214		case 4:
215			ast->dram_type = AST_DRAM_512Mx16;
216			break;
217		case 8:
218			if (mcr_cfg & 0x40)
219				ast->dram_type = AST_DRAM_1Gx16;
220			else
221				ast->dram_type = AST_DRAM_512Mx32;
222			break;
223		case 0xc:
224			ast->dram_type = AST_DRAM_1Gx32;
225			break;
226		}
227	}
228
229	if (mcr_scu_strap & 0x2000)
230		ref_pll = 14318;
231	else
232		ref_pll = 12000;
233
234	denum = mcr_scu_mpll & 0x1f;
235	num = (mcr_scu_mpll & 0x3fe0) >> 5;
236	dsel = (mcr_scu_mpll & 0xc000) >> 14;
237	switch (dsel) {
238	case 3:
239		div = 0x4;
240		break;
241	case 2:
242	case 1:
243		div = 0x2;
244		break;
245	default:
246		div = 0x1;
247		break;
248	}
249	ast->mclk = ref_pll * (num + 2) / ((denum + 2) * (div * 1000));
250	return 0;
251}
252
253struct drm_device *ast_device_create(struct pci_dev *pdev,
254				     const struct drm_driver *drv,
255				     enum ast_chip chip,
256				     enum ast_config_mode config_mode,
257				     void __iomem *regs,
258				     void __iomem *ioregs,
259				     bool need_post)
260{
261	struct drm_device *dev;
262	struct ast_device *ast;
263	int ret;
264
265	ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);
266	if (IS_ERR(ast))
267		return ERR_CAST(ast);
268	dev = &ast->base;
269
270	ast->chip = chip;
271	ast->config_mode = config_mode;
272	ast->regs = regs;
273	ast->ioregs = ioregs;
274
275	ast_detect_widescreen(ast);
276	ast_detect_tx_chip(ast, need_post);
277
278	ret = ast_get_dram_info(dev);
279	if (ret)
280		return ERR_PTR(ret);
281
282	drm_info(dev, "dram MCLK=%u Mhz type=%d bus_width=%d\n",
283		 ast->mclk, ast->dram_type, ast->dram_bus_width);
284
285	if (need_post)
286		ast_post_gpu(dev);
287
288	ret = ast_mm_init(ast);
289	if (ret)
290		return ERR_PTR(ret);
291
292	/* map reserved buffer */
293	ast->dp501_fw_buf = NULL;
294	if (ast->vram_size < pci_resource_len(pdev, 0)) {
295		ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0);
296		if (!ast->dp501_fw_buf)
297			drm_info(dev, "failed to map reserved buffer!\n");
298	}
299
300	ret = ast_mode_config_init(ast);
301	if (ret)
302		return ERR_PTR(ret);
303
304	return dev;
305}