diff mbox series

video: fbdev: ssd1307fb: Added support to Column offset

Message ID 1589370694-14327-1-git-send-email-alencar.fmce@imbel.gov.br (mailing list archive)
State Superseded, archived
Headers show
Series video: fbdev: ssd1307fb: Added support to Column offset | expand

Commit Message

Rodrigo Alencar May 13, 2020, 11:51 a.m. UTC
This patch provides support for displays like VGM128064B0W10,
which requires a column offset of 2, i.e., its segments starts
in SEG2 and ends in SEG129.

Signed-off-by: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>
---
 Documentation/devicetree/bindings/display/ssd1307fb.txt | 1 +
 drivers/video/fbdev/ssd1307fb.c                         | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Geert Uytterhoeven May 13, 2020, 1:45 p.m. UTC | #1
CC dt

On Wed, May 13, 2020 at 1:52 PM Rodrigo Rolim Mendes de Alencar
<455.rodrigo.alencar@gmail.com> wrote:
> This patch provides support for displays like VGM128064B0W10,
> which requires a column offset of 2, i.e., its segments starts
> in SEG2 and ends in SEG129.
>
> Signed-off-by: Rodrigo Alencar <455.rodrigo.alencar@gmail.com>
> ---
>  Documentation/devicetree/bindings/display/ssd1307fb.txt | 1 +
>  drivers/video/fbdev/ssd1307fb.c                         | 8 ++++++--
>  2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/display/ssd1307fb.txt b/Documentation/devicetree/bindings/display/ssd1307fb.txt
> index 27333b9551b3..a9b51fd724a9 100644
> --- a/Documentation/devicetree/bindings/display/ssd1307fb.txt
> +++ b/Documentation/devicetree/bindings/display/ssd1307fb.txt
> @@ -19,6 +19,7 @@ Optional properties:
>    - vbat-supply: The supply for VBAT
>    - solomon,segment-no-remap: Display needs normal (non-inverted) data column
>                                to segment mapping
> +  - solomon,col-offset: Offset of columns (SEG) that the screen is mapped to.
>    - solomon,com-seq: Display uses sequential COM pin configuration
>    - solomon,com-lrremap: Display uses left-right COM pin remap
>    - solomon,com-invdir: Display uses inverted COM pin scan direction
> diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
> index 8e06ba912d60..0241585bfbcc 100644
> --- a/drivers/video/fbdev/ssd1307fb.c
> +++ b/drivers/video/fbdev/ssd1307fb.c
> @@ -74,6 +74,7 @@ struct ssd1307fb_par {
>         struct fb_info *info;
>         u8 lookup_table[4];
>         u32 page_offset;
> +       u32 col_offset;
>         u32 prechargep1;
>         u32 prechargep2;
>         struct pwm_device *pwm;
> @@ -458,11 +459,11 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
>         if (ret < 0)
>                 return ret;
>
> -       ret = ssd1307fb_write_cmd(par->client, 0x0);
> +       ret = ssd1307fb_write_cmd(par->client, par->col_offset);
>         if (ret < 0)
>                 return ret;
>
> -       ret = ssd1307fb_write_cmd(par->client, par->width - 1);
> +       ret = ssd1307fb_write_cmd(par->client, par->col_offset + par->width - 1);
>         if (ret < 0)
>                 return ret;
>
> @@ -626,6 +627,9 @@ static int ssd1307fb_probe(struct i2c_client *client)
>         if (device_property_read_u32(dev, "solomon,page-offset", &par->page_offset))
>                 par->page_offset = 1;
>
> +       if (of_property_read_u32(node, "solomon,col-offset", &par->col_offset))
> +               par->col_offset = 0;
> +
>         if (device_property_read_u32(dev, "solomon,com-offset", &par->com_offset))
>                 par->com_offset = 0;
Andy Shevchenko May 13, 2020, 3:03 p.m. UTC | #2
On Wed, May 13, 2020 at 2:51 PM Rodrigo Rolim Mendes de Alencar
<455.rodrigo.alencar@gmail.com> wrote:
>
> This patch provides support for displays like VGM128064B0W10,
> which requires a column offset of 2, i.e., its segments starts
> in SEG2 and ends in SEG129.

You forgot
1) version of the patch (series) to be bumped
2) Cc to fbdev maintainer (I did here FYI)

> -       ret = ssd1307fb_write_cmd(par->client, 0x0);
> +       ret = ssd1307fb_write_cmd(par->client, par->col_offset);
>         if (ret < 0)
>                 return ret;
>
> -       ret = ssd1307fb_write_cmd(par->client, par->width - 1);
> +       ret = ssd1307fb_write_cmd(par->client, par->col_offset + par->width - 1);
>         if (ret < 0)
>                 return ret;
>
> @@ -626,6 +627,9 @@ static int ssd1307fb_probe(struct i2c_client *client)
>         if (device_property_read_u32(dev, "solomon,page-offset", &par->page_offset))
>                 par->page_offset = 1;
>
> +       if (of_property_read_u32(node, "solomon,col-offset", &par->col_offset))
> +               par->col_offset = 0;

This won't work on non-OF systems, but easy to fix: simple see around
and do in the same way.

>         if (device_property_read_u32(dev, "solomon,com-offset", &par->com_offset))
>                 par->com_offset = 0;
kernel test robot May 13, 2020, 4:32 p.m. UTC | #3
Hi Rodrigo,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20200512]
[cannot apply to robh/for-next linus/master linux/master v5.7-rc5 v5.7-rc4 v5.7-rc3 v5.7-rc5]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Rodrigo-Rolim-Mendes-de-Alencar/video-fbdev-ssd1307fb-Added-support-to-Column-offset/20200513-195401
base:    e098d7762d602be640c53565ceca342f81e55ad2
config: alpha-allyesconfig (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=alpha 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

drivers/video/fbdev/ssd1307fb.c: In function 'ssd1307fb_probe':
>> drivers/video/fbdev/ssd1307fb.c:630:27: error: 'node' undeclared (first use in this function); did you mean 'inode'?
630 |  if (of_property_read_u32(node, "solomon,col-offset", &par->col_offset))
|                           ^~~~
|                           inode
drivers/video/fbdev/ssd1307fb.c:630:27: note: each undeclared identifier is reported only once for each function it appears in

vim +630 drivers/video/fbdev/ssd1307fb.c

   579	
   580	static int ssd1307fb_probe(struct i2c_client *client)
   581	{
   582		struct device *dev = &client->dev;
   583		struct backlight_device *bl;
   584		char bl_name[12];
   585		struct fb_info *info;
   586		struct fb_deferred_io *ssd1307fb_defio;
   587		u32 vmem_size;
   588		struct ssd1307fb_par *par;
   589		void *vmem;
   590		int ret;
   591	
   592		info = framebuffer_alloc(sizeof(struct ssd1307fb_par), dev);
   593		if (!info)
   594			return -ENOMEM;
   595	
   596		par = info->par;
   597		par->info = info;
   598		par->client = client;
   599	
   600		par->device_info = device_get_match_data(dev);
   601	
   602		par->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
   603		if (IS_ERR(par->reset)) {
   604			dev_err(dev, "failed to get reset gpio: %ld\n",
   605				PTR_ERR(par->reset));
   606			ret = PTR_ERR(par->reset);
   607			goto fb_alloc_error;
   608		}
   609	
   610		par->vbat_reg = devm_regulator_get_optional(dev, "vbat");
   611		if (IS_ERR(par->vbat_reg)) {
   612			ret = PTR_ERR(par->vbat_reg);
   613			if (ret == -ENODEV) {
   614				par->vbat_reg = NULL;
   615			} else {
   616				dev_err(dev, "failed to get VBAT regulator: %d\n", ret);
   617				goto fb_alloc_error;
   618			}
   619		}
   620	
   621		if (device_property_read_u32(dev, "solomon,width", &par->width))
   622			par->width = 96;
   623	
   624		if (device_property_read_u32(dev, "solomon,height", &par->height))
   625			par->height = 16;
   626	
   627		if (device_property_read_u32(dev, "solomon,page-offset", &par->page_offset))
   628			par->page_offset = 1;
   629	
 > 630		if (of_property_read_u32(node, "solomon,col-offset", &par->col_offset))
   631			par->col_offset = 0;
   632	
   633		if (device_property_read_u32(dev, "solomon,com-offset", &par->com_offset))
   634			par->com_offset = 0;
   635	
   636		if (device_property_read_u32(dev, "solomon,prechargep1", &par->prechargep1))
   637			par->prechargep1 = 2;
   638	
   639		if (device_property_read_u32(dev, "solomon,prechargep2", &par->prechargep2))
   640			par->prechargep2 = 2;
   641	
   642		if (!device_property_read_u8_array(dev, "solomon,lookup-table",
   643						   par->lookup_table,
   644						   ARRAY_SIZE(par->lookup_table)))
   645			par->lookup_table_set = 1;
   646	
   647		par->seg_remap = !device_property_read_bool(dev, "solomon,segment-no-remap");
   648		par->com_seq = device_property_read_bool(dev, "solomon,com-seq");
   649		par->com_lrremap = device_property_read_bool(dev, "solomon,com-lrremap");
   650		par->com_invdir = device_property_read_bool(dev, "solomon,com-invdir");
   651		par->area_color_enable =
   652			device_property_read_bool(dev, "solomon,area-color-enable");
   653		par->low_power = device_property_read_bool(dev, "solomon,low-power");
   654	
   655		par->contrast = 127;
   656		par->vcomh = par->device_info->default_vcomh;
   657	
   658		/* Setup display timing */
   659		if (device_property_read_u32(dev, "solomon,dclk-div", &par->dclk_div))
   660			par->dclk_div = par->device_info->default_dclk_div;
   661		if (device_property_read_u32(dev, "solomon,dclk-frq", &par->dclk_frq))
   662			par->dclk_frq = par->device_info->default_dclk_frq;
   663	
   664		vmem_size = DIV_ROUND_UP(par->width, 8) * par->height;
   665	
   666		vmem = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
   667						get_order(vmem_size));
   668		if (!vmem) {
   669			dev_err(dev, "Couldn't allocate graphical memory.\n");
   670			ret = -ENOMEM;
   671			goto fb_alloc_error;
   672		}
   673	
   674		ssd1307fb_defio = devm_kzalloc(dev, sizeof(*ssd1307fb_defio),
   675					       GFP_KERNEL);
   676		if (!ssd1307fb_defio) {
   677			dev_err(dev, "Couldn't allocate deferred io.\n");
   678			ret = -ENOMEM;
   679			goto fb_alloc_error;
   680		}
   681	
   682		ssd1307fb_defio->delay = HZ / refreshrate;
   683		ssd1307fb_defio->deferred_io = ssd1307fb_deferred_io;
   684	
   685		info->fbops = &ssd1307fb_ops;
   686		info->fix = ssd1307fb_fix;
   687		info->fix.line_length = DIV_ROUND_UP(par->width, 8);
   688		info->fbdefio = ssd1307fb_defio;
   689	
   690		info->var = ssd1307fb_var;
   691		info->var.xres = par->width;
   692		info->var.xres_virtual = par->width;
   693		info->var.yres = par->height;
   694		info->var.yres_virtual = par->height;
   695	
   696		info->screen_buffer = vmem;
   697		info->fix.smem_start = __pa(vmem);
   698		info->fix.smem_len = vmem_size;
   699	
   700		fb_deferred_io_init(info);
   701	
   702		i2c_set_clientdata(client, info);
   703	
   704		if (par->reset) {
   705			/* Reset the screen */
   706			gpiod_set_value_cansleep(par->reset, 1);
   707			udelay(4);
   708			gpiod_set_value_cansleep(par->reset, 0);
   709			udelay(4);
   710		}
   711	
   712		if (par->vbat_reg) {
   713			ret = regulator_enable(par->vbat_reg);
   714			if (ret) {
   715				dev_err(dev, "failed to enable VBAT: %d\n", ret);
   716				goto reset_oled_error;
   717			}
   718		}
   719	
   720		ret = ssd1307fb_init(par);
   721		if (ret)
   722			goto regulator_enable_error;
   723	
   724		ret = register_framebuffer(info);
   725		if (ret) {
   726			dev_err(dev, "Couldn't register the framebuffer\n");
   727			goto panel_init_error;
   728		}
   729	
   730		snprintf(bl_name, sizeof(bl_name), "ssd1307fb%d", info->node);
   731		bl = backlight_device_register(bl_name, dev, par, &ssd1307fb_bl_ops,
   732					       NULL);
   733		if (IS_ERR(bl)) {
   734			ret = PTR_ERR(bl);
   735			dev_err(dev, "unable to register backlight device: %d\n", ret);
   736			goto bl_init_error;
   737		}
   738	
   739		bl->props.brightness = par->contrast;
   740		bl->props.max_brightness = MAX_CONTRAST;
   741		info->bl_dev = bl;
   742	
   743		dev_info(dev, "fb%d: %s framebuffer device registered, using %d bytes of video memory\n", info->node, info->fix.id, vmem_size);
   744	
   745		return 0;
   746	
   747	bl_init_error:
   748		unregister_framebuffer(info);
   749	panel_init_error:
   750		if (par->device_info->need_pwm) {
   751			pwm_disable(par->pwm);
   752			pwm_put(par->pwm);
   753		}
   754	regulator_enable_error:
   755		if (par->vbat_reg)
   756			regulator_disable(par->vbat_reg);
   757	reset_oled_error:
   758		fb_deferred_io_cleanup(info);
   759	fb_alloc_error:
   760		framebuffer_release(info);
   761		return ret;
   762	}
   763	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/Documentation/devicetree/bindings/display/ssd1307fb.txt b/Documentation/devicetree/bindings/display/ssd1307fb.txt
index 27333b9551b3..a9b51fd724a9 100644
--- a/Documentation/devicetree/bindings/display/ssd1307fb.txt
+++ b/Documentation/devicetree/bindings/display/ssd1307fb.txt
@@ -19,6 +19,7 @@  Optional properties:
   - vbat-supply: The supply for VBAT
   - solomon,segment-no-remap: Display needs normal (non-inverted) data column
                               to segment mapping
+  - solomon,col-offset: Offset of columns (SEG) that the screen is mapped to.
   - solomon,com-seq: Display uses sequential COM pin configuration
   - solomon,com-lrremap: Display uses left-right COM pin remap
   - solomon,com-invdir: Display uses inverted COM pin scan direction
diff --git a/drivers/video/fbdev/ssd1307fb.c b/drivers/video/fbdev/ssd1307fb.c
index 8e06ba912d60..0241585bfbcc 100644
--- a/drivers/video/fbdev/ssd1307fb.c
+++ b/drivers/video/fbdev/ssd1307fb.c
@@ -74,6 +74,7 @@  struct ssd1307fb_par {
 	struct fb_info *info;
 	u8 lookup_table[4];
 	u32 page_offset;
+	u32 col_offset;
 	u32 prechargep1;
 	u32 prechargep2;
 	struct pwm_device *pwm;
@@ -458,11 +459,11 @@  static int ssd1307fb_init(struct ssd1307fb_par *par)
 	if (ret < 0)
 		return ret;
 
-	ret = ssd1307fb_write_cmd(par->client, 0x0);
+	ret = ssd1307fb_write_cmd(par->client, par->col_offset);
 	if (ret < 0)
 		return ret;
 
-	ret = ssd1307fb_write_cmd(par->client, par->width - 1);
+	ret = ssd1307fb_write_cmd(par->client, par->col_offset + par->width - 1);
 	if (ret < 0)
 		return ret;
 
@@ -626,6 +627,9 @@  static int ssd1307fb_probe(struct i2c_client *client)
 	if (device_property_read_u32(dev, "solomon,page-offset", &par->page_offset))
 		par->page_offset = 1;
 
+	if (of_property_read_u32(node, "solomon,col-offset", &par->col_offset))
+		par->col_offset = 0;
+
 	if (device_property_read_u32(dev, "solomon,com-offset", &par->com_offset))
 		par->com_offset = 0;