[PATCH v2] HAB: fuse recommended OCOTP_DIR_BT_DIS

2018-08-10 Thread Bastian Stender
This is now recommended for all systems. Especially for the HAB usecase
disallowing alternative boot selection after WDOG reset is essential.

Signed-off-by: Bastian Stender 
---
Changes since v1:
  - removed accidentally added empty line
---
 drivers/hab/hab.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/hab/hab.c b/drivers/hab/hab.c
index 0d71f5bf26..03bb65e0fa 100644
--- a/drivers/hab/hab.c
+++ b/drivers/hab/hab.c
@@ -161,6 +161,12 @@ static int imx_hab_permanent_write_enable_ocotp(int enable)
 
 static int imx_hab_lockdown_device_ocotp(void)
 {
+   int ret;
+
+   ret = imx_ocotp_write_field(OCOTP_DIR_BT_DIS, 1);
+   if (ret < 0)
+   return ret;
+
return imx_ocotp_write_field(OCOTP_SEC_CONFIG_1, 1);
 }
 
-- 
2.18.0


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


[PATCH 1/2] ARM: imx: add fusemap entries for i.MX6SDL silicon revision >=1.4

2018-08-10 Thread Bastian Stender
Signed-off-by: Bastian Stender 
---
 arch/arm/mach-imx/include/mach/ocotp-fusemap.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/mach-imx/include/mach/ocotp-fusemap.h 
b/arch/arm/mach-imx/include/mach/ocotp-fusemap.h
index 44b58ca6e8..aec50dbf8a 100644
--- a/arch/arm/mach-imx/include/mach/ocotp-fusemap.h
+++ b/arch/arm/mach-imx/include/mach/ocotp-fusemap.h
@@ -23,7 +23,11 @@
 #define OCOTP_BOOT_CFG2(OCOTP_WORD(0x450) | 
OCOTP_BIT(8) | OCOTP_WIDTH(8))
 #define OCOTP_BOOT_CFG3(OCOTP_WORD(0x450) | 
OCOTP_BIT(16) | OCOTP_WIDTH(8))
 #define OCOTP_BOOT_CFG4(OCOTP_WORD(0x450) | 
OCOTP_BIT(24) | OCOTP_WIDTH(8))
+/* available on i.MX6SDL silicon revision >=1.4, "reserved" elsewhere */
+#define OCOTP_SDP_DISABLE  (OCOTP_WORD(0x460) | OCOTP_BIT(0) | 
OCOTP_WIDTH(1))
 #define OCOTP_SEC_CONFIG_1 (OCOTP_WORD(0x460) | OCOTP_BIT(1) | 
OCOTP_WIDTH(1))
+/* available on i.MX6SDL silicon revision >=1.4, "reserved" elsewhere */
+#define OCOTP_SDP_READ_DISABLE (OCOTP_WORD(0x460) | OCOTP_BIT(2) | 
OCOTP_WIDTH(1))
 #define OCOTP_DIR_BT_DIS   (OCOTP_WORD(0x460) | OCOTP_BIT(3) | 
OCOTP_WIDTH(1))
 #define OCOTP_BT_FUSE_SEL  (OCOTP_WORD(0x460) | OCOTP_BIT(4) | 
OCOTP_WIDTH(1))
 #define OCOTP_SJC_DISABLE  (OCOTP_WORD(0x460) | OCOTP_BIT(20) | 
OCOTP_WIDTH(1))
@@ -31,6 +35,8 @@
 #define OCOTP_JTAG_SMODE   (OCOTP_WORD(0x460) | OCOTP_BIT(22) | 
OCOTP_WIDTH(2))
 #define OCOTP_KTE  (OCOTP_WORD(0x460) | OCOTP_BIT(26) | 
OCOTP_WIDTH(1))
 #define OCOTP_JTAG_HEO (OCOTP_WORD(0x460) | OCOTP_BIT(27) | 
OCOTP_WIDTH(1))
+/* available on i.MX6SDL silicon revision >=1.4, "reserved" elsewhere */
+#define OCOTP_FORCE_INTERNAL_BOOT  (OCOTP_WORD(0x460) | OCOTP_BIT(31) | 
OCOTP_WIDTH(1))
 #define OCOTP_NAND_READ_CMD_CODE1  (OCOTP_WORD(0x470) | OCOTP_BIT(0) | 
OCOTP_WIDTH(8))
 #define OCOTP_NAND_READ_CMD_CODE2  (OCOTP_WORD(0x470) | OCOTP_BIT(8) | 
OCOTP_WIDTH(8))
 #define OCOTP_TEMP_SENSE   (OCOTP_WORD(0x4e0) | OCOTP_BIT(0) | 
OCOTP_WIDTH(32))
-- 
2.18.0


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


[PATCH 2/2] HAB: fuse recommended OCOTP_DIR_BT_DIS

2018-08-10 Thread Bastian Stender
This is now recommended for all systems. Especially for the HAB usecase
disallowing alternative boot selection after WDOG reset is essential.

Signed-off-by: Bastian Stender 
---
 drivers/hab/hab.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/hab/hab.c b/drivers/hab/hab.c
index 0d71f5bf26..423f69e5b1 100644
--- a/drivers/hab/hab.c
+++ b/drivers/hab/hab.c
@@ -161,7 +161,14 @@ static int imx_hab_permanent_write_enable_ocotp(int enable)
 
 static int imx_hab_lockdown_device_ocotp(void)
 {
+   int ret;
+
+   ret = imx_ocotp_write_field(OCOTP_DIR_BT_DIS, 1);
+   if (ret < 0)
+   return ret;
+
return imx_ocotp_write_field(OCOTP_SEC_CONFIG_1, 1);
+
 }
 
 static int imx_hab_device_locked_down_ocotp(void)
-- 
2.18.0


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


Re: MFGtools support in barebox

2018-07-18 Thread Bastian Stender

Hi,

On 07/18/2018 03:01 PM, Oleksij Rempel wrote:

you email is in the list. (well, different version of it are already
in the list). Please wait if some one can respond here.

I'm not an expert, but probably what you need is
https://github.com/rauc


Have a look here:

http://rauc.readthedocs.io/en/latest/advanced.html#updating-the-bootloader

Updating barebox on NAND is not yet implemented. It would certainly be a
nice feature to have. Have a look in section 7.6.2 if you want to do that.

Regards,
Bastian

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


Re: [PATCH v2] commands: mmc_extcsd: Add support to write multibyte registers

2018-06-07 Thread Bastian Stender

On 06/07/2018 10:25 AM, Teresa Remmet wrote:

It has been possible to write only the first byte of a multibyte register.
Updated the command to write the complete value of a multibyte register at once.

Signed-off-by: Teresa Remmet 


Reviewed-by: Bastian Stender 

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


Re: [PATCH] commands: mmc_extcsd: Add support to write multibyte registers

2018-06-07 Thread Bastian Stender

Hi Teresa,

On 06/04/2018 02:47 PM, Teresa Remmet wrote:

It has been possible to write only the first byte of a multibyte register.
Updated the command to write the complete value of a multibyte register at once.

Signed-off-by: Teresa Remmet 
---
  commands/mmc_extcsd.c | 44 +++-
  1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c
index acd23a466bcb..a5af97fbbaf1 100644
--- a/commands/mmc_extcsd.c
+++ b/commands/mmc_extcsd.c
@@ -2306,10 +2306,8 @@ static int request_write_operation(void)
return 0;
  }
  
-static void write_field(struct mci *mci, u8 *reg, u16 index, u8 value,

-   int always_write)
+int request_one_time_programmable(u16 index)


Why do you remove "static" here?


  {
-
switch (index) {
case EXT_CSD_BOOT_CONFIG_PROT:
case EXT_CSD_BOOT_WP:
@@ -2349,18 +2347,15 @@ static void write_field(struct mci *mci, u8 *reg, u16 
index, u8 value,
case 52:
case EXT_CSD_BARRIER_CTRL:
case EXT_CSD_SECURE_REMOVAL_TYPE:
-   if (!always_write)
-   if (request_write_operation() == 0) {
-   printf("Abort write operation!\n");
-   goto out;
-   }
-   break;
+   if (request_write_operation() == 0) {
+   printf("Abort write operation!\n");
+   return 1;
+   } else {
+   return 0;
+   }
}
  
-	mci_switch(mci, index, value);

-
-out:
-   return;
+   return 0;
  }
  
  static int do_mmc_extcsd(int argc, char *argv[])

@@ -2430,11 +2425,26 @@ static int do_mmc_extcsd(int argc, char *argv[])
if (!print_field(dst, index)) {
printf("No field with this index found. Abort write 
operation!\n");
} else {
-   write_field(mci, dst, index, value, always_write);
+   struct extcsd_reg *ext;
+   int i;
+   int val = 0;
+
+   if (!always_write) {
+   retval = request_one_time_programmable(index);
+   if (retval)
+   goto error_with_mem;
+   }
+
+   ext = &extcsd[index];
+   for (i = 0; i < ext->width; i++) {
+   val = (value >> (i * 8)) & 0xFF;
+
+   mci_switch(mci, index + i, val);
+   retval = mci_send_ext_csd(mci, dst);
+   if (retval != 0)
+   goto error_with_mem;
+   }
printf("\nValue written!\n\n");
-   retval = mci_send_ext_csd(mci, dst);
-   if (retval != 0)
-   goto error_with_mem;
print_field(dst, index);
}
else



Everything else looks good to me.

Regards,
Bastian

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


[PATCH] Documentation: Bootchooser: fix typo

2018-01-19 Thread Bastian Stender
Signed-off-by: Bastian Stender 
---
 Documentation/user/bootchooser.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/user/bootchooser.rst 
b/Documentation/user/bootchooser.rst
index 3d473b5969..9a75afbf5e 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -353,7 +353,7 @@ node. It then looks like:
 It could makes sense to store the result of the last *bootchooser* operation
 in the *state* variable set as well. In order to do so, add a node with the 
name
 ``last_chosen`` to the *state* variable set. *bootchooser* will use it if 
present.
-The *state' variable set definition then looks like:
+The *state* variable set definition then looks like:
 
 .. code-block:: text
 
-- 
2.11.0


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


Re: [PATCH] i2c: mv64xxx: add timeout waiting for bus ready

2017-11-17 Thread Bastian Stender

On 11/17/2017 09:48 AM, Sascha Hauer wrote:

On Wed, Nov 15, 2017 at 12:11:03PM +0100, Bastian Stender wrote:

On 08/16/2017 12:16 PM, Bastian Stender wrote:

This prevents barebox hanging e.g. in case the i2c clock is accidentally
connected to GND.

Signed-off-by: Bastian Stender 
---


Any thoughts on this one?


Patch looks fine. I must have overlooked it. Should I apply it as
is?


Yes, please. I did a quick test and the patch still works as expected :)

Bastian

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


Re: [PATCH] i2c: mv64xxx: add timeout waiting for bus ready

2017-11-15 Thread Bastian Stender

On 08/16/2017 12:16 PM, Bastian Stender wrote:

This prevents barebox hanging e.g. in case the i2c clock is accidentally
connected to GND.

Signed-off-by: Bastian Stender 
---


Any thoughts on this one?

Regards,
Bastian

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


[PATCH] i2c: mv64xxx: add timeout waiting for bus ready

2017-08-16 Thread Bastian Stender
This prevents barebox hanging e.g. in case the i2c clock is accidentally
connected to GND.

Signed-off-by: Bastian Stender 
---
 drivers/i2c/busses/i2c-mv64xxx.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index fd1665bebb..f54d81608f 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -37,6 +37,8 @@
 #defineREG_CONTROL_TWSIEN  0x0040
 #defineREG_CONTROL_INTEN   0x0080
 
+#define MV46XXX_I2C_TIMEOUT(100 * MSECOND) /* transfer 
timeout */
+
 /* Ctlr status values */
 #defineSTATUS_MAST_START   0x08
 #defineSTATUS_MAST_REPEAT_START0x10
@@ -421,10 +423,11 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
  *
  *
  */
-static void
+static int
 mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
 {
u32 status;
+   uint64_t start = get_time_ns();
do {
if (mv64xxx_read(drv_data, drv_data->reg_offsets.control) &
REG_CONTROL_IFLG) {
@@ -432,6 +435,11 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data 
*drv_data)
  drv_data->reg_offsets.status);
mv64xxx_i2c_fsm(drv_data, status);
mv64xxx_i2c_do_action(drv_data);
+   } else {
+   if (is_timeout(start, MV46XXX_I2C_TIMEOUT)) {
+   dev_warn(&drv_data->adapter.dev, "timeout 
waiting for bus ready\n");
+   return -ETIMEDOUT;
+   }
}
if (drv_data->rc) {
drv_data->state = STATE_IDLE;
@@ -440,6 +448,8 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data 
*drv_data)
drv_data->block = false;
}
} while (drv_data->block);
+
+   return 0;
 }
 
 /*
@@ -453,7 +463,7 @@ static int
 mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 {
struct mv64xxx_i2c_data *drv_data = container_of(adap, struct 
mv64xxx_i2c_data, adapter);
-   int ret = num;
+   int ret;
 
BUG_ON(drv_data->msgs != NULL);
 
@@ -463,15 +473,15 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg 
msgs[], int num)
drv_data->send_stop = (num == 1);
drv_data->block = true;
mv64xxx_i2c_send_start(drv_data);
-   mv64xxx_i2c_wait_for_completion(drv_data);
+   ret = mv64xxx_i2c_wait_for_completion(drv_data);
 
-   if (drv_data->rc < 0)
+   if (!ret && drv_data->rc < 0)
ret = drv_data->rc;
 
drv_data->num_msgs = 0;
drv_data->msgs = NULL;
 
-   return ret;
+   return (ret < 0) ? ret : num;
 }
 
 /*
-- 
2.11.0


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


[PATCH] video/ssd1307fb: add support for VBAT

2017-07-24 Thread Bastian Stender
Adds support to the driver to enable VBAT regulator at init time.

This is similar to ba14301e0356 ("fbdev/ssd1307fb: add support to enable
VBAT") and cfc5b2b551d8 ("fbdev/ssd1307fb: fix optional VBAT support")
in Linux kernel.

Signed-off-by: Bastian Stender 
---
 drivers/video/ssd1307fb.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c
index 7437d340ee..54e02e7220 100644
--- a/drivers/video/ssd1307fb.c
+++ b/drivers/video/ssd1307fb.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define SSD1307FB_DATA  0x40
 #define SSD1307FB_COMMAND   0x80
@@ -70,6 +71,7 @@ struct ssd1307fb_par {
u32 prechargep1;
u32 prechargep2;
int reset;
+   struct regulator *vbat;
u32 seg_remap;
u32 vcomh;
u32 width;
@@ -422,6 +424,12 @@ static int ssd1307fb_probe(struct device_d *dev)
goto fb_alloc_error;
}
 
+   par->vbat = regulator_get(&client->dev, "vbat-supply");
+   if (IS_ERR(par->vbat)) {
+   dev_info(&client->dev, "Will not use VBAT");
+   par->vbat = NULL;
+   }
+
ret = of_property_read_u32(node, "solomon,width", &par->width);
if (ret) {
dev_err(&client->dev,
@@ -505,11 +513,26 @@ static int ssd1307fb_probe(struct device_d *dev)
goto reset_oled_error;
}
 
+   if (par->vbat) {
+   ret = regulator_disable(par->vbat);
+   if (ret < 0)
+   goto reset_oled_error;
+   }
+
i2c_set_clientdata(client, info);
 
/* Reset the screen */
gpio_set_value(par->reset, 0);
udelay(4);
+
+   if (par->vbat) {
+   ret = regulator_enable(par->vbat);
+   if (ret < 0)
+   goto reset_oled_error;
+   }
+
+   mdelay(100);
+
gpio_set_value(par->reset, 1);
udelay(4);
 
@@ -548,6 +571,7 @@ static int ssd1307fb_probe(struct device_d *dev)
 panel_init_error:
 reset_oled_error:
 fb_alloc_error:
+   regulator_disable(par->vbat);
free(info);
return ret;
 }
-- 
2.11.0


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


[PATCH] lib/fonts: add 6x8 font

2017-06-21 Thread Bastian Stender
From: Sven Schneider 

This font is derived from linux lib/fonts/font_6x10.c.

Signed-off-by: Sven Schneider 
---
 lib/fonts/Kconfig|8 +-
 lib/fonts/Makefile   |1 +
 lib/fonts/font_6x8.c | 2581 ++
 3 files changed, 2589 insertions(+), 1 deletion(-)
 create mode 100644 lib/fonts/font_6x8.c

diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig
index 3cd8d7698..e1a736d13 100644
--- a/lib/fonts/Kconfig
+++ b/lib/fonts/Kconfig
@@ -28,11 +28,17 @@ config FONT_CUSTOM_16X
help
  This font is useful for Chinese and other non ascii chars.
 
+config FONT_6x8
+   bool "6x8 font"
+   help
+ This font is useful for small displays (OLED).
+
 config FONT_AUTOSELECT
def_bool y
-   depends on !FONT_MINI_8x8
+   depends on !FONT_8x8
depends on !FONT_MINI_4x6
depends on !FONT_7x14
+   depends on !FONT_6x8
select FONT_8x16
 
 endif # FONTS
diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile
index 9e63ce630..394e2c5e4 100644
--- a/lib/fonts/Makefile
+++ b/lib/fonts/Makefile
@@ -7,6 +7,7 @@ font-objs-$(CONFIG_FONT_8x8)   += font_8x8.o
 font-objs-$(CONFIG_FONT_7x14)  += font_7x14.o
 font-objs-$(CONFIG_FONT_MINI_4x6)  += font_mini_4x6.o
 font-objs-$(CONFIG_FONT_CUSTOM_16X)+= font_custom_16x.o
+font-objs-$(CONFIG_FONT_6x8)   += font_6x8.o
 
 font-objs += $(font-objs-y)
 
diff --git a/lib/fonts/font_6x8.c b/lib/fonts/font_6x8.c
new file mode 100644
index 0..4ed7a8d43
--- /dev/null
+++ b/lib/fonts/font_6x8.c
@@ -0,0 +1,2581 @@
+#include 
+#include 
+
+#define FONTDATAMAX 2048
+
+static const unsigned char fontdata_6x8[FONTDATAMAX] = {
+
+   /* 0 0x00 '^@' */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+
+   /* 1 0x01 '^A' */
+   0x78, /* 00 */
+   0x84, /* 11 */
+   0xCC, /* 110011 */
+   0x84, /* 11 */
+   0xCC, /* 110011 */
+   0xB4, /* 101101 */
+   0x78, /* 00 */
+   0x00, /* 00 */
+
+   /* 2 0x02 '^B' */
+   0x78, /* 00 */
+   0xFC, /* 11 */
+   0xB4, /* 101101 */
+   0xFC, /* 11 */
+   0xB4, /* 101101 */
+   0xCC, /* 110011 */
+   0x78, /* 00 */
+   0x00, /* 00 */
+
+   /* 3 0x03 '^C' */
+   0x00, /* 00 */
+   0x28, /* 001010 */
+   0x7C, /* 01 */
+   0x7C, /* 01 */
+   0x38, /* 001110 */
+   0x10, /* 000100 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+
+   /* 4 0x04 '^D' */
+   0x00, /* 00 */
+   0x10, /* 000100 */
+   0x38, /* 001110 */
+   0x7C, /* 01 */
+   0x38, /* 001110 */
+   0x10, /* 000100 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+
+   /* 5 0x05 '^E' */
+   0x00, /* 00 */
+   0x38, /* 001110 */
+   0x38, /* 001110 */
+   0x6C, /* 011011 */
+   0x6C, /* 011011 */
+   0x10, /* 000100 */
+   0x38, /* 001110 */
+   0x00, /* 00 */
+
+   /* 6 0x06 '^F' */
+   0x00, /* 00 */
+   0x10, /* 000100 */
+   0x38, /* 001110 */
+   0x7C, /* 01 */
+   0x7C, /* 01 */
+   0x10, /* 000100 */
+   0x38, /* 001110 */
+   0x00, /* 00 */
+
+   /* 7 0x07 '^G' */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x30, /* 001100 */
+   0x78, /* 00 */
+   0x30, /* 001100 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+
+   /* 8 0x08 '^H' */
+   0xFC, /* 11 */
+   0xFC, /* 11 */
+   0xCC, /* 110011 */
+   0x84, /* 11 */
+   0xCC, /* 110011 */
+   0xFC, /* 11 */
+   0xFC, /* 11 */
+   0xFC, /* 11 */
+
+   /* 9 0x09 '^I' */
+   0x00, /* 00 */
+   0x30, /* 001100 */
+   0x48, /* 010010 */
+   0x84, /* 11 */
+   0x48, /* 010010 */
+   0x30, /* 001100 */
+   0x00, /* 00 */
+   0x00, /* 00 */
+
+   /* 10 0x0A '^J' */
+   0xFC, /* 11 */
+   0xCC, /* 110011 */
+   0xB4, /* 101101 */
+   0x78, /* 00 */
+   0xB4, /* 101101 */
+   0xCC, /* 110011 */
+   0xFC, /* 11 */
+   0xFC, /* 11 */
+
+   /* 11 0x0B '^K' */
+   0x3C, /* 00 */
+   0x14, /* 000101 */
+   0x20, /* 001000 */
+   0x78, /* 00 */
+   0x44, /* 010001 */
+   0x44, /* 010001 */
+   0x38, /* 001110 */
+   0x00, /* 00 */
+
+   /* 12 0x0C '^L' */
+   0x38, /* 001110 */
+   0x44, /* 010001 */
+   0x44, /* 010001 */
+   0x38, /* 001110 */
+   0x10, /* 000100 */
+   0x38, /* 001110 */
+   0x10, /* 000100 */
+   0x00, /* 00 */
+
+   /* 13 0x0D '^M' */
+   0x18, /* 000110 */
+   0x14, /* 000101 */
+   0x14, /* 000101 */
+   0x10, /* 000100 */

[PATCH] firmware: altera-serial: add support for Arria 10

2017-06-07 Thread Bastian Stender
Make FPGA specific settings configurable (padding, spi bits per word,
delays) and add Arria 10 support. The Arria 10 compatible is the same
as in the kernel patch "fpga manager: Add altera-ps-spi driver for
Altera FPGAs" (drivers/fpga/altera-ps-spi.c). The Arria 5 compatible
works unchanged.

This patch was tested with Arria 5 and Arria 10.

Signed-off-by: Bastian Stender 
---
 .../bindings/firmware/altr,passive-serial.txt  |   3 +-
 drivers/firmware/altera_serial.c   | 159 +++--
 2 files changed, 115 insertions(+), 47 deletions(-)

diff --git a/Documentation/devicetree/bindings/firmware/altr,passive-serial.txt 
b/Documentation/devicetree/bindings/firmware/altr,passive-serial.txt
index d357dd39c..eec12fbac 100644
--- a/Documentation/devicetree/bindings/firmware/altr,passive-serial.txt
+++ b/Documentation/devicetree/bindings/firmware/altr,passive-serial.txt
@@ -6,7 +6,8 @@ passive serial mode. This is used to upload the firmware and
 to start the FPGA.
 
 Required properties:
-- compatible: shall be "altr,fpga-passive-serial"
+- compatible: shall be "altr,fpga-passive-serial" or
+  "altr,fpga-arria10-passive-serial" for Arria 10
 - reg: SPI chip select
 - nstat-gpios: Specify GPIO for controlling the nstat pin
 - confd-gpios: Specify GPIO for controlling the confd pin
diff --git a/drivers/firmware/altera_serial.c b/drivers/firmware/altera_serial.c
index b119778d7..3a0175dd0 100644
--- a/drivers/firmware/altera_serial.c
+++ b/drivers/firmware/altera_serial.c
@@ -25,11 +25,12 @@
 #include 
 #include 
 
-
 /*
  * Physical requirements:
- * - three free GPIOs for the signals nCONFIG, CONFIGURE_DONE, nSTATUS
- * - 32 bit per word, LSB first capable SPI master (MOSI + clock)
+ * - free GPIOs for the signals nCONFIG, CONFIGURE_DONE, nSTATUS (optionally
+ *   for ARRIA 10)
+ * - 32 bit / 8 bit (ARRIA 10) per word, LSB first capable SPI master
+ *   (MOSI + clock)
  *
  * Example how to configure this driver via device tree
  *
@@ -43,6 +44,13 @@
  * };
  */
 
+struct altera_ps_data {
+   int status_wait_max_us;
+   int t_st2ck_us;
+   int spi_bits_per_word;
+   int padding;
+};
+
 struct fpga_spi {
struct firmware_handler fh;
int nstat_gpio; /* input GPIO to read the status line */
@@ -50,9 +58,36 @@ struct fpga_spi {
int nconfig_gpio; /* output GPIO to start the FPGA's config */
struct device_d *dev;
struct spi_device *spi;
+   const struct altera_ps_data *data;
bool padding_done;
 };
 
+/*  |   Arria 5   |   Arria 10  |
+ * t_CF2ST0 | [; 600] | [; 600] | ns
+ * t_CFG|[2;] |[2;] | µs
+ * t_STATUS | [268; 1506] | [268; 3000] | µs
+ * t_CF2ST1 |[; 1506] |[; 3000] | µs
+ * t_CF2CK  | [1506;] |  [3010 µs;] | µs
+ * t_ST2CK  |[2;] |   [10;] | µs
+ * t_CD2UM  |  [175; 437] |  [175; 830] | µs
+ */
+
+/* Arria 5 */
+static struct altera_ps_data a5_data = {
+   .status_wait_max_us = 1506, /* max(t_CF2ST1) */
+   .t_st2ck_us = 2, /* min(t_ST2CK) */
+   .spi_bits_per_word = 32,
+   .padding = true,
+};
+
+/* Arria 10 */
+static struct altera_ps_data a10_data = {
+   .status_wait_max_us = 3000, /* max(t_CF2ST1) */
+   .t_st2ck_us = 10, /* min(t_ST2CK) */
+   .spi_bits_per_word = 8,
+   .padding = false,
+};
+
 static int altera_spi_open(struct firmware_handler *fh)
 {
struct fpga_spi *this = container_of(fh, struct fpga_spi, fh);
@@ -77,7 +112,6 @@ static int altera_spi_open(struct firmware_handler *fh)
(gpio_get_value(this->confd_gpio) == 0));
}
 
-
if (ret != 0) {
dev_err(dev, "FPGA does not acknowledge the programming 
initiation\n");
if (gpio_is_valid(this->nstat_gpio) && 
gpio_get_value(this->nstat_gpio))
@@ -94,24 +128,30 @@ static int altera_spi_open(struct firmware_handler *fh)
this->padding_done = false;
 
/*
-* after about 1506 µs the FPGA must acknowledge this step
-* with the STATUS line at high level
+* after max { max(t_STATUS), max(t_CF2ST1) } the FPGA must acknowledge 
this
+* step with the STATUS line at high level
 */
-
if (gpio_is_valid(this->nstat_gpio)) {
-   ret = wait_on_timeout(1600 * USECOND,
-   gpio_get_value(this->nstat_gpio) == 1);
-   if (ret != 0) {
-   dev_err(dev, "FPGA does not acknowledge the programming 
start\n");
+   ret = wait_on_timeout(this->data->status_wait_max_us * USECOND,
+   gpio_get_value(this->nstat_gpio));
+   if (ret) {
+   dev_err(dev, "nSTATUS still low after max(t_CF2ST1)! 
%d\n", ret);
return ret;
}
} else {
-   udel

Re: [PATCH] i2c: mv64xxx: fix indentation

2017-05-22 Thread Bastian Stender

On 05/22/2017 03:29 PM, Antony Pavlov wrote:

The patch fixes this compiler's warning:

drivers/i2c/busses/i2c-mv64xxx.c: In function ‘mv64xxx_i2c_fsm’:
drivers/i2c/busses/i2c-mv64xxx.c:303:3: warning: this ‘if’ clause does
not guard... [-Wmisleading-indentation]
   if (drv_data->bytes_left == 1)
   ^~
drivers/i2c/busses/i2c-mv64xxx.c:305:4: note: ...this statement, but the
latter is misleadingly indented as if it is guarded by the ‘if’
udelay(2);
^~

Signed-off-by: Antony Pavlov 
Cc: Bastian Stender 
---
 drivers/i2c/busses/i2c-mv64xxx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 1a5d5ef9b..285ede84c 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -302,7 +302,7 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 
status)

if (drv_data->bytes_left == 1)
drv_data->cntl_bits &= ~REG_CONTROL_ACK;
-   udelay(2);
+   udelay(2);
break;

case STATUS_MAST_RD_DATA_NO_ACK: /* 0x58 */



Yes, the indentation happened accidentally. I just checked the 
functional spec again: the udelay is necessary regardless of 
drv_data->bytes_left.


Thanks.

Regards,
Bastian

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


[PATCH v2 3/4] fb: introduce flush for virtual framebuffer

2017-02-28 Thread Bastian Stender
Some drivers need an explicit sync method to flush the virtual
framebuffer to the display. It is called fb_flush().

fb_flush() gets called on fbc_putc, on fb_close and in the pattern cycle
in the fbtest command.

Signed-off-by: Bastian Stender 
---
 commands/fbtest.c |  1 +
 drivers/video/fb.c| 26 ++
 drivers/video/fbconsole.c |  3 +++
 include/fb.h  |  2 ++
 4 files changed, 32 insertions(+)

diff --git a/commands/fbtest.c b/commands/fbtest.c
index bd0e140d07..ca6ec21991 100644
--- a/commands/fbtest.c
+++ b/commands/fbtest.c
@@ -169,6 +169,7 @@ static int do_fbtest(int argc, char *argv[])
pattern = patterns[i++ % ARRAY_SIZE(patterns)].func;
pattern(sc, color);
gu_screen_blit(sc);
+   fb_flush(sc->info);
 
start = get_time_ns();
while (!is_timeout(start, 2 * SECOND))
diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 4d2d3aa650..6b88f2df97 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -31,6 +31,30 @@ static int fb_ioctl(struct cdev* cdev, int req, void *data)
return 0;
 }
 
+static int fb_close(struct cdev *cdev)
+{
+   struct fb_info *info = cdev->priv;
+
+   if (info->fbops->fb_flush)
+   info->fbops->fb_flush(info);
+   return 0;
+}
+
+static int fb_op_flush(struct cdev *cdev)
+{
+   struct fb_info *info = cdev->priv;
+
+   if (info->fbops->fb_flush)
+   info->fbops->fb_flush(info);
+   return 0;
+}
+
+void fb_flush(struct fb_info *info)
+{
+   if (info->fbops->fb_flush)
+   info->fbops->fb_flush(info);
+}
+
 static void fb_release_shadowfb(struct fb_info *info)
 {
free(info->screen_base_shadow);
@@ -199,6 +223,8 @@ static struct file_operations fb_ops = {
.memmap = generic_memmap_rw,
.lseek  = dev_lseek_default,
.ioctl  = fb_ioctl,
+   .close  = fb_close,
+   .flush  = fb_op_flush,
 };
 
 static void fb_print_mode(struct fb_videomode *mode)
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 64f7d7364e..4cf8338ed8 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -292,6 +292,7 @@ static void fbc_putc(struct console_device *cdev, char c)
 {
struct fbc_priv *priv = container_of(cdev,
struct fbc_priv, cdev);
+   struct fb_info *fb = priv->fb;
 
if (priv->in_console)
return;
@@ -345,6 +346,8 @@ static void fbc_putc(struct console_device *cdev, char c)
break;
}
priv->in_console = 0;
+
+   fb_flush(fb);
 }
 
 static int setup_font(struct fbc_priv *priv)
diff --git a/include/fb.h b/include/fb.h
index b2a9c7152b..271b939968 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -86,6 +86,7 @@ struct fb_ops {
void (*fb_enable)(struct fb_info *info);
void (*fb_disable)(struct fb_info *info);
int (*fb_activate_var)(struct fb_info *info);
+   void (*fb_flush)(struct fb_info *info);
 };
 
 /*
@@ -152,6 +153,7 @@ int register_framebuffer(struct fb_info *info);
 
 int fb_enable(struct fb_info *info);
 int fb_disable(struct fb_info *info);
+void fb_flush(struct fb_info *info);
 
 #define FBIOGET_SCREENINFO _IOR('F', 1, loff_t)
 #defineFBIO_ENABLE _IO('F', 2)
-- 
2.11.0


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


[PATCH v2 4/4] video: add support for Solomon SSD1307 OLED controller family

2017-02-28 Thread Bastian Stender
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 
---
 drivers/video/Kconfig |   4 +
 drivers/video/Makefile|   1 +
 drivers/video/ssd1307fb.c | 566 ++
 3 files changed, 571 insertions(+)
 create mode 100644 drivers/video/ssd1307fb.c

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 8f31f5af74..39ed9bde9a 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 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 00..ff4af2cdf4
--- /dev/null
+++ b/drivers/video/ssd1307fb.c
@@ -0,0 +1,566 @@
+/*
+ * Driver for the Solomon SSD1307 OLED controller family
+ *
+ * Supports:
+ *  - SSD1305 (untested)
+ *  - SSD1306
+ *  - SSD1309 (untested)
+ *
+ * The SSD1307 controller is currently unsupported as the PWM parts were not
+ * ported.
+ *
+ * Copyright 2012 Maxime Ripard , Free 
Electrons
+ *
+ * Ported to barebox from linux v4.10
+ * Copyright (C) 2017 Pengutronix, Bastian Stender 
+ *
+ * Licensed under the GPLv2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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_RANGE0x22
+#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_ON0xaf
+#define SSD1307FB_START_PAGE_ADDRESS0xb0
+#define SSD1307FB_SET_DISPLAY_OFFSET0xd3
+#define SSD1307FB_SET_CLOCK_FREQ0xd5
+#define SSD1307FB_SET_PRECHARGE_PERIOD  0xd9
+#define SSD1307FB_SET_COM_PINS_CONFIG   0xda
+#define SSD1307FB_SET_VCOMH 0xdb
+
+struct ssd1307fb_deviceinfo {
+   u32 default_vcomh;
+   u32 default_dclk_div;
+   u32 default_dclk_frq;
+   int need_chargepump;
+};
+
+struct ssd1307fb_par {
+   u32 com_invdir;
+   u32 com_lrremap;
+   u32 com_offset;
+   u32 com_seq;
+   u32 contrast;
+   u32 dclk_div;
+   u32 dclk_frq;
+   const struct ssd1307fb_deviceinfo *device_info;
+   struct i2c_client *client;
+   u32 height;
+   struct fb_info *info;
+   u32 page_offset;
+   u32 prechargep1;
+   u32 prechargep2;
+   int reset;
+   u32 seg_remap;
+   u32 vcomh;
+   u32 width;
+};
+
+struct ssd1307fb_array {
+   u8 type;
+   u8 data[0];
+};
+
+static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type)
+{
+   struct ssd1307fb_array *array;
+
+   array = kzalloc(sizeof(struct ssd1307fb_array) + len, GFP_KERNEL);
+   if (!array)
+   return NULL;
+
+   array->type = type;
+
+   return array;
+}
+
+static int ssd1307fb_write_array(struct i2c_client *client,
+struct ssd1307fb_array *array, u32 len)
+{
+   int ret;
+
+   len += sizeof(struct ssd1307fb_array);
+
+   ret = i2c_master_send(client, (u8 *)array, len);
+   if (ret != len) {
+   

[PATCH v2 1/4] console: replace set_active by open/close

2017-02-28 Thread Bastian Stender
Opening and closing consoles should be independent from setting them
active. This way it is possible to open e.g. a framebuffer console and
display text on it without showing stdout/stderr.

Signed-off-by: Bastian Stender 
---
 common/console.c  | 46 --
 drivers/video/fbconsole.c | 28 ++--
 include/console.h |  7 ++-
 net/netconsole.c  | 27 +--
 4 files changed, 85 insertions(+), 23 deletions(-)

diff --git a/common/console.c b/common/console.c
index 74ccfcfc3e..eccbeed0ca 100644
--- a/common/console.c
+++ b/common/console.c
@@ -59,6 +59,39 @@ static struct kfifo __console_output_fifo;
 static struct kfifo *console_input_fifo = &__console_input_fifo;
 static struct kfifo *console_output_fifo = &__console_output_fifo;
 
+int console_open(struct console_device *cdev)
+{
+   int ret;
+
+   if (cdev->open && !cdev->open_count) {
+   ret = cdev->open(cdev);
+   if (ret)
+   return ret;
+   }
+
+   cdev->open_count++;
+
+   return 0;
+}
+
+int console_close(struct console_device *cdev)
+{
+   int ret;
+
+   if (!cdev->open_count)
+   return -EBADFD;
+
+   cdev->open_count--;
+
+   if (cdev->close && !cdev->open_count) {
+   ret = cdev->close(cdev);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 int console_set_active(struct console_device *cdev, unsigned flag)
 {
int ret, i;
@@ -71,8 +104,15 @@ int console_set_active(struct console_device *cdev, 
unsigned flag)
if (!flag && cdev->f_active && cdev->flush)
cdev->flush(cdev);
 
-   if (cdev->set_active) {
-   ret = cdev->set_active(cdev, flag);
+   if (flag == cdev->f_active)
+   return 0;
+
+   if (!flag) {
+   ret = console_close(cdev);
+   if (ret)
+   return ret;
+   } else {
+   ret = console_open(cdev);
if (ret)
return ret;
}
@@ -264,6 +304,8 @@ int console_register(struct console_device *newcdev)
if (newcdev->putc && !newcdev->puts)
newcdev->puts = __console_puts;
 
+   newcdev->open_count = 0;
+
dev_add_param(dev, "active", console_active_set, console_active_get, 0);
 
if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 693c21f547..64f7d7364e 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -365,21 +365,13 @@ static int setup_font(struct fbc_priv *priv)
return 0;
 }
 
-static int fbc_set_active(struct console_device *cdev, unsigned flags)
+static int fbc_open(struct console_device *cdev)
 {
struct fbc_priv *priv = container_of(cdev,
struct fbc_priv, cdev);
struct fb_info *fb = priv->fb;
int ret;
 
-   if (priv->active) {
-   fb_close(priv->sc);
-   priv->active = false;
-   }
-
-   if (!(flags & (CONSOLE_STDOUT | CONSOLE_STDERR)))
-   return 0;
-
ret = setup_font(priv);
if (ret)
return ret;
@@ -400,6 +392,21 @@ static int fbc_set_active(struct console_device *cdev, 
unsigned flags)
return 0;
 }
 
+static int fbc_close(struct console_device *cdev)
+{
+   struct fbc_priv *priv = container_of(cdev,
+   struct fbc_priv, cdev);
+
+   if (priv->active) {
+   fb_close(priv->sc);
+   priv->active = false;
+
+   return 0;
+   }
+
+   return -EINVAL;
+}
+
 static int set_font(struct param_d *p, void *vpriv)
 {
struct fbc_priv *priv = vpriv;
@@ -434,7 +441,8 @@ int register_fbconsole(struct fb_info *fb)
cdev->getc = fbc_getc;
cdev->devname = "fbconsole";
cdev->devid = DEVICE_ID_DYNAMIC;
-   cdev->set_active = fbc_set_active;
+   cdev->open = fbc_open;
+   cdev->close = fbc_close;
 
ret = console_register(cdev);
if (ret) {
diff --git a/include/console.h b/include/console.h
index 4b2f134a4c..a1ebc8581b 100644
--- a/include/console.h
+++ b/include/console.h
@@ -44,7 +44,8 @@ struct console_device {
int (*setbrg)(struct console_device *cdev, int baudrate);
void (*flush)(struct console_device *cdev);
int (*set_mode)(struct console_device *cdev, enum console_mode mode);
-   int (*set_active)(struct console_device *cdev, unsigned active);
+   int (*open)(struct console_device *cdev);
+   int (*close)(struct console_device *cdev);
 
char *devname;
int devid;
@@ -54,6 +55,8 @@ 

[PATCH v2 2/4] console: expose consoles in devfs

2017-02-28 Thread Bastian Stender
This enables displaying text on e.g. a framebuffer console by issueing

echo -o /dev/fbconsole0 abc123

Signed-off-by: Bastian Stender 
---
 common/console.c  | 53 +
 include/console.h |  3 +++
 2 files changed, 56 insertions(+)

diff --git a/common/console.c b/common/console.c
index eccbeed0ca..668c870ab4 100644
--- a/common/console.c
+++ b/common/console.c
@@ -272,6 +272,40 @@ static int __console_puts(struct console_device *cdev, 
const char *s)
return n;
 }
 
+static int fops_open(struct cdev *cdev, unsigned long flags)
+{
+   struct console_device *priv = cdev->priv;
+
+   return console_open(priv);
+}
+
+static int fops_close(struct cdev *dev)
+{
+   struct console_device *priv = dev->priv;
+
+   return console_close(priv);
+}
+
+static int fops_flush(struct cdev *dev)
+{
+   struct console_device *priv = dev->priv;
+
+   if (priv->flush)
+   priv->flush(priv);
+
+   return 0;
+}
+
+static int fops_write(struct cdev* dev, const void* buf, size_t count,
+ loff_t offset, ulong flags)
+{
+   struct console_device *priv = dev->priv;
+
+   priv->puts(priv, buf);
+
+   return 0;
+}
+
 int console_register(struct console_device *newcdev)
 {
struct device_d *dev = &newcdev->class_dev;
@@ -326,6 +360,25 @@ int console_register(struct console_device *newcdev)
console_set_active(newcdev, CONSOLE_STDIN |
CONSOLE_STDOUT | CONSOLE_STDERR);
 
+   /* expose console as device in fs */
+   newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name,
+   newcdev->class_dev.id);
+   newcdev->devfs.priv = newcdev;
+   newcdev->devfs.dev = dev;
+   newcdev->devfs.ops = &newcdev->fops;
+   newcdev->devfs.flags = DEVFS_IS_CHARACTER_DEV;
+   newcdev->fops.open = fops_open;
+   newcdev->fops.close = fops_close;
+   newcdev->fops.flush = fops_flush;
+   newcdev->fops.write = fops_write;
+
+   ret = devfs_create(&newcdev->devfs);
+
+   if (ret) {
+   pr_err("device creation failed with %s\n", strerror(-ret));
+   return ret;
+   }
+
return 0;
 }
 EXPORT_SYMBOL(console_register);
diff --git a/include/console.h b/include/console.h
index a1ebc8581b..126c2e8aa3 100644
--- a/include/console.h
+++ b/include/console.h
@@ -61,6 +61,9 @@ struct console_device {
unsigned int baudrate_param;
 
const char *linux_console_name;
+
+   struct cdev devfs;
+   struct file_operations fops;
 };
 
 int console_register(struct console_device *cdev);
-- 
2.11.0


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


[PATCH v2 0/4] Prepare consoles, add fb flush and Solomon SSD1307 OLED controller support

2017-02-28 Thread Bastian Stender
Changes since last version:

console: replace set_active by open/close
  - use a counter rather than flags
  - inrease counter independent of the presence of the cdev->open() hook

console: expose consoles in devfs
  - test for presence before using flush hook

video: add support for Solomon SSD1307 OLED controller family
  - remove pwm dependency and SSD1307 compatibility
  - use tabs and spaces consistently
  - remove unnecessary 'struct ssd1307fb_par'
  - remove unnecessary xzalloc check
  - bail out if any of the *required* device tree properties are missing
  - replace errno on gpio failure with error string
  - remove obsolete printk include

Bastian Stender (4):
  console: replace set_active by open/close
  console: expose consoles in devfs
  fb: introduce flush for virtual framebuffer
  video: add support for Solomon SSD1307 OLED controller family

 commands/fbtest.c |   1 +
 common/console.c  |  99 +++-
 drivers/video/Kconfig |   4 +
 drivers/video/Makefile|   1 +
 drivers/video/fb.c|  26 +++
 drivers/video/fbconsole.c |  31 ++-
 drivers/video/ssd1307fb.c | 566 ++
 include/console.h |  10 +-
 include/fb.h  |   2 +
 net/netconsole.c  |  27 ++-
 10 files changed, 744 insertions(+), 23 deletions(-)
 create mode 100644 drivers/video/ssd1307fb.c

-- 
2.11.0


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


[PATCH v2] console: expose consoles in devfs

2017-02-27 Thread Bastian Stender
This enables displaying text on e.g. a framebuffer console by issueing

echo -o /dev/fbconsole0 abc123

Signed-off-by: Bastian Stender 
---
 common/console.c  | 52 
 include/console.h |  3 +++
 2 files changed, 55 insertions(+)

diff --git a/common/console.c b/common/console.c
index 3ff32b8327..bde4c08414 100644
--- a/common/console.c
+++ b/common/console.c
@@ -259,6 +259,39 @@ static int __console_puts(struct console_device *cdev, 
const char *s)
return n;
 }
 
+static int fops_open(struct cdev *cdev, unsigned long flags)
+{
+   struct console_device *priv = cdev->priv;
+
+   return console_open(priv);
+}
+
+static int fops_close(struct cdev *dev)
+{
+   struct console_device *priv = dev->priv;
+
+   return console_close(priv);
+}
+
+static int fops_flush(struct cdev *dev)
+{
+   struct console_device *priv = dev->priv;
+
+   priv->flush(priv);
+
+   return 0;
+}
+
+static int fops_write(struct cdev* dev, const void* buf, size_t count,
+ loff_t offset, ulong flags)
+{
+   struct console_device *priv = dev->priv;
+
+   priv->puts(priv, buf);
+
+   return 0;
+}
+
 int console_register(struct console_device *newcdev)
 {
struct device_d *dev = &newcdev->class_dev;
@@ -311,6 +344,25 @@ int console_register(struct console_device *newcdev)
console_set_active(newcdev, CONSOLE_STDIN |
CONSOLE_STDOUT | CONSOLE_STDERR);
 
+   /* expose console as device in fs */
+   newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name,
+   newcdev->class_dev.id);
+   newcdev->devfs.priv = newcdev;
+   newcdev->devfs.dev = dev;
+   newcdev->devfs.ops = &newcdev->fops;
+   newcdev->devfs.flags = DEVFS_IS_CHARACTER_DEV;
+   newcdev->fops.open = fops_open;
+   newcdev->fops.close = fops_close;
+   newcdev->fops.flush = fops_flush;
+   newcdev->fops.write = fops_write;
+
+   ret = devfs_create(&newcdev->devfs);
+
+   if (ret) {
+   pr_err("device creation failed with %s\n", strerror(-ret));
+   return ret;
+   }
+
return 0;
 }
 EXPORT_SYMBOL(console_register);
diff --git a/include/console.h b/include/console.h
index 85e15cad67..68edc3aaf1 100644
--- a/include/console.h
+++ b/include/console.h
@@ -63,6 +63,9 @@ struct console_device {
unsigned int baudrate_param;
 
const char *linux_console_name;
+
+   struct cdev devfs;
+   struct file_operations fops;
 };
 
 int console_register(struct console_device *cdev);
-- 
2.11.0


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


[PATCH v2] console: replace set_active by open/close

2017-02-27 Thread Bastian Stender
Opening and closing consoles should be independent from setting them
active. This way it is possible to open e.g. a framebuffer console and
display text on it without showing stdout/stderr.

Signed-off-by: Bastian Stender 
---
 common/console.c  | 31 +--
 drivers/video/fbconsole.c | 28 ++--
 include/console.h |  9 -
 net/netconsole.c  | 27 +--
 4 files changed, 72 insertions(+), 23 deletions(-)

diff --git a/common/console.c b/common/console.c
index 74ccfcfc3e..3ff32b8327 100644
--- a/common/console.c
+++ b/common/console.c
@@ -59,6 +59,26 @@ static struct kfifo __console_output_fifo;
 static struct kfifo *console_input_fifo = &__console_input_fifo;
 static struct kfifo *console_output_fifo = &__console_output_fifo;
 
+int console_open(struct console_device *cdev)
+{
+   if (cdev->open && !(cdev-> flags & FLAG_CONSOLE_OPEN)) {
+   cdev->flags |= FLAG_CONSOLE_OPEN;
+   return cdev->open(cdev);
+   }
+
+   return 0;
+}
+
+int console_close(struct console_device *cdev)
+{
+   if (cdev->close && cdev-> flags & FLAG_CONSOLE_OPEN) {
+   cdev->flags &= ~FLAG_CONSOLE_OPEN;
+   return cdev->close(cdev);
+   }
+
+   return 0;
+}
+
 int console_set_active(struct console_device *cdev, unsigned flag)
 {
int ret, i;
@@ -71,8 +91,15 @@ int console_set_active(struct console_device *cdev, unsigned 
flag)
if (!flag && cdev->f_active && cdev->flush)
cdev->flush(cdev);
 
-   if (cdev->set_active) {
-   ret = cdev->set_active(cdev, flag);
+   if (flag == cdev->f_active)
+   return 0;
+
+   if (!flag) {
+   ret = console_close(cdev);
+   if (ret)
+   return ret;
+   } else {
+   ret = console_open(cdev);
if (ret)
return ret;
}
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 693c21f547..64f7d7364e 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -365,21 +365,13 @@ static int setup_font(struct fbc_priv *priv)
return 0;
 }
 
-static int fbc_set_active(struct console_device *cdev, unsigned flags)
+static int fbc_open(struct console_device *cdev)
 {
struct fbc_priv *priv = container_of(cdev,
struct fbc_priv, cdev);
struct fb_info *fb = priv->fb;
int ret;
 
-   if (priv->active) {
-   fb_close(priv->sc);
-   priv->active = false;
-   }
-
-   if (!(flags & (CONSOLE_STDOUT | CONSOLE_STDERR)))
-   return 0;
-
ret = setup_font(priv);
if (ret)
return ret;
@@ -400,6 +392,21 @@ static int fbc_set_active(struct console_device *cdev, 
unsigned flags)
return 0;
 }
 
+static int fbc_close(struct console_device *cdev)
+{
+   struct fbc_priv *priv = container_of(cdev,
+   struct fbc_priv, cdev);
+
+   if (priv->active) {
+   fb_close(priv->sc);
+   priv->active = false;
+
+   return 0;
+   }
+
+   return -EINVAL;
+}
+
 static int set_font(struct param_d *p, void *vpriv)
 {
struct fbc_priv *priv = vpriv;
@@ -434,7 +441,8 @@ int register_fbconsole(struct fb_info *fb)
cdev->getc = fbc_getc;
cdev->devname = "fbconsole";
cdev->devid = DEVICE_ID_DYNAMIC;
-   cdev->set_active = fbc_set_active;
+   cdev->open = fbc_open;
+   cdev->close = fbc_close;
 
ret = console_register(cdev);
if (ret) {
diff --git a/include/console.h b/include/console.h
index 4b2f134a4c..85e15cad67 100644
--- a/include/console.h
+++ b/include/console.h
@@ -28,6 +28,8 @@
 #define CONSOLE_STDOUT  (1 << 1)
 #define CONSOLE_STDERR  (1 << 2)
 
+#define FLAG_CONSOLE_OPEN   (1 << 0)
+
 enum console_mode {
CONSOLE_MODE_NORMAL,
CONSOLE_MODE_RS485,
@@ -44,7 +46,8 @@ struct console_device {
int (*setbrg)(struct console_device *cdev, int baudrate);
void (*flush)(struct console_device *cdev);
int (*set_mode)(struct console_device *cdev, enum console_mode mode);
-   int (*set_active)(struct console_device *cdev, unsigned active);
+   int (*open)(struct console_device *cdev);
+   int (*close)(struct console_device *cdev);
 
char *devname;
int devid;
@@ -54,6 +57,8 @@ struct console_device {
unsigned char f_active;
char active[4];
 
+   unsigned flags;
+
unsigned int baudrate;
unsigned int baudrate_param;
 
@@ -75,6 +80,8 @@ extern int barebox_loglevel;
 
 struct console_device *console_get_first_active(void);
 

Re: [PATCH 4/4] video: add support for Solomon SSD1307 OLED controller family

2017-02-27 Thread Bastian Stender

On 02/27/2017 11:08 AM, Sascha Hauer wrote:

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 
---
 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 00..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 , Free 
Electrons
+ *
+ * Ported to barebox from linux v4.10
+ * Copyright (C) 2017 Pengutronix, Bastian Stender 
+ *
+ * Licensed under the GPLv2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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_RANGE0x21
+#define SSD1307FB_SET_PAGE_RANGE   0x22
+#define SSD1307FB_CONTRAST 0x81
+#defineSSD1307FB_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
+#defineSSD1307FB_SET_CLOCK_FREQ0xd5
+#defineSSD1307FB_SET_PRECHARGE_PERIOD  0xd9
+#defineSSD1307FB_SET_COM_PINS_CONFIG   0xda
+#defineSSD1307FB_SET_VCOMH 0xdb


please consistently use spaces after #define


Will do.




+
+struct ssd1307fb_par;


Unnecessary.


Ok.




+
+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.


Ok.




+
+   par = info->priv;
+   par->info = info;
+   par->client = client;
+
+   par->device_info = (struct ssd1307fb_deviceinfo *)match->data;
+
+   par->

[PATCH v3] fbconsole: check cursor position before moving

2017-02-27 Thread Bastian Stender
Moving the cursor to x=2, y=2 with "\e[3;3H" on a 12x2 framebuffer
console lead to a barebox crash while drawing the cursor. If the
cursor position is out of bounds clip the cursor to the corresponding
edge.

Signed-off-by: Bastian Stender 
---
 drivers/video/fbconsole.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 64f7d7364e..33649c597d 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -264,10 +264,13 @@ static void fbc_parse_csi(struct fbc_priv *priv)
return;
case 'H':
video_invertchar(priv, priv->x, priv->y);
+
pos = simple_strtoul(priv->csi, &end, 10);
-   priv->y = pos ? pos - 1 : 0;
+   priv->y = clamp(pos - 1, 0, (int) priv->rows);
+
pos = simple_strtoul(end + 1, NULL, 10);
-   priv->x = pos ? pos - 1 : 0;
+   priv->x = clamp(pos - 1, 0, (int) priv->cols);
+
video_invertchar(priv, priv->x, priv->y);
case 'K':
pos = simple_strtoul(priv->csi, &end, 10);
-- 
2.11.0


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


Re: [PATCH 4/4] video: add support for Solomon SSD1307 OLED controller family

2017-02-24 Thread Bastian Stender

On 02/24/2017 03:25 PM, 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 
---
 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


Oops, it actually does not depend on PWM. Only the SSD1307 needs PWM, 
but I did not port that part as I have no way to test it. I should 
probably mention that.



+
 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 00..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)


Remove that for now.


+ * - SSD1309 (untested)
+ *
+ * Copyright 2012 Maxime Ripard , Free 
Electrons
+ *
+ * Ported to barebox from linux v4.10
+ * Copyright (C) 2017 Pengutronix, Bastian Stender 
+ *
+ * Licensed under the GPLv2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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_RANGE0x21
+#define SSD1307FB_SET_PAGE_RANGE   0x22
+#define SSD1307FB_CONTRAST 0x81
+#defineSSD1307FB_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
+#defineSSD1307FB_SET_CLOCK_FREQ0xd5
+#defineSSD1307FB_SET_PRECHARGE_PERIOD  0xd9
+#defineSSD1307FB_SET_COM_PINS_CONFIG   0xda
+#defineSSD1307FB_SET_VCOMH 0xdb
+
+struct ssd1307fb_par;
+
+struct ssd1307fb_deviceinfo {
+   u32 default_vcomh;
+   u32 default_dclk_div;
+   u32 default_dclk_frq;
+   int need_chargepump;
+};
+
+struct ssd1307fb_par {
+   u32 com_invdir;
+   u32 com_lrremap;
+   u32 com_offset;
+   u32 com_seq;
+   u32 contrast;
+   u32 dclk_div;
+   u32 dclk_frq;
+   const struct ssd1307fb_deviceinfo *device_info;
+   struct i2c_client *client;
+   u32 height;
+   struct fb_info *info;
+   u32 page_offset;
+   u32 prechargep1;
+   u32 prechargep2;
+   int reset;
+   u32 seg_remap;
+   u32 vcomh;
+   u32 width;
+};
+
+struct ssd1307fb_array {
+   u8  type;
+   u8  data[0];
+};
+
+static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type)
+{
+   struct ssd1307fb_array *array;
+
+   array = kzalloc(sizeof(struct ssd1307fb_array) + len, GFP_KERNEL);
+   if (!array)
+   return NULL;
+
+   array->type = type;
+
+   return array;
+}
+
+static int ssd1307fb_write_array(struct i2c_client *client,
+struct ssd1307fb_array *array, u32 len)
+{
+   int ret;
+
+   len += sizeof(st

[PATCH 2/4] console: expose consoles in devfs

2017-02-24 Thread Bastian Stender
This enables displaying text on e.g. a framebuffer console by issueing

echo -o /dev/fbconsole0 abc123

Signed-off-by: Bastian Stender 
---
 common/console.c  | 52 
 include/console.h |  3 +++
 2 files changed, 55 insertions(+)

diff --git a/common/console.c b/common/console.c
index 43890b3da8..dcd67afe20 100644
--- a/common/console.c
+++ b/common/console.c
@@ -243,6 +243,39 @@ static int __console_puts(struct console_device *cdev, 
const char *s)
return n;
 }
 
+static int fops_open(struct cdev *cdev, unsigned long flags)
+{
+   struct console_device *priv = cdev->priv;
+
+   return priv->open(priv);
+}
+
+static int fops_close(struct cdev *dev)
+{
+   struct console_device *priv = dev->priv;
+
+   return priv->close(priv);
+}
+
+static int fops_flush(struct cdev *dev)
+{
+   struct console_device *priv = dev->priv;
+
+   priv->flush(priv);
+
+   return 0;
+}
+
+static int fops_write(struct cdev* dev, const void* buf, size_t count,
+ loff_t offset, ulong flags)
+{
+   struct console_device *priv = dev->priv;
+
+   priv->puts(priv, buf);
+
+   return 0;
+}
+
 int console_register(struct console_device *newcdev)
 {
struct device_d *dev = &newcdev->class_dev;
@@ -295,6 +328,25 @@ int console_register(struct console_device *newcdev)
console_set_active(newcdev, CONSOLE_STDIN |
CONSOLE_STDOUT | CONSOLE_STDERR);
 
+   /* expose console as device in fs */
+   newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name,
+   newcdev->class_dev.id);
+   newcdev->devfs.priv = newcdev;
+   newcdev->devfs.dev = dev;
+   newcdev->devfs.ops = &newcdev->fops;
+   newcdev->devfs.flags = DEVFS_IS_CHARACTER_DEV;
+   newcdev->fops.open = fops_open;
+   newcdev->fops.close = fops_close;
+   newcdev->fops.flush = fops_flush;
+   newcdev->fops.write = fops_write;
+
+   ret = devfs_create(&newcdev->devfs);
+
+   if (ret) {
+   pr_err("device creation failed with %s\n", strerror(-ret));
+   return ret;
+   }
+
return 0;
 }
 EXPORT_SYMBOL(console_register);
diff --git a/include/console.h b/include/console.h
index 53f6e47fcc..d9fa05c2ce 100644
--- a/include/console.h
+++ b/include/console.h
@@ -59,6 +59,9 @@ struct console_device {
unsigned int baudrate_param;
 
const char *linux_console_name;
+
+   struct cdev devfs;
+   struct file_operations fops;
 };
 
 int console_register(struct console_device *cdev);
-- 
2.11.0


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


[PATCH 1/4] console: replace set_active by open/close

2017-02-24 Thread Bastian Stender
Opening and closing consoles should be independent from setting them
active. This way it is possible to open e.g. a framebuffer console and
display text on it without showing stdout/stderr.

Signed-off-by: Bastian Stender 
---
 common/console.c  | 19 +++
 drivers/video/fbconsole.c | 28 ++--
 include/console.h |  3 ++-
 net/netconsole.c  | 27 +--
 4 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/common/console.c b/common/console.c
index 74ccfcfc3e..43890b3da8 100644
--- a/common/console.c
+++ b/common/console.c
@@ -71,10 +71,21 @@ int console_set_active(struct console_device *cdev, 
unsigned flag)
if (!flag && cdev->f_active && cdev->flush)
cdev->flush(cdev);
 
-   if (cdev->set_active) {
-   ret = cdev->set_active(cdev, flag);
-   if (ret)
-   return ret;
+   if (flag == cdev->f_active)
+   return 0;
+
+   if (!flag) {
+   if (cdev->close) {
+   ret = cdev->close(cdev);
+   if (ret)
+   return ret;
+   }
+   } else {
+   if (cdev->open) {
+   ret = cdev->open(cdev);
+   if (ret)
+   return ret;
+   }
}
 
cdev->f_active = flag;
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 693c21f547..64f7d7364e 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -365,21 +365,13 @@ static int setup_font(struct fbc_priv *priv)
return 0;
 }
 
-static int fbc_set_active(struct console_device *cdev, unsigned flags)
+static int fbc_open(struct console_device *cdev)
 {
struct fbc_priv *priv = container_of(cdev,
struct fbc_priv, cdev);
struct fb_info *fb = priv->fb;
int ret;
 
-   if (priv->active) {
-   fb_close(priv->sc);
-   priv->active = false;
-   }
-
-   if (!(flags & (CONSOLE_STDOUT | CONSOLE_STDERR)))
-   return 0;
-
ret = setup_font(priv);
if (ret)
return ret;
@@ -400,6 +392,21 @@ static int fbc_set_active(struct console_device *cdev, 
unsigned flags)
return 0;
 }
 
+static int fbc_close(struct console_device *cdev)
+{
+   struct fbc_priv *priv = container_of(cdev,
+   struct fbc_priv, cdev);
+
+   if (priv->active) {
+   fb_close(priv->sc);
+   priv->active = false;
+
+   return 0;
+   }
+
+   return -EINVAL;
+}
+
 static int set_font(struct param_d *p, void *vpriv)
 {
struct fbc_priv *priv = vpriv;
@@ -434,7 +441,8 @@ int register_fbconsole(struct fb_info *fb)
cdev->getc = fbc_getc;
cdev->devname = "fbconsole";
cdev->devid = DEVICE_ID_DYNAMIC;
-   cdev->set_active = fbc_set_active;
+   cdev->open = fbc_open;
+   cdev->close = fbc_close;
 
ret = console_register(cdev);
if (ret) {
diff --git a/include/console.h b/include/console.h
index 4b2f134a4c..53f6e47fcc 100644
--- a/include/console.h
+++ b/include/console.h
@@ -44,7 +44,8 @@ struct console_device {
int (*setbrg)(struct console_device *cdev, int baudrate);
void (*flush)(struct console_device *cdev);
int (*set_mode)(struct console_device *cdev, enum console_mode mode);
-   int (*set_active)(struct console_device *cdev, unsigned active);
+   int (*open)(struct console_device *cdev);
+   int (*close)(struct console_device *cdev);
 
char *devname;
int devid;
diff --git a/net/netconsole.c b/net/netconsole.c
index ce3c418798..ef8b1856b6 100644
--- a/net/netconsole.c
+++ b/net/netconsole.c
@@ -105,19 +105,11 @@ static void nc_putc(struct console_device *cdev, char c)
priv->busy = 0;
 }
 
-static int nc_set_active(struct console_device *cdev, unsigned flags)
+static int nc_open(struct console_device *cdev)
 {
struct nc_priv *priv = container_of(cdev,
struct nc_priv, cdev);
 
-   if (priv->con) {
-   net_unregister(priv->con);
-   priv->con = NULL;
-   }
-
-   if (!flags)
-   return 0;
-
if (!priv->port) {
pr_err("port not set\n");
return -EINVAL;
@@ -142,6 +134,20 @@ static int nc_set_active(struct console_device *cdev, 
unsigned flags)
return 0;
 }
 
+static int nc_close(struct console_device *cdev)
+{
+   struct nc_priv *priv = container_of(cdev,
+   struct nc_priv, cdev);
+
+   if (priv->con) {
+   net_unregister(priv->con);

[PATCH 4/4] video: add support for Solomon SSD1307 OLED controller family

2017-02-24 Thread Bastian Stender
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 
---
 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 00..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 , Free 
Electrons
+ *
+ * Ported to barebox from linux v4.10
+ * Copyright (C) 2017 Pengutronix, Bastian Stender 
+ *
+ * Licensed under the GPLv2 or later.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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_RANGE0x21
+#define SSD1307FB_SET_PAGE_RANGE   0x22
+#define SSD1307FB_CONTRAST 0x81
+#defineSSD1307FB_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
+#defineSSD1307FB_SET_CLOCK_FREQ0xd5
+#defineSSD1307FB_SET_PRECHARGE_PERIOD  0xd9
+#defineSSD1307FB_SET_COM_PINS_CONFIG   0xda
+#defineSSD1307FB_SET_VCOMH 0xdb
+
+struct ssd1307fb_par;
+
+struct ssd1307fb_deviceinfo {
+   u32 default_vcomh;
+   u32 default_dclk_div;
+   u32 default_dclk_frq;
+   int need_chargepump;
+};
+
+struct ssd1307fb_par {
+   u32 com_invdir;
+   u32 com_lrremap;
+   u32 com_offset;
+   u32 com_seq;
+   u32 contrast;
+   u32 dclk_div;
+   u32 dclk_frq;
+   const struct ssd1307fb_deviceinfo *device_info;
+   struct i2c_client *client;
+   u32 height;
+   struct fb_info *info;
+   u32 page_offset;
+   u32 prechargep1;
+   u32 prechargep2;
+   int reset;
+   u32 seg_remap;
+   u32 vcomh;
+   u32 width;
+};
+
+struct ssd1307fb_array {
+   u8  type;
+   u8  data[0];
+};
+
+static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type)
+{
+   struct ssd1307fb_array *array;
+
+   array = kzalloc(sizeof(struct ssd1307fb_array) + len, GFP_KERNEL);
+   if (!array)
+   return NULL;
+
+   array->type = type;
+
+   return array;
+}
+
+static int ssd1307fb_write_array(struct i2c_client *client,
+struct ssd1307fb_array *array, u32 len)
+{
+   int ret;
+
+   len += sizeof(struct ssd1307fb_array);
+
+   ret = i2c_master_send(client, (u8 *)array, len);
+   if (ret != len) {
+   dev_err(&client->dev, "Couldn't send I2C command.\n");
+   return ret;
+  

[PATCH 3/4] fb: introduce flush for virtual framebuffer

2017-02-24 Thread Bastian Stender
Some drivers need an explicit sync method to flush the virtual
framebuffer to the display. It is called fb_flush().

fb_flush() gets called on fbc_putc, on fb_close and in the pattern cycle
in the fbtest command.

Signed-off-by: Bastian Stender 
---
 commands/fbtest.c |  1 +
 drivers/video/fb.c| 26 ++
 drivers/video/fbconsole.c |  3 +++
 include/fb.h  |  2 ++
 4 files changed, 32 insertions(+)

diff --git a/commands/fbtest.c b/commands/fbtest.c
index bd0e140d07..ca6ec21991 100644
--- a/commands/fbtest.c
+++ b/commands/fbtest.c
@@ -169,6 +169,7 @@ static int do_fbtest(int argc, char *argv[])
pattern = patterns[i++ % ARRAY_SIZE(patterns)].func;
pattern(sc, color);
gu_screen_blit(sc);
+   fb_flush(sc->info);
 
start = get_time_ns();
while (!is_timeout(start, 2 * SECOND))
diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 4d2d3aa650..6b88f2df97 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -31,6 +31,30 @@ static int fb_ioctl(struct cdev* cdev, int req, void *data)
return 0;
 }
 
+static int fb_close(struct cdev *cdev)
+{
+   struct fb_info *info = cdev->priv;
+
+   if (info->fbops->fb_flush)
+   info->fbops->fb_flush(info);
+   return 0;
+}
+
+static int fb_op_flush(struct cdev *cdev)
+{
+   struct fb_info *info = cdev->priv;
+
+   if (info->fbops->fb_flush)
+   info->fbops->fb_flush(info);
+   return 0;
+}
+
+void fb_flush(struct fb_info *info)
+{
+   if (info->fbops->fb_flush)
+   info->fbops->fb_flush(info);
+}
+
 static void fb_release_shadowfb(struct fb_info *info)
 {
free(info->screen_base_shadow);
@@ -199,6 +223,8 @@ static struct file_operations fb_ops = {
.memmap = generic_memmap_rw,
.lseek  = dev_lseek_default,
.ioctl  = fb_ioctl,
+   .close  = fb_close,
+   .flush  = fb_op_flush,
 };
 
 static void fb_print_mode(struct fb_videomode *mode)
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 64f7d7364e..4cf8338ed8 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -292,6 +292,7 @@ static void fbc_putc(struct console_device *cdev, char c)
 {
struct fbc_priv *priv = container_of(cdev,
struct fbc_priv, cdev);
+   struct fb_info *fb = priv->fb;
 
if (priv->in_console)
return;
@@ -345,6 +346,8 @@ static void fbc_putc(struct console_device *cdev, char c)
break;
}
priv->in_console = 0;
+
+   fb_flush(fb);
 }
 
 static int setup_font(struct fbc_priv *priv)
diff --git a/include/fb.h b/include/fb.h
index b2a9c7152b..271b939968 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -86,6 +86,7 @@ struct fb_ops {
void (*fb_enable)(struct fb_info *info);
void (*fb_disable)(struct fb_info *info);
int (*fb_activate_var)(struct fb_info *info);
+   void (*fb_flush)(struct fb_info *info);
 };
 
 /*
@@ -152,6 +153,7 @@ int register_framebuffer(struct fb_info *info);
 
 int fb_enable(struct fb_info *info);
 int fb_disable(struct fb_info *info);
+void fb_flush(struct fb_info *info);
 
 #define FBIOGET_SCREENINFO _IOR('F', 1, loff_t)
 #defineFBIO_ENABLE _IO('F', 2)
-- 
2.11.0


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


[PATCH 0/4] Prepare consoles, add fb flush and Solomon SSD1307 OLED controller support

2017-02-24 Thread Bastian Stender
Hi,

This patch set basically adds support for the Solomon SSD1307 OLED
controller family along with some framebuffer and console features
needed.

To enable opening and closing consoles regardless of stdin, stdout and
stderr the open and close methods were introduced. In combination with
the 2nd patch it is now possible to display text with
'echo -o  abcdef'.

The 3rd patch adds a flush method for drivers using a virtual
framebuffer - like the SSD1307 OLED controller. It is called at
appropriate times. The 4th patch finally adds Solomon SSD1307 OLED
controller support.

Regards,
Bastian

Bastian Stender (4):
  console: replace set_active by open/close
  console: expose consoles in devfs
  fb: introduce flush for virtual framebuffer
  video: add support for Solomon SSD1307 OLED controller family

 commands/fbtest.c |   1 +
 common/console.c  |  71 +-
 drivers/video/Kconfig |   4 +
 drivers/video/Makefile|   1 +
 drivers/video/fb.c|  26 +++
 drivers/video/fbconsole.c |  31 ++-
 drivers/video/ssd1307fb.c | 569 ++
 include/console.h |   6 +-
 include/fb.h  |   2 +
 net/netconsole.c  |  27 ++-
 10 files changed, 713 insertions(+), 25 deletions(-)
 create mode 100644 drivers/video/ssd1307fb.c

-- 
2.11.0


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


[PATCH v2] fbconsole: check cursor position before moving

2017-02-24 Thread Bastian Stender
Moving the cursor to x=2, y=2 with "\e[3;3H" on a 12x2 framebuffer
console lead to a barebox crash while drawing the cursor. If the
cursor position is out of bounds clip the cursor to the corresponding
edge.

Signed-off-by: Bastian Stender 
---
 drivers/video/fbconsole.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 64f7d7364e..843a026ff6 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -264,10 +264,13 @@ static void fbc_parse_csi(struct fbc_priv *priv)
return;
case 'H':
video_invertchar(priv, priv->x, priv->y);
+
pos = simple_strtoul(priv->csi, &end, 10);
-   priv->y = pos ? pos - 1 : 0;
+   priv->y = !pos ? 0 : pos < priv->rows ? pos - 1 : priv->rows - 
1;
+
pos = simple_strtoul(end + 1, NULL, 10);
-   priv->x = pos ? pos - 1 : 0;
+   priv->x = !pos ? 0 : pos < priv->cols ? pos - 1 : priv->cols - 
1;
+
video_invertchar(priv, priv->x, priv->y);
case 'K':
pos = simple_strtoul(priv->csi, &end, 10);
-- 
2.11.0


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


Re: [PATCH 1/2] fbconsole: check cursor position before moving

2017-02-24 Thread Bastian Stender

On 02/24/2017 12:18 PM, Ian Abbott wrote:

On 24/02/17 07:32, Sascha Hauer wrote:

On Thu, Feb 23, 2017 at 06:20:21PM +0100, Bastian Stender wrote:

Moving the cursor to x=2, y=2 with "\e[3;3H" on a 12x2 framebuffer
console lead to a barebox crash while drawing the cursor. The cursor can
only be moved to a valid position between (0,0) and (priv->cols,
priv->rows) now.

Signed-off-by: Bastian Stender 
---
 drivers/video/fbconsole.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 64f7d7364e..3879741b2a 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -264,10 +264,13 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 return;
 case 'H':
 video_invertchar(priv, priv->x, priv->y);
+
 pos = simple_strtoul(priv->csi, &end, 10);
-priv->y = pos ? pos - 1 : 0;
+priv->y = (pos && pos <= priv->rows + 1) ? pos - 1 : 0;
+
 pos = simple_strtoul(end + 1, NULL, 10);
-priv->x = pos ? pos - 1 : 0;
+priv->x = (pos && pos <= priv->cols + 1) ? pos - 1 : 0;
+


When moving out of the screen shouldn't we place the cursor on the
bottom right corner of the screen? With this patch we move it to the top
left corner.


Or clip to each edge, something like:

 priv->y = !pos ? 0 : pos < priv->rows ? pos - 1 : priv->rows - 1;

Same for priv->x and priv->cols?


Sounds good to me, I'll send a new version of this patch.

Regards,
Bastian

--
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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


[PATCH 2/2] fbconsole: implement vt100 cursor shown/hidden

2017-02-23 Thread Bastian Stender
This implements the vt100 show cursor command '[?25h' and the hide
cursor command '[?25l'. It is useful for displaying text on a non-active
(no stdout/stdin/stderr) console with 'echo'.

Signed-off-by: Bastian Stender 
---
 drivers/video/fbconsole.c | 55 ++-
 1 file changed, 50 insertions(+), 5 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 3879741b2a..b6059e86f5 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -11,6 +11,7 @@ enum state_t {
LIT,/* Literal input */
ESC,/* Start of escape sequence */
CSI,/* Reading arguments in "CSI Pn ;...*/
+   CSI_CNT,
 };
 
 struct fbc_priv {
@@ -34,10 +35,12 @@ struct fbc_priv {
 
 #define ANSI_FLAG_INVERT   (1 << 0)
 #define ANSI_FLAG_BRIGHT   (1 << 1)
+#define HIDE_CURSOR(1 << 2)
unsigned flags;
 
int csipos;
u8 csi[256];
+   unsigned char csi_cmd;
 
int active;
int in_console;
@@ -144,6 +147,12 @@ static void video_invertchar(struct fbc_priv *priv, int x, 
int y)
priv->font->width, priv->font->height);
 }
 
+static void show_cursor(struct fbc_priv *priv, int x, int y)
+{
+   if (!(priv->flags & HIDE_CURSOR))
+   video_invertchar(priv, x, y);
+}
+
 static void printchar(struct fbc_priv *priv, int c)
 {
video_invertchar(priv, priv->x, priv->y);
@@ -200,7 +209,7 @@ static void printchar(struct fbc_priv *priv, int c)
priv->y = priv->rows;
}
 
-   video_invertchar(priv, priv->x, priv->y);
+   show_cursor(priv, priv->x, priv->y);
 
return;
 }
@@ -258,12 +267,43 @@ static void fbc_parse_csi(struct fbc_priv *priv)
case 'm':
fbc_parse_colors(priv);
return;
+   case '?': /* vt100: show/hide cursor */
+   priv->csi_cmd = last;
+   priv->state = CSI_CNT;
+   return;
+   case 'h':
+   /* suffix for vt100 "[?25h" */
+   switch (priv->csi_cmd) {
+   case '?': /* cursor visible */
+   priv->csi_cmd = -1;
+   if (!(priv->flags & HIDE_CURSOR))
+   break;
+
+   priv->flags &= ~HIDE_CURSOR;
+   /* show cursor now */
+   show_cursor(priv, priv->x, priv->y);
+   break;
+   }
+   break;
+   case 'l':
+   /* suffix for vt100 "[?25l" */
+   switch (priv->csi_cmd) {
+   case '?': /* cursor invisible */
+   priv->csi_cmd = -1;
+
+   /* hide cursor now */
+   video_invertchar(priv, priv->x, priv->y);
+   priv->flags |= HIDE_CURSOR;
+
+   break;
+   }
+   break;
case 'J':
cls(priv);
-   video_invertchar(priv, priv->x, priv->y);
+   show_cursor(priv, priv->x, priv->y);
return;
case 'H':
-   video_invertchar(priv, priv->x, priv->y);
+   show_cursor(priv, priv->x, priv->y);
 
pos = simple_strtoul(priv->csi, &end, 10);
priv->y = (pos && pos <= priv->rows + 1) ? pos - 1 : 0;
@@ -271,7 +311,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
pos = simple_strtoul(end + 1, NULL, 10);
priv->x = (pos && pos <= priv->cols + 1) ? pos - 1 : 0;
 
-   video_invertchar(priv, priv->x, priv->y);
+   show_cursor(priv, priv->x, priv->y);
case 'K':
pos = simple_strtoul(priv->csi, &end, 10);
video_invertchar(priv, priv->x, priv->y);
@@ -343,9 +383,14 @@ static void fbc_putc(struct console_device *cdev, char c)
break;
default:
fbc_parse_csi(priv);
-   priv->state = LIT;
+   if (priv->state != CSI_CNT)
+   priv->state = LIT;
}
break;
+   case CSI_CNT:
+   priv->state = CSI;
+   break;
+
}
priv->in_console = 0;
 }
-- 
2.11.0


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


[PATCH 1/2] fbconsole: check cursor position before moving

2017-02-23 Thread Bastian Stender
Moving the cursor to x=2, y=2 with "\e[3;3H" on a 12x2 framebuffer
console lead to a barebox crash while drawing the cursor. The cursor can
only be moved to a valid position between (0,0) and (priv->cols,
priv->rows) now.

Signed-off-by: Bastian Stender 
---
 drivers/video/fbconsole.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 64f7d7364e..3879741b2a 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -264,10 +264,13 @@ static void fbc_parse_csi(struct fbc_priv *priv)
return;
case 'H':
video_invertchar(priv, priv->x, priv->y);
+
pos = simple_strtoul(priv->csi, &end, 10);
-   priv->y = pos ? pos - 1 : 0;
+   priv->y = (pos && pos <= priv->rows + 1) ? pos - 1 : 0;
+
pos = simple_strtoul(end + 1, NULL, 10);
-   priv->x = pos ? pos - 1 : 0;
+   priv->x = (pos && pos <= priv->cols + 1) ? pos - 1 : 0;
+
video_invertchar(priv, priv->x, priv->y);
case 'K':
pos = simple_strtoul(priv->csi, &end, 10);
-- 
2.11.0


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


[PATCH] lib/fonts: add VGA8x8 font

2017-02-23 Thread Bastian Stender
Ported from Linux v4.10.

This font is ideal for displaying a framebuffer console on a small display.

Signed-off-by: Bastian Stender 
---
 lib/fonts/Kconfig|4 +
 lib/fonts/Makefile   |1 +
 lib/fonts/font_8x8.c | 2587 ++
 3 files changed, 2592 insertions(+)
 create mode 100644 lib/fonts/font_8x8.c

diff --git a/lib/fonts/Kconfig b/lib/fonts/Kconfig
index d23b283964..3cd8d7698b 100644
--- a/lib/fonts/Kconfig
+++ b/lib/fonts/Kconfig
@@ -14,6 +14,9 @@ config FONT_8x16
  This is the "high resolution" font for the VGA frame buffer (the one
  provided by the VGA text console 80x25 mode).
 
+config FONT_8x8
+   bool "VGA 8x8 font"
+
 config FONT_7x14
bool "7x14 font"
 
@@ -27,6 +30,7 @@ config FONT_CUSTOM_16X
 
 config FONT_AUTOSELECT
def_bool y
+   depends on !FONT_MINI_8x8
depends on !FONT_MINI_4x6
depends on !FONT_7x14
select FONT_8x16
diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile
index 98245b3d65..9e63ce6303 100644
--- a/lib/fonts/Makefile
+++ b/lib/fonts/Makefile
@@ -3,6 +3,7 @@
 font-objs := fonts.o
 
 font-objs-$(CONFIG_FONT_8x16)  += font_8x16.o
+font-objs-$(CONFIG_FONT_8x8)   += font_8x8.o
 font-objs-$(CONFIG_FONT_7x14)  += font_7x14.o
 font-objs-$(CONFIG_FONT_MINI_4x6)  += font_mini_4x6.o
 font-objs-$(CONFIG_FONT_CUSTOM_16X)+= font_custom_16x.o
diff --git a/lib/fonts/font_8x8.c b/lib/fonts/font_8x8.c
new file mode 100644
index 00..24216a68a2
--- /dev/null
+++ b/lib/fonts/font_8x8.c
@@ -0,0 +1,2587 @@
+/**/
+/**/
+/*   Font file generated by cpi2fnt   */
+/**/
+/**/
+
+#include 
+#include 
+
+#define FONTDATAMAX 2048
+
+static const unsigned char fontdata_8x8[FONTDATAMAX] = {
+
+   /* 0 0x00 '^@' */
+   0x00, /*  */
+   0x00, /*  */
+   0x00, /*  */
+   0x00, /*  */
+   0x00, /*  */
+   0x00, /*  */
+   0x00, /*  */
+   0x00, /*  */
+
+   /* 1 0x01 '^A' */
+   0x7e, /* 0110 */
+   0x81, /* 1001 */
+   0xa5, /* 10100101 */
+   0x81, /* 1001 */
+   0xbd, /* 1001 */
+   0x99, /* 10011001 */
+   0x81, /* 1001 */
+   0x7e, /* 0110 */
+
+   /* 2 0x02 '^B' */
+   0x7e, /* 0110 */
+   0xff, /*  */
+   0xdb, /* 11011011 */
+   0xff, /*  */
+   0xc3, /* 1111 */
+   0xe7, /* 11100111 */
+   0xff, /*  */
+   0x7e, /* 0110 */
+
+   /* 3 0x03 '^C' */
+   0x6c, /* 01101100 */
+   0xfe, /* 1110 */
+   0xfe, /* 1110 */
+   0xfe, /* 1110 */
+   0x7c, /* 0100 */
+   0x38, /* 00111000 */
+   0x10, /* 0001 */
+   0x00, /*  */
+
+   /* 4 0x04 '^D' */
+   0x10, /* 0001 */
+   0x38, /* 00111000 */
+   0x7c, /* 0100 */
+   0xfe, /* 1110 */
+   0x7c, /* 0100 */
+   0x38, /* 00111000 */
+   0x10, /* 0001 */
+   0x00, /*  */
+
+   /* 5 0x05 '^E' */
+   0x38, /* 00111000 */
+   0x7c, /* 0100 */
+   0x38, /* 00111000 */
+   0xfe, /* 1110 */
+   0xfe, /* 1110 */
+   0xd6, /* 11010110 */
+   0x10, /* 0001 */
+   0x38, /* 00111000 */
+
+   /* 6 0x06 '^F' */
+   0x10, /* 0001 */
+   0x38, /* 00111000 */
+   0x7c, /* 0100 */
+   0xfe, /* 1110 */
+   0xfe, /* 1110 */
+   0x7c, /* 0100 */
+   0x10, /* 0001 */
+   0x38, /* 00111000 */
+
+   /* 7 0x07 '^G' */
+   0x00, /*  */
+   0x00, /*  */
+   0x18, /* 00011000 */
+   0x3c, /* 0000 */
+   0x3c, /* 0000 */
+   0x18, /* 00011000 */
+   0x00, /*  */
+   0x00, /*  */
+
+   /* 8 0x08 '^H' */
+   0xff, /*  */
+   0xff, /*  */
+   0xe7, /* 11100111 */
+   0xc3, /* 1111 */
+   0xc3, /* 1111 */
+   0xe7, /* 11100111 */
+   0xff, /*  */
+   0xff, /*  */
+
+   /* 9 0x09 '^I' */
+   0x00, /*  */
+   0x3c, /* 0000 */
+   0x66, /* 01100110 */
+   0x42, /* 0110 */
+   0x42, /* 0110 */
+   0x66, /* 01100110 */
+   0x3c, /* 0000 */
+   0x00, /*  */
+
+   /* 10 0x0a '^J' */
+   0xff, /*  */
+   0xc3, /* 1111 */
+   0x99, /* 10011001 */
+   0xbd, /* 1001 */
+   0xbd, /* 1001 */
+   0x99, /* 10011001 */
+   0xc3, /* 1111 */
+   0xff, /*  */
+
+   /* 11 0x0b '^K' */
+  

[PATCH 2/3] graphic_utils: do not allocate info in fb_open

2017-02-23 Thread Bastian Stender
info was errorneously allocated, but it really is a pointer to a fb_info
struct from the framebuffer. This fixes a memory leak.

Signed-off-by: Bastian Stender 
---
 lib/gui/graphic_utils.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
index f6ab5ea0d1..7d238e9ff9 100644
--- a/lib/gui/graphic_utils.c
+++ b/lib/gui/graphic_utils.c
@@ -277,8 +277,6 @@ struct screen *fb_open(const char * fbdev)
if (fd < 0)
return ERR_PTR(fd);
 
-   info = xzalloc(sizeof(*info));
-
ret = ioctl(fd, FBIOGET_SCREENINFO, &info);
if (ret) {
goto failed_screeninfo;
@@ -291,7 +289,6 @@ struct screen *fb_open(const char * fbdev)
}
 
sc->fd = fd;
-   sc->info = info;
 
return sc;
 
-- 
2.11.0


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


[PATCH 3/3] 2d-primitives: check dimensions in __illuminate

2017-02-23 Thread Bastian Stender
gl_draw_circle draws outside of the screen if the resolution is too low.
This lead to memory corruption. Check the dimensions before drawing.

Signed-off-by: Bastian Stender 
---
 lib/gui/2d-primitives.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/gui/2d-primitives.c b/lib/gui/2d-primitives.c
index f3814eea44..0f29b32bab 100644
--- a/lib/gui/2d-primitives.c
+++ b/lib/gui/2d-primitives.c
@@ -13,6 +13,9 @@ static void __illuminate(struct fb_info *info,
 {
void *pixel;
 
+   if (x < 0 || y < 0 || x >= info->xres || y >= info->yres)
+   return;
+
pixel  = fb_get_screen_base(info);
pixel += y * info->line_length + x * (info->bits_per_pixel >> 3);
 
-- 
2.11.0


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


[PATCH 1/3] graphic_utils: implement 8 bpp color depth in gu_set_pixel

2017-02-23 Thread Bastian Stender
Signed-off-by: Bastian Stender 
---
 lib/gui/graphic_utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
index d3f5cce4b7..f6ab5ea0d1 100644
--- a/lib/gui/graphic_utils.c
+++ b/lib/gui/graphic_utils.c
@@ -132,6 +132,7 @@ void gu_set_pixel(struct fb_info *info, void *adr, u32 px)
 {
switch (info->bits_per_pixel) {
case 8:
+   *(u8 *)adr = px & 0xff;
break;
case 16:
*(u16 *)adr = px & 0x;
-- 
2.11.0


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


[PATCH 1/2] i2c: mv64xxx: add software delays

2017-02-23 Thread Bastian Stender
As stated in Marvell's Functional Specifications in MV-S107021-U0 Rev. A
on page 420 ff. software delays are needed. "SW delay represent a delay
of at least 2 internal clock cycles". These delays are hereby
implemented.

The original kernel driver compensates the needed software delays with
the time the interrupts take.

Signed-off-by: Bastian Stender 
---
 drivers/i2c/busses/i2c-mv64xxx.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 9b9e6c953f..45d5a2b6dc 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -270,6 +270,7 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 
status)
}
/* FALLTHRU */
case STATUS_MAST_RD_DATA_ACK: /* 0x50 */
+   udelay(2);
if (status != STATUS_MAST_RD_DATA_ACK)
drv_data->action = ACTION_CONTINUE;
else {
@@ -280,6 +281,7 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 
status)
 
if (drv_data->bytes_left == 1)
drv_data->cntl_bits &= ~REG_CONTROL_ACK;
+   udelay(2);
break;
 
case STATUS_MAST_RD_DATA_NO_ACK: /* 0x58 */
@@ -318,6 +320,8 @@ static void mv64xxx_i2c_send_start(struct mv64xxx_i2c_data 
*drv_data)
mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
mv64xxx_write(drv_data, drv_data->cntl_bits | REG_CONTROL_START,
drv_data->reg_offsets.control);
+
+   udelay(2);
 }
 
 static void
@@ -333,7 +337,7 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
mv64xxx_i2c_send_start(drv_data);
 
if (drv_data->errata_delay)
-   udelay(5);
+   udelay(3);
 
/*
 * We're never at the start of the message here, and by this
@@ -349,6 +353,7 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
break;
 
case ACTION_SEND_ADDR_1:
+   udelay(2);
mv64xxx_write(drv_data, drv_data->addr1,
drv_data->reg_offsets.data);
mv64xxx_write(drv_data, drv_data->cntl_bits,
@@ -360,9 +365,11 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
drv_data->reg_offsets.data);
mv64xxx_write(drv_data, drv_data->cntl_bits,
drv_data->reg_offsets.control);
+   udelay(2);
break;
 
case ACTION_SEND_DATA:
+   udelay(2);
mv64xxx_write(drv_data, 
drv_data->msg->buf[drv_data->byte_posn++],
drv_data->reg_offsets.data);
mv64xxx_write(drv_data, drv_data->cntl_bits,
@@ -383,8 +390,9 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
mv64xxx_write(drv_data, drv_data->cntl_bits | REG_CONTROL_STOP,
drv_data->reg_offsets.control);
drv_data->block = false;
+   udelay(2);
if (drv_data->errata_delay)
-   udelay(5);
+   udelay(3);
 
break;
 
-- 
2.11.0


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


[PATCH 2/2] i2c: mv64xxx: simplify mv64xxx_i2c_wait_for_completion

2017-02-23 Thread Bastian Stender
Two nested while loops are not necessary here, so integrate the read,
i2c_fsm and i2c_do_action calls into mv64xxx_i2c_wait_for_completion()
and remove the obsolete interrupt remains.

Signed-off-by: Bastian Stender 
---
 drivers/i2c/busses/i2c-mv64xxx.c | 29 -
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 45d5a2b6dc..caece3b78e 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -414,26 +414,6 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
}
 }
 
-static void mv64xxx_i2c_intr(struct mv64xxx_i2c_data *drv_data)
-{
-   u32 status;
-   uint64_t start;
-
-   start = get_time_ns();
-
-   while (mv64xxx_read(drv_data, drv_data->reg_offsets.control) &
-   REG_CONTROL_IFLG) {
-   status = mv64xxx_read(drv_data, drv_data->reg_offsets.status);
-   mv64xxx_i2c_fsm(drv_data, status);
-   mv64xxx_i2c_do_action(drv_data);
-
-   if (is_timeout_non_interruptible(start, 3 * SECOND)) {
-   drv_data->rc = -EIO;
-   break;
-   }
-   }
-}
-
 /*
  *
  *
@@ -444,8 +424,15 @@ static void mv64xxx_i2c_intr(struct mv64xxx_i2c_data 
*drv_data)
 static void
 mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
 {
+   u32 status;
do {
-   mv64xxx_i2c_intr(drv_data);
+   if (mv64xxx_read(drv_data, drv_data->reg_offsets.control) &
+   REG_CONTROL_IFLG) {
+   status = mv64xxx_read(drv_data,
+ drv_data->reg_offsets.status);
+   mv64xxx_i2c_fsm(drv_data, status);
+   mv64xxx_i2c_do_action(drv_data);
+   }
if (drv_data->rc) {
drv_data->state = STATE_IDLE;
dev_err(&drv_data->adapter.dev, "I2C bus error\n");
-- 
2.11.0


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