blob: c6acf9f28074a3045111401ca7dbccb72c753f82 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/delay.h>
18#include <linux/mm.h>
19#include <linux/fb.h>
20#include <linux/init.h>
21#include <linux/ioport.h>
22#include <linux/device.h>
23#include <linux/dma-mapping.h>
24
25#include "msm_fb.h"
26#include "mddihost.h"
27#include "mddihosti.h"
28
29#include <linux/clk.h>
30#include <mach/clk.h>
31
32struct semaphore mddi_host_mutex;
33
34struct clk *mddi_io_clk;
35static boolean mddi_host_powered = FALSE;
36static boolean mddi_host_initialized = FALSE;
37extern uint32 *mddi_reg_read_value_ptr;
38
39mddi_lcd_func_type mddi_lcd;
40
41extern mddi_client_capability_type mddi_client_capability_pkt;
42
43#ifdef MDDI_HOST_WINDOW_WORKAROUND
44/* Tables showing number of rows that would cause a packet length
45 * ending in 0x02, for each number of columns. These tables have
46 * been generated for MDDI packets that have 16 and 16 bits-per-pixel.
47 * This is a work-around for MDDI clients that declare a CRC error
48 * on MDDI packets where ((length & 0x00ff) == 0x02).
49 */
50static uint16 error_vals_16bpp[] = {
510, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
520, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0,
530, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
540, 10, 0, 0, 0, 14, 0, 0, 0, 2, 0, 0, 4, 6, 12, 0,
550, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
560, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 11, 4, 0, 12, 0,
570, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
580, 10, 0, 1, 0, 14, 0, 0, 0, 2, 0, 3, 4, 6, 12, 0,
590, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
600, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0,
610, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
620, 10, 0, 0, 0, 14, 0, 0, 0, 2, 0, 0, 4, 6, 12, 0,
630, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0,
640, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 11, 4, 0, 12, 0,
650, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
66};
67
68static uint16 error_vals_18bpp[] = {
690, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
700, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
710, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 14,
720, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 9, 0, 0,
730, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
740, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 7,
750, 0, 0, 0, 0, 0, 1, 0, 0, 16, 0, 0, 0, 0, 0, 6,
7614, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
770, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
780, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
797, 0, 0, 0, 0, 0, 0, 4, 0, 16, 0, 0, 0, 0, 0, 0,
800, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
810, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
820, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
830, 7, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 9, 0
84};
85#endif
86
87#ifdef FEATURE_MDDI_HITACHI
88extern void mddi_hitachi_window_adjust(uint16 x1,
89 uint16 x2, uint16 y1, uint16 y2);
90#endif
91
92extern void mddi_toshiba_lcd_init(void);
93
94#ifdef FEATURE_MDDI_S6D0142
95extern void mddi_s6d0142_lcd_init(void);
96extern void mddi_s6d0142_window_adjust(uint16 x1,
97 uint16 x2,
98 uint16 y1,
99 uint16 y2,
100 mddi_llist_done_cb_type done_cb);
101#endif
102
103void mddi_init(void)
104{
105 if (mddi_host_initialized)
106 return;
107
108 mddi_host_initialized = TRUE;
109
110 sema_init(&mddi_host_mutex, 1);
111
112 if (!mddi_host_powered) {
113 down(&mddi_host_mutex);
114 mddi_host_init(MDDI_HOST_PRIM);
115 mddi_host_powered = TRUE;
116 up(&mddi_host_mutex);
117 mdelay(10);
118 }
119}
120
121int mddi_host_register_read(uint32 reg_addr,
122 uint32 *reg_value_ptr, boolean wait, mddi_host_type host) {
123 mddi_linked_list_type *curr_llist_ptr;
124 mddi_register_access_packet_type *regacc_pkt_ptr;
125 uint16 curr_llist_idx;
126 int ret = 0;
127
128 if (in_interrupt())
129 MDDI_MSG_CRIT("Called from ISR context\n");
130
131 if (!mddi_host_powered) {
132 MDDI_MSG_ERR("MDDI powered down!\n");
133 mddi_init();
134 }
135
136 down(&mddi_host_mutex);
137
138 mddi_reg_read_value_ptr = reg_value_ptr;
139 curr_llist_idx = mddi_get_reg_read_llist_item(host, TRUE);
140 if (curr_llist_idx == UNASSIGNED_INDEX) {
141 up(&mddi_host_mutex);
142
143 /* need to change this to some sort of wait */
144 MDDI_MSG_ERR("Attempting to queue up more than 1 reg read\n");
145 return -EINVAL;
146 }
147
148 curr_llist_ptr = &llist_extern[host][curr_llist_idx];
149 curr_llist_ptr->link_controller_flags = 0x11;
150 curr_llist_ptr->packet_header_count = 14;
151 curr_llist_ptr->packet_data_count = 0;
152
153 curr_llist_ptr->next_packet_pointer = NULL;
154 curr_llist_ptr->packet_data_pointer = NULL;
155 curr_llist_ptr->reserved = 0;
156
157 regacc_pkt_ptr = &curr_llist_ptr->packet_header.register_pkt;
158
159 regacc_pkt_ptr->packet_length = curr_llist_ptr->packet_header_count;
160 regacc_pkt_ptr->packet_type = 146; /* register access packet */
161 regacc_pkt_ptr->bClient_ID = 0;
162 regacc_pkt_ptr->read_write_info = 0x8001;
163 regacc_pkt_ptr->register_address = reg_addr;
164
165 /* now adjust pointers */
166 mddi_queue_forward_packets(curr_llist_idx, curr_llist_idx, wait,
167 NULL, host);
168 /* need to check if we can write the pointer or not */
169
170 up(&mddi_host_mutex);
171
172 if (wait) {
173 int wait_ret;
174
175 mddi_linked_list_notify_type *llist_notify_ptr;
176 llist_notify_ptr = &llist_extern_notify[host][curr_llist_idx];
177 wait_ret = wait_for_completion_timeout(
178 &(llist_notify_ptr->done_comp), 5 * HZ);
179
180 if (wait_ret <= 0)
181 ret = -EBUSY;
182
183 if (wait_ret < 0)
184 printk(KERN_ERR "%s: failed to wait for completion!\n",
185 __func__);
186 else if (!wait_ret)
187 printk(KERN_ERR "%s: Timed out waiting!\n", __func__);
188
189 if (!ret && (mddi_reg_read_value_ptr == reg_value_ptr) &&
190 (*reg_value_ptr == -EBUSY)) {
191 printk(KERN_ERR "%s - failed to get data from client",
192 __func__);
193 mddi_reg_read_value_ptr = NULL;
194 ret = -EBUSY;
195 }
196 }
197
198 MDDI_MSG_DEBUG("Reg Read value=0x%x\n", *reg_value_ptr);
199
200 return ret;
201} /* mddi_host_register_read */
202
203int mddi_host_register_write(uint32 reg_addr,
204 uint32 reg_val, enum mddi_data_packet_size_type packet_size,
205 boolean wait, mddi_llist_done_cb_type done_cb, mddi_host_type host) {
206 mddi_linked_list_type *curr_llist_ptr;
207 mddi_linked_list_type *curr_llist_dma_ptr;
208 mddi_register_access_packet_type *regacc_pkt_ptr;
209 uint16 curr_llist_idx;
210 int ret = 0;
211
212 if (in_interrupt())
213 MDDI_MSG_CRIT("Called from ISR context\n");
214
215 if (!mddi_host_powered) {
216 MDDI_MSG_ERR("MDDI powered down!\n");
217 mddi_init();
218 }
219
220 down(&mddi_host_mutex);
221
222 curr_llist_idx = mddi_get_next_free_llist_item(host, TRUE);
223 curr_llist_ptr = &llist_extern[host][curr_llist_idx];
224 curr_llist_dma_ptr = &llist_dma_extern[host][curr_llist_idx];
225
226 curr_llist_ptr->link_controller_flags = 1;
227 curr_llist_ptr->packet_header_count = 14;
228 curr_llist_ptr->packet_data_count = 4;
229
230 curr_llist_ptr->next_packet_pointer = NULL;
231 curr_llist_ptr->reserved = 0;
232
233 regacc_pkt_ptr = &curr_llist_ptr->packet_header.register_pkt;
234
235 regacc_pkt_ptr->packet_length = curr_llist_ptr->packet_header_count +
236 (uint16)packet_size;
237 regacc_pkt_ptr->packet_type = 146; /* register access packet */
238 regacc_pkt_ptr->bClient_ID = 0;
239 regacc_pkt_ptr->read_write_info = 0x0001;
240 regacc_pkt_ptr->register_address = reg_addr;
241 regacc_pkt_ptr->register_data_list[0] = reg_val;
242
243 MDDI_MSG_DEBUG("Reg Access write reg=0x%x, value=0x%x\n",
244 regacc_pkt_ptr->register_address,
245 regacc_pkt_ptr->register_data_list[0]);
246
247 regacc_pkt_ptr = &curr_llist_dma_ptr->packet_header.register_pkt;
248 curr_llist_ptr->packet_data_pointer =
249 (void *)(&regacc_pkt_ptr->register_data_list[0]);
250
251 /* now adjust pointers */
252 mddi_queue_forward_packets(curr_llist_idx, curr_llist_idx, wait,
253 done_cb, host);
254
255 up(&mddi_host_mutex);
256
257 if (wait) {
258 int wait_ret;
259
260 mddi_linked_list_notify_type *llist_notify_ptr;
261 llist_notify_ptr = &llist_extern_notify[host][curr_llist_idx];
262 wait_ret = wait_for_completion_timeout(
263 &(llist_notify_ptr->done_comp), 5 * HZ);
264
265 if (wait_ret <= 0)
266 ret = -EBUSY;
267
268 if (wait_ret < 0)
269 printk(KERN_ERR "%s: failed to wait for completion!\n",
270 __func__);
271 else if (!wait_ret)
272 printk(KERN_ERR "%s: Timed out waiting!\n", __func__);
273 }
274
275 return ret;
276} /* mddi_host_register_write */
277
278boolean mddi_host_register_read_int
279 (uint32 reg_addr, uint32 *reg_value_ptr, mddi_host_type host) {
280 mddi_linked_list_type *curr_llist_ptr;
281 mddi_register_access_packet_type *regacc_pkt_ptr;
282 uint16 curr_llist_idx;
283
284 if (!in_interrupt())
285 MDDI_MSG_CRIT("Called from TASK context\n");
286
287 if (!mddi_host_powered) {
288 MDDI_MSG_ERR("MDDI powered down!\n");
289 return FALSE;
290 }
291
292 if (down_trylock(&mddi_host_mutex) != 0)
293 return FALSE;
294
295 mddi_reg_read_value_ptr = reg_value_ptr;
296 curr_llist_idx = mddi_get_reg_read_llist_item(host, FALSE);
297 if (curr_llist_idx == UNASSIGNED_INDEX) {
298 up(&mddi_host_mutex);
299 return FALSE;
300 }
301
302 curr_llist_ptr = &llist_extern[host][curr_llist_idx];
303 curr_llist_ptr->link_controller_flags = 0x11;
304 curr_llist_ptr->packet_header_count = 14;
305 curr_llist_ptr->packet_data_count = 0;
306
307 curr_llist_ptr->next_packet_pointer = NULL;
308 curr_llist_ptr->packet_data_pointer = NULL;
309 curr_llist_ptr->reserved = 0;
310
311 regacc_pkt_ptr = &curr_llist_ptr->packet_header.register_pkt;
312
313 regacc_pkt_ptr->packet_length = curr_llist_ptr->packet_header_count;
314 regacc_pkt_ptr->packet_type = 146; /* register access packet */
315 regacc_pkt_ptr->bClient_ID = 0;
316 regacc_pkt_ptr->read_write_info = 0x8001;
317 regacc_pkt_ptr->register_address = reg_addr;
318
319 /* now adjust pointers */
320 mddi_queue_forward_packets(curr_llist_idx, curr_llist_idx, FALSE,
321 NULL, host);
322 /* need to check if we can write the pointer or not */
323
324 up(&mddi_host_mutex);
325
326 return TRUE;
327
328} /* mddi_host_register_read */
329
330boolean mddi_host_register_write_int
331 (uint32 reg_addr,
332 uint32 reg_val, mddi_llist_done_cb_type done_cb, mddi_host_type host) {
333 mddi_linked_list_type *curr_llist_ptr;
334 mddi_linked_list_type *curr_llist_dma_ptr;
335 mddi_register_access_packet_type *regacc_pkt_ptr;
336 uint16 curr_llist_idx;
337
338 if (!in_interrupt())
339 MDDI_MSG_CRIT("Called from TASK context\n");
340
341 if (!mddi_host_powered) {
342 MDDI_MSG_ERR("MDDI powered down!\n");
343 return FALSE;
344 }
345
346 if (down_trylock(&mddi_host_mutex) != 0)
347 return FALSE;
348
349 curr_llist_idx = mddi_get_next_free_llist_item(host, FALSE);
350 if (curr_llist_idx == UNASSIGNED_INDEX) {
351 up(&mddi_host_mutex);
352 return FALSE;
353 }
354
355 curr_llist_ptr = &llist_extern[host][curr_llist_idx];
356 curr_llist_dma_ptr = &llist_dma_extern[host][curr_llist_idx];
357
358 curr_llist_ptr->link_controller_flags = 1;
359 curr_llist_ptr->packet_header_count = 14;
360 curr_llist_ptr->packet_data_count = 4;
361
362 curr_llist_ptr->next_packet_pointer = NULL;
363 curr_llist_ptr->reserved = 0;
364
365 regacc_pkt_ptr = &curr_llist_ptr->packet_header.register_pkt;
366
367 regacc_pkt_ptr->packet_length = curr_llist_ptr->packet_header_count + 4;
368 regacc_pkt_ptr->packet_type = 146; /* register access packet */
369 regacc_pkt_ptr->bClient_ID = 0;
370 regacc_pkt_ptr->read_write_info = 0x0001;
371 regacc_pkt_ptr->register_address = reg_addr;
372 regacc_pkt_ptr->register_data_list[0] = reg_val;
373
374 regacc_pkt_ptr = &curr_llist_dma_ptr->packet_header.register_pkt;
375 curr_llist_ptr->packet_data_pointer =
376 (void *)(&(regacc_pkt_ptr->register_data_list[0]));
377
378 /* now adjust pointers */
379 mddi_queue_forward_packets(curr_llist_idx, curr_llist_idx, FALSE,
380 done_cb, host);
381 up(&mddi_host_mutex);
382
383 return TRUE;
384
385} /* mddi_host_register_write */
386
387void mddi_wait(uint16 time_ms)
388{
389 mdelay(time_ms);
390}
391
392void mddi_client_lcd_vsync_detected(boolean detected)
393{
394 if (mddi_lcd.vsync_detected)
395 (*mddi_lcd.vsync_detected) (detected);
396}
397
398/* extended version of function includes done callback */
399void mddi_window_adjust_ext(struct msm_fb_data_type *mfd,
400 uint16 x1,
401 uint16 x2,
402 uint16 y1,
403 uint16 y2, mddi_llist_done_cb_type done_cb)
404{
405#ifdef FEATURE_MDDI_HITACHI
406 if (mfd->panel.id == HITACHI)
407 mddi_hitachi_window_adjust(x1, x2, y1, y2);
408#elif defined(FEATURE_MDDI_S6D0142)
409 if (mfd->panel.id == MDDI_LCD_S6D0142)
410 mddi_s6d0142_window_adjust(x1, x2, y1, y2, done_cb);
411#else
412 /* Do nothing then... except avoid lint/compiler warnings */
413 (void)x1;
414 (void)x2;
415 (void)y1;
416 (void)y2;
417 (void)done_cb;
418#endif
419}
420
421void mddi_window_adjust(struct msm_fb_data_type *mfd,
422 uint16 x1, uint16 x2, uint16 y1, uint16 y2)
423{
424 mddi_window_adjust_ext(mfd, x1, x2, y1, y2, NULL);
425}
426
427#ifdef MDDI_HOST_WINDOW_WORKAROUND
428uint16 mddi_assign_pkt_height(uint16 pkt_width,
429 uint16 pkt_height, uint16 bpp)
430{
431 uint16 new_pkt_height;
432 uint16 problem_height = 0;
433
434 if (pkt_width <= 240) {
435 if (bpp == 16)
436 problem_height = error_vals_16bpp[pkt_width-1];
437 else if (bpp == 18)
438 problem_height = error_vals_18bpp[pkt_width-1];
439 else {
440 printk(KERN_ERR"Invalid bpp value");
441 return -EINVAL;
442 }
443 }
444 if (problem_height == pkt_height)
445 new_pkt_height = problem_height - 1;
446 else
447 new_pkt_height = pkt_height;
448
449 return new_pkt_height;
450}
451#endif
452
453#ifdef ENABLE_MDDI_MULTI_READ_WRITE
454int mddi_host_register_multiwrite(uint32 reg_addr,
455 uint32 *value_list_ptr,
456 uint32 value_count, boolean wait, mddi_llist_done_cb_type done_cb,
457 mddi_host_type host)
458{
459 mddi_linked_list_type *curr_llist_ptr;
460 mddi_linked_list_type *curr_llist_dma_ptr;
461 mddi_register_access_packet_type *regacc_pkt_ptr;
462 uint16 curr_llist_idx;
463 int ret = 0;
464
465 if (!value_list_ptr || !value_count ||
466 value_count > MDDI_HOST_MAX_CLIENT_REG_IN_SAME_ADDR) {
467 MDDI_MSG_ERR("\n Invalid value_list or value_count");
468 return -EINVAL;
469 }
470
471 if (in_interrupt())
472 MDDI_MSG_CRIT("Called from ISR context\n");
473
474 if (!mddi_host_powered) {
475 MDDI_MSG_ERR("MDDI powered down!\n");
476 mddi_init();
477 }
478
479 down(&mddi_host_mutex);
480
481 curr_llist_idx = mddi_get_next_free_llist_item(host, TRUE);
482 curr_llist_ptr = &llist_extern[host][curr_llist_idx];
483 curr_llist_dma_ptr = &llist_dma_extern[host][curr_llist_idx];
484
485 curr_llist_ptr->link_controller_flags = 1;
486 curr_llist_ptr->packet_header_count = 14;
487 curr_llist_ptr->packet_data_count =
488 (uint16)(value_count * 4);
489
490 curr_llist_ptr->next_packet_pointer = NULL;
491 curr_llist_ptr->reserved = 0;
492
493 regacc_pkt_ptr = &curr_llist_ptr->packet_header.register_pkt;
494
495 regacc_pkt_ptr->packet_length = curr_llist_ptr->packet_header_count
496 + curr_llist_ptr->packet_data_count;
497 regacc_pkt_ptr->packet_type = 146; /* register access packet */
498 regacc_pkt_ptr->bClient_ID = 0;
499 regacc_pkt_ptr->read_write_info = value_count;
500 regacc_pkt_ptr->register_address = reg_addr;
501 memcpy((void *)&regacc_pkt_ptr->register_data_list[0], value_list_ptr,
502 curr_llist_ptr->packet_data_count);
503
504 regacc_pkt_ptr = &curr_llist_dma_ptr->packet_header.register_pkt;
505 curr_llist_ptr->packet_data_pointer =
506 (void *)(&regacc_pkt_ptr->register_data_list[0]);
507 MDDI_MSG_DEBUG("MultiReg Access write reg=0x%x, value[0]=0x%x\n",
508 regacc_pkt_ptr->register_address,
509 regacc_pkt_ptr->register_data_list[0]);
510
511 /* now adjust pointers */
512 mddi_queue_forward_packets(curr_llist_idx, curr_llist_idx, wait,
513 done_cb, host);
514
515 up(&mddi_host_mutex);
516
517 if (wait) {
518 int wait_ret;
519
520 mddi_linked_list_notify_type *llist_notify_ptr;
521 llist_notify_ptr = &llist_extern_notify[host][curr_llist_idx];
522 wait_ret = wait_for_completion_timeout(
523 &(llist_notify_ptr->done_comp), 5 * HZ);
524
525 if (wait_ret <= 0)
526 ret = -EBUSY;
527
528 if (wait_ret < 0)
529 printk(KERN_ERR "%s: failed to wait for completion!\n",
530 __func__);
531 else if (!wait_ret)
532 printk(KERN_ERR "%s: Timed out waiting!\n", __func__);
533 }
534
535 return ret;
536}
537
538int mddi_host_register_multiread(uint32 reg_addr,
539 uint32 *value_list_ptr, uint32 value_count,
540 boolean wait, mddi_host_type host) {
541 mddi_linked_list_type *curr_llist_ptr;
542 mddi_register_access_packet_type *regacc_pkt_ptr;
543 uint16 curr_llist_idx;
544 int ret = 0;
545
546 if (!value_list_ptr || !value_count ||
547 value_count >= MDDI_HOST_MAX_CLIENT_REG_IN_SAME_ADDR) {
548 MDDI_MSG_ERR("\n Invalid value_list or value_count");
549 return -EINVAL;
550 }
551
552 if (in_interrupt())
553 MDDI_MSG_CRIT("Called from ISR context\n");
554
555 if (!mddi_host_powered) {
556 MDDI_MSG_ERR("MDDI powered down!\n");
557 mddi_init();
558 }
559
560 down(&mddi_host_mutex);
561
562 mddi_reg_read_value_ptr = value_list_ptr;
563 curr_llist_idx = mddi_get_reg_read_llist_item(host, TRUE);
564 if (curr_llist_idx == UNASSIGNED_INDEX) {
565 up(&mddi_host_mutex);
566
567 /* need to change this to some sort of wait */
568 MDDI_MSG_ERR("Attempting to queue up more than 1 reg read\n");
569 return -EINVAL;
570 }
571
572 curr_llist_ptr = &llist_extern[host][curr_llist_idx];
573 curr_llist_ptr->link_controller_flags = 0x11;
574 curr_llist_ptr->packet_header_count = 14;
575 curr_llist_ptr->packet_data_count = 0;
576
577 curr_llist_ptr->next_packet_pointer = NULL;
578 curr_llist_ptr->packet_data_pointer = NULL;
579 curr_llist_ptr->reserved = 0;
580
581 regacc_pkt_ptr = &curr_llist_ptr->packet_header.register_pkt;
582
583 regacc_pkt_ptr->packet_length = curr_llist_ptr->packet_header_count;
584 regacc_pkt_ptr->packet_type = 146; /* register access packet */
585 regacc_pkt_ptr->bClient_ID = 0;
586 regacc_pkt_ptr->read_write_info = 0x8000 | value_count;
587 regacc_pkt_ptr->register_address = reg_addr;
588
589 /* now adjust pointers */
590 mddi_queue_forward_packets(curr_llist_idx, curr_llist_idx, wait,
591 NULL, host);
592 /* need to check if we can write the pointer or not */
593
594 up(&mddi_host_mutex);
595
596 if (wait) {
597 int wait_ret;
598
599 mddi_linked_list_notify_type *llist_notify_ptr;
600 llist_notify_ptr = &llist_extern_notify[host][curr_llist_idx];
601 wait_ret = wait_for_completion_timeout(
602 &(llist_notify_ptr->done_comp), 5 * HZ);
603
604 if (wait_ret <= 0)
605 ret = -EBUSY;
606
607 if (wait_ret < 0)
608 printk(KERN_ERR "%s: failed to wait for completion!\n",
609 __func__);
610 else if (!wait_ret)
611 printk(KERN_ERR "%s: Timed out waiting!\n", __func__);
612
613 if (!ret && (mddi_reg_read_value_ptr == value_list_ptr) &&
614 (*value_list_ptr == -EBUSY)) {
615 printk(KERN_ERR "%s - failed to get data from client",
616 __func__);
617 mddi_reg_read_value_ptr = NULL;
618 ret = -EBUSY;
619 }
620 }
621
622 MDDI_MSG_DEBUG("MultiReg Read value[0]=0x%x\n", *value_list_ptr);
623
624 return ret;
625}
626#endif