Blame view

drivers/ps3/ps3av.c 27.8 KB
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1
  /*
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
2
   *  PS3 AV backend support.
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
3
   *
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
4
5
   *  Copyright (C) 2007 Sony Computer Entertainment Inc.
   *  Copyright 2007 Sony Corp.
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
6
   *
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
7
8
9
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; version 2 of the License.
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
10
   *
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
11
12
13
14
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
15
   *
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
16
17
18
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
19
   */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
20
  #include <linux/kernel.h>
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
21
22
23
  #include <linux/module.h>
  #include <linux/delay.h>
  #include <linux/notifier.h>
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
24
  #include <linux/ioctl.h>
d7dd91ff2   Geert Uytterhoeven   ps3fb: default to...
25
  #include <linux/fb.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
26
  #include <linux/slab.h>
ef596c697   Geert Uytterhoeven   [POWERPC] ps3: al...
27
28
  
  #include <asm/firmware.h>
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
29
30
31
32
33
34
35
  #include <asm/ps3av.h>
  #include <asm/ps3.h>
  
  #include "vuart.h"
  
  #define BUFSIZE          4096	/* vuart buf size */
  #define PS3AV_BUF_SIZE   512	/* max packet size */
d7dd91ff2   Geert Uytterhoeven   ps3fb: default to...
36
  static int safe_mode;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
37
38
  static int timeout = 5000;	/* in msec ( 5 sec ) */
  module_param(timeout, int, 0644);
fffe52e86   Geert Uytterhoeven   ps3av: misc updates
39
  static struct ps3av {
fffe52e86   Geert Uytterhoeven   ps3av: misc updates
40
41
42
43
44
  	struct mutex mutex;
  	struct work_struct work;
  	struct completion done;
  	struct workqueue_struct *wq;
  	int open_count;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
45
  	struct ps3_system_bus_device *dev;
fffe52e86   Geert Uytterhoeven   ps3av: misc updates
46
47
48
49
50
51
52
53
54
  
  	int region;
  	struct ps3av_pkt_av_get_hw_conf av_hw_conf;
  	u32 av_port[PS3AV_AV_PORT_MAX + PS3AV_OPT_PORT_MAX];
  	u32 opt_port[PS3AV_OPT_PORT_MAX];
  	u32 head[PS3AV_HEAD_MAX];
  	u32 audio_port;
  	int ps3av_mode;
  	int ps3av_mode_old;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
55
56
57
58
  	union {
  		struct ps3av_reply_hdr reply_hdr;
  		u8 raw[PS3AV_BUF_SIZE];
  	} recv_buf;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
59
  } *ps3av;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  
  /* color space */
  #define YUV444 PS3AV_CMD_VIDEO_CS_YUV444_8
  #define RGB8   PS3AV_CMD_VIDEO_CS_RGB_8
  /* format */
  #define XRGB   PS3AV_CMD_VIDEO_FMT_X8R8G8B8
  /* aspect */
  #define A_N    PS3AV_CMD_AV_ASPECT_4_3
  #define A_W    PS3AV_CMD_AV_ASPECT_16_9
  static const struct avset_video_mode {
  	u32 cs;
  	u32 fmt;
  	u32 vid;
  	u32 aspect;
  	u32 x;
  	u32 y;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
76
77
  } video_mode_table[] = {
  	{     0, }, /* auto */
3c4f594a6   Geert Uytterhoeven   ps3av: ps3av_get_...
78
79
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480I,       A_N,  720,  480},
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480P,       A_N,  720,  480},
7a4a89c38   sebastian.blanes@gmail.com   ps3av: Set 16:9 a...
80
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_60HZ,  A_W, 1280,  720},
3c4f594a6   Geert Uytterhoeven   ps3av: ps3av_get_...
81
82
83
84
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_60HZ, A_W, 1920, 1080},
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_60HZ, A_W, 1920, 1080},
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576I,       A_N,  720,  576},
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576P,       A_N,  720,  576},
7a4a89c38   sebastian.blanes@gmail.com   ps3av: Set 16:9 a...
85
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_50HZ,  A_W, 1280,  720},
3c4f594a6   Geert Uytterhoeven   ps3av: ps3av_get_...
86
87
88
89
90
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_50HZ, A_W, 1920, 1080},
  	{YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_50HZ, A_W, 1920, 1080},
  	{  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WXGA,       A_W, 1280,  768},
  	{  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_SXGA,       A_N, 1280, 1024},
  	{  RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WUXGA,      A_W, 1920, 1200},
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  };
  
  /* supported CIDs */
  static u32 cmd_table[] = {
  	/* init */
  	PS3AV_CID_AV_INIT,
  	PS3AV_CID_AV_FIN,
  	PS3AV_CID_VIDEO_INIT,
  	PS3AV_CID_AUDIO_INIT,
  
  	/* set */
  	PS3AV_CID_AV_ENABLE_EVENT,
  	PS3AV_CID_AV_DISABLE_EVENT,
  
  	PS3AV_CID_AV_VIDEO_CS,
  	PS3AV_CID_AV_VIDEO_MUTE,
  	PS3AV_CID_AV_VIDEO_DISABLE_SIG,
  	PS3AV_CID_AV_AUDIO_PARAM,
  	PS3AV_CID_AV_AUDIO_MUTE,
  	PS3AV_CID_AV_HDMI_MODE,
  	PS3AV_CID_AV_TV_MUTE,
  
  	PS3AV_CID_VIDEO_MODE,
  	PS3AV_CID_VIDEO_FORMAT,
  	PS3AV_CID_VIDEO_PITCH,
  
  	PS3AV_CID_AUDIO_MODE,
  	PS3AV_CID_AUDIO_MUTE,
  	PS3AV_CID_AUDIO_ACTIVE,
  	PS3AV_CID_AUDIO_INACTIVE,
  	PS3AV_CID_AVB_PARAM,
  
  	/* get */
  	PS3AV_CID_AV_GET_HW_CONF,
  	PS3AV_CID_AV_GET_MONITOR_INFO,
  
  	/* event */
  	PS3AV_CID_EVENT_UNPLUGGED,
  	PS3AV_CID_EVENT_PLUGGED,
  	PS3AV_CID_EVENT_HDCP_DONE,
  	PS3AV_CID_EVENT_HDCP_FAIL,
  	PS3AV_CID_EVENT_HDCP_AUTH,
  	PS3AV_CID_EVENT_HDCP_ERROR,
  
  	0
  };
  
  #define PS3AV_EVENT_CMD_MASK           0x10000000
  #define PS3AV_EVENT_ID_MASK            0x0000ffff
  #define PS3AV_CID_MASK                 0xffffffff
  #define PS3AV_REPLY_BIT                0x80000000
  
  #define ps3av_event_get_port_id(cid)   ((cid >> 16) & 0xff)
  
  static u32 *ps3av_search_cmd_table(u32 cid, u32 mask)
  {
  	u32 *table;
  	int i;
  
  	table = cmd_table;
  	for (i = 0;; table++, i++) {
  		if ((*table & mask) == (cid & mask))
  			break;
  		if (*table == 0)
  			return NULL;
  	}
  	return table;
  }
  
  static int ps3av_parse_event_packet(const struct ps3av_reply_hdr *hdr)
  {
  	u32 *table;
  
  	if (hdr->cid & PS3AV_EVENT_CMD_MASK) {
  		table = ps3av_search_cmd_table(hdr->cid, PS3AV_EVENT_CMD_MASK);
  		if (table)
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
167
  			dev_dbg(&ps3av->dev->core,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
168
169
170
171
172
173
174
175
  				"recv event packet cid:%08x port:0x%x size:%d
  ",
  				hdr->cid, ps3av_event_get_port_id(hdr->cid),
  				hdr->size);
  		else
  			printk(KERN_ERR
  			       "%s: failed event packet, cid:%08x size:%d
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
176
  			       __func__, hdr->cid, hdr->size);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
177
178
179
180
  		return 1;	/* receive event packet */
  	}
  	return 0;
  }
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  
  #define POLLING_INTERVAL  25	/* in msec */
  
  static int ps3av_vuart_write(struct ps3_system_bus_device *dev,
  			     const void *buf, unsigned long size)
  {
  	int error;
  	dev_dbg(&dev->core, " -> %s:%d
  ", __func__, __LINE__);
  	error = ps3_vuart_write(dev, buf, size);
  	dev_dbg(&dev->core, " <- %s:%d
  ", __func__, __LINE__);
  	return error ? error : size;
  }
  
  static int ps3av_vuart_read(struct ps3_system_bus_device *dev, void *buf,
  			    unsigned long size, int timeout)
  {
  	int error;
  	int loopcnt = 0;
  
  	dev_dbg(&dev->core, " -> %s:%d
  ", __func__, __LINE__);
  	timeout = (timeout + POLLING_INTERVAL - 1) / POLLING_INTERVAL;
  	while (loopcnt++ <= timeout) {
  		error = ps3_vuart_read(dev, buf, size);
  		if (!error)
  			return size;
  		if (error != -EAGAIN) {
  			printk(KERN_ERR "%s: ps3_vuart_read failed %d
  ",
  			       __func__, error);
  			return error;
  		}
  		msleep(POLLING_INTERVAL);
  	}
  	return -EWOULDBLOCK;
  }
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
219
220
221
222
223
224
225
  static int ps3av_send_cmd_pkt(const struct ps3av_send_hdr *send_buf,
  			      struct ps3av_reply_hdr *recv_buf, int write_len,
  			      int read_len)
  {
  	int res;
  	u32 cmd;
  	int event;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
226
  	if (!ps3av)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
227
228
229
  		return -ENODEV;
  
  	/* send pkt */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
230
  	res = ps3av_vuart_write(ps3av->dev, send_buf, write_len);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
231
  	if (res < 0) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
232
  		dev_dbg(&ps3av->dev->core,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
233
234
  			"%s: ps3av_vuart_write() failed (result=%d)
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
235
  			__func__, res);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
236
237
238
239
240
241
242
  		return res;
  	}
  
  	/* recv pkt */
  	cmd = send_buf->cid;
  	do {
  		/* read header */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
243
  		res = ps3av_vuart_read(ps3av->dev, recv_buf, PS3AV_HDR_SIZE,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
244
245
  				       timeout);
  		if (res != PS3AV_HDR_SIZE) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
246
  			dev_dbg(&ps3av->dev->core,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
247
248
  				"%s: ps3av_vuart_read() failed (result=%d)
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
249
  				__func__, res);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
250
251
252
253
  			return res;
  		}
  
  		/* read body */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
254
  		res = ps3av_vuart_read(ps3av->dev, &recv_buf->cid,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
255
256
  				       recv_buf->size, timeout);
  		if (res < 0) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
257
  			dev_dbg(&ps3av->dev->core,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
258
259
  				"%s: ps3av_vuart_read() failed (result=%d)
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
260
  				__func__, res);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
261
262
263
264
265
266
267
268
  			return res;
  		}
  		res += PS3AV_HDR_SIZE;	/* total len */
  		event = ps3av_parse_event_packet(recv_buf);
  		/* ret > 0 event packet */
  	} while (event);
  
  	if ((cmd | PS3AV_REPLY_BIT) != recv_buf->cid) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
269
270
  		dev_dbg(&ps3av->dev->core, "%s: reply err (result=%x)
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
271
  			__func__, recv_buf->cid);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
272
273
274
275
276
277
278
279
280
281
282
283
284
  		return -EINVAL;
  	}
  
  	return 0;
  }
  
  static int ps3av_process_reply_packet(struct ps3av_send_hdr *cmd_buf,
  				      const struct ps3av_reply_hdr *recv_buf,
  				      int user_buf_size)
  {
  	int return_len;
  
  	if (recv_buf->version != PS3AV_VERSION) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
285
286
  		dev_dbg(&ps3av->dev->core, "reply_packet invalid version:%x
  ",
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  			recv_buf->version);
  		return -EFAULT;
  	}
  	return_len = recv_buf->size + PS3AV_HDR_SIZE;
  	if (return_len > user_buf_size)
  		return_len = user_buf_size;
  	memcpy(cmd_buf, recv_buf, return_len);
  	return 0;		/* success */
  }
  
  void ps3av_set_hdr(u32 cid, u16 size, struct ps3av_send_hdr *hdr)
  {
  	hdr->version = PS3AV_VERSION;
  	hdr->size = size - PS3AV_HDR_SIZE;
  	hdr->cid = cid;
  }
  
  int ps3av_do_pkt(u32 cid, u16 send_len, size_t usr_buf_size,
  		 struct ps3av_send_hdr *buf)
  {
  	int res = 0;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
308
  	u32 *table;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
309
  	BUG_ON(!ps3av);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
310

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
311
  	mutex_lock(&ps3av->mutex);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
312
313
314
315
316
317
318
319
320
321
322
  
  	table = ps3av_search_cmd_table(cid, PS3AV_CID_MASK);
  	BUG_ON(!table);
  	BUG_ON(send_len < PS3AV_HDR_SIZE);
  	BUG_ON(usr_buf_size < send_len);
  	BUG_ON(usr_buf_size > PS3AV_BUF_SIZE);
  
  	/* create header */
  	ps3av_set_hdr(cid, send_len, buf);
  
  	/* send packet via vuart */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
323
  	res = ps3av_send_cmd_pkt(buf, &ps3av->recv_buf.reply_hdr, send_len,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
324
325
326
327
328
  				 usr_buf_size);
  	if (res < 0) {
  		printk(KERN_ERR
  		       "%s: ps3av_send_cmd_pkt() failed (result=%d)
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
329
  		       __func__, res);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
330
331
332
333
  		goto err;
  	}
  
  	/* process reply packet */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
334
  	res = ps3av_process_reply_packet(buf, &ps3av->recv_buf.reply_hdr,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
335
336
337
338
  					 usr_buf_size);
  	if (res < 0) {
  		printk(KERN_ERR "%s: put_return_status() failed (result=%d)
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
339
  		       __func__, res);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
340
341
  		goto err;
  	}
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
342
  	mutex_unlock(&ps3av->mutex);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
343
344
345
  	return 0;
  
        err:
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
346
  	mutex_unlock(&ps3av->mutex);
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
347
348
  	printk(KERN_ERR "%s: failed cid:%x res:%d
  ", __func__, cid, res);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
349
350
351
352
353
354
  	return res;
  }
  
  static int ps3av_set_av_video_mute(u32 mute)
  {
  	int i, num_of_av_port, res;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
355
356
  	num_of_av_port = ps3av->av_hw_conf.num_of_hdmi +
  			 ps3av->av_hw_conf.num_of_avmulti;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
357
358
  	/* video mute on */
  	for (i = 0; i < num_of_av_port; i++) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
359
  		res = ps3av_cmd_av_video_mute(1, &ps3av->av_port[i], mute);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
360
361
362
363
364
365
366
367
368
369
  		if (res < 0)
  			return -1;
  	}
  
  	return 0;
  }
  
  static int ps3av_set_video_disable_sig(void)
  {
  	int i, num_of_hdmi_port, num_of_av_port, res;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
370
371
372
  	num_of_hdmi_port = ps3av->av_hw_conf.num_of_hdmi;
  	num_of_av_port = ps3av->av_hw_conf.num_of_hdmi +
  			 ps3av->av_hw_conf.num_of_avmulti;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
373
374
375
  
  	/* tv mute */
  	for (i = 0; i < num_of_hdmi_port; i++) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
376
  		res = ps3av_cmd_av_tv_mute(ps3av->av_port[i],
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
377
378
379
380
381
382
383
384
  					   PS3AV_CMD_MUTE_ON);
  		if (res < 0)
  			return -1;
  	}
  	msleep(100);
  
  	/* video mute on */
  	for (i = 0; i < num_of_av_port; i++) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
385
  		res = ps3av_cmd_av_video_disable_sig(ps3av->av_port[i]);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
386
387
388
  		if (res < 0)
  			return -1;
  		if (i < num_of_hdmi_port) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
389
  			res = ps3av_cmd_av_tv_mute(ps3av->av_port[i],
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
390
391
392
393
394
395
396
397
398
399
400
401
402
  						   PS3AV_CMD_MUTE_OFF);
  			if (res < 0)
  				return -1;
  		}
  	}
  	msleep(300);
  
  	return 0;
  }
  
  static int ps3av_set_audio_mute(u32 mute)
  {
  	int i, num_of_av_port, num_of_opt_port, res;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
403
404
405
  	num_of_av_port = ps3av->av_hw_conf.num_of_hdmi +
  			 ps3av->av_hw_conf.num_of_avmulti;
  	num_of_opt_port = ps3av->av_hw_conf.num_of_spdif;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
406
407
  
  	for (i = 0; i < num_of_av_port; i++) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
408
  		res = ps3av_cmd_av_audio_mute(1, &ps3av->av_port[i], mute);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
409
410
411
412
  		if (res < 0)
  			return -1;
  	}
  	for (i = 0; i < num_of_opt_port; i++) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
413
  		res = ps3av_cmd_audio_mute(1, &ps3av->opt_port[i], mute);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
414
415
416
417
418
419
420
421
422
423
424
425
426
  		if (res < 0)
  			return -1;
  	}
  
  	return 0;
  }
  
  int ps3av_set_audio_mode(u32 ch, u32 fs, u32 word_bits, u32 format, u32 source)
  {
  	struct ps3av_pkt_avb_param avb_param;
  	int i, num_of_audio, vid, res;
  	struct ps3av_pkt_audio_mode audio_mode;
  	u32 len = 0;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
427
428
429
  	num_of_audio = ps3av->av_hw_conf.num_of_hdmi +
  		       ps3av->av_hw_conf.num_of_avmulti +
  		       ps3av->av_hw_conf.num_of_spdif;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
430
431
432
433
  
  	avb_param.num_of_video_pkt = 0;
  	avb_param.num_of_audio_pkt = PS3AV_AVB_NUM_AUDIO;	/* always 0 */
  	avb_param.num_of_av_video_pkt = 0;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
434
  	avb_param.num_of_av_audio_pkt = ps3av->av_hw_conf.num_of_hdmi;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
435

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
436
  	vid = video_mode_table[ps3av->ps3av_mode].vid;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
437
438
439
440
441
  
  	/* audio mute */
  	ps3av_set_audio_mute(PS3AV_CMD_MUTE_ON);
  
  	/* audio inactive */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
442
  	res = ps3av_cmd_audio_active(0, ps3av->audio_port);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
443
  	if (res < 0)
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
444
  		dev_dbg(&ps3av->dev->core,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
445
446
447
448
449
  			"ps3av_cmd_audio_active OFF failed
  ");
  
  	/* audio_pkt */
  	for (i = 0; i < num_of_audio; i++) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
450
451
452
  		ps3av_cmd_set_audio_mode(&audio_mode, ps3av->av_port[i], ch,
  					 fs, word_bits, format, source);
  		if (i < ps3av->av_hw_conf.num_of_hdmi) {
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
453
454
  			/* hdmi only */
  			len += ps3av_cmd_set_av_audio_param(&avb_param.buf[len],
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
455
  							    ps3av->av_port[i],
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
456
457
458
459
460
  							    &audio_mode, vid);
  		}
  		/* audio_mode pkt should be sent separately */
  		res = ps3av_cmd_audio_mode(&audio_mode);
  		if (res < 0)
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
461
  			dev_dbg(&ps3av->dev->core,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
462
463
464
465
466
467
468
469
  				"ps3av_cmd_audio_mode failed, port:%x
  ", i);
  	}
  
  	/* send command using avb pkt */
  	len += offsetof(struct ps3av_pkt_avb_param, buf);
  	res = ps3av_cmd_avb_param(&avb_param, len);
  	if (res < 0)
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
470
471
  		dev_dbg(&ps3av->dev->core, "ps3av_cmd_avb_param failed
  ");
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
472
473
474
475
476
  
  	/* audio mute */
  	ps3av_set_audio_mute(PS3AV_CMD_MUTE_OFF);
  
  	/* audio active */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
477
  	res = ps3av_cmd_audio_active(1, ps3av->audio_port);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
478
  	if (res < 0)
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
479
480
481
  		dev_dbg(&ps3av->dev->core,
  			"ps3av_cmd_audio_active ON failed
  ");
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
482
483
484
485
486
487
488
489
490
491
492
493
  
  	return 0;
  }
  
  EXPORT_SYMBOL_GPL(ps3av_set_audio_mode);
  
  static int ps3av_set_videomode(void)
  {
  	/* av video mute */
  	ps3av_set_av_video_mute(PS3AV_CMD_MUTE_ON);
  
  	/* wake up ps3avd to do the actual video mode setting */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
494
  	queue_work(ps3av->wq, &ps3av->work);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
495
496
497
  
  	return 0;
  }
8ca0bf750   Masashi Kimoto   ps3: Fix black an...
498
  static void ps3av_set_videomode_packet(u32 id)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
499
500
  {
  	struct ps3av_pkt_avb_param avb_param;
8ca0bf750   Masashi Kimoto   ps3: Fix black an...
501
  	unsigned int i;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
502
503
504
505
506
507
508
509
  	u32 len = 0, av_video_cs;
  	const struct avset_video_mode *video_mode;
  	int res;
  
  	video_mode = &video_mode_table[id & PS3AV_MODE_MASK];
  
  	avb_param.num_of_video_pkt = PS3AV_AVB_NUM_VIDEO;	/* num of head */
  	avb_param.num_of_audio_pkt = 0;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
510
511
  	avb_param.num_of_av_video_pkt = ps3av->av_hw_conf.num_of_hdmi +
  					ps3av->av_hw_conf.num_of_avmulti;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
512
  	avb_param.num_of_av_audio_pkt = 0;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
513
514
515
  	/* video_pkt */
  	for (i = 0; i < avb_param.num_of_video_pkt; i++)
  		len += ps3av_cmd_set_video_mode(&avb_param.buf[len],
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
516
  						ps3av->head[i], video_mode->vid,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
517
518
519
520
521
522
523
524
  						video_mode->fmt, id);
  	/* av_video_pkt */
  	for (i = 0; i < avb_param.num_of_av_video_pkt; i++) {
  		if (id & PS3AV_MODE_DVI || id & PS3AV_MODE_RGB)
  			av_video_cs = RGB8;
  		else
  			av_video_cs = video_mode->cs;
  #ifndef PS3AV_HDMI_YUV
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
525
526
  		if (ps3av->av_port[i] == PS3AV_CMD_AVPORT_HDMI_0 ||
  		    ps3av->av_port[i] == PS3AV_CMD_AVPORT_HDMI_1)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
527
528
529
  			av_video_cs = RGB8;	/* use RGB for HDMI */
  #endif
  		len += ps3av_cmd_set_av_video_cs(&avb_param.buf[len],
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
530
  						 ps3av->av_port[i],
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
531
532
533
534
535
536
537
538
  						 video_mode->vid, av_video_cs,
  						 video_mode->aspect, id);
  	}
  	/* send command using avb pkt */
  	len += offsetof(struct ps3av_pkt_avb_param, buf);
  	res = ps3av_cmd_avb_param(&avb_param, len);
  	if (res == PS3AV_STATUS_NO_SYNC_HEAD)
  		printk(KERN_WARNING
8354be9c1   Frans Pop   powerpc: Remove t...
539
540
  		       "%s: Command failed. Please try your request again.
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
541
  		       __func__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
542
  	else if (res)
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
543
544
  		dev_dbg(&ps3av->dev->core, "ps3av_cmd_avb_param failed
  ");
8ca0bf750   Masashi Kimoto   ps3: Fix black an...
545
546
547
548
  }
  
  static void ps3av_set_videomode_cont(u32 id, u32 old_id)
  {
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
549
  	static int vesa;
8ca0bf750   Masashi Kimoto   ps3: Fix black an...
550
551
552
553
554
555
556
557
558
  	int res;
  
  	/* video signal off */
  	ps3av_set_video_disable_sig();
  
  	/*
  	 * AV backend needs non-VESA mode setting at least one time
  	 * when VESA mode is used.
  	 */
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
559
  	if (vesa == 0 && (id & PS3AV_MODE_MASK) >= PS3AV_MODE_WXGA) {
8ca0bf750   Masashi Kimoto   ps3: Fix black an...
560
  		/* vesa mode */
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
561
  		ps3av_set_videomode_packet(PS3AV_MODE_480P);
8ca0bf750   Masashi Kimoto   ps3: Fix black an...
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  	}
  	vesa = 1;
  
  	/* Retail PS3 product doesn't support this */
  	if (id & PS3AV_MODE_HDCP_OFF) {
  		res = ps3av_cmd_av_hdmi_mode(PS3AV_CMD_AV_HDMI_HDCP_OFF);
  		if (res == PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
  			dev_dbg(&ps3av->dev->core, "Not supported
  ");
  		else if (res)
  			dev_dbg(&ps3av->dev->core,
  				"ps3av_cmd_av_hdmi_mode failed
  ");
  	} else if (old_id & PS3AV_MODE_HDCP_OFF) {
  		res = ps3av_cmd_av_hdmi_mode(PS3AV_CMD_AV_HDMI_MODE_NORMAL);
  		if (res < 0 && res != PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
  			dev_dbg(&ps3av->dev->core,
  				"ps3av_cmd_av_hdmi_mode failed
  ");
  	}
  
  	ps3av_set_videomode_packet(id);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
584
585
586
587
588
  
  	msleep(1500);
  	/* av video mute */
  	ps3av_set_av_video_mute(PS3AV_CMD_MUTE_OFF);
  }
5caf5db88   Geert Uytterhoeven   ps3av: thread upd...
589
  static void ps3avd(struct work_struct *work)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
590
  {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
591
592
  	ps3av_set_videomode_cont(ps3av->ps3av_mode, ps3av->ps3av_mode_old);
  	complete(&ps3av->done);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
593
  }
fd5621129   Geert Uytterhoeven   ps3av: add autode...
594
595
596
597
598
599
600
601
  #define SHIFT_50	0
  #define SHIFT_60	4
  #define SHIFT_VESA	8
  
  static const struct {
  	unsigned mask : 19;
  	unsigned id :  4;
  } ps3av_preferred_modes[] = {
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
602
603
604
605
606
607
608
609
610
611
612
  	{ PS3AV_RESBIT_WUXGA      << SHIFT_VESA, PS3AV_MODE_WUXGA   },
  	{ PS3AV_RESBIT_1920x1080P << SHIFT_60,   PS3AV_MODE_1080P60 },
  	{ PS3AV_RESBIT_1920x1080P << SHIFT_50,   PS3AV_MODE_1080P50 },
  	{ PS3AV_RESBIT_1920x1080I << SHIFT_60,   PS3AV_MODE_1080I60 },
  	{ PS3AV_RESBIT_1920x1080I << SHIFT_50,   PS3AV_MODE_1080I50 },
  	{ PS3AV_RESBIT_SXGA       << SHIFT_VESA, PS3AV_MODE_SXGA    },
  	{ PS3AV_RESBIT_WXGA       << SHIFT_VESA, PS3AV_MODE_WXGA    },
  	{ PS3AV_RESBIT_1280x720P  << SHIFT_60,   PS3AV_MODE_720P60  },
  	{ PS3AV_RESBIT_1280x720P  << SHIFT_50,   PS3AV_MODE_720P50  },
  	{ PS3AV_RESBIT_720x480P   << SHIFT_60,   PS3AV_MODE_480P    },
  	{ PS3AV_RESBIT_720x576P   << SHIFT_50,   PS3AV_MODE_576P    },
fd5621129   Geert Uytterhoeven   ps3av: add autode...
613
  };
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
614
615
  static enum ps3av_mode_num ps3av_resbit2id(u32 res_50, u32 res_60,
  					   u32 res_vesa)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
616
  {
fd5621129   Geert Uytterhoeven   ps3av: add autode...
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
  	unsigned int i;
  	u32 res_all;
  
  	/*
  	 * We mask off the resolution bits we care about and combine the
  	 * results in one bitfield, so make sure there's no overlap
  	 */
  	BUILD_BUG_ON(PS3AV_RES_MASK_50 << SHIFT_50 &
  		     PS3AV_RES_MASK_60 << SHIFT_60);
  	BUILD_BUG_ON(PS3AV_RES_MASK_50 << SHIFT_50 &
  		     PS3AV_RES_MASK_VESA << SHIFT_VESA);
  	BUILD_BUG_ON(PS3AV_RES_MASK_60 << SHIFT_60 &
  		     PS3AV_RES_MASK_VESA << SHIFT_VESA);
  	res_all = (res_50 & PS3AV_RES_MASK_50) << SHIFT_50 |
  		  (res_60 & PS3AV_RES_MASK_60) << SHIFT_60 |
  		  (res_vesa & PS3AV_RES_MASK_VESA) << SHIFT_VESA;
  
  	if (!res_all)
  		return 0;
  
  	for (i = 0; i < ARRAY_SIZE(ps3av_preferred_modes); i++)
  		if (res_all & ps3av_preferred_modes[i].mask)
  			return ps3av_preferred_modes[i].id;
  
  	return 0;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
642
  }
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
643
  static enum ps3av_mode_num ps3av_hdmi_get_id(struct ps3av_info_monitor *info)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
644
  {
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
645
  	enum ps3av_mode_num id;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
646

d7dd91ff2   Geert Uytterhoeven   ps3fb: default to...
647
648
  	if (safe_mode)
  		return PS3AV_DEFAULT_HDMI_MODE_ID_REG_60;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
649
  	/* check native resolution */
fd5621129   Geert Uytterhoeven   ps3av: add autode...
650
651
652
653
654
  	id = ps3av_resbit2id(info->res_50.native, info->res_60.native,
  			     info->res_vesa.native);
  	if (id) {
  		pr_debug("%s: Using native mode %d
  ", __func__, id);
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
655
  		return id;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
656
  	}
fd5621129   Geert Uytterhoeven   ps3av: add autode...
657
658
659
660
661
662
  	/* check supported resolutions */
  	id = ps3av_resbit2id(info->res_50.res_bits, info->res_60.res_bits,
  			     info->res_vesa.res_bits);
  	if (id) {
  		pr_debug("%s: Using supported mode %d
  ", __func__, id);
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
663
  		return id;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
664
  	}
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
665
  	if (ps3av->region & PS3AV_REGION_60)
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
666
  		id = PS3AV_DEFAULT_HDMI_MODE_ID_REG_60;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
667
  	else
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
668
  		id = PS3AV_DEFAULT_HDMI_MODE_ID_REG_50;
fd5621129   Geert Uytterhoeven   ps3av: add autode...
669
670
  	pr_debug("%s: Using default mode %d
  ", __func__, id);
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
671
  	return id;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
672
  }
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
  static void ps3av_monitor_info_dump(const struct ps3av_pkt_av_get_monitor_info *monitor_info)
  {
  	const struct ps3av_info_monitor *info = &monitor_info->info;
  	const struct ps3av_info_audio *audio = info->audio;
  	char id[sizeof(info->monitor_id)*3+1];
  	int i;
  
  	pr_debug("Monitor Info: size %u
  ", monitor_info->send_hdr.size);
  
  	pr_debug("avport: %02x
  ", info->avport);
  	for (i = 0; i < sizeof(info->monitor_id); i++)
  		sprintf(&id[i*3], " %02x", info->monitor_id[i]);
  	pr_debug("monitor_id: %s
  ", id);
  	pr_debug("monitor_type: %02x
  ", info->monitor_type);
  	pr_debug("monitor_name: %.*s
  ", (int)sizeof(info->monitor_name),
  		 info->monitor_name);
  
  	/* resolution */
  	pr_debug("resolution_60: bits: %08x native: %08x
  ",
  		 info->res_60.res_bits, info->res_60.native);
  	pr_debug("resolution_50: bits: %08x native: %08x
  ",
  		 info->res_50.res_bits, info->res_50.native);
  	pr_debug("resolution_other: bits: %08x native: %08x
  ",
  		 info->res_other.res_bits, info->res_other.native);
  	pr_debug("resolution_vesa: bits: %08x native: %08x
  ",
  		 info->res_vesa.res_bits, info->res_vesa.native);
  
  	/* color space */
  	pr_debug("color space    rgb: %02x
  ", info->cs.rgb);
  	pr_debug("color space yuv444: %02x
  ", info->cs.yuv444);
  	pr_debug("color space yuv422: %02x
  ", info->cs.yuv422);
  
  	/* color info */
  	pr_debug("color info   red: X %04x Y %04x
  ", info->color.red_x,
  		 info->color.red_y);
  	pr_debug("color info green: X %04x Y %04x
  ", info->color.green_x,
  		 info->color.green_y);
  	pr_debug("color info  blue: X %04x Y %04x
  ", info->color.blue_x,
  		 info->color.blue_y);
  	pr_debug("color info white: X %04x Y %04x
  ", info->color.white_x,
  		 info->color.white_y);
  	pr_debug("color info gamma:  %08x
  ", info->color.gamma);
  
  	/* other info */
  	pr_debug("supported_AI: %02x
  ", info->supported_ai);
  	pr_debug("speaker_info: %02x
  ", info->speaker_info);
  	pr_debug("num of audio: %02x
  ", info->num_of_audio_block);
  
  	/* audio block */
  	for (i = 0; i < info->num_of_audio_block; i++) {
  		pr_debug("audio[%d] type: %02x max_ch: %02x fs: %02x sbit: "
  			 "%02x
  ",
  			 i, audio->type, audio->max_num_of_ch, audio->fs,
  			 audio->sbit);
  		audio++;
  	}
  }
57f70c606   Geert Uytterhoeven   ps3av: add quirk ...
751
752
  static const struct ps3av_monitor_quirk {
  	const char *monitor_name;
3305a6bc2   Geert Uytterhoeven   ps3av: remove unu...
753
  	u32 clear_60;
57f70c606   Geert Uytterhoeven   ps3av: add quirk ...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
  } ps3av_monitor_quirks[] = {
  	{
  		.monitor_name	= "DELL 2007WFP",
  		.clear_60	= PS3AV_RESBIT_1920x1080I
  	}, {
  		.monitor_name	= "L226WTQ",
  		.clear_60	= PS3AV_RESBIT_1920x1080I |
  				  PS3AV_RESBIT_1920x1080P
  	}, {
  		.monitor_name	= "SyncMaster",
  		.clear_60	= PS3AV_RESBIT_1920x1080I
  	}
  };
  
  static void ps3av_fixup_monitor_info(struct ps3av_info_monitor *info)
  {
  	unsigned int i;
  	const struct ps3av_monitor_quirk *quirk;
  
  	for (i = 0; i < ARRAY_SIZE(ps3av_monitor_quirks); i++) {
  		quirk = &ps3av_monitor_quirks[i];
  		if (!strncmp(info->monitor_name, quirk->monitor_name,
  			     sizeof(info->monitor_name))) {
  			pr_info("%s: Applying quirk for %s
  ", __func__,
  				quirk->monitor_name);
  			info->res_60.res_bits &= ~quirk->clear_60;
  			info->res_60.native &= ~quirk->clear_60;
57f70c606   Geert Uytterhoeven   ps3av: add quirk ...
782
783
784
785
  			break;
  		}
  	}
  }
ce4c371a9   Geert Uytterhoeven   ps3av: dont disti...
786
  static int ps3av_auto_videomode(struct ps3av_pkt_av_get_hw_conf *av_hw_conf)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
787
  {
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
788
  	int i, res, id = 0, dvi = 0, rgb = 0;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
789
790
  	struct ps3av_pkt_av_get_monitor_info monitor_info;
  	struct ps3av_info_monitor *info;
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
791
  	/* get mode id for hdmi */
101aa56d0   Geert Uytterhoeven   ps3av: treat DVI-...
792
  	for (i = 0; i < av_hw_conf->num_of_hdmi && !id; i++) {
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
793
794
795
796
797
  		res = ps3av_cmd_video_get_monitor_info(&monitor_info,
  						       PS3AV_CMD_AVPORT_HDMI_0 +
  						       i);
  		if (res < 0)
  			return -1;
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
798
  		ps3av_monitor_info_dump(&monitor_info);
101aa56d0   Geert Uytterhoeven   ps3av: treat DVI-...
799

11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
800
  		info = &monitor_info.info;
57f70c606   Geert Uytterhoeven   ps3av: add quirk ...
801
  		ps3av_fixup_monitor_info(info);
101aa56d0   Geert Uytterhoeven   ps3av: treat DVI-...
802
803
  		switch (info->monitor_type) {
  		case PS3AV_MONITOR_TYPE_DVI:
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
804
  			dvi = PS3AV_MODE_DVI;
101aa56d0   Geert Uytterhoeven   ps3av: treat DVI-...
805
806
807
  			/* fall through */
  		case PS3AV_MONITOR_TYPE_HDMI:
  			id = ps3av_hdmi_get_id(info);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
808
809
810
  			break;
  		}
  	}
101aa56d0   Geert Uytterhoeven   ps3av: treat DVI-...
811
  	if (!id) {
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
812
  		/* no HDMI interface or HDMI is off */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
813
  		if (ps3av->region & PS3AV_REGION_60)
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
814
  			id = PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_60;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
815
  		else
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
816
  			id = PS3AV_DEFAULT_AVMULTI_MODE_ID_REG_50;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
817
  		if (ps3av->region & PS3AV_REGION_RGB)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
818
  			rgb = PS3AV_MODE_RGB;
fd5621129   Geert Uytterhoeven   ps3av: add autode...
819
820
  		pr_debug("%s: Using avmulti mode %d
  ", __func__, id);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
821
  	}
71a27feca   Geert Uytterhoeven   ps3av: use PS3 vi...
822
  	return id | dvi | rgb;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
823
824
825
826
827
  }
  
  static int ps3av_get_hw_conf(struct ps3av *ps3av)
  {
  	int i, j, k, res;
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
828
  	const struct ps3av_pkt_av_get_hw_conf *hw_conf;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
829
830
831
832
833
  
  	/* get av_hw_conf */
  	res = ps3av_cmd_av_get_hw_conf(&ps3av->av_hw_conf);
  	if (res < 0)
  		return -1;
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
834
835
836
837
838
839
840
  	hw_conf = &ps3av->av_hw_conf;
  	pr_debug("av_h_conf: num of hdmi: %u
  ", hw_conf->num_of_hdmi);
  	pr_debug("av_h_conf: num of avmulti: %u
  ", hw_conf->num_of_avmulti);
  	pr_debug("av_h_conf: num of spdif: %u
  ", hw_conf->num_of_spdif);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
841
842
843
844
845
  
  	for (i = 0; i < PS3AV_HEAD_MAX; i++)
  		ps3av->head[i] = PS3AV_CMD_VIDEO_HEAD_A + i;
  	for (i = 0; i < PS3AV_OPT_PORT_MAX; i++)
  		ps3av->opt_port[i] = PS3AV_CMD_AVPORT_SPDIF_0 + i;
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
846
  	for (i = 0; i < hw_conf->num_of_hdmi; i++)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
847
  		ps3av->av_port[i] = PS3AV_CMD_AVPORT_HDMI_0 + i;
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
848
  	for (j = 0; j < hw_conf->num_of_avmulti; j++)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
849
  		ps3av->av_port[i + j] = PS3AV_CMD_AVPORT_AVMULTI_0 + j;
eea820ab0   Geert Uytterhoeven   ps3av: eliminate ...
850
  	for (k = 0; k < hw_conf->num_of_spdif; k++)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
851
852
853
854
855
856
857
858
859
860
861
862
  		ps3av->av_port[i + j + k] = PS3AV_CMD_AVPORT_SPDIF_0 + k;
  
  	/* set all audio port */
  	ps3av->audio_port = PS3AV_CMD_AUDIO_PORT_HDMI_0
  	    | PS3AV_CMD_AUDIO_PORT_HDMI_1
  	    | PS3AV_CMD_AUDIO_PORT_AVMULTI_0
  	    | PS3AV_CMD_AUDIO_PORT_SPDIF_0 | PS3AV_CMD_AUDIO_PORT_SPDIF_1;
  
  	return 0;
  }
  
  /* set mode using id */
e7eec2fc2   roel kluin   powerpc/ps3: Make...
863
  int ps3av_set_video_mode(int id)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
864
865
866
867
868
869
  {
  	int size;
  	u32 option;
  
  	size = ARRAY_SIZE(video_mode_table);
  	if ((id & PS3AV_MODE_MASK) > size - 1 || id < 0) {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
870
871
  		dev_dbg(&ps3av->dev->core, "%s: error id :%d
  ", __func__, id);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
872
873
874
875
876
  		return -EINVAL;
  	}
  
  	/* auto mode */
  	option = id & ~PS3AV_MODE_MASK;
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
877
  	if ((id & PS3AV_MODE_MASK) == PS3AV_MODE_AUTO) {
ce4c371a9   Geert Uytterhoeven   ps3av: dont disti...
878
  		id = ps3av_auto_videomode(&ps3av->av_hw_conf);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
879
  		if (id < 1) {
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
880
881
  			printk(KERN_ERR "%s: invalid id :%d
  ", __func__, id);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
882
883
884
885
886
887
  			return -EINVAL;
  		}
  		id |= option;
  	}
  
  	/* set videomode */
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
888
889
890
  	wait_for_completion(&ps3av->done);
  	ps3av->ps3av_mode_old = ps3av->ps3av_mode;
  	ps3av->ps3av_mode = id;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
891
  	if (ps3av_set_videomode())
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
892
  		ps3av->ps3av_mode = ps3av->ps3av_mode_old;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
893
894
895
896
897
  
  	return 0;
  }
  
  EXPORT_SYMBOL_GPL(ps3av_set_video_mode);
ce4c371a9   Geert Uytterhoeven   ps3av: dont disti...
898
  int ps3av_get_auto_mode(void)
640729014   Masashi Kimoto   ps3: Make `ps3vid...
899
  {
ce4c371a9   Geert Uytterhoeven   ps3av: dont disti...
900
  	return ps3av_auto_videomode(&ps3av->av_hw_conf);
640729014   Masashi Kimoto   ps3: Make `ps3vid...
901
902
903
  }
  
  EXPORT_SYMBOL_GPL(ps3av_get_auto_mode);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
904
905
  int ps3av_get_mode(void)
  {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
906
  	return ps3av ? ps3av->ps3av_mode : 0;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
907
908
909
  }
  
  EXPORT_SYMBOL_GPL(ps3av_get_mode);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
910
911
912
913
914
915
916
917
  /* get resolution by video_mode */
  int ps3av_video_mode2res(u32 id, u32 *xres, u32 *yres)
  {
  	int size;
  
  	id = id & PS3AV_MODE_MASK;
  	size = ARRAY_SIZE(video_mode_table);
  	if (id > size - 1 || id < 0) {
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
918
919
  		printk(KERN_ERR "%s: invalid mode %d
  ", __func__, id);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
  		return -EINVAL;
  	}
  	*xres = video_mode_table[id].x;
  	*yres = video_mode_table[id].y;
  	return 0;
  }
  
  EXPORT_SYMBOL_GPL(ps3av_video_mode2res);
  
  /* mute */
  int ps3av_video_mute(int mute)
  {
  	return ps3av_set_av_video_mute(mute ? PS3AV_CMD_MUTE_ON
  					    : PS3AV_CMD_MUTE_OFF);
  }
  
  EXPORT_SYMBOL_GPL(ps3av_video_mute);
756ba83ee   Masakazu Mokuno   ps3: Add ps3av_au...
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
  /* mute analog output only */
  int ps3av_audio_mute_analog(int mute)
  {
  	int i, res;
  
  	for (i = 0; i < ps3av->av_hw_conf.num_of_avmulti; i++) {
  		res = ps3av_cmd_av_audio_mute(1,
  			&ps3av->av_port[i + ps3av->av_hw_conf.num_of_hdmi],
  			mute);
  		if (res < 0)
  			return -1;
  	}
  	return 0;
  }
  EXPORT_SYMBOL_GPL(ps3av_audio_mute_analog);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
952
953
954
955
956
957
958
  int ps3av_audio_mute(int mute)
  {
  	return ps3av_set_audio_mute(mute ? PS3AV_CMD_MUTE_ON
  					 : PS3AV_CMD_MUTE_OFF);
  }
  
  EXPORT_SYMBOL_GPL(ps3av_audio_mute);
a469f563d   Geert Uytterhoeven   drivers/ps3: Add ...
959
  static int __devinit ps3av_probe(struct ps3_system_bus_device *dev)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
960
961
  {
  	int res;
e7eec2fc2   roel kluin   powerpc/ps3: Make...
962
  	int id;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
963

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
964
965
966
967
  	dev_dbg(&dev->core, " -> %s:%d
  ", __func__, __LINE__);
  	dev_dbg(&dev->core, "  timeout=%d
  ", timeout);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
968

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
969
970
971
972
973
  	if (ps3av) {
  		dev_err(&dev->core, "Only one ps3av device is supported
  ");
  		return -EBUSY;
  	}
5caf5db88   Geert Uytterhoeven   ps3av: thread upd...
974

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
975
976
  	ps3av = kzalloc(sizeof(*ps3av), GFP_KERNEL);
  	if (!ps3av)
5caf5db88   Geert Uytterhoeven   ps3av: thread upd...
977
  		return -ENOMEM;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
978

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
979
  	mutex_init(&ps3av->mutex);
084ffff29   Geert Uytterhoeven   ps3: use symbolic...
980
  	ps3av->ps3av_mode = PS3AV_MODE_AUTO;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
981
982
983
984
985
986
  	ps3av->dev = dev;
  
  	INIT_WORK(&ps3av->work, ps3avd);
  	init_completion(&ps3av->done);
  	complete(&ps3av->done);
  	ps3av->wq = create_singlethread_workqueue("ps3avd");
e7eec2fc2   roel kluin   powerpc/ps3: Make...
987
988
  	if (!ps3av->wq) {
  		res = -ENOMEM;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
989
  		goto fail;
e7eec2fc2   roel kluin   powerpc/ps3: Make...
990
  	}
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
991

11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
992
993
  	switch (ps3_os_area_get_av_multi_out()) {
  	case PS3_PARAM_AV_MULTI_OUT_NTSC:
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
994
  		ps3av->region = PS3AV_REGION_60;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
995
996
997
  		break;
  	case PS3_PARAM_AV_MULTI_OUT_PAL_YCBCR:
  	case PS3_PARAM_AV_MULTI_OUT_SECAM:
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
998
  		ps3av->region = PS3AV_REGION_50;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
999
1000
  		break;
  	case PS3_PARAM_AV_MULTI_OUT_PAL_RGB:
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1001
  		ps3av->region = PS3AV_REGION_50 | PS3AV_REGION_RGB;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1002
1003
  		break;
  	default:
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1004
  		ps3av->region = PS3AV_REGION_60;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1005
1006
1007
1008
1009
1010
  		break;
  	}
  
  	/* init avsetting modules */
  	res = ps3av_cmd_init();
  	if (res < 0)
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
1011
1012
  		printk(KERN_ERR "%s: ps3av_cmd_init failed %d
  ", __func__,
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1013
  		       res);
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1014
  	ps3av_get_hw_conf(ps3av);
d7dd91ff2   Geert Uytterhoeven   ps3fb: default to...
1015
1016
1017
1018
1019
  
  #ifdef CONFIG_FB
  	if (fb_mode_option && !strcmp(fb_mode_option, "safe"))
  		safe_mode = 1;
  #endif /* CONFIG_FB */
ce4c371a9   Geert Uytterhoeven   ps3av: dont disti...
1020
  	id = ps3av_auto_videomode(&ps3av->av_hw_conf);
e7eec2fc2   roel kluin   powerpc/ps3: Make...
1021
1022
1023
1024
1025
1026
  	if (id < 0) {
  		printk(KERN_ERR "%s: invalid id :%d
  ", __func__, id);
  		res = -EINVAL;
  		goto fail;
  	}
d7dd91ff2   Geert Uytterhoeven   ps3fb: default to...
1027
  	safe_mode = 0;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1028
1029
1030
  	mutex_lock(&ps3av->mutex);
  	ps3av->ps3av_mode = id;
  	mutex_unlock(&ps3av->mutex);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1031

13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1032
1033
  	dev_dbg(&dev->core, " <- %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1034
1035
  
  	return 0;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1036
1037
1038
1039
  
  fail:
  	kfree(ps3av);
  	ps3av = NULL;
e7eec2fc2   roel kluin   powerpc/ps3: Make...
1040
  	return res;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1041
  }
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1042
  static int ps3av_remove(struct ps3_system_bus_device *dev)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1043
  {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1044
1045
1046
  	dev_dbg(&dev->core, " -> %s:%d
  ", __func__, __LINE__);
  	if (ps3av) {
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1047
  		ps3av_cmd_fin();
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1048
1049
1050
1051
  		if (ps3av->wq)
  			destroy_workqueue(ps3av->wq);
  		kfree(ps3av);
  		ps3av = NULL;
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1052
  	}
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1053
1054
  	dev_dbg(&dev->core, " <- %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1055
1056
  	return 0;
  }
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1057
  static void ps3av_shutdown(struct ps3_system_bus_device *dev)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1058
  {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1059
1060
  	dev_dbg(&dev->core, " -> %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1061
  	ps3av_remove(dev);
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1062
1063
  	dev_dbg(&dev->core, " <- %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1064
1065
1066
  }
  
  static struct ps3_vuart_port_driver ps3av_driver = {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1067
1068
  	.core.match_id = PS3_MATCH_ID_AV_SETTINGS,
  	.core.core.name = "ps3_av",
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1069
1070
1071
1072
  	.probe = ps3av_probe,
  	.remove = ps3av_remove,
  	.shutdown = ps3av_shutdown,
  };
a469f563d   Geert Uytterhoeven   drivers/ps3: Add ...
1073
  static int __init ps3av_module_init(void)
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1074
  {
ef596c697   Geert Uytterhoeven   [POWERPC] ps3: al...
1075
1076
1077
1078
  	int error;
  
  	if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
  		return -ENODEV;
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1079
1080
  	pr_debug(" -> %s:%d
  ", __func__, __LINE__);
ef596c697   Geert Uytterhoeven   [POWERPC] ps3: al...
1081
  	error = ps3_vuart_port_driver_register(&ps3av_driver);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1082
1083
1084
1085
  	if (error) {
  		printk(KERN_ERR
  		       "%s: ps3_vuart_port_driver_register failed %d
  ",
253f04e78   Geert Uytterhoeven   ps3av: Use __func...
1086
  		       __func__, error);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1087
1088
  		return error;
  	}
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1089
1090
  	pr_debug(" <- %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1091
1092
1093
1094
1095
  	return error;
  }
  
  static void __exit ps3av_module_exit(void)
  {
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1096
1097
  	pr_debug(" -> %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1098
  	ps3_vuart_port_driver_unregister(&ps3av_driver);
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1099
1100
  	pr_debug(" <- %s:%d
  ", __func__, __LINE__);
11227fd19   Geert Uytterhoeven   [PATCH] ps3: AV S...
1101
1102
1103
1104
  }
  
  subsys_initcall(ps3av_module_init);
  module_exit(ps3av_module_exit);
13a5e30cf   Geoff Levand   [POWERPC] PS3: Re...
1105
1106
1107
1108
1109
  
  MODULE_LICENSE("GPL v2");
  MODULE_DESCRIPTION("PS3 AV Settings Driver");
  MODULE_AUTHOR("Sony Computer Entertainment Inc.");
  MODULE_ALIAS(PS3_MODULE_ALIAS_AV_SETTINGS);