1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2dc55ac3bSJyri Sarha /* 3dc55ac3bSJyri Sarha * Copyright (C) 2016 Texas Instruments 4dc55ac3bSJyri Sarha * Author: Jyri Sarha <jsarha@ti.com> 5dc55ac3bSJyri Sarha */ 6dc55ac3bSJyri Sarha 7f56c9202SChristopher Spinrath #include <linux/gpio/consumer.h> 895b60804SSam Ravnborg #include <linux/i2c.h> 972bd9ea3SVille Syrjälä #include <linux/media-bus-format.h> 10dc55ac3bSJyri Sarha #include <linux/module.h> 11dc55ac3bSJyri Sarha #include <linux/of_graph.h> 12dc55ac3bSJyri Sarha #include <linux/platform_device.h> 135cafa0f1SLaurent Pinchart #include <linux/workqueue.h> 14dc55ac3bSJyri Sarha 15dc55ac3bSJyri Sarha #include <drm/drm_atomic_helper.h> 16ee68c743SBoris Brezillon #include <drm/drm_bridge.h> 17dc55ac3bSJyri Sarha #include <drm/drm_crtc.h> 18255490f9SVille Syrjälä #include <drm/drm_edid.h> 1995b60804SSam Ravnborg #include <drm/drm_print.h> 20fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h> 21dc55ac3bSJyri Sarha 22f56c9202SChristopher Spinrath #define HOTPLUG_DEBOUNCE_MS 1100 23f56c9202SChristopher Spinrath 24dc55ac3bSJyri Sarha struct tfp410 { 25dc55ac3bSJyri Sarha struct drm_bridge bridge; 26dc55ac3bSJyri Sarha struct drm_connector connector; 27dc55ac3bSJyri Sarha 280eb2766dSPeter Ujfalusi u32 bus_format; 29f56c9202SChristopher Spinrath struct delayed_work hpd_work; 3038c02db7SLaurent Pinchart struct gpio_desc *powerdown; 31dc55ac3bSJyri Sarha 32897dae56SLaurent Pinchart struct drm_bridge_timings timings; 335cafa0f1SLaurent Pinchart struct drm_bridge *next_bridge; 34897dae56SLaurent Pinchart 35dc55ac3bSJyri Sarha struct device *dev; 36dc55ac3bSJyri Sarha }; 37dc55ac3bSJyri Sarha 38dc55ac3bSJyri Sarha static inline struct tfp410 * 39dc55ac3bSJyri Sarha drm_bridge_to_tfp410(struct drm_bridge *bridge) 40dc55ac3bSJyri Sarha { 41dc55ac3bSJyri Sarha return container_of(bridge, struct tfp410, bridge); 42dc55ac3bSJyri Sarha } 43dc55ac3bSJyri Sarha 44dc55ac3bSJyri Sarha static inline struct tfp410 * 45dc55ac3bSJyri Sarha drm_connector_to_tfp410(struct drm_connector *connector) 46dc55ac3bSJyri Sarha { 47dc55ac3bSJyri Sarha return container_of(connector, struct tfp410, connector); 48dc55ac3bSJyri Sarha } 49dc55ac3bSJyri Sarha 50dc55ac3bSJyri Sarha static int tfp410_get_modes(struct drm_connector *connector) 51dc55ac3bSJyri Sarha { 52dc55ac3bSJyri Sarha struct tfp410 *dvi = drm_connector_to_tfp410(connector); 53dc55ac3bSJyri Sarha struct edid *edid; 54dc55ac3bSJyri Sarha int ret; 55dc55ac3bSJyri Sarha 5611d3cf80SLaurent Pinchart if (dvi->next_bridge->ops & DRM_BRIDGE_OP_EDID) { 575cafa0f1SLaurent Pinchart edid = drm_bridge_get_edid(dvi->next_bridge, connector); 5811d3cf80SLaurent Pinchart if (!edid) 59dc55ac3bSJyri Sarha DRM_INFO("EDID read failed. Fallback to standard modes\n"); 6011d3cf80SLaurent Pinchart } else { 6111d3cf80SLaurent Pinchart edid = NULL; 6211d3cf80SLaurent Pinchart } 635cafa0f1SLaurent Pinchart 6411d3cf80SLaurent Pinchart if (!edid) { 655cafa0f1SLaurent Pinchart /* 665cafa0f1SLaurent Pinchart * No EDID, fallback on the XGA standard modes and prefer a mode 675cafa0f1SLaurent Pinchart * pretty much anything can handle. 685cafa0f1SLaurent Pinchart */ 695cafa0f1SLaurent Pinchart ret = drm_add_modes_noedid(connector, 1920, 1200); 705cafa0f1SLaurent Pinchart drm_set_preferred_mode(connector, 1024, 768); 715cafa0f1SLaurent Pinchart return ret; 72dc55ac3bSJyri Sarha } 73dc55ac3bSJyri Sarha 74c555f023SDaniel Vetter drm_connector_update_edid_property(connector, edid); 75dc55ac3bSJyri Sarha 76c08f99c3STomi Valkeinen ret = drm_add_edid_modes(connector, edid); 77c08f99c3STomi Valkeinen 78c08f99c3STomi Valkeinen kfree(edid); 79c08f99c3STomi Valkeinen 80c08f99c3STomi Valkeinen return ret; 81dc55ac3bSJyri Sarha } 82dc55ac3bSJyri Sarha 83dc55ac3bSJyri Sarha static const struct drm_connector_helper_funcs tfp410_con_helper_funcs = { 84dc55ac3bSJyri Sarha .get_modes = tfp410_get_modes, 85dc55ac3bSJyri Sarha }; 86dc55ac3bSJyri Sarha 87dc55ac3bSJyri Sarha static enum drm_connector_status 88dc55ac3bSJyri Sarha tfp410_connector_detect(struct drm_connector *connector, bool force) 89dc55ac3bSJyri Sarha { 90dc55ac3bSJyri Sarha struct tfp410 *dvi = drm_connector_to_tfp410(connector); 91dc55ac3bSJyri Sarha 925cafa0f1SLaurent Pinchart return drm_bridge_detect(dvi->next_bridge); 93dc55ac3bSJyri Sarha } 94dc55ac3bSJyri Sarha 95dc55ac3bSJyri Sarha static const struct drm_connector_funcs tfp410_con_funcs = { 96dc55ac3bSJyri Sarha .detect = tfp410_connector_detect, 97dc55ac3bSJyri Sarha .fill_modes = drm_helper_probe_single_connector_modes, 98dc55ac3bSJyri Sarha .destroy = drm_connector_cleanup, 99dc55ac3bSJyri Sarha .reset = drm_atomic_helper_connector_reset, 100dc55ac3bSJyri Sarha .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 101dc55ac3bSJyri Sarha .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 102dc55ac3bSJyri Sarha }; 103dc55ac3bSJyri Sarha 1045cafa0f1SLaurent Pinchart static void tfp410_hpd_work_func(struct work_struct *work) 1055cafa0f1SLaurent Pinchart { 1065cafa0f1SLaurent Pinchart struct tfp410 *dvi; 1075cafa0f1SLaurent Pinchart 1085cafa0f1SLaurent Pinchart dvi = container_of(work, struct tfp410, hpd_work.work); 1095cafa0f1SLaurent Pinchart 1105cafa0f1SLaurent Pinchart if (dvi->bridge.dev) 1115cafa0f1SLaurent Pinchart drm_helper_hpd_irq_event(dvi->bridge.dev); 1125cafa0f1SLaurent Pinchart } 1135cafa0f1SLaurent Pinchart 1145cafa0f1SLaurent Pinchart static void tfp410_hpd_callback(void *arg, enum drm_connector_status status) 1155cafa0f1SLaurent Pinchart { 1165cafa0f1SLaurent Pinchart struct tfp410 *dvi = arg; 1175cafa0f1SLaurent Pinchart 1185cafa0f1SLaurent Pinchart mod_delayed_work(system_wq, &dvi->hpd_work, 1195cafa0f1SLaurent Pinchart msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS)); 1205cafa0f1SLaurent Pinchart } 1215cafa0f1SLaurent Pinchart 122a25b988fSLaurent Pinchart static int tfp410_attach(struct drm_bridge *bridge, 123a25b988fSLaurent Pinchart enum drm_bridge_attach_flags flags) 124dc55ac3bSJyri Sarha { 125dc55ac3bSJyri Sarha struct tfp410 *dvi = drm_bridge_to_tfp410(bridge); 126dc55ac3bSJyri Sarha int ret; 127dc55ac3bSJyri Sarha 1285cafa0f1SLaurent Pinchart ret = drm_bridge_attach(bridge->encoder, dvi->next_bridge, bridge, 1295cafa0f1SLaurent Pinchart DRM_BRIDGE_ATTACH_NO_CONNECTOR); 1305cafa0f1SLaurent Pinchart if (ret < 0) 1315cafa0f1SLaurent Pinchart return ret; 1325cafa0f1SLaurent Pinchart 133e00a5caaSLaurent Pinchart if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) 134e00a5caaSLaurent Pinchart return 0; 135a25b988fSLaurent Pinchart 136dc55ac3bSJyri Sarha if (!bridge->encoder) { 137dc55ac3bSJyri Sarha dev_err(dvi->dev, "Missing encoder\n"); 138dc55ac3bSJyri Sarha return -ENODEV; 139dc55ac3bSJyri Sarha } 140dc55ac3bSJyri Sarha 1415cafa0f1SLaurent Pinchart if (dvi->next_bridge->ops & DRM_BRIDGE_OP_DETECT) 142f56c9202SChristopher Spinrath dvi->connector.polled = DRM_CONNECTOR_POLL_HPD; 1433d31e215SPeter Ujfalusi else 1443d31e215SPeter Ujfalusi dvi->connector.polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; 145f56c9202SChristopher Spinrath 1465cafa0f1SLaurent Pinchart if (dvi->next_bridge->ops & DRM_BRIDGE_OP_HPD) { 1475cafa0f1SLaurent Pinchart INIT_DELAYED_WORK(&dvi->hpd_work, tfp410_hpd_work_func); 1485cafa0f1SLaurent Pinchart drm_bridge_hpd_enable(dvi->next_bridge, tfp410_hpd_callback, 1495cafa0f1SLaurent Pinchart dvi); 1505cafa0f1SLaurent Pinchart } 1515cafa0f1SLaurent Pinchart 152dc55ac3bSJyri Sarha drm_connector_helper_add(&dvi->connector, 153dc55ac3bSJyri Sarha &tfp410_con_helper_funcs); 154cfb44455SAndrzej Pietrasiewicz ret = drm_connector_init_with_ddc(bridge->dev, &dvi->connector, 155cfb44455SAndrzej Pietrasiewicz &tfp410_con_funcs, 1565cafa0f1SLaurent Pinchart dvi->next_bridge->type, 1575cafa0f1SLaurent Pinchart dvi->next_bridge->ddc); 158dc55ac3bSJyri Sarha if (ret) { 15948bc281eSGeert Uytterhoeven dev_err(dvi->dev, "drm_connector_init_with_ddc() failed: %d\n", 16048bc281eSGeert Uytterhoeven ret); 161dc55ac3bSJyri Sarha return ret; 162dc55ac3bSJyri Sarha } 163dc55ac3bSJyri Sarha 1640eb2766dSPeter Ujfalusi drm_display_info_set_bus_formats(&dvi->connector.display_info, 1650eb2766dSPeter Ujfalusi &dvi->bus_format, 1); 1660eb2766dSPeter Ujfalusi 1675cafa0f1SLaurent Pinchart drm_connector_attach_encoder(&dvi->connector, bridge->encoder); 168dc55ac3bSJyri Sarha 169dc55ac3bSJyri Sarha return 0; 170dc55ac3bSJyri Sarha } 171dc55ac3bSJyri Sarha 1725cafa0f1SLaurent Pinchart static void tfp410_detach(struct drm_bridge *bridge) 1735cafa0f1SLaurent Pinchart { 1745cafa0f1SLaurent Pinchart struct tfp410 *dvi = drm_bridge_to_tfp410(bridge); 1755cafa0f1SLaurent Pinchart 1765cafa0f1SLaurent Pinchart if (dvi->connector.dev && dvi->next_bridge->ops & DRM_BRIDGE_OP_HPD) { 1775cafa0f1SLaurent Pinchart drm_bridge_hpd_disable(dvi->next_bridge); 1785cafa0f1SLaurent Pinchart cancel_delayed_work_sync(&dvi->hpd_work); 1795cafa0f1SLaurent Pinchart } 1805cafa0f1SLaurent Pinchart } 1815cafa0f1SLaurent Pinchart 18238c02db7SLaurent Pinchart static void tfp410_enable(struct drm_bridge *bridge) 18338c02db7SLaurent Pinchart { 18438c02db7SLaurent Pinchart struct tfp410 *dvi = drm_bridge_to_tfp410(bridge); 18538c02db7SLaurent Pinchart 18638c02db7SLaurent Pinchart gpiod_set_value_cansleep(dvi->powerdown, 0); 18738c02db7SLaurent Pinchart } 18838c02db7SLaurent Pinchart 18938c02db7SLaurent Pinchart static void tfp410_disable(struct drm_bridge *bridge) 19038c02db7SLaurent Pinchart { 19138c02db7SLaurent Pinchart struct tfp410 *dvi = drm_bridge_to_tfp410(bridge); 19238c02db7SLaurent Pinchart 19338c02db7SLaurent Pinchart gpiod_set_value_cansleep(dvi->powerdown, 1); 19438c02db7SLaurent Pinchart } 19538c02db7SLaurent Pinchart 1969109594dSTomi Valkeinen static enum drm_mode_status tfp410_mode_valid(struct drm_bridge *bridge, 19712c683e1SLaurent Pinchart const struct drm_display_info *info, 1989109594dSTomi Valkeinen const struct drm_display_mode *mode) 1999109594dSTomi Valkeinen { 2009109594dSTomi Valkeinen if (mode->clock < 25000) 2019109594dSTomi Valkeinen return MODE_CLOCK_LOW; 2029109594dSTomi Valkeinen 2039109594dSTomi Valkeinen if (mode->clock > 165000) 2049109594dSTomi Valkeinen return MODE_CLOCK_HIGH; 2059109594dSTomi Valkeinen 2069109594dSTomi Valkeinen return MODE_OK; 2079109594dSTomi Valkeinen } 2089109594dSTomi Valkeinen 209dc55ac3bSJyri Sarha static const struct drm_bridge_funcs tfp410_bridge_funcs = { 210dc55ac3bSJyri Sarha .attach = tfp410_attach, 2115cafa0f1SLaurent Pinchart .detach = tfp410_detach, 21238c02db7SLaurent Pinchart .enable = tfp410_enable, 21338c02db7SLaurent Pinchart .disable = tfp410_disable, 2149109594dSTomi Valkeinen .mode_valid = tfp410_mode_valid, 215dc55ac3bSJyri Sarha }; 216dc55ac3bSJyri Sarha 217897dae56SLaurent Pinchart static const struct drm_bridge_timings tfp410_default_timings = { 218897dae56SLaurent Pinchart .input_bus_flags = DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE 219897dae56SLaurent Pinchart | DRM_BUS_FLAG_DE_HIGH, 220897dae56SLaurent Pinchart .setup_time_ps = 1200, 221897dae56SLaurent Pinchart .hold_time_ps = 1300, 222897dae56SLaurent Pinchart }; 223897dae56SLaurent Pinchart 224897dae56SLaurent Pinchart static int tfp410_parse_timings(struct tfp410 *dvi, bool i2c) 225897dae56SLaurent Pinchart { 226897dae56SLaurent Pinchart struct drm_bridge_timings *timings = &dvi->timings; 227897dae56SLaurent Pinchart struct device_node *ep; 228897dae56SLaurent Pinchart u32 pclk_sample = 0; 2290eb2766dSPeter Ujfalusi u32 bus_width = 24; 230db8f92a5SRicardo Cañuelo u32 deskew = 0; 231897dae56SLaurent Pinchart 232897dae56SLaurent Pinchart /* Start with defaults. */ 233897dae56SLaurent Pinchart *timings = tfp410_default_timings; 234897dae56SLaurent Pinchart 235897dae56SLaurent Pinchart if (i2c) 236897dae56SLaurent Pinchart /* 237897dae56SLaurent Pinchart * In I2C mode timings are configured through the I2C interface. 238897dae56SLaurent Pinchart * As the driver doesn't support I2C configuration yet, we just 239897dae56SLaurent Pinchart * go with the defaults (BSEL=1, DSEL=1, DKEN=0, EDGE=1). 240897dae56SLaurent Pinchart */ 241897dae56SLaurent Pinchart return 0; 242897dae56SLaurent Pinchart 243897dae56SLaurent Pinchart /* 244897dae56SLaurent Pinchart * In non-I2C mode, timings are configured through the BSEL, DSEL, DKEN 245897dae56SLaurent Pinchart * and EDGE pins. They are specified in DT through endpoint properties 246897dae56SLaurent Pinchart * and vendor-specific properties. 247897dae56SLaurent Pinchart */ 248897dae56SLaurent Pinchart ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0); 249897dae56SLaurent Pinchart if (!ep) 250897dae56SLaurent Pinchart return -EINVAL; 251897dae56SLaurent Pinchart 252897dae56SLaurent Pinchart /* Get the sampling edge from the endpoint. */ 253897dae56SLaurent Pinchart of_property_read_u32(ep, "pclk-sample", &pclk_sample); 2540eb2766dSPeter Ujfalusi of_property_read_u32(ep, "bus-width", &bus_width); 255897dae56SLaurent Pinchart of_node_put(ep); 256897dae56SLaurent Pinchart 257897dae56SLaurent Pinchart timings->input_bus_flags = DRM_BUS_FLAG_DE_HIGH; 258897dae56SLaurent Pinchart 259897dae56SLaurent Pinchart switch (pclk_sample) { 260897dae56SLaurent Pinchart case 0: 261897dae56SLaurent Pinchart timings->input_bus_flags |= DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE 262897dae56SLaurent Pinchart | DRM_BUS_FLAG_SYNC_SAMPLE_NEGEDGE; 263897dae56SLaurent Pinchart break; 264897dae56SLaurent Pinchart case 1: 265897dae56SLaurent Pinchart timings->input_bus_flags |= DRM_BUS_FLAG_PIXDATA_SAMPLE_POSEDGE 266897dae56SLaurent Pinchart | DRM_BUS_FLAG_SYNC_SAMPLE_POSEDGE; 267897dae56SLaurent Pinchart break; 268897dae56SLaurent Pinchart default: 269897dae56SLaurent Pinchart return -EINVAL; 270897dae56SLaurent Pinchart } 271897dae56SLaurent Pinchart 2720eb2766dSPeter Ujfalusi switch (bus_width) { 2730eb2766dSPeter Ujfalusi case 12: 2740eb2766dSPeter Ujfalusi dvi->bus_format = MEDIA_BUS_FMT_RGB888_2X12_LE; 2750eb2766dSPeter Ujfalusi break; 2760eb2766dSPeter Ujfalusi case 24: 2770eb2766dSPeter Ujfalusi dvi->bus_format = MEDIA_BUS_FMT_RGB888_1X24; 2780eb2766dSPeter Ujfalusi break; 2790eb2766dSPeter Ujfalusi default: 2800eb2766dSPeter Ujfalusi return -EINVAL; 2810eb2766dSPeter Ujfalusi } 2820eb2766dSPeter Ujfalusi 283897dae56SLaurent Pinchart /* Get the setup and hold time from vendor-specific properties. */ 284db8f92a5SRicardo Cañuelo of_property_read_u32(dvi->dev->of_node, "ti,deskew", &deskew); 285db8f92a5SRicardo Cañuelo if (deskew > 7) 286897dae56SLaurent Pinchart return -EINVAL; 287897dae56SLaurent Pinchart 288b9fe8620SRicardo Cañuelo timings->setup_time_ps = 1200 - 350 * ((s32)deskew - 4); 289b9fe8620SRicardo Cañuelo timings->hold_time_ps = max(0, 1300 + 350 * ((s32)deskew - 4)); 290897dae56SLaurent Pinchart 291897dae56SLaurent Pinchart return 0; 292897dae56SLaurent Pinchart } 293897dae56SLaurent Pinchart 294897dae56SLaurent Pinchart static int tfp410_init(struct device *dev, bool i2c) 295dc55ac3bSJyri Sarha { 2965cafa0f1SLaurent Pinchart struct device_node *node; 297dc55ac3bSJyri Sarha struct tfp410 *dvi; 298dc55ac3bSJyri Sarha int ret; 299dc55ac3bSJyri Sarha 300dc55ac3bSJyri Sarha if (!dev->of_node) { 301dc55ac3bSJyri Sarha dev_err(dev, "device-tree data is missing\n"); 302dc55ac3bSJyri Sarha return -ENXIO; 303dc55ac3bSJyri Sarha } 304dc55ac3bSJyri Sarha 305dc55ac3bSJyri Sarha dvi = devm_kzalloc(dev, sizeof(*dvi), GFP_KERNEL); 306dc55ac3bSJyri Sarha if (!dvi) 307dc55ac3bSJyri Sarha return -ENOMEM; 3085cafa0f1SLaurent Pinchart 3095cafa0f1SLaurent Pinchart dvi->dev = dev; 310dc55ac3bSJyri Sarha dev_set_drvdata(dev, dvi); 311dc55ac3bSJyri Sarha 312dc55ac3bSJyri Sarha dvi->bridge.funcs = &tfp410_bridge_funcs; 313dc55ac3bSJyri Sarha dvi->bridge.of_node = dev->of_node; 314897dae56SLaurent Pinchart dvi->bridge.timings = &dvi->timings; 3155cafa0f1SLaurent Pinchart dvi->bridge.type = DRM_MODE_CONNECTOR_DVID; 316dc55ac3bSJyri Sarha 317897dae56SLaurent Pinchart ret = tfp410_parse_timings(dvi, i2c); 318897dae56SLaurent Pinchart if (ret) 3195cafa0f1SLaurent Pinchart return ret; 320897dae56SLaurent Pinchart 3215cafa0f1SLaurent Pinchart /* Get the next bridge, connected to port@1. */ 3225cafa0f1SLaurent Pinchart node = of_graph_get_remote_node(dev->of_node, 1, -1); 3235cafa0f1SLaurent Pinchart if (!node) 3245cafa0f1SLaurent Pinchart return -ENODEV; 325dc55ac3bSJyri Sarha 3265cafa0f1SLaurent Pinchart dvi->next_bridge = of_drm_find_bridge(node); 3275cafa0f1SLaurent Pinchart of_node_put(node); 3285cafa0f1SLaurent Pinchart 3295cafa0f1SLaurent Pinchart if (!dvi->next_bridge) 3305cafa0f1SLaurent Pinchart return -EPROBE_DEFER; 3315cafa0f1SLaurent Pinchart 3325cafa0f1SLaurent Pinchart /* Get the powerdown GPIO. */ 33338c02db7SLaurent Pinchart dvi->powerdown = devm_gpiod_get_optional(dev, "powerdown", 33438c02db7SLaurent Pinchart GPIOD_OUT_HIGH); 33538c02db7SLaurent Pinchart if (IS_ERR(dvi->powerdown)) { 33638c02db7SLaurent Pinchart dev_err(dev, "failed to parse powerdown gpio\n"); 33738c02db7SLaurent Pinchart return PTR_ERR(dvi->powerdown); 33838c02db7SLaurent Pinchart } 33938c02db7SLaurent Pinchart 3405cafa0f1SLaurent Pinchart /* Register the DRM bridge. */ 341f74c5275SInki Dae drm_bridge_add(&dvi->bridge); 342dc55ac3bSJyri Sarha 343dc55ac3bSJyri Sarha return 0; 344dc55ac3bSJyri Sarha } 345dc55ac3bSJyri Sarha 3466a47a16dSUwe Kleine-König static void tfp410_fini(struct device *dev) 347dc55ac3bSJyri Sarha { 348dc55ac3bSJyri Sarha struct tfp410 *dvi = dev_get_drvdata(dev); 349dc55ac3bSJyri Sarha 350dc55ac3bSJyri Sarha drm_bridge_remove(&dvi->bridge); 351dc55ac3bSJyri Sarha } 352dc55ac3bSJyri Sarha 353dc55ac3bSJyri Sarha static int tfp410_probe(struct platform_device *pdev) 354dc55ac3bSJyri Sarha { 355897dae56SLaurent Pinchart return tfp410_init(&pdev->dev, false); 356dc55ac3bSJyri Sarha } 357dc55ac3bSJyri Sarha 35867fcd5d2SUwe Kleine-König static void tfp410_remove(struct platform_device *pdev) 359dc55ac3bSJyri Sarha { 3606a47a16dSUwe Kleine-König tfp410_fini(&pdev->dev); 361dc55ac3bSJyri Sarha } 362dc55ac3bSJyri Sarha 363dc55ac3bSJyri Sarha static const struct of_device_id tfp410_match[] = { 364dc55ac3bSJyri Sarha { .compatible = "ti,tfp410" }, 365dc55ac3bSJyri Sarha {}, 366dc55ac3bSJyri Sarha }; 367dc55ac3bSJyri Sarha MODULE_DEVICE_TABLE(of, tfp410_match); 368dc55ac3bSJyri Sarha 3695b47d089SWei Yongjun static struct platform_driver tfp410_platform_driver = { 370dc55ac3bSJyri Sarha .probe = tfp410_probe, 37167fcd5d2SUwe Kleine-König .remove_new = tfp410_remove, 372dc55ac3bSJyri Sarha .driver = { 373dc55ac3bSJyri Sarha .name = "tfp410-bridge", 374dc55ac3bSJyri Sarha .of_match_table = tfp410_match, 375dc55ac3bSJyri Sarha }, 376dc55ac3bSJyri Sarha }; 377dc55ac3bSJyri Sarha 378dc55ac3bSJyri Sarha #if IS_ENABLED(CONFIG_I2C) 379dc55ac3bSJyri Sarha /* There is currently no i2c functionality. */ 380612e241fSUwe Kleine-König static int tfp410_i2c_probe(struct i2c_client *client) 381dc55ac3bSJyri Sarha { 382dc55ac3bSJyri Sarha int reg; 383dc55ac3bSJyri Sarha 384dc55ac3bSJyri Sarha if (!client->dev.of_node || 385dc55ac3bSJyri Sarha of_property_read_u32(client->dev.of_node, "reg", ®)) { 386dc55ac3bSJyri Sarha dev_err(&client->dev, 387dc55ac3bSJyri Sarha "Can't get i2c reg property from device-tree\n"); 388dc55ac3bSJyri Sarha return -ENXIO; 389dc55ac3bSJyri Sarha } 390dc55ac3bSJyri Sarha 391897dae56SLaurent Pinchart return tfp410_init(&client->dev, true); 392dc55ac3bSJyri Sarha } 393dc55ac3bSJyri Sarha 394ed5c2f5fSUwe Kleine-König static void tfp410_i2c_remove(struct i2c_client *client) 395dc55ac3bSJyri Sarha { 3966a47a16dSUwe Kleine-König tfp410_fini(&client->dev); 397dc55ac3bSJyri Sarha } 398dc55ac3bSJyri Sarha 399dc55ac3bSJyri Sarha static const struct i2c_device_id tfp410_i2c_ids[] = { 400dc55ac3bSJyri Sarha { "tfp410", 0 }, 401dc55ac3bSJyri Sarha { } 402dc55ac3bSJyri Sarha }; 403dc55ac3bSJyri Sarha MODULE_DEVICE_TABLE(i2c, tfp410_i2c_ids); 404dc55ac3bSJyri Sarha 405dc55ac3bSJyri Sarha static struct i2c_driver tfp410_i2c_driver = { 406dc55ac3bSJyri Sarha .driver = { 407dc55ac3bSJyri Sarha .name = "tfp410", 408dc55ac3bSJyri Sarha .of_match_table = of_match_ptr(tfp410_match), 409dc55ac3bSJyri Sarha }, 410dc55ac3bSJyri Sarha .id_table = tfp410_i2c_ids, 411*332af828SUwe Kleine-König .probe = tfp410_i2c_probe, 412dc55ac3bSJyri Sarha .remove = tfp410_i2c_remove, 413dc55ac3bSJyri Sarha }; 414dc55ac3bSJyri Sarha #endif /* IS_ENABLED(CONFIG_I2C) */ 415dc55ac3bSJyri Sarha 416dc55ac3bSJyri Sarha static struct { 417dc55ac3bSJyri Sarha uint i2c:1; 418dc55ac3bSJyri Sarha uint platform:1; 419dc55ac3bSJyri Sarha } tfp410_registered_driver; 420dc55ac3bSJyri Sarha 421dc55ac3bSJyri Sarha static int __init tfp410_module_init(void) 422dc55ac3bSJyri Sarha { 423dc55ac3bSJyri Sarha int ret; 424dc55ac3bSJyri Sarha 425dc55ac3bSJyri Sarha #if IS_ENABLED(CONFIG_I2C) 426dc55ac3bSJyri Sarha ret = i2c_add_driver(&tfp410_i2c_driver); 427dc55ac3bSJyri Sarha if (ret) 428dc55ac3bSJyri Sarha pr_err("%s: registering i2c driver failed: %d", 429dc55ac3bSJyri Sarha __func__, ret); 430dc55ac3bSJyri Sarha else 431dc55ac3bSJyri Sarha tfp410_registered_driver.i2c = 1; 432dc55ac3bSJyri Sarha #endif 433dc55ac3bSJyri Sarha 434dc55ac3bSJyri Sarha ret = platform_driver_register(&tfp410_platform_driver); 435dc55ac3bSJyri Sarha if (ret) 436dc55ac3bSJyri Sarha pr_err("%s: registering platform driver failed: %d", 437dc55ac3bSJyri Sarha __func__, ret); 438dc55ac3bSJyri Sarha else 439dc55ac3bSJyri Sarha tfp410_registered_driver.platform = 1; 440dc55ac3bSJyri Sarha 441dc55ac3bSJyri Sarha if (tfp410_registered_driver.i2c || 442dc55ac3bSJyri Sarha tfp410_registered_driver.platform) 443dc55ac3bSJyri Sarha return 0; 444dc55ac3bSJyri Sarha 445dc55ac3bSJyri Sarha return ret; 446dc55ac3bSJyri Sarha } 447dc55ac3bSJyri Sarha module_init(tfp410_module_init); 448dc55ac3bSJyri Sarha 449dc55ac3bSJyri Sarha static void __exit tfp410_module_exit(void) 450dc55ac3bSJyri Sarha { 451dc55ac3bSJyri Sarha #if IS_ENABLED(CONFIG_I2C) 452dc55ac3bSJyri Sarha if (tfp410_registered_driver.i2c) 453dc55ac3bSJyri Sarha i2c_del_driver(&tfp410_i2c_driver); 454dc55ac3bSJyri Sarha #endif 455dc55ac3bSJyri Sarha if (tfp410_registered_driver.platform) 456dc55ac3bSJyri Sarha platform_driver_unregister(&tfp410_platform_driver); 457dc55ac3bSJyri Sarha } 458dc55ac3bSJyri Sarha module_exit(tfp410_module_exit); 459dc55ac3bSJyri Sarha 460dc55ac3bSJyri Sarha MODULE_AUTHOR("Jyri Sarha <jsarha@ti.com>"); 461dc55ac3bSJyri Sarha MODULE_DESCRIPTION("TI TFP410 DVI bridge driver"); 462dc55ac3bSJyri Sarha MODULE_LICENSE("GPL"); 463