// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 BayLibre, SAS
* Author: Neil Armstrong <narmstrong@baylibre.com>
*/
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regulator/consumer.h>
#include <video/mipi_display.h>
#include <drm/drm_crtc.h>
#include <drm/drm_device.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_modes.h>
#include <drm/drm_panel.h>
struct khadas_ts050_panel {
struct drm_panel base;
struct mipi_dsi_device *link;
struct regulator *supply;
struct gpio_desc *reset_gpio;
struct gpio_desc *enable_gpio;
bool prepared;
bool enabled;
};
struct khadas_ts050_panel_cmd {
u8 cmd;
u8 data;
};
/* Only the CMD1 User Command set is documented */
static const struct khadas_ts050_panel_cmd init_code[] = {
/* Select Unknown CMD Page (Undocumented) */
{0xff, 0xee},
/* Reload CMD1: Don't reload default value to register */
{0xfb, 0x01},
{0x1f, 0x45},
{0x24, 0x4f},
{0x38, 0xc8},
{0x39, 0x27},
{0x1e, 0x77},
{0x1d, 0x0f},
{0x7e, 0x71},
{0x7c, 0x03},
{0xff, 0x00},
{0xfb, 0x01},
{0x35, 0x01},
/* Select CMD2 Page0 (Undocumented) */
{0xff, 0x01},
/* Reload CMD1: Don't reload default value to register */
{0xfb, 0x01},
{0x00, 0x01},
{0x01, 0x55},
{0x02, 0x40},
{0x05, 0x40},
{0x06, 0x4a},
{0x07, 0x24},
{0x08, 0x0c},
{0x0b, 0x7d},
{0x0c, 0x7d},
{0x0e, 0xb0},
{0x0f, 0xae},
{0x11, 0x10},
{0x12, 0x10},
{0x13, 0x03},
{0x14, 0x4a},
{0x15, 0x12},
{0x16, 0x12},
{0x18, 0x00},
{0x19, 0x77},
{0x1a, 0x55},
{0x1b, 0x13},
{0x1c, 0x00},
{0x1d, 0x00},
{0x1e, 0x13},
{0x1f, 0x00},
{0x23, 0x00},
{0x24, 0x00},
{0x25, 0x00},
{0x26, 0x00},
{0x27, 0x00},
{0x28, 0x00},
{0x35, 0x00},
{0x66, 0x00},
{0x58, 0x82},
{0x59, 0x02},
{0x5a, 0x02},
{0x5b, 0x02},
{0x5c, 0x82},
{0x5d, 0x82},
{0x5e, 0x02},
{0x5f, 0x02},
{0x72, 0x31},
/* Select CMD2 Page4 (Undocumented) */
{0xff, 0x05},
/* Reload CMD1: Don't reload default value to register */
{0xfb, 0x01},
{0x00, 0x01},
{0x01, 0x0b},
{0x02, 0x0c},
{0x03, 0x09},
{0x04, 0x0a},
{0x05, 0x00},
{0x06, 0x0f},
{0x07, 0x10},
{0x08, 0x00},
{0x09, 0x00},
{0x0a, 0x00},
{0x0b, 0x00},
{0x0c, 0x00},
{0x0d, 0x13},
{0x0e, 0x15},
{0x0f, 0x17},
{0x10, 0x01},
{0x11, 0x0b},
{0x12, 0x0c},
{0x13, 0x09},
{0x14, 0x0a},
{0x15, 0x00},
{0x16, 0x0f},
{0x17, 0x10},
{0x18, 0x00},
{0x19, 0x00},
{0x1a, 0x00},
{0x1b, 0x00},
{0x1c, 0x00},
{0x1d, 0x13},
{0x1e, 0x15},
{0x1f, 0x17},
{0x20, 0x00},
{0x21, 0x03},
{0x22, 0x01},
{0x23, 0x40},
{0x24, 0x40},
{0x25, 0xed},
{0x29, 0x58},
{0x2a, 0x12},
{0x2b, 0x01},
{0x4b, 0x06},
{0x4c, 0x11},
{0x4d, 0x20},
{0x4e, 0x02},
{0x4f, 0x02},
{0x50, 0x20},
{0x51, 0x61},
{0x52, 0x01},
{0x53, 0x63},
{0x54, 0x77},
{0x55, 0xed},
{0x5b, 0x00},
{0x5c, 0x00},
{0x5d, 0x00},
{0x5e, 0x00},
{0x5f, 0x15},
{0x60, 0x75},
{0x61, 0x00},
{0x62, 0x00},
{0x63, 0x00},
{0x64, 0x00},
{0x65, 0x00},
{0x66, 0x00},
{0x67, 0x00},
{0x68, 0x04},
{0x69, 0x00},
{0x6a, 0x00},
{0x6c, 0x40},
{0x75, 0x01},
{0x76, 0x01},
{0x7a, 0x80},
{0x7b, 0xa3},
{0x7c, 0xd8},
{0x7d, 0x60},
{0x7f, 0x15},
{0x80, 0x81},
{0x83, 0x05},
{0x93, 0x08},
{0x94, 0x10},
{0x8a, 0x00},
{0x9b, 0x0f},
{0xea, 0xff},
{0xec, 0x00},
/* Select CMD2 Page0 (Undocumented) */
{0xff, 0x01},
/* Reload CMD1: Don't reload default value to register */
{0xfb, 0x01},
{0x75, 0x00},
{0x76, 0xdf},
{0x77, 0x00},
{0x78, 0xe4},
{0x79, 0x00},
{0x7a, 0xed},
{0x7b, 0x00},
{0x7c, 0xf6},
{0x7d, 0x00},
{0x7e, 0xff},
{0x7f, 0x01},
{0x80, 0x07},
{0x81, 0x01},
{0x82, 0x10},
{0x83, 0x01},
{0x84, 0x18},
{0x85, 0x01},
{0x86, 0x20},
{0x87, 0x01},
{0x88, 0x3d},
{0x89, 0x01},
{0x8a, 0x56},
{0x8b, 0x01},
{0x8c, 0x84},
{0x8d, 0x01},
{0x8e, 0xab},
{0x8f, 0x01},
{0x90, 0xec},
{0x91, 0x02},
{0x92,