#include <linux/device.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/of_graph.h>
#include <linux/slab.h>
#include <drm/drmP.h>
struct adv7511_link_config link_config;
struct adv7511 *adv7511;
struct device *dev = &i2c->dev;
+#if IS_ENABLED(CONFIG_OF_DYNAMIC)
+ struct device_node *remote_node = NULL, *endpoint = NULL;
+ struct of_changeset ocs;
+ struct property *prop;
+#endif
unsigned int main_i2c_addr = i2c->addr << 1;
unsigned int edid_i2c_addr = main_i2c_addr + 4;
unsigned int val;
}
adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
- if (IS_ERR(adv7511->regmap))
- return PTR_ERR(adv7511->regmap);
+ if (IS_ERR(adv7511->regmap)) {
+ ret = PTR_ERR(adv7511->regmap);
+ goto of_reconfig;
+ }
ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
if (ret)
- return ret;
+ goto of_reconfig;
dev_dbg(dev, "Rev. %d\n", val);
if (adv7511->type == ADV7511)
adv7533_uninit_cec(adv7511);
err_i2c_unregister_edid:
i2c_unregister_device(adv7511->i2c_edid);
+of_reconfig:
+#if IS_ENABLED(CONFIG_OF_DYNAMIC)
+ endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+ if (endpoint)
+ remote_node = of_graph_get_remote_port_parent(endpoint);
+
+ if (remote_node) {
+ int num_endpoints = 0;
+
+ /*
+ * Remote node should have two endpoints (input and output: us)
+ * If remote node has more than two endpoints, probably that it
+ * has more outputs, so there is no need to disable it.
+ */
+ endpoint = NULL;
+ while ((endpoint = of_graph_get_next_endpoint(remote_node,
+ endpoint)))
+ num_endpoints++;
+
+ if (num_endpoints > 2) {
+ of_node_put(remote_node);
+ return ret;
+ }
+
+ prop = devm_kzalloc(dev, sizeof(*prop), GFP_KERNEL);
+ prop->name = devm_kstrdup(dev, "status", GFP_KERNEL);
+ prop->value = devm_kstrdup(dev, "disabled", GFP_KERNEL);
+ prop->length = 9;
+ of_changeset_init(&ocs);
+ of_changeset_update_property(&ocs, remote_node, prop);
+ ret = of_changeset_apply(&ocs);
+ if (!ret)
+ dev_warn(dev,
+ "Probe failed. Remote port '%s' disabled\n",
+ remote_node->full_name);
+
+ of_node_put(remote_node);
+ };
+#endif
return ret;
}
drm_bridge_remove(&adv7511->bridge);
- i2c_unregister_device(adv7511->i2c_edid);
-
- kfree(adv7511->edid);
+ if (adv7511->i2c_edid) {
+ i2c_unregister_device(adv7511->i2c_edid);
+ kfree(adv7511->edid);
+ }
return 0;
}