diff mbox

[v3,1/7] fbcon: Add fbcon_rotate_hint to struct fb_info

Message ID 20171023071425.5090-2-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hans de Goede Oct. 23, 2017, 7:14 a.m. UTC
On some hardware the LCD panel is not mounted upright in the casing,
but upside-down or rotated 90 degrees. In this case we want the console
to automatically be rotated to compensate.

The fbdev-driver may know about the need to rotate. Add a new
fbcon_rotate_hint field to struct fb_info, which gets initialized to -1.
If the fbdev-driver knows that some sort of rotation is necessary then
it can set this field to a FB_ROTATE_* value to tell the fbcon console
driver to rotate the console.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/video/fbdev/core/fbcon.c   | 18 ++++++++++++------
 drivers/video/fbdev/core/fbsysfs.c |  1 +
 include/linux/fb.h                 |  5 +++++
 3 files changed, 18 insertions(+), 6 deletions(-)

Comments

Sebastian Reichel Oct. 23, 2017, 12:43 p.m. UTC | #1
Hi Hans,

On Mon, Oct 23, 2017 at 09:14:19AM +0200, Hans de Goede wrote:
> On some hardware the LCD panel is not mounted upright in the casing,
> but upside-down or rotated 90 degrees. In this case we want the console
> to automatically be rotated to compensate.
> 
> The fbdev-driver may know about the need to rotate. Add a new
> fbcon_rotate_hint field to struct fb_info, which gets initialized to -1.
> If the fbdev-driver knows that some sort of rotation is necessary then
> it can set this field to a FB_ROTATE_* value to tell the fbcon console
> driver to rotate the console.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---

Thanks for your work. I will give it a try with Droid 4 and N950
once I find some time :)

[...]

> +	p->con_rotate = initial_rotation;
> +	if (p->con_rotate == -1)
> +		p->con_rotate = info->fbcon_rotate_hint;
> +	if (p->con_rotate == -1)
>  		p->con_rotate = fbcon_platform_get_rotate(info);

[...]

> +	p->con_rotate = initial_rotation;
> +	if (p->con_rotate == -1)
> +		p->con_rotate = info->fbcon_rotate_hint;
> +	if (p->con_rotate == -1)
>  		p->con_rotate = fbcon_platform_get_rotate(info);
> +

maybe add a little helper function to reduce code duplication?

-- Sebastian
Hans de Goede Oct. 23, 2017, 1:54 p.m. UTC | #2
Hi,

On 23-10-17 14:43, Sebastian Reichel wrote:
> Hi Hans,
> 
> On Mon, Oct 23, 2017 at 09:14:19AM +0200, Hans de Goede wrote:
>> On some hardware the LCD panel is not mounted upright in the casing,
>> but upside-down or rotated 90 degrees. In this case we want the console
>> to automatically be rotated to compensate.
>>
>> The fbdev-driver may know about the need to rotate. Add a new
>> fbcon_rotate_hint field to struct fb_info, which gets initialized to -1.
>> If the fbdev-driver knows that some sort of rotation is necessary then
>> it can set this field to a FB_ROTATE_* value to tell the fbcon console
>> driver to rotate the console.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
> 
> Thanks for your work. I will give it a try with Droid 4 and N950
> once I find some time :)

Ah, I did not even realize that this work would be useful for those
too, but yes that makes sense.


> [...]
> 
>> +	p->con_rotate = initial_rotation;
>> +	if (p->con_rotate == -1)
>> +		p->con_rotate = info->fbcon_rotate_hint;
>> +	if (p->con_rotate == -1)
>>   		p->con_rotate = fbcon_platform_get_rotate(info);
> 
> [...]
> 
>> +	p->con_rotate = initial_rotation;
>> +	if (p->con_rotate == -1)
>> +		p->con_rotate = info->fbcon_rotate_hint;
>> +	if (p->con_rotate == -1)
>>   		p->con_rotate = fbcon_platform_get_rotate(info);
>> +
> 
> maybe add a little helper function to reduce code duplication?

Maybe, I took a look and there already is a fbcon_set_rotation()
helper which does something completely different, so it might
be best to just keep this as is to avoid confusion between
2 similar named functions.

Regards,

Hans
diff mbox

Patch

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 04612f938bab..fb317ed76b45 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -963,10 +963,13 @@  static const char *fbcon_startup(void)
 	ops->cur_rotate = -1;
 	ops->cur_blink_jiffies = HZ / 5;
 	info->fbcon_par = ops;
-	if (initial_rotation != -1)
-		p->con_rotate = initial_rotation;
-	else
+
+	p->con_rotate = initial_rotation;
+	if (p->con_rotate == -1)
+		p->con_rotate = info->fbcon_rotate_hint;
+	if (p->con_rotate == -1)
 		p->con_rotate = fbcon_platform_get_rotate(info);
+
 	set_blitting_type(vc, info);
 
 	if (info->fix.type != FB_TYPE_TEXT) {
@@ -1103,10 +1106,13 @@  static void fbcon_init(struct vc_data *vc, int init)
 
 	ops = info->fbcon_par;
 	ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
-	if (initial_rotation != -1)
-		p->con_rotate = initial_rotation;
-	else
+
+	p->con_rotate = initial_rotation;
+	if (p->con_rotate == -1)
+		p->con_rotate = info->fbcon_rotate_hint;
+	if (p->con_rotate == -1)
 		p->con_rotate = fbcon_platform_get_rotate(info);
+
 	set_blitting_type(vc, info);
 
 	cols = vc->vc_cols;
diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c
index 15755ce1d26c..e31a182b42bf 100644
--- a/drivers/video/fbdev/core/fbsysfs.c
+++ b/drivers/video/fbdev/core/fbsysfs.c
@@ -58,6 +58,7 @@  struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
 		info->par = p + fb_info_size;
 
 	info->device = dev;
+	info->fbcon_rotate_hint = -1;
 
 #ifdef CONFIG_FB_BACKLIGHT
 	mutex_init(&info->bl_curve_mutex);
diff --git a/include/linux/fb.h b/include/linux/fb.h
index f4386b0ccf40..10cf71cc5d13 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -464,6 +464,11 @@  struct fb_info {
 	atomic_t count;
 	int node;
 	int flags;
+	/*
+	 * -1 by default, set to a FB_ROTATE_* value by the driver, if it knows
+	 * a lcd is not mounted upright and fbcon should rotate to compensate.
+	 */
+	int fbcon_rotate_hint;
 	struct mutex lock;		/* Lock for open/release/ioctl funcs */
 	struct mutex mm_lock;		/* Lock for fb_mmap and smem_* fields */
 	struct fb_var_screeninfo var;	/* Current var */