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

Merge branch 'imx-drm-staging' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into staging-next

Russell writes:

These changes, which convert imx-drm to use the recently merged
component infrastructure, have been reviewed and acked by Philipp Zabel,
Shawn Guo and Fabio Estevam, and are now deemed to be ready.

+936 -1515
+8 -2
arch/arm/boot/dts/imx51-babbage.dts
··· 21 21 reg = <0x90000000 0x20000000>; 22 22 }; 23 23 24 - display@di0 { 24 + display0: display@di0 { 25 25 compatible = "fsl,imx-parallel-display"; 26 26 crtcs = <&ipu 0>; 27 27 interface-pix-fmt = "rgb24"; ··· 43 43 }; 44 44 }; 45 45 46 - display@di1 { 46 + display1: display@di1 { 47 47 compatible = "fsl,imx-parallel-display"; 48 48 crtcs = <&ipu 1>; 49 49 interface-pix-fmt = "rgb565"; ··· 79 79 linux,code = <116>; /* KEY_POWER */ 80 80 gpio-key,wakeup; 81 81 }; 82 + }; 83 + 84 + imx-drm { 85 + compatible = "fsl,imx-drm"; 86 + crtcs = <&ipu 0>, <&ipu 1>; 87 + connectors = <&display0>, <&display1>; 82 88 }; 83 89 84 90 sound {
+7 -1
arch/arm/boot/dts/imx53-m53evk.dts
··· 21 21 }; 22 22 23 23 soc { 24 - display@di1 { 24 + display1: display@di1 { 25 25 compatible = "fsl,imx-parallel-display"; 26 26 crtcs = <&ipu 1>; 27 27 interface-pix-fmt = "bgr666"; ··· 51 51 pwms = <&pwm1 0 3000>; 52 52 brightness-levels = <0 4 8 16 32 64 128 255>; 53 53 default-brightness-level = <6>; 54 + }; 55 + 56 + imx-drm { 57 + compatible = "fsl,imx-drm"; 58 + crtcs = <&ipu 1>; 59 + connectors = <&display1>; 54 60 }; 55 61 56 62 leds {
+6
arch/arm/boot/dts/imx53-mba53.dts
··· 43 43 status = "disabled"; 44 44 }; 45 45 46 + imx-drm { 47 + compatible = "fsl,imx-drm"; 48 + crtcs = <&ipu 1>; 49 + connectors = <&disp1>, <&tve>; 50 + }; 51 + 46 52 reg_3p2v: 3p2v { 47 53 compatible = "regulator-fixed"; 48 54 regulator-name = "3P2V";
+7 -1
arch/arm/boot/dts/imx53-qsb.dts
··· 21 21 reg = <0x70000000 0x40000000>; 22 22 }; 23 23 24 - display@di0 { 24 + display0: display@di0 { 25 25 compatible = "fsl,imx-parallel-display"; 26 26 crtcs = <&ipu 0>; 27 27 interface-pix-fmt = "rgb565"; ··· 70 70 linux,code = <114>; /* KEY_VOLUMEDOWN */ 71 71 gpio-key,wakeup; 72 72 }; 73 + }; 74 + 75 + imx-drm { 76 + compatible = "fsl,imx-drm"; 77 + crtcs = <&ipu 0>; 78 + connectors = <&display0>; 73 79 }; 74 80 75 81 leds {
+5
arch/arm/boot/dts/imx6dl.dtsi
··· 88 88 crtcs = <&ipu1 0>, <&ipu1 1>; 89 89 }; 90 90 }; 91 + 92 + &hdmi { 93 + compatible = "fsl,imx6dl-hdmi"; 94 + crtcs = <&ipu1 0>, <&ipu1 1>; 95 + };
+4
arch/arm/boot/dts/imx6q-sabresd.dts
··· 20 20 compatible = "fsl,imx6q-sabresd", "fsl,imx6q"; 21 21 }; 22 22 23 + &imx_drm { 24 + crtcs = <&ipu1 0>, <&ipu1 1>, <&ipu2 0>, <&ipu2 1>; 25 + }; 26 + 23 27 &sata { 24 28 status = "okay"; 25 29 };
+5
arch/arm/boot/dts/imx6q.dtsi
··· 159 159 crtcs = <&ipu1 0>, <&ipu1 1>, <&ipu2 0>, <&ipu2 1>; 160 160 }; 161 161 }; 162 + 163 + &hdmi { 164 + compatible = "fsl,imx6q-hdmi"; 165 + crtcs = <&ipu1 0>, <&ipu1 1>, <&ipu2 0>, <&ipu2 1>; 166 + };
+6
arch/arm/boot/dts/imx6qdl-sabresd.dtsi
··· 62 62 }; 63 63 }; 64 64 65 + imx_drm: imx-drm { 66 + compatible = "fsl,imx-drm"; 67 + crtcs = <&ipu1 0>, <&ipu1 1>; 68 + connectors = <&ldb>; 69 + }; 70 + 65 71 sound { 66 72 compatible = "fsl,imx6q-sabresd-wm8962", 67 73 "fsl,imx-audio-wm8962";
+9
arch/arm/boot/dts/imx6qdl.dtsi
··· 1368 1368 }; 1369 1369 }; 1370 1370 1371 + hdmi: hdmi@0120000 { 1372 + reg = <0x00120000 0x9000>; 1373 + interrupts = <0 115 0x04>; 1374 + gpr = <&gpr>; 1375 + clocks = <&clks 123>, <&clks 124>; 1376 + clock-names = "iahb", "isfr"; 1377 + status = "disabled"; 1378 + }; 1379 + 1371 1380 dcic1: dcic@020e4000 { 1372 1381 reg = <0x020e4000 0x4000>; 1373 1382 interrupts = <0 124 0x04>;
+1 -2
drivers/staging/imx-drm/Makefile
··· 1 1 2 - imxdrm-objs := imx-drm-core.o imx-fb.o 2 + imxdrm-objs := imx-drm-core.o 3 3 4 4 obj-$(CONFIG_DRM_IMX) += imxdrm.o 5 5 6 6 obj-$(CONFIG_DRM_IMX_PARALLEL_DISPLAY) += parallel-display.o 7 7 obj-$(CONFIG_DRM_IMX_TVE) += imx-tve.o 8 8 obj-$(CONFIG_DRM_IMX_LDB) += imx-ldb.o 9 - obj-$(CONFIG_DRM_IMX_FB_HELPER) += imx-fbdev.o 10 9 obj-$(CONFIG_DRM_IMX_IPUV3_CORE) += ipu-v3/ 11 10 12 11 imx-ipuv3-crtc-objs := ipuv3-crtc.o ipuv3-plane.o
+274 -542
drivers/staging/imx-drm/imx-drm-core.c
··· 13 13 * GNU General Public License for more details. 14 14 * 15 15 */ 16 - 16 + #include <linux/component.h> 17 17 #include <linux/device.h> 18 + #include <linux/fb.h> 19 + #include <linux/module.h> 18 20 #include <linux/platform_device.h> 19 21 #include <drm/drmP.h> 20 22 #include <drm/drm_fb_helper.h> 21 23 #include <drm/drm_crtc_helper.h> 22 - #include <linux/fb.h> 23 - #include <linux/module.h> 24 24 #include <drm/drm_gem_cma_helper.h> 25 25 #include <drm/drm_fb_cma_helper.h> 26 26 ··· 28 28 29 29 #define MAX_CRTC 4 30 30 31 - struct crtc_cookie { 32 - void *cookie; 33 - int id; 34 - struct list_head list; 35 - }; 31 + struct imx_drm_crtc; 36 32 37 33 struct imx_drm_device { 38 34 struct drm_device *drm; 39 - struct device *dev; 40 - struct list_head crtc_list; 41 - struct list_head encoder_list; 42 - struct list_head connector_list; 43 - struct mutex mutex; 35 + struct imx_drm_crtc *crtc[MAX_CRTC]; 44 36 int pipes; 45 37 struct drm_fbdev_cma *fbhelper; 46 38 }; 47 39 48 40 struct imx_drm_crtc { 49 41 struct drm_crtc *crtc; 50 - struct list_head list; 51 - struct imx_drm_device *imxdrm; 52 42 int pipe; 53 43 struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs; 54 - struct module *owner; 55 - struct crtc_cookie cookie; 44 + void *cookie; 45 + int id; 46 + int mux_id; 56 47 }; 57 48 58 - struct imx_drm_encoder { 59 - struct drm_encoder *encoder; 60 - struct list_head list; 61 - struct module *owner; 62 - struct list_head possible_crtcs; 63 - }; 64 - 65 - struct imx_drm_connector { 66 - struct drm_connector *connector; 67 - struct list_head list; 68 - struct module *owner; 69 - }; 49 + static int legacyfb_depth = 16; 50 + module_param(legacyfb_depth, int, 0444); 70 51 71 52 int imx_drm_crtc_id(struct imx_drm_crtc *crtc) 72 53 { ··· 57 76 58 77 static void imx_drm_driver_lastclose(struct drm_device *drm) 59 78 { 79 + #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) 60 80 struct imx_drm_device *imxdrm = drm->dev_private; 61 81 62 82 if (imxdrm->fbhelper) 63 83 drm_fbdev_cma_restore_mode(imxdrm->fbhelper); 84 + #endif 64 85 } 65 86 66 87 static int imx_drm_driver_unload(struct drm_device *drm) 67 88 { 89 + #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) 68 90 struct imx_drm_device *imxdrm = drm->dev_private; 91 + #endif 69 92 70 - imx_drm_device_put(); 93 + drm_kms_helper_poll_fini(drm); 94 + 95 + #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) 96 + if (imxdrm->fbhelper) 97 + drm_fbdev_cma_fini(imxdrm->fbhelper); 98 + #endif 99 + 100 + component_unbind_all(drm->dev, drm); 71 101 72 102 drm_vblank_cleanup(drm); 73 - drm_kms_helper_poll_fini(drm); 74 103 drm_mode_config_cleanup(drm); 75 104 76 105 return 0; 77 106 } 78 107 79 - /* 80 - * We don't care at all for crtc numbers, but the core expects the 81 - * crtcs to be numbered 82 - */ 83 - static struct imx_drm_crtc *imx_drm_crtc_by_num(struct imx_drm_device *imxdrm, 84 - int num) 108 + struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) 85 109 { 86 - struct imx_drm_crtc *imx_drm_crtc; 110 + struct imx_drm_device *imxdrm = crtc->dev->dev_private; 111 + unsigned i; 87 112 88 - list_for_each_entry(imx_drm_crtc, &imxdrm->crtc_list, list) 89 - if (imx_drm_crtc->pipe == num) 90 - return imx_drm_crtc; 113 + for (i = 0; i < MAX_CRTC; i++) 114 + if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc) 115 + return imxdrm->crtc[i]; 116 + 91 117 return NULL; 92 118 } 93 119 94 - int imx_drm_crtc_panel_format_pins(struct drm_crtc *crtc, u32 encoder_type, 120 + int imx_drm_panel_format_pins(struct drm_encoder *encoder, 95 121 u32 interface_pix_fmt, int hsync_pin, int vsync_pin) 96 122 { 97 - struct imx_drm_device *imxdrm = crtc->dev->dev_private; 98 - struct imx_drm_crtc *imx_crtc; 99 123 struct imx_drm_crtc_helper_funcs *helper; 124 + struct imx_drm_crtc *imx_crtc; 100 125 101 - list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list) 102 - if (imx_crtc->crtc == crtc) 103 - goto found; 126 + imx_crtc = imx_drm_find_crtc(encoder->crtc); 127 + if (!imx_crtc) 128 + return -EINVAL; 104 129 105 - return -EINVAL; 106 - found: 107 130 helper = &imx_crtc->imx_drm_helper_funcs; 108 131 if (helper->set_interface_pix_fmt) 109 - return helper->set_interface_pix_fmt(crtc, 110 - encoder_type, interface_pix_fmt, 132 + return helper->set_interface_pix_fmt(encoder->crtc, 133 + encoder->encoder_type, interface_pix_fmt, 111 134 hsync_pin, vsync_pin); 112 135 return 0; 113 136 } 114 - EXPORT_SYMBOL_GPL(imx_drm_crtc_panel_format_pins); 137 + EXPORT_SYMBOL_GPL(imx_drm_panel_format_pins); 115 138 116 - int imx_drm_crtc_panel_format(struct drm_crtc *crtc, u32 encoder_type, 117 - u32 interface_pix_fmt) 139 + int imx_drm_panel_format(struct drm_encoder *encoder, u32 interface_pix_fmt) 118 140 { 119 - return imx_drm_crtc_panel_format_pins(crtc, encoder_type, 120 - interface_pix_fmt, 2, 3); 141 + return imx_drm_panel_format_pins(encoder, interface_pix_fmt, 2, 3); 121 142 } 122 - EXPORT_SYMBOL_GPL(imx_drm_crtc_panel_format); 143 + EXPORT_SYMBOL_GPL(imx_drm_panel_format); 123 144 124 145 int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc) 125 146 { ··· 144 161 static int imx_drm_enable_vblank(struct drm_device *drm, int crtc) 145 162 { 146 163 struct imx_drm_device *imxdrm = drm->dev_private; 147 - struct imx_drm_crtc *imx_drm_crtc; 164 + struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; 148 165 int ret; 149 166 150 - imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc); 151 167 if (!imx_drm_crtc) 152 168 return -EINVAL; 153 169 ··· 162 180 static void imx_drm_disable_vblank(struct drm_device *drm, int crtc) 163 181 { 164 182 struct imx_drm_device *imxdrm = drm->dev_private; 165 - struct imx_drm_crtc *imx_drm_crtc; 183 + struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc]; 166 184 167 - imx_drm_crtc = imx_drm_crtc_by_num(imxdrm, crtc); 168 185 if (!imx_drm_crtc) 169 186 return; 170 187 ··· 196 215 .llseek = noop_llseek, 197 216 }; 198 217 199 - static struct imx_drm_device *imx_drm_device; 200 - 201 - static struct imx_drm_device *__imx_drm_device(void) 218 + int imx_drm_connector_mode_valid(struct drm_connector *connector, 219 + struct drm_display_mode *mode) 202 220 { 203 - return imx_drm_device; 221 + return MODE_OK; 222 + } 223 + EXPORT_SYMBOL(imx_drm_connector_mode_valid); 224 + 225 + void imx_drm_connector_destroy(struct drm_connector *connector) 226 + { 227 + drm_sysfs_connector_remove(connector); 228 + drm_connector_cleanup(connector); 229 + } 230 + EXPORT_SYMBOL_GPL(imx_drm_connector_destroy); 231 + 232 + void imx_drm_encoder_destroy(struct drm_encoder *encoder) 233 + { 234 + drm_encoder_cleanup(encoder); 235 + } 236 + EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy); 237 + 238 + static void imx_drm_output_poll_changed(struct drm_device *drm) 239 + { 240 + #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) 241 + struct imx_drm_device *imxdrm = drm->dev_private; 242 + 243 + drm_fbdev_cma_hotplug_event(imxdrm->fbhelper); 244 + #endif 204 245 } 205 246 206 - struct drm_device *imx_drm_device_get(void) 207 - { 208 - struct imx_drm_device *imxdrm = __imx_drm_device(); 209 - struct imx_drm_encoder *enc; 210 - struct imx_drm_connector *con; 211 - struct imx_drm_crtc *crtc; 212 - 213 - list_for_each_entry(enc, &imxdrm->encoder_list, list) { 214 - if (!try_module_get(enc->owner)) { 215 - dev_err(imxdrm->dev, "could not get module %s\n", 216 - module_name(enc->owner)); 217 - goto unwind_enc; 218 - } 219 - } 220 - 221 - list_for_each_entry(con, &imxdrm->connector_list, list) { 222 - if (!try_module_get(con->owner)) { 223 - dev_err(imxdrm->dev, "could not get module %s\n", 224 - module_name(con->owner)); 225 - goto unwind_con; 226 - } 227 - } 228 - 229 - list_for_each_entry(crtc, &imxdrm->crtc_list, list) { 230 - if (!try_module_get(crtc->owner)) { 231 - dev_err(imxdrm->dev, "could not get module %s\n", 232 - module_name(crtc->owner)); 233 - goto unwind_crtc; 234 - } 235 - } 236 - 237 - return imxdrm->drm; 238 - 239 - unwind_crtc: 240 - list_for_each_entry_continue_reverse(crtc, &imxdrm->crtc_list, list) 241 - module_put(crtc->owner); 242 - unwind_con: 243 - list_for_each_entry_continue_reverse(con, &imxdrm->connector_list, list) 244 - module_put(con->owner); 245 - unwind_enc: 246 - list_for_each_entry_continue_reverse(enc, &imxdrm->encoder_list, list) 247 - module_put(enc->owner); 248 - 249 - mutex_unlock(&imxdrm->mutex); 250 - 251 - return NULL; 252 - 253 - } 254 - EXPORT_SYMBOL_GPL(imx_drm_device_get); 255 - 256 - void imx_drm_device_put(void) 257 - { 258 - struct imx_drm_device *imxdrm = __imx_drm_device(); 259 - struct imx_drm_encoder *enc; 260 - struct imx_drm_connector *con; 261 - struct imx_drm_crtc *crtc; 262 - 263 - mutex_lock(&imxdrm->mutex); 264 - 265 - list_for_each_entry(crtc, &imxdrm->crtc_list, list) 266 - module_put(crtc->owner); 267 - 268 - list_for_each_entry(con, &imxdrm->connector_list, list) 269 - module_put(con->owner); 270 - 271 - list_for_each_entry(enc, &imxdrm->encoder_list, list) 272 - module_put(enc->owner); 273 - 274 - mutex_unlock(&imxdrm->mutex); 275 - } 276 - EXPORT_SYMBOL_GPL(imx_drm_device_put); 277 - 278 - static int drm_mode_group_reinit(struct drm_device *dev) 279 - { 280 - struct drm_mode_group *group = &dev->primary->mode_group; 281 - uint32_t *id_list = group->id_list; 282 - int ret; 283 - 284 - ret = drm_mode_group_init_legacy_group(dev, group); 285 - if (ret < 0) 286 - return ret; 287 - 288 - kfree(id_list); 289 - return 0; 290 - } 247 + static struct drm_mode_config_funcs imx_drm_mode_config_funcs = { 248 + .fb_create = drm_fb_cma_create, 249 + .output_poll_changed = imx_drm_output_poll_changed, 250 + }; 291 251 292 252 /* 293 - * register an encoder to the drm core 294 - */ 295 - static int imx_drm_encoder_register(struct imx_drm_encoder *imx_drm_encoder) 296 - { 297 - struct imx_drm_device *imxdrm = __imx_drm_device(); 298 - 299 - INIT_LIST_HEAD(&imx_drm_encoder->possible_crtcs); 300 - 301 - drm_encoder_init(imxdrm->drm, imx_drm_encoder->encoder, 302 - imx_drm_encoder->encoder->funcs, 303 - imx_drm_encoder->encoder->encoder_type); 304 - 305 - drm_mode_group_reinit(imxdrm->drm); 306 - 307 - return 0; 308 - } 309 - 310 - /* 311 - * unregister an encoder from the drm core 312 - */ 313 - static void imx_drm_encoder_unregister(struct imx_drm_encoder 314 - *imx_drm_encoder) 315 - { 316 - struct imx_drm_device *imxdrm = __imx_drm_device(); 317 - 318 - drm_encoder_cleanup(imx_drm_encoder->encoder); 319 - 320 - drm_mode_group_reinit(imxdrm->drm); 321 - } 322 - 323 - /* 324 - * register a connector to the drm core 325 - */ 326 - static int imx_drm_connector_register( 327 - struct imx_drm_connector *imx_drm_connector) 328 - { 329 - struct imx_drm_device *imxdrm = __imx_drm_device(); 330 - 331 - drm_connector_init(imxdrm->drm, imx_drm_connector->connector, 332 - imx_drm_connector->connector->funcs, 333 - imx_drm_connector->connector->connector_type); 334 - drm_mode_group_reinit(imxdrm->drm); 335 - 336 - return drm_sysfs_connector_add(imx_drm_connector->connector); 337 - } 338 - 339 - /* 340 - * unregister a connector from the drm core 341 - */ 342 - static void imx_drm_connector_unregister( 343 - struct imx_drm_connector *imx_drm_connector) 344 - { 345 - struct imx_drm_device *imxdrm = __imx_drm_device(); 346 - 347 - drm_sysfs_connector_remove(imx_drm_connector->connector); 348 - drm_connector_cleanup(imx_drm_connector->connector); 349 - 350 - drm_mode_group_reinit(imxdrm->drm); 351 - } 352 - 353 - /* 354 - * Called by the CRTC driver when all CRTCs are registered. This 355 - * puts all the pieces together and initializes the driver. 356 - * Once this is called no more CRTCs can be registered since 357 - * the drm core has hardcoded the number of crtcs in several 358 - * places. 253 + * Main DRM initialisation. This binds, initialises and registers 254 + * with DRM the subcomponents of the driver. 359 255 */ 360 256 static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags) 361 257 { 362 - struct imx_drm_device *imxdrm = __imx_drm_device(); 258 + struct imx_drm_device *imxdrm; 259 + struct drm_connector *connector; 363 260 int ret; 261 + 262 + imxdrm = devm_kzalloc(drm->dev, sizeof(*imxdrm), GFP_KERNEL); 263 + if (!imxdrm) 264 + return -ENOMEM; 364 265 365 266 imxdrm->drm = drm; 366 267 ··· 259 396 */ 260 397 drm->irq_enabled = true; 261 398 399 + /* 400 + * set max width and height as default value(4096x4096). 401 + * this value would be used to check framebuffer size limitation 402 + * at drm_mode_addfb(). 403 + */ 404 + drm->mode_config.min_width = 64; 405 + drm->mode_config.min_height = 64; 406 + drm->mode_config.max_width = 4096; 407 + drm->mode_config.max_height = 4096; 408 + drm->mode_config.funcs = &imx_drm_mode_config_funcs; 409 + 262 410 drm_mode_config_init(drm); 263 - imx_drm_mode_config_init(drm); 264 - 265 - mutex_lock(&imxdrm->mutex); 266 - 267 - drm_kms_helper_poll_init(drm); 268 - 269 - /* setup the grouping for the legacy output */ 270 - ret = drm_mode_group_init_legacy_group(drm, 271 - &drm->primary->mode_group); 272 - if (ret) 273 - goto err_kms; 274 411 275 412 ret = drm_vblank_init(drm, MAX_CRTC); 276 413 if (ret) 277 414 goto err_kms; 278 415 279 416 /* 280 - * with vblank_disable_allowed = true, vblank interrupt will be disabled 281 - * by drm timer once a current process gives up ownership of 282 - * vblank event.(after drm_vblank_put function is called) 417 + * with vblank_disable_allowed = true, vblank interrupt will be 418 + * disabled by drm timer once a current process gives up ownership 419 + * of vblank event. (after drm_vblank_put function is called) 283 420 */ 284 421 drm->vblank_disable_allowed = true; 285 422 286 - if (!imx_drm_device_get()) { 287 - ret = -EINVAL; 423 + platform_set_drvdata(drm->platformdev, drm); 424 + 425 + /* Now try and bind all our sub-components */ 426 + ret = component_bind_all(drm->dev, drm); 427 + if (ret) 288 428 goto err_vblank; 429 + 430 + /* 431 + * All components are now added, we can publish the connector sysfs 432 + * entries to userspace. This will generate hotplug events and so 433 + * userspace will expect to be able to access DRM at this point. 434 + */ 435 + list_for_each_entry(connector, &drm->mode_config.connector_list, head) { 436 + ret = drm_sysfs_connector_add(connector); 437 + if (ret) { 438 + dev_err(drm->dev, 439 + "[CONNECTOR:%d:%s] drm_sysfs_connector_add failed: %d\n", 440 + connector->base.id, 441 + drm_get_connector_name(connector), ret); 442 + goto err_unbind; 443 + } 289 444 } 290 445 291 - platform_set_drvdata(drm->platformdev, drm); 292 - mutex_unlock(&imxdrm->mutex); 446 + /* 447 + * All components are now initialised, so setup the fb helper. 448 + * The fb helper takes copies of key hardware information, so the 449 + * crtcs/connectors/encoders must not change after this point. 450 + */ 451 + #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER) 452 + if (legacyfb_depth != 16 && legacyfb_depth != 32) { 453 + dev_warn(drm->dev, "Invalid legacyfb_depth. Defaulting to 16bpp\n"); 454 + legacyfb_depth = 16; 455 + } 456 + imxdrm->fbhelper = drm_fbdev_cma_init(drm, legacyfb_depth, 457 + drm->mode_config.num_crtc, MAX_CRTC); 458 + if (IS_ERR(imxdrm->fbhelper)) { 459 + ret = PTR_ERR(imxdrm->fbhelper); 460 + imxdrm->fbhelper = NULL; 461 + goto err_unbind; 462 + } 463 + #endif 464 + 465 + drm_kms_helper_poll_init(drm); 466 + 293 467 return 0; 294 468 469 + err_unbind: 470 + component_unbind_all(drm->dev, drm); 295 471 err_vblank: 296 472 drm_vblank_cleanup(drm); 297 473 err_kms: 298 - drm_kms_helper_poll_fini(drm); 299 474 drm_mode_config_cleanup(drm); 300 - mutex_unlock(&imxdrm->mutex); 301 475 302 476 return ret; 303 - } 304 - 305 - static void imx_drm_update_possible_crtcs(void) 306 - { 307 - struct imx_drm_device *imxdrm = __imx_drm_device(); 308 - struct imx_drm_crtc *imx_drm_crtc; 309 - struct imx_drm_encoder *enc; 310 - struct crtc_cookie *cookie; 311 - 312 - list_for_each_entry(enc, &imxdrm->encoder_list, list) { 313 - u32 possible_crtcs = 0; 314 - 315 - list_for_each_entry(cookie, &enc->possible_crtcs, list) { 316 - list_for_each_entry(imx_drm_crtc, &imxdrm->crtc_list, list) { 317 - if (imx_drm_crtc->cookie.cookie == cookie->cookie && 318 - imx_drm_crtc->cookie.id == cookie->id) { 319 - possible_crtcs |= 1 << imx_drm_crtc->pipe; 320 - } 321 - } 322 - } 323 - enc->encoder->possible_crtcs = possible_crtcs; 324 - enc->encoder->possible_clones = possible_crtcs; 325 - } 326 477 } 327 478 328 479 /* ··· 345 468 * The return value if !NULL is a cookie for the caller to pass to 346 469 * imx_drm_remove_crtc later. 347 470 */ 348 - int imx_drm_add_crtc(struct drm_crtc *crtc, 471 + int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc, 349 472 struct imx_drm_crtc **new_crtc, 350 473 const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs, 351 - struct module *owner, void *cookie, int id) 474 + void *cookie, int id) 352 475 { 353 - struct imx_drm_device *imxdrm = __imx_drm_device(); 476 + struct imx_drm_device *imxdrm = drm->dev_private; 354 477 struct imx_drm_crtc *imx_drm_crtc; 355 478 int ret; 356 - 357 - mutex_lock(&imxdrm->mutex); 358 479 359 480 /* 360 481 * The vblank arrays are dimensioned by MAX_CRTC - we can't 361 482 * pass IDs greater than this to those functions. 362 483 */ 363 - if (imxdrm->pipes >= MAX_CRTC) { 364 - ret = -EINVAL; 365 - goto err_busy; 366 - } 484 + if (imxdrm->pipes >= MAX_CRTC) 485 + return -EINVAL; 367 486 368 - if (imxdrm->drm->open_count) { 369 - ret = -EBUSY; 370 - goto err_busy; 371 - } 487 + if (imxdrm->drm->open_count) 488 + return -EBUSY; 372 489 373 490 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL); 374 - if (!imx_drm_crtc) { 375 - ret = -ENOMEM; 376 - goto err_alloc; 377 - } 491 + if (!imx_drm_crtc) 492 + return -ENOMEM; 378 493 379 494 imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs; 380 495 imx_drm_crtc->pipe = imxdrm->pipes++; 381 - imx_drm_crtc->cookie.cookie = cookie; 382 - imx_drm_crtc->cookie.id = id; 383 - 496 + imx_drm_crtc->cookie = cookie; 497 + imx_drm_crtc->id = id; 498 + imx_drm_crtc->mux_id = imx_drm_crtc->pipe; 384 499 imx_drm_crtc->crtc = crtc; 385 - imx_drm_crtc->imxdrm = imxdrm; 386 500 387 - imx_drm_crtc->owner = owner; 388 - 389 - list_add_tail(&imx_drm_crtc->list, &imxdrm->crtc_list); 501 + imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc; 390 502 391 503 *new_crtc = imx_drm_crtc; 392 504 ··· 386 520 drm_crtc_helper_add(crtc, 387 521 imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs); 388 522 389 - drm_crtc_init(imxdrm->drm, crtc, 523 + drm_crtc_init(drm, crtc, 390 524 imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs); 391 - 392 - drm_mode_group_reinit(imxdrm->drm); 393 - 394 - imx_drm_update_possible_crtcs(); 395 - 396 - mutex_unlock(&imxdrm->mutex); 397 525 398 526 return 0; 399 527 400 528 err_register: 401 - list_del(&imx_drm_crtc->list); 529 + imxdrm->crtc[imx_drm_crtc->pipe] = NULL; 402 530 kfree(imx_drm_crtc); 403 - err_alloc: 404 - err_busy: 405 - mutex_unlock(&imxdrm->mutex); 406 531 return ret; 407 532 } 408 533 EXPORT_SYMBOL_GPL(imx_drm_add_crtc); ··· 403 546 */ 404 547 int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc) 405 548 { 406 - struct imx_drm_device *imxdrm = imx_drm_crtc->imxdrm; 407 - 408 - mutex_lock(&imxdrm->mutex); 549 + struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private; 409 550 410 551 drm_crtc_cleanup(imx_drm_crtc->crtc); 411 552 412 - list_del(&imx_drm_crtc->list); 413 - 414 - drm_mode_group_reinit(imxdrm->drm); 415 - 416 - mutex_unlock(&imxdrm->mutex); 553 + imxdrm->crtc[imx_drm_crtc->pipe] = NULL; 417 554 418 555 kfree(imx_drm_crtc); 419 556 ··· 416 565 EXPORT_SYMBOL_GPL(imx_drm_remove_crtc); 417 566 418 567 /* 419 - * imx_drm_add_encoder - add a new encoder 568 + * Find the DRM CRTC possible mask for the device node cookie/id. 569 + * 570 + * The encoder possible masks are defined by their position in the 571 + * mode_config crtc_list. This means that CRTCs must not be added 572 + * or removed once the DRM device has been fully initialised. 420 573 */ 421 - int imx_drm_add_encoder(struct drm_encoder *encoder, 422 - struct imx_drm_encoder **newenc, struct module *owner) 574 + static uint32_t imx_drm_find_crtc_mask(struct imx_drm_device *imxdrm, 575 + void *cookie, int id) 423 576 { 424 - struct imx_drm_device *imxdrm = __imx_drm_device(); 425 - struct imx_drm_encoder *imx_drm_encoder; 426 - int ret; 577 + unsigned i; 427 578 428 - mutex_lock(&imxdrm->mutex); 429 - 430 - if (imxdrm->drm->open_count) { 431 - ret = -EBUSY; 432 - goto err_busy; 579 + for (i = 0; i < MAX_CRTC; i++) { 580 + struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[i]; 581 + if (imx_drm_crtc && imx_drm_crtc->id == id && 582 + imx_drm_crtc->cookie == cookie) 583 + return drm_crtc_mask(imx_drm_crtc->crtc); 433 584 } 434 - 435 - imx_drm_encoder = kzalloc(sizeof(*imx_drm_encoder), GFP_KERNEL); 436 - if (!imx_drm_encoder) { 437 - ret = -ENOMEM; 438 - goto err_alloc; 439 - } 440 - 441 - imx_drm_encoder->encoder = encoder; 442 - imx_drm_encoder->owner = owner; 443 - 444 - ret = imx_drm_encoder_register(imx_drm_encoder); 445 - if (ret) { 446 - ret = -ENOMEM; 447 - goto err_register; 448 - } 449 - 450 - list_add_tail(&imx_drm_encoder->list, &imxdrm->encoder_list); 451 - 452 - *newenc = imx_drm_encoder; 453 - 454 - mutex_unlock(&imxdrm->mutex); 455 585 456 586 return 0; 457 - 458 - err_register: 459 - kfree(imx_drm_encoder); 460 - err_alloc: 461 - err_busy: 462 - mutex_unlock(&imxdrm->mutex); 463 - 464 - return ret; 465 587 } 466 - EXPORT_SYMBOL_GPL(imx_drm_add_encoder); 467 588 468 - int imx_drm_encoder_add_possible_crtcs( 469 - struct imx_drm_encoder *imx_drm_encoder, 470 - struct device_node *np) 589 + int imx_drm_encoder_parse_of(struct drm_device *drm, 590 + struct drm_encoder *encoder, struct device_node *np) 471 591 { 472 - struct imx_drm_device *imxdrm = __imx_drm_device(); 473 - struct of_phandle_args args; 474 - struct crtc_cookie *c; 475 - int ret = 0; 476 - int i; 477 - 478 - if (!list_empty(&imx_drm_encoder->possible_crtcs)) 479 - return -EBUSY; 592 + struct imx_drm_device *imxdrm = drm->dev_private; 593 + uint32_t crtc_mask = 0; 594 + int i, ret = 0; 480 595 481 596 for (i = 0; !ret; i++) { 482 - ret = of_parse_phandle_with_args(np, "crtcs", 483 - "#crtc-cells", i, &args); 484 - if (ret < 0) 597 + struct of_phandle_args args; 598 + uint32_t mask; 599 + int id; 600 + 601 + ret = of_parse_phandle_with_args(np, "crtcs", "#crtc-cells", i, 602 + &args); 603 + if (ret == -ENOENT) 485 604 break; 605 + if (ret < 0) 606 + return ret; 486 607 487 - c = kzalloc(sizeof(*c), GFP_KERNEL); 488 - if (!c) { 489 - of_node_put(args.np); 490 - return -ENOMEM; 491 - } 492 - 493 - c->cookie = args.np; 494 - c->id = args.args_count > 0 ? args.args[0] : 0; 495 - 608 + id = args.args_count > 0 ? args.args[0] : 0; 609 + mask = imx_drm_find_crtc_mask(imxdrm, args.np, id); 496 610 of_node_put(args.np); 497 611 498 - mutex_lock(&imxdrm->mutex); 612 + /* 613 + * If we failed to find the CRTC(s) which this encoder is 614 + * supposed to be connected to, it's because the CRTC has 615 + * not been registered yet. Defer probing, and hope that 616 + * the required CRTC is added later. 617 + */ 618 + if (mask == 0) 619 + return -EPROBE_DEFER; 499 620 500 - list_add_tail(&c->list, &imx_drm_encoder->possible_crtcs); 501 - 502 - mutex_unlock(&imxdrm->mutex); 621 + crtc_mask |= mask; 503 622 } 504 623 505 - imx_drm_update_possible_crtcs(); 624 + encoder->possible_crtcs = crtc_mask; 625 + 626 + /* FIXME: this is the mask of outputs which can clone this output. */ 627 + encoder->possible_clones = ~0; 506 628 507 629 return 0; 508 630 } 509 - EXPORT_SYMBOL_GPL(imx_drm_encoder_add_possible_crtcs); 631 + EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of); 510 632 511 - int imx_drm_encoder_get_mux_id(struct imx_drm_encoder *imx_drm_encoder, 512 - struct drm_crtc *crtc) 633 + int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder) 513 634 { 514 - struct imx_drm_device *imxdrm = __imx_drm_device(); 515 - struct imx_drm_crtc *imx_crtc; 516 - int i = 0; 635 + struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc); 517 636 518 - list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list) { 519 - if (imx_crtc->crtc == crtc) 520 - goto found; 521 - i++; 522 - } 523 - 524 - return -EINVAL; 525 - found: 526 - return i; 637 + return imx_crtc ? imx_crtc->mux_id : -EINVAL; 527 638 } 528 639 EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id); 529 - 530 - /* 531 - * imx_drm_remove_encoder - remove an encoder 532 - */ 533 - int imx_drm_remove_encoder(struct imx_drm_encoder *imx_drm_encoder) 534 - { 535 - struct imx_drm_device *imxdrm = __imx_drm_device(); 536 - struct crtc_cookie *c, *tmp; 537 - 538 - mutex_lock(&imxdrm->mutex); 539 - 540 - imx_drm_encoder_unregister(imx_drm_encoder); 541 - 542 - list_del(&imx_drm_encoder->list); 543 - 544 - list_for_each_entry_safe(c, tmp, &imx_drm_encoder->possible_crtcs, 545 - list) 546 - kfree(c); 547 - 548 - mutex_unlock(&imxdrm->mutex); 549 - 550 - kfree(imx_drm_encoder); 551 - 552 - return 0; 553 - } 554 - EXPORT_SYMBOL_GPL(imx_drm_remove_encoder); 555 - 556 - /* 557 - * imx_drm_add_connector - add a connector 558 - */ 559 - int imx_drm_add_connector(struct drm_connector *connector, 560 - struct imx_drm_connector **new_con, 561 - struct module *owner) 562 - { 563 - struct imx_drm_device *imxdrm = __imx_drm_device(); 564 - struct imx_drm_connector *imx_drm_connector; 565 - int ret; 566 - 567 - mutex_lock(&imxdrm->mutex); 568 - 569 - if (imxdrm->drm->open_count) { 570 - ret = -EBUSY; 571 - goto err_busy; 572 - } 573 - 574 - imx_drm_connector = kzalloc(sizeof(*imx_drm_connector), GFP_KERNEL); 575 - if (!imx_drm_connector) { 576 - ret = -ENOMEM; 577 - goto err_alloc; 578 - } 579 - 580 - imx_drm_connector->connector = connector; 581 - imx_drm_connector->owner = owner; 582 - 583 - ret = imx_drm_connector_register(imx_drm_connector); 584 - if (ret) 585 - goto err_register; 586 - 587 - list_add_tail(&imx_drm_connector->list, &imxdrm->connector_list); 588 - 589 - *new_con = imx_drm_connector; 590 - 591 - mutex_unlock(&imxdrm->mutex); 592 - 593 - return 0; 594 - 595 - err_register: 596 - kfree(imx_drm_connector); 597 - err_alloc: 598 - err_busy: 599 - mutex_unlock(&imxdrm->mutex); 600 - 601 - return ret; 602 - } 603 - EXPORT_SYMBOL_GPL(imx_drm_add_connector); 604 - 605 - void imx_drm_fb_helper_set(struct drm_fbdev_cma *fbdev_helper) 606 - { 607 - struct imx_drm_device *imxdrm = __imx_drm_device(); 608 - 609 - imxdrm->fbhelper = fbdev_helper; 610 - } 611 - EXPORT_SYMBOL_GPL(imx_drm_fb_helper_set); 612 - 613 - /* 614 - * imx_drm_remove_connector - remove a connector 615 - */ 616 - int imx_drm_remove_connector(struct imx_drm_connector *imx_drm_connector) 617 - { 618 - struct imx_drm_device *imxdrm = __imx_drm_device(); 619 - 620 - mutex_lock(&imxdrm->mutex); 621 - 622 - imx_drm_connector_unregister(imx_drm_connector); 623 - 624 - list_del(&imx_drm_connector->list); 625 - 626 - mutex_unlock(&imxdrm->mutex); 627 - 628 - kfree(imx_drm_connector); 629 - 630 - return 0; 631 - } 632 - EXPORT_SYMBOL_GPL(imx_drm_remove_connector); 633 640 634 641 static const struct drm_ioctl_desc imx_drm_ioctls[] = { 635 642 /* none so far */ ··· 528 819 .patchlevel = 0, 529 820 }; 530 821 822 + static int compare_parent_of(struct device *dev, void *data) 823 + { 824 + struct of_phandle_args *args = data; 825 + return dev->parent && dev->parent->of_node == args->np; 826 + } 827 + 828 + static int compare_of(struct device *dev, void *data) 829 + { 830 + return dev->of_node == data; 831 + } 832 + 833 + static int imx_drm_add_components(struct device *master, struct master *m) 834 + { 835 + struct device_node *np = master->of_node; 836 + unsigned i; 837 + int ret; 838 + 839 + for (i = 0; ; i++) { 840 + struct of_phandle_args args; 841 + 842 + ret = of_parse_phandle_with_fixed_args(np, "crtcs", 1, 843 + i, &args); 844 + if (ret) 845 + break; 846 + 847 + ret = component_master_add_child(m, compare_parent_of, &args); 848 + of_node_put(args.np); 849 + 850 + if (ret) 851 + return ret; 852 + } 853 + 854 + for (i = 0; ; i++) { 855 + struct device_node *node; 856 + 857 + node = of_parse_phandle(np, "connectors", i); 858 + if (!node) 859 + break; 860 + 861 + ret = component_master_add_child(m, compare_of, node); 862 + of_node_put(node); 863 + 864 + if (ret) 865 + return ret; 866 + } 867 + return 0; 868 + } 869 + 870 + static int imx_drm_bind(struct device *dev) 871 + { 872 + return drm_platform_init(&imx_drm_driver, to_platform_device(dev)); 873 + } 874 + 875 + static void imx_drm_unbind(struct device *dev) 876 + { 877 + drm_put_dev(dev_get_drvdata(dev)); 878 + } 879 + 880 + static const struct component_master_ops imx_drm_ops = { 881 + .add_components = imx_drm_add_components, 882 + .bind = imx_drm_bind, 883 + .unbind = imx_drm_unbind, 884 + }; 885 + 531 886 static int imx_drm_platform_probe(struct platform_device *pdev) 532 887 { 533 888 int ret; ··· 600 827 if (ret) 601 828 return ret; 602 829 603 - imx_drm_device->dev = &pdev->dev; 604 - 605 - return drm_platform_init(&imx_drm_driver, pdev); 830 + return component_master_add(&pdev->dev, &imx_drm_ops); 606 831 } 607 832 608 833 static int imx_drm_platform_remove(struct platform_device *pdev) 609 834 { 610 - drm_put_dev(platform_get_drvdata(pdev)); 611 - 835 + component_master_del(&pdev->dev, &imx_drm_ops); 612 836 return 0; 613 837 } 838 + 839 + static const struct of_device_id imx_drm_dt_ids[] = { 840 + { .compatible = "fsl,imx-drm", }, 841 + { /* sentinel */ }, 842 + }; 843 + MODULE_DEVICE_TABLE(of, imx_drm_dt_ids); 614 844 615 845 static struct platform_driver imx_drm_pdrv = { 616 846 .probe = imx_drm_platform_probe, ··· 621 845 .driver = { 622 846 .owner = THIS_MODULE, 623 847 .name = "imx-drm", 848 + .of_match_table = imx_drm_dt_ids, 624 849 }, 625 850 }; 626 - 627 - static struct platform_device *imx_drm_pdev; 628 - 629 - static int __init imx_drm_init(void) 630 - { 631 - int ret; 632 - 633 - imx_drm_device = kzalloc(sizeof(*imx_drm_device), GFP_KERNEL); 634 - if (!imx_drm_device) 635 - return -ENOMEM; 636 - 637 - mutex_init(&imx_drm_device->mutex); 638 - INIT_LIST_HEAD(&imx_drm_device->crtc_list); 639 - INIT_LIST_HEAD(&imx_drm_device->connector_list); 640 - INIT_LIST_HEAD(&imx_drm_device->encoder_list); 641 - 642 - imx_drm_pdev = platform_device_register_simple("imx-drm", -1, NULL, 0); 643 - if (IS_ERR(imx_drm_pdev)) { 644 - ret = PTR_ERR(imx_drm_pdev); 645 - goto err_pdev; 646 - } 647 - 648 - ret = platform_driver_register(&imx_drm_pdrv); 649 - if (ret) 650 - goto err_pdrv; 651 - 652 - return 0; 653 - 654 - err_pdrv: 655 - platform_device_unregister(imx_drm_pdev); 656 - err_pdev: 657 - kfree(imx_drm_device); 658 - 659 - return ret; 660 - } 661 - 662 - static void __exit imx_drm_exit(void) 663 - { 664 - platform_device_unregister(imx_drm_pdev); 665 - platform_driver_unregister(&imx_drm_pdrv); 666 - 667 - kfree(imx_drm_device); 668 - } 669 - 670 - module_init(imx_drm_init); 671 - module_exit(imx_drm_exit); 851 + module_platform_driver(imx_drm_pdrv); 672 852 673 853 MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 674 854 MODULE_DESCRIPTION("i.MX drm driver core");
+14 -25
drivers/staging/imx-drm/imx-drm.h
··· 5 5 6 6 #define IPU_PIX_FMT_GBR24 v4l2_fourcc('G', 'B', 'R', '3') 7 7 8 + struct device_node; 8 9 struct drm_crtc; 9 10 struct drm_connector; 10 11 struct drm_device; 12 + struct drm_display_mode; 11 13 struct drm_encoder; 12 - struct imx_drm_crtc; 13 14 struct drm_fbdev_cma; 14 15 struct drm_framebuffer; 16 + struct imx_drm_crtc; 15 17 struct platform_device; 16 18 17 19 int imx_drm_crtc_id(struct imx_drm_crtc *crtc); ··· 27 25 const struct drm_crtc_funcs *crtc_funcs; 28 26 }; 29 27 30 - int imx_drm_add_crtc(struct drm_crtc *crtc, 28 + int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc, 31 29 struct imx_drm_crtc **new_crtc, 32 30 const struct imx_drm_crtc_helper_funcs *imx_helper_funcs, 33 - struct module *owner, void *cookie, int id); 31 + void *cookie, int id); 34 32 int imx_drm_remove_crtc(struct imx_drm_crtc *); 35 33 int imx_drm_init_drm(struct platform_device *pdev, 36 34 int preferred_bpp); ··· 40 38 void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc); 41 39 void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc); 42 40 43 - struct imx_drm_encoder; 44 - int imx_drm_add_encoder(struct drm_encoder *encoder, 45 - struct imx_drm_encoder **new_enc, 46 - struct module *owner); 47 - int imx_drm_remove_encoder(struct imx_drm_encoder *); 48 - 49 - struct imx_drm_connector; 50 - int imx_drm_add_connector(struct drm_connector *connector, 51 - struct imx_drm_connector **new_con, 52 - struct module *owner); 53 - int imx_drm_remove_connector(struct imx_drm_connector *); 54 - 55 41 void imx_drm_mode_config_init(struct drm_device *drm); 56 42 57 43 struct drm_gem_cma_object *imx_drm_fb_get_obj(struct drm_framebuffer *fb); 58 44 59 - struct drm_device *imx_drm_device_get(void); 60 - void imx_drm_device_put(void); 61 - int imx_drm_crtc_panel_format_pins(struct drm_crtc *crtc, u32 encoder_type, 45 + int imx_drm_panel_format_pins(struct drm_encoder *encoder, 62 46 u32 interface_pix_fmt, int hsync_pin, int vsync_pin); 63 - int imx_drm_crtc_panel_format(struct drm_crtc *crtc, u32 encoder_type, 47 + int imx_drm_panel_format(struct drm_encoder *encoder, 64 48 u32 interface_pix_fmt); 65 - void imx_drm_fb_helper_set(struct drm_fbdev_cma *fbdev_helper); 66 49 67 - struct device_node; 50 + int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder); 51 + int imx_drm_encoder_parse_of(struct drm_device *drm, 52 + struct drm_encoder *encoder, struct device_node *np); 68 53 69 - int imx_drm_encoder_get_mux_id(struct imx_drm_encoder *imx_drm_encoder, 70 - struct drm_crtc *crtc); 71 - int imx_drm_encoder_add_possible_crtcs(struct imx_drm_encoder *imx_drm_encoder, 72 - struct device_node *np); 54 + int imx_drm_connector_mode_valid(struct drm_connector *connector, 55 + struct drm_display_mode *mode); 56 + void imx_drm_connector_destroy(struct drm_connector *connector); 57 + void imx_drm_encoder_destroy(struct drm_encoder *encoder); 73 58 74 59 #endif /* _IMX_DRM_H_ */
-47
drivers/staging/imx-drm/imx-fb.c
··· 1 - /* 2 - * i.MX drm driver 3 - * 4 - * Copyright (C) 2012 Sascha Hauer, Pengutronix 5 - * 6 - * Based on Samsung Exynos code 7 - * 8 - * Copyright (c) 2011 Samsung Electronics Co., Ltd. 9 - * 10 - * This program is free software; you can redistribute it and/or 11 - * modify it under the terms of the GNU General Public License 12 - * as published by the Free Software Foundation; either version 2 13 - * of the License, or (at your option) any later version. 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - */ 20 - #include <linux/module.h> 21 - #include <drm/drmP.h> 22 - #include <drm/drm_crtc.h> 23 - #include <drm/drm_crtc_helper.h> 24 - #include <drm/drm_gem_cma_helper.h> 25 - #include <drm/drm_fb_cma_helper.h> 26 - 27 - #include "imx-drm.h" 28 - 29 - static struct drm_mode_config_funcs imx_drm_mode_config_funcs = { 30 - .fb_create = drm_fb_cma_create, 31 - }; 32 - 33 - void imx_drm_mode_config_init(struct drm_device *dev) 34 - { 35 - dev->mode_config.min_width = 64; 36 - dev->mode_config.min_height = 64; 37 - 38 - /* 39 - * set max width and height as default value(4096x4096). 40 - * this value would be used to check framebuffer size limitation 41 - * at drm_mode_addfb(). 42 - */ 43 - dev->mode_config.max_width = 4096; 44 - dev->mode_config.max_height = 4096; 45 - 46 - dev->mode_config.funcs = &imx_drm_mode_config_funcs; 47 - }
-74
drivers/staging/imx-drm/imx-fbdev.c
··· 1 - /* 2 - * i.MX drm driver 3 - * 4 - * Copyright (C) 2012 Sascha Hauer, Pengutronix 5 - * 6 - * Based on Samsung Exynos code 7 - * 8 - * Copyright (c) 2011 Samsung Electronics Co., Ltd. 9 - * 10 - * This program is free software; you can redistribute it and/or 11 - * modify it under the terms of the GNU General Public License 12 - * as published by the Free Software Foundation; either version 2 13 - * of the License, or (at your option) any later version. 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - */ 20 - #include <linux/module.h> 21 - #include <drm/drmP.h> 22 - #include <drm/drm_crtc.h> 23 - #include <drm/drm_crtc_helper.h> 24 - #include <drm/drm_fb_cma_helper.h> 25 - 26 - #include "imx-drm.h" 27 - 28 - #define MAX_CONNECTOR 4 29 - #define PREFERRED_BPP 16 30 - 31 - static struct drm_fbdev_cma *fbdev_cma; 32 - 33 - static int legacyfb_depth = 16; 34 - 35 - module_param(legacyfb_depth, int, 0444); 36 - 37 - static int __init imx_fb_helper_init(void) 38 - { 39 - struct drm_device *drm = imx_drm_device_get(); 40 - 41 - if (!drm) 42 - return -EINVAL; 43 - 44 - if (legacyfb_depth != 16 && legacyfb_depth != 32) { 45 - pr_warn("i.MX legacyfb: invalid legacyfb_depth setting. defaulting to 16bpp\n"); 46 - legacyfb_depth = 16; 47 - } 48 - 49 - fbdev_cma = drm_fbdev_cma_init(drm, legacyfb_depth, 50 - drm->mode_config.num_crtc, MAX_CONNECTOR); 51 - 52 - if (IS_ERR(fbdev_cma)) { 53 - imx_drm_device_put(); 54 - return PTR_ERR(fbdev_cma); 55 - } 56 - 57 - imx_drm_fb_helper_set(fbdev_cma); 58 - 59 - return 0; 60 - } 61 - 62 - static void __exit imx_fb_helper_exit(void) 63 - { 64 - imx_drm_fb_helper_set(NULL); 65 - drm_fbdev_cma_fini(fbdev_cma); 66 - imx_drm_device_put(); 67 - } 68 - 69 - late_initcall(imx_fb_helper_init); 70 - module_exit(imx_fb_helper_exit); 71 - 72 - MODULE_DESCRIPTION("Freescale i.MX legacy fb driver"); 73 - MODULE_AUTHOR("Sascha Hauer, Pengutronix"); 74 - MODULE_LICENSE("GPL");
+255 -404
drivers/staging/imx-drm/imx-hdmi.c
··· 12 12 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de> 13 13 */ 14 14 15 + #include <linux/component.h> 15 16 #include <linux/irq.h> 16 17 #include <linux/delay.h> 17 18 #include <linux/err.h> ··· 113 112 114 113 struct imx_hdmi { 115 114 struct drm_connector connector; 116 - struct imx_drm_connector *imx_drm_connector; 117 115 struct drm_encoder encoder; 118 - struct imx_drm_encoder *imx_drm_encoder; 119 116 120 117 enum imx_hdmi_devtype dev_type; 121 118 struct device *dev; 122 119 struct clk *isfr_clk; 123 120 struct clk *iahb_clk; 121 + 122 + enum drm_connector_status connector_status; 124 123 125 124 struct hdmi_data_info hdmi_data; 126 125 int vic; ··· 135 134 struct i2c_adapter *ddc; 136 135 void __iomem *regs; 137 136 138 - unsigned long pixel_clk_rate; 139 137 unsigned int sample_rate; 140 138 int ratio; 141 139 }; ··· 156 156 return readb(hdmi->regs + offset); 157 157 } 158 158 159 + static void hdmi_modb(struct imx_hdmi *hdmi, u8 data, u8 mask, unsigned reg) 160 + { 161 + u8 val = hdmi_readb(hdmi, reg) & ~mask; 162 + val |= data & mask; 163 + hdmi_writeb(hdmi, val, reg); 164 + } 165 + 159 166 static void hdmi_mask_writeb(struct imx_hdmi *hdmi, u8 data, unsigned int reg, 160 167 u8 shift, u8 mask) 161 168 { 162 - u8 value = hdmi_readb(hdmi, reg) & ~mask; 163 - value |= (data << shift) & mask; 164 - hdmi_writeb(hdmi, value, reg); 169 + hdmi_modb(hdmi, data << shift, mask, reg); 165 170 } 166 171 167 172 static void hdmi_set_clock_regenerator_n(struct imx_hdmi *hdmi, 168 173 unsigned int value) 169 174 { 170 - u8 val; 171 - 172 175 hdmi_writeb(hdmi, value & 0xff, HDMI_AUD_N1); 173 176 hdmi_writeb(hdmi, (value >> 8) & 0xff, HDMI_AUD_N2); 174 177 hdmi_writeb(hdmi, (value >> 16) & 0x0f, HDMI_AUD_N3); 175 178 176 179 /* nshift factor = 0 */ 177 - val = hdmi_readb(hdmi, HDMI_AUD_CTS3); 178 - val &= ~HDMI_AUD_CTS3_N_SHIFT_MASK; 179 - hdmi_writeb(hdmi, val, HDMI_AUD_CTS3); 180 + hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3); 180 181 } 181 182 182 183 static void hdmi_regenerate_cts(struct imx_hdmi *hdmi, unsigned int cts) 183 184 { 184 - u8 val; 185 - 186 185 /* Must be set/cleared first */ 187 - val = hdmi_readb(hdmi, HDMI_AUD_CTS3); 188 - val &= ~HDMI_AUD_CTS3_CTS_MANUAL; 189 - hdmi_writeb(hdmi, val, HDMI_AUD_CTS3); 186 + hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); 190 187 191 188 hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1); 192 189 hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2); ··· 328 331 return (cts * ratio) / 100; 329 332 } 330 333 331 - static void hdmi_get_pixel_clk(struct imx_hdmi *hdmi) 332 - { 333 - unsigned long rate; 334 - 335 - rate = 65000000; /* FIXME */ 336 - 337 - if (rate) 338 - hdmi->pixel_clk_rate = rate; 339 - } 340 - 341 - static void hdmi_set_clk_regenerator(struct imx_hdmi *hdmi) 334 + static void hdmi_set_clk_regenerator(struct imx_hdmi *hdmi, 335 + unsigned long pixel_clk) 342 336 { 343 337 unsigned int clk_n, clk_cts; 344 338 345 - clk_n = hdmi_compute_n(hdmi->sample_rate, hdmi->pixel_clk_rate, 339 + clk_n = hdmi_compute_n(hdmi->sample_rate, pixel_clk, 346 340 hdmi->ratio); 347 - clk_cts = hdmi_compute_cts(hdmi->sample_rate, hdmi->pixel_clk_rate, 341 + clk_cts = hdmi_compute_cts(hdmi->sample_rate, pixel_clk, 348 342 hdmi->ratio); 349 343 350 344 if (!clk_cts) { 351 345 dev_dbg(hdmi->dev, "%s: pixel clock not supported: %lu\n", 352 - __func__, hdmi->pixel_clk_rate); 346 + __func__, pixel_clk); 353 347 return; 354 348 } 355 349 356 350 dev_dbg(hdmi->dev, "%s: samplerate=%d ratio=%d pixelclk=%lu N=%d cts=%d\n", 357 351 __func__, hdmi->sample_rate, hdmi->ratio, 358 - hdmi->pixel_clk_rate, clk_n, clk_cts); 352 + pixel_clk, clk_n, clk_cts); 359 353 360 354 hdmi_set_clock_regenerator_n(hdmi, clk_n); 361 355 hdmi_regenerate_cts(hdmi, clk_cts); ··· 354 366 355 367 static void hdmi_init_clk_regenerator(struct imx_hdmi *hdmi) 356 368 { 357 - unsigned int clk_n, clk_cts; 358 - 359 - clk_n = hdmi_compute_n(hdmi->sample_rate, hdmi->pixel_clk_rate, 360 - hdmi->ratio); 361 - clk_cts = hdmi_compute_cts(hdmi->sample_rate, hdmi->pixel_clk_rate, 362 - hdmi->ratio); 363 - 364 - if (!clk_cts) { 365 - dev_dbg(hdmi->dev, "%s: pixel clock not supported: %lu\n", 366 - __func__, hdmi->pixel_clk_rate); 367 - return; 368 - } 369 - 370 - dev_dbg(hdmi->dev, "%s: samplerate=%d ratio=%d pixelclk=%lu N=%d cts=%d\n", 371 - __func__, hdmi->sample_rate, hdmi->ratio, 372 - hdmi->pixel_clk_rate, clk_n, clk_cts); 373 - 374 - hdmi_set_clock_regenerator_n(hdmi, clk_n); 375 - hdmi_regenerate_cts(hdmi, clk_cts); 369 + hdmi_set_clk_regenerator(hdmi, 74250000); 376 370 } 377 371 378 372 static void hdmi_clk_regenerator_update_pixel_clock(struct imx_hdmi *hdmi) 379 373 { 380 - /* Get pixel clock from ipu */ 381 - hdmi_get_pixel_clk(hdmi); 382 - hdmi_set_clk_regenerator(hdmi); 374 + hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mpixelclock); 383 375 } 384 376 385 377 /* ··· 453 485 static void imx_hdmi_update_csc_coeffs(struct imx_hdmi *hdmi) 454 486 { 455 487 const u16 (*csc_coeff)[3][4] = &csc_coeff_default; 488 + unsigned i; 456 489 u32 csc_scale = 1; 457 - u8 val; 458 490 459 491 if (is_color_space_conversion(hdmi)) { 460 492 if (hdmi->hdmi_data.enc_out_format == RGB) { ··· 471 503 } 472 504 } 473 505 474 - hdmi_writeb(hdmi, ((*csc_coeff)[0][0] & 0xff), HDMI_CSC_COEF_A1_LSB); 475 - hdmi_writeb(hdmi, ((*csc_coeff)[0][0] >> 8), HDMI_CSC_COEF_A1_MSB); 476 - hdmi_writeb(hdmi, ((*csc_coeff)[0][1] & 0xff), HDMI_CSC_COEF_A2_LSB); 477 - hdmi_writeb(hdmi, ((*csc_coeff)[0][1] >> 8), HDMI_CSC_COEF_A2_MSB); 478 - hdmi_writeb(hdmi, ((*csc_coeff)[0][2] & 0xff), HDMI_CSC_COEF_A3_LSB); 479 - hdmi_writeb(hdmi, ((*csc_coeff)[0][2] >> 8), HDMI_CSC_COEF_A3_MSB); 480 - hdmi_writeb(hdmi, ((*csc_coeff)[0][3] & 0xff), HDMI_CSC_COEF_A4_LSB); 481 - hdmi_writeb(hdmi, ((*csc_coeff)[0][3] >> 8), HDMI_CSC_COEF_A4_MSB); 506 + /* The CSC registers are sequential, alternating MSB then LSB */ 507 + for (i = 0; i < ARRAY_SIZE(csc_coeff_default[0]); i++) { 508 + u16 coeff_a = (*csc_coeff)[0][i]; 509 + u16 coeff_b = (*csc_coeff)[1][i]; 510 + u16 coeff_c = (*csc_coeff)[2][i]; 482 511 483 - hdmi_writeb(hdmi, ((*csc_coeff)[1][0] & 0xff), HDMI_CSC_COEF_B1_LSB); 484 - hdmi_writeb(hdmi, ((*csc_coeff)[1][0] >> 8), HDMI_CSC_COEF_B1_MSB); 485 - hdmi_writeb(hdmi, ((*csc_coeff)[1][1] & 0xff), HDMI_CSC_COEF_B2_LSB); 486 - hdmi_writeb(hdmi, ((*csc_coeff)[1][1] >> 8), HDMI_CSC_COEF_B2_MSB); 487 - hdmi_writeb(hdmi, ((*csc_coeff)[1][2] & 0xff), HDMI_CSC_COEF_B3_LSB); 488 - hdmi_writeb(hdmi, ((*csc_coeff)[1][2] >> 8), HDMI_CSC_COEF_B3_MSB); 489 - hdmi_writeb(hdmi, ((*csc_coeff)[1][3] & 0xff), HDMI_CSC_COEF_B4_LSB); 490 - hdmi_writeb(hdmi, ((*csc_coeff)[1][3] >> 8), HDMI_CSC_COEF_B4_MSB); 512 + hdmi_writeb(hdmi, coeff_a & 0xff, HDMI_CSC_COEF_A1_LSB + i * 2); 513 + hdmi_writeb(hdmi, coeff_a >> 8, HDMI_CSC_COEF_A1_MSB + i * 2); 514 + hdmi_writeb(hdmi, coeff_b & 0xff, HDMI_CSC_COEF_B1_LSB + i * 2); 515 + hdmi_writeb(hdmi, coeff_b >> 8, HDMI_CSC_COEF_B1_MSB + i * 2); 516 + hdmi_writeb(hdmi, coeff_c & 0xff, HDMI_CSC_COEF_C1_LSB + i * 2); 517 + hdmi_writeb(hdmi, coeff_c >> 8, HDMI_CSC_COEF_C1_MSB + i * 2); 518 + } 491 519 492 - hdmi_writeb(hdmi, ((*csc_coeff)[2][0] & 0xff), HDMI_CSC_COEF_C1_LSB); 493 - hdmi_writeb(hdmi, ((*csc_coeff)[2][0] >> 8), HDMI_CSC_COEF_C1_MSB); 494 - hdmi_writeb(hdmi, ((*csc_coeff)[2][1] & 0xff), HDMI_CSC_COEF_C2_LSB); 495 - hdmi_writeb(hdmi, ((*csc_coeff)[2][1] >> 8), HDMI_CSC_COEF_C2_MSB); 496 - hdmi_writeb(hdmi, ((*csc_coeff)[2][2] & 0xff), HDMI_CSC_COEF_C3_LSB); 497 - hdmi_writeb(hdmi, ((*csc_coeff)[2][2] >> 8), HDMI_CSC_COEF_C3_MSB); 498 - hdmi_writeb(hdmi, ((*csc_coeff)[2][3] & 0xff), HDMI_CSC_COEF_C4_LSB); 499 - hdmi_writeb(hdmi, ((*csc_coeff)[2][3] >> 8), HDMI_CSC_COEF_C4_MSB); 500 - 501 - val = hdmi_readb(hdmi, HDMI_CSC_SCALE); 502 - val &= ~HDMI_CSC_SCALE_CSCSCALE_MASK; 503 - val |= csc_scale & HDMI_CSC_SCALE_CSCSCALE_MASK; 504 - hdmi_writeb(hdmi, val, HDMI_CSC_SCALE); 520 + hdmi_modb(hdmi, csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK, 521 + HDMI_CSC_SCALE); 505 522 } 506 523 507 524 static void hdmi_video_csc(struct imx_hdmi *hdmi) ··· 494 541 int color_depth = 0; 495 542 int interpolation = HDMI_CSC_CFG_INTMODE_DISABLE; 496 543 int decimation = 0; 497 - u8 val; 498 544 499 545 /* YCC422 interpolation to 444 mode */ 500 546 if (is_color_space_interpolation(hdmi)) ··· 514 562 515 563 /* Configure the CSC registers */ 516 564 hdmi_writeb(hdmi, interpolation | decimation, HDMI_CSC_CFG); 517 - val = hdmi_readb(hdmi, HDMI_CSC_SCALE); 518 - val &= ~HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK; 519 - val |= color_depth; 520 - hdmi_writeb(hdmi, val, HDMI_CSC_SCALE); 565 + hdmi_modb(hdmi, color_depth, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK, 566 + HDMI_CSC_SCALE); 521 567 522 568 imx_hdmi_update_csc_coeffs(hdmi); 523 569 } ··· 531 581 unsigned int remap_size = HDMI_VP_REMAP_YCC422_16bit; 532 582 unsigned int output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_PP; 533 583 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; 534 - u8 val; 584 + u8 val, vp_conf; 535 585 536 586 if (hdmi_data->enc_out_format == RGB 537 587 || hdmi_data->enc_out_format == YCBCR444) { ··· 570 620 HDMI_VP_PR_CD_DESIRED_PR_FACTOR_MASK); 571 621 hdmi_writeb(hdmi, val, HDMI_VP_PR_CD); 572 622 573 - val = hdmi_readb(hdmi, HDMI_VP_STUFF); 574 - val &= ~HDMI_VP_STUFF_PR_STUFFING_MASK; 575 - val |= HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE; 576 - hdmi_writeb(hdmi, val, HDMI_VP_STUFF); 623 + hdmi_modb(hdmi, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE, 624 + HDMI_VP_STUFF_PR_STUFFING_MASK, HDMI_VP_STUFF); 577 625 578 626 /* Data from pixel repeater block */ 579 627 if (hdmi_data->pix_repet_factor > 1) { 580 - val = hdmi_readb(hdmi, HDMI_VP_CONF); 581 - val &= ~(HDMI_VP_CONF_PR_EN_MASK | 582 - HDMI_VP_CONF_BYPASS_SELECT_MASK); 583 - val |= HDMI_VP_CONF_PR_EN_ENABLE | 584 - HDMI_VP_CONF_BYPASS_SELECT_PIX_REPEATER; 585 - hdmi_writeb(hdmi, val, HDMI_VP_CONF); 628 + vp_conf = HDMI_VP_CONF_PR_EN_ENABLE | 629 + HDMI_VP_CONF_BYPASS_SELECT_PIX_REPEATER; 586 630 } else { /* data from packetizer block */ 587 - val = hdmi_readb(hdmi, HDMI_VP_CONF); 588 - val &= ~(HDMI_VP_CONF_PR_EN_MASK | 589 - HDMI_VP_CONF_BYPASS_SELECT_MASK); 590 - val |= HDMI_VP_CONF_PR_EN_DISABLE | 591 - HDMI_VP_CONF_BYPASS_SELECT_VID_PACKETIZER; 592 - hdmi_writeb(hdmi, val, HDMI_VP_CONF); 631 + vp_conf = HDMI_VP_CONF_PR_EN_DISABLE | 632 + HDMI_VP_CONF_BYPASS_SELECT_VID_PACKETIZER; 593 633 } 594 634 595 - val = hdmi_readb(hdmi, HDMI_VP_STUFF); 596 - val &= ~HDMI_VP_STUFF_IDEFAULT_PHASE_MASK; 597 - val |= 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET; 598 - hdmi_writeb(hdmi, val, HDMI_VP_STUFF); 635 + hdmi_modb(hdmi, vp_conf, 636 + HDMI_VP_CONF_PR_EN_MASK | 637 + HDMI_VP_CONF_BYPASS_SELECT_MASK, HDMI_VP_CONF); 638 + 639 + hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET, 640 + HDMI_VP_STUFF_IDEFAULT_PHASE_MASK, HDMI_VP_STUFF); 599 641 600 642 hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP); 601 643 602 644 if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_PP) { 603 - val = hdmi_readb(hdmi, HDMI_VP_CONF); 604 - val &= ~(HDMI_VP_CONF_BYPASS_EN_MASK | 605 - HDMI_VP_CONF_PP_EN_ENMASK | 606 - HDMI_VP_CONF_YCC422_EN_MASK); 607 - val |= HDMI_VP_CONF_BYPASS_EN_DISABLE | 608 - HDMI_VP_CONF_PP_EN_ENABLE | 609 - HDMI_VP_CONF_YCC422_EN_DISABLE; 610 - hdmi_writeb(hdmi, val, HDMI_VP_CONF); 645 + vp_conf = HDMI_VP_CONF_BYPASS_EN_DISABLE | 646 + HDMI_VP_CONF_PP_EN_ENABLE | 647 + HDMI_VP_CONF_YCC422_EN_DISABLE; 611 648 } else if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422) { 612 - val = hdmi_readb(hdmi, HDMI_VP_CONF); 613 - val &= ~(HDMI_VP_CONF_BYPASS_EN_MASK | 614 - HDMI_VP_CONF_PP_EN_ENMASK | 615 - HDMI_VP_CONF_YCC422_EN_MASK); 616 - val |= HDMI_VP_CONF_BYPASS_EN_DISABLE | 617 - HDMI_VP_CONF_PP_EN_DISABLE | 618 - HDMI_VP_CONF_YCC422_EN_ENABLE; 619 - hdmi_writeb(hdmi, val, HDMI_VP_CONF); 649 + vp_conf = HDMI_VP_CONF_BYPASS_EN_DISABLE | 650 + HDMI_VP_CONF_PP_EN_DISABLE | 651 + HDMI_VP_CONF_YCC422_EN_ENABLE; 620 652 } else if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS) { 621 - val = hdmi_readb(hdmi, HDMI_VP_CONF); 622 - val &= ~(HDMI_VP_CONF_BYPASS_EN_MASK | 623 - HDMI_VP_CONF_PP_EN_ENMASK | 624 - HDMI_VP_CONF_YCC422_EN_MASK); 625 - val |= HDMI_VP_CONF_BYPASS_EN_ENABLE | 626 - HDMI_VP_CONF_PP_EN_DISABLE | 627 - HDMI_VP_CONF_YCC422_EN_DISABLE; 628 - hdmi_writeb(hdmi, val, HDMI_VP_CONF); 653 + vp_conf = HDMI_VP_CONF_BYPASS_EN_ENABLE | 654 + HDMI_VP_CONF_PP_EN_DISABLE | 655 + HDMI_VP_CONF_YCC422_EN_DISABLE; 629 656 } else { 630 657 return; 631 658 } 632 659 633 - val = hdmi_readb(hdmi, HDMI_VP_STUFF); 634 - val &= ~(HDMI_VP_STUFF_PP_STUFFING_MASK | 635 - HDMI_VP_STUFF_YCC422_STUFFING_MASK); 636 - val |= HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE | 637 - HDMI_VP_STUFF_YCC422_STUFFING_STUFFING_MODE; 638 - hdmi_writeb(hdmi, val, HDMI_VP_STUFF); 660 + hdmi_modb(hdmi, vp_conf, 661 + HDMI_VP_CONF_BYPASS_EN_MASK | HDMI_VP_CONF_PP_EN_ENMASK | 662 + HDMI_VP_CONF_YCC422_EN_MASK, HDMI_VP_CONF); 639 663 640 - val = hdmi_readb(hdmi, HDMI_VP_CONF); 641 - val &= ~HDMI_VP_CONF_OUTPUT_SELECTOR_MASK; 642 - val |= output_select; 643 - hdmi_writeb(hdmi, val, HDMI_VP_CONF); 664 + hdmi_modb(hdmi, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE | 665 + HDMI_VP_STUFF_YCC422_STUFFING_STUFFING_MODE, 666 + HDMI_VP_STUFF_PP_STUFFING_MASK | 667 + HDMI_VP_STUFF_YCC422_STUFFING_MASK, HDMI_VP_STUFF); 668 + 669 + hdmi_modb(hdmi, output_select, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK, 670 + HDMI_VP_CONF); 644 671 } 645 672 646 673 static inline void hdmi_phy_test_clear(struct imx_hdmi *hdmi, 647 674 unsigned char bit) 648 675 { 649 - u8 val = hdmi_readb(hdmi, HDMI_PHY_TST0); 650 - val &= ~HDMI_PHY_TST0_TSTCLR_MASK; 651 - val |= (bit << HDMI_PHY_TST0_TSTCLR_OFFSET) & 652 - HDMI_PHY_TST0_TSTCLR_MASK; 653 - hdmi_writeb(hdmi, val, HDMI_PHY_TST0); 676 + hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLR_OFFSET, 677 + HDMI_PHY_TST0_TSTCLR_MASK, HDMI_PHY_TST0); 654 678 } 655 679 656 680 static inline void hdmi_phy_test_enable(struct imx_hdmi *hdmi, 657 681 unsigned char bit) 658 682 { 659 - u8 val = hdmi_readb(hdmi, HDMI_PHY_TST0); 660 - val &= ~HDMI_PHY_TST0_TSTEN_MASK; 661 - val |= (bit << HDMI_PHY_TST0_TSTEN_OFFSET) & 662 - HDMI_PHY_TST0_TSTEN_MASK; 663 - hdmi_writeb(hdmi, val, HDMI_PHY_TST0); 683 + hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTEN_OFFSET, 684 + HDMI_PHY_TST0_TSTEN_MASK, HDMI_PHY_TST0); 664 685 } 665 686 666 687 static inline void hdmi_phy_test_clock(struct imx_hdmi *hdmi, 667 688 unsigned char bit) 668 689 { 669 - u8 val = hdmi_readb(hdmi, HDMI_PHY_TST0); 670 - val &= ~HDMI_PHY_TST0_TSTCLK_MASK; 671 - val |= (bit << HDMI_PHY_TST0_TSTCLK_OFFSET) & 672 - HDMI_PHY_TST0_TSTCLK_MASK; 673 - hdmi_writeb(hdmi, val, HDMI_PHY_TST0); 690 + hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLK_OFFSET, 691 + HDMI_PHY_TST0_TSTCLK_MASK, HDMI_PHY_TST0); 674 692 } 675 693 676 694 static inline void hdmi_phy_test_din(struct imx_hdmi *hdmi, ··· 729 811 HDMI_PHY_CONF0_SELDIPIF_MASK); 730 812 } 731 813 814 + enum { 815 + RES_8, 816 + RES_10, 817 + RES_12, 818 + RES_MAX, 819 + }; 820 + 821 + struct mpll_config { 822 + unsigned long mpixelclock; 823 + struct { 824 + u16 cpce; 825 + u16 gmp; 826 + } res[RES_MAX]; 827 + }; 828 + 829 + static const struct mpll_config mpll_config[] = { 830 + { 831 + 45250000, { 832 + { 0x01e0, 0x0000 }, 833 + { 0x21e1, 0x0000 }, 834 + { 0x41e2, 0x0000 } 835 + }, 836 + }, { 837 + 92500000, { 838 + { 0x0140, 0x0005 }, 839 + { 0x2141, 0x0005 }, 840 + { 0x4142, 0x0005 }, 841 + }, 842 + }, { 843 + 148500000, { 844 + { 0x00a0, 0x000a }, 845 + { 0x20a1, 0x000a }, 846 + { 0x40a2, 0x000a }, 847 + }, 848 + }, { 849 + ~0UL, { 850 + { 0x00a0, 0x000a }, 851 + { 0x2001, 0x000f }, 852 + { 0x4002, 0x000f }, 853 + }, 854 + } 855 + }; 856 + 857 + struct curr_ctrl { 858 + unsigned long mpixelclock; 859 + u16 curr[RES_MAX]; 860 + }; 861 + 862 + static const struct curr_ctrl curr_ctrl[] = { 863 + /* pixelclk bpp8 bpp10 bpp12 */ 864 + { 865 + 54000000, { 0x091c, 0x091c, 0x06dc }, 866 + }, { 867 + 58400000, { 0x091c, 0x06dc, 0x06dc }, 868 + }, { 869 + 72000000, { 0x06dc, 0x06dc, 0x091c }, 870 + }, { 871 + 74250000, { 0x06dc, 0x0b5c, 0x091c }, 872 + }, { 873 + 118800000, { 0x091c, 0x091c, 0x06dc }, 874 + }, { 875 + 216000000, { 0x06dc, 0x0b5c, 0x091c }, 876 + } 877 + }; 878 + 732 879 static int hdmi_phy_configure(struct imx_hdmi *hdmi, unsigned char prep, 733 880 unsigned char res, int cscon) 734 881 { 882 + unsigned res_idx, i; 735 883 u8 val, msec; 736 - 737 - /* color resolution 0 is 8 bit colour depth */ 738 - if (!res) 739 - res = 8; 740 884 741 885 if (prep) 742 886 return -EINVAL; 743 - else if (res != 8 && res != 12) 887 + 888 + switch (res) { 889 + case 0: /* color resolution 0 is 8 bit colour depth */ 890 + case 8: 891 + res_idx = RES_8; 892 + break; 893 + case 10: 894 + res_idx = RES_10; 895 + break; 896 + case 12: 897 + res_idx = RES_12; 898 + break; 899 + default: 744 900 return -EINVAL; 901 + } 745 902 746 903 /* Enable csc path */ 747 904 if (cscon) ··· 843 850 HDMI_PHY_I2CM_SLAVE_ADDR); 844 851 hdmi_phy_test_clear(hdmi, 0); 845 852 846 - if (hdmi->hdmi_data.video_mode.mpixelclock <= 45250000) { 847 - switch (res) { 848 - case 8: 849 - /* PLL/MPLL Cfg */ 850 - hdmi_phy_i2c_write(hdmi, 0x01e0, 0x06); 851 - hdmi_phy_i2c_write(hdmi, 0x0000, 0x15); /* GMPCTRL */ 853 + /* PLL/MPLL Cfg - always match on final entry */ 854 + for (i = 0; i < ARRAY_SIZE(mpll_config) - 1; i++) 855 + if (hdmi->hdmi_data.video_mode.mpixelclock <= 856 + mpll_config[i].mpixelclock) 852 857 break; 853 - case 10: 854 - hdmi_phy_i2c_write(hdmi, 0x21e1, 0x06); 855 - hdmi_phy_i2c_write(hdmi, 0x0000, 0x15); 856 - break; 857 - case 12: 858 - hdmi_phy_i2c_write(hdmi, 0x41e2, 0x06); 859 - hdmi_phy_i2c_write(hdmi, 0x0000, 0x15); 860 - break; 861 - default: 862 - return -EINVAL; 863 - } 864 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 92500000) { 865 - switch (res) { 866 - case 8: 867 - hdmi_phy_i2c_write(hdmi, 0x0140, 0x06); 868 - hdmi_phy_i2c_write(hdmi, 0x0005, 0x15); 869 - break; 870 - case 10: 871 - hdmi_phy_i2c_write(hdmi, 0x2141, 0x06); 872 - hdmi_phy_i2c_write(hdmi, 0x0005, 0x15); 873 - break; 874 - case 12: 875 - hdmi_phy_i2c_write(hdmi, 0x4142, 0x06); 876 - hdmi_phy_i2c_write(hdmi, 0x0005, 0x15); 877 - default: 878 - return -EINVAL; 879 - } 880 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 148500000) { 881 - switch (res) { 882 - case 8: 883 - hdmi_phy_i2c_write(hdmi, 0x00a0, 0x06); 884 - hdmi_phy_i2c_write(hdmi, 0x000a, 0x15); 885 - break; 886 - case 10: 887 - hdmi_phy_i2c_write(hdmi, 0x20a1, 0x06); 888 - hdmi_phy_i2c_write(hdmi, 0x000a, 0x15); 889 - break; 890 - case 12: 891 - hdmi_phy_i2c_write(hdmi, 0x40a2, 0x06); 892 - hdmi_phy_i2c_write(hdmi, 0x000a, 0x15); 893 - default: 894 - return -EINVAL; 895 - } 896 - } else { 897 - switch (res) { 898 - case 8: 899 - hdmi_phy_i2c_write(hdmi, 0x00a0, 0x06); 900 - hdmi_phy_i2c_write(hdmi, 0x000a, 0x15); 901 - break; 902 - case 10: 903 - hdmi_phy_i2c_write(hdmi, 0x2001, 0x06); 904 - hdmi_phy_i2c_write(hdmi, 0x000f, 0x15); 905 - break; 906 - case 12: 907 - hdmi_phy_i2c_write(hdmi, 0x4002, 0x06); 908 - hdmi_phy_i2c_write(hdmi, 0x000f, 0x15); 909 - default: 910 - return -EINVAL; 911 - } 912 - } 913 858 914 - if (hdmi->hdmi_data.video_mode.mpixelclock <= 54000000) { 915 - switch (res) { 916 - case 8: 917 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); /* CURRCTRL */ 859 + hdmi_phy_i2c_write(hdmi, mpll_config[i].res[res_idx].cpce, 0x06); 860 + hdmi_phy_i2c_write(hdmi, mpll_config[i].res[res_idx].gmp, 0x15); 861 + 862 + for (i = 0; i < ARRAY_SIZE(curr_ctrl); i++) 863 + if (hdmi->hdmi_data.video_mode.mpixelclock <= 864 + curr_ctrl[i].mpixelclock) 918 865 break; 919 - case 10: 920 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 921 - break; 922 - case 12: 923 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 924 - break; 925 - default: 926 - return -EINVAL; 927 - } 928 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 58400000) { 929 - switch (res) { 930 - case 8: 931 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 932 - break; 933 - case 10: 934 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 935 - break; 936 - case 12: 937 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 938 - break; 939 - default: 940 - return -EINVAL; 941 - } 942 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 72000000) { 943 - switch (res) { 944 - case 8: 945 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 946 - break; 947 - case 10: 948 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 949 - break; 950 - case 12: 951 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 952 - break; 953 - default: 954 - return -EINVAL; 955 - } 956 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 74250000) { 957 - switch (res) { 958 - case 8: 959 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 960 - break; 961 - case 10: 962 - hdmi_phy_i2c_write(hdmi, 0x0b5c, 0x10); 963 - break; 964 - case 12: 965 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 966 - break; 967 - default: 968 - return -EINVAL; 969 - } 970 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 118800000) { 971 - switch (res) { 972 - case 8: 973 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 974 - break; 975 - case 10: 976 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 977 - break; 978 - case 12: 979 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 980 - break; 981 - default: 982 - return -EINVAL; 983 - } 984 - } else if (hdmi->hdmi_data.video_mode.mpixelclock <= 216000000) { 985 - switch (res) { 986 - case 8: 987 - hdmi_phy_i2c_write(hdmi, 0x06dc, 0x10); 988 - break; 989 - case 10: 990 - hdmi_phy_i2c_write(hdmi, 0x0b5c, 0x10); 991 - break; 992 - case 12: 993 - hdmi_phy_i2c_write(hdmi, 0x091c, 0x10); 994 - break; 995 - default: 996 - return -EINVAL; 997 - } 998 - } else { 866 + 867 + if (i >= ARRAY_SIZE(curr_ctrl)) { 999 868 dev_err(hdmi->dev, 1000 869 "Pixel clock %d - unsupported by HDMI\n", 1001 870 hdmi->hdmi_data.video_mode.mpixelclock); 1002 871 return -EINVAL; 1003 872 } 873 + 874 + /* CURRCTRL */ 875 + hdmi_phy_i2c_write(hdmi, curr_ctrl[i].curr[res_idx], 0x10); 1004 876 1005 877 hdmi_phy_i2c_write(hdmi, 0x0000, 0x13); /* PLLPHBYCTRL */ 1006 878 hdmi_phy_i2c_write(hdmi, 0x0006, 0x17); ··· 935 1077 936 1078 static void hdmi_tx_hdcp_config(struct imx_hdmi *hdmi) 937 1079 { 938 - u8 de, val; 1080 + u8 de; 939 1081 940 1082 if (hdmi->hdmi_data.video_mode.mdataenablepolarity) 941 1083 de = HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_HIGH; ··· 943 1085 de = HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_LOW; 944 1086 945 1087 /* disable rx detect */ 946 - val = hdmi_readb(hdmi, HDMI_A_HDCPCFG0); 947 - val &= HDMI_A_HDCPCFG0_RXDETECT_MASK; 948 - val |= HDMI_A_HDCPCFG0_RXDETECT_DISABLE; 949 - hdmi_writeb(hdmi, val, HDMI_A_HDCPCFG0); 1088 + hdmi_modb(hdmi, HDMI_A_HDCPCFG0_RXDETECT_DISABLE, 1089 + HDMI_A_HDCPCFG0_RXDETECT_MASK, HDMI_A_HDCPCFG0); 950 1090 951 - val = hdmi_readb(hdmi, HDMI_A_VIDPOLCFG); 952 - val &= HDMI_A_VIDPOLCFG_DATAENPOL_MASK; 953 - val |= de; 954 - hdmi_writeb(hdmi, val, HDMI_A_VIDPOLCFG); 1091 + hdmi_modb(hdmi, de, HDMI_A_VIDPOLCFG_DATAENPOL_MASK, HDMI_A_VIDPOLCFG); 955 1092 956 - val = hdmi_readb(hdmi, HDMI_A_HDCPCFG1); 957 - val &= HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_MASK; 958 - val |= HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE; 959 - hdmi_writeb(hdmi, val, HDMI_A_HDCPCFG1); 1093 + hdmi_modb(hdmi, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE, 1094 + HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_MASK, HDMI_A_HDCPCFG1); 960 1095 } 961 1096 962 1097 static void hdmi_config_AVI(struct imx_hdmi *hdmi) ··· 1173 1322 1174 1323 static void hdmi_enable_audio_clk(struct imx_hdmi *hdmi) 1175 1324 { 1176 - u8 clkdis; 1177 - 1178 - clkdis = hdmi_readb(hdmi, HDMI_MC_CLKDIS); 1179 - clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE; 1180 - hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS); 1325 + hdmi_modb(hdmi, 0, HDMI_MC_CLKDIS_AUDCLK_DISABLE, HDMI_MC_CLKDIS); 1181 1326 } 1182 1327 1183 1328 /* Workaround to clear the overflow condition */ ··· 1308 1461 /* Clear Hotplug interrupts */ 1309 1462 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD, HDMI_IH_PHY_STAT0); 1310 1463 1311 - /* Unmute interrupts */ 1312 - hdmi_writeb(hdmi, ~HDMI_IH_PHY_STAT0_HPD, HDMI_IH_MUTE_PHY_STAT0); 1313 - 1314 1464 return 0; 1315 1465 } 1316 1466 ··· 1376 1532 static enum drm_connector_status imx_hdmi_connector_detect(struct drm_connector 1377 1533 *connector, bool force) 1378 1534 { 1379 - /* FIXME */ 1380 - return connector_status_connected; 1381 - } 1382 - 1383 - static void imx_hdmi_connector_destroy(struct drm_connector *connector) 1384 - { 1535 + struct imx_hdmi *hdmi = container_of(connector, struct imx_hdmi, 1536 + connector); 1537 + return hdmi->connector_status; 1385 1538 } 1386 1539 1387 1540 static int imx_hdmi_connector_get_modes(struct drm_connector *connector) ··· 1404 1563 } 1405 1564 1406 1565 return 0; 1407 - } 1408 - 1409 - static int imx_hdmi_connector_mode_valid(struct drm_connector *connector, 1410 - struct drm_display_mode *mode) 1411 - { 1412 - 1413 - return MODE_OK; 1414 1566 } 1415 1567 1416 1568 static struct drm_encoder *imx_hdmi_connector_best_encoder(struct drm_connector ··· 1453 1619 struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder); 1454 1620 1455 1621 imx_hdmi_poweroff(hdmi); 1456 - imx_drm_crtc_panel_format(encoder->crtc, DRM_MODE_ENCODER_NONE, 1457 - V4L2_PIX_FMT_RGB24); 1622 + imx_drm_panel_format(encoder, V4L2_PIX_FMT_RGB24); 1458 1623 } 1459 1624 1460 1625 static void imx_hdmi_encoder_commit(struct drm_encoder *encoder) 1461 1626 { 1462 1627 struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder); 1463 - int mux = imx_drm_encoder_get_mux_id(hdmi->imx_drm_encoder, 1464 - encoder->crtc); 1628 + int mux = imx_drm_encoder_get_mux_id(encoder); 1465 1629 1466 1630 imx_hdmi_set_ipu_di_mux(hdmi, mux); 1467 1631 1468 1632 imx_hdmi_poweron(hdmi); 1469 1633 } 1470 1634 1471 - static void imx_hdmi_encoder_destroy(struct drm_encoder *encoder) 1472 - { 1473 - return; 1474 - } 1475 - 1476 1635 static struct drm_encoder_funcs imx_hdmi_encoder_funcs = { 1477 - .destroy = imx_hdmi_encoder_destroy, 1636 + .destroy = imx_drm_encoder_destroy, 1478 1637 }; 1479 1638 1480 1639 static struct drm_encoder_helper_funcs imx_hdmi_encoder_helper_funcs = { ··· 1483 1656 .dpms = drm_helper_connector_dpms, 1484 1657 .fill_modes = drm_helper_probe_single_connector_modes, 1485 1658 .detect = imx_hdmi_connector_detect, 1486 - .destroy = imx_hdmi_connector_destroy, 1659 + .destroy = imx_drm_connector_destroy, 1487 1660 }; 1488 1661 1489 1662 static struct drm_connector_helper_funcs imx_hdmi_connector_helper_funcs = { 1490 1663 .get_modes = imx_hdmi_connector_get_modes, 1491 - .mode_valid = imx_hdmi_connector_mode_valid, 1664 + .mode_valid = imx_drm_connector_mode_valid, 1492 1665 .best_encoder = imx_hdmi_connector_best_encoder, 1493 1666 }; 1667 + 1668 + static irqreturn_t imx_hdmi_hardirq(int irq, void *dev_id) 1669 + { 1670 + struct imx_hdmi *hdmi = dev_id; 1671 + u8 intr_stat; 1672 + 1673 + intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); 1674 + if (intr_stat) 1675 + hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); 1676 + 1677 + return intr_stat ? IRQ_WAKE_THREAD : IRQ_NONE; 1678 + } 1494 1679 1495 1680 static irqreturn_t imx_hdmi_irq(int irq, void *dev_id) 1496 1681 { 1497 1682 struct imx_hdmi *hdmi = dev_id; 1498 1683 u8 intr_stat; 1499 1684 u8 phy_int_pol; 1500 - u8 val; 1501 1685 1502 1686 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); 1503 1687 ··· 1518 1680 if (phy_int_pol & HDMI_PHY_HPD) { 1519 1681 dev_dbg(hdmi->dev, "EVENT=plugin\n"); 1520 1682 1521 - val = hdmi_readb(hdmi, HDMI_PHY_POL0); 1522 - val &= ~HDMI_PHY_HPD; 1523 - hdmi_writeb(hdmi, val, HDMI_PHY_POL0); 1683 + hdmi_modb(hdmi, 0, HDMI_PHY_HPD, HDMI_PHY_POL0); 1524 1684 1685 + hdmi->connector_status = connector_status_connected; 1525 1686 imx_hdmi_poweron(hdmi); 1526 1687 } else { 1527 1688 dev_dbg(hdmi->dev, "EVENT=plugout\n"); 1528 1689 1529 - val = hdmi_readb(hdmi, HDMI_PHY_POL0); 1530 - val |= HDMI_PHY_HPD; 1531 - hdmi_writeb(hdmi, val, HDMI_PHY_POL0); 1690 + hdmi_modb(hdmi, HDMI_PHY_HPD, HDMI_PHY_HPD, HDMI_PHY_POL0); 1532 1691 1692 + hdmi->connector_status = connector_status_disconnected; 1533 1693 imx_hdmi_poweroff(hdmi); 1534 1694 } 1695 + drm_helper_hpd_irq_event(hdmi->connector.dev); 1535 1696 } 1536 1697 1537 1698 hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0); 1699 + hdmi_writeb(hdmi, ~HDMI_IH_PHY_STAT0_HPD, HDMI_IH_MUTE_PHY_STAT0); 1538 1700 1539 1701 return IRQ_HANDLED; 1540 1702 } 1541 1703 1542 - static int imx_hdmi_register(struct imx_hdmi *hdmi) 1704 + static int imx_hdmi_register(struct drm_device *drm, struct imx_hdmi *hdmi) 1543 1705 { 1544 1706 int ret; 1545 1707 1546 - hdmi->connector.funcs = &imx_hdmi_connector_funcs; 1547 - hdmi->encoder.funcs = &imx_hdmi_encoder_funcs; 1708 + ret = imx_drm_encoder_parse_of(drm, &hdmi->encoder, 1709 + hdmi->dev->of_node); 1710 + if (ret) 1711 + return ret; 1548 1712 1549 - hdmi->encoder.encoder_type = DRM_MODE_ENCODER_TMDS; 1550 - hdmi->connector.connector_type = DRM_MODE_CONNECTOR_HDMIA; 1713 + hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD; 1551 1714 1552 1715 drm_encoder_helper_add(&hdmi->encoder, &imx_hdmi_encoder_helper_funcs); 1553 - ret = imx_drm_add_encoder(&hdmi->encoder, &hdmi->imx_drm_encoder, 1554 - THIS_MODULE); 1555 - if (ret) { 1556 - dev_err(hdmi->dev, "adding encoder failed: %d\n", ret); 1557 - return ret; 1558 - } 1716 + drm_encoder_init(drm, &hdmi->encoder, &imx_hdmi_encoder_funcs, 1717 + DRM_MODE_ENCODER_TMDS); 1559 1718 1560 1719 drm_connector_helper_add(&hdmi->connector, 1561 1720 &imx_hdmi_connector_helper_funcs); 1562 - 1563 - ret = imx_drm_add_connector(&hdmi->connector, 1564 - &hdmi->imx_drm_connector, THIS_MODULE); 1565 - if (ret) { 1566 - imx_drm_remove_encoder(hdmi->imx_drm_encoder); 1567 - dev_err(hdmi->dev, "adding connector failed: %d\n", ret); 1568 - return ret; 1569 - } 1721 + drm_connector_init(drm, &hdmi->connector, &imx_hdmi_connector_funcs, 1722 + DRM_MODE_CONNECTOR_HDMIA); 1570 1723 1571 1724 hdmi->connector.encoder = &hdmi->encoder; 1572 1725 ··· 1584 1755 }; 1585 1756 MODULE_DEVICE_TABLE(of, imx_hdmi_dt_ids); 1586 1757 1587 - static int imx_hdmi_platform_probe(struct platform_device *pdev) 1758 + static int imx_hdmi_bind(struct device *dev, struct device *master, void *data) 1588 1759 { 1760 + struct platform_device *pdev = to_platform_device(dev); 1589 1761 const struct of_device_id *of_id = 1590 - of_match_device(imx_hdmi_dt_ids, &pdev->dev); 1591 - struct device_node *np = pdev->dev.of_node; 1762 + of_match_device(imx_hdmi_dt_ids, dev); 1763 + struct drm_device *drm = data; 1764 + struct device_node *np = dev->of_node; 1592 1765 struct device_node *ddc_node; 1593 1766 struct imx_hdmi *hdmi; 1594 1767 struct resource *iores; 1595 1768 int ret, irq; 1596 1769 1597 - hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); 1770 + hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); 1598 1771 if (!hdmi) 1599 1772 return -ENOMEM; 1600 1773 1601 - hdmi->dev = &pdev->dev; 1774 + hdmi->dev = dev; 1775 + hdmi->connector_status = connector_status_disconnected; 1776 + hdmi->sample_rate = 48000; 1777 + hdmi->ratio = 100; 1602 1778 1603 1779 if (of_id) { 1604 1780 const struct platform_device_id *device_id = of_id->data; ··· 1625 1791 if (irq < 0) 1626 1792 return -EINVAL; 1627 1793 1628 - ret = devm_request_irq(&pdev->dev, irq, imx_hdmi_irq, 0, 1629 - dev_name(&pdev->dev), hdmi); 1794 + ret = devm_request_threaded_irq(dev, irq, imx_hdmi_hardirq, 1795 + imx_hdmi_irq, IRQF_SHARED, 1796 + dev_name(dev), hdmi); 1630 1797 if (ret) 1631 1798 return ret; 1632 1799 1633 1800 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1634 - hdmi->regs = devm_ioremap_resource(&pdev->dev, iores); 1801 + hdmi->regs = devm_ioremap_resource(dev, iores); 1635 1802 if (IS_ERR(hdmi->regs)) 1636 1803 return PTR_ERR(hdmi->regs); 1637 1804 ··· 1671 1836 } 1672 1837 1673 1838 /* Product and revision IDs */ 1674 - dev_info(&pdev->dev, 1839 + dev_info(dev, 1675 1840 "Detected HDMI controller 0x%x:0x%x:0x%x:0x%x\n", 1676 1841 hdmi_readb(hdmi, HDMI_DESIGN_ID), 1677 1842 hdmi_readb(hdmi, HDMI_REVISION_ID), ··· 1699 1864 if (ret) 1700 1865 goto err_iahb; 1701 1866 1702 - ret = imx_hdmi_register(hdmi); 1867 + ret = imx_hdmi_register(drm, hdmi); 1703 1868 if (ret) 1704 1869 goto err_iahb; 1705 1870 1706 - imx_drm_encoder_add_possible_crtcs(hdmi->imx_drm_encoder, np); 1871 + /* Unmute interrupts */ 1872 + hdmi_writeb(hdmi, ~HDMI_IH_PHY_STAT0_HPD, HDMI_IH_MUTE_PHY_STAT0); 1707 1873 1708 - platform_set_drvdata(pdev, hdmi); 1874 + dev_set_drvdata(dev, hdmi); 1709 1875 1710 1876 return 0; 1711 1877 ··· 1718 1882 return ret; 1719 1883 } 1720 1884 1721 - static int imx_hdmi_platform_remove(struct platform_device *pdev) 1885 + static void imx_hdmi_unbind(struct device *dev, struct device *master, 1886 + void *data) 1722 1887 { 1723 - struct imx_hdmi *hdmi = platform_get_drvdata(pdev); 1724 - struct drm_connector *connector = &hdmi->connector; 1725 - struct drm_encoder *encoder = &hdmi->encoder; 1888 + struct imx_hdmi *hdmi = dev_get_drvdata(dev); 1726 1889 1727 - drm_mode_connector_detach_encoder(connector, encoder); 1728 - imx_drm_remove_connector(hdmi->imx_drm_connector); 1729 - imx_drm_remove_encoder(hdmi->imx_drm_encoder); 1890 + /* Disable all interrupts */ 1891 + hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); 1892 + 1893 + hdmi->connector.funcs->destroy(&hdmi->connector); 1894 + hdmi->encoder.funcs->destroy(&hdmi->encoder); 1730 1895 1731 1896 clk_disable_unprepare(hdmi->iahb_clk); 1732 1897 clk_disable_unprepare(hdmi->isfr_clk); 1733 1898 i2c_put_adapter(hdmi->ddc); 1899 + } 1734 1900 1901 + static const struct component_ops hdmi_ops = { 1902 + .bind = imx_hdmi_bind, 1903 + .unbind = imx_hdmi_unbind, 1904 + }; 1905 + 1906 + static int imx_hdmi_platform_probe(struct platform_device *pdev) 1907 + { 1908 + return component_add(&pdev->dev, &hdmi_ops); 1909 + } 1910 + 1911 + static int imx_hdmi_platform_remove(struct platform_device *pdev) 1912 + { 1913 + component_del(&pdev->dev, &hdmi_ops); 1735 1914 return 0; 1736 1915 } 1737 1916
+54 -71
drivers/staging/imx-drm/imx-ldb.c
··· 20 20 21 21 #include <linux/module.h> 22 22 #include <linux/clk.h> 23 + #include <linux/component.h> 23 24 #include <drm/drmP.h> 24 25 #include <drm/drm_fb_helper.h> 25 26 #include <drm/drm_crtc_helper.h> ··· 59 58 struct imx_ldb_channel { 60 59 struct imx_ldb *ldb; 61 60 struct drm_connector connector; 62 - struct imx_drm_connector *imx_drm_connector; 63 61 struct drm_encoder encoder; 64 - struct imx_drm_encoder *imx_drm_encoder; 62 + struct device_node *child; 65 63 int chno; 66 64 void *edid; 67 65 int edid_len; ··· 91 91 return connector_status_connected; 92 92 } 93 93 94 - static void imx_ldb_connector_destroy(struct drm_connector *connector) 95 - { 96 - /* do not free here */ 97 - } 98 - 99 94 static int imx_ldb_connector_get_modes(struct drm_connector *connector) 100 95 { 101 96 struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector); ··· 113 118 } 114 119 115 120 return num_modes; 116 - } 117 - 118 - static int imx_ldb_connector_mode_valid(struct drm_connector *connector, 119 - struct drm_display_mode *mode) 120 - { 121 - return 0; 122 121 } 123 122 124 123 static struct drm_encoder *imx_ldb_connector_best_encoder( ··· 168 179 u32 pixel_fmt; 169 180 unsigned long serial_clk; 170 181 unsigned long di_clk = mode->clock * 1000; 171 - int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->imx_drm_encoder, 172 - encoder->crtc); 182 + int mux = imx_drm_encoder_get_mux_id(encoder); 173 183 174 184 if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) { 175 185 /* dual channel LVDS mode */ ··· 195 207 pixel_fmt = V4L2_PIX_FMT_RGB24; 196 208 } 197 209 198 - imx_drm_crtc_panel_format(encoder->crtc, DRM_MODE_ENCODER_LVDS, 199 - pixel_fmt); 210 + imx_drm_panel_format(encoder, pixel_fmt); 200 211 } 201 212 202 213 static void imx_ldb_encoder_commit(struct drm_encoder *encoder) ··· 203 216 struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); 204 217 struct imx_ldb *ldb = imx_ldb_ch->ldb; 205 218 int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; 206 - int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->imx_drm_encoder, 207 - encoder->crtc); 219 + int mux = imx_drm_encoder_get_mux_id(encoder); 208 220 209 221 if (dual) { 210 222 clk_prepare_enable(ldb->clk[0]); ··· 302 316 } 303 317 } 304 318 305 - static void imx_ldb_encoder_destroy(struct drm_encoder *encoder) 306 - { 307 - /* do not free here */ 308 - } 309 - 310 319 static struct drm_connector_funcs imx_ldb_connector_funcs = { 311 320 .dpms = drm_helper_connector_dpms, 312 321 .fill_modes = drm_helper_probe_single_connector_modes, 313 322 .detect = imx_ldb_connector_detect, 314 - .destroy = imx_ldb_connector_destroy, 323 + .destroy = imx_drm_connector_destroy, 315 324 }; 316 325 317 326 static struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs = { 318 327 .get_modes = imx_ldb_connector_get_modes, 319 328 .best_encoder = imx_ldb_connector_best_encoder, 320 - .mode_valid = imx_ldb_connector_mode_valid, 329 + .mode_valid = imx_drm_connector_mode_valid, 321 330 }; 322 331 323 332 static struct drm_encoder_funcs imx_ldb_encoder_funcs = { 324 - .destroy = imx_ldb_encoder_destroy, 333 + .destroy = imx_drm_encoder_destroy, 325 334 }; 326 335 327 336 static struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = { ··· 343 362 return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]); 344 363 } 345 364 346 - static int imx_ldb_register(struct imx_ldb_channel *imx_ldb_ch) 365 + static int imx_ldb_register(struct drm_device *drm, 366 + struct imx_ldb_channel *imx_ldb_ch) 347 367 { 348 - int ret; 349 368 struct imx_ldb *ldb = imx_ldb_ch->ldb; 369 + int ret; 370 + 371 + ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->encoder, 372 + imx_ldb_ch->child); 373 + if (ret) 374 + return ret; 350 375 351 376 ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno); 352 377 if (ret) 353 378 return ret; 379 + 354 380 if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) { 355 - ret |= imx_ldb_get_clk(ldb, 1); 381 + ret = imx_ldb_get_clk(ldb, 1); 356 382 if (ret) 357 383 return ret; 358 384 } 359 385 360 - imx_ldb_ch->connector.funcs = &imx_ldb_connector_funcs; 361 - imx_ldb_ch->encoder.funcs = &imx_ldb_encoder_funcs; 362 - 363 - imx_ldb_ch->encoder.encoder_type = DRM_MODE_ENCODER_LVDS; 364 - imx_ldb_ch->connector.connector_type = DRM_MODE_CONNECTOR_LVDS; 365 - 366 386 drm_encoder_helper_add(&imx_ldb_ch->encoder, 367 387 &imx_ldb_encoder_helper_funcs); 368 - ret = imx_drm_add_encoder(&imx_ldb_ch->encoder, 369 - &imx_ldb_ch->imx_drm_encoder, THIS_MODULE); 370 - if (ret) { 371 - dev_err(ldb->dev, "adding encoder failed with %d\n", ret); 372 - return ret; 373 - } 388 + drm_encoder_init(drm, &imx_ldb_ch->encoder, &imx_ldb_encoder_funcs, 389 + DRM_MODE_ENCODER_LVDS); 374 390 375 391 drm_connector_helper_add(&imx_ldb_ch->connector, 376 392 &imx_ldb_connector_helper_funcs); 377 - 378 - ret = imx_drm_add_connector(&imx_ldb_ch->connector, 379 - &imx_ldb_ch->imx_drm_connector, THIS_MODULE); 380 - if (ret) { 381 - imx_drm_remove_encoder(imx_ldb_ch->imx_drm_encoder); 382 - dev_err(ldb->dev, "adding connector failed with %d\n", ret); 383 - return ret; 384 - } 393 + drm_connector_init(drm, &imx_ldb_ch->connector, 394 + &imx_ldb_connector_funcs, DRM_MODE_CONNECTOR_LVDS); 385 395 386 396 drm_mode_connector_attach_encoder(&imx_ldb_ch->connector, 387 397 &imx_ldb_ch->encoder); ··· 431 459 }; 432 460 MODULE_DEVICE_TABLE(of, imx_ldb_dt_ids); 433 461 434 - static int imx_ldb_probe(struct platform_device *pdev) 462 + static int imx_ldb_bind(struct device *dev, struct device *master, void *data) 435 463 { 436 - struct device_node *np = pdev->dev.of_node; 464 + struct drm_device *drm = data; 465 + struct device_node *np = dev->of_node; 437 466 const struct of_device_id *of_id = 438 - of_match_device(imx_ldb_dt_ids, &pdev->dev); 467 + of_match_device(imx_ldb_dt_ids, dev); 439 468 struct device_node *child; 440 469 const u8 *edidp; 441 470 struct imx_ldb *imx_ldb; ··· 446 473 int ret; 447 474 int i; 448 475 449 - imx_ldb = devm_kzalloc(&pdev->dev, sizeof(*imx_ldb), GFP_KERNEL); 476 + imx_ldb = devm_kzalloc(dev, sizeof(*imx_ldb), GFP_KERNEL); 450 477 if (!imx_ldb) 451 478 return -ENOMEM; 452 479 453 480 imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr"); 454 481 if (IS_ERR(imx_ldb->regmap)) { 455 - dev_err(&pdev->dev, "failed to get parent regmap\n"); 482 + dev_err(dev, "failed to get parent regmap\n"); 456 483 return PTR_ERR(imx_ldb->regmap); 457 484 } 458 485 459 - imx_ldb->dev = &pdev->dev; 486 + imx_ldb->dev = dev; 460 487 461 488 if (of_id) 462 489 imx_ldb->lvds_mux = of_id->data; ··· 494 521 return -EINVAL; 495 522 496 523 if (dual && i > 0) { 497 - dev_warn(&pdev->dev, "dual-channel mode, ignoring second output\n"); 524 + dev_warn(dev, "dual-channel mode, ignoring second output\n"); 498 525 continue; 499 526 } 500 527 ··· 504 531 channel = &imx_ldb->channel[i]; 505 532 channel->ldb = imx_ldb; 506 533 channel->chno = i; 534 + channel->child = child; 507 535 508 536 edidp = of_get_property(child, "edid", &channel->edid_len); 509 537 if (edidp) { ··· 534 560 break; 535 561 case LVDS_BIT_MAP_JEIDA: 536 562 if (datawidth == 18) { 537 - dev_err(&pdev->dev, "JEIDA standard only supported in 24 bit\n"); 563 + dev_err(dev, "JEIDA standard only supported in 24 bit\n"); 538 564 return -EINVAL; 539 565 } 540 566 if (i == 0 || dual) ··· 543 569 imx_ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 | LDB_BIT_MAP_CH1_JEIDA; 544 570 break; 545 571 default: 546 - dev_err(&pdev->dev, "data mapping not specified or invalid\n"); 572 + dev_err(dev, "data mapping not specified or invalid\n"); 547 573 return -EINVAL; 548 574 } 549 575 550 - ret = imx_ldb_register(channel); 576 + ret = imx_ldb_register(drm, channel); 551 577 if (ret) 552 578 return ret; 553 - 554 - imx_drm_encoder_add_possible_crtcs(channel->imx_drm_encoder, child); 555 579 } 556 580 557 - platform_set_drvdata(pdev, imx_ldb); 581 + dev_set_drvdata(dev, imx_ldb); 558 582 559 583 return 0; 560 584 } 561 585 562 - static int imx_ldb_remove(struct platform_device *pdev) 586 + static void imx_ldb_unbind(struct device *dev, struct device *master, 587 + void *data) 563 588 { 564 - struct imx_ldb *imx_ldb = platform_get_drvdata(pdev); 589 + struct imx_ldb *imx_ldb = dev_get_drvdata(dev); 565 590 int i; 566 591 567 592 for (i = 0; i < 2; i++) { 568 593 struct imx_ldb_channel *channel = &imx_ldb->channel[i]; 569 - struct drm_connector *connector = &channel->connector; 570 - struct drm_encoder *encoder = &channel->encoder; 571 594 572 - drm_mode_connector_detach_encoder(connector, encoder); 573 - 574 - imx_drm_remove_connector(channel->imx_drm_connector); 575 - imx_drm_remove_encoder(channel->imx_drm_encoder); 595 + channel->connector.funcs->destroy(&channel->connector); 596 + channel->encoder.funcs->destroy(&channel->encoder); 576 597 } 598 + } 577 599 600 + static const struct component_ops imx_ldb_ops = { 601 + .bind = imx_ldb_bind, 602 + .unbind = imx_ldb_unbind, 603 + }; 604 + 605 + static int imx_ldb_probe(struct platform_device *pdev) 606 + { 607 + return component_add(&pdev->dev, &imx_ldb_ops); 608 + } 609 + 610 + static int imx_ldb_remove(struct platform_device *pdev) 611 + { 612 + component_del(&pdev->dev, &imx_ldb_ops); 578 613 return 0; 579 614 } 580 615
+65 -69
drivers/staging/imx-drm/imx-tve.c
··· 20 20 21 21 #include <linux/clk.h> 22 22 #include <linux/clk-provider.h> 23 + #include <linux/component.h> 23 24 #include <linux/module.h> 24 25 #include <linux/i2c.h> 25 26 #include <linux/regmap.h> ··· 111 110 112 111 struct imx_tve { 113 112 struct drm_connector connector; 114 - struct imx_drm_connector *imx_drm_connector; 115 113 struct drm_encoder encoder; 116 - struct imx_drm_encoder *imx_drm_encoder; 117 114 struct device *dev; 118 115 spinlock_t lock; /* register lock */ 119 116 bool enabled; ··· 224 225 return connector_status_connected; 225 226 } 226 227 227 - static void imx_tve_connector_destroy(struct drm_connector *connector) 228 - { 229 - /* do not free here */ 230 - } 231 - 232 228 static int imx_tve_connector_get_modes(struct drm_connector *connector) 233 229 { 234 230 struct imx_tve *tve = con_to_tve(connector); ··· 248 254 { 249 255 struct imx_tve *tve = con_to_tve(connector); 250 256 unsigned long rate; 257 + int ret; 258 + 259 + ret = imx_drm_connector_mode_valid(connector, mode); 260 + if (ret != MODE_OK) 261 + return ret; 251 262 252 263 /* pixel clock with 2x oversampling */ 253 264 rate = clk_round_rate(tve->clk, 2000UL * mode->clock) / 2000; ··· 304 305 305 306 switch (tve->mode) { 306 307 case TVE_MODE_VGA: 307 - imx_drm_crtc_panel_format_pins(encoder->crtc, 308 - DRM_MODE_ENCODER_DAC, IPU_PIX_FMT_GBR24, 308 + imx_drm_panel_format_pins(encoder, IPU_PIX_FMT_GBR24, 309 309 tve->hsync_pin, tve->vsync_pin); 310 310 break; 311 311 case TVE_MODE_TVOUT: 312 - imx_drm_crtc_panel_format(encoder->crtc, DRM_MODE_ENCODER_TVDAC, 313 - V4L2_PIX_FMT_YUV444); 312 + imx_drm_panel_format(encoder, V4L2_PIX_FMT_YUV444); 314 313 break; 315 314 } 316 315 } ··· 361 364 tve_disable(tve); 362 365 } 363 366 364 - static void imx_tve_encoder_destroy(struct drm_encoder *encoder) 365 - { 366 - /* do not free here */ 367 - } 368 - 369 367 static struct drm_connector_funcs imx_tve_connector_funcs = { 370 368 .dpms = drm_helper_connector_dpms, 371 369 .fill_modes = drm_helper_probe_single_connector_modes, 372 370 .detect = imx_tve_connector_detect, 373 - .destroy = imx_tve_connector_destroy, 371 + .destroy = imx_drm_connector_destroy, 374 372 }; 375 373 376 374 static struct drm_connector_helper_funcs imx_tve_connector_helper_funcs = { ··· 375 383 }; 376 384 377 385 static struct drm_encoder_funcs imx_tve_encoder_funcs = { 378 - .destroy = imx_tve_encoder_destroy, 386 + .destroy = imx_drm_encoder_destroy, 379 387 }; 380 388 381 389 static struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = { ··· 495 503 return 0; 496 504 } 497 505 498 - static int imx_tve_register(struct imx_tve *tve) 506 + static int imx_tve_register(struct drm_device *drm, struct imx_tve *tve) 499 507 { 508 + int encoder_type; 500 509 int ret; 501 510 502 - tve->connector.funcs = &imx_tve_connector_funcs; 503 - tve->encoder.funcs = &imx_tve_encoder_funcs; 511 + encoder_type = tve->mode == TVE_MODE_VGA ? 512 + DRM_MODE_ENCODER_DAC : DRM_MODE_ENCODER_TVDAC; 504 513 505 - tve->encoder.encoder_type = DRM_MODE_ENCODER_NONE; 506 - tve->connector.connector_type = DRM_MODE_CONNECTOR_VGA; 514 + ret = imx_drm_encoder_parse_of(drm, &tve->encoder, 515 + tve->dev->of_node); 516 + if (ret) 517 + return ret; 507 518 508 519 drm_encoder_helper_add(&tve->encoder, &imx_tve_encoder_helper_funcs); 509 - ret = imx_drm_add_encoder(&tve->encoder, &tve->imx_drm_encoder, 510 - THIS_MODULE); 511 - if (ret) { 512 - dev_err(tve->dev, "adding encoder failed with %d\n", ret); 513 - return ret; 514 - } 520 + drm_encoder_init(drm, &tve->encoder, &imx_tve_encoder_funcs, 521 + encoder_type); 515 522 516 523 drm_connector_helper_add(&tve->connector, 517 524 &imx_tve_connector_helper_funcs); 518 - 519 - ret = imx_drm_add_connector(&tve->connector, 520 - &tve->imx_drm_connector, THIS_MODULE); 521 - if (ret) { 522 - imx_drm_remove_encoder(tve->imx_drm_encoder); 523 - dev_err(tve->dev, "adding connector failed with %d\n", ret); 524 - return ret; 525 - } 525 + drm_connector_init(drm, &tve->connector, &imx_tve_connector_funcs, 526 + DRM_MODE_CONNECTOR_VGA); 526 527 527 528 drm_mode_connector_attach_encoder(&tve->connector, &tve->encoder); 528 529 ··· 561 576 return -EINVAL; 562 577 } 563 578 564 - static int imx_tve_probe(struct platform_device *pdev) 579 + static int imx_tve_bind(struct device *dev, struct device *master, void *data) 565 580 { 566 - struct device_node *np = pdev->dev.of_node; 581 + struct platform_device *pdev = to_platform_device(dev); 582 + struct drm_device *drm = data; 583 + struct device_node *np = dev->of_node; 567 584 struct device_node *ddc_node; 568 585 struct imx_tve *tve; 569 586 struct resource *res; ··· 574 587 int irq; 575 588 int ret; 576 589 577 - tve = devm_kzalloc(&pdev->dev, sizeof(*tve), GFP_KERNEL); 590 + tve = devm_kzalloc(dev, sizeof(*tve), GFP_KERNEL); 578 591 if (!tve) 579 592 return -ENOMEM; 580 593 581 - tve->dev = &pdev->dev; 594 + tve->dev = dev; 582 595 spin_lock_init(&tve->lock); 583 596 584 597 ddc_node = of_parse_phandle(np, "ddc", 0); ··· 589 602 590 603 tve->mode = of_get_tve_mode(np); 591 604 if (tve->mode != TVE_MODE_VGA) { 592 - dev_err(&pdev->dev, "only VGA mode supported, currently\n"); 605 + dev_err(dev, "only VGA mode supported, currently\n"); 593 606 return -EINVAL; 594 607 } 595 608 ··· 598 611 &tve->hsync_pin); 599 612 600 613 if (ret < 0) { 601 - dev_err(&pdev->dev, "failed to get vsync pin\n"); 614 + dev_err(dev, "failed to get vsync pin\n"); 602 615 return ret; 603 616 } 604 617 ··· 606 619 &tve->vsync_pin); 607 620 608 621 if (ret < 0) { 609 - dev_err(&pdev->dev, "failed to get vsync pin\n"); 622 + dev_err(dev, "failed to get vsync pin\n"); 610 623 return ret; 611 624 } 612 625 } 613 626 614 627 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 615 - base = devm_ioremap_resource(&pdev->dev, res); 628 + base = devm_ioremap_resource(dev, res); 616 629 if (IS_ERR(base)) 617 630 return PTR_ERR(base); 618 631 619 632 tve_regmap_config.lock_arg = tve; 620 - tve->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "tve", base, 633 + tve->regmap = devm_regmap_init_mmio_clk(dev, "tve", base, 621 634 &tve_regmap_config); 622 635 if (IS_ERR(tve->regmap)) { 623 - dev_err(&pdev->dev, "failed to init regmap: %ld\n", 636 + dev_err(dev, "failed to init regmap: %ld\n", 624 637 PTR_ERR(tve->regmap)); 625 638 return PTR_ERR(tve->regmap); 626 639 } 627 640 628 641 irq = platform_get_irq(pdev, 0); 629 642 if (irq < 0) { 630 - dev_err(&pdev->dev, "failed to get irq\n"); 643 + dev_err(dev, "failed to get irq\n"); 631 644 return irq; 632 645 } 633 646 634 - ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 647 + ret = devm_request_threaded_irq(dev, irq, NULL, 635 648 imx_tve_irq_handler, IRQF_ONESHOT, 636 649 "imx-tve", tve); 637 650 if (ret < 0) { 638 - dev_err(&pdev->dev, "failed to request irq: %d\n", ret); 651 + dev_err(dev, "failed to request irq: %d\n", ret); 639 652 return ret; 640 653 } 641 654 642 - tve->dac_reg = devm_regulator_get(&pdev->dev, "dac"); 655 + tve->dac_reg = devm_regulator_get(dev, "dac"); 643 656 if (!IS_ERR(tve->dac_reg)) { 644 657 regulator_set_voltage(tve->dac_reg, 2750000, 2750000); 645 658 ret = regulator_enable(tve->dac_reg); ··· 647 660 return ret; 648 661 } 649 662 650 - tve->clk = devm_clk_get(&pdev->dev, "tve"); 663 + tve->clk = devm_clk_get(dev, "tve"); 651 664 if (IS_ERR(tve->clk)) { 652 - dev_err(&pdev->dev, "failed to get high speed tve clock: %ld\n", 665 + dev_err(dev, "failed to get high speed tve clock: %ld\n", 653 666 PTR_ERR(tve->clk)); 654 667 return PTR_ERR(tve->clk); 655 668 } 656 669 657 670 /* this is the IPU DI clock input selector, can be parented to tve_di */ 658 - tve->di_sel_clk = devm_clk_get(&pdev->dev, "di_sel"); 671 + tve->di_sel_clk = devm_clk_get(dev, "di_sel"); 659 672 if (IS_ERR(tve->di_sel_clk)) { 660 - dev_err(&pdev->dev, "failed to get ipu di mux clock: %ld\n", 673 + dev_err(dev, "failed to get ipu di mux clock: %ld\n", 661 674 PTR_ERR(tve->di_sel_clk)); 662 675 return PTR_ERR(tve->di_sel_clk); 663 676 } ··· 668 681 669 682 ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); 670 683 if (ret < 0) { 671 - dev_err(&pdev->dev, "failed to read configuration register: %d\n", ret); 684 + dev_err(dev, "failed to read configuration register: %d\n", ret); 672 685 return ret; 673 686 } 674 687 if (val != 0x00100000) { 675 - dev_err(&pdev->dev, "configuration register default value indicates this is not a TVEv2\n"); 688 + dev_err(dev, "configuration register default value indicates this is not a TVEv2\n"); 676 689 return -ENODEV; 677 690 } 678 691 679 692 /* disable cable detection for VGA mode */ 680 693 ret = regmap_write(tve->regmap, TVE_CD_CONT_REG, 0); 681 694 682 - ret = imx_tve_register(tve); 695 + ret = imx_tve_register(drm, tve); 683 696 if (ret) 684 697 return ret; 685 698 686 - ret = imx_drm_encoder_add_possible_crtcs(tve->imx_drm_encoder, np); 687 - 688 - platform_set_drvdata(pdev, tve); 699 + dev_set_drvdata(dev, tve); 689 700 690 701 return 0; 691 702 } 692 703 693 - static int imx_tve_remove(struct platform_device *pdev) 704 + static void imx_tve_unbind(struct device *dev, struct device *master, 705 + void *data) 694 706 { 695 - struct imx_tve *tve = platform_get_drvdata(pdev); 696 - struct drm_connector *connector = &tve->connector; 697 - struct drm_encoder *encoder = &tve->encoder; 707 + struct imx_tve *tve = dev_get_drvdata(dev); 698 708 699 - drm_mode_connector_detach_encoder(connector, encoder); 700 - 701 - imx_drm_remove_connector(tve->imx_drm_connector); 702 - imx_drm_remove_encoder(tve->imx_drm_encoder); 709 + tve->connector.funcs->destroy(&tve->connector); 710 + tve->encoder.funcs->destroy(&tve->encoder); 703 711 704 712 if (!IS_ERR(tve->dac_reg)) 705 713 regulator_disable(tve->dac_reg); 714 + } 706 715 716 + static const struct component_ops imx_tve_ops = { 717 + .bind = imx_tve_bind, 718 + .unbind = imx_tve_unbind, 719 + }; 720 + 721 + static int imx_tve_probe(struct platform_device *pdev) 722 + { 723 + return component_add(&pdev->dev, &imx_tve_ops); 724 + } 725 + 726 + static int imx_tve_remove(struct platform_device *pdev) 727 + { 728 + component_del(&pdev->dev, &imx_tve_ops); 707 729 return 0; 708 730 } 709 731
+127 -190
drivers/staging/imx-drm/ipu-v3/ipu-di.c
··· 19 19 #include <linux/io.h> 20 20 #include <linux/err.h> 21 21 #include <linux/platform_device.h> 22 - #include <linux/clk.h> 23 - #include <linux/clk-provider.h> 24 - #include <linux/clkdev.h> 25 22 26 23 #include "imx-ipu-v3.h" 27 24 #include "ipu-prv.h" ··· 30 33 struct clk *clk_di; /* display input clock */ 31 34 struct clk *clk_ipu; /* IPU bus clock */ 32 35 struct clk *clk_di_pixel; /* resulting pixel clock */ 33 - struct clk_hw clk_hw_out; 34 - char *clk_name; 35 36 bool inuse; 36 - unsigned long clkflags; 37 37 struct ipu_soc *ipu; 38 38 }; 39 39 ··· 134 140 { 135 141 writel(value, di->base + offset); 136 142 } 137 - 138 - static int ipu_di_clk_calc_div(unsigned long inrate, unsigned long outrate) 139 - { 140 - u64 tmp = inrate; 141 - int div; 142 - 143 - tmp *= 16; 144 - 145 - do_div(tmp, outrate); 146 - 147 - div = tmp; 148 - 149 - if (div < 0x10) 150 - div = 0x10; 151 - 152 - #ifdef WTF_IS_THIS 153 - /* 154 - * Freescale has this in their Kernel. It is neither clear what 155 - * it does nor why it does it 156 - */ 157 - if (div & 0x10) 158 - div &= ~0x7; 159 - else { 160 - /* Round up divider if it gets us closer to desired pix clk */ 161 - if ((div & 0xC) == 0xC) { 162 - div += 0x10; 163 - div &= ~0xF; 164 - } 165 - } 166 - #endif 167 - return div; 168 - } 169 - 170 - static unsigned long clk_di_recalc_rate(struct clk_hw *hw, 171 - unsigned long parent_rate) 172 - { 173 - struct ipu_di *di = container_of(hw, struct ipu_di, clk_hw_out); 174 - unsigned long outrate; 175 - u32 div = ipu_di_read(di, DI_BS_CLKGEN0); 176 - 177 - if (div < 0x10) 178 - div = 0x10; 179 - 180 - outrate = (parent_rate / div) * 16; 181 - 182 - return outrate; 183 - } 184 - 185 - static long clk_di_round_rate(struct clk_hw *hw, unsigned long rate, 186 - unsigned long *prate) 187 - { 188 - struct ipu_di *di = container_of(hw, struct ipu_di, clk_hw_out); 189 - unsigned long outrate; 190 - int div; 191 - u32 val; 192 - 193 - div = ipu_di_clk_calc_div(*prate, rate); 194 - 195 - outrate = (*prate / div) * 16; 196 - 197 - val = ipu_di_read(di, DI_GENERAL); 198 - 199 - if (!(val & DI_GEN_DI_CLK_EXT) && outrate > *prate / 2) 200 - outrate = *prate / 2; 201 - 202 - dev_dbg(di->ipu->dev, 203 - "%s: inrate: %ld div: 0x%08x outrate: %ld wanted: %ld\n", 204 - __func__, *prate, div, outrate, rate); 205 - 206 - return outrate; 207 - } 208 - 209 - static int clk_di_set_rate(struct clk_hw *hw, unsigned long rate, 210 - unsigned long parent_rate) 211 - { 212 - struct ipu_di *di = container_of(hw, struct ipu_di, clk_hw_out); 213 - int div; 214 - u32 clkgen0; 215 - 216 - clkgen0 = ipu_di_read(di, DI_BS_CLKGEN0) & ~0xfff; 217 - 218 - div = ipu_di_clk_calc_div(parent_rate, rate); 219 - 220 - ipu_di_write(di, clkgen0 | div, DI_BS_CLKGEN0); 221 - 222 - dev_dbg(di->ipu->dev, "%s: inrate: %ld desired: %ld div: 0x%08x\n", 223 - __func__, parent_rate, rate, div); 224 - return 0; 225 - } 226 - 227 - static u8 clk_di_get_parent(struct clk_hw *hw) 228 - { 229 - struct ipu_di *di = container_of(hw, struct ipu_di, clk_hw_out); 230 - u32 val; 231 - 232 - val = ipu_di_read(di, DI_GENERAL); 233 - 234 - return val & DI_GEN_DI_CLK_EXT ? 1 : 0; 235 - } 236 - 237 - static int clk_di_set_parent(struct clk_hw *hw, u8 index) 238 - { 239 - struct ipu_di *di = container_of(hw, struct ipu_di, clk_hw_out); 240 - u32 val; 241 - 242 - val = ipu_di_read(di, DI_GENERAL); 243 - 244 - if (index) 245 - val |= DI_GEN_DI_CLK_EXT; 246 - else 247 - val &= ~DI_GEN_DI_CLK_EXT; 248 - 249 - ipu_di_write(di, val, DI_GENERAL); 250 - 251 - return 0; 252 - } 253 - 254 - static struct clk_ops clk_di_ops = { 255 - .round_rate = clk_di_round_rate, 256 - .set_rate = clk_di_set_rate, 257 - .recalc_rate = clk_di_recalc_rate, 258 - .set_parent = clk_di_set_parent, 259 - .get_parent = clk_di_get_parent, 260 - }; 261 143 262 144 static void ipu_di_data_wave_config(struct ipu_di *di, 263 145 int wave_gen, ··· 398 528 ipu_di_sync_config(di, cfg_vga, 0, ARRAY_SIZE(cfg_vga)); 399 529 } 400 530 531 + static void ipu_di_config_clock(struct ipu_di *di, 532 + const struct ipu_di_signal_cfg *sig) 533 + { 534 + struct clk *clk; 535 + unsigned clkgen0; 536 + uint32_t val; 537 + 538 + if (sig->clkflags & IPU_DI_CLKMODE_EXT) { 539 + /* 540 + * CLKMODE_EXT means we must use the DI clock: this is 541 + * needed for things like LVDS which needs to feed the 542 + * DI and LDB with the same pixel clock. 543 + */ 544 + clk = di->clk_di; 545 + 546 + if (sig->clkflags & IPU_DI_CLKMODE_SYNC) { 547 + /* 548 + * CLKMODE_SYNC means that we want the DI to be 549 + * clocked at the same rate as the parent clock. 550 + * This is needed (eg) for LDB which needs to be 551 + * fed with the same pixel clock. We assume that 552 + * the LDB clock has already been set correctly. 553 + */ 554 + clkgen0 = 1 << 4; 555 + } else { 556 + /* 557 + * We can use the divider. We should really have 558 + * a flag here indicating whether the bridge can 559 + * cope with a fractional divider or not. For the 560 + * time being, let's go for simplicitly and 561 + * reliability. 562 + */ 563 + unsigned long in_rate; 564 + unsigned div; 565 + 566 + clk_set_rate(clk, sig->pixelclock); 567 + 568 + in_rate = clk_get_rate(clk); 569 + div = (in_rate + sig->pixelclock / 2) / sig->pixelclock; 570 + if (div == 0) 571 + div = 1; 572 + 573 + clkgen0 = div << 4; 574 + } 575 + } else { 576 + /* 577 + * For other interfaces, we can arbitarily select between 578 + * the DI specific clock and the internal IPU clock. See 579 + * DI_GENERAL bit 20. We select the IPU clock if it can 580 + * give us a clock rate within 1% of the requested frequency, 581 + * otherwise we use the DI clock. 582 + */ 583 + unsigned long rate, clkrate; 584 + unsigned div, error; 585 + 586 + clkrate = clk_get_rate(di->clk_ipu); 587 + div = (clkrate + sig->pixelclock / 2) / sig->pixelclock; 588 + rate = clkrate / div; 589 + 590 + error = rate / (sig->pixelclock / 1000); 591 + 592 + dev_dbg(di->ipu->dev, " IPU clock can give %lu with divider %u, error %d.%u%%\n", 593 + rate, div, (signed)(error - 1000) / 10, error % 10); 594 + 595 + /* Allow a 1% error */ 596 + if (error < 1010 && error >= 990) { 597 + clk = di->clk_ipu; 598 + 599 + clkgen0 = div << 4; 600 + } else { 601 + unsigned long in_rate; 602 + unsigned div; 603 + 604 + clk = di->clk_di; 605 + 606 + clk_set_rate(clk, sig->pixelclock); 607 + 608 + in_rate = clk_get_rate(clk); 609 + div = (in_rate + sig->pixelclock / 2) / sig->pixelclock; 610 + if (div == 0) 611 + div = 1; 612 + 613 + clkgen0 = div << 4; 614 + } 615 + } 616 + 617 + di->clk_di_pixel = clk; 618 + 619 + /* Set the divider */ 620 + ipu_di_write(di, clkgen0, DI_BS_CLKGEN0); 621 + 622 + /* 623 + * Set the high/low periods. Bits 24:16 give us the falling edge, 624 + * and bits 8:0 give the rising edge. LSB is fraction, and is 625 + * based on the divider above. We want a 50% duty cycle, so set 626 + * the falling edge to be half the divider. 627 + */ 628 + ipu_di_write(di, (clkgen0 >> 4) << 16, DI_BS_CLKGEN1); 629 + 630 + /* Finally select the input clock */ 631 + val = ipu_di_read(di, DI_GENERAL) & ~DI_GEN_DI_CLK_EXT; 632 + if (clk == di->clk_di) 633 + val |= DI_GEN_DI_CLK_EXT; 634 + ipu_di_write(di, val, DI_GENERAL); 635 + 636 + dev_dbg(di->ipu->dev, "Want %luHz IPU %luHz DI %luHz using %s, %luHz\n", 637 + sig->pixelclock, 638 + clk_get_rate(di->clk_ipu), 639 + clk_get_rate(di->clk_di), 640 + clk == di->clk_di ? "DI" : "IPU", 641 + clk_get_rate(di->clk_di_pixel) / (clkgen0 >> 4)); 642 + } 643 + 401 644 int ipu_di_init_sync_panel(struct ipu_di *di, struct ipu_di_signal_cfg *sig) 402 645 { 403 646 u32 reg; 404 647 u32 di_gen, vsync_cnt; 405 648 u32 div; 406 649 u32 h_total, v_total; 407 - int ret; 408 - unsigned long round; 409 - struct clk *parent; 410 650 411 651 dev_dbg(di->ipu->dev, "disp %d: panel size = %d x %d\n", 412 652 di->id, sig->width, sig->height); ··· 524 544 if ((sig->v_sync_width == 0) || (sig->h_sync_width == 0)) 525 545 return -EINVAL; 526 546 527 - if (sig->clkflags & IPU_DI_CLKMODE_EXT) 528 - parent = di->clk_di; 529 - else 530 - parent = di->clk_ipu; 531 - 532 - ret = clk_set_parent(di->clk_di_pixel, parent); 533 - if (ret) { 534 - dev_err(di->ipu->dev, 535 - "setting pixel clock to parent %s failed with %d\n", 536 - __clk_get_name(parent), ret); 537 - return ret; 538 - } 539 - 540 - if (sig->clkflags & IPU_DI_CLKMODE_SYNC) 541 - round = clk_get_rate(parent); 542 - else 543 - round = clk_round_rate(di->clk_di_pixel, sig->pixelclock); 544 - 545 - ret = clk_set_rate(di->clk_di_pixel, round); 546 - 547 547 h_total = sig->width + sig->h_sync_width + sig->h_start_width + 548 548 sig->h_end_width; 549 549 v_total = sig->height + sig->v_sync_width + sig->v_start_width + 550 550 sig->v_end_width; 551 551 552 + dev_dbg(di->ipu->dev, "Clocks: IPU %luHz DI %luHz Needed %luHz\n", 553 + clk_get_rate(di->clk_ipu), 554 + clk_get_rate(di->clk_di), 555 + sig->pixelclock); 556 + 552 557 mutex_lock(&di_mutex); 558 + 559 + ipu_di_config_clock(di, sig); 553 560 554 561 div = ipu_di_read(di, DI_BS_CLKGEN0) & 0xfff; 555 562 div = div / 16; /* Now divider is integer portion */ ··· 621 654 622 655 int ipu_di_enable(struct ipu_di *di) 623 656 { 624 - int ret = clk_prepare_enable(di->clk_di_pixel); 657 + int ret; 658 + 659 + WARN_ON(IS_ERR(di->clk_di_pixel)); 660 + 661 + ret = clk_prepare_enable(di->clk_di_pixel); 625 662 if (ret) 626 663 return ret; 627 664 ··· 637 666 638 667 int ipu_di_disable(struct ipu_di *di) 639 668 { 669 + WARN_ON(IS_ERR(di->clk_di_pixel)); 670 + 640 671 ipu_module_disable(di->ipu, di->module); 641 672 642 673 clk_disable_unprepare(di->clk_di_pixel); ··· 694 721 u32 module, struct clk *clk_ipu) 695 722 { 696 723 struct ipu_di *di; 697 - int ret; 698 - const char *di_parent[2]; 699 - struct clk_init_data init = { 700 - .ops = &clk_di_ops, 701 - .num_parents = 2, 702 - .flags = 0, 703 - }; 704 724 705 725 if (id > 1) 706 726 return -ENODEV; ··· 715 749 if (!di->base) 716 750 return -ENOMEM; 717 751 718 - di_parent[0] = __clk_get_name(di->clk_ipu); 719 - di_parent[1] = __clk_get_name(di->clk_di); 720 - 721 752 ipu_di_write(di, 0x10, DI_BS_CLKGEN0); 722 - 723 - init.parent_names = (const char **)&di_parent; 724 - di->clk_name = kasprintf(GFP_KERNEL, "%s_di%d_pixel", 725 - dev_name(dev), id); 726 - if (!di->clk_name) 727 - return -ENOMEM; 728 - 729 - init.name = di->clk_name; 730 - 731 - di->clk_hw_out.init = &init; 732 - di->clk_di_pixel = clk_register(dev, &di->clk_hw_out); 733 - 734 - if (IS_ERR(di->clk_di_pixel)) { 735 - ret = PTR_ERR(di->clk_di_pixel); 736 - goto failed_clk_register; 737 - } 738 753 739 754 dev_dbg(dev, "DI%d base: 0x%08lx remapped to %p\n", 740 755 id, base, di->base); ··· 723 776 di->ipu = ipu; 724 777 725 778 return 0; 726 - 727 - failed_clk_register: 728 - 729 - kfree(di->clk_name); 730 - 731 - return ret; 732 779 } 733 780 734 781 void ipu_di_exit(struct ipu_soc *ipu, int id) 735 782 { 736 - struct ipu_di *di = ipu->di_priv[id]; 737 - 738 - clk_unregister(di->clk_di_pixel); 739 - kfree(di->clk_name); 740 783 }
+46 -26
drivers/staging/imx-drm/ipuv3-crtc.c
··· 17 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 18 18 * MA 02110-1301, USA. 19 19 */ 20 + #include <linux/component.h> 20 21 #include <linux/module.h> 21 22 #include <linux/export.h> 22 23 #include <linux/device.h> ··· 285 284 ipu_crtc->di_clkflags = IPU_DI_CLKMODE_SYNC | 286 285 IPU_DI_CLKMODE_EXT; 287 286 break; 287 + case DRM_MODE_ENCODER_TMDS: 288 288 case DRM_MODE_ENCODER_NONE: 289 289 ipu_crtc->di_clkflags = 0; 290 290 break; ··· 336 334 } 337 335 338 336 static int ipu_crtc_init(struct ipu_crtc *ipu_crtc, 339 - struct ipu_client_platformdata *pdata) 337 + struct ipu_client_platformdata *pdata, struct drm_device *drm) 340 338 { 341 339 struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent); 342 340 int dp = -EINVAL; ··· 350 348 return ret; 351 349 } 352 350 353 - ret = imx_drm_add_crtc(&ipu_crtc->base, 351 + ret = imx_drm_add_crtc(drm, &ipu_crtc->base, 354 352 &ipu_crtc->imx_crtc, 355 - &ipu_crtc_helper_funcs, THIS_MODULE, 353 + &ipu_crtc_helper_funcs, 356 354 ipu_crtc->dev->parent->of_node, pdata->di); 357 355 if (ret) { 358 356 dev_err(ipu_crtc->dev, "adding crtc failed with %d.\n", ret); ··· 401 399 return ret; 402 400 } 403 401 404 - static int ipu_drm_probe(struct platform_device *pdev) 402 + static int ipu_drm_bind(struct device *dev, struct device *master, void *data) 405 403 { 406 - struct ipu_client_platformdata *pdata = pdev->dev.platform_data; 404 + struct ipu_client_platformdata *pdata = dev->platform_data; 405 + struct drm_device *drm = data; 407 406 struct ipu_crtc *ipu_crtc; 408 407 int ret; 409 408 410 - if (!pdata) 409 + ipu_crtc = devm_kzalloc(dev, sizeof(*ipu_crtc), GFP_KERNEL); 410 + if (!ipu_crtc) 411 + return -ENOMEM; 412 + 413 + ipu_crtc->dev = dev; 414 + 415 + ret = ipu_crtc_init(ipu_crtc, pdata, drm); 416 + if (ret) 417 + return ret; 418 + 419 + dev_set_drvdata(dev, ipu_crtc); 420 + 421 + return 0; 422 + } 423 + 424 + static void ipu_drm_unbind(struct device *dev, struct device *master, 425 + void *data) 426 + { 427 + struct ipu_crtc *ipu_crtc = dev_get_drvdata(dev); 428 + 429 + imx_drm_remove_crtc(ipu_crtc->imx_crtc); 430 + 431 + ipu_plane_put_resources(ipu_crtc->plane[0]); 432 + ipu_put_resources(ipu_crtc); 433 + } 434 + 435 + static const struct component_ops ipu_crtc_ops = { 436 + .bind = ipu_drm_bind, 437 + .unbind = ipu_drm_unbind, 438 + }; 439 + 440 + static int ipu_drm_probe(struct platform_device *pdev) 441 + { 442 + int ret; 443 + 444 + if (!pdev->dev.platform_data) 411 445 return -EINVAL; 412 446 413 447 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); 414 448 if (ret) 415 449 return ret; 416 450 417 - ipu_crtc = devm_kzalloc(&pdev->dev, sizeof(*ipu_crtc), GFP_KERNEL); 418 - if (!ipu_crtc) 419 - return -ENOMEM; 420 - 421 - ipu_crtc->dev = &pdev->dev; 422 - 423 - ret = ipu_crtc_init(ipu_crtc, pdata); 424 - if (ret) 425 - return ret; 426 - 427 - platform_set_drvdata(pdev, ipu_crtc); 428 - 429 - return 0; 451 + return component_add(&pdev->dev, &ipu_crtc_ops); 430 452 } 431 453 432 454 static int ipu_drm_remove(struct platform_device *pdev) 433 455 { 434 - struct ipu_crtc *ipu_crtc = platform_get_drvdata(pdev); 435 - 436 - imx_drm_remove_crtc(ipu_crtc->imx_crtc); 437 - 438 - ipu_plane_put_resources(ipu_crtc->plane[0]); 439 - ipu_put_resources(ipu_crtc); 440 - 456 + component_del(&pdev->dev, &ipu_crtc_ops); 441 457 return 0; 442 458 } 443 459
+43 -61
drivers/staging/imx-drm/parallel-display.c
··· 18 18 * MA 02110-1301, USA. 19 19 */ 20 20 21 + #include <linux/component.h> 21 22 #include <linux/module.h> 22 23 #include <drm/drmP.h> 23 24 #include <drm/drm_fb_helper.h> ··· 33 32 34 33 struct imx_parallel_display { 35 34 struct drm_connector connector; 36 - struct imx_drm_connector *imx_drm_connector; 37 35 struct drm_encoder encoder; 38 - struct imx_drm_encoder *imx_drm_encoder; 39 36 struct device *dev; 40 37 void *edid; 41 38 int edid_len; ··· 46 47 struct drm_connector *connector, bool force) 47 48 { 48 49 return connector_status_connected; 49 - } 50 - 51 - static void imx_pd_connector_destroy(struct drm_connector *connector) 52 - { 53 - /* do not free here */ 54 50 } 55 51 56 52 static int imx_pd_connector_get_modes(struct drm_connector *connector) ··· 79 85 return num_modes; 80 86 } 81 87 82 - static int imx_pd_connector_mode_valid(struct drm_connector *connector, 83 - struct drm_display_mode *mode) 84 - { 85 - return 0; 86 - } 87 - 88 88 static struct drm_encoder *imx_pd_connector_best_encoder( 89 89 struct drm_connector *connector) 90 90 { ··· 102 114 { 103 115 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); 104 116 105 - imx_drm_crtc_panel_format(encoder->crtc, DRM_MODE_ENCODER_NONE, 106 - imxpd->interface_pix_fmt); 117 + imx_drm_panel_format(encoder, imxpd->interface_pix_fmt); 107 118 } 108 119 109 120 static void imx_pd_encoder_commit(struct drm_encoder *encoder) ··· 119 132 { 120 133 } 121 134 122 - static void imx_pd_encoder_destroy(struct drm_encoder *encoder) 123 - { 124 - /* do not free here */ 125 - } 126 - 127 135 static struct drm_connector_funcs imx_pd_connector_funcs = { 128 136 .dpms = drm_helper_connector_dpms, 129 137 .fill_modes = drm_helper_probe_single_connector_modes, 130 138 .detect = imx_pd_connector_detect, 131 - .destroy = imx_pd_connector_destroy, 139 + .destroy = imx_drm_connector_destroy, 132 140 }; 133 141 134 142 static struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = { 135 143 .get_modes = imx_pd_connector_get_modes, 136 144 .best_encoder = imx_pd_connector_best_encoder, 137 - .mode_valid = imx_pd_connector_mode_valid, 145 + .mode_valid = imx_drm_connector_mode_valid, 138 146 }; 139 147 140 148 static struct drm_encoder_funcs imx_pd_encoder_funcs = { 141 - .destroy = imx_pd_encoder_destroy, 149 + .destroy = imx_drm_encoder_destroy, 142 150 }; 143 151 144 152 static struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = { ··· 145 163 .disable = imx_pd_encoder_disable, 146 164 }; 147 165 148 - static int imx_pd_register(struct imx_parallel_display *imxpd) 166 + static int imx_pd_register(struct drm_device *drm, 167 + struct imx_parallel_display *imxpd) 149 168 { 150 169 int ret; 151 170 152 - drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder); 153 - 154 - imxpd->connector.funcs = &imx_pd_connector_funcs; 155 - imxpd->encoder.funcs = &imx_pd_encoder_funcs; 156 - 157 - imxpd->encoder.encoder_type = DRM_MODE_ENCODER_NONE; 158 - imxpd->connector.connector_type = DRM_MODE_CONNECTOR_VGA; 171 + ret = imx_drm_encoder_parse_of(drm, &imxpd->encoder, 172 + imxpd->dev->of_node); 173 + if (ret) 174 + return ret; 159 175 160 176 drm_encoder_helper_add(&imxpd->encoder, &imx_pd_encoder_helper_funcs); 161 - ret = imx_drm_add_encoder(&imxpd->encoder, &imxpd->imx_drm_encoder, 162 - THIS_MODULE); 163 - if (ret) { 164 - dev_err(imxpd->dev, "adding encoder failed with %d\n", ret); 165 - return ret; 166 - } 177 + drm_encoder_init(drm, &imxpd->encoder, &imx_pd_encoder_funcs, 178 + DRM_MODE_ENCODER_NONE); 167 179 168 180 drm_connector_helper_add(&imxpd->connector, 169 181 &imx_pd_connector_helper_funcs); 182 + drm_connector_init(drm, &imxpd->connector, &imx_pd_connector_funcs, 183 + DRM_MODE_CONNECTOR_VGA); 170 184 171 - ret = imx_drm_add_connector(&imxpd->connector, 172 - &imxpd->imx_drm_connector, THIS_MODULE); 173 - if (ret) { 174 - imx_drm_remove_encoder(imxpd->imx_drm_encoder); 175 - dev_err(imxpd->dev, "adding connector failed with %d\n", ret); 176 - return ret; 177 - } 185 + drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder); 178 186 179 187 imxpd->connector.encoder = &imxpd->encoder; 180 188 181 189 return 0; 182 190 } 183 191 184 - static int imx_pd_probe(struct platform_device *pdev) 192 + static int imx_pd_bind(struct device *dev, struct device *master, void *data) 185 193 { 186 - struct device_node *np = pdev->dev.of_node; 194 + struct drm_device *drm = data; 195 + struct device_node *np = dev->of_node; 187 196 const u8 *edidp; 188 197 struct imx_parallel_display *imxpd; 189 198 int ret; 190 199 const char *fmt; 191 200 192 - imxpd = devm_kzalloc(&pdev->dev, sizeof(*imxpd), GFP_KERNEL); 201 + imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL); 193 202 if (!imxpd) 194 203 return -ENOMEM; 195 204 ··· 198 225 imxpd->interface_pix_fmt = V4L2_PIX_FMT_BGR666; 199 226 } 200 227 201 - imxpd->dev = &pdev->dev; 228 + imxpd->dev = dev; 202 229 203 - ret = imx_pd_register(imxpd); 230 + ret = imx_pd_register(drm, imxpd); 204 231 if (ret) 205 232 return ret; 206 233 207 - ret = imx_drm_encoder_add_possible_crtcs(imxpd->imx_drm_encoder, np); 208 - 209 - platform_set_drvdata(pdev, imxpd); 234 + dev_set_drvdata(dev, imxpd); 210 235 211 236 return 0; 212 237 } 213 238 239 + static void imx_pd_unbind(struct device *dev, struct device *master, 240 + void *data) 241 + { 242 + struct imx_parallel_display *imxpd = dev_get_drvdata(dev); 243 + 244 + imxpd->encoder.funcs->destroy(&imxpd->encoder); 245 + imxpd->connector.funcs->destroy(&imxpd->connector); 246 + } 247 + 248 + static const struct component_ops imx_pd_ops = { 249 + .bind = imx_pd_bind, 250 + .unbind = imx_pd_unbind, 251 + }; 252 + 253 + static int imx_pd_probe(struct platform_device *pdev) 254 + { 255 + return component_add(&pdev->dev, &imx_pd_ops); 256 + } 257 + 214 258 static int imx_pd_remove(struct platform_device *pdev) 215 259 { 216 - struct imx_parallel_display *imxpd = platform_get_drvdata(pdev); 217 - struct drm_connector *connector = &imxpd->connector; 218 - struct drm_encoder *encoder = &imxpd->encoder; 219 - 220 - drm_mode_connector_detach_encoder(connector, encoder); 221 - 222 - imx_drm_remove_connector(imxpd->imx_drm_connector); 223 - imx_drm_remove_encoder(imxpd->imx_drm_encoder); 224 - 260 + component_del(&pdev->dev, &imx_pd_ops); 225 261 return 0; 226 262 } 227 263