Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * NXP PTN3460 DP/LVDS bridge driver
  3 *
  4 * Copyright (C) 2013 Google, Inc.
  5 *
  6 * This software is licensed under the terms of the GNU General Public
  7 * License version 2, as published by the Free Software Foundation, and
  8 * may be copied, distributed, and modified under those terms.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 */
 15
 16#include <linux/delay.h>
 17#include <linux/gpio.h>
 18#include <linux/gpio/consumer.h>
 19#include <linux/i2c.h>
 20#include <linux/module.h>
 21#include <linux/of.h>
 22#include <linux/of_gpio.h>
 23#include <linux/of_graph.h>
 24
 
 25#include <drm/drm_panel.h>
 26
 27#include "drm_crtc.h"
 28#include "drm_crtc_helper.h"
 29#include "drm_atomic_helper.h"
 30#include "drm_edid.h"
 31#include "drmP.h"
 32
 33#define PTN3460_EDID_ADDR			0x0
 34#define PTN3460_EDID_EMULATION_ADDR		0x84
 35#define PTN3460_EDID_ENABLE_EMULATION		0
 36#define PTN3460_EDID_EMULATION_SELECTION	1
 37#define PTN3460_EDID_SRAM_LOAD_ADDR		0x85
 38
 39struct ptn3460_bridge {
 40	struct drm_connector connector;
 41	struct i2c_client *client;
 42	struct drm_bridge bridge;
 43	struct edid *edid;
 44	struct drm_panel *panel;
 45	struct gpio_desc *gpio_pd_n;
 46	struct gpio_desc *gpio_rst_n;
 47	u32 edid_emulation;
 48	bool enabled;
 49};
 50
 51static inline struct ptn3460_bridge *
 52		bridge_to_ptn3460(struct drm_bridge *bridge)
 53{
 54	return container_of(bridge, struct ptn3460_bridge, bridge);
 55}
 56
 57static inline struct ptn3460_bridge *
 58		connector_to_ptn3460(struct drm_connector *connector)
 59{
 60	return container_of(connector, struct ptn3460_bridge, connector);
 61}
 62
 63static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr,
 64		u8 *buf, int len)
 65{
 66	int ret;
 67
 68	ret = i2c_master_send(ptn_bridge->client, &addr, 1);
 69	if (ret <= 0) {
 70		DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
 71		return ret;
 72	}
 73
 74	ret = i2c_master_recv(ptn_bridge->client, buf, len);
 75	if (ret <= 0) {
 76		DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret);
 77		return ret;
 78	}
 79
 80	return 0;
 81}
 82
 83static int ptn3460_write_byte(struct ptn3460_bridge *ptn_bridge, char addr,
 84		char val)
 85{
 86	int ret;
 87	char buf[2];
 88
 89	buf[0] = addr;
 90	buf[1] = val;
 91
 92	ret = i2c_master_send(ptn_bridge->client, buf, ARRAY_SIZE(buf));
 93	if (ret <= 0) {
 94		DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
 95		return ret;
 96	}
 97
 98	return 0;
 99}
100
101static int ptn3460_select_edid(struct ptn3460_bridge *ptn_bridge)
102{
103	int ret;
104	char val;
105
106	/* Load the selected edid into SRAM (accessed at PTN3460_EDID_ADDR) */
107	ret = ptn3460_write_byte(ptn_bridge, PTN3460_EDID_SRAM_LOAD_ADDR,
108			ptn_bridge->edid_emulation);
109	if (ret) {
110		DRM_ERROR("Failed to transfer EDID to sram, ret=%d\n", ret);
111		return ret;
112	}
113
114	/* Enable EDID emulation and select the desired EDID */
115	val = 1 << PTN3460_EDID_ENABLE_EMULATION |
116		ptn_bridge->edid_emulation << PTN3460_EDID_EMULATION_SELECTION;
117
118	ret = ptn3460_write_byte(ptn_bridge, PTN3460_EDID_EMULATION_ADDR, val);
119	if (ret) {
120		DRM_ERROR("Failed to write EDID value, ret=%d\n", ret);
121		return ret;
122	}
123
124	return 0;
125}
126
127static void ptn3460_pre_enable(struct drm_bridge *bridge)
128{
129	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
130	int ret;
131
132	if (ptn_bridge->enabled)
133		return;
134
135	gpiod_set_value(ptn_bridge->gpio_pd_n, 1);
136
137	gpiod_set_value(ptn_bridge->gpio_rst_n, 0);
138	usleep_range(10, 20);
139	gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
140
141	if (drm_panel_prepare(ptn_bridge->panel)) {
142		DRM_ERROR("failed to prepare panel\n");
143		return;
144	}
145
146	/*
147	 * There's a bug in the PTN chip where it falsely asserts hotplug before
148	 * it is fully functional. We're forced to wait for the maximum start up
149	 * time specified in the chip's datasheet to make sure we're really up.
150	 */
151	msleep(90);
152
153	ret = ptn3460_select_edid(ptn_bridge);
154	if (ret)
155		DRM_ERROR("Select EDID failed ret=%d\n", ret);
156
157	ptn_bridge->enabled = true;
158}
159
160static void ptn3460_enable(struct drm_bridge *bridge)
161{
162	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
163
164	if (drm_panel_enable(ptn_bridge->panel)) {
165		DRM_ERROR("failed to enable panel\n");
166		return;
167	}
168}
169
170static void ptn3460_disable(struct drm_bridge *bridge)
171{
172	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
173
174	if (!ptn_bridge->enabled)
175		return;
176
177	ptn_bridge->enabled = false;
178
179	if (drm_panel_disable(ptn_bridge->panel)) {
180		DRM_ERROR("failed to disable panel\n");
181		return;
182	}
183
184	gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
185	gpiod_set_value(ptn_bridge->gpio_pd_n, 0);
186}
187
188static void ptn3460_post_disable(struct drm_bridge *bridge)
189{
190	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
191
192	if (drm_panel_unprepare(ptn_bridge->panel)) {
193		DRM_ERROR("failed to unprepare panel\n");
194		return;
195	}
196}
197
198static int ptn3460_get_modes(struct drm_connector *connector)
199{
200	struct ptn3460_bridge *ptn_bridge;
201	u8 *edid;
202	int ret, num_modes = 0;
203	bool power_off;
204
205	ptn_bridge = connector_to_ptn3460(connector);
206
207	if (ptn_bridge->edid)
208		return drm_add_edid_modes(connector, ptn_bridge->edid);
209
210	power_off = !ptn_bridge->enabled;
211	ptn3460_pre_enable(&ptn_bridge->bridge);
212
213	edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
214	if (!edid) {
215		DRM_ERROR("Failed to allocate EDID\n");
216		return 0;
217	}
218
219	ret = ptn3460_read_bytes(ptn_bridge, PTN3460_EDID_ADDR, edid,
220			EDID_LENGTH);
221	if (ret) {
222		kfree(edid);
223		goto out;
224	}
225
226	ptn_bridge->edid = (struct edid *)edid;
227	drm_mode_connector_update_edid_property(connector, ptn_bridge->edid);
228
229	num_modes = drm_add_edid_modes(connector, ptn_bridge->edid);
230
231out:
232	if (power_off)
233		ptn3460_disable(&ptn_bridge->bridge);
234
235	return num_modes;
236}
237
238static struct drm_encoder *ptn3460_best_encoder(struct drm_connector *connector)
239{
240	struct ptn3460_bridge *ptn_bridge = connector_to_ptn3460(connector);
241
242	return ptn_bridge->bridge.encoder;
243}
244
245static const struct drm_connector_helper_funcs ptn3460_connector_helper_funcs = {
246	.get_modes = ptn3460_get_modes,
247	.best_encoder = ptn3460_best_encoder,
248};
249
250static enum drm_connector_status ptn3460_detect(struct drm_connector *connector,
251		bool force)
252{
253	return connector_status_connected;
254}
255
256static void ptn3460_connector_destroy(struct drm_connector *connector)
257{
258	drm_connector_cleanup(connector);
259}
260
261static const struct drm_connector_funcs ptn3460_connector_funcs = {
262	.dpms = drm_atomic_helper_connector_dpms,
263	.fill_modes = drm_helper_probe_single_connector_modes,
264	.detect = ptn3460_detect,
265	.destroy = ptn3460_connector_destroy,
266	.reset = drm_atomic_helper_connector_reset,
267	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
268	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
269};
270
271static int ptn3460_bridge_attach(struct drm_bridge *bridge)
272{
273	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
274	int ret;
275
276	if (!bridge->encoder) {
277		DRM_ERROR("Parent encoder object not found");
278		return -ENODEV;
279	}
280
281	ptn_bridge->connector.polled = DRM_CONNECTOR_POLL_HPD;
282	ret = drm_connector_init(bridge->dev, &ptn_bridge->connector,
283			&ptn3460_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
284	if (ret) {
285		DRM_ERROR("Failed to initialize connector with drm\n");
286		return ret;
287	}
288	drm_connector_helper_add(&ptn_bridge->connector,
289					&ptn3460_connector_helper_funcs);
290	drm_connector_register(&ptn_bridge->connector);
291	drm_mode_connector_attach_encoder(&ptn_bridge->connector,
292							bridge->encoder);
293
294	if (ptn_bridge->panel)
295		drm_panel_attach(ptn_bridge->panel, &ptn_bridge->connector);
296
297	drm_helper_hpd_irq_event(ptn_bridge->connector.dev);
298
299	return ret;
300}
301
302static const struct drm_bridge_funcs ptn3460_bridge_funcs = {
303	.pre_enable = ptn3460_pre_enable,
304	.enable = ptn3460_enable,
305	.disable = ptn3460_disable,
306	.post_disable = ptn3460_post_disable,
307	.attach = ptn3460_bridge_attach,
308};
309
310static int ptn3460_probe(struct i2c_client *client,
311				const struct i2c_device_id *id)
312{
313	struct device *dev = &client->dev;
314	struct ptn3460_bridge *ptn_bridge;
315	struct device_node *endpoint, *panel_node;
316	int ret;
317
318	ptn_bridge = devm_kzalloc(dev, sizeof(*ptn_bridge), GFP_KERNEL);
319	if (!ptn_bridge) {
320		return -ENOMEM;
321	}
322
323	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
324	if (endpoint) {
325		panel_node = of_graph_get_remote_port_parent(endpoint);
326		if (panel_node) {
327			ptn_bridge->panel = of_drm_find_panel(panel_node);
328			of_node_put(panel_node);
329			if (!ptn_bridge->panel)
330				return -EPROBE_DEFER;
331		}
332	}
333
334	ptn_bridge->client = client;
335
336	ptn_bridge->gpio_pd_n = devm_gpiod_get(&client->dev, "powerdown",
337					       GPIOD_OUT_HIGH);
338	if (IS_ERR(ptn_bridge->gpio_pd_n)) {
339		ret = PTR_ERR(ptn_bridge->gpio_pd_n);
340		dev_err(dev, "cannot get gpio_pd_n %d\n", ret);
341		return ret;
342	}
343
344	/*
345	 * Request the reset pin low to avoid the bridge being
346	 * initialized prematurely
347	 */
348	ptn_bridge->gpio_rst_n = devm_gpiod_get(&client->dev, "reset",
349						GPIOD_OUT_LOW);
350	if (IS_ERR(ptn_bridge->gpio_rst_n)) {
351		ret = PTR_ERR(ptn_bridge->gpio_rst_n);
352		DRM_ERROR("cannot get gpio_rst_n %d\n", ret);
353		return ret;
354	}
355
356	ret = of_property_read_u32(dev->of_node, "edid-emulation",
357			&ptn_bridge->edid_emulation);
358	if (ret) {
359		dev_err(dev, "Can't read EDID emulation value\n");
360		return ret;
361	}
362
363	ptn_bridge->bridge.funcs = &ptn3460_bridge_funcs;
364	ptn_bridge->bridge.of_node = dev->of_node;
365	ret = drm_bridge_add(&ptn_bridge->bridge);
366	if (ret) {
367		DRM_ERROR("Failed to add bridge\n");
368		return ret;
369	}
370
371	i2c_set_clientdata(client, ptn_bridge);
372
373	return 0;
374}
375
376static int ptn3460_remove(struct i2c_client *client)
377{
378	struct ptn3460_bridge *ptn_bridge = i2c_get_clientdata(client);
379
380	drm_bridge_remove(&ptn_bridge->bridge);
381
382	return 0;
383}
384
385static const struct i2c_device_id ptn3460_i2c_table[] = {
386	{"ptn3460", 0},
387	{},
388};
389MODULE_DEVICE_TABLE(i2c, ptn3460_i2c_table);
390
391static const struct of_device_id ptn3460_match[] = {
392	{ .compatible = "nxp,ptn3460" },
393	{},
394};
395MODULE_DEVICE_TABLE(of, ptn3460_match);
396
397static struct i2c_driver ptn3460_driver = {
398	.id_table	= ptn3460_i2c_table,
399	.probe		= ptn3460_probe,
400	.remove		= ptn3460_remove,
401	.driver		= {
402		.name	= "nxp,ptn3460",
403		.of_match_table = ptn3460_match,
404	},
405};
406module_i2c_driver(ptn3460_driver);
407
408MODULE_AUTHOR("Sean Paul <seanpaul@chromium.org>");
409MODULE_DESCRIPTION("NXP ptn3460 eDP-LVDS converter driver");
410MODULE_LICENSE("GPL v2");
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * NXP PTN3460 DP/LVDS bridge driver
  4 *
  5 * Copyright (C) 2013 Google, Inc.
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include <linux/delay.h>
 
  9#include <linux/gpio/consumer.h>
 10#include <linux/i2c.h>
 11#include <linux/module.h>
 12#include <linux/of.h>
 13#include <drm/drm_atomic_helper.h>
 14#include <drm/drm_crtc.h>
 15#include <drm/drm_edid.h>
 16#include <drm/drm_of.h>
 17#include <drm/drm_panel.h>
 18#include <drm/drm_print.h>
 19#include <drm/drm_probe_helper.h>
 
 
 
 
 20
 21#define PTN3460_EDID_ADDR			0x0
 22#define PTN3460_EDID_EMULATION_ADDR		0x84
 23#define PTN3460_EDID_ENABLE_EMULATION		0
 24#define PTN3460_EDID_EMULATION_SELECTION	1
 25#define PTN3460_EDID_SRAM_LOAD_ADDR		0x85
 26
 27struct ptn3460_bridge {
 28	struct drm_connector connector;
 29	struct i2c_client *client;
 30	struct drm_bridge bridge;
 31	struct edid *edid;
 32	struct drm_panel *panel;
 33	struct gpio_desc *gpio_pd_n;
 34	struct gpio_desc *gpio_rst_n;
 35	u32 edid_emulation;
 36	bool enabled;
 37};
 38
 39static inline struct ptn3460_bridge *
 40		bridge_to_ptn3460(struct drm_bridge *bridge)
 41{
 42	return container_of(bridge, struct ptn3460_bridge, bridge);
 43}
 44
 45static inline struct ptn3460_bridge *
 46		connector_to_ptn3460(struct drm_connector *connector)
 47{
 48	return container_of(connector, struct ptn3460_bridge, connector);
 49}
 50
 51static int ptn3460_read_bytes(struct ptn3460_bridge *ptn_bridge, char addr,
 52		u8 *buf, int len)
 53{
 54	int ret;
 55
 56	ret = i2c_master_send(ptn_bridge->client, &addr, 1);
 57	if (ret <= 0) {
 58		DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
 59		return ret;
 60	}
 61
 62	ret = i2c_master_recv(ptn_bridge->client, buf, len);
 63	if (ret <= 0) {
 64		DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret);
 65		return ret;
 66	}
 67
 68	return 0;
 69}
 70
 71static int ptn3460_write_byte(struct ptn3460_bridge *ptn_bridge, char addr,
 72		char val)
 73{
 74	int ret;
 75	char buf[2];
 76
 77	buf[0] = addr;
 78	buf[1] = val;
 79
 80	ret = i2c_master_send(ptn_bridge->client, buf, ARRAY_SIZE(buf));
 81	if (ret <= 0) {
 82		DRM_ERROR("Failed to send i2c command, ret=%d\n", ret);
 83		return ret;
 84	}
 85
 86	return 0;
 87}
 88
 89static int ptn3460_select_edid(struct ptn3460_bridge *ptn_bridge)
 90{
 91	int ret;
 92	char val;
 93
 94	/* Load the selected edid into SRAM (accessed at PTN3460_EDID_ADDR) */
 95	ret = ptn3460_write_byte(ptn_bridge, PTN3460_EDID_SRAM_LOAD_ADDR,
 96			ptn_bridge->edid_emulation);
 97	if (ret) {
 98		DRM_ERROR("Failed to transfer EDID to sram, ret=%d\n", ret);
 99		return ret;
100	}
101
102	/* Enable EDID emulation and select the desired EDID */
103	val = 1 << PTN3460_EDID_ENABLE_EMULATION |
104		ptn_bridge->edid_emulation << PTN3460_EDID_EMULATION_SELECTION;
105
106	ret = ptn3460_write_byte(ptn_bridge, PTN3460_EDID_EMULATION_ADDR, val);
107	if (ret) {
108		DRM_ERROR("Failed to write EDID value, ret=%d\n", ret);
109		return ret;
110	}
111
112	return 0;
113}
114
115static void ptn3460_pre_enable(struct drm_bridge *bridge)
116{
117	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
118	int ret;
119
120	if (ptn_bridge->enabled)
121		return;
122
123	gpiod_set_value(ptn_bridge->gpio_pd_n, 1);
124
125	gpiod_set_value(ptn_bridge->gpio_rst_n, 0);
126	usleep_range(10, 20);
127	gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
128
129	if (drm_panel_prepare(ptn_bridge->panel)) {
130		DRM_ERROR("failed to prepare panel\n");
131		return;
132	}
133
134	/*
135	 * There's a bug in the PTN chip where it falsely asserts hotplug before
136	 * it is fully functional. We're forced to wait for the maximum start up
137	 * time specified in the chip's datasheet to make sure we're really up.
138	 */
139	msleep(90);
140
141	ret = ptn3460_select_edid(ptn_bridge);
142	if (ret)
143		DRM_ERROR("Select EDID failed ret=%d\n", ret);
144
145	ptn_bridge->enabled = true;
146}
147
148static void ptn3460_enable(struct drm_bridge *bridge)
149{
150	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
151
152	if (drm_panel_enable(ptn_bridge->panel)) {
153		DRM_ERROR("failed to enable panel\n");
154		return;
155	}
156}
157
158static void ptn3460_disable(struct drm_bridge *bridge)
159{
160	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
161
162	if (!ptn_bridge->enabled)
163		return;
164
165	ptn_bridge->enabled = false;
166
167	if (drm_panel_disable(ptn_bridge->panel)) {
168		DRM_ERROR("failed to disable panel\n");
169		return;
170	}
171
172	gpiod_set_value(ptn_bridge->gpio_rst_n, 1);
173	gpiod_set_value(ptn_bridge->gpio_pd_n, 0);
174}
175
176static void ptn3460_post_disable(struct drm_bridge *bridge)
177{
178	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
179
180	if (drm_panel_unprepare(ptn_bridge->panel)) {
181		DRM_ERROR("failed to unprepare panel\n");
182		return;
183	}
184}
185
186static int ptn3460_get_modes(struct drm_connector *connector)
187{
188	struct ptn3460_bridge *ptn_bridge;
189	u8 *edid;
190	int ret, num_modes = 0;
191	bool power_off;
192
193	ptn_bridge = connector_to_ptn3460(connector);
194
195	if (ptn_bridge->edid)
196		return drm_add_edid_modes(connector, ptn_bridge->edid);
197
198	power_off = !ptn_bridge->enabled;
199	ptn3460_pre_enable(&ptn_bridge->bridge);
200
201	edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
202	if (!edid) {
203		DRM_ERROR("Failed to allocate EDID\n");
204		return 0;
205	}
206
207	ret = ptn3460_read_bytes(ptn_bridge, PTN3460_EDID_ADDR, edid,
208			EDID_LENGTH);
209	if (ret) {
210		kfree(edid);
211		goto out;
212	}
213
214	ptn_bridge->edid = (struct edid *)edid;
215	drm_connector_update_edid_property(connector, ptn_bridge->edid);
216
217	num_modes = drm_add_edid_modes(connector, ptn_bridge->edid);
218
219out:
220	if (power_off)
221		ptn3460_disable(&ptn_bridge->bridge);
222
223	return num_modes;
224}
225
 
 
 
 
 
 
 
226static const struct drm_connector_helper_funcs ptn3460_connector_helper_funcs = {
227	.get_modes = ptn3460_get_modes,
 
228};
229
 
 
 
 
 
 
 
 
 
 
 
230static const struct drm_connector_funcs ptn3460_connector_funcs = {
 
231	.fill_modes = drm_helper_probe_single_connector_modes,
232	.destroy = drm_connector_cleanup,
 
233	.reset = drm_atomic_helper_connector_reset,
234	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
235	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
236};
237
238static int ptn3460_bridge_attach(struct drm_bridge *bridge)
239{
240	struct ptn3460_bridge *ptn_bridge = bridge_to_ptn3460(bridge);
241	int ret;
242
243	if (!bridge->encoder) {
244		DRM_ERROR("Parent encoder object not found");
245		return -ENODEV;
246	}
247
248	ptn_bridge->connector.polled = DRM_CONNECTOR_POLL_HPD;
249	ret = drm_connector_init(bridge->dev, &ptn_bridge->connector,
250			&ptn3460_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
251	if (ret) {
252		DRM_ERROR("Failed to initialize connector with drm\n");
253		return ret;
254	}
255	drm_connector_helper_add(&ptn_bridge->connector,
256					&ptn3460_connector_helper_funcs);
257	drm_connector_register(&ptn_bridge->connector);
258	drm_connector_attach_encoder(&ptn_bridge->connector,
259							bridge->encoder);
260
261	if (ptn_bridge->panel)
262		drm_panel_attach(ptn_bridge->panel, &ptn_bridge->connector);
263
264	drm_helper_hpd_irq_event(ptn_bridge->connector.dev);
265
266	return ret;
267}
268
269static const struct drm_bridge_funcs ptn3460_bridge_funcs = {
270	.pre_enable = ptn3460_pre_enable,
271	.enable = ptn3460_enable,
272	.disable = ptn3460_disable,
273	.post_disable = ptn3460_post_disable,
274	.attach = ptn3460_bridge_attach,
275};
276
277static int ptn3460_probe(struct i2c_client *client,
278				const struct i2c_device_id *id)
279{
280	struct device *dev = &client->dev;
281	struct ptn3460_bridge *ptn_bridge;
 
282	int ret;
283
284	ptn_bridge = devm_kzalloc(dev, sizeof(*ptn_bridge), GFP_KERNEL);
285	if (!ptn_bridge) {
286		return -ENOMEM;
287	}
288
289	ret = drm_of_find_panel_or_bridge(dev->of_node, 0, 0, &ptn_bridge->panel, NULL);
290	if (ret)
291		return ret;
 
 
 
 
 
 
 
292
293	ptn_bridge->client = client;
294
295	ptn_bridge->gpio_pd_n = devm_gpiod_get(&client->dev, "powerdown",
296					       GPIOD_OUT_HIGH);
297	if (IS_ERR(ptn_bridge->gpio_pd_n)) {
298		ret = PTR_ERR(ptn_bridge->gpio_pd_n);
299		dev_err(dev, "cannot get gpio_pd_n %d\n", ret);
300		return ret;
301	}
302
303	/*
304	 * Request the reset pin low to avoid the bridge being
305	 * initialized prematurely
306	 */
307	ptn_bridge->gpio_rst_n = devm_gpiod_get(&client->dev, "reset",
308						GPIOD_OUT_LOW);
309	if (IS_ERR(ptn_bridge->gpio_rst_n)) {
310		ret = PTR_ERR(ptn_bridge->gpio_rst_n);
311		DRM_ERROR("cannot get gpio_rst_n %d\n", ret);
312		return ret;
313	}
314
315	ret = of_property_read_u32(dev->of_node, "edid-emulation",
316			&ptn_bridge->edid_emulation);
317	if (ret) {
318		dev_err(dev, "Can't read EDID emulation value\n");
319		return ret;
320	}
321
322	ptn_bridge->bridge.funcs = &ptn3460_bridge_funcs;
323	ptn_bridge->bridge.of_node = dev->of_node;
324	drm_bridge_add(&ptn_bridge->bridge);
 
 
 
 
325
326	i2c_set_clientdata(client, ptn_bridge);
327
328	return 0;
329}
330
331static int ptn3460_remove(struct i2c_client *client)
332{
333	struct ptn3460_bridge *ptn_bridge = i2c_get_clientdata(client);
334
335	drm_bridge_remove(&ptn_bridge->bridge);
336
337	return 0;
338}
339
340static const struct i2c_device_id ptn3460_i2c_table[] = {
341	{"ptn3460", 0},
342	{},
343};
344MODULE_DEVICE_TABLE(i2c, ptn3460_i2c_table);
345
346static const struct of_device_id ptn3460_match[] = {
347	{ .compatible = "nxp,ptn3460" },
348	{},
349};
350MODULE_DEVICE_TABLE(of, ptn3460_match);
351
352static struct i2c_driver ptn3460_driver = {
353	.id_table	= ptn3460_i2c_table,
354	.probe		= ptn3460_probe,
355	.remove		= ptn3460_remove,
356	.driver		= {
357		.name	= "nxp,ptn3460",
358		.of_match_table = ptn3460_match,
359	},
360};
361module_i2c_driver(ptn3460_driver);
362
363MODULE_AUTHOR("Sean Paul <seanpaul@chromium.org>");
364MODULE_DESCRIPTION("NXP ptn3460 eDP-LVDS converter driver");
365MODULE_LICENSE("GPL v2");