mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Bastian Stender <bst@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 4/4] video: add support for Solomon SSD1307 OLED controller family
Date: Mon, 27 Feb 2017 11:08:50 +0100	[thread overview]
Message-ID: <20170227100850.dv7kxvyxhutqfra6@pengutronix.de> (raw)
In-Reply-To: <20170224142501.2679-5-bst@pengutronix.de>

On Fri, Feb 24, 2017 at 03:25:01PM +0100, Bastian Stender wrote:
> It was ported from linux v4.10. Like the kernel driver only
> communication via I2C is supported.
> 
> It has only been tested with a SSD1306 and a 96x16 OLED display:
> 
> 	&i2c0 {
> 		status = "okay";
> 
> 		ssd1306: oled@3c {
> 			compatible = "solomon,ssd1306fb-i2c";
> 			reg = <0x3c>;
> 			reset-gpios = <&gpio1 1 0>;
> 			solomon,height = <16>;
> 			solomon,width = <96>;
> 			solomon,page-offset = <0>;
> 			solomon,com-invdir;
> 			solomon,com-seq;
> 		};
> 
> Signed-off-by: Bastian Stender <bst@pengutronix.de>
> ---
>  drivers/video/Kconfig     |   4 +
>  drivers/video/Makefile    |   1 +
>  drivers/video/ssd1307fb.c | 569 ++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 574 insertions(+)
>  create mode 100644 drivers/video/ssd1307fb.c
> 
> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
> index 8f31f5af74..50a876acb1 100644
> --- a/drivers/video/Kconfig
> +++ b/drivers/video/Kconfig
> @@ -12,6 +12,10 @@ config FRAMEBUFFER_CONSOLE
>  	select FONTS
>  	prompt "framebuffer console support"
>  
> +config DRIVER_VIDEO_FB_SSD1307
> +	bool "Solomon SSD1307 framebuffer support"
> +	depends on PWM && I2C && GPIOLIB
> +
>  config VIDEO_VPL
>  	depends on OFTREE
>  	bool
> diff --git a/drivers/video/Makefile b/drivers/video/Makefile
> index 1bf2e1f3ca..e23c9c37b6 100644
> --- a/drivers/video/Makefile
> +++ b/drivers/video/Makefile
> @@ -21,3 +21,4 @@ obj-$(CONFIG_DRIVER_VIDEO_OMAP) += omap.o
>  obj-$(CONFIG_DRIVER_VIDEO_BCM283X) += bcm2835.o
>  obj-$(CONFIG_DRIVER_VIDEO_SIMPLEFB) += simplefb.o
>  obj-$(CONFIG_DRIVER_VIDEO_IMX_IPUV3) += imx-ipu-v3/
> +obj-$(CONFIG_DRIVER_VIDEO_FB_SSD1307) += ssd1307fb.o
> diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c
> new file mode 100644
> index 0000000000..0dfdcc2232
> --- /dev/null
> +++ b/drivers/video/ssd1307fb.c
> @@ -0,0 +1,569 @@
> +/*
> + * Driver for the Solomon SSD1307 OLED controller family
> + *
> + * Supports:
> + *	- SSD1305 (untested)
> + *	- SSD1306
> + *	- SSD1307 (untested)
> + *	- SSD1309 (untested)
> + *
> + * Copyright 2012 Maxime Ripard <maxime.ripard@free-electrons.com>, Free Electrons
> + *
> + * Ported to barebox from linux v4.10
> + * Copyright (C) 2017 Pengutronix, Bastian Stender <kernel@pengutronix.de>
> + *
> + * Licensed under the GPLv2 or later.
> + */
> +
> +#include <common.h>
> +#include <init.h>
> +#include <fb.h>
> +#include <i2c/i2c.h>
> +#include <of_device.h>
> +#include <gpio.h>
> +#include <of_gpio.h>
> +#include <printk.h>
> +
> +#define SSD1307FB_DATA			0x40
> +#define SSD1307FB_COMMAND		0x80
> +
> +#define SSD1307FB_SET_ADDRESS_MODE	0x20
> +#define SSD1307FB_SET_ADDRESS_MODE_HORIZONTAL	(0x00)
> +#define SSD1307FB_SET_ADDRESS_MODE_VERTICAL	(0x01)
> +#define SSD1307FB_SET_ADDRESS_MODE_PAGE		(0x02)
> +#define SSD1307FB_SET_COL_RANGE		0x21
> +#define SSD1307FB_SET_PAGE_RANGE	0x22
> +#define SSD1307FB_CONTRAST		0x81
> +#define	SSD1307FB_CHARGE_PUMP		0x8d
> +#define SSD1307FB_SEG_REMAP_ON		0xa1
> +#define SSD1307FB_DISPLAY_OFF		0xae
> +#define SSD1307FB_SET_MULTIPLEX_RATIO	0xa8
> +#define SSD1307FB_DISPLAY_ON		0xaf
> +#define SSD1307FB_START_PAGE_ADDRESS	0xb0
> +#define SSD1307FB_SET_DISPLAY_OFFSET	0xd3
> +#define	SSD1307FB_SET_CLOCK_FREQ	0xd5
> +#define	SSD1307FB_SET_PRECHARGE_PERIOD	0xd9
> +#define	SSD1307FB_SET_COM_PINS_CONFIG	0xda
> +#define	SSD1307FB_SET_VCOMH		0xdb

please consistently use spaces after #define

> +
> +struct ssd1307fb_par;

Unnecessary.

> +
> +struct ssd1307fb_deviceinfo {
> +	u32 default_vcomh;
> +	u32 default_dclk_div;
> +	u32 default_dclk_frq;
> +	int need_chargepump;
> +};
> +

[...]

> +static int ssd1307fb_probe(struct device_d *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct fb_info *info;
> +	struct device_node *node = dev->device_node;
> +	const struct of_device_id *match =
> +		of_match_node(ssd1307fb_of_match, dev->device_node);
> +	u32 vmem_size;
> +	struct ssd1307fb_par *par;
> +	struct ssd1307fb_array *array;
> +	u8 *vmem;
> +	int ret;
> +	int i, j;
> +
> +	if (!node) {
> +		dev_err(&client->dev, "No device tree data found!\n");
> +		return -EINVAL;
> +	}
> +
> +	info = xzalloc(sizeof(struct fb_info));
> +	if (!info) {
> +		dev_err(&client->dev, "Couldn't allocate framebuffer.\n");
> +		return -ENOMEM;
> +	}

xzalloc always returns succesfully, no need to check.

> +
> +	par = info->priv;
> +	par->info = info;
> +	par->client = client;
> +
> +	par->device_info = (struct ssd1307fb_deviceinfo *)match->data;
> +
> +	par->reset = of_get_named_gpio(node,
> +					 "reset-gpios", 0);
> +	if (!gpio_is_valid(par->reset)) {
> +		dev_err(&client->dev,
> +			"Couldn't get named gpio 'reset-gpios' %d.\n",
> +			par->reset);
> +		ret = par->reset;
> +		goto fb_alloc_error;
> +	}

Is this gpio really mandatory?

> +
> +	if (of_property_read_u32(node, "solomon,width", &par->width))
> +		par->width = 96;
> +
> +	if (of_property_read_u32(node, "solomon,height", &par->height))
> +		par->height = 16;

These defaults only work for you. You should bail out with an error if
the devicetree does not contain values for these instead.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-02-27 10:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 14:24 [PATCH 0/4] Prepare consoles, add fb flush and Solomon SSD1307 OLED controller support Bastian Stender
2017-02-24 14:24 ` [PATCH 1/4] console: replace set_active by open/close Bastian Stender
2017-02-27  9:54   ` Sascha Hauer
2017-02-27 15:56     ` [PATCH v2] " Bastian Stender
2017-02-28  7:41       ` Sascha Hauer
2017-02-24 14:24 ` [PATCH 2/4] console: expose consoles in devfs Bastian Stender
2017-02-27  9:55   ` Sascha Hauer
2017-02-27 16:01     ` [PATCH v2] " Bastian Stender
2017-02-28  7:50       ` Sascha Hauer
2017-02-24 14:25 ` [PATCH 3/4] fb: introduce flush for virtual framebuffer Bastian Stender
2017-02-24 14:25 ` [PATCH 4/4] video: add support for Solomon SSD1307 OLED controller family Bastian Stender
2017-02-24 16:10   ` Bastian Stender
2017-02-27 10:08   ` Sascha Hauer [this message]
2017-02-27 15:45     ` Bastian Stender
2017-02-28  7:57       ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170227100850.dv7kxvyxhutqfra6@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=bst@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox