<div dir="ltr"><div>Hi Sam,</div><div><br></div><div>  Thanks for your comments, i will rework this panel driver after l3gd20 patch submission.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Sam Ravnborg <<a href="mailto:sam@ravnborg.org">sam@ravnborg.org</a>> 于2020年5月8日周五 下午5:02写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Dillon.<br>
<br>
Patch submissions starts to look fine.<br>
<br>
On Fri, May 08, 2020 at 12:13:14PM +0800, <a href="mailto:dillon.minfei@gmail.com" target="_blank">dillon.minfei@gmail.com</a> wrote:<br>
> From: dillon min <<a href="mailto:dillon.minfei@gmail.com" target="_blank">dillon.minfei@gmail.com</a>><br>
> <br>
> This is a driver for 320x240 TFT panels, accepting a rgb input<br>
> streams that get adapted and scaled to the panel.<br>
This driver is, I suppose, prepared to be a driver for ILI9341 based<br>
panles, and as such not for a fixed resolution.<br>
I expect (hope) we in the future will see more panels added.<br>
<br></blockquote><div>As i checked ili9341 datasheets, this panel just support 240x320 resolution only.  if i'm wrong , please correct me. thanks</div><div><a href="https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf">https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf</a><br></div><div><br></div><div>This panel can support 9 different kinds of interface , "3/4-line Serial Interface" have been supported by tiny/ili9341.c. i was verified it</div><div>but the performance on stm32f4 is very low. </div><div><br></div><div>currently, i just have stm32f429-disco in hands, with 18-bit parallel rgb bus connected on this board. reference to panel-ilitek-ili9322 and panel-ilitek-ili9881 driver, i have some plan to rewrite this driver. </div><div><br></div><div>1 add your below comments in.</div><div>2 use dc-gpio, reset-gpio, rgb-interface-bits from dts to config panel interface.</div><div>3 drop regmap, porting drm_mipi_dbi's mipi_dbi_command to config panel paramter. like tiny/ili9341.c</div><div>4 support rgb-16, rgb-18 interface.</div><div>5 use optional regulator or power gpio to control panel's power, as panel power is always on for my board, so i can't test this part. could i add the code which can't be tested?</div><div>6 support rotation in panel config (currently , i rotate the screen by kernel cmdline paramter)</div><div><br></div><div>if you have any other common panel configuration should be add , please inform me.</div><div><br></div><div>thanks.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Some things to fix, see comments in the follwoing.<br>
<br>
        Sam<br>
<br>
> <br>
> Signed-off-by: dillon min <<a href="mailto:dillon.minfei@gmail.com" target="_blank">dillon.minfei@gmail.com</a>><br>
> ---<br>
>  drivers/gpu/drm/panel/Kconfig                |   8 +<br>
>  drivers/gpu/drm/panel/Makefile               |   1 +<br>
>  drivers/gpu/drm/panel/panel-ilitek-ili9341.c | 561 +++++++++++++++++++++++++++<br>
>  3 files changed, 570 insertions(+)<br>
>  create mode 100644 drivers/gpu/drm/panel/panel-ilitek-ili9341.c<br>
> <br>
> diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig<br>
> index a1723c1..e42692c 100644<br>
> --- a/drivers/gpu/drm/panel/Kconfig<br>
> +++ b/drivers/gpu/drm/panel/Kconfig<br>
> @@ -95,6 +95,14 @@ config DRM_PANEL_ILITEK_IL9322<br>
>         Say Y here if you want to enable support for Ilitek IL9322<br>
>         QVGA (320x240) RGB, YUV and ITU-T BT.656 panels.<br>
>  <br>
> +config DRM_PANEL_ILITEK_IL9341<br>
ILI9341 - so the config name matches the name of the driver IC.<br>
<br>
> +     tristate "Ilitek ILI9341 240x320 QVGA panels"<br>
> +     depends on OF && SPI<br>
> +     select REGMAP<br>
> +     help<br>
> +       Say Y here if you want to enable support for Ilitek IL9341<br>
> +       QVGA (240x320) RGB panels.<br>
See comment to the changelog, the driver is more generic - I assume.<br>
So the wording here can be improved to express this.<br>
<br></blockquote><div>Add support RGB 16bits and RGB 18bits bus only ? </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +<br>
>  config DRM_PANEL_ILITEK_ILI9881C<br>
>       tristate "Ilitek ILI9881C-based panels"<br>
>       depends on OF<br>
> diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile<br>
> index 96a883c..d123543 100644<br>
> --- a/drivers/gpu/drm/panel/Makefile<br>
> +++ b/drivers/gpu/drm/panel/Makefile<br>
> @@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_PANEL_ELIDA_KD35T133) += panel-elida-kd35t133.o<br>
>  obj-$(CONFIG_DRM_PANEL_FEIXIN_K101_IM2BA02) += panel-feixin-k101-im2ba02.o<br>
>  obj-$(CONFIG_DRM_PANEL_FEIYANG_FY07024DI26A30D) += panel-feiyang-fy07024di26a30d.o<br>
>  obj-$(CONFIG_DRM_PANEL_ILITEK_IL9322) += panel-ilitek-ili9322.o<br>
> +obj-$(CONFIG_DRM_PANEL_ILITEK_IL9341) += panel-ilitek-ili9341.o<br>
>  obj-$(CONFIG_DRM_PANEL_ILITEK_ILI9881C) += panel-ilitek-ili9881c.o<br>
>  obj-$(CONFIG_DRM_PANEL_INNOLUX_P079ZCA) += panel-innolux-p079zca.o<br>
>  obj-$(CONFIG_DRM_PANEL_JDI_LT070ME05000) += panel-jdi-lt070me05000.o<br>
> diff --git a/drivers/gpu/drm/panel/panel-ilitek-ili9341.c b/drivers/gpu/drm/panel/panel-ilitek-ili9341.c<br>
> new file mode 100644<br>
> index 0000000..ec22d80<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/panel/panel-ilitek-ili9341.c<br>
> @@ -0,0 +1,561 @@<br>
> +// SPDX-License-Identifier: GPL-2.0-only<br>
> +/*<br>
> + * Ilitek ILI9341 TFT LCD drm_panel driver.<br>
> + *<br>
> + * This panel can be configured to support:<br>
> + * - 16-bit parallel RGB interface<br>
The interface to ILI9341 is SPI, and the interface between the ILI9341<br>
and the panel is more of an itnernal thing. Or did I get this worng?<br>
<br></blockquote><div>SPI is for register configuration.  RGB parallel for data transfer</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + *<br>
> + * Copyright (C) 2020 Dillon Min <<a href="mailto:dillon.minfei@gmail.com" target="_blank">dillon.minfei@gmail.com</a>><br>
> + * Derived from drivers/drm/gpu/panel/panel-ilitek-ili9322.c<br>
> + */<br>
> +<br>
> +#include <linux/bitops.h><br>
> +#include <linux/gpio/consumer.h><br>
> +#include <linux/module.h><br>
> +#include <linux/of_device.h><br>
> +#include <linux/regmap.h><br>
> +#include <linux/regulator/consumer.h><br>
> +#include <linux/spi/spi.h><br>
> +<br>
> +#include <video/mipi_display.h><br>
> +#include <video/of_videomode.h><br>
> +#include <video/videomode.h><br>
> +<br>
> +#include <drm/drm_modes.h><br>
> +#include <drm/drm_panel.h><br>
> +#include <drm/drm_print.h><br>
> +<br>
> +#define DEFAULT_SPI_SPEED    10000000<br>
> +<br>
<br>
Please use same case for hex numbers in the driver.<br>
My personal preferences is lower-case.<br>
<br></blockquote><div>in next patch, spi speed will be configured by dts, not hardcode here.</div><div>below register address will change to lower-case hex numbers.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +#define ILI9341_SLEEP_OUT            0x11   /* Sleep out register */<br>
> +#define ILI9341_GAMMA                0x26   /* Gamma register */<br>
> +#define ILI9341_DISPLAY_OFF          0x28   /* Display off register */<br>
> +#define ILI9341_DISPLAY_ON           0x29   /* Display on register */<br>
> +#define ILI9341_COLUMN_ADDR          0x2A   /* Colomn address register */<br>
> +#define ILI9341_PAGE_ADDR            0x2B   /* Page address register */<br>
> +#define ILI9341_GRAM                 0x2C   /* GRAM register */<br>
> +#define ILI9341_MAC                  0x36   /* Memory Access Control register*/<br>
> +#define ILI9341_PIXEL_FORMAT         0x3A   /* Pixel Format register */<br>
> +#define ILI9341_WDB                  0x51   /* Write Brightness Display<br>
> +                                          * register<br>
> +                                          */<br>
> +#define ILI9341_WCD                  0x53   /* Write Control Display<br>
> +                                          * register<br>
> +                                          */<br>
> +#define ILI9341_RGB_INTERFACE        0xB0   /* RGB Interface Signal Control */<br>
> +#define ILI9341_FRC                  0xB1   /* Frame Rate Control register */<br>
> +#define ILI9341_BPC                  0xB5   /* Blanking Porch Control<br>
> +                                          * register<br>
> +                                          */<br>
> +#define ILI9341_DFC                  0xB6   /* Display Function Control<br>
> +                                          * register<br>
> +                                          */<br>
> +#define ILI9341_POWER1               0xC0   /* Power Control 1 register */<br>
> +#define ILI9341_POWER2               0xC1   /* Power Control 2 register */<br>
> +#define ILI9341_VCOM1                0xC5   /* VCOM Control 1 register */<br>
> +#define ILI9341_VCOM2                0xC7   /* VCOM Control 2 register */<br>
> +#define ILI9341_POWERA               0xCB   /* Power control A register */<br>
> +#define ILI9341_POWERB               0xCF   /* Power control B register */<br>
> +#define ILI9341_PGAMMA               0xE0   /* Positive Gamma Correction<br>
> +                                          * register<br>
> +                                          */<br>
> +#define ILI9341_NGAMMA               0xE1   /* Negative Gamma Correction<br>
> +                                          * register<br>
> +                                          */<br>
> +#define ILI9341_DTCA                 0xE8   /* Driver timing control A */<br>
> +#define ILI9341_DTCB                 0xEA   /* Driver timing control B */<br>
> +#define ILI9341_POWER_SEQ            0xED   /* Power on sequence register */<br>
> +#define ILI9341_3GAMMA_EN            0xF2   /* 3 Gamma enable register */<br>
> +#define ILI9341_INTERFACE            0xF6   /* Interface control register */<br>
> +#define ILI9341_PRC                  0xF7   /* Pump ratio control register */<br>
> +<br>
<br>
All the following should be const.<br></blockquote><div>ok</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Can any of the below be replaces by DEFINED constants?<br>
> +static u8 ili9341_cmd0[] = {0xc3, 0x08, 0x50};<br>
> +static u8 ili9341_powerb[] = {0x00, 0xc1, 0x30};<br>
> +static u8 ili9341_power_seq[] = {0x64, 0x03, 0x12, 0x81};<br>
> +static u8 ili9341_dtca[] = {0x85, 0x00, 0x78};<br>
> +static u8 ili9341_powera[] = {0x39, 0x2c, 0x00, 0x34, 0x02};<br>
> +static u8 ili9341_prc[] = {0x20};<br>
> +static u8 ili9341_dtcb[] = {0x00, 0x00};<br>
> +static u8 ili9341_frc[] = {0x00, 0x1b};<br>
> +static u8 ili9341_dfc1[] = {0x0a, 0xa2};<br>
> +static u8 ili9341_power1[] = {0x10};<br>
> +static u8 ili9341_power2[] = {0x10};<br>
> +static u8 ili9341_vcom1[] = {0x45, 0x15};<br>
> +static u8 ili9341_vcom2[] = {0x90};<br>
> +static u8 ili9341_mac[] = {0xc8};<br>
> +static u8 ili9341_gamma_en[] = {0x00};<br>
> +static u8 ili9341_rgb_intr[] = {0xc2};<br>
> +static u8 ili9341_dfc2[] = {0x0a, 0xa7, 0x27, 0x04};<br>
> +static u8 ili9341_column_addr[] = {0x00, 0x00, 0x00, 0xef};<br>
> +static u8 ili9341_page_addr[] = {0x00, 0x00, 0x01, 0x3f};<br>
> +static u8 ili9341_intr[] = {0x01, 0x00, 0x06};<br>
> +static u8 ili9341_gamma[] = {0x01};<br>
> +static u8 ili9341_pgamma[] = {0x0f, 0x29, 0x24, 0x0c, 0x0e, 0x09, 0x4e, 0x78,<br>
> +                             0x3c, 0x09, 0x13, 0x05, 0x17, 0x11, 0x00};<br>
> +static u8 ili9341_ngamma[] = {0x00, 0x16, 0x1b, 0x04, 0x11, 0x07, 0x31, 0x33,<br>
> +                             0x42, 0x05, 0x0c, 0x0a, 0x28, 0x2f, 0x0f};<br>
> +<br>
> +/**<br>
> + * enum ili9341_input - the format of the incoming signal to the panel<br>
> + *<br>
> + * The panel can be connected to various input streams and four of them can<br>
> + * be selected by electronic straps on the display. However it is possible<br>
> + * to select another mode or override the electronic default with this<br>
> + * setting.<br>
> + */<br>
> +enum ili9341_input {<br>
> +     ILI9341_INPUT_PRGB_THROUGH = 0x0,<br>
> +     ILI9341_INPUT_PRGB_ALIGNED = 0x1,<br>
> +     ILI9341_INPUT_UNKNOWN = 0xf,<br>
> +};<br>
> +<br>
> +/**<br>
> + * struct ili9341_config - the system specific ILI9341 configuration<br>
> + * @width_mm: physical panel width [mm]<br>
> + * @height_mm: physical panel height [mm]<br>
> + * @input: the input/entry type used in this system, if this is set to<br>
> + * ILI9341_INPUT_UNKNOWN the driver will try to figure it out by probing<br>
> + * the hardware<br>
> + * @dclk_active_high: data/pixel clock active high, data will be clocked<br>
> + * in on the rising edge of the DCLK (this is usually the case).<br>
> + * @de_active_high: DE (data entry) is active high<br>
> + * @hsync_active_high: HSYNC is active high<br>
> + * @vsync_active_high: VSYNC is active high<br>
> + */<br>
> +struct ili9341_config {<br>
> +     u32 width_mm;<br>
> +     u32 height_mm;<br>
> +     enum ili9341_input input;<br>
> +     bool dclk_active_high;<br>
> +     bool de_active_high;<br>
> +     bool hsync_active_high;<br>
> +     bool vsync_active_high;<br>
> +};<br>
> +<br>
> +struct ili9341 {<br>
> +     struct device *dev;<br>
> +     const struct ili9341_config *conf;<br>
> +     struct drm_panel panel;<br>
> +     struct regmap *regmap;<br>
> +     struct gpio_desc *reset_gpio;<br>
> +     struct gpio_desc *dc_gpio;<br>
> +     enum ili9341_input input;<br>
<br>
> +     struct videomode vm;<br>
videomode is not used. So drop this field and drop the include files<br>
that are no logner needed.<br>
<br></blockquote><div>ok </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +};<br>
> +<br>
> +static inline struct ili9341 *panel_to_ili9341(struct drm_panel *panel)<br>
> +{<br>
> +     return container_of(panel, struct ili9341, panel);<br>
> +}<br>
> +<br>
> +int ili9341_spi_transfer(struct spi_device *spi, u32 speed_hz,<br>
> +                       u8 bpw, const void *buf, size_t len)<br>
> +{<br>
> +     size_t max_chunk = spi_max_transfer_size(spi);<br>
> +     struct spi_transfer tr = {<br>
const?<br>
<br></blockquote><div>ok </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +             .bits_per_word = bpw,<br>
> +             .speed_hz = speed_hz,<br>
> +             .len = len,<br>
> +     };<br>
> +     struct spi_message m;<br>
> +     size_t chunk;<br>
> +     int ret;<br>
> +<br>
> +     spi_message_init_with_transfers(&m, &tr, 1);<br>
> +<br>
> +     while (len) {<br>
> +             chunk = min(len, max_chunk);<br>
> +<br>
> +             tr.tx_buf = buf;<br>
> +             tr.len = chunk;<br>
> +             buf += chunk;<br>
> +             len -= chunk;<br>
> +<br>
> +             ret = spi_sync(spi, &m);<br>
> +             if (ret)<br>
> +                     return ret;<br>
> +     }<br>
> +     return 0;<br>
> +}<br>
> +static int ili9341_regmap_spi_write(void *context, const void *data,<br>
> +                                 size_t count)<br>
> +{<br>
> +     struct device *dev = context;<br>
> +     struct spi_device *spi = to_spi_device(dev);<br>
> +     struct ili9341 *ili = spi_get_drvdata(spi);<br>
> +     int ret = 0;<br>
> +<br>
> +     gpiod_set_value_cansleep(ili->dc_gpio, 0);<br>
> +<br>
> +     ret = ili9341_spi_transfer(spi, DEFAULT_SPI_SPEED, 8, data+0, 1);<br>
> +     if (ret || count == 1 ||<br>
> +                     ((u8 *)data)[0] == ILI9341_GRAM ||<br>
> +                     ((u8 *)data)[0] == ILI9341_DISPLAY_ON ||<br>
> +                     ((u8 *)data)[0] == ILI9341_SLEEP_OUT ||<br>
> +                     ((u8 *)data)[0] == ILI9341_DISPLAY_OFF)<br>
> +             return ret;<br>
> +<br>
> +     gpiod_set_value_cansleep(ili->dc_gpio, 1);<br>
> +<br>
> +     return ili9341_spi_transfer(spi, DEFAULT_SPI_SPEED, 8, data+1, count-1);<br>
> +}<br>
> +<br>
> +static int ili9341_regmap_spi_read(void *context, const void *reg,<br>
> +                                size_t reg_size, void *val, size_t val_size)<br>
> +{<br>
> +     return 0;<br>
> +}<br>
Is this function really needed? If not delete it.<br>
<br></blockquote><div>regmap will be drop in next patch. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +<br>
> +static struct regmap_bus ili9341_regmap_bus = {<br>
> +     .write = ili9341_regmap_spi_write,<br>
> +     .read = ili9341_regmap_spi_read,<br>
> +     .reg_format_endian_default = REGMAP_ENDIAN_BIG,<br>
> +     .val_format_endian_default = REGMAP_ENDIAN_BIG,<br>
> +};<br>
> +<br>
> +static bool ili9341_volatile_reg(struct device *dev, unsigned int reg)<br>
> +{<br>
> +     return false;<br>
> +}<br>
Is this function really nedded? If not delete it.<br>
<br>
> +<br>
> +static bool ili9341_writeable_reg(struct device *dev, unsigned int reg)<br>
> +{<br>
> +     /* Just register 0 is read-only */<br>
> +     if (reg == 0x00)<br>
> +             return false;<br>
> +     return true;<br>
> +}<br>
> +<br>
> +static const struct regmap_config ili9341_regmap_config = {<br>
> +     .reg_bits = 8,<br>
> +     .val_bits = 8,<br>
> +     .max_register = 0xff,<br>
> +     .cache_type = REGCACHE_RBTREE,<br>
> +     .volatile_reg = ili9341_volatile_reg,<br>
> +     .writeable_reg = ili9341_writeable_reg,<br>
> +};<br>
> +<br>
<br>
No error checks - consider something like:<br>
<br>
static int bulk_write(struct ili9341 *ili, u8 reg, const u8[] data, int len)<br>
{<br>
        int err = ili->err;<br>
<br>
        if (!err) {<br>
                err = regmap_bulk_write(ili->regmap, reg, data, len);<br>
                if (err) {<br>
                        dev_err(...);<br>
                        ili->err = err;<br>
                }<br>
        }<br>
<br>
        return err;<br>
}<br>
<br>
Then you can use this in the following, and make this more readable.<br>
<br></blockquote><div>ok, thanks for detail guide.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +static int ili9341_init(struct drm_panel *panel, struct ili9341 *ili)<br>
> +{<br>
> +     regmap_bulk_write(ili->regmap, 0xca,<br>
> +                                     ili9341_cmd0, sizeof(ili9341_cmd0));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_POWERB,<br>
> +                             ili9341_powerb, sizeof(ili9341_powerb));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_POWER_SEQ,<br>
> +                             ili9341_power_seq, sizeof(ili9341_power_seq));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_DTCA,<br>
> +                             ili9341_dtca, sizeof(ili9341_dtca));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_POWERA,<br>
> +                             ili9341_powera, sizeof(ili9341_powera));<br>
> +     regmap_write(ili->regmap, ILI9341_PRC, ili9341_prc[0]);<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_DTCB,<br>
> +                             ili9341_dtcb, sizeof(ili9341_dtcb));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_FRC,<br>
> +                             ili9341_frc, sizeof(ili9341_frc));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_DFC,<br>
> +                             ili9341_dfc1, sizeof(ili9341_dfc1));<br>
> +     regmap_write(ili->regmap, ILI9341_POWER1, ili9341_power1[0]);<br>
> +     regmap_write(ili->regmap, ILI9341_POWER2, ili9341_power2[0]);<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_VCOM1,<br>
> +                             ili9341_vcom1, sizeof(ili9341_vcom1));<br>
> +     regmap_write(ili->regmap, ILI9341_VCOM2, ili9341_vcom2[0]);<br>
> +     regmap_write(ili->regmap, ILI9341_MAC, ili9341_mac[0]);<br>
> +     regmap_write(ili->regmap, ILI9341_3GAMMA_EN, ili9341_gamma_en[0]);<br>
> +     regmap_write(ili->regmap, ILI9341_RGB_INTERFACE, ili9341_rgb_intr[0]);<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_DFC,<br>
> +                             ili9341_dfc2, sizeof(ili9341_dfc2));<br>
> +<br>
> +     /* colomn address set */<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_COLUMN_ADDR,<br>
> +                     ili9341_column_addr, sizeof(ili9341_column_addr));<br>
> +<br>
> +     /* Page Address Set */<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_PAGE_ADDR,<br>
> +                             ili9341_page_addr, sizeof(ili9341_page_addr));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_INTERFACE,<br>
> +                             ili9341_intr, sizeof(ili9341_intr));<br>
> +     regmap_write(ili->regmap, ILI9341_GRAM, 0);<br>
> +     msleep(200);<br>
> +<br>
> +     regmap_write(ili->regmap, ILI9341_GAMMA, ili9341_gamma[0]);<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_PGAMMA,<br>
> +                             ili9341_pgamma, sizeof(ili9341_pgamma));<br>
> +     regmap_bulk_write(ili->regmap, ILI9341_NGAMMA,<br>
> +                             ili9341_ngamma, sizeof(ili9341_ngamma));<br>
> +     regmap_write(ili->regmap, ILI9341_SLEEP_OUT, 0);<br>
> +     msleep(200);<br>
> +<br>
> +     regmap_write(ili->regmap, ILI9341_DISPLAY_ON, 0);<br>
> +<br>
> +     /* GRAM start writing */<br>
> +     regmap_write(ili->regmap, ILI9341_GRAM, 0);<br>
> +<br>
> +     dev_info(ili->dev, "initialized display\n");<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +/*<br>
> + * This power-on sequence if from the datasheet, page 57.<br>
> + */<br>
> +static int ili9341_power_on(struct ili9341 *ili)<br>
> +{<br>
> +     /* Assert RESET */<br>
> +     gpiod_set_value(ili->reset_gpio, 1);<br>
> +<br>
> +     msleep(20);<br>
> +<br>
> +     /* De-assert RESET */<br>
> +     gpiod_set_value(ili->reset_gpio, 0);<br>
> +<br>
> +     msleep(10);<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +static int ili9341_power_off(struct ili9341 *ili)<br>
> +{<br>
<br>
        Assert reset?<br>
will add reset-pin control here.<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     return 0;<br>
> +}<br>
> +<br>
> +static int ili9341_disable(struct drm_panel *panel)<br>
> +{<br>
> +     struct ili9341 *ili = panel_to_ili9341(panel);<br>
> +     int ret;<br>
> +<br>
> +     ret = regmap_write(ili->regmap, ILI9341_DISPLAY_OFF, 0);<br>
> +     if (ret) {<br>
> +             dev_err(ili->dev, "unable to go to standby mode\n");<br>
> +             return ret;<br>
> +     }<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +static int ili9341_unprepare(struct drm_panel *panel)<br>
> +{<br>
> +     struct ili9341 *ili = panel_to_ili9341(panel);<br>
> +<br>
> +     return ili9341_power_off(ili);<br>
> +}<br>
> +<br>
> +static int ili9341_prepare(struct drm_panel *panel)<br>
> +{<br>
> +     struct ili9341 *ili = panel_to_ili9341(panel);<br>
> +     int ret;<br>
> +<br>
> +     ret = ili9341_power_on(ili);<br>
> +     if (ret < 0)<br>
> +             return ret;<br>
> +<br>
> +     ret = ili9341_init(panel, ili);<br>
> +     if (ret < 0)<br>
> +             ili9341_unprepare(panel);<br>
> +<br>
> +     return ret;<br>
> +}<br>
> +<br>
> +static int ili9341_enable(struct drm_panel *panel)<br>
> +{<br>
> +     struct ili9341 *ili = panel_to_ili9341(panel);<br>
> +     int ret;<br>
> +<br>
> +     ret = regmap_write(ili->regmap, ILI9341_DISPLAY_ON, 0);<br>
> +     if (ret) {<br>
> +             dev_err(ili->dev, "unable to enable panel\n");<br>
> +             return ret;<br>
> +     }<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +/* This is the only mode listed for parallel RGB in the datasheet */<br>
> +static const struct drm_display_mode prgb_320x240_mode = {<br>
> +     .clock = 6100,<br>
> +     .hdisplay = 240,<br>
> +     .hsync_start = 240 + 10,<br>
> +     .hsync_end = 240 + 10 + 10,<br>
> +     .htotal = 280,<br>
> +     .vdisplay = 320,<br>
> +     .vsync_start = 320 + 4,<br>
> +     .vsync_end = 320 + 4 + 2,<br>
> +     .vtotal = 328,<br>
> +     .vrefresh = 60,<br>
> +     .flags = 0,<br>
> +};<br>
> +<br>
> +static int ili9341_get_modes(struct drm_panel *panel,<br>
> +                             struct drm_connector *connector)<br>
> +{<br>
> +     struct ili9341 *ili = panel_to_ili9341(panel);<br>
> +     struct drm_device *drm = connector->dev;<br>
> +     struct drm_display_mode *mode;<br>
> +     struct drm_display_info *info;<br>
> +<br>
> +     info = &connector->display_info;<br>
> +     info->width_mm = ili->conf->width_mm;<br>
> +     info->height_mm = ili->conf->height_mm;<br>
> +     if (ili->conf->dclk_active_high)<br>
> +             info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE;<br>
> +     else<br>
> +             info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE;<br>
> +<br>
> +     if (ili->conf->de_active_high)<br>
> +             info->bus_flags |= DRM_BUS_FLAG_DE_HIGH;<br>
> +     else<br>
> +             info->bus_flags |= DRM_BUS_FLAG_DE_LOW;<br>
> +<br>
> +     switch (ili->input) {<br>
> +     case ILI9341_INPUT_PRGB_THROUGH:<br>
> +     case ILI9341_INPUT_PRGB_ALIGNED:<br>
> +             mode = drm_mode_duplicate(drm, &prgb_320x240_mode);<br>
> +             break;<br>
> +     default:<br>
> +             mode = NULL;<br>
> +             break;<br>
> +     }<br>
> +     if (!mode) {<br>
> +             DRM_ERROR("bad mode or failed to add mode\n");<br>
> +             return -EINVAL;<br>
> +     }<br>
> +     drm_mode_set_name(mode);<br>
> +     /*<br>
> +      * This is the preferred mode because most people are going<br>
> +      * to want to use the display with VGA type graphics.<br>
> +      */<br>
> +     mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;<br>
> +<br>
> +     /* Set up the polarity */<br>
> +     if (ili->conf->hsync_active_high)<br>
> +             mode->flags |= DRM_MODE_FLAG_PHSYNC;<br>
> +     else<br>
> +             mode->flags |= DRM_MODE_FLAG_NHSYNC;<br>
> +     if (ili->conf->vsync_active_high)<br>
> +             mode->flags |= DRM_MODE_FLAG_PVSYNC;<br>
> +     else<br>
> +             mode->flags |= DRM_MODE_FLAG_NVSYNC;<br>
> +<br>
> +     mode->width_mm = ili->conf->width_mm;<br>
> +     mode->height_mm = ili->conf->height_mm;<br>
> +     drm_mode_probed_add(connector, mode);<br>
> +<br>
> +     return 1; /* Number of modes */<br>
> +}<br>
> +<br>
> +static const struct drm_panel_funcs ili9341_drm_funcs = {<br>
> +     .disable = ili9341_disable,<br>
> +     .unprepare = ili9341_unprepare,<br>
> +     .prepare = ili9341_prepare,<br>
> +     .enable = ili9341_enable,<br>
> +     .get_modes = ili9341_get_modes,<br>
> +};<br>
> +<br>
> +static int ili9341_probe(struct spi_device *spi)<br>
> +{<br>
> +     struct device *dev = &spi->dev;<br>
> +     struct ili9341 *ili;<br>
> +     const struct regmap_config *regmap_config;<br>
> +     int ret;<br>
> +<br>
> +     ili = devm_kzalloc(dev, sizeof(struct ili9341), GFP_KERNEL);<br>
> +     if (!ili)<br>
> +             return -ENOMEM;<br>
> +<br>
> +     spi_set_drvdata(spi, ili);<br>
> +<br>
> +     ili->dev = dev;<br>
> +     /*<br>
> +      * Every new incarnation of this display must have a unique<br>
> +      * data entry for the system in this driver.<br>
> +      */<br>
> +     ili->conf = of_device_get_match_data(dev);<br>
> +     if (!ili->conf) {<br>
> +             dev_err(dev, "missing device configuration\n");<br>
> +             return -ENODEV;<br>
> +     }<br>
> +<br>
> +     ili->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);<br>
> +     if (IS_ERR(ili->reset_gpio)) {<br>
> +             dev_err(dev, "failed to get RESET GPIO\n");<br>
> +             return PTR_ERR(ili->reset_gpio);<br>
> +     }<br>
> +<br>
> +     ili->dc_gpio = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);<br>
> +     if (IS_ERR(ili->dc_gpio)) {<br>
> +             dev_err(dev, "failed to get DC GPIO\n");<br>
> +             return PTR_ERR(ili->dc_gpio);<br>
> +     }<br>
> +<br>
> +     spi->bits_per_word = 8;<br>
> +     ret = spi_setup(spi);<br>
> +     if (ret < 0) {<br>
> +             dev_err(dev, "spi setup failed.\n");<br>
> +             return ret;<br>
> +     }<br>
> +<br>
> +     regmap_config = &ili9341_regmap_config;<br>
> +<br>
> +     ili->regmap = devm_regmap_init(dev, &ili9341_regmap_bus, dev,<br>
> +                                    regmap_config);<br>
> +     if (IS_ERR(ili->regmap)) {<br>
> +             dev_err(dev, "failed to allocate register map\n");<br>
> +             return PTR_ERR(ili->regmap);<br>
> +     }<br>
> +<br>
> +     ili->input = ili->conf->input;<br>
> +<br>
> +     drm_panel_init(&ili->panel, dev, &ili9341_drm_funcs,<br>
> +                    DRM_MODE_CONNECTOR_DPI);<br>
> +<br>
> +     return drm_panel_add(&ili->panel);<br>
> +}<br>
> +<br>
> +static int ili9341_remove(struct spi_device *spi)<br>
> +{<br>
> +     struct ili9341 *ili = spi_get_drvdata(spi);<br>
> +<br>
> +     ili9341_power_off(ili);<br>
> +     drm_panel_remove(&ili->panel);<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +<br>
> +/*<br>
> + * The Stm32f429-disco board has a panel ili9341 connected to ltdc controller<br>
> + */<br>
> +static const struct ili9341_config ili9341_data = {<br>
This should be named "disco" something as this is m32f429-disco<br>
specific.<br>
<br></blockquote><div>ok </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     .width_mm = 65,<br>
> +     .height_mm = 50,<br>
> +     .input = ILI9341_INPUT_PRGB_THROUGH,<br>
> +     .dclk_active_high = true,<br>
> +     .de_active_high = false,<br>
> +     .hsync_active_high = false,<br>
> +     .vsync_active_high = false,<br>
> +};<br>
> +<br>
> +static const struct of_device_id ili9341_of_match[] = {<br>
> +     {<br>
> +             .compatible = "stm32f429,ltdc-panel",<br>
> +             .data = &ili9341_data,<br>
> +     },<br>
<br>
<br>
> +     {<br>
> +             .compatible = "ilitek,ili9341",<br>
> +             .data = NULL,<br>
This part is wrong, as ilitek,ili9341 is just the generic part.<br>
Only the first entry is relevant.<br>
<br>
<br></blockquote><div>ok </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +     },<br>
> +     { }<br>
> +};<br>
> +MODULE_DEVICE_TABLE(of, ili9341_of_match);<br>
> +<br>
> +static struct spi_driver ili9341_driver = {<br>
> +     .probe = ili9341_probe,<br>
> +     .remove = ili9341_remove,<br>
> +     .driver = {<br>
> +             .name = "panel-ilitek-ili9341",<br>
> +             .of_match_table = ili9341_of_match,<br>
> +     },<br>
> +};<br>
> +module_spi_driver(ili9341_driver);<br>
> +<br>
> +MODULE_AUTHOR("Dillon Min <<a href="mailto:dillon.minfei@gmail.com" target="_blank">dillon.minfei@gmail.com</a>>");<br>
> +MODULE_DESCRIPTION("ILI9341 LCD panel driver");<br>
> +MODULE_LICENSE("GPL v2");<br>
> -- <br>
> 2.7.4<br>
</blockquote></div></div>