Commit de6786be authored by Marko Kohtala's avatar Marko Kohtala Committed by Bartlomiej Zolnierkiewicz

video: ssd1307fb: Add devicetree configuration of display setup

Various displays have differences that only mean initializing the display
driver IC with different fixed register values. Defining these in
devicetree offers easier way to adapt the driver to new displays than
requiring a patch to the kernel.

This adds devicetree properties needed to make the initialization match
the example setup as offered by Densitron for their 128x36 display.

It also makes some old one bit parameter handling a little cleaner.
Signed-off-by: default avatarMarko Kohtala <marko.kohtala@okoko.fi>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
Cc: Michal Vokáč <michal.vokac@ysoft.com>
[b.zolnierkie: fix parenthesis alignment]
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190618074111.9309-7-marko.kohtala@okoko.fi
parent ca6216fc
......@@ -28,6 +28,7 @@
#define SSD1307FB_SET_COL_RANGE 0x21
#define SSD1307FB_SET_PAGE_RANGE 0x22
#define SSD1307FB_CONTRAST 0x81
#define SSD1307FB_SET_LOOKUP_TABLE 0x91
#define SSD1307FB_CHARGE_PUMP 0x8d
#define SSD1307FB_SEG_REMAP_ON 0xa1
#define SSD1307FB_DISPLAY_OFF 0xae
......@@ -36,6 +37,7 @@
#define SSD1307FB_START_PAGE_ADDRESS 0xb0
#define SSD1307FB_SET_DISPLAY_OFFSET 0xd3
#define SSD1307FB_SET_CLOCK_FREQ 0xd5
#define SSD1307FB_SET_AREA_COLOR_MODE 0xd8
#define SSD1307FB_SET_PRECHARGE_PERIOD 0xd9
#define SSD1307FB_SET_COM_PINS_CONFIG 0xda
#define SSD1307FB_SET_VCOMH 0xdb
......@@ -58,10 +60,14 @@ struct ssd1307fb_deviceinfo {
};
struct ssd1307fb_par {
u32 com_invdir;
u32 com_lrremap;
unsigned area_color_enable : 1;
unsigned com_invdir : 1;
unsigned com_lrremap : 1;
unsigned com_seq : 1;
unsigned lookup_table_set : 1;
unsigned low_power : 1;
unsigned seg_remap : 1;
u32 com_offset;
u32 com_seq;
u32 contrast;
u32 dclk_div;
u32 dclk_frq;
......@@ -69,6 +75,7 @@ struct ssd1307fb_par {
struct i2c_client *client;
u32 height;
struct fb_info *info;
u8 lookup_table[4];
u32 page_offset;
u32 prechargep1;
u32 prechargep2;
......@@ -76,7 +83,6 @@ struct ssd1307fb_par {
u32 pwm_period;
struct gpio_desc *reset;
struct regulator *vbat_reg;
u32 seg_remap;
u32 vcomh;
u32 width;
};
......@@ -98,6 +104,9 @@ static const struct fb_fix_screeninfo ssd1307fb_fix = {
static const struct fb_var_screeninfo ssd1307fb_var = {
.bits_per_pixel = 1,
.red = { .length = 1 },
.green = { .length = 1 },
.blue = { .length = 1 },
};
static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type)
......@@ -334,7 +343,7 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
}
/* Set COM direction */
com_invdir = 0xc0 | (par->com_invdir & 0x1) << 3;
com_invdir = 0xc0 | par->com_invdir << 3;
ret = ssd1307fb_write_cmd(par->client, com_invdir);
if (ret < 0)
return ret;
......@@ -367,6 +376,22 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
if (ret < 0)
return ret;
/* Set Set Area Color Mode ON/OFF & Low Power Display Mode */
if (par->area_color_enable || par->low_power) {
u32 mode;
ret = ssd1307fb_write_cmd(par->client,
SSD1307FB_SET_AREA_COLOR_MODE);
if (ret < 0)
return ret;
mode = (par->area_color_enable ? 0x30 : 0) |
(par->low_power ? 5 : 0);
ret = ssd1307fb_write_cmd(par->client, mode);
if (ret < 0)
return ret;
}
/* Set precharge period in number of ticks from the internal clock */
ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PRECHARGE_PERIOD);
if (ret < 0)
......@@ -382,8 +407,7 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
if (ret < 0)
return ret;
compins = 0x02 | !(par->com_seq & 0x1) << 4
| (par->com_lrremap & 0x1) << 5;
compins = 0x02 | !par->com_seq << 4 | par->com_lrremap << 5;
ret = ssd1307fb_write_cmd(par->client, compins);
if (ret < 0)
return ret;
......@@ -407,6 +431,28 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
if (ret < 0)
return ret;
/* Set lookup table */
if (par->lookup_table_set) {
int i;
ret = ssd1307fb_write_cmd(par->client,
SSD1307FB_SET_LOOKUP_TABLE);
if (ret < 0)
return ret;
for (i = 0; i < ARRAY_SIZE(par->lookup_table); ++i) {
u8 val = par->lookup_table[i];
if (val < 31 || val > 63)
dev_warn(&par->client->dev,
"lookup table index %d value out of range 31 <= %d <= 63\n",
i, val);
ret = ssd1307fb_write_cmd(par->client, val);
if (ret < 0)
return ret;
}
}
/* Switch to horizontal addressing mode */
ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_ADDRESS_MODE);
if (ret < 0)
......@@ -607,17 +653,27 @@ static int ssd1307fb_probe(struct i2c_client *client,
if (of_property_read_u32(node, "solomon,prechargep2", &par->prechargep2))
par->prechargep2 = 2;
if (!of_property_read_u8_array(node, "solomon,lookup-table",
par->lookup_table,
ARRAY_SIZE(par->lookup_table)))
par->lookup_table_set = 1;
par->seg_remap = !of_property_read_bool(node, "solomon,segment-no-remap");
par->com_seq = of_property_read_bool(node, "solomon,com-seq");
par->com_lrremap = of_property_read_bool(node, "solomon,com-lrremap");
par->com_invdir = of_property_read_bool(node, "solomon,com-invdir");
par->area_color_enable =
of_property_read_bool(node, "solomon,area-color-enable");
par->low_power = of_property_read_bool(node, "solomon,low-power");
par->contrast = 127;
par->vcomh = par->device_info->default_vcomh;
/* Setup display timing */
par->dclk_div = par->device_info->default_dclk_div;
par->dclk_frq = par->device_info->default_dclk_frq;
if (of_property_read_u32(node, "solomon,dclk-div", &par->dclk_div))
par->dclk_div = par->device_info->default_dclk_div;
if (of_property_read_u32(node, "solomon,dclk-frq", &par->dclk_frq))
par->dclk_frq = par->device_info->default_dclk_frq;
vmem_size = DIV_ROUND_UP(par->width, 8) * par->height;
......@@ -651,13 +707,6 @@ static int ssd1307fb_probe(struct i2c_client *client,
info->var.yres = par->height;
info->var.yres_virtual = par->height;
info->var.red.length = 1;
info->var.red.offset = 0;
info->var.green.length = 1;
info->var.green.offset = 0;
info->var.blue.length = 1;
info->var.blue.offset = 0;
info->screen_buffer = vmem;
info->fix.smem_start = __pa(vmem);
info->fix.smem_len = vmem_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment