Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
s5p_mfc_cmd_v5.c
Go to the documentation of this file.
1 /*
2  * linux/drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
3  *
4  * Copyright (C) 2011 Samsung Electronics Co., Ltd.
5  * http://www.samsung.com/
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  */
12 
13 #include "regs-mfc.h"
14 #include "s5p_mfc_cmd.h"
15 #include "s5p_mfc_common.h"
16 #include "s5p_mfc_debug.h"
17 
18 /* This function is used to send a command to the MFC */
20  struct s5p_mfc_cmd_args *args)
21 {
22  int cur_cmd;
23  unsigned long timeout;
24 
26  /* wait until host to risc command register becomes 'H2R_CMD_EMPTY' */
27  do {
28  if (time_after(jiffies, timeout)) {
29  mfc_err("Timeout while waiting for hardware\n");
30  return -EIO;
31  }
32  cur_cmd = mfc_read(dev, S5P_FIMV_HOST2RISC_CMD);
33  } while (cur_cmd != S5P_FIMV_H2R_CMD_EMPTY);
34  mfc_write(dev, args->arg[0], S5P_FIMV_HOST2RISC_ARG1);
35  mfc_write(dev, args->arg[1], S5P_FIMV_HOST2RISC_ARG2);
36  mfc_write(dev, args->arg[2], S5P_FIMV_HOST2RISC_ARG3);
37  mfc_write(dev, args->arg[3], S5P_FIMV_HOST2RISC_ARG4);
38  /* Issue the command */
40  return 0;
41 }
42 
43 /* Initialize the MFC */
45 {
46  struct s5p_mfc_cmd_args h2r_args;
47 
48  memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
49  h2r_args.arg[0] = dev->fw_size;
51  &h2r_args);
52 }
53 
54 /* Suspend the MFC hardware */
56 {
57  struct s5p_mfc_cmd_args h2r_args;
58 
59  memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
60  return s5p_mfc_cmd_host2risc_v5(dev, S5P_FIMV_H2R_CMD_SLEEP, &h2r_args);
61 }
62 
63 /* Wake up the MFC hardware */
65 {
66  struct s5p_mfc_cmd_args h2r_args;
67 
68  memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
70  &h2r_args);
71 }
72 
73 
75 {
76  struct s5p_mfc_dev *dev = ctx->dev;
77  struct s5p_mfc_cmd_args h2r_args;
78  int ret;
79 
80  /* Preparing decoding - getting instance number */
81  mfc_debug(2, "Getting instance number (codec: %d)\n", ctx->codec_mode);
82  dev->curr_ctx = ctx->num;
83  memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
84  switch (ctx->codec_mode) {
86  h2r_args.arg[0] = S5P_FIMV_CODEC_H264_DEC;
87  break;
89  h2r_args.arg[0] = S5P_FIMV_CODEC_VC1_DEC;
90  break;
92  h2r_args.arg[0] = S5P_FIMV_CODEC_MPEG4_DEC;
93  break;
95  h2r_args.arg[0] = S5P_FIMV_CODEC_MPEG2_DEC;
96  break;
98  h2r_args.arg[0] = S5P_FIMV_CODEC_H263_DEC;
99  break;
101  h2r_args.arg[0] = S5P_FIMV_CODEC_VC1RCV_DEC;
102  break;
104  h2r_args.arg[0] = S5P_FIMV_CODEC_H264_ENC;
105  break;
107  h2r_args.arg[0] = S5P_FIMV_CODEC_MPEG4_ENC;
108  break;
110  h2r_args.arg[0] = S5P_FIMV_CODEC_H263_ENC;
111  break;
112  default:
113  h2r_args.arg[0] = S5P_FIMV_CODEC_NONE;
114  };
115  h2r_args.arg[1] = 0; /* no crc & no pixelcache */
116  h2r_args.arg[2] = ctx->ctx.ofs;
117  h2r_args.arg[3] = ctx->ctx.size;
119  &h2r_args);
120  if (ret) {
121  mfc_err("Failed to create a new instance\n");
122  ctx->state = MFCINST_ERROR;
123  }
124  return ret;
125 }
126 
128 {
129  struct s5p_mfc_dev *dev = ctx->dev;
130  struct s5p_mfc_cmd_args h2r_args;
131  int ret;
132 
133  if (ctx->state == MFCINST_FREE) {
134  mfc_err("Instance already returned\n");
135  ctx->state = MFCINST_ERROR;
136  return -EINVAL;
137  }
138  /* Closing decoding instance */
139  mfc_debug(2, "Returning instance number %d\n", ctx->inst_no);
140  dev->curr_ctx = ctx->num;
141  memset(&h2r_args, 0, sizeof(struct s5p_mfc_cmd_args));
142  h2r_args.arg[0] = ctx->inst_no;
144  &h2r_args);
145  if (ret) {
146  mfc_err("Failed to return an instance\n");
147  ctx->state = MFCINST_ERROR;
148  return -EINVAL;
149  }
150  return 0;
151 }
152 
153 /* Initialize cmd function pointers for MFC v5 */
154 static struct s5p_mfc_hw_cmds s5p_mfc_cmds_v5 = {
155  .cmd_host2risc = s5p_mfc_cmd_host2risc_v5,
156  .sys_init_cmd = s5p_mfc_sys_init_cmd_v5,
157  .sleep_cmd = s5p_mfc_sleep_cmd_v5,
158  .wakeup_cmd = s5p_mfc_wakeup_cmd_v5,
159  .open_inst_cmd = s5p_mfc_open_inst_cmd_v5,
160  .close_inst_cmd = s5p_mfc_close_inst_cmd_v5,
161 };
162 
164 {
165  return &s5p_mfc_cmds_v5;
166 }