mipi_dsi.c 6.33 KB
Newer Older
Tony Feng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
/*
 * Copyright (C) 2013 ROCKCHIP, Inc.
 * drivers/video/display/transmitter/mipi_dsi.c
 * author: hhb@rock-chips.com
 * create date: 2013-01-17
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */
#ifndef CONFIG_MIPI_DSI
#include <common.h>
#endif
#ifdef CONFIG_RK_3288_DSI_UBOOT
#include <asm/io.h>
#include <errno.h>
#include <malloc.h>
#include <fdtdec.h>
#include <errno.h>
#include <asm/io.h>
#include <asm/arch/rkplat.h>
#include <lcd.h>
#include "mipi_dsi.h"
#else
#include <linux/module.h>
#include <linux/init.h>
/* #include <asm/system.h> */
#include <linux/fb.h>
#include <linux/delay.h>
#include <linux/rk_fb.h>
#include <linux/rk_screen.h>
#include <linux/ktime.h>

#include "mipi_dsi.h"
#endif

#define MAX_DSI_CHIPS 5

/*
*			 Driver Version Note
*
*v1.0 : this driver is a top level architecture of mipi dsi driver;
*v1.1 : add struct mipi_dsi_screen
*v1.2 : add id argument to identify different dsi 
*v1.3 : fix send commad's methods  
*/
#define MIPI_DSI_VERSION_AND_TIME  "mipi_dsi v1.3 2014-04-17"
#ifdef CONFIG_RK_3288_DSI_UBOOT
#define	printk(x...)	printf(x)
#endif


static struct mipi_dsi_ops *dsi_ops[MAX_DSI_CHIPS] = {NULL};
//static struct mipi_dsi_ops *cur_dsi_ops;

int register_dsi_ops(unsigned int id, struct mipi_dsi_ops *ops) {

	//int i = 0;
	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	dsi_ops[id] = ops;
	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(register_dsi_ops);
#endif

int del_dsi_ops(struct mipi_dsi_ops *ops) {

	int i = 0;

	for(i = 0; i < MAX_DSI_CHIPS; i++) {
		if(dsi_ops[i] == ops) {
			dsi_ops[i] = NULL;
			break;	
		}	
	}

	if(i == MAX_DSI_CHIPS) {
		printk("dsi ops not found\n");
		return -1;
	}
	return 0;	
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(del_dsi_ops);
#endif

int dsi_probe_current_chip(unsigned int id) {
	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];
	if(!ops)
		return -EINVAL;

	id = ops->get_id(ops->dsi);

	return id;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_probe_current_chip);
#endif
int dsi_power_up(unsigned int id) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;
	if(ops->power_up)
		ops->power_up(ops->dsi);
	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_power_up);
#endif

int dsi_power_off(unsigned int id) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->power_down)
		ops->power_down(ops->dsi);

	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_power_off);
#endif
int dsi_set_regs(unsigned int id, void *array, u32 n) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_set_regs)
		ops->dsi_set_regs(ops->dsi, array, n);

	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_set_regs);
#endif
int dsi_init(unsigned int id, u32 n) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_init)
		ops->dsi_init(ops->dsi, n);

	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_init);
#endif
int dsi_enable_video_mode(unsigned int id, u32 enable) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_enable_video_mode)
		ops->dsi_enable_video_mode(ops->dsi, enable);

	return 0;

}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_enable_video_mode);
#endif
int dsi_enable_command_mode(unsigned int id, u32 enable) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_enable_command_mode)
		ops->dsi_enable_command_mode(ops->dsi, enable);

	return 0;

}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_enable_command_mode);
#endif
int dsi_enable_hs_clk(unsigned int id, u32 enable) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_enable_hs_clk)
		ops->dsi_enable_hs_clk(ops->dsi, enable);

	return 0;

}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_enable_hs_clk);
#endif
int dsi_is_active(unsigned int id) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_is_active)
		return ops->dsi_is_active(ops->dsi);
	else
		return -1;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_is_active);
#endif
int dsi_is_enable(unsigned int id, u32 enable){

    struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_is_enable)
		ops->dsi_is_enable(ops->dsi, enable);

	return 0;
	
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_is_enable);
#endif
int dsi_send_dcs_packet(unsigned int id, unsigned char *packet, u32 n) {

	struct mipi_dsi_ops *ops = NULL;

    //printk("dsi_send_dcs_packet-------id=%d\n",id);
	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_send_dcs_packet)
		ops->dsi_send_dcs_packet(ops->dsi, packet, n);
	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_send_dcs_packet);
#endif

int dsi_read_dcs_packet(unsigned int id, unsigned char *packet, u32 n) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_read_dcs_packet)
		ops->dsi_read_dcs_packet(ops->dsi, packet, n);
	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_read_dcs_packet);
#endif

int dsi_send_packet(unsigned int id, unsigned char *packet, u32 n) {

	struct mipi_dsi_ops *ops = NULL;

	if(id > (MAX_DSI_CHIPS - 1))
		return -EINVAL;

	ops = dsi_ops[id];

	if(!ops)
		return -EINVAL;

	if(ops->dsi_send_packet)
		ops->dsi_send_packet(ops->dsi, packet, n);
		
	return 0;
}
#ifdef CONFIG_MIPI_DSI
EXPORT_SYMBOL(dsi_send_packet);
#endif