| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("MediaTek Software") are
- * protected under relevant copyright laws. The information contained herein
- * is confidential and proprietary to MediaTek Inc. and/or its licensors.
- * Without the prior written permission of MediaTek inc. and/or its licensors,
- * any reproduction, modification, use or disclosure of MediaTek Software,
- * and information contained herein, in whole or in part, shall be strictly prohibited.
- */
- /* MediaTek Inc. (C) 2015. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
- * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
- * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
- * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
- * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * The following software/firmware and/or related documentation ("MediaTek Software")
- * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
- * applicable license agreements with MediaTek Inc.
- */
- #ifndef BUILD_LK
- #include <linux/string.h>
- #include <linux/string.h>
- #include <linux/regulator/consumer.h>
- #include <linux/device.h>
- #include <linux/platform_device.h>
- #include <linux/slab.h>
- #include <linux/fs.h>
- #include <linux/interrupt.h>
- #include <linux/io.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/spinlock.h>
- #include <linux/syscore_ops.h>
- #include <linux/timer.h>
- #include <linux/types.h>
- #include <linux/sched.h>
- #include <linux/of.h>
- #include <linux/of_device.h>
- #include <linux/regulator/consumer.h>
- #include <linux/gpio.h>
- #include <linux/pinctrl/consumer.h>
- #else
- #include <string.h>
- #endif
- #include "lcm_drv.h"
- #ifdef BUILD_LK
- #include <platform/mt_gpio.h>
- #include <platform/mt_pmic.h>
- #elif defined(BUILD_UBOOT)
- #else
- #include <mach/mt_gpio.h>
- #include <mach/mt_pm_ldo.h>
- #endif
- /* --------------------------------------------------------------------------- */
- /* Local Constants */
- /* --------------------------------------------------------------------------- */
- #define FRAME_WIDTH (2560)
- #define FRAME_HEIGHT (1600)
- /* EVB / P1 board*/
- /* GPIO42/GPIO103 vdd18_lcd(1.8V) */
- #ifdef GPIO_LCM_PWR_EN
- #define GPIO_LCD_PWR_EN GPIO_LCM_PWR_EN
- #else
- #define GPIO_LCD_PWR_EN /*GPIO42*/GPIO103
- #endif
- /* GPIO131/NULL vdd33_lcd */
- /*
- #ifdef GPIO_LCM_PWR2_EN
- #define GPIO_LCD_PWR2_EN GPIO_LCM_PWR2_EN
- #else
- #define GPIO_LCD_PWR2_EN GPIO131
- #endif
- */
- /* GPIO127/GPIO105 LCM_RST for panel */
- #ifdef GPIO_LCM_RST
- #define GPIO_LCD_RST_EN GPIO_LCM_RST
- #else
- #define GPIO_LCD_RST_EN /*GPIO127*/GPIO105
- #endif
- /* GPIO87/GPIOEXT14 DISP_PWM0 for backlight panel */
- #ifdef GPIO_LCM_BL_EN
- #define GPIO_LCD_BL_EN GPIO_LCM_BL_EN
- #else
- #define GPIO_LCD_BL_EN /*GPIO87*/GPIOEXT14
- #endif
- /* GPIOEXT24/GPIO102 led_en for panel */
- #ifdef GPIO_LCM_LED_EN
- #define GPIO_LCD_LED_EN GPIO_LCM_LED_EN
- #else
- #define GPIO_LCD_LED_EN /*GPIOEXT24*/GPIO102
- #endif
- /* --------------------------------------------------------------------------- */
- /* Local Variables */
- /* --------------------------------------------------------------------------- */
- static LCM_UTIL_FUNCS lcm_util = {
- .set_reset_pin = NULL,
- .udelay = NULL,
- .mdelay = NULL,
- };
- #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
- #define UDELAY(n) (lcm_util.udelay(n))
- #define MDELAY(n) (lcm_util.mdelay(n))
- /* --------------------------------------------------------------------------- */
- /* Local Functions */
- /* --------------------------------------------------------------------------- */
- #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update)
- #define dsi_set_cmdq(pdata, queue_size, force_update) lcm_util.dsi_set_cmdq(pdata, queue_size, force_update)
- #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd)
- #define write_regs(addr, pdata, byte_nums) lcm_util.dsi_write_regs(addr, pdata, byte_nums)
- #define read_reg(cmd) lcm_util.dsi_dcs_read_lcm_reg(cmd)
- #define read_reg_v2(cmd, buffer, buffer_size) lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size)
- #define LCM_DSI_CMD_MODE 0
- /* #define PUSH_TABLET_USING */
- #define REGFLAG_DELAY 0xFFFC
- #define REGFLAG_END_OF_TABLE 0xFFFD
- #ifdef PUSH_TABLET_USING
- struct LCM_setting_table {
- unsigned int cmd;
- unsigned char count;
- unsigned char para_list[64];
- };
- static struct LCM_setting_table lcm_initialization_setting[] = {
- {0x01, 0, {}},
- {REGFLAG_DELAY, 10, {}},
- {0x3a, 1, {0x77}},
- {0x2a, 4, {0x00,0x00,0x04,0xff}},
- {0x2b, 4, {0x00,0x00,0x06,0x3f}},
- {0x35, 1, {0x00}},
- {0x44, 2, {0x00,0x00}},
- {0x51, 1, {0xff}},
- {0x53, 1, {0x24}},
- {0x51, 1, {0xff}},
- {0x53, 1, {0x24}},
- {0x55, 1, {0x00}},
- {0x11, 0,{}},
- {REGFLAG_DELAY, 120, {}},
- {0xB0, 1, {0x04}},
- #if (LCM_DSI_CMD_MODE)
- {0xB3, 3,{0x04,0x08,0x00,0x22,0x00}},
- {0xB3, 1, {0x04}},
- #else
- {0xB3, 5,{0x14,0x08,0x00,0x22,0x00}},
- {0xB3, 1, {0x14}},
- #endif
- {0x29, 0,{}},
- {REGFLAG_DELAY, 20, {}},
- {REGFLAG_END_OF_TABLE, 0x00, {}}
- };
- static struct LCM_setting_table lcm_suspend_setting[] = {
- {0x28,0,{}},
- {REGFLAG_DELAY, 20, {}},
- {0x10,0,{}},
- {REGFLAG_DELAY, 120, {}},
- {REGFLAG_END_OF_TABLE, 0x00, {}}
- };
- static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update)
- {
- unsigned int i;
- unsigned cmd;
- for (i = 0; i < count; i++) {
- cmd = table[i].cmd;
- switch (cmd) {
- case REGFLAG_DELAY :
- if (table[i].count <= 10)
- MDELAY(table[i].count);
- else
- MDELAY(table[i].count);
- break;
- case REGFLAG_END_OF_TABLE :
- break;
- default:
- dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update);
- }
- }
- }
- #endif
- static void init_lcm_registers(void)
- {
- unsigned int data_array[16];
- #ifdef BUILD_LK
- dprintf(INFO, "%s, LK\n", __func__);
- #else
- pr_debug("%s, KE\n", __func__);
- #endif
- #ifdef PUSH_TABLET_USING
- push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
- #else
- data_array[0] = 0x00010500;
- dsi_set_cmdq(data_array, 1, 1);
- MDELAY(10);
- data_array[0] = 0x773a1500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x00053902;
- data_array[1] = 0x0400002a;
- data_array[2] = 0xff;
- dsi_set_cmdq(data_array, 3, 1);
- data_array[0] = 0x00053902;
- data_array[1] = 0x0600002b;
- data_array[2] = 0x3f;
- dsi_set_cmdq(data_array, 3, 1);
- data_array[0] = 0x00351500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x00033902;
- data_array[1] = 0x00000044;
- dsi_set_cmdq(data_array, 2, 1);
- data_array[0] = 0xff511500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x24531500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0xff511500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x24531500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x00551500;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x00110500;
- dsi_set_cmdq(data_array, 1, 1);
- MDELAY(120);
- data_array[0] = 0x04b02300;
- dsi_set_cmdq(data_array, 1, 1);
- #if (LCM_DSI_CMD_MODE)
- data_array[0] = 0x00062902;
- data_array[1] = 0x000804b3;
- data_array[2] = 0x00000022;
- dsi_set_cmdq(data_array, 3, 1);
- data_array[0] = 0x04b32300;
- dsi_set_cmdq(data_array, 1, 1);
- #else
- data_array[0] = 0x00062902;
- data_array[1] = 0x000814b3;
- data_array[2] = 0x00000022;
- dsi_set_cmdq(data_array, 3, 1);
- data_array[0] = 0x14b32300;
- dsi_set_cmdq(data_array, 1, 1);
- #endif
- data_array[0] = 0x00290500;
- dsi_set_cmdq(data_array, 1, 1);
- MDELAY(20);
- #endif
- }
- /* --------------------------------------------------------------------------- */
- /* LCM Driver Implementations */
- /* --------------------------------------------------------------------------- */
- static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
- {
- memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
- }
- #ifndef BUILD_LK
- static void lcm_request_gpio_control(void)
- {
- gpio_request(GPIO_LCD_PWR_EN, "GPIO_LCD_PWR_EN");
- pr_debug("[KE/LCM] GPIO_LCD_PWR_EN = 0x%x\n", GPIO_LCD_PWR_EN);
- gpio_request(GPIO_LCD_BL_EN, "GPIO_LCD_BL_EN");
- pr_debug("[KE/LCM] GPIO_LCD_BL_EN = 0x%x\n", GPIO_LCD_BL_EN);
- gpio_request(GPIO_LCD_RST_EN, "GPIO_LCD_RST_EN");
- pr_debug("[KE/LCM] GPIO_LCD_RST_EN = 0x%x\n", GPIO_LCD_RST_EN);
- gpio_request(GPIO_LCD_LED_EN, "GPIO_LCD_LED_EN");
- pr_debug("[KE/LCM] GPIO_LCD_LED_EN = 0x%x\n", GPIO_LCD_LED_EN);
- }
- #endif
- static void lcm_set_gpio_output(unsigned int GPIO, unsigned int output)
- {
- if (GPIO == 0xFFFFFFFF) {
- #ifdef BUILD_LK
- dprintf(INFO, "[LK/LCM] GPIO_LCD_PWR_EN = 0x%x\n", GPIO_LCD_PWR_EN);
- dprintf(INFO, "[LK/LCM] GPIO_LCD_RST_EN = 0x%x\n", GPIO_LCD_RST_EN);
- dprintf(INFO, "[LK/LCM] GPIO_LCD_BL_EN = 0x%x\n", GPIO_LCD_BL_EN);
- dprintf(INFO, "[LK/LCM] GPIO_LCM_LED_EN = 0x%x\n", GPIO_LCM_LED_EN);
- #elif (defined BUILD_UBOOT)
- #else
- #endif
- return;
- }
- #ifdef BUILD_LK
- mt_set_gpio_mode(GPIO, GPIO_MODE_00);
- mt_set_gpio_dir(GPIO, GPIO_DIR_OUT);
- mt_set_gpio_out(GPIO, (output > 0) ? GPIO_OUT_ONE : GPIO_OUT_ZERO);
- #else
- gpio_set_value(GPIO, (output > 0) ? GPIO_OUT_ONE : GPIO_OUT_ZERO);
- #endif
- }
- static void lcm_get_params(LCM_PARAMS *params)
- {
- memset(params, 0, sizeof(LCM_PARAMS));
- params->type = LCM_TYPE_DSI;
- params->width = FRAME_WIDTH;
- params->height = FRAME_HEIGHT;
- params->lcm_if = LCM_INTERFACE_DSI_DUAL;
- params->lcm_cmd_if = LCM_INTERFACE_DSI_DUAL;
- #if (LCM_DSI_CMD_MODE)
- params->dsi.mode = CMD_MODE;
- #else
- params->dsi.mode = BURST_VDO_MODE;
- #endif
- params->dsi.LANE_NUM = LCM_FOUR_LANE;
- params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
- params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST;
- params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB;
- params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888;
- params->dsi.packet_size = 256;
- params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888;
- params->dsi.vertical_sync_active = 4;
- params->dsi.vertical_backporch = 4;
- params->dsi.vertical_frontporch = 12;
- params->dsi.vertical_active_line = FRAME_HEIGHT;
- params->dsi.horizontal_sync_active = 20;
- params->dsi.horizontal_backporch = 32;
- params->dsi.horizontal_frontporch = 92;
- params->dsi.horizontal_active_pixel = FRAME_WIDTH;
- params->dsi.PLL_CLOCK = 450;
- params->dsi.ssc_disable = 1;
- params->dsi.cont_clock = 0;
- params->dsi.ufoe_enable = 1;
- params->dsi.ufoe_params.lr_mode_en = 1;
- }
- static void init_power(void)
- {
- #ifdef BUILD_LK
- dprintf(INFO, "%s, LK\n", __func__);
- lcm_set_gpio_output(GPIO_LCD_BL_EN, GPIO_OUT_ZERO);
- MDELAY(10);
- lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ZERO);
- MDELAY(10);
- lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ZERO);
- MDELAY(10);
- lcm_set_gpio_output(GPIO_LCD_LED_EN, GPIO_OUT_ZERO);
- MDELAY(10);
- /* 1.initial start */
- lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ONE);
- MDELAY(2);
- lcm_set_gpio_output(GPIO_LCD_LED_EN, GPIO_OUT_ONE);
- MDELAY(50);
- lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
- MDELAY(20);
- lcm_set_gpio_output(GPIO_LCD_BL_EN, GPIO_OUT_ONE);
- #else
- #endif
- }
- static void lcm_init(struct platform_device *pdev)
- {
- #ifdef BUILD_LK
- dprintf(INFO, "%s, LK\n", __func__);
- #else
- lcm_request_gpio_control();
- #endif
- init_lcm_registers();
- }
- static void lcm_suspend(void)
- {
- unsigned int data_array[16];
- #ifdef BUILD_LK
- dprintf(INFO, "%s, LK\n", __func__);
- #else
- pr_debug("%s, kernel", __func__);
- #endif
- #ifdef PUSH_TABLET_USING
- push_table(lcm_suspend_setting, sizeof(lcm_suspend_setting) / sizeof(struct LCM_setting_table), 1);
- #else
- data_array[0] = 0x00280500;
- dsi_set_cmdq(data_array, 1, 1);
- MDELAY(20);
- data_array[0] = 0x00100500;
- dsi_set_cmdq(data_array, 1, 1);
- MDELAY(100);
- #endif
- lcm_set_gpio_output(GPIO_LCD_LED_EN, GPIO_OUT_ZERO);
- MDELAY(20);
- lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ZERO);
- MDELAY(10);
- lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ZERO);
- MDELAY(10);
- }
- static void lcm_resume(void)
- {
- #ifdef BUILD_LK
- dprintf(INFO, "%s, LK\n", __func__);
- #else
- pr_debug("%s, kernel", __func__);
- #endif
- /* 1.initial start */
- lcm_set_gpio_output(GPIO_LCD_PWR_EN, GPIO_OUT_ONE);
- MDELAY(2);
- lcm_set_gpio_output(GPIO_LCD_LED_EN, GPIO_OUT_ONE);
- MDELAY(50);
- lcm_set_gpio_output(GPIO_LCD_RST_EN, GPIO_OUT_ONE);
- MDELAY(20);
- lcm_set_gpio_output(GPIO_LCD_BL_EN, GPIO_OUT_ONE);
- MDELAY(20);
- init_lcm_registers();
- }
- #if (LCM_DSI_CMD_MODE)
- static void lcm_update(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
- {
- unsigned int x0 = x;
- unsigned int y0 = y;
- unsigned int x1 = x0 + width - 1;
- unsigned int y1 = y0 + height - 1;
- unsigned char x0_MSB = ((x0 >> 8) & 0xFF);
- unsigned char x0_LSB = (x0 & 0xFF);
- unsigned char x1_MSB = ((x1 >> 8) & 0xFF);
- unsigned char x1_LSB = (x1 & 0xFF);
- unsigned char y0_MSB = ((y0 >> 8) & 0xFF);
- unsigned char y0_LSB = (y0 & 0xFF);
- unsigned char y1_MSB = ((y1 >> 8) & 0xFF);
- unsigned char y1_LSB = (y1 & 0xFF);
- unsigned int data_array[16];
- data_array[0] = 0x00053902;
- data_array[1] = (x1_MSB << 24) | (x0_LSB << 16) | (x0_MSB << 8) | 0x2a;
- data_array[2] = (x1_LSB);
- dsi_set_cmdq(data_array, 3, 1);
- data_array[0] = 0x00053902;
- data_array[1] = (y1_MSB << 24) | (y0_LSB << 16) | (y0_MSB << 8) | 0x2b;
- data_array[2] = (y1_LSB);
- dsi_set_cmdq(data_array, 3, 1);
- data_array[0] = 0x00290508;
- dsi_set_cmdq(data_array, 1, 1);
- data_array[0] = 0x002c3909;
- dsi_set_cmdq(data_array, 1, 0);
- }
- #endif
- LCM_DRIVER r69429_wqxga_dsi_vdo_lcm_drv = {
- .name = "r69429_wqxga_dsi_vdo",
- .set_util_funcs = lcm_set_util_funcs,
- .get_params = lcm_get_params,
- .init_power = init_power,
- .init = lcm_init,
- .suspend = lcm_suspend,
- .resume = lcm_resume,
- #if (LCM_DSI_CMD_MODE)
- .update = lcm_update,
- #endif
- };
|