Skip to content

Commit a55863b

Browse files
drm/sitronix/st7571-i2c: Add support for the ST7567 Controller
The Sitronix ST7567 is a monochrome Dot Matrix LCD Controller that has SPI, I2C and parallel interfaces. The st7571-i2c driver only has support for I2C so displays using other transport interfaces are currently not supported. The DRM_FORMAT_R1 pixel format and data commands are the same than what is used by the ST7571 controller, so only is needed a different callback that implements the expected initialization sequence for the ST7567 chip. Reviewed-by: Marcus Folkesson <[email protected]> Reviewed-by: Thomas Zimmermann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Javier Martinez Canillas <[email protected]>
1 parent d2bfb99 commit a55863b

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

drivers/gpu/drm/sitronix/st7571-i2c.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
#define ST7571_SET_COLOR_MODE(c) (0x10 | FIELD_PREP(GENMASK(0, 0), (c)))
6969
#define ST7571_COMMAND_SET_NORMAL (0x00)
7070

71+
/* ST7567 commands */
72+
#define ST7567_SET_LCD_BIAS(m) (0xa2 | FIELD_PREP(GENMASK(0, 0), (m)))
73+
7174
#define ST7571_PAGE_HEIGHT 8
7275

7376
#define DRIVER_NAME "st7571"
@@ -774,6 +777,32 @@ static int st7571_validate_parameters(struct st7571_device *st7571)
774777
return 0;
775778
}
776779

780+
static int st7567_parse_dt(struct st7571_device *st7567)
781+
{
782+
struct device *dev = &st7567->client->dev;
783+
struct device_node *np = dev->of_node;
784+
struct display_timing dt;
785+
int ret;
786+
787+
ret = of_get_display_timing(np, "panel-timing", &dt);
788+
if (ret) {
789+
dev_err(dev, "Failed to get display timing from DT\n");
790+
return ret;
791+
}
792+
793+
of_property_read_u32(np, "width-mm", &st7567->width_mm);
794+
of_property_read_u32(np, "height-mm", &st7567->height_mm);
795+
796+
st7567->pformat = &st7571_monochrome;
797+
st7567->bpp = 1;
798+
799+
st7567->startline = dt.vfront_porch.typ;
800+
st7567->nlines = dt.vactive.typ;
801+
st7567->ncols = dt.hactive.typ;
802+
803+
return 0;
804+
}
805+
777806
static int st7571_parse_dt(struct st7571_device *st7571)
778807
{
779808
struct device *dev = &st7571->client->dev;
@@ -819,6 +848,38 @@ static void st7571_reset(struct st7571_device *st7571)
819848
gpiod_set_value_cansleep(st7571->reset, 0);
820849
}
821850

851+
static int st7567_lcd_init(struct st7571_device *st7567)
852+
{
853+
/*
854+
* Most of the initialization sequence is taken directly from the
855+
* referential initial code in the ST7567 datasheet.
856+
*/
857+
u8 commands[] = {
858+
ST7571_DISPLAY_OFF,
859+
860+
ST7567_SET_LCD_BIAS(1),
861+
862+
ST7571_SET_SEG_SCAN_DIR(0),
863+
ST7571_SET_COM_SCAN_DIR(1),
864+
865+
ST7571_SET_REGULATOR_REG(4),
866+
ST7571_SET_CONTRAST_MSB,
867+
ST7571_SET_CONTRAST_LSB(0x20),
868+
869+
ST7571_SET_START_LINE_MSB,
870+
ST7571_SET_START_LINE_LSB(st7567->startline),
871+
872+
ST7571_SET_POWER(0x4), /* Power Control, VC: ON, VR: OFF, VF: OFF */
873+
ST7571_SET_POWER(0x6), /* Power Control, VC: ON, VR: ON, VF: OFF */
874+
ST7571_SET_POWER(0x7), /* Power Control, VC: ON, VR: ON, VF: ON */
875+
876+
ST7571_SET_REVERSE(0),
877+
ST7571_SET_ENTIRE_DISPLAY_ON(0),
878+
};
879+
880+
return st7571_send_command_list(st7567, commands, ARRAY_SIZE(commands));
881+
}
882+
822883
static int st7571_lcd_init(struct st7571_device *st7571)
823884
{
824885
/*
@@ -963,6 +1024,18 @@ static void st7571_remove(struct i2c_client *client)
9631024
drm_dev_unplug(&st7571->dev);
9641025
}
9651026

1027+
struct st7571_panel_data st7567_config = {
1028+
.init = st7567_lcd_init,
1029+
.parse_dt = st7567_parse_dt,
1030+
.constraints = {
1031+
.min_nlines = 1,
1032+
.max_nlines = 64,
1033+
.min_ncols = 128,
1034+
.max_ncols = 128,
1035+
.support_grayscale = false,
1036+
},
1037+
};
1038+
9661039
struct st7571_panel_data st7571_config = {
9671040
.init = st7571_lcd_init,
9681041
.parse_dt = st7571_parse_dt,
@@ -976,12 +1049,14 @@ struct st7571_panel_data st7571_config = {
9761049
};
9771050

9781051
static const struct of_device_id st7571_of_match[] = {
1052+
{ .compatible = "sitronix,st7567", .data = &st7567_config },
9791053
{ .compatible = "sitronix,st7571", .data = &st7571_config },
9801054
{},
9811055
};
9821056
MODULE_DEVICE_TABLE(of, st7571_of_match);
9831057

9841058
static const struct i2c_device_id st7571_id[] = {
1059+
{ "st7567", 0 },
9851060
{ "st7571", 0 },
9861061
{ }
9871062
};

0 commit comments

Comments
 (0)