Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/ast: Detect ast device type and config mode without ast device

Return the ast chip and config in the detection function's parameters
instead of storing them directly in the ast device instance.

v2:
* add break statements to switch default branches (Jocelyn)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231116100240.22975-10-tzimmermann@suse.de

+59 -47
+59 -47
drivers/gpu/drm/ast/ast_main.c
··· 76 76 __ast_write8_i(ioregs, AST_IO_VGACRI, 0x80, AST_IO_VGACR80_PASSWORD); 77 77 } 78 78 79 - static int ast_device_config_init(struct ast_device *ast) 79 + static int ast_detect_chip(struct pci_dev *pdev, 80 + void __iomem *regs, void __iomem *ioregs, 81 + enum ast_chip *chip_out, 82 + enum ast_config_mode *config_mode_out) 80 83 { 81 - struct drm_device *dev = &ast->base; 82 - struct pci_dev *pdev = to_pci_dev(dev->dev); 83 - struct device_node *np = dev->dev->of_node; 84 + struct device *dev = &pdev->dev; 85 + struct device_node *np = dev->of_node; 86 + enum ast_config_mode config_mode = ast_use_defaults; 84 87 uint32_t scu_rev = 0xffffffff; 88 + enum ast_chip chip; 85 89 u32 data; 86 - u8 jregd0, jregd1; 90 + u8 vgacrd0, vgacrd1; 87 91 88 92 /* 89 93 * Find configuration mode and read SCU revision 90 94 */ 91 95 92 - ast->config_mode = ast_use_defaults; 93 - 94 96 /* Check if we have device-tree properties */ 95 97 if (np && !of_property_read_u32(np, "aspeed,scu-revision-id", &data)) { 96 98 /* We do, disable P2A access */ 97 - ast->config_mode = ast_use_dt; 99 + config_mode = ast_use_dt; 98 100 scu_rev = data; 99 101 } else if (pdev->device == PCI_CHIP_AST2000) { // Not all families have a P2A bridge 100 102 /* ··· 104 102 * is disabled. We force using P2A if VGA only mode bit 105 103 * is set D[7] 106 104 */ 107 - jregd0 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff); 108 - jregd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff); 109 - if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) { 105 + vgacrd0 = __ast_read8_i(ioregs, AST_IO_VGACRI, 0xd0); 106 + vgacrd1 = __ast_read8_i(ioregs, AST_IO_VGACRI, 0xd1); 107 + if (!(vgacrd0 & 0x80) || !(vgacrd1 & 0x10)) { 110 108 111 109 /* 112 110 * We have a P2A bridge and it is enabled. ··· 114 112 115 113 /* Patch AST2500/AST2510 */ 116 114 if ((pdev->revision & 0xf0) == 0x40) { 117 - if (!(jregd0 & AST_VRAM_INIT_STATUS_MASK)) 118 - ast_patch_ahb_2500(ast->regs); 115 + if (!(vgacrd0 & AST_VRAM_INIT_STATUS_MASK)) 116 + ast_patch_ahb_2500(regs); 119 117 } 120 118 121 119 /* Double check that it's actually working */ 122 - data = ast_read32(ast, 0xf004); 120 + data = __ast_read32(regs, 0xf004); 123 121 if ((data != 0xffffffff) && (data != 0x00)) { 124 - ast->config_mode = ast_use_p2a; 122 + config_mode = ast_use_p2a; 125 123 126 124 /* Read SCU7c (silicon revision register) */ 127 - ast_write32(ast, 0xf004, 0x1e6e0000); 128 - ast_write32(ast, 0xf000, 0x1); 129 - scu_rev = ast_read32(ast, 0x1207c); 125 + __ast_write32(regs, 0xf004, 0x1e6e0000); 126 + __ast_write32(regs, 0xf000, 0x1); 127 + scu_rev = __ast_read32(regs, 0x1207c); 130 128 } 131 129 } 132 130 } 133 131 134 - switch (ast->config_mode) { 132 + switch (config_mode) { 135 133 case ast_use_defaults: 136 - drm_info(dev, "Using default configuration\n"); 134 + dev_info(dev, "Using default configuration\n"); 137 135 break; 138 136 case ast_use_dt: 139 - drm_info(dev, "Using device-tree for configuration\n"); 137 + dev_info(dev, "Using device-tree for configuration\n"); 140 138 break; 141 139 case ast_use_p2a: 142 - drm_info(dev, "Using P2A bridge for configuration\n"); 140 + dev_info(dev, "Using P2A bridge for configuration\n"); 143 141 break; 144 142 } 145 143 ··· 148 146 */ 149 147 150 148 if (pdev->revision >= 0x50) { 151 - ast->chip = AST2600; 152 - drm_info(dev, "AST 2600 detected\n"); 149 + chip = AST2600; 150 + dev_info(dev, "AST 2600 detected\n"); 153 151 } else if (pdev->revision >= 0x40) { 154 152 switch (scu_rev & 0x300) { 155 153 case 0x0100: 156 - ast->chip = AST2510; 157 - drm_info(dev, "AST 2510 detected\n"); 154 + chip = AST2510; 155 + dev_info(dev, "AST 2510 detected\n"); 158 156 break; 159 157 default: 160 - ast->chip = AST2500; 161 - drm_info(dev, "AST 2500 detected\n"); 158 + chip = AST2500; 159 + dev_info(dev, "AST 2500 detected\n"); 160 + break; 162 161 } 163 162 } else if (pdev->revision >= 0x30) { 164 163 switch (scu_rev & 0x300) { 165 164 case 0x0100: 166 - ast->chip = AST1400; 167 - drm_info(dev, "AST 1400 detected\n"); 165 + chip = AST1400; 166 + dev_info(dev, "AST 1400 detected\n"); 168 167 break; 169 168 default: 170 - ast->chip = AST2400; 171 - drm_info(dev, "AST 2400 detected\n"); 169 + chip = AST2400; 170 + dev_info(dev, "AST 2400 detected\n"); 171 + break; 172 172 } 173 173 } else if (pdev->revision >= 0x20) { 174 174 switch (scu_rev & 0x300) { 175 175 case 0x0000: 176 - ast->chip = AST1300; 177 - drm_info(dev, "AST 1300 detected\n"); 176 + chip = AST1300; 177 + dev_info(dev, "AST 1300 detected\n"); 178 178 break; 179 179 default: 180 - ast->chip = AST2300; 181 - drm_info(dev, "AST 2300 detected\n"); 180 + chip = AST2300; 181 + dev_info(dev, "AST 2300 detected\n"); 182 182 break; 183 183 } 184 184 } else if (pdev->revision >= 0x10) { 185 185 switch (scu_rev & 0x0300) { 186 186 case 0x0200: 187 - ast->chip = AST1100; 188 - drm_info(dev, "AST 1100 detected\n"); 187 + chip = AST1100; 188 + dev_info(dev, "AST 1100 detected\n"); 189 189 break; 190 190 case 0x0100: 191 - ast->chip = AST2200; 192 - drm_info(dev, "AST 2200 detected\n"); 191 + chip = AST2200; 192 + dev_info(dev, "AST 2200 detected\n"); 193 193 break; 194 194 case 0x0000: 195 - ast->chip = AST2150; 196 - drm_info(dev, "AST 2150 detected\n"); 195 + chip = AST2150; 196 + dev_info(dev, "AST 2150 detected\n"); 197 197 break; 198 198 default: 199 - ast->chip = AST2100; 200 - drm_info(dev, "AST 2100 detected\n"); 199 + chip = AST2100; 200 + dev_info(dev, "AST 2100 detected\n"); 201 201 break; 202 202 } 203 203 } else { 204 - ast->chip = AST2000; 205 - drm_info(dev, "AST 2000 detected\n"); 204 + chip = AST2000; 205 + dev_info(dev, "AST 2000 detected\n"); 206 206 } 207 + 208 + *chip_out = chip; 209 + *config_mode_out = config_mode; 207 210 208 211 return 0; 209 212 } ··· 438 431 int ret = 0; 439 432 void __iomem *regs; 440 433 void __iomem *ioregs; 434 + enum ast_config_mode config_mode; 435 + enum ast_chip chip; 441 436 442 437 ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base); 443 438 if (IS_ERR(ast)) ··· 511 502 if (ret) 512 503 return ERR_PTR(ret); 513 504 514 - ret = ast_device_config_init(ast); 505 + ret = ast_detect_chip(pdev, regs, ioregs, &chip, &config_mode); 515 506 if (ret) 516 507 return ERR_PTR(ret); 508 + 509 + ast->chip = chip; 510 + ast->config_mode = config_mode; 517 511 518 512 ast_detect_widescreen(ast); 519 513 ast_detect_tx_chip(ast, need_post);