};
struct iw7027_s *bl_iw7027;
-static int test_brightness[] = {
- 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
- 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
-};
+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_spi_dump_dim(char *buf)
{
int len = 0;
- unsigned int i;
+ unsigned int i, num;
unsigned char val;
+ struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
if (buf == NULL)
return len;
len += sprintf(buf, "iw7027 reg dimming:\n");
- for (i = 0x40; i <= 0x54; i++) {
+ num = ldim_drv->ldev_conf->bl_regnum;
+ for (i = 0x40; i <= (0x40 + (num * 2)); i++) {
iw7027_rreg(bl_iw7027->spi, i, &val);
len += sprintf(buf+len, " 0x%02x=0x%02x\n", i, val);
}
return val;
}
+static int smr_cnt;
static int iw7027_smr(unsigned short *buf, unsigned char len)
{
int i;
unsigned int value_flag = 0, temp;
- unsigned char val[20];
- unsigned short *mapping;
+ unsigned short *mapping, num;
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
+ if (smr_cnt++ >= 30)
+ smr_cnt = 0;
+
if (iw7027_on_flag == 0) {
- if (ldim_debug_print)
+ if (smr_cnt == 0)
LDIMPR("%s: on_flag=%d\n", __func__, iw7027_on_flag);
return 0;
}
- if (len != 10) {
- LDIMERR("%s: data len %d invalid\n", __func__, len);
+ num = ldim_drv->ldev_conf->bl_regnum;
+ if (len != num) {
+ if (smr_cnt == 0)
+ LDIMERR("%s: data len %d invalid\n", __func__, len);
+ return -1;
+ }
+ if (val_brightness == NULL) {
+ if (smr_cnt == 0)
+ LDIMERR("%s: val_brightness is null\n", __func__);
return -1;
}
if (iw7027_spi_op_flag) {
- if (ldim_debug_print) {
+ if (smr_cnt == 0) {
LDIMPR("%s: spi_op_flag=%d\n",
__func__, iw7027_spi_op_flag);
}
dim_min = ldim_drv->ldev_conf->dim_min;
if (bl_iw7027->test_mode) {
- for (i = 0; i < 10; i++) {
- val[2*i] = (test_brightness[i] >> 8) & 0xf;
- val[2*i+1] = test_brightness[i] & 0xff;
+ if (test_brightness == NULL) {
+ if (smr_cnt == 0)
+ LDIMERR("test_brightness is null\n");
+ return 0;
+ }
+ for (i = 0; i < num; i++) {
+ val_brightness[2*i] = (test_brightness[i] >> 8) & 0xf;
+ val_brightness[2*i+1] = test_brightness[i] & 0xff;
}
} else {
- for (i = 0; i < 10; i++)
+ for (i = 0; i < num; i++)
value_flag += buf[i];
if (value_flag == 0) {
- for (i = 0; i < 20; i++)
- val[i] = 0;
+ for (i = 0; i < (num * 2); i++)
+ val_brightness[i] = 0;
} else {
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < num; i++) {
temp = iw7027_get_value(buf[mapping[i]]);
- val[2*i] = (temp >> 8) & 0xf;
- val[2*i+1] = temp & 0xff;
+ val_brightness[2*i] = (temp >> 8) & 0xf;
+ val_brightness[2*i+1] = temp & 0xff;
}
}
}
- iw7027_wregs(bl_iw7027->spi, 0x40, val, 20);
+ iw7027_wregs(bl_iw7027->spi, 0x40, val_brightness, (num * 2));
iw7027_spi_op_flag = 0;
return 0;
} else if (!strcmp(attr->attr.name, "test")) {
ret = sprintf(buf, "test mode=%d\n", bl->test_mode);
} else if (!strcmp(attr->attr.name, "brightness")) {
- ret = sprintf(buf, "0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n",
- test_brightness[0],
- test_brightness[1],
- test_brightness[2],
- test_brightness[3],
- test_brightness[4],
- test_brightness[5],
- test_brightness[6],
- test_brightness[7]);
+ if (test_brightness == NULL) {
+ ret = sprintf(buf, "test_brightness is null\n");
+ return ret;
+ }
+ ret = sprintf(buf, "test_brightness: ");
+ for (i = 0; i < ldim_drv->ldev_conf->bl_regnum; i++)
+ ret += sprintf(buf+ret, " 0x%x", test_brightness[i]);
+ ret += sprintf(buf+ret, "\n");
} else if (!strcmp(attr->attr.name, "status")) {
ret = sprintf(buf, "iw7027 status:\n"
"dev_index = %d\n"
static ssize_t iw7027_store(struct class *class,
struct class_attribute *attr, const char *buf, size_t count)
{
+ struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
struct iw7027_s *bl = container_of(class, struct iw7027_s, cls);
unsigned int val, val2;
unsigned char reg_addr, reg_val;
} else if (!strcmp(attr->attr.name, "brightness")) {
i = sscanf(buf, "%d %d", &val, &val2);
val &= 0xfff;
- LDIMPR("brightness=%d, index=%d\n", val, val2);
- if ((i == 2) && (val2 < ARRAY_SIZE(test_brightness)))
- test_brightness[val2] = val;
+ if (test_brightness == NULL) {
+ LDIMERR("test_brightness is null\n");
+ return count;
+ }
+ if ((i == 2) && (val2 < ldim_drv->ldev_conf->bl_regnum)) {
+ test_brightness[val2] = (unsigned short)val;
+ LDIMPR("brightness=%d, index=%d\n", val, val2);
+ }
} else
LDIMERR("LDIM argment error!\n");
return count;
int ldim_dev_iw7027_probe(void)
{
struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver();
- int ret;
+ int ret, i;
iw7027_on_flag = 0;
iw7027_spi_op_flag = 0;
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->cmd_size = ldim_drv->ldev_conf->cmd_size;
bl_iw7027->init_data = ldim_drv->ldev_conf->init_on;
+ val_brightness = kcalloc(ldim_drv->ldev_conf->bl_regnum * 2,
+ sizeof(unsigned char), GFP_KERNEL);
+ if (val_brightness == NULL) {
+ LDIMERR("malloc val_brightness failed\n");
+ kfree(bl_iw7027);
+ return -1;
+ }
+ test_brightness = kcalloc(ldim_drv->ldev_conf->bl_regnum,
+ sizeof(unsigned short), GFP_KERNEL);
+ if (test_brightness == NULL) {
+ LDIMERR("malloc test_brightness failed\n");
+ } else {
+ for (i = 0; i < ldim_drv->ldev_conf->bl_regnum; i++)
+ test_brightness[i] = 0xfff;
+ }
+
iw7027_ldim_driver_update();
bl_iw7027->cls.name = kzalloc(10, GFP_KERNEL);
bl_iw7027->cls.class_attrs = iw7027_class_attrs;
ret = class_register(&bl_iw7027->cls);
if (ret < 0)
- pr_err("register iw7027 class failed\n");
+ LDIMERR("register iw7027 class failed\n");
iw7027_on_flag = 1; /* default enable in uboot */
int ldim_dev_iw7027_remove(void)
{
+ 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;