Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * MIPI-DSI Samsung s6d16d0 panel driver. This is a 864x480
0004  * AMOLED panel with a command-only DSI interface.
0005  */
0006 
0007 #include <drm/drm_modes.h>
0008 #include <drm/drm_mipi_dsi.h>
0009 #include <drm/drm_panel.h>
0010 
0011 #include <linux/gpio/consumer.h>
0012 #include <linux/regulator/consumer.h>
0013 #include <linux/delay.h>
0014 #include <linux/of_device.h>
0015 #include <linux/module.h>
0016 
0017 struct s6d16d0 {
0018     struct device *dev;
0019     struct drm_panel panel;
0020     struct regulator *supply;
0021     struct gpio_desc *reset_gpio;
0022 };
0023 
0024 /*
0025  * The timings are not very helpful as the display is used in
0026  * command mode.
0027  */
0028 static const struct drm_display_mode samsung_s6d16d0_mode = {
0029     /* HS clock, (htotal*vtotal*vrefresh)/1000 */
0030     .clock = 420160,
0031     .hdisplay = 864,
0032     .hsync_start = 864 + 154,
0033     .hsync_end = 864 + 154 + 16,
0034     .htotal = 864 + 154 + 16 + 32,
0035     .vdisplay = 480,
0036     .vsync_start = 480 + 1,
0037     .vsync_end = 480 + 1 + 1,
0038     .vtotal = 480 + 1 + 1 + 1,
0039     .width_mm = 84,
0040     .height_mm = 48,
0041 };
0042 
0043 static inline struct s6d16d0 *panel_to_s6d16d0(struct drm_panel *panel)
0044 {
0045     return container_of(panel, struct s6d16d0, panel);
0046 }
0047 
0048 static int s6d16d0_unprepare(struct drm_panel *panel)
0049 {
0050     struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
0051     struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
0052     int ret;
0053 
0054     /* Enter sleep mode */
0055     ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
0056     if (ret) {
0057         dev_err(s6->dev, "failed to enter sleep mode (%d)\n", ret);
0058         return ret;
0059     }
0060 
0061     /* Assert RESET */
0062     gpiod_set_value_cansleep(s6->reset_gpio, 1);
0063     regulator_disable(s6->supply);
0064 
0065     return 0;
0066 }
0067 
0068 static int s6d16d0_prepare(struct drm_panel *panel)
0069 {
0070     struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
0071     struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
0072     int ret;
0073 
0074     ret = regulator_enable(s6->supply);
0075     if (ret) {
0076         dev_err(s6->dev, "failed to enable supply (%d)\n", ret);
0077         return ret;
0078     }
0079 
0080     /* Assert RESET */
0081     gpiod_set_value_cansleep(s6->reset_gpio, 1);
0082     udelay(10);
0083     /* De-assert RESET */
0084     gpiod_set_value_cansleep(s6->reset_gpio, 0);
0085     msleep(120);
0086 
0087     /* Enabe tearing mode: send TE (tearing effect) at VBLANK */
0088     ret = mipi_dsi_dcs_set_tear_on(dsi,
0089                        MIPI_DSI_DCS_TEAR_MODE_VBLANK);
0090     if (ret) {
0091         dev_err(s6->dev, "failed to enable vblank TE (%d)\n", ret);
0092         return ret;
0093     }
0094     /* Exit sleep mode and power on */
0095     ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
0096     if (ret) {
0097         dev_err(s6->dev, "failed to exit sleep mode (%d)\n", ret);
0098         return ret;
0099     }
0100 
0101     return 0;
0102 }
0103 
0104 static int s6d16d0_enable(struct drm_panel *panel)
0105 {
0106     struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
0107     struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
0108     int ret;
0109 
0110     ret = mipi_dsi_dcs_set_display_on(dsi);
0111     if (ret) {
0112         dev_err(s6->dev, "failed to turn display on (%d)\n", ret);
0113         return ret;
0114     }
0115 
0116     return 0;
0117 }
0118 
0119 static int s6d16d0_disable(struct drm_panel *panel)
0120 {
0121     struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
0122     struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
0123     int ret;
0124 
0125     ret = mipi_dsi_dcs_set_display_off(dsi);
0126     if (ret) {
0127         dev_err(s6->dev, "failed to turn display off (%d)\n", ret);
0128         return ret;
0129     }
0130 
0131     return 0;
0132 }
0133 
0134 static int s6d16d0_get_modes(struct drm_panel *panel,
0135                  struct drm_connector *connector)
0136 {
0137     struct drm_display_mode *mode;
0138 
0139     mode = drm_mode_duplicate(connector->dev, &samsung_s6d16d0_mode);
0140     if (!mode) {
0141         dev_err(panel->dev, "bad mode or failed to add mode\n");
0142         return -EINVAL;
0143     }
0144     drm_mode_set_name(mode);
0145     mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
0146 
0147     connector->display_info.width_mm = mode->width_mm;
0148     connector->display_info.height_mm = mode->height_mm;
0149 
0150     drm_mode_probed_add(connector, mode);
0151 
0152     return 1; /* Number of modes */
0153 }
0154 
0155 static const struct drm_panel_funcs s6d16d0_drm_funcs = {
0156     .disable = s6d16d0_disable,
0157     .unprepare = s6d16d0_unprepare,
0158     .prepare = s6d16d0_prepare,
0159     .enable = s6d16d0_enable,
0160     .get_modes = s6d16d0_get_modes,
0161 };
0162 
0163 static int s6d16d0_probe(struct mipi_dsi_device *dsi)
0164 {
0165     struct device *dev = &dsi->dev;
0166     struct s6d16d0 *s6;
0167     int ret;
0168 
0169     s6 = devm_kzalloc(dev, sizeof(struct s6d16d0), GFP_KERNEL);
0170     if (!s6)
0171         return -ENOMEM;
0172 
0173     mipi_dsi_set_drvdata(dsi, s6);
0174     s6->dev = dev;
0175 
0176     dsi->lanes = 2;
0177     dsi->format = MIPI_DSI_FMT_RGB888;
0178     dsi->hs_rate = 420160000;
0179     dsi->lp_rate = 19200000;
0180     /*
0181      * This display uses command mode so no MIPI_DSI_MODE_VIDEO
0182      * or MIPI_DSI_MODE_VIDEO_SYNC_PULSE
0183      *
0184      * As we only send commands we do not need to be continuously
0185      * clocked.
0186      */
0187     dsi->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS;
0188 
0189     s6->supply = devm_regulator_get(dev, "vdd1");
0190     if (IS_ERR(s6->supply))
0191         return PTR_ERR(s6->supply);
0192 
0193     /* This asserts RESET by default */
0194     s6->reset_gpio = devm_gpiod_get_optional(dev, "reset",
0195                          GPIOD_OUT_HIGH);
0196     if (IS_ERR(s6->reset_gpio)) {
0197         ret = PTR_ERR(s6->reset_gpio);
0198         if (ret != -EPROBE_DEFER)
0199             dev_err(dev, "failed to request GPIO (%d)\n", ret);
0200         return ret;
0201     }
0202 
0203     drm_panel_init(&s6->panel, dev, &s6d16d0_drm_funcs,
0204                DRM_MODE_CONNECTOR_DSI);
0205 
0206     drm_panel_add(&s6->panel);
0207 
0208     ret = mipi_dsi_attach(dsi);
0209     if (ret < 0)
0210         drm_panel_remove(&s6->panel);
0211 
0212     return ret;
0213 }
0214 
0215 static int s6d16d0_remove(struct mipi_dsi_device *dsi)
0216 {
0217     struct s6d16d0 *s6 = mipi_dsi_get_drvdata(dsi);
0218 
0219     mipi_dsi_detach(dsi);
0220     drm_panel_remove(&s6->panel);
0221 
0222     return 0;
0223 }
0224 
0225 static const struct of_device_id s6d16d0_of_match[] = {
0226     { .compatible = "samsung,s6d16d0" },
0227     { }
0228 };
0229 MODULE_DEVICE_TABLE(of, s6d16d0_of_match);
0230 
0231 static struct mipi_dsi_driver s6d16d0_driver = {
0232     .probe = s6d16d0_probe,
0233     .remove = s6d16d0_remove,
0234     .driver = {
0235         .name = "panel-samsung-s6d16d0",
0236         .of_match_table = s6d16d0_of_match,
0237     },
0238 };
0239 module_mipi_dsi_driver(s6d16d0_driver);
0240 
0241 MODULE_AUTHOR("Linus Wallei <linus.walleij@linaro.org>");
0242 MODULE_DESCRIPTION("MIPI-DSI s6d16d0 Panel Driver");
0243 MODULE_LICENSE("GPL v2");