video: Use fractional units for X coordinates

With anti-aliased fonts we need a more fine-grained horizontal position
than a single pixel. Characters can be positioned to start part-way through
a pixel, with anti-aliasing (greyscale edges) taking care of the visual
effect.

To cope with this, use fractional units (1/256 pixel) for horizontal
positions in the text console.

Signed-off-by: Simon Glass <sjg@chromium.org>
[agust: rebased]
Signed-off-by: Anatolij Gustschin <agust@denx.de>
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index d1031c8..89a55dd 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -71,13 +71,18 @@
 	return 0;
 }
 
-static int console_normal_putc_xy(struct udevice *dev, uint x, uint y, char ch)
+static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
+				  char ch)
 {
+	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct udevice *vid = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid);
 	int i, row;
 	void *line = vid_priv->fb + y * vid_priv->line_length +
-		x * VNBYTES(vid_priv->bpix);
+		VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
+
+	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
+		return -EAGAIN;
 
 	for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
 		uchar bits = video_fontdata[ch * VIDEO_FONT_HEIGHT + row];
@@ -125,6 +130,20 @@
 		line += vid_priv->line_length;
 	}
 
+	return VID_TO_POS(VIDEO_FONT_WIDTH);
+}
+
+static int console_normal_probe(struct udevice *dev)
+{
+	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+	struct udevice *vid_dev = dev->parent;
+	struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
+
+	vc_priv->x_charsize = VIDEO_FONT_WIDTH;
+	vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
+	vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
+	vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
+
 	return 0;
 }
 
@@ -138,4 +157,5 @@
 	.name	= "vidconsole0",
 	.id	= UCLASS_VIDEO_CONSOLE,
 	.ops	= &console_normal_ops,
+	.probe	= console_normal_probe,
 };