From: "Thomas Niederprüm" <niederp@physik.uni-kl.de>
To: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: linux-fbdev@vger.kernel.org, plagnioj@jcrosoft.com,
tomi.valkeinen@ti.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 7/8] fbdev: ssd1307fb: Add sysfs handles to expose contrast and dim setting to userspace.
Date: Sat, 07 Feb 2015 16:42:44 +0000 [thread overview]
Message-ID: <20150207174244.25987977@maestro.intranet> (raw)
In-Reply-To: <20150207114329.GQ2079@lukather>
Am Sat, 7 Feb 2015 12:43:29 +0100
schrieb Maxime Ripard <maxime.ripard@free-electrons.com>:
> On Fri, Feb 06, 2015 at 11:28:13PM +0100, niederp@physik.uni-kl.de
> wrote:
> > From: Thomas Niederprüm <niederp@physik.uni-kl.de>
> >
> > This patch adds sysfs handles to enable userspace control over the
> > display contrast as well as the dim mode. The handles are available
> > as "contrast" and "dim" in the framebuffers sysfs domain.
> >
> > Signed-off-by: Thomas Niederprüm <niederp@physik.uni-kl.de>
> > ---
> > drivers/video/fbdev/ssd1307fb.c | 88
> > ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87
> > insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/video/fbdev/ssd1307fb.c
> > b/drivers/video/fbdev/ssd1307fb.c index b38315d..02931c7 100644
> > --- a/drivers/video/fbdev/ssd1307fb.c
> > +++ b/drivers/video/fbdev/ssd1307fb.c
> > @@ -33,6 +33,7 @@
> > #define SSD1307FB_CONTRAST 0x81
> > #define SSD1307FB_CHARGE_PUMP 0x8d
> > #define SSD1307FB_SEG_REMAP_ON 0xa1
> > +#define SSD1307FB_DISPLAY_DIM 0xac
> > #define SSD1307FB_DISPLAY_OFF 0xae
> > #define SSD1307FB_SET_MULTIPLEX_RATIO 0xa8
> > #define SSD1307FB_DISPLAY_ON 0xaf
> > @@ -43,6 +44,9 @@
> > #define SSD1307FB_SET_COM_PINS_CONFIG 0xda
> > #define SSD1307FB_SET_VCOMH 0xdb
> >
> > +#define MIN_CONTRAST 0
> > +#define MAX_CONTRAST 255
> > +
> > #define BITSPERPIXEL 1
> > #define DELAYDIVIDER 20
> >
> > @@ -69,6 +73,7 @@ struct ssd1307fb_par {
> > u32 dclk_div;
> > u32 dclk_frq;
> > struct ssd1307fb_deviceinfo *device_info;
> > + u32 dim;
> > struct i2c_client *client;
> > u32 height;
> > struct fb_info *info;
> > @@ -515,6 +520,79 @@ static const struct of_device_id
> > ssd1307fb_of_match[] = { };
> > MODULE_DEVICE_TABLE(of, ssd1307fb_of_match);
> >
> > +static ssize_t show_contrast(struct device *device,
> > + struct device_attribute *attr, char
> > *buf) +{
> > + struct fb_info *info = dev_get_drvdata(device);
> > + struct ssd1307fb_par *par = info->par;
> > +
> > + return snprintf(buf, PAGE_SIZE, "%d\n", par->contrast);
> > +}
> > +
> > +static ssize_t store_contrast(struct device *device,
> > + struct device_attribute *attr,
> > + const char *buf, size_t count)
> > +{
> > + struct fb_info *info = dev_get_drvdata(device);
> > + struct ssd1307fb_par *par = info->par;
> > + unsigned long contrastval;
> > + int ret;
> > +
> > + ret = kstrtoul(buf, 0, &contrastval);
> > + if (ret < 0)
> > + return ret;
> > +
> > + par->contrast = max(min(contrastval,
> > + (ulong)MAX_CONTRAST), (ulong)MIN_CONTRAST);
> > +
> > + ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CONTRAST);
> > + ret = ret & ssd1307fb_write_cmd(par->client,
> > par->contrast);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return count;
> > +}
> > +
> > +
> > +static ssize_t show_dim(struct device *device,
> > + struct device_attribute *attr, char
> > *buf) +{
> > + struct fb_info *info = dev_get_drvdata(device);
> > + struct ssd1307fb_par *par = info->par;
> > +
> > + return snprintf(buf, PAGE_SIZE, "%d\n", par->dim);
> > +}
> > +
> > +static ssize_t store_dim(struct device *device,
> > + struct device_attribute *attr,
> > + const char *buf, size_t count)
> > +{
> > + struct fb_info *info = dev_get_drvdata(device);
> > + struct ssd1307fb_par *par = info->par;
> > + unsigned long dimval;
> > + int ret;
> > +
> > + ret = kstrtoul(buf, 0, &dimval);
> > + if (ret < 0)
> > + return ret;
> > +
> > + par->dim = max(min(dimval, (ulong)1), (ulong)0);
> > + if (par->dim)
> > + ret = ssd1307fb_write_cmd(par->client,
> > SSD1307FB_DISPLAY_DIM);
> > + else
> > + ret = ssd1307fb_write_cmd(par->client,
> > SSD1307FB_DISPLAY_ON);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return count;
> > +}
> > +
> > +static struct device_attribute device_attrs[] = {
> > + __ATTR(contrast, S_IRUGO|S_IWUSR, show_contrast,
> > store_contrast),
> > + __ATTR(dim, S_IRUGO|S_IWUSR, show_dim, store_dim),
> > +
> > +};
> > +
>
> I would have thought this was something accessible through the
> framebuffer ioctl.
>
> Apparently it's not, at least for the contrast, so maybe it should be
> added there, instead of doing it for a single driver?
I think the contrast setting for an OLED display is much like the
backlight setting for LCD panel. Since there is also no ioctl to set
the backlight of an LCD I wonder if the contrast of an OLED should have
one.
>
> (oh, and btw, every sysfs file should be documented in
> Documentation/ABI)
>
> > static int ssd1307fb_probe(struct i2c_client *client,
> > const struct i2c_device_id *id)
> > {
> > @@ -523,7 +601,7 @@ static int ssd1307fb_probe(struct i2c_client
> > *client, u32 vmem_size;
> > struct ssd1307fb_par *par;
> > u8 *vmem;
> > - int ret;
> > + int ret, i;
> >
> > if (!node) {
> > dev_err(&client->dev, "No device tree data
> > found!\n"); @@ -650,6 +728,14 @@ static int ssd1307fb_probe(struct
> > i2c_client *client, goto reset_oled_error;
> >
> > ret = register_framebuffer(info);
> > +
> > + for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
> > + ret = device_create_file(info->dev,
> > &device_attrs[i]); +
> > + if (ret) {
> > + dev_err(&client->dev, "Couldn't register sysfs
> > nodes\n");
> > + }
> > +
>
> sysfs_create_groups does pretty much that already.
I'll have a look at it.
>
> And don't forget to remove these files in the .remove()
Good point! :)
>
> > if (ret) {
> > dev_err(&client->dev, "Couldn't register the
> > framebuffer\n"); goto panel_init_error;
> > --
> > 2.1.1
> >
>
> Maxime
>
next prev parent reply other threads:[~2015-02-07 16:42 UTC|newest]
Thread overview: 138+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-06 22:28 [PATCH 0/8] Cleanup and add support for SSD1305 niederp
2015-02-06 22:28 ` [PATCH 1/8] Documentation: dts: add missing Solomon Systech vendor prefix niederp
2015-02-06 22:28 ` [PATCH 2/8] fbdev: ssd1307fb: Unify init code and make controller configurable from device tree niederp
2015-02-07 10:42 ` Maxime Ripard
2015-02-07 14:59 ` Thomas Niederprüm
2015-02-07 15:19 ` Noralf Trønnes
2015-02-09 10:37 ` Thomas Niederprüm
2015-02-12 16:58 ` Maxime Ripard
2015-02-12 16:41 ` Maxime Ripard
2015-02-14 16:12 ` Thomas Niederprüm
2015-02-23 9:43 ` Maxime Ripard
2015-02-06 22:28 ` [PATCH 3/8] fbdev: ssd1307fb: Add support for SSD1305 niederp
2015-02-06 22:28 ` [PATCH 4/8] fbdev: ssd1307fb: Use vmalloc to allocate video memory niederp
2015-02-07 11:18 ` Maxime Ripard
2015-02-07 15:35 ` Thomas Niederprüm
2015-02-12 15:11 ` Maxime Ripard
2015-02-14 14:22 ` Thomas Niederprüm
2015-02-14 15:36 ` Maxime Ripard
2015-03-10 11:28 ` Tomi Valkeinen
2015-03-13 21:31 ` Thomas Niederprüm
2015-03-14 22:02 ` Geert Uytterhoeven
2015-03-20 11:37 ` Tomi Valkeinen
2015-03-20 12:12 ` Geert Uytterhoeven
2015-03-20 14:47 ` Maxime Ripard
2015-03-20 15:24 ` Geert Uytterhoeven
2015-03-20 20:27 ` Thomas Niederprüm
2015-03-20 15:25 ` Tomi Valkeinen
2015-03-20 20:36 ` Thomas Niederprüm
2015-02-06 22:28 ` [PATCH 5/8] fbdev: ssd1307fb: Add module parameter bitsperpixel niederp
2015-02-07 11:20 ` Maxime Ripard
2015-02-07 16:05 ` Thomas Niederprüm
2015-02-14 15:54 ` Maxime Ripard
2015-03-10 10:45 ` Tomi Valkeinen
2015-03-13 19:25 ` Thomas Niederprüm
2015-03-25 10:56 ` Olliver Schinagl
2015-03-25 16:02 ` Maxime Ripard
2015-02-06 22:28 ` [PATCH 6/8] fbdev: ssd1307fb: Add module parameter to set update delay of the deffered io niederp
2015-02-07 11:26 ` Maxime Ripard
2015-02-07 16:12 ` Thomas Niederprüm
2015-02-09 9:03 ` Maxime Ripard
2015-02-06 22:28 ` [PATCH 7/8] fbdev: ssd1307fb: Add sysfs handles to expose contrast and dim setting to userspace niederp
2015-02-07 11:43 ` Maxime Ripard
2015-02-07 16:42 ` Thomas Niederprüm [this message]
2015-02-09 8:52 ` Maxime Ripard
2015-03-10 10:49 ` Tomi Valkeinen
2015-03-13 19:21 ` Thomas Niederprüm
2015-02-06 22:28 ` [PATCH 8/8] fbdev: ssd1307fb: Turn off display on driver unload niederp
2015-02-07 11:45 ` Maxime Ripard
2015-02-07 16:49 ` Thomas Niederprüm
2015-03-01 22:27 ` [PATCHv2 00/10] fbdev: ssd1307fb: Cleanup and add support for SSD1305 Thomas Niederprüm
2015-03-01 22:27 ` [PATCHv2 01/10] fbdev: ssd1307fb: fix memory address smem_start Thomas Niederprüm
2015-03-03 7:17 ` Maxime Ripard
2015-03-01 22:27 ` [PATCHv2 02/10] fbdev: ssd1307fb: Use vmalloc to allocate video memory Thomas Niederprüm
2015-03-03 8:52 ` Maxime Ripard
2015-03-03 19:04 ` Thomas Niederprüm
2015-03-01 22:27 ` [PATCHv2 03/10] Documentation: dts: add missing Solomon Systech vendor prefix Thomas Niederprüm
2015-03-01 22:27 ` [PATCHv2 04/10] fbdev: ssd1307fb: Unify init code and obtain hw specific bits from DT Thomas Niederprüm
2015-03-05 21:49 ` Maxime Ripard
2015-03-01 22:27 ` [PATCHv2 05/10] fbdev: ssd1307fb: fix in tree users of ssd1306 Thomas Niederprüm
2015-03-03 9:31 ` Maxime Ripard
2015-03-01 22:27 ` [PATCHv2 06/10] fbdev: ssd1307fb: Add support for SSD1305 Thomas Niederprüm
2015-03-01 22:28 ` [PATCHv2 07/10] fbdev: ssd1307fb: Add module parameter to set refresh rate of the display Thomas Niederprüm
2015-03-05 22:12 ` Maxime Ripard
2015-03-01 22:28 ` [PATCHv2 08/10] fbdev: ssd1307fb: Add module parameter bitsperpixel Thomas Niederprüm
2015-03-01 22:28 ` [PATCHv2 09/10] fbdev: ssd1307fb: Add sysfs handles to expose contrast and dim setting to userspace Thomas Niederprüm
2015-03-01 22:28 ` [PATCHv2 10/10] fbdev: ssd1307fb: Turn off display on driver unload Thomas Niederprüm
2015-03-03 9:40 ` Maxime Ripard
2015-03-09 22:22 ` [PATCHv3 00/10] fbdev: ssd1307fb: Cleanup and add support for SSD1305 Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 01/10] fbdev: ssd1307fb: fix memory address smem_start Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 02/10] fbdev: ssd1307fb: Use vmalloc to allocate video memory Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 03/10] of: Add Solomon Systech vendor prefix Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 04/10] fbdev: ssd1307fb: Unify init code and obtain hw specific bits from DT Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 05/10] ARM: mxs: fix in tree users of ssd1306 Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 06/10] fbdev: ssd1307fb: Add support for SSD1305 Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 07/10] fbdev: ssd1307fb: Add module parameter to set refresh rate of the display Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 08/10] fbdev: ssd1307fb: Add module parameter bitsperpixel Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 09/10] fbdev: ssd1307fb: Add sysfs handles to expose contrast and dim setting to userspace Thomas Niederprüm
2015-03-09 22:22 ` [PATCHv3 10/10] fbdev: ssd1307fb: Turn off display on driver unload Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 00/10] Cleanup and add support for SSD1305 Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 01/10] fbdev: ssd1307fb: fix memory address smem_start Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 02/10] fbdev: ssd1307fb: Allocate page aligned video memory Thomas Niederprüm
2015-03-18 17:38 ` Maxime Ripard
2015-03-16 17:11 ` [PATCHv4 03/10] of: Add Solomon Systech vendor prefix Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 04/10] fbdev: ssd1307fb: Unify init code and obtain hw specific bits from DT Thomas Niederprüm
2015-03-18 19:27 ` Maxime Ripard
2015-03-20 21:12 ` Thomas Niederprüm
2015-03-24 15:24 ` Maxime Ripard
2015-03-16 17:11 ` [PATCHv4 05/10] ARM: mxs: fix in tree users of ssd1306 Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 06/10] fbdev: ssd1307fb: Add support for SSD1305 Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 07/10] fbdev: ssd1307fb: Add a module parameter to set the refresh rate Thomas Niederprüm
2015-03-19 13:18 ` Maxime Ripard
2015-03-20 21:16 ` Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 08/10] fbdev: ssd1307fb: Turn off display on driver unload Thomas Niederprüm
2015-03-16 17:11 ` [PATCHv4 09/10] fbdev: ssd1307fb: add backlight controls for setting the contrast Thomas Niederprüm
2015-03-19 13:22 ` Maxime Ripard
2015-03-16 17:11 ` [PATCHv4 10/10] fbdev: ssd1307fb: Add blank mode Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 00/11] Cleanup and add support for SSD1305 Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 01/11] fbdev: ssd1307fb: fix memory address smem_start Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 02/11] fbdev: ssd1307fb: Allocate page aligned video memory Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 03/11] of: Add Solomon Systech vendor prefix Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 04/11] fbdev: ssd1307fb: Unify init code and obtain hw specific bits from DT Thomas Niederprüm
2015-03-24 22:14 ` Maxime Ripard
2015-03-25 20:03 ` Thomas Niederprüm
2015-03-25 15:49 ` Olliver Schinagl
2015-03-25 22:14 ` Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 05/11] ARM: mxs: fix in tree users of ssd1306 Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 06/11] fbdev: ssd1307fb: Add support for SSD1305 Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 07/11] fbdev: ssd1307fb: Add a module parameter to set the refresh rate Thomas Niederprüm
2015-03-24 21:54 ` Maxime Ripard
2015-03-24 21:23 ` [PATCHv5 08/11] fbdev: ssd1307fb: Turn off display on driver unload Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 09/11] fbdev: ssd1307fb: Add module parameter to set the initial contrast Thomas Niederprüm
2015-03-24 22:16 ` Maxime Ripard
2015-03-25 20:10 ` Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 10/11] fbdev: ssd1307fb: add backlight controls for setting the contrast Thomas Niederprüm
2015-03-24 21:23 ` [PATCHv5 11/11] fbdev: ssd1307fb: Add blank mode Thomas Niederprüm
2015-03-25 15:50 ` Olliver Schinagl
2015-03-25 20:33 ` Thomas Niederprüm
2015-03-25 22:00 ` Maxime Ripard
2015-03-31 18:27 ` [PATCHv6 00/10] Cleanup and add support for SSD1305 Thomas Niederprüm
2015-03-31 18:27 ` [PATCHv6 01/10] fbdev: ssd1307fb: fix memory address smem_start Thomas Niederprüm
2015-03-31 18:27 ` [PATCHv6 02/10] fbdev: ssd1307fb: Allocate page aligned video memory Thomas Niederprüm
2015-03-31 18:27 ` [PATCHv6 03/10] of: Add Solomon Systech vendor prefix Thomas Niederprüm
2015-04-01 20:33 ` Rob Herring
2015-03-31 18:27 ` [PATCHv6 04/10] fbdev: ssd1307fb: Unify init code and obtain hw specific bits from DT Thomas Niederprüm
2015-04-01 16:00 ` Maxime Ripard
2015-03-31 18:27 ` [PATCHv6 05/10] ARM: mxs: fix in tree users of ssd1306 Thomas Niederprüm
2015-05-07 10:55 ` Tomi Valkeinen
2015-05-07 11:28 ` Shawn Guo
2015-05-08 13:31 ` Maxime Ripard
2015-05-26 7:08 ` Tomi Valkeinen
2015-05-27 3:03 ` Shawn Guo
2015-03-31 18:27 ` [PATCHv6 06/10] fbdev: ssd1307fb: Add support for SSD1305 Thomas Niederprüm
2015-04-01 16:01 ` Maxime Ripard
2015-03-31 18:27 ` [PATCHv6 07/10] fbdev: ssd1307fb: Add a module parameter to set the refresh rate Thomas Niederprüm
2015-03-31 18:27 ` [PATCHv6 08/10] fbdev: ssd1307fb: Turn off display on driver unload Thomas Niederprüm
2015-03-31 18:27 ` [PATCHv6 09/10] fbdev: ssd1307fb: add backlight controls for setting the contrast Thomas Niederprüm
2015-03-31 18:27 ` [PATCHv6 10/10] fbdev: ssd1307fb: Add blank mode Thomas Niederprüm
2015-05-27 10:15 ` [PATCHv6 00/10] Cleanup and add support for SSD1305 Tomi Valkeinen
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=20150207174244.25987977@maestro.intranet \
--to=niederp@physik.uni-kl.de \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.ripard@free-electrons.com \
--cc=plagnioj@jcrosoft.com \
--cc=tomi.valkeinen@ti.com \
/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;
as well as URLs for NNTP newsgroup(s).