backlight: ldim: update usage for new spi driver [1/1]

PD#SWPL-1603

Problem:
don't support old spi driver now

Solution:
update new spi driver api for ldim driver

Verify:
txlx r311

Change-Id: I4dff13e4cab5666a30488730e27c6275b933a922
Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
This commit is contained in:
Evoke Zhang
2018-11-02 14:22:41 +08:00
committed by Dongjin Kim
parent 05151a301d
commit b592efb805
17 changed files with 506 additions and 435 deletions

View File

@@ -14707,6 +14707,10 @@ F: arch/arm/boot/dts/amlogic/partition_mbox_ab_P_32.dtsi
F: arch/arm64/boot/dts/amlogic/firmware_avb_ab.dtsi
F: arch/arm64/boot/dts/amlogic/partition_mbox_ab_P_32.dtsi
AMLOGIC BACKLIGHT LDIM DRIVER
M: Evoke Zhang <evoke.zhang@amlogic.com>
F: drivers/amlogic/media/vout/backlight/aml_ldim/ldim_spi.c
HARDKERNEL S922D odroidn2
M: Joy Cho <joy.cho@hardkernel.com>
F: arch/arm64/configs/odroidn2_defconfig

View File

@@ -818,6 +818,7 @@
0xc0 2 0x34 0xc8
0xc0 2 0x35 0xbf
0xff 0>;
init_off = <0xff 0>;
};
};

View File

@@ -37,6 +37,8 @@
serial2 = &uart_B;
serial3 = &uart_C;
serial4 = &uart_AO_B;
spi0 = &spicc0;
spi1 = &spicc1;
};
ion_dev {

View File

@@ -37,6 +37,8 @@
serial2 = &uart_B;
serial3 = &uart_C;
serial4 = &uart_AO_B;
spi0 = &spicc0;
spi1 = &spicc1;
};
ion_dev {

View File

@@ -37,6 +37,8 @@
serial2 = &uart_B;
serial3 = &uart_C;
serial4 = &uart_AO_B;
spi0 = &spicc0;
spi1 = &spicc1;
};
ion_dev {

View File

@@ -37,6 +37,8 @@
serial2 = &uart_B;
serial3 = &uart_C;
serial4 = &uart_AO_B;
spi0 = &spicc0;
spi1 = &spicc1;
};
ion_dev {

View File

@@ -37,6 +37,8 @@
serial2 = &uart_B;
serial3 = &uart_C;
serial4 = &uart_AO_B;
spi0 = &spicc0;
spi1 = &spicc1;
};
ion_dev {

View File

@@ -1,7 +1,8 @@
#
# Makefile for LDIM.
#
obj-$(CONFIG_AMLOGIC_LOCAL_DIMMING) = aml_ldim.o ldim_dev_drv.o ob3350_bl.o global_bl.o iw7027_bl.o
obj-$(CONFIG_AMLOGIC_LOCAL_DIMMING) = aml_ldim.o ldim_dev_drv.o ldim_spi.o \
ob3350_bl.o global_bl.o iw7027_bl.o
aml_ldim-objs := ldim_drv.o ldim_func.o

View File

@@ -148,10 +148,8 @@ static struct class_attribute global_class_attrs[] = {
__ATTR_NULL
};
static int global_ldim_driver_update(void)
static int global_ldim_driver_update(struct aml_ldim_driver_s *ldim_drv)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
ldim_drv->device_power_on = global_power_on;
ldim_drv->device_power_off = global_power_off;
ldim_drv->device_bri_update = global_smr;
@@ -159,7 +157,7 @@ static int global_ldim_driver_update(void)
return 0;
}
int ldim_dev_global_probe(void)
int ldim_dev_global_probe(struct aml_ldim_driver_s *ldim_drv)
{
int ret;
@@ -170,7 +168,7 @@ int ldim_dev_global_probe(void)
return -1;
}
global_ldim_driver_update();
global_ldim_driver_update(ldim_drv);
bl_global->cls.name = kzalloc(10, GFP_KERNEL);
if (bl_global->cls.name == NULL) {
@@ -189,7 +187,7 @@ int ldim_dev_global_probe(void)
return ret;
}
int ldim_dev_global_remove(void)
int ldim_dev_global_remove(struct aml_ldim_driver_s *ldim_drv)
{
kfree(bl_global);
bl_global = NULL;

View File

@@ -49,7 +49,6 @@
#define IW7027_POWER_ON 0
#define IW7027_POWER_RESET 1
static int iw7027_on_flag;
static int iw7027_spi_op_flag;
static DEFINE_MUTEX(iw7027_spi_mutex);
@@ -68,82 +67,49 @@ struct iw7027_s *bl_iw7027;
static unsigned short *test_brightness;
static unsigned char *val_brightness;
static int iw7027_wreg(struct spi_device *spi, u8 addr, u8 val)
static int iw7027_wreg(struct spi_device *spi, unsigned char addr,
unsigned char val)
{
u8 tbuf[3];
unsigned char tbuf[3];
int ret;
mutex_lock(&iw7027_spi_mutex);
if (bl_iw7027->cs_hold_delay)
udelay(bl_iw7027->cs_hold_delay);
dirspi_start(spi);
if (bl_iw7027->cs_clk_delay)
udelay(bl_iw7027->cs_clk_delay);
tbuf[0] = NORMAL_MSG | SINGLE_DATA | IW7027_DEV_ADDR;
tbuf[1] = addr & 0x7f;
tbuf[2] = val;
ret = dirspi_write(spi, tbuf, 3);
if (bl_iw7027->cs_clk_delay)
udelay(bl_iw7027->cs_clk_delay);
dirspi_stop(spi);
mutex_unlock(&iw7027_spi_mutex);
ret = ldim_spi_write(spi, tbuf, 3);
return ret;
}
static int iw7027_rreg(struct spi_device *spi, u8 addr, u8 *val)
static int iw7027_rreg(struct spi_device *spi, unsigned char addr,
unsigned char *val)
{
u8 tbuf[3], temp;
unsigned char tbuf[3], temp;
int ret;
/* page select */
temp = (addr >= 0x80) ? 0x80 : 0x0;
iw7027_wreg(spi, 0x78, temp);
mutex_lock(&iw7027_spi_mutex);
if (bl_iw7027->cs_hold_delay)
udelay(bl_iw7027->cs_hold_delay);
dirspi_start(spi);
if (bl_iw7027->cs_clk_delay)
udelay(bl_iw7027->cs_clk_delay);
tbuf[0] = NORMAL_MSG | SINGLE_DATA | IW7027_DEV_ADDR;
tbuf[1] = addr | 0x80;
tbuf[2] = 0;
ret = dirspi_write(spi, tbuf, 3);
ret = dirspi_read(spi, val, 1);
if (bl_iw7027->cs_clk_delay)
udelay(bl_iw7027->cs_clk_delay);
dirspi_stop(spi);
mutex_unlock(&iw7027_spi_mutex);
ret = ldim_spi_read(spi, tbuf, 3, val, 1);
return ret;
}
static int iw7027_wregs(struct spi_device *spi, u8 addr, u8 *val, int len)
static int iw7027_wregs(struct spi_device *spi, unsigned char addr,
unsigned char *val, int len)
{
u8 tbuf[30];
unsigned char tbuf[30];
int ret;
mutex_lock(&iw7027_spi_mutex);
if (bl_iw7027->cs_hold_delay)
udelay(bl_iw7027->cs_hold_delay);
dirspi_start(spi);
if (bl_iw7027->cs_clk_delay)
udelay(bl_iw7027->cs_clk_delay);
tbuf[0] = NORMAL_MSG | BLOCK_DATA | IW7027_DEV_ADDR;
tbuf[1] = len;
tbuf[2] = addr & 0x7f;
memcpy(&tbuf[3], val, len);
ret = dirspi_write(spi, tbuf, len+3);
if (bl_iw7027->cs_clk_delay)
udelay(bl_iw7027->cs_clk_delay);
dirspi_stop(spi);
mutex_unlock(&iw7027_spi_mutex);
ret = ldim_spi_write(spi, tbuf, (len+3));
return ret;
}
@@ -253,42 +219,25 @@ static int ldim_power_cmd_fixed_size(void)
return ret;
}
static int iw7027_power_on_init(int flag)
static int iw7027_power_on_init(void)
{
unsigned char cmd_size;
int i, ret = 0;
int ret = 0;
LDIMPR("%s: spi_op_flag=%d\n", __func__, iw7027_spi_op_flag);
if (flag == IW7027_POWER_RESET)
goto iw7027_power_reset_p;
i = 1000;
while ((iw7027_spi_op_flag) && (i > 0)) {
i--;
udelay(10);
}
if (iw7027_spi_op_flag == 1) {
LDIMERR("%s: wait spi idle state failed\n", __func__);
return 0;
}
iw7027_spi_op_flag = 1;
iw7027_power_reset_p:
cmd_size = bl_iw7027->cmd_size;
if (cmd_size < 1) {
LDIMERR("%s: cmd_size %d is invalid\n", __func__, cmd_size);
if (bl_iw7027->cmd_size < 1) {
LDIMERR("%s: cmd_size %d is invalid\n",
__func__, bl_iw7027->cmd_size);
return -1;
}
if (cmd_size == LCD_EXT_CMD_SIZE_DYNAMIC)
if (bl_iw7027->init_data == NULL) {
LDIMERR("%s: init_data is null\n", __func__);
return -1;
}
if (bl_iw7027->cmd_size == LCD_EXT_CMD_SIZE_DYNAMIC)
ret = ldim_power_cmd_dynamic_size();
else
ret = ldim_power_cmd_fixed_size();
if (flag == IW7027_POWER_RESET)
return ret;
iw7027_spi_op_flag = 0;
return ret;
}
@@ -298,6 +247,8 @@ static int iw7027_hw_init_on(void)
unsigned char reg_chk, reg_duty_chk;
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
mutex_lock(&iw7027_spi_mutex);
/* step 1: system power_on */
ldim_gpio_set(ldim_drv->ldev_conf->en_gpio,
ldim_drv->ldev_conf->en_gpio_on);
@@ -319,7 +270,7 @@ static int iw7027_hw_init_on(void)
}
/* step 4: configure initial registers */
iw7027_power_on_init(IW7027_POWER_ON);
iw7027_power_on_init();
/* step 5: supply stable vsync */
ldim_set_duty_pwm(&(ldim_drv->ldev_conf->pwm_config));
@@ -344,7 +295,7 @@ static int iw7027_hw_init_on(void)
}
LDIMPR("%s: calibration done: [%d] = %x\n", __func__, i, reg_duty_chk);
iw7027_spi_op_flag = 0;
mutex_unlock(&iw7027_spi_mutex);
return 0;
}
@@ -352,20 +303,16 @@ static int iw7027_hw_init_on(void)
static int iw7027_hw_init_off(void)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
int i = 1000;
while ((iw7027_spi_op_flag) && (i > 0)) {
i--;
udelay(10);
}
if (iw7027_spi_op_flag == 1)
LDIMERR("%s: wait spi idle state failed\n", __func__);
mutex_lock(&iw7027_spi_mutex);
ldim_gpio_set(ldim_drv->ldev_conf->en_gpio,
ldim_drv->ldev_conf->en_gpio_off);
ldim_drv->pinmux_ctrl(0);
ldim_pwm_off(&(ldim_drv->ldev_conf->pwm_config));
mutex_unlock(&iw7027_spi_mutex);
return 0;
}
@@ -378,6 +325,8 @@ static int iw7027_spi_dump_low(char *buf)
if (buf == NULL)
return len;
mutex_lock(&iw7027_spi_mutex);
len += sprintf(buf, "iw7027 reg low:\n");
for (i = 0; i <= 0x7f; i++) {
iw7027_rreg(bl_iw7027->spi, i, &val);
@@ -385,6 +334,8 @@ static int iw7027_spi_dump_low(char *buf)
}
len += sprintf(buf+len, "\n");
mutex_unlock(&iw7027_spi_mutex);
return len;
}
@@ -397,6 +348,8 @@ static int iw7027_spi_dump_high(char *buf)
if (buf == NULL)
return len;
mutex_lock(&iw7027_spi_mutex);
len += sprintf(buf, "iw7027 reg high:\n");
for (i = 0x80; i <= 0xff; i++) {
iw7027_rreg(bl_iw7027->spi, i, &val);
@@ -404,6 +357,8 @@ static int iw7027_spi_dump_high(char *buf)
}
len += sprintf(buf+len, "\n");
mutex_unlock(&iw7027_spi_mutex);
return len;
}
@@ -417,6 +372,8 @@ static int iw7027_spi_dump_dim(char *buf)
if (buf == NULL)
return len;
mutex_lock(&iw7027_spi_mutex);
len += sprintf(buf, "iw7027 reg dimming:\n");
num = ldim_drv->ldev_conf->bl_regnum;
for (i = 0x40; i <= (0x40 + (num * 2)); i++) {
@@ -425,6 +382,8 @@ static int iw7027_spi_dump_dim(char *buf)
}
len += sprintf(buf+len, "\n");
mutex_unlock(&iw7027_spi_mutex);
return len;
}
@@ -465,15 +424,8 @@ static int iw7027_smr(unsigned short *buf, unsigned char len)
LDIMERR("%s: val_brightness is null\n", __func__);
return -1;
}
if (iw7027_spi_op_flag) {
if (smr_cnt == 0) {
LDIMPR("%s: spi_op_flag=%d\n",
__func__, iw7027_spi_op_flag);
}
return 0;
}
iw7027_spi_op_flag = 1;
mutex_lock(&iw7027_spi_mutex);
mapping = &ldim_drv->ldev_conf->bl_mapping[0];
dim_max = ldim_drv->ldev_conf->dim_max;
@@ -506,7 +458,7 @@ static int iw7027_smr(unsigned short *buf, unsigned char len)
iw7027_wregs(bl_iw7027->spi, 0x40, val_brightness, (num * 2));
iw7027_spi_op_flag = 0;
mutex_unlock(&iw7027_spi_mutex);
return 0;
}
@@ -563,7 +515,6 @@ static ssize_t iw7027_show(struct class *class,
"en_off = %d\n"
"cs_hold_delay = %d\n"
"cs_clk_delay = %d\n"
"spi_op_flag = %d\n"
"dim_max = 0x%03x\n"
"dim_min = 0x%03x\n",
ldim_drv->dev_index, iw7027_on_flag,
@@ -571,48 +522,14 @@ static ssize_t iw7027_show(struct class *class,
ldim_drv->ldev_conf->en_gpio_off,
ldim_drv->ldev_conf->cs_hold_delay,
ldim_drv->ldev_conf->cs_clk_delay,
iw7027_spi_op_flag,
ldim_drv->ldev_conf->dim_max,
ldim_drv->ldev_conf->dim_min);
} else if (!strcmp(attr->attr.name, "dump_low")) {
i = 1000;
while ((iw7027_spi_op_flag) && (i > 0)) {
i--;
udelay(10);
}
if (iw7027_spi_op_flag == 0) {
iw7027_spi_op_flag = 1;
ret = iw7027_spi_dump_low(buf);
iw7027_spi_op_flag = 0;
} else {
LDIMERR("%s: wait spi idle state failed\n", __func__);
}
ret = iw7027_spi_dump_low(buf);
} else if (!strcmp(attr->attr.name, "dump_high")) {
i = 1000;
while ((iw7027_spi_op_flag) && (i > 0)) {
i--;
udelay(10);
}
if (iw7027_spi_op_flag == 0) {
iw7027_spi_op_flag = 1;
ret = iw7027_spi_dump_high(buf);
iw7027_spi_op_flag = 0;
} else {
LDIMERR("%s: wait spi idle state failed\n", __func__);
}
ret = iw7027_spi_dump_high(buf);
} else if (!strcmp(attr->attr.name, "dump_dim")) {
i = 1000;
while ((iw7027_spi_op_flag) && (i > 0)) {
i--;
udelay(10);
}
if (iw7027_spi_op_flag == 0) {
iw7027_spi_op_flag = 1;
ret = iw7027_spi_dump_dim(buf);
iw7027_spi_op_flag = 0;
} else {
LDIMERR("%s: wait spi idle state failed\n", __func__);
}
ret = iw7027_spi_dump_dim(buf);
}
return ret;
@@ -646,19 +563,23 @@ static ssize_t iw7027_store(struct class *class,
if (buf[0] == 'w') {
i = sscanf(buf, "w %x %x", &val, &val2);
if (i == 2) {
mutex_lock(&iw7027_spi_mutex);
reg_addr = (unsigned char)val;
reg_val = (unsigned char)val2;
iw7027_wreg(bl->spi, reg_addr, reg_val);
mutex_unlock(&iw7027_spi_mutex);
} else {
LDIMERR("%s: invalid args\n", __func__);
}
} else if (buf[0] == 'r') {
i = sscanf(buf, "r %x", &val);
if (i == 1) {
mutex_lock(&iw7027_spi_mutex);
reg_addr = (unsigned char)val;
iw7027_rreg(bl->spi, reg_addr, &reg_val);
pr_info("reg 0x%02x = 0x%02x\n",
reg_addr, reg_val);
mutex_unlock(&iw7027_spi_mutex);
} else {
LDIMERR("%s: invalid args\n", __func__);
}
@@ -697,57 +618,24 @@ static struct class_attribute iw7027_class_attrs[] = {
__ATTR_NULL
};
static int iw7027_ldim_driver_update(void)
static int iw7027_ldim_driver_update(struct aml_ldim_driver_s *ldim_drv)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
ldim_drv->device_power_on = iw7027_power_on;
ldim_drv->device_power_off = iw7027_power_off;
ldim_drv->device_bri_update = iw7027_smr;
return 0;
}
static int ldim_spi_dev_probe(struct spi_device *spi)
int ldim_dev_iw7027_probe(struct aml_ldim_driver_s *ldim_drv)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
int ret;
ldim_drv->spi = spi;
dev_set_drvdata(&spi->dev, ldim_drv->ldev_conf);
spi->bits_per_word = 8;
ret = spi_setup(spi);
if (ret)
LDIMERR("spi setup failed\n");
LDIMPR("%s ok\n", __func__);
return ret;
}
static int ldim_spi_dev_remove(struct spi_device *spi)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
ldim_drv->spi = NULL;
return 0;
}
static struct spi_driver ldim_spi_dev_driver = {
.probe = ldim_spi_dev_probe,
.remove = ldim_spi_dev_remove,
.driver = {
.name = "ldim_dev",
.owner = THIS_MODULE,
},
};
int ldim_dev_iw7027_probe(void)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
int ret, i;
if (ldim_drv->spi_dev == NULL) {
LDIMERR("%s: spi_dev is null\n", __func__);
return -1;
}
iw7027_on_flag = 0;
iw7027_spi_op_flag = 0;
bl_iw7027 = kzalloc(sizeof(struct iw7027_s), GFP_KERNEL);
if (bl_iw7027 == NULL) {
@@ -755,16 +643,8 @@ int ldim_dev_iw7027_probe(void)
return -1;
}
spi_register_board_info(ldim_drv->spi_dev, 1);
ret = spi_register_driver(&ldim_spi_dev_driver);
if (ret) {
LDIMERR("register ldim_dev spi driver failed\n");
kfree(bl_iw7027);
return -1;
}
bl_iw7027->test_mode = 0;
bl_iw7027->spi = ldim_drv->spi;
bl_iw7027->spi = ldim_drv->spi_dev;
bl_iw7027->cs_hold_delay = ldim_drv->ldev_conf->cs_hold_delay;
bl_iw7027->cs_clk_delay = ldim_drv->ldev_conf->cs_clk_delay;
bl_iw7027->cmd_size = ldim_drv->ldev_conf->cmd_size;
@@ -787,7 +667,7 @@ int ldim_dev_iw7027_probe(void)
test_brightness[i] = 0xfff;
}
iw7027_ldim_driver_update();
iw7027_ldim_driver_update(ldim_drv);
bl_iw7027->cls.name = kzalloc(10, GFP_KERNEL);
sprintf((char *)bl_iw7027->cls.name, "iw7027");
@@ -802,14 +682,13 @@ int ldim_dev_iw7027_probe(void)
return ret;
}
int ldim_dev_iw7027_remove(void)
int ldim_dev_iw7027_remove(struct aml_ldim_driver_s *ldim_drv)
{
kfree(val_brightness);
val_brightness = NULL;
kfree(test_brightness);
test_brightness = NULL;
spi_unregister_driver(&ldim_spi_dev_driver);
kfree(bl_iw7027);
bl_iw7027 = NULL;

View File

@@ -46,7 +46,7 @@ struct bl_gpio_s ldim_gpio[BL_GPIO_NUM_MAX] = {
{.probe_flag = 0, .register_flag = 0,},
};
static struct spi_board_info ldim_spi_dev = {
static struct spi_board_info ldim_spi_info = {
.modalias = "ldim_dev",
.mode = SPI_MODE_0,
.max_speed_hz = 1000000, /* 1MHz */
@@ -57,6 +57,7 @@ static struct spi_board_info ldim_spi_dev = {
static unsigned char *table_init_on_dft;
static unsigned char *table_init_off_dft;
static int ldim_dev_probe_flag;
struct ldim_dev_config_s ldim_dev_config = {
.type = LDIM_DEV_TYPE_NORMAL,
@@ -254,7 +255,7 @@ void ldim_set_duty_pwm(struct bl_pwm_config_s *bl_pwm)
temp = (((temp * bl_pwm->pwm_duty) + 50) / 100);
bl_pwm->pwm_level = (unsigned int)temp;
if (ldim_debug_print) {
if (ldim_debug_print == 2) {
LDIMPR(
"pwm port %d: duty=%d%%, pwm_max=%d, pwm_min=%d, pwm_level=%d\n",
bl_pwm->pwm_port, bl_pwm->pwm_duty,
@@ -310,7 +311,7 @@ static int ldim_pwm_pinmux_ctrl(int status)
if (IS_ERR(ldim_drv->pin)) {
LDIMERR("set pinmux %s error\n", ldim_pinmux_str[index]);
} else {
LDIMPR("set pinmux %s: %p\n",
LDIMPR("set pinmux %s: 0x%p\n",
ldim_pinmux_str[index], ldim_drv->pin);
}
ldim_drv->pinmux_flag = index;
@@ -347,7 +348,7 @@ static void ldim_dev_init_table_dynamic_size_print(
if (flag) {
pr_info("power on:\n");
table = econf->init_on;
max_len = econf->init_off_cnt;
max_len = econf->init_on_cnt;
} else {
pr_info("power off:\n");
table = econf->init_off;
@@ -468,148 +469,148 @@ static void ldim_dev_config_print(void)
"dev_index = %d\n",
ldim_drv->valid_flag,
ldim_drv->dev_index);
if (ldim_drv->ldev_conf) {
bl_pwm = &ldim_drv->ldev_conf->pwm_config;
pr_info("dev_name = %s\n"
"type = %d\n"
"en_gpio = %d\n"
"en_gpio_on = %d\n"
"en_gpio_off = %d\n"
"dim_min = 0x%03x\n"
"dim_max = 0x%03x\n",
ldim_drv->ldev_conf->name,
ldim_drv->ldev_conf->type,
ldim_drv->ldev_conf->en_gpio,
ldim_drv->ldev_conf->en_gpio_on,
ldim_drv->ldev_conf->en_gpio_off,
ldim_drv->ldev_conf->dim_min,
ldim_drv->ldev_conf->dim_max);
pr_info("region_num = %d\n",
ldim_drv->ldev_conf->bl_regnum);
n = ldim_drv->ldev_conf->bl_regnum;
len = (n * 4) + 50;
str = kcalloc(len, sizeof(char), GFP_KERNEL);
if (str == NULL) {
pr_info("%s: buf malloc error\n", __func__);
} else {
len = sprintf(str, "region_mapping:\n ");
for (i = 0; i < n; i++) {
len += sprintf(str+len, "%d,",
ldim_drv->ldev_conf->bl_mapping[i]);
}
pr_info("%s\n\n", str);
kfree(str);
}
if (ldim_drv->ldev_conf == NULL) {
LDIMERR("%s: device config is null\n", __func__);
return;
}
switch (ldim_drv->ldev_conf->type) {
case LDIM_DEV_TYPE_SPI:
pr_info("spi_modalias = %s\n"
"spi_mode = %d\n"
"spi_max_speed_hz = %d\n"
"spi_bus_num = %d\n"
"spi_chip_select = %d\n"
"cs_hold_delay = %d\n"
"cs_clk_delay = %d\n"
"lamp_err_gpio = %d\n"
"fault_check = %d\n"
"write_check = %d\n\n",
ldim_drv->spi_dev->modalias,
ldim_drv->spi_dev->mode,
ldim_drv->spi_dev->max_speed_hz,
ldim_drv->spi_dev->bus_num,
ldim_drv->spi_dev->chip_select,
ldim_drv->ldev_conf->cs_hold_delay,
ldim_drv->ldev_conf->cs_clk_delay,
ldim_drv->ldev_conf->lamp_err_gpio,
ldim_drv->ldev_conf->fault_check,
ldim_drv->ldev_conf->write_check);
bl_pwm = &ldim_drv->ldev_conf->pwm_config;
pr_info("dev_name = %s\n"
"type = %d\n"
"en_gpio = %d\n"
"en_gpio_on = %d\n"
"en_gpio_off = %d\n"
"dim_min = 0x%03x\n"
"dim_max = 0x%03x\n"
"region_num = %d\n",
ldim_drv->ldev_conf->name,
ldim_drv->ldev_conf->type,
ldim_drv->ldev_conf->en_gpio,
ldim_drv->ldev_conf->en_gpio_on,
ldim_drv->ldev_conf->en_gpio_off,
ldim_drv->ldev_conf->dim_min,
ldim_drv->ldev_conf->dim_max,
ldim_drv->ldev_conf->bl_regnum);
n = ldim_drv->ldev_conf->bl_regnum;
len = (n * 4) + 50;
str = kcalloc(len, sizeof(char), GFP_KERNEL);
if (str == NULL) {
pr_info("%s: buf malloc error\n", __func__);
} else {
len = sprintf(str, "region_mapping:\n ");
for (i = 0; i < n; i++) {
len += sprintf(str+len, "%d,",
ldim_drv->ldev_conf->bl_mapping[i]);
}
pr_info("%s\n\n", str);
kfree(str);
}
switch (ldim_drv->ldev_conf->type) {
case LDIM_DEV_TYPE_SPI:
pr_info("spi_pointer = 0x%p\n"
"spi_modalias = %s\n"
"spi_mode = %d\n"
"spi_max_speed_hz = %d\n"
"spi_bus_num = %d\n"
"spi_chip_select = %d\n"
"cs_hold_delay = %d\n"
"cs_clk_delay = %d\n"
"lamp_err_gpio = %d\n"
"fault_check = %d\n"
"write_check = %d\n\n",
ldim_drv->spi_dev,
ldim_drv->spi_info->modalias,
ldim_drv->spi_info->mode,
ldim_drv->spi_info->max_speed_hz,
ldim_drv->spi_info->bus_num,
ldim_drv->spi_info->chip_select,
ldim_drv->ldev_conf->cs_hold_delay,
ldim_drv->ldev_conf->cs_clk_delay,
ldim_drv->ldev_conf->lamp_err_gpio,
ldim_drv->ldev_conf->fault_check,
ldim_drv->ldev_conf->write_check);
break;
case LDIM_DEV_TYPE_I2C:
break;
case LDIM_DEV_TYPE_NORMAL:
default:
break;
}
if (bl_pwm->pwm_port < BL_PWM_MAX) {
pr_info("pwm_port: %d\n"
"pwm_pol: %d\n"
"pwm_freq: %d\n"
"pwm_cnt: %d\n"
"pwm_level: %d\n"
"pwm_duty: %d%%\n",
bl_pwm->pwm_port, bl_pwm->pwm_method,
bl_pwm->pwm_freq, bl_pwm->pwm_cnt,
bl_pwm->pwm_level, bl_pwm->pwm_duty);
switch (bl_pwm->pwm_port) {
case BL_PWM_A:
case BL_PWM_B:
case BL_PWM_C:
case BL_PWM_D:
case BL_PWM_E:
case BL_PWM_F:
if (IS_ERR_OR_NULL(bl_pwm->pwm_data.pwm)) {
pr_info("pwm invalid\n");
break;
}
pr_info("pwm_pointer: %p\n",
bl_pwm->pwm_data.pwm);
pwm_get_state(bl_pwm->pwm_data.pwm, &pstate);
pr_info("pwm state:\n"
" period: %d\n"
" duty_cycle: %d\n"
" polarity: %d\n"
" enabled: %d\n",
pstate.period, pstate.duty_cycle,
pstate.polarity, pstate.enabled);
value = bl_cbus_read(
bl_drv->data->pwm_reg[bl_pwm->pwm_port]);
pr_info("pwm_reg: 0x%08x\n", value);
break;
case LDIM_DEV_TYPE_I2C:
break;
case LDIM_DEV_TYPE_NORMAL:
case BL_PWM_VS:
pr_info("pwm_reg0: 0x%08x\n"
"pwm_reg1: 0x%08x\n"
"pwm_reg2: 0x%08x\n"
"pwm_reg3: 0x%08x\n",
bl_vcbus_read(VPU_VPU_PWM_V0),
bl_vcbus_read(VPU_VPU_PWM_V1),
bl_vcbus_read(VPU_VPU_PWM_V2),
bl_vcbus_read(VPU_VPU_PWM_V3));
break;
default:
break;
}
if (bl_pwm->pwm_port < BL_PWM_MAX) {
pr_info("pwm_port: %d\n"
"pwm_pol: %d\n"
"pwm_freq: %d\n"
"pwm_cnt: %d\n"
"pwm_level: %d\n"
"pwm_duty: %d%%\n",
bl_pwm->pwm_port, bl_pwm->pwm_method,
bl_pwm->pwm_freq, bl_pwm->pwm_cnt,
bl_pwm->pwm_level, bl_pwm->pwm_duty);
switch (bl_pwm->pwm_port) {
case BL_PWM_A:
case BL_PWM_B:
case BL_PWM_C:
case BL_PWM_D:
case BL_PWM_E:
case BL_PWM_F:
if (IS_ERR_OR_NULL(bl_pwm->pwm_data.pwm)) {
pr_info("pwm invalid\n");
break;
}
pr_info("pwm_pointer: %p\n",
bl_pwm->pwm_data.pwm);
pwm_get_state(bl_pwm->pwm_data.pwm, &pstate);
pr_info("pwm state:\n"
" period: %d\n"
" duty_cycle: %d\n"
" polarity: %d\n"
" enabled: %d\n",
pstate.period, pstate.duty_cycle,
pstate.polarity, pstate.enabled);
value = bl_cbus_read(bl_drv->data->pwm_reg[
bl_pwm->pwm_port]);
pr_info("pwm_reg: 0x%08x\n",
value);
break;
case BL_PWM_VS:
pr_info("pwm_reg0: 0x%08x\n"
"pwm_reg1: 0x%08x\n"
"pwm_reg2: 0x%08x\n"
"pwm_reg3: 0x%08x\n",
bl_vcbus_read(VPU_VPU_PWM_V0),
bl_vcbus_read(VPU_VPU_PWM_V1),
bl_vcbus_read(VPU_VPU_PWM_V2),
bl_vcbus_read(VPU_VPU_PWM_V3));
break;
default:
break;
}
}
pr_info("pinmux_flag: %d\n"
"pinmux_pointer: 0x%p\n\n",
ldim_drv->pinmux_flag,
ldim_drv->pin);
}
pr_info("pinmux_flag: %d\n"
"pinmux_pointer: 0x%p\n\n",
ldim_drv->pinmux_flag,
ldim_drv->pin);
if (ldim_drv->ldev_conf->cmd_size > 0) {
pr_info("table_loaded: %d\n"
"cmd_size: %d\n"
"init_on_cnt: %d\n"
"init_off_cnt: %d\n",
ldim_drv->ldev_conf->init_loaded,
ldim_drv->ldev_conf->cmd_size,
ldim_drv->ldev_conf->init_on_cnt,
ldim_drv->ldev_conf->init_off_cnt);
if (ldim_drv->ldev_conf->cmd_size ==
LCD_EXT_CMD_SIZE_DYNAMIC) {
ldim_dev_init_table_dynamic_size_print(
ldim_drv->ldev_conf, 1);
ldim_dev_init_table_dynamic_size_print(
ldim_drv->ldev_conf, 0);
} else {
ldim_dev_init_table_fixed_size_print(
ldim_drv->ldev_conf, 1);
ldim_dev_init_table_fixed_size_print(
ldim_drv->ldev_conf, 0);
}
if (ldim_drv->ldev_conf->cmd_size > 0) {
pr_info("table_loaded: %d\n"
"cmd_size: %d\n"
"init_on_cnt: %d\n"
"init_off_cnt: %d\n",
ldim_drv->ldev_conf->init_loaded,
ldim_drv->ldev_conf->cmd_size,
ldim_drv->ldev_conf->init_on_cnt,
ldim_drv->ldev_conf->init_off_cnt);
if (ldim_drv->ldev_conf->cmd_size == LCD_EXT_CMD_SIZE_DYNAMIC) {
ldim_dev_init_table_dynamic_size_print(
ldim_drv->ldev_conf, 1);
ldim_dev_init_table_dynamic_size_print(
ldim_drv->ldev_conf, 0);
} else {
ldim_dev_init_table_fixed_size_print(
ldim_drv->ldev_conf, 1);
ldim_dev_init_table_fixed_size_print(
ldim_drv->ldev_conf, 0);
}
} else {
pr_info("device config is null\n");
}
}
@@ -1008,16 +1009,16 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index)
switch (ldim_dev_config.type) {
case LDIM_DEV_TYPE_SPI:
/* get spi config */
ldim_drv->spi_dev = &ldim_spi_dev;
ldim_drv->spi_info = &ldim_spi_info;
ret = of_property_read_u32(child, "spi_bus_num", &val);
if (ret) {
LDIMERR("failed to get spi_bus_num\n");
} else {
ldim_spi_dev.bus_num = val;
ldim_spi_info.bus_num = val;
if (ldim_debug_print) {
LDIMPR("spi bus_num: %d\n",
ldim_spi_dev.bus_num);
ldim_spi_info.bus_num);
}
}
@@ -1025,10 +1026,10 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index)
if (ret) {
LDIMERR("failed to get spi_chip_select\n");
} else {
ldim_spi_dev.chip_select = val;
ldim_spi_info.chip_select = val;
if (ldim_debug_print) {
LDIMPR("spi chip_select: %d\n",
ldim_spi_dev.chip_select);
ldim_spi_info.chip_select);
}
}
@@ -1036,10 +1037,10 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index)
if (ret) {
LDIMERR("failed to get spi_chip_select\n");
} else {
ldim_spi_dev.max_speed_hz = val;
ldim_spi_info.max_speed_hz = val;
if (ldim_debug_print) {
LDIMPR("spi max_speed_hz: %d\n",
ldim_spi_dev.max_speed_hz);
ldim_spi_info.max_speed_hz);
}
}
@@ -1047,9 +1048,9 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index)
if (ret) {
LDIMERR("failed to get spi_mode\n");
} else {
ldim_spi_dev.mode = val;
ldim_spi_info.mode = val;
if (ldim_debug_print)
LDIMPR("spi mode: %d\n", ldim_spi_dev.mode);
LDIMPR("spi mode: %d\n", ldim_spi_info.mode);
}
ret = of_property_read_u32_array(child, "spi_cs_delay",
@@ -1108,14 +1109,14 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index)
child, &ldim_dev_config, 1);
if (ret)
break;
ret = ldim_dev_init_table_dynamic_size_load_dts(
ldim_dev_init_table_dynamic_size_load_dts(
child, &ldim_dev_config, 0);
} else {
ret = ldim_dev_init_table_fixed_size_load_dts(
child, &ldim_dev_config, 1);
if (ret)
break;
ret = ldim_dev_init_table_fixed_size_load_dts(
ldim_dev_init_table_fixed_size_load_dts(
child, &ldim_dev_config, 0);
}
if (ret == 0)
@@ -1147,60 +1148,81 @@ ldim_get_config_err:
return -1;
}
static int ldim_dev_add_driver(struct ldim_dev_config_s *ldev_conf, int index)
static int ldim_dev_add_driver(struct aml_ldim_driver_s *ldim_drv)
{
int ret = 0;
struct ldim_dev_config_s *ldev_conf = ldim_drv->ldev_conf;
int index = ldim_drv->dev_index;
int ret = -1;
if (strcmp(ldev_conf->name, "iw7027") == 0) {
ret = ldim_dev_iw7027_probe();
goto ldim_dev_add_driver_next;
} else if (strcmp(ldev_conf->name, "ob3350") == 0) {
ret = ldim_dev_ob3350_probe();
goto ldim_dev_add_driver_next;
} else if (strcmp(ldev_conf->name, "global") == 0) {
ret = ldim_dev_global_probe();
goto ldim_dev_add_driver_next;
} else {
LDIMERR("invalid device name: %s\n", ldev_conf->name);
ret = -1;
switch (ldim_dev_config.type) {
case LDIM_DEV_TYPE_SPI:
ret = ldim_spi_driver_add(ldim_drv);
break;
case LDIM_DEV_TYPE_I2C:
break;
case LDIM_DEV_TYPE_NORMAL:
default:
break;
}
if (ret)
return ret;
ret = -1;
if (strcmp(ldev_conf->name, "iw7027") == 0)
ret = ldim_dev_iw7027_probe(ldim_drv);
else if (strcmp(ldev_conf->name, "ob3350") == 0)
ret = ldim_dev_ob3350_probe(ldim_drv);
else if (strcmp(ldev_conf->name, "global") == 0)
ret = ldim_dev_global_probe(ldim_drv);
else
LDIMERR("invalid device name: %s\n", ldev_conf->name);
ldim_dev_add_driver_next:
if (ret) {
LDIMERR("add device driver failed %s(%d)\n",
LDIMERR("add device driver failed: %s(%d)\n",
ldev_conf->name, index);
} else {
LDIMPR("add device driver %s(%d)\n", ldev_conf->name, index);
ldim_dev_probe_flag = 1;
LDIMPR("add device driver: %s(%d)\n", ldev_conf->name, index);
}
return ret;
}
static int ldim_dev_remove_driver(struct ldim_dev_config_s *ldev_conf,
int index)
static int ldim_dev_remove_driver(struct aml_ldim_driver_s *ldim_drv)
{
int ret = 0;
struct ldim_dev_config_s *ldev_conf = ldim_drv->ldev_conf;
int index = ldim_drv->dev_index;
int ret = -1;
if (strcmp(ldev_conf->name, "iw7027") == 0) {
ret = ldim_dev_iw7027_remove();
goto ldim_dev_remove_driver_next;
} else if (strcmp(ldev_conf->name, "ob3350") == 0) {
ret = ldim_dev_ob3350_remove();
goto ldim_dev_remove_driver_next;
} else if (strcmp(ldev_conf->name, "global") == 0) {
ret = ldim_dev_global_remove();
goto ldim_dev_remove_driver_next;
} else {
LDIMERR("invalid device name: %s\n", ldev_conf->name);
ret = -1;
if (ldim_dev_probe_flag) {
if (strcmp(ldev_conf->name, "iw7027") == 0)
ret = ldim_dev_iw7027_remove(ldim_drv);
else if (strcmp(ldev_conf->name, "ob3350") == 0)
ret = ldim_dev_ob3350_remove(ldim_drv);
else if (strcmp(ldev_conf->name, "global") == 0)
ret = ldim_dev_global_remove(ldim_drv);
else
LDIMERR("invalid device name: %s\n", ldev_conf->name);
if (ret) {
LDIMERR("remove device driver failed: %s(%d)\n",
ldev_conf->name, index);
} else {
ldim_dev_probe_flag = 0;
LDIMPR("remove device driver: %s(%d)\n",
ldev_conf->name, index);
}
}
ldim_dev_remove_driver_next:
if (ret) {
LDIMERR("remove device driver failed %s(%d)\n",
ldev_conf->name, index);
} else {
LDIMPR("remove device driver %s(%d)\n", ldev_conf->name, index);
switch (ldim_dev_config.type) {
case LDIM_DEV_TYPE_SPI:
ldim_spi_driver_remove(ldim_drv);
break;
case LDIM_DEV_TYPE_I2C:
break;
case LDIM_DEV_TYPE_NORMAL:
default:
break;
}
return ret;
@@ -1209,8 +1231,8 @@ ldim_dev_remove_driver_next:
static int ldim_dev_probe(struct platform_device *pdev)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
int ret = 0;
ldim_dev_probe_flag = 0;
if (ldim_drv->dev_index != 0xff) {
/* get configs */
ldim_drv->dev = &pdev->dev;
@@ -1221,27 +1243,25 @@ static int ldim_dev_probe(struct platform_device *pdev)
ldim_dev_get_config_from_dts(pdev->dev.of_node,
ldim_drv->dev_index);
ldim_dev_add_driver(ldim_drv->ldev_conf, ldim_drv->dev_index);
ldim_dev_add_driver(ldim_drv);
}
/* init ldim function */
if (ldim_drv->valid_flag)
ldim_drv->init();
LDIMPR("%s OK\n", __func__);
return ret;
return 0;
}
static int __exit ldim_dev_remove(struct platform_device *pdev)
{
int ret = 0;
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
if (ldim_drv->dev_index != 0xff) {
ldim_dev_remove_driver(ldim_drv->ldev_conf,
ldim_drv->dev_index);
}
if (ldim_drv->dev_index != 0xff)
ldim_dev_remove_driver(ldim_drv);
LDIMPR("%s OK\n", __func__);
return ret;
return 0;
}
#ifdef CONFIG_OF

View File

@@ -17,6 +17,16 @@
#ifndef __LDIM_DEV_DRV_H
#define __LDIM_DEV_DRV_H
#include <linux/spi/spi.h>
#include <linux/amlogic/media/vout/lcd/aml_ldim.h>
/* ldim spi api*/
extern int ldim_spi_write(struct spi_device *spi, unsigned char *tbuf,
int wlen);
extern int ldim_spi_read(struct spi_device *spi, unsigned char *tbuf, int wlen,
unsigned char *rbuf, int rlen);
extern int ldim_spi_driver_add(struct aml_ldim_driver_s *ldim_drv);
extern int ldim_spi_driver_remove(struct aml_ldim_driver_s *ldim_drv);
/* ldim global api */
extern void ldim_gpio_set(int index, int value);
@@ -25,14 +35,14 @@ extern void ldim_set_duty_pwm(struct bl_pwm_config_s *ld_pwm);
extern void ldim_pwm_off(struct bl_pwm_config_s *ld_pwm);
/* ldim dev api */
extern int ldim_dev_iw7027_probe(void);
extern int ldim_dev_iw7027_remove(void);
extern int ldim_dev_iw7027_probe(struct aml_ldim_driver_s *ldim_drv);
extern int ldim_dev_iw7027_remove(struct aml_ldim_driver_s *ldim_drv);
extern int ldim_dev_ob3350_probe(void);
extern int ldim_dev_ob3350_remove(void);
extern int ldim_dev_ob3350_probe(struct aml_ldim_driver_s *ldim_drv);
extern int ldim_dev_ob3350_remove(struct aml_ldim_driver_s *ldim_drv);
extern int ldim_dev_global_probe(void);
extern int ldim_dev_global_remove(void);
extern int ldim_dev_global_probe(struct aml_ldim_driver_s *ldim_drv);
extern int ldim_dev_global_remove(struct aml_ldim_driver_s *ldim_drv);
#endif /* __LDIM_DEV_DRV_H */

View File

@@ -59,7 +59,7 @@ const char ldim_dev_id[] = "ldim-dev";
unsigned char ldim_debug_print;
struct ldim_dev_s {
struct aml_ldim_func_s *ldim_func;
struct ldim_operate_func_s *ldim_op_func;
struct ldim_param_s *ldim_db_para;
struct cdev cdev;
@@ -98,6 +98,7 @@ static struct work_struct ldim_on_vs_work;
static struct work_struct ldim_off_vs_work;
static unsigned int ldim_irq_cnt;
static unsigned int brightness_vs_cnt;
/*BL_matrix remap curve*/
static unsigned int bl_remap_curve[16] = {
@@ -331,12 +332,12 @@ static void ldim_stts_initial(unsigned int pic_h, unsigned int pic_v,
resolution = (((pic_h - 1) & 0xffff) << 16) | ((pic_v - 1) & 0xffff);
/*Wr_reg(VDIN0_HIST_CTRL, 0x10d);*/
if (ldim_dev.ldim_func == NULL) {
LDIMERR("%s: invalid ldim_func\n", __func__);
if (ldim_dev.ldim_op_func == NULL) {
LDIMERR("%s: invalid ldim_op_func\n", __func__);
return;
}
if (ldim_dev.ldim_func->stts_init)
ldim_dev.ldim_func->stts_init(resolution);
if (ldim_dev.ldim_op_func->stts_init)
ldim_dev.ldim_op_func->stts_init(resolution);
resolution_region = 0;
@@ -586,12 +587,12 @@ static void LDIM_Initial(unsigned int pic_h, unsigned int pic_v,
if (LDIM_DATA_FROM_DB)
ldim_db_load_update(&nPRM, ldim_dev.ldim_db_para);
if (ldim_dev.ldim_func == NULL) {
LDIMERR("%s: invalid ldim_func\n", __func__);
if (ldim_dev.ldim_op_func == NULL) {
LDIMERR("%s: invalid ldim_op_func\n", __func__);
return;
}
if (ldim_dev.ldim_func->ldim_init)
ldim_dev.ldim_func->ldim_init(ldim_bl_en, ldim_hvcnt_bypass);
if (ldim_dev.ldim_op_func->ldim_init)
ldim_dev.ldim_op_func->ldim_init(ldim_bl_en, ldim_hvcnt_bypass);
}
static void ldim_update_matrix(unsigned int mode)
@@ -682,13 +683,13 @@ static void ldim_update_txlx(void)
static void ldim_update_setting(void)
{
if (ldim_dev.ldim_func == NULL) {
if (ldim_debug_print)
LDIMERR("%s: invalid ldim_func\n", __func__);
if (ldim_dev.ldim_op_func == NULL) {
if (brightness_vs_cnt == 0)
LDIMERR("%s: invalid ldim_op_func\n", __func__);
return;
}
if (ldim_dev.ldim_func->update_setting)
ldim_dev.ldim_func->update_setting();
if (ldim_dev.ldim_op_func->update_setting)
ldim_dev.ldim_op_func->update_setting();
}
static irqreturn_t ldim_vsync_isr(int irq, void *dev_id)
@@ -700,6 +701,9 @@ static irqreturn_t ldim_vsync_isr(int irq, void *dev_id)
spin_lock_irqsave(&ldim_isr_lock, flags);
if (brightness_vs_cnt++ >= 30) /* for debug print */
brightness_vs_cnt = 0;
if (ldim_func_en) {
if (ldim_avg_update_en)
ldim_update_setting();
@@ -722,7 +726,6 @@ static irqreturn_t ldim_vsync_isr(int irq, void *dev_id)
return IRQ_HANDLED;
}
static int brightness_vs_cnt;
static void ldim_on_vs_brightness(void)
{
unsigned int size;
@@ -731,9 +734,6 @@ static void ldim_on_vs_brightness(void)
if (ldim_on_flag == 0)
return;
if (brightness_vs_cnt++ >= 30)
brightness_vs_cnt = 0;
if (ldim_func_bypass)
return;
@@ -787,9 +787,6 @@ static void ldim_off_vs_brightness(void)
if (ldim_on_flag == 0)
return;
if (brightness_vs_cnt++ >= 30)
brightness_vs_cnt = 0;
size = ldim_blk_row * ldim_blk_col;
if (ldim_level_update) {
@@ -1768,6 +1765,8 @@ static struct aml_ldim_driver_s ldim_driver = {
.device_power_off = NULL,
.device_bri_update = NULL,
.device_bri_check = NULL,
.spi_dev = NULL,
.spi_info = NULL,
};
struct aml_ldim_driver_s *aml_ldim_get_driver(void)
@@ -3191,13 +3190,13 @@ ldim_malloc_err0:
return -1;
}
static struct aml_ldim_func_s ldim_func_txlx = {
static struct ldim_operate_func_s ldim_op_func_txlx = {
.update_setting = ldim_update_txlx,
.stts_init = ldim_stts_initial_txlx,
.ldim_init = ldim_initial_txlx,
};
static struct aml_ldim_func_s ldim_func_tl1 = {
static struct ldim_operate_func_s ldim_op_func_tl1 = {
.update_setting = NULL,
.stts_init = NULL,
.ldim_init = NULL,
@@ -3211,6 +3210,8 @@ int aml_ldim_probe(struct platform_device *pdev)
struct ldim_dev_s *devp = &ldim_dev;
struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
memset(devp, 0, (sizeof(struct ldim_dev_s)));
#ifdef LDIM_DEBUG_INFO
ldim_debug_print = 1;
#endif
@@ -3236,16 +3237,16 @@ int aml_ldim_probe(struct platform_device *pdev)
/* db para */
LDIM_DATA_FROM_DB = 0;
devp->ldim_db_para = NULL;
/* ldim_func */
/* ldim_op_func */
switch (bl_drv->data->chip_type) {
case BL_CHIP_TL1:
devp->ldim_func = &ldim_func_tl1;
devp->ldim_op_func = &ldim_op_func_tl1;
break;
case BL_CHIP_TXLX:
devp->ldim_func = &ldim_func_txlx;
devp->ldim_op_func = &ldim_op_func_txlx;
break;
default:
devp->ldim_func = NULL;
devp->ldim_op_func = NULL;
break;
}
@@ -3255,8 +3256,6 @@ int aml_ldim_probe(struct platform_device *pdev)
goto err;
}
memset(devp, 0, (sizeof(struct ldim_dev_s)));
ret = alloc_chrdev_region(&devp->aml_ldim_devno, 0, 1,
AML_LDIM_DEVICE_NAME);
if (ret < 0) {

View File

@@ -23,7 +23,8 @@
/*20180725: new pwm control flow support */
/*20180730: algorithm clear up */
/*20180820: pq tooling support, espically optimize some alg parameters */
#define LDIM_DRV_VER "20180820"
/*20181101: fix ldim_op_func null mistake, add new spi api support */
#define LDIM_DRV_VER "20181101"
extern unsigned char ldim_debug_print;
@@ -36,7 +37,7 @@ extern int LD_remap_lut[16][32];
/*========================================*/
struct aml_ldim_func_s {
struct ldim_operate_func_s {
void (*update_setting)(void);
void (*stts_init)(unsigned int resolution);
void (*ldim_init)(unsigned int bl_en, unsigned int hvcnt_bypass);

View File

@@ -0,0 +1,155 @@
/*
* drivers/amlogic/media/vout/backlight/aml_ldim/ldim_spi.c
*
* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/device.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/of_address.h>
#include <linux/amlogic/media/vout/lcd/aml_ldim.h>
#include "ldim_drv.h"
#include "ldim_dev_drv.h"
static unsigned int cs_hold_delay;
static unsigned int cs_clk_delay;
int ldim_spi_write(struct spi_device *spi, unsigned char *tbuf, int tlen)
{
struct spi_transfer xfer;
struct spi_message msg;
int ret;
if (cs_hold_delay)
udelay(cs_hold_delay);
spi_message_init(&msg);
memset(&xfer, 0, sizeof(xfer));
xfer.tx_buf = (void *)tbuf;
xfer.rx_buf = NULL;
xfer.len = tlen;
spi_message_add_tail(&xfer, &msg);
ret = spi_sync(spi, &msg);
return ret;
}
int ldim_spi_read(struct spi_device *spi, unsigned char *tbuf, int tlen,
unsigned char *rbuf, int rlen)
{
struct spi_transfer xfer[2];
struct spi_message msg;
int ret;
if (cs_hold_delay)
udelay(cs_hold_delay);
spi_message_init(&msg);
memset(&xfer, 0, sizeof(xfer));
xfer[0].tx_buf = (void *)tbuf;
xfer[0].rx_buf = NULL;
xfer[0].len = tlen;
spi_message_add_tail(&xfer[0], &msg);
xfer[1].tx_buf = NULL;
xfer[1].rx_buf = (void *)rbuf;
xfer[1].len = rlen;
spi_message_add_tail(&xfer[1], &msg);
ret = spi_sync(spi, &msg);
return ret;
}
static int ldim_spi_dev_probe(struct spi_device *spi)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
int ret;
if (ldim_debug_print)
LDIMPR("%s\n", __func__);
ldim_drv->spi_dev = spi;
dev_set_drvdata(&spi->dev, ldim_drv->ldev_conf);
spi->bits_per_word = 8;
cs_hold_delay = ldim_drv->ldev_conf->cs_hold_delay;
cs_clk_delay = ldim_drv->ldev_conf->cs_clk_delay;
ret = spi_setup(spi);
if (ret)
LDIMERR("spi setup failed\n");
return ret;
}
static int ldim_spi_dev_remove(struct spi_device *spi)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
if (ldim_debug_print)
LDIMPR("%s\n", __func__);
ldim_drv->spi_dev = NULL;
return 0;
}
static struct spi_driver ldim_spi_dev_driver = {
.probe = ldim_spi_dev_probe,
.remove = ldim_spi_dev_remove,
.driver = {
.name = "ldim_dev",
.owner = THIS_MODULE,
},
};
int ldim_spi_driver_add(struct aml_ldim_driver_s *ldim_drv)
{
int ret;
if (ldim_drv->spi_info == NULL) {
LDIMERR("%s: spi_info is null\n", __func__);
return -1;
}
spi_register_board_info(ldim_drv->spi_info, 1);
ret = spi_register_driver(&ldim_spi_dev_driver);
if (ret) {
LDIMERR("%s failed\n", __func__);
return -1;
}
if (ldim_drv->spi_dev == NULL) {
LDIMERR("%s failed\n", __func__);
return -1;
}
LDIMPR("%s ok\n", __func__);
return 0;
}
int ldim_spi_driver_remove(struct aml_ldim_driver_s *ldim_drv)
{
if (ldim_drv->spi_dev)
spi_unregister_driver(&ldim_spi_dev_driver);
LDIMPR("%s ok\n", __func__);
return 0;
}

View File

@@ -149,10 +149,8 @@ static struct class_attribute ob3350_class_attrs[] = {
__ATTR_NULL
};
static int ob3350_ldim_driver_update(void)
static int ob3350_ldim_driver_update(struct aml_ldim_driver_s *ldim_drv)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
ldim_drv->device_power_on = ob3350_power_on;
ldim_drv->device_power_off = ob3350_power_off;
ldim_drv->device_bri_update = ob3350_smr;
@@ -160,7 +158,7 @@ static int ob3350_ldim_driver_update(void)
return 0;
}
int ldim_dev_ob3350_probe(void)
int ldim_dev_ob3350_probe(struct aml_ldim_driver_s *ldim_drv)
{
int ret;
@@ -171,7 +169,7 @@ int ldim_dev_ob3350_probe(void)
return -1;
}
ob3350_ldim_driver_update();
ob3350_ldim_driver_update(ldim_drv);
bl_ob3350->cls.name = kzalloc(10, GFP_KERNEL);
sprintf((char *)bl_ob3350->cls.name, "ob3350");
@@ -186,7 +184,7 @@ int ldim_dev_ob3350_probe(void)
return ret;
}
int ldim_dev_ob3350_remove(void)
int ldim_dev_ob3350_remove(struct aml_ldim_driver_s *ldim_drv)
{
kfree(bl_ob3350);
bl_ob3350 = NULL;

View File

@@ -34,11 +34,6 @@
#define LD_DATA_MIN 10
#define LD_DATA_MAX 0xfff
extern int dirspi_write(struct spi_device *spi, u8 *buf, int len);
extern int dirspi_read(struct spi_device *spi, u8 *buf, int len);
extern void dirspi_start(struct spi_device *spi);
extern void dirspi_stop(struct spi_device *spi);
#define _VE_LDIM 'C'
/* VPP.ldim IOCTL command list */
@@ -120,8 +115,8 @@ struct aml_ldim_driver_s {
void (*test_ctrl)(int flag);
struct pinctrl *pin;
struct device *dev;
struct spi_device *spi;
struct spi_board_info *spi_dev;
struct spi_device *spi_dev;
struct spi_board_info *spi_info;
};
struct ldim_param_s {