Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panel: Add support for Olimex LCD-OLinuXino panel

This patch adds Olimex Ltd. LCD-OLinuXino bridge panel driver. The panel
is used with different LCDs (currently from 480x272 to 1280x800). A
small EEPROM chip is used for identification, which holds some factory
data and timing requirements.

Signed-off-by: Stefan Mavrodiev <stefan@olimex.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1531383729-13932-1-git-send-email-stefan@olimex.com

authored by

Stefan Mavrodiev and committed by
Thierry Reding
17fd7a9d 6cbe7cd1

+391
+42
Documentation/devicetree/bindings/display/panel/olimex,lcd-olinuxino.txt
··· 1 + Binding for Olimex Ltd. LCD-OLinuXino bridge panel. 2 + 3 + This device can be used as bridge between a host controller and LCD panels. 4 + Currently supported LCDs are: 5 + - LCD-OLinuXino-4.3TS 6 + - LCD-OLinuXino-5 7 + - LCD-OLinuXino-7 8 + - LCD-OLinuXino-10 9 + 10 + The panel itself contains: 11 + - AT24C16C EEPROM holding panel identification and timing requirements 12 + - AR1021 resistive touch screen controller (optional) 13 + - FT5x6 capacitive touch screnn controller (optional) 14 + - GT911/GT928 capacitive touch screen controller (optional) 15 + 16 + The above chips share same I2C bus. The EEPROM is factory preprogrammed with 17 + device information (id, serial, etc.) and timing requirements. 18 + 19 + Touchscreen bingings can be found in these files: 20 + - input/touchscreen/goodix.txt 21 + - input/touchscreen/edt-ft5x06.txt 22 + - input/touchscreen/ar1021.txt 23 + 24 + Required properties: 25 + - compatible: should be "olimex,lcd-olinuxino" 26 + - reg: address of the configuration EEPROM, should be <0x50> 27 + - power-supply: phandle of the regulator that provides the supply voltage 28 + 29 + Optional properties: 30 + - enable-gpios: GPIO pin to enable or disable the panel 31 + - backlight: phandle of the backlight device attacked to the panel 32 + 33 + Example: 34 + &i2c2 { 35 + panel@50 { 36 + compatible = "olimex,lcd-olinuxino"; 37 + reg = <0x50>; 38 + power-supply = <&reg_vcc5v0>; 39 + enable-gpios = <&pio 7 8 GPIO_ACTIVE_HIGH>; 40 + backlight = <&backlight>; 41 + }; 42 + };
+6
MAINTAINERS
··· 4664 4664 F: drivers/gpu/drm/nouveau/ 4665 4665 F: include/uapi/drm/nouveau_drm.h 4666 4666 4667 + DRM DRIVER FOR OLIMEX LCD-OLINUXINO PANELS 4668 + M: Stefan Mavrodiev <stefan@olimex.com> 4669 + S: Maintained 4670 + F: drivers/gpu/drm/panel/panel-olimex-lcd-olinuxino.c 4671 + F: Documentation/devicetree/bindings/display/panel/olimex,lcd-olinuxino.txt 4672 + 4667 4673 DRM DRIVER FOR PERVASIVE DISPLAYS REPAPER PANELS 4668 4674 M: Noralf Trønnes <noralf@tronnes.org> 4669 4675 S: Maintained
+12
drivers/gpu/drm/panel/Kconfig
··· 90 90 Say Y here if you want to enable support for LG4573 RGB panel. 91 91 To compile this driver as a module, choose M here. 92 92 93 + config DRM_PANEL_OLIMEX_LCD_OLINUXINO 94 + tristate "Olimex LCD-OLinuXino panel" 95 + depends on OF 96 + depends on I2C 97 + depends on BACKLIGHT_CLASS_DEVICE 98 + help 99 + The panel is used with different sizes LCDs, from 480x272 to 100 + 1280x800, and 24 bit per pixel. 101 + 102 + Say Y here if you want to enable support for Olimex Ltd. 103 + LCD-OLinuXino panel. 104 + 93 105 config DRM_PANEL_ORISETECH_OTM8009A 94 106 tristate "Orise Technology otm8009a 480x800 dsi 2dl panel" 95 107 depends on OF
+1
drivers/gpu/drm/panel/Makefile
··· 7 7 obj-$(CONFIG_DRM_PANEL_INNOLUX_P079ZCA) += panel-innolux-p079zca.o 8 8 obj-$(CONFIG_DRM_PANEL_JDI_LT070ME05000) += panel-jdi-lt070me05000.o 9 9 obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o 10 + obj-$(CONFIG_DRM_PANEL_OLIMEX_LCD_OLINUXINO) += panel-olimex-lcd-olinuxino.o 10 11 obj-$(CONFIG_DRM_PANEL_ORISETECH_OTM8009A) += panel-orisetech-otm8009a.o 11 12 obj-$(CONFIG_DRM_PANEL_PANASONIC_VVX10F034N00) += panel-panasonic-vvx10f034n00.o 12 13 obj-$(CONFIG_DRM_PANEL_RASPBERRYPI_TOUCHSCREEN) += panel-raspberrypi-touchscreen.o
+330
drivers/gpu/drm/panel/panel-olimex-lcd-olinuxino.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * LCD-OLinuXino support for panel driver 4 + * 5 + * Copyright (C) 2018 Olimex Ltd. 6 + * Author: Stefan Mavrodiev <stefan@olimex.com> 7 + */ 8 + 9 + #include <linux/backlight.h> 10 + #include <linux/crc32.h> 11 + #include <linux/gpio/consumer.h> 12 + #include <linux/i2c.h> 13 + #include <linux/module.h> 14 + #include <linux/mutex.h> 15 + #include <linux/of.h> 16 + #include <linux/regulator/consumer.h> 17 + 18 + #include <drm/drm_modes.h> 19 + #include <drm/drm_panel.h> 20 + #include <drm/drmP.h> 21 + 22 + #include <video/videomode.h> 23 + #include <video/display_timing.h> 24 + 25 + #define LCD_OLINUXINO_HEADER_MAGIC 0x4F4CB727 26 + #define LCD_OLINUXINO_DATA_LEN 256 27 + 28 + struct lcd_olinuxino_mode { 29 + u32 pixelclock; 30 + u32 hactive; 31 + u32 hfp; 32 + u32 hbp; 33 + u32 hpw; 34 + u32 vactive; 35 + u32 vfp; 36 + u32 vbp; 37 + u32 vpw; 38 + u32 refresh; 39 + u32 flags; 40 + }; 41 + 42 + struct lcd_olinuxino_info { 43 + char name[32]; 44 + u32 width_mm; 45 + u32 height_mm; 46 + u32 bpc; 47 + u32 bus_format; 48 + u32 bus_flag; 49 + } __attribute__((__packed__)); 50 + 51 + struct lcd_olinuxino_eeprom { 52 + u32 header; 53 + u32 id; 54 + char revision[4]; 55 + u32 serial; 56 + struct lcd_olinuxino_info info; 57 + u32 num_modes; 58 + u8 reserved[180]; 59 + u32 checksum; 60 + } __attribute__((__packed__)); 61 + 62 + struct lcd_olinuxino { 63 + struct drm_panel panel; 64 + struct device *dev; 65 + struct i2c_client *client; 66 + struct mutex mutex; 67 + 68 + bool prepared; 69 + bool enabled; 70 + 71 + struct backlight_device *backlight; 72 + struct regulator *supply; 73 + struct gpio_desc *enable_gpio; 74 + 75 + struct lcd_olinuxino_eeprom eeprom; 76 + }; 77 + 78 + static inline struct lcd_olinuxino *to_lcd_olinuxino(struct drm_panel *panel) 79 + { 80 + return container_of(panel, struct lcd_olinuxino, panel); 81 + } 82 + 83 + static int lcd_olinuxino_disable(struct drm_panel *panel) 84 + { 85 + struct lcd_olinuxino *lcd = to_lcd_olinuxino(panel); 86 + 87 + if (!lcd->enabled) 88 + return 0; 89 + 90 + backlight_disable(lcd->backlight); 91 + 92 + lcd->enabled = false; 93 + 94 + return 0; 95 + } 96 + 97 + static int lcd_olinuxino_unprepare(struct drm_panel *panel) 98 + { 99 + struct lcd_olinuxino *lcd = to_lcd_olinuxino(panel); 100 + 101 + if (!lcd->prepared) 102 + return 0; 103 + 104 + gpiod_set_value_cansleep(lcd->enable_gpio, 0); 105 + regulator_disable(lcd->supply); 106 + 107 + lcd->prepared = false; 108 + 109 + return 0; 110 + } 111 + 112 + static int lcd_olinuxino_prepare(struct drm_panel *panel) 113 + { 114 + struct lcd_olinuxino *lcd = to_lcd_olinuxino(panel); 115 + int ret; 116 + 117 + if (lcd->prepared) 118 + return 0; 119 + 120 + ret = regulator_enable(lcd->supply); 121 + if (ret < 0) 122 + return ret; 123 + 124 + gpiod_set_value_cansleep(lcd->enable_gpio, 1); 125 + lcd->prepared = true; 126 + 127 + return 0; 128 + } 129 + 130 + static int lcd_olinuxino_enable(struct drm_panel *panel) 131 + { 132 + struct lcd_olinuxino *lcd = to_lcd_olinuxino(panel); 133 + 134 + if (lcd->enabled) 135 + return 0; 136 + 137 + backlight_enable(lcd->backlight); 138 + 139 + lcd->enabled = true; 140 + 141 + return 0; 142 + } 143 + 144 + static int lcd_olinuxino_get_modes(struct drm_panel *panel) 145 + { 146 + struct lcd_olinuxino *lcd = to_lcd_olinuxino(panel); 147 + struct drm_connector *connector = lcd->panel.connector; 148 + struct lcd_olinuxino_info *lcd_info = &lcd->eeprom.info; 149 + struct drm_device *drm = lcd->panel.drm; 150 + struct lcd_olinuxino_mode *lcd_mode; 151 + struct drm_display_mode *mode; 152 + u32 i, num = 0; 153 + 154 + for (i = 0; i < lcd->eeprom.num_modes; i++) { 155 + lcd_mode = (struct lcd_olinuxino_mode *) 156 + &lcd->eeprom.reserved[i * sizeof(*lcd_mode)]; 157 + 158 + mode = drm_mode_create(drm); 159 + if (!mode) { 160 + dev_err(drm->dev, "failed to add mode %ux%u@%u\n", 161 + lcd_mode->hactive, 162 + lcd_mode->vactive, 163 + lcd_mode->refresh); 164 + continue; 165 + } 166 + 167 + mode->clock = lcd_mode->pixelclock; 168 + mode->hdisplay = lcd_mode->hactive; 169 + mode->hsync_start = lcd_mode->hactive + lcd_mode->hfp; 170 + mode->hsync_end = lcd_mode->hactive + lcd_mode->hfp + 171 + lcd_mode->hpw; 172 + mode->htotal = lcd_mode->hactive + lcd_mode->hfp + 173 + lcd_mode->hpw + lcd_mode->hbp; 174 + mode->vdisplay = lcd_mode->vactive; 175 + mode->vsync_start = lcd_mode->vactive + lcd_mode->vfp; 176 + mode->vsync_end = lcd_mode->vactive + lcd_mode->vfp + 177 + lcd_mode->vpw; 178 + mode->vtotal = lcd_mode->vactive + lcd_mode->vfp + 179 + lcd_mode->vpw + lcd_mode->vbp; 180 + mode->vrefresh = lcd_mode->refresh; 181 + 182 + /* Always make the first mode preferred */ 183 + if (i == 0) 184 + mode->type |= DRM_MODE_TYPE_PREFERRED; 185 + mode->type |= DRM_MODE_TYPE_DRIVER; 186 + 187 + drm_mode_set_name(mode); 188 + drm_mode_probed_add(connector, mode); 189 + 190 + num++; 191 + } 192 + 193 + memcpy(connector->display_info.name, lcd_info->name, 32); 194 + connector->display_info.width_mm = lcd_info->width_mm; 195 + connector->display_info.height_mm = lcd_info->height_mm; 196 + connector->display_info.bpc = lcd_info->bpc; 197 + 198 + if (lcd_info->bus_format) 199 + drm_display_info_set_bus_formats(&connector->display_info, 200 + &lcd_info->bus_format, 1); 201 + connector->display_info.bus_flags = lcd_info->bus_flag; 202 + 203 + return num; 204 + } 205 + 206 + static const struct drm_panel_funcs lcd_olinuxino_funcs = { 207 + .disable = lcd_olinuxino_disable, 208 + .unprepare = lcd_olinuxino_unprepare, 209 + .prepare = lcd_olinuxino_prepare, 210 + .enable = lcd_olinuxino_enable, 211 + .get_modes = lcd_olinuxino_get_modes, 212 + }; 213 + 214 + static int lcd_olinuxino_probe(struct i2c_client *client, 215 + const struct i2c_device_id *id) 216 + { 217 + struct device *dev = &client->dev; 218 + struct lcd_olinuxino *lcd; 219 + u32 checksum, i; 220 + int ret = 0; 221 + 222 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 223 + I2C_FUNC_SMBUS_READ_I2C_BLOCK)) 224 + return -ENODEV; 225 + 226 + lcd = devm_kzalloc(dev, sizeof(*lcd), GFP_KERNEL); 227 + if (!lcd) 228 + return -ENOMEM; 229 + 230 + i2c_set_clientdata(client, lcd); 231 + lcd->dev = dev; 232 + lcd->client = client; 233 + 234 + mutex_init(&lcd->mutex); 235 + 236 + /* Copy data into buffer */ 237 + for (i = 0; i < LCD_OLINUXINO_DATA_LEN; i += I2C_SMBUS_BLOCK_MAX) { 238 + mutex_lock(&lcd->mutex); 239 + ret = i2c_smbus_read_i2c_block_data(client, 240 + i, 241 + I2C_SMBUS_BLOCK_MAX, 242 + (u8 *)&lcd->eeprom + i); 243 + mutex_unlock(&lcd->mutex); 244 + if (ret < 0) { 245 + dev_err(dev, "error reading from device at %02x\n", i); 246 + return ret; 247 + } 248 + } 249 + 250 + /* Check configuration checksum */ 251 + checksum = ~crc32(~0, (u8 *)&lcd->eeprom, 252); 252 + if (checksum != lcd->eeprom.checksum) { 253 + dev_err(dev, "configuration checksum does not match!\n"); 254 + return -EINVAL; 255 + } 256 + 257 + /* Check magic header */ 258 + if (lcd->eeprom.header != LCD_OLINUXINO_HEADER_MAGIC) { 259 + dev_err(dev, "magic header does not match\n"); 260 + return -EINVAL; 261 + } 262 + 263 + dev_info(dev, "Detected %s, Rev. %s, Serial: %08x\n", 264 + lcd->eeprom.info.name, 265 + lcd->eeprom.revision, 266 + lcd->eeprom.serial); 267 + 268 + /* 269 + * The eeprom can hold up to 4 modes. 270 + * If the stored value is bigger, overwrite it. 271 + */ 272 + if (lcd->eeprom.num_modes > 4) { 273 + dev_warn(dev, "invalid number of modes, falling back to 4\n"); 274 + lcd->eeprom.num_modes = 4; 275 + } 276 + 277 + lcd->enabled = false; 278 + lcd->prepared = false; 279 + 280 + lcd->supply = devm_regulator_get(dev, "power"); 281 + if (IS_ERR(lcd->supply)) 282 + return PTR_ERR(lcd->supply); 283 + 284 + lcd->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); 285 + if (IS_ERR(lcd->enable_gpio)) 286 + return PTR_ERR(lcd->enable_gpio); 287 + 288 + lcd->backlight = devm_of_find_backlight(dev); 289 + if (IS_ERR(lcd->backlight)) 290 + return PTR_ERR(lcd->backlight); 291 + 292 + drm_panel_init(&lcd->panel); 293 + lcd->panel.dev = dev; 294 + lcd->panel.funcs = &lcd_olinuxino_funcs; 295 + 296 + return drm_panel_add(&lcd->panel); 297 + } 298 + 299 + static int lcd_olinuxino_remove(struct i2c_client *client) 300 + { 301 + struct lcd_olinuxino *panel = i2c_get_clientdata(client); 302 + 303 + drm_panel_remove(&panel->panel); 304 + 305 + lcd_olinuxino_disable(&panel->panel); 306 + lcd_olinuxino_unprepare(&panel->panel); 307 + 308 + return 0; 309 + } 310 + 311 + static const struct of_device_id lcd_olinuxino_of_ids[] = { 312 + { .compatible = "olimex,lcd-olinuxino" }, 313 + { } 314 + }; 315 + MODULE_DEVICE_TABLE(of, lcd_olinuxino_of_ids); 316 + 317 + static struct i2c_driver lcd_olinuxino_driver = { 318 + .driver = { 319 + .name = "lcd_olinuxino", 320 + .of_match_table = lcd_olinuxino_of_ids, 321 + }, 322 + .probe = lcd_olinuxino_probe, 323 + .remove = lcd_olinuxino_remove, 324 + }; 325 + 326 + module_i2c_driver(lcd_olinuxino_driver); 327 + 328 + MODULE_AUTHOR("Stefan Mavrodiev <stefan@olimex.com>"); 329 + MODULE_DESCRIPTION("LCD-OLinuXino driver"); 330 + MODULE_LICENSE("GPL");