notro / fbtft

Linux Framebuffer drivers for small TFT LCD display modules. Development has moved to https://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/tree/drivers/staging/fbtft?h=staging-testing
1.85k stars 496 forks source link

Problems with DTS #212

Closed ololoshka2871 closed 9 years ago

ololoshka2871 commented 9 years ago

Good day.

I want to add support ili9136 on my BeagleBone Black. When I works on DTS, I had a few problems: I have disabled HDMI, by this instruction: https://github.com/notro/fbtft/wiki/BeagleBone-Black#disable-hdmi

My DTS:

/*
* Copyright (C) 2014 ololoshka2871
* Based on NEOSEC-TINYLCD35-00A0.dts by Noralf Tronnes
*
* nokia5110-lcd
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "NOKIA5110-LCD";

    /* version */
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =
        /* the pin header uses */
        "P9.31", /* spi1_sclk */
        "P9.29", /* spi1_d0 MISO */
        "P9.30", /* spi1_d1 MOSI */
        "P9.28", /* spi1_cs0 */
        "P9.11", /* gpio0_30 - reset */
        "P9.12", /* gpio1_28 - dc */
        "P9.15", /* gpio1_16 - led */
        "spi1";

    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            bb_spi1_pins: pinmux_bb_spi1_pins {
                pinctrl-single,pins = <
                    0x190 0x13    /* P9_31 = mcasp0_aclkx.spi1_sclk , OUTPUT_PU$
                    0x194 0x33    /* P9_29 = mcasp0_fsx.spi1_d0     , INPUT_PUL$
                    0x198 0x13    /* P9_30 = mcasp0_axr0.spi1_d1    , OUTPUT_PU$
                    0x19c 0x13    /* P9_28 = mcasp0_ahclkr.spi1_cs0 , OUTPUT_PU$
                >;
            };
            lcd_ctrl_pinmux: lcd_ctrl_pins {
                pinctrl-single,pins = <
                    0x070 0x17 /* P9.11 gpio0_30 OUTPUT_PULLUP | MODE7 */
                    0x078 0x17 /* P9.12 gpio1_28 OUTPUT_PULLUP | MODE7 */
                    0x040 0x07 /* P9.15 gpio1_16 OUTPUT_PULDOWN| MODE7 */
                >;
            };
        };
    };

    fragment@1 {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&bb_spi1_pins>;

            #address-cells = <1>;
            #size-cells = <0>;

            nokia5110: nokia5110@0 {
                compatible = "ilitek,ili9163";
                reg = <0>;

                pinctrl-names = "default";
                pinctrl-0 = <&lcd_ctrl_pinmux>;

                spi-max-frequency = <32000000>;
                rotate = <0>;
                bgr;
                fps = <5>;
                buswidth = <8>;

                reset-gpios = <&gpio1 30 0>;
                dc-gpios = <&gpio2 28 0>;
                #led-gpios = <&gpio2 16 0>;
                debug = <7>;
            };
        };
    };
};

If I enable parameter "led-gpios", then causes an error loading the module:

[   62.448835] of_get_named_gpio_flags exited with status 30
[   62.448870] fb_ili9163 spi1.0: fbtft_request_one_gpio: 'reset-gpios' = GPIO30
[   62.448885] of_get_named_gpio_flags exited with status 60
[   62.448903] fb_ili9163 spi1.0: fbtft_request_one_gpio: 'dc-gpios' = GPIO60
[   62.448919] of_get_named_gpio_flags exited with status 48
[   62.448935] fb_ili9163 spi1.0: fbtft_request_one_gpio: 'led-gpios' = GPIO48
[   62.448947] of_get_named_gpio_flags: can't parse gpios property
[   62.448958] fb_ili9163 spi1.0: failed to get 'led-gpios' from DT
[   62.467913] fb_ili9163: probe of spi1.0 failed with error -22

I think the kernel tries to load the driver twice, why?

[  115.660194] bone-capemgr bone_capemgr.9: part_number 'NOKIA5110-LCD', version 'N/A'
[  115.660277] bone-capemgr bone_capemgr.9: slot #7: generic override
[  115.660294] bone-capemgr bone_capemgr.9: bone: Using override eeprom data at slot 7
[  115.660312] bone-capemgr bone_capemgr.9: slot #7: 'Override Board Name,00A0,Override Manuf,NOKIA5110-LCD'
[  115.660414] bone-capemgr bone_capemgr.9: slot #7: Requesting part number/version based 'NOKIA5110-LCD-00A0.dtbo
[  115.660432] bone-capemgr bone_capemgr.9: slot #7: Requesting firmware 'NOKIA5110-LCD-00A0.dtbo' for board-name 'Override Board Name', version '00A0'
[  115.671863] bone-capemgr bone_capemgr.9: slot #7: dtbo 'NOKIA5110-LCD-00A0.dtbo' loaded; converting to live tree
[  115.672199] bone-capemgr bone_capemgr.9: slot #7: #2 overlays
[  115.732886] edma-dma-engine edma-dma-engine.0: allocated channel for 0:43
[  115.732956] edma-dma-engine edma-dma-engine.0: allocated channel for 0:42
[  115.733171] fbtft_of_value: buswidth = 8
[  115.733185] fbtft_of_value: debug = 3
[  115.733194] fbtft_of_value: rotate = 0
[  115.733202] fbtft_of_value: fps = 10
[  115.733319] of_get_named_gpio_flags exited with status 30
[  115.733351] fb_ili9163 spi1.0: fbtft_request_one_gpio: 'reset-gpios' = GPIO30
[  115.733507] of_get_named_gpio_flags exited with status 60
[  115.733532] fb_ili9163 spi1.0: fbtft_request_one_gpio: 'dc-gpios' = GPIO60
[  115.733570] fb_ili9163 spi1.0: fbtft_verify_gpios()
[  115.733582] fb_ili9163 spi1.0: init_display()
[  115.733592] fb_ili9163 spi1.0: fbtft_reset()
[  116.376674] fb_ili9163 spi1.0: set_var()
[  116.398110] fb_ili9163 spi1.0: Display update: 1500 kB/s (21.311 ms), fps=0 (0.000 ms)
[  116.398832] Console: switching to colour frame buffer device 32x21
[  116.399203] graphics fb0: fb_ili9163 frame buffer, 128x128, 32 KiB video memory, 4 KiB DMA buffer memory, fps=10, spi1.0 at 32 MHz
[  116.402176] fb_ili9163 0.lcd@0: fbtft_probe_common()
[  116.402209] fbtft_of_value: buswidth = 8
[  116.402219] fbtft_of_value: debug = 3
[  116.402227] fbtft_of_value: rotate = 0
[  116.402236] fbtft_of_value: fps = 10
[  116.402373] of_get_named_gpio_flags exited with status 30
[  116.402388] gpio_request: gpio-30 (fb_ili9163) status -16
[  116.402404] fb_ili9163 0.lcd@0: gpio_request_one('reset-gpios'=30) failed with -16
[  116.438680] fb_ili9163: probe of 0.lcd@0 failed with error -16
[  116.438732] bone-capemgr bone_capemgr.9: slot #7: Applied #2 overlays.

systemd or kernel automatically starts the console session on fb0, I can see small blinking cursor on display. How to prevent this action?

[  116.398832] Console: switching to colour frame buffer device 32x21
notro commented 9 years ago

If I enable parameter "led-gpios", then causes an error loading the module:

What's with the '#' sign?

#led-gpios = <&gpio2 16 0>;
[   62.448935] fb_ili9163 spi1.0: fbtft_request_one_gpio: 'led-gpios' = GPIO48
[   62.448947] of_get_named_gpio_flags: can't parse gpios property
[   62.448958] fb_ili9163 spi1.0: failed to get 'led-gpios' from DT
[   62.467913] fb_ili9163: probe of spi1.0 failed with error -22

This means that of_get_named_gpio_flags() returns -EINVAL (-22). Has this something to do with the '#' sign, since it can't parse it?

I think the kernel tries to load the driver twice, why?

Yes, I have seen that. The BBB overlay code makes a platform device as well. This is usually no problem for drivers, but the FBTFT drivers support both SPI and platform devices, and thus it tries the bind the platform device as well. It will fail, because the gpios are in use. So it ends up as noise in the kernel log.

ololoshka2871 commented 9 years ago

Finally it works! I have added support backlight by BBB's PWM and soviet PNP transistor. Gamma-correction curves are builded-in controller, default selection is 2,2. Also controller provides "Gamma Correction Setting", but it has no visible effect, disabled by default.

diff --git a/Kconfig b/Kconfig
index 995a910..6cf0c58 100644
--- a/Kconfig
+++ b/Kconfig
@@ -38,6 +38,12 @@ config FB_TFT_HX8353D
    help
      Generic Framebuffer support for HX8353D

+config FB_TFT_ILI9163
+   tristate "FB driver for the ILI9163 LCD Controller"
+   depends on FB_TFT
+   help
+     Generic Framebuffer support for ILI9163
+
 config FB_TFT_ILI9320
    tristate "FB driver for the ILI9320 LCD Controller"
    depends on FB_TFT
diff --git a/Makefile b/Makefile
index 71c755d..75f69d5 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_FB_TFT_BD663474)    += fb_bd663474.o
 obj-$(CONFIG_FB_TFT_HX8340BN)    += fb_hx8340bn.o
 obj-$(CONFIG_FB_TFT_HX8347D)     += fb_hx8347d.o
 obj-$(CONFIG_FB_TFT_HX8353D)     += fb_hx8353d.o
+obj-$(CONFIG_FB_TFT_ILI9163)     += fb_ili9163.o
 obj-$(CONFIG_FB_TFT_ILI9320)     += fb_ili9320.o
 obj-$(CONFIG_FB_TFT_ILI9325)     += fb_ili9325.o
 obj-$(CONFIG_FB_TFT_ILI9340)     += fb_ili9340.o
diff --git a/dts/overlays/bbb/NOKIA5110-LCD-00A0.dts b/dts/overlays/bbb/NOKIA5110-LCD-00A0.dts
new file mode 100644
index 0000000..6cfa77c
--- /dev/null
+++ b/dts/overlays/bbb/NOKIA5110-LCD-00A0.dts
@@ -0,0 +1,128 @@
+/*
+* Copyright (C) 2014 ololoshka2871
+* Based on NEOSEC-TINYLCD35-00A0.dts by Noralf Tronnes
+*
+* nokia5110-lcd
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation.
+*/
+
+/dts-v1/;
+/plugin/;
+
+/ {
+    compatible = "ti,beaglebone", "ti,beaglebone-black";
+
+    /* identification */
+    part-number = "NOKIA5110-LCD";
+
+    /* version */
+    version = "00A0";
+
+    /* state the resources this cape uses */
+    exclusive-use =
+        /* the pin header uses */
+       "P9.31", /* spi1_sclk */
+       "P9.29", /* spi1_d0 MISO */
+       "P9.30", /* spi1_d1 MOSI */
+       "P9.28", /* spi1_cs0 */
+       "P9.11", /* gpio0_30 - reset */
+       "P9.12", /* gpio1_28 - dc */
+       "P9.15", /* gpio1_16 - led */
+       "P9.14", /* backlight */
+       "ehrpwm1A",
+        "spi1";
+
+    fragment@0 {
+        target = <&am33xx_pinmux>;
+        __overlay__ {
+            bb_spi1_pins: pinmux_bb_spi1_pins {
+                pinctrl-single,pins = <
+                    0x190 0x13    /* P9_31 = mcasp0_aclkx.spi1_sclk , OUTPUT_PULLUP | MODE3 */
+                    0x194 0x33    /* P9_29 = mcasp0_fsx.spi1_d0     , INPUT_PULLUP  | MODE3 */
+                    0x198 0x13    /* P9_30 = mcasp0_axr0.spi1_d1    , OUTPUT_PULLUP | MODE3 */
+                    0x19c 0x13    /* P9_28 = mcasp0_ahclkr.spi1_cs0 , OUTPUT_PULLUP | MODE3 */
+                >;
+           };
+            lcd_ctrl_pinmux: lcd_ctrl_pins {
+               pinctrl-single,pins = <
+                   0x070 0x17 /* P9.11 gpio0_30 OUTPUT_PULLUP | MODE7 */
+                   0x078 0x17 /* P9.12 gpio1_28 OUTPUT_PULLUP | MODE7 */
+                   0x040 0x07 /* P9.15 gpio1_16 OUTPUT_PULDOWN| MODE7 */
+               >;
+            };
+           pwm_bl_pins: pinmux_pwm_bl_pins {
+               pinctrl-single,pins = <
+                   0x48 0x06 /* ehrpwm1a, MODE6 */
+               >;
+           };
+        };
+    };
+
+    fragment@1 {
+       target = <&spi1>;
+       __overlay__ {
+           status = "okay";
+           pinctrl-names = "default";
+           pinctrl-0 = <&bb_spi1_pins>;
+
+           #address-cells = <1>;
+           #size-cells = <0>;
+
+           nokia5110: nokia5110@0 {
+               compatible = "ilitek,ili9163";
+               reg = <0>;
+
+               pinctrl-names = "default";
+               pinctrl-0 = <&lcd_ctrl_pinmux>;
+
+               spi-max-frequency = <12000000>;
+               rotate = <90>;
+               bgr;
+               fps = <30>;
+               buswidth = <8>;
+
+               reset-gpios = <&gpio1 30 0>;
+               dc-gpios = <&gpio2 28 0>;
+
+               debug = <1>;
+           };
+       };
+   };
+
+   fragment@2 {
+       target = <&epwmss1>;
+       __overlay__ {
+           status = "okay";
+       };
+   };
+
+   fragment@3 {
+       target = <&ehrpwm1>;
+       __overlay__ {
+           status = "okay";
+       };
+   };
+
+   fragment@4 {
+       target = <&ocp>;
+       __overlay__ {
+           backlight {
+               compatible = "pwm-backlight";
+               pinctrl-names = "default";
+               pinctrl-0 = <&pwm_bl_pins>;
+               status = "okay";
+               enabled = <1>;
+
+               pwms = <&ehrpwm1 0 500000 1>;
+               pwm-names = "backlight";
+
+               brightness-levels = <0 8 16 32 48 64 80 96 112 128 144
+                                       160 176 192 208 224 240 255>;
+               default-brightness-level = <10>; /* index to the array above */
+           };
+       };
+   };
+};
diff --git a/fb_ili9163.c b/fb_ili9163.c
new file mode 100644
index 0000000..72e0be2
--- /dev/null
+++ b/fb_ili9163.c
@@ -0,0 +1,291 @@
+/*
+ * FB driver for the ILI9163 LCD Controller
+ *
+ * Copyright (C) 2014 ololoshka2871
+ *
+ * Based on ili9325.c by Noralf Tronnes and
+ * .S.U.M.O.T.O.Y. by Max MC Costa (https://github.com/sumotoy/TFT_ILI9163C).
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+
+#include "fbtft.h"
+
+#define DRVNAME            "fb_ili9163"
+#define WIDTH          128
+#define HEIGHT         128
+#define BPP                16
+#define FPS                30
+
+#ifdef GAMMA_ADJ
+#define GAMMA_LEN      15
+#define GAMMA_NUM      1
+#define DEFAULT_GAMMA  "36 29 12 22 1C 15 42 B7 2F 13 12 0A 11 0B 06\n"
+#endif
+
+/* ILI9163C commands */
+#define CMD_NOP            0x00 /* Non operation*/
+#define CMD_SWRESET        0x01 /* Soft Reset */
+#define CMD_SLPIN      0x10 /* Sleep ON */
+#define CMD_SLPOUT     0x11 /* Sleep OFF */
+#define CMD_PTLON      0x12 /* Partial Mode ON */
+#define CMD_NORML      0x13 /* Normal Display ON */
+#define CMD_DINVOF     0x20 /* Display Inversion OFF */
+#define CMD_DINVON     0x21 /* Display Inversion ON */
+#define CMD_GAMMASET   0x26 /* Gamma Set (0x01[1],0x02[2],0x04[3],0x08[4]) */
+#define CMD_DISPOFF        0x28 /* Display OFF */
+#define CMD_DISPON     0x29 /* Display ON */
+#define CMD_IDLEON     0x39 /* Idle Mode ON */
+#define CMD_IDLEOF     0x38 /* Idle Mode OFF */
+#define CMD_CLMADRS        0x2A /* Column Address Set */
+#define CMD_PGEADRS        0x2B /* Page Address Set */
+
+#define CMD_RAMWR      0x2C /* Memory Write */
+#define CMD_RAMRD      0x2E /* Memory Read */
+#define CMD_CLRSPACE   0x2D /* Color Space : 4K/65K/262K */
+#define CMD_PARTAREA   0x30 /* Partial Area */
+#define CMD_VSCLLDEF   0x33 /* Vertical Scroll Definition */
+#define CMD_TEFXLON        0x34 /* Tearing Effect Line ON */
+#define CMD_TEFXLOF        0x35 /* Tearing Effect Line OFF */
+#define CMD_MADCTL     0x36 /* Memory Access Control */
+
+#define CMD_PIXFMT     0x3A /* Interface Pixel Format */
+#define CMD_FRMCTR1        0xB1 /* Frame Rate Control (In normal mode/Full colors) */
+#define CMD_FRMCTR2        0xB2 /* Frame Rate Control(In Idle mode/8-colors) */
+#define CMD_FRMCTR3        0xB3 /* Frame Rate Control(In Partial mode/full colors) */
+#define CMD_DINVCTR        0xB4 /* Display Inversion Control */
+#define CMD_RGBBLK     0xB5 /* RGB Interface Blanking Porch setting */
+#define CMD_DFUNCTR        0xB6 /* Display Fuction set 5 */
+#define CMD_SDRVDIR        0xB7 /* Source Driver Direction Control */
+#define CMD_GDRVDIR        0xB8 /* Gate Driver Direction Control  */
+
+#define CMD_PWCTR1     0xC0 /* Power_Control1 */
+#define CMD_PWCTR2     0xC1 /* Power_Control2 */
+#define CMD_PWCTR3     0xC2 /* Power_Control3 */
+#define CMD_PWCTR4     0xC3 /* Power_Control4 */
+#define CMD_PWCTR5     0xC4 /* Power_Control5 */
+#define CMD_VCOMCTR1   0xC5 /* VCOM_Control 1 */
+#define CMD_VCOMCTR2   0xC6 /* VCOM_Control 2 */
+#define CMD_VCOMOFFS   0xC7 /* VCOM Offset Control */
+#define CMD_PGAMMAC        0xE0 /* Positive Gamma Correction Setting */
+#define CMD_NGAMMAC        0xE1 /* Negative Gamma Correction Setting */
+#define CMD_GAMRSEL        0xF2 /* GAM_R_SEL */
+
+/*
+This display:
+http://www.ebay.com/itm/Replace-Nokia-5110-LCD-1-44-Red-Serial-128X128-SPI-Color-TFT-LCD-Display-Module-/271422122271
+This particular display has a design error! The controller has 3 pins to configure to constrain
+the memory and resolution to a fixed dimension (in that case 128x128) but they leaved those pins
+configured for 128x160 so there was several pixel memory addressing problems.
+I solved by setup several parameters that dinamically fix the resolution as needit so below
+the parameters for this diplay. If you have a strain or a correct display (can happen with chinese)
+you can copy those parameters and create setup for different displays.
+*/
+
+#ifdef RED
+#define __OFFSET       32 /*see note 2 - this is the red version */
+#else
+#define __OFFSET       0  /*see note 2 - this is the black version */
+#endif
+
+static int init_display(struct fbtft_par *par)
+{
+   fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
+
+   par->fbtftops.reset(par);
+
+   if (par->gpio.cs != -1)
+       gpio_set_value(par->gpio.cs, 0);  /* Activate chip */
+
+   write_reg(par, CMD_SWRESET); /* software reset */
+   mdelay(500);
+   write_reg(par, CMD_SLPOUT); /* exit sleep */
+   mdelay(5);
+   write_reg(par, CMD_PIXFMT, 0x05); /* Set Color Format 16bit */
+   write_reg(par, CMD_GAMMASET, 0x02); /* default gamma curve 3 */
+#ifdef GAMMA_ADJ
+   write_reg(par, CMD_GAMRSEL, 0x01); /* Enable Gamma adj */
+#endif
+   write_reg(par, CMD_NORML);
+   write_reg(par, CMD_DFUNCTR, 0xff, 0x06);
+   write_reg(par, CMD_FRMCTR1, 0x08, 0x02); /* Frame Rate Control (In normal mode/Full colors) */
+   write_reg(par, CMD_DINVCTR, 0x07); /* display inversion  */
+   write_reg(par, CMD_PWCTR1, 0x0A, 0x02); /* Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD */
+   write_reg(par, CMD_PWCTR2, 0x02); /* Set BT[2:0] for AVDD & VCL & VGH & VGL  */
+   write_reg(par, CMD_VCOMCTR1, 0x50, 0x63); /* Set VMH[6:0] & VML[6:0] for VOMH & VCOML */
+   write_reg(par, CMD_VCOMOFFS, 0);
+
+   write_reg(par, CMD_CLMADRS, 0, 0, 0, WIDTH); /* Set Column Address */
+   write_reg(par, CMD_PGEADRS, 0, 0, 0, HEIGHT); /* Set Page Address */
+
+   write_reg(par, CMD_DISPON); /* display ON */
+   write_reg(par, CMD_RAMWR); /* Memory Write */
+
+   return 0;
+}
+
+static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
+{
+   fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
+       "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
+
+   switch (par->info->var.rotate) {
+   case 0:
+       write_reg(par, CMD_CLMADRS, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
+       write_reg(par, CMD_PGEADRS,
+                   (ys + __OFFSET) >> 8, (ys + __OFFSET) & 0xff,
+                   (ye + __OFFSET) >> 8, (ye + __OFFSET) & 0xff);
+       break;
+   case 90:
+       write_reg(par, CMD_CLMADRS,
+                   (xs + __OFFSET) >> 8, (xs + __OFFSET) & 0xff,
+                   (xe + __OFFSET) >> 8, (xe + __OFFSET) & 0xff);
+       write_reg(par, CMD_PGEADRS, ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
+       break;
+   case 180:
+   case 270:
+       write_reg(par, CMD_CLMADRS, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
+       write_reg(par, CMD_PGEADRS, ys >> 8, ys & 0xff, ye >> 8, ye & 0xff);
+       break;
+   default:
+       par->info->var.rotate = 0; /* Fix incorrect setting */
+   }
+   write_reg(par, CMD_RAMWR); /* Write Data to GRAM mode */
+}
+
+static int set_var(struct fbtft_par *par)
+{
+/*
+7) MY:  1(bottom to top),  0(top to bottom)    Row Address Order
+6) MX:  1(R to L),         0(L to R)           Column Address Order
+5) MV:  1(Exchanged),      0(normal)           Row/Column exchange
+4) ML:  1(bottom to top),  0(top to bottom)    Vertical Refresh Order
+3) RGB: 1(BGR),                0(RGB)          Color Space
+2) MH:  1(R to L),         0(L to R)           Horizontal Refresh Order
+1)
+0)
+
+    MY, MX, MV, ML,RGB, MH, D1, D0
+   0 | 0 | 0 | 0 | 1 | 0 | 0 | 0   //normal
+   1 | 0 | 0 | 0 | 1 | 0 | 0 | 0   //Y-Mirror
+   0 | 1 | 0 | 0 | 1 | 0 | 0 | 0   //X-Mirror
+   1 | 1 | 0 | 0 | 1 | 0 | 0 | 0   //X-Y-Mirror
+   0 | 0 | 1 | 0 | 1 | 0 | 0 | 0   //X-Y Exchange
+   1 | 0 | 1 | 0 | 1 | 0 | 0 | 0   //X-Y Exchange, Y-Mirror
+   0 | 1 | 1 | 0 | 1 | 0 | 0 | 0   //XY exchange
+   1 | 1 | 1 | 0 | 1 | 0 | 0 | 0
+*/
+
+   u8 mactrl_data = 0; /* Avoid compiler warning */
+
+   fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
+
+   switch (par->info->var.rotate) {
+   case 0:
+       mactrl_data = 0x08;
+       break;
+   case 180:
+       mactrl_data = 0xC8;
+       break;
+   case 270:
+       mactrl_data = 0xA8;
+       break;
+   case 90:
+       mactrl_data = 0x68;
+       break;
+   }
+
+   /* Colorspcae */
+   if (par->bgr)
+       mactrl_data |= (1 << 2);
+   write_reg(par, CMD_MADCTL, mactrl_data);
+   write_reg(par, CMD_RAMWR); /* Write Data to GRAM mode */
+   return 0;
+}
+
+#ifdef GAMMA_ADJ
+#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+static int gamma_adj(struct fbtft_par *par, unsigned long *curves)
+{
+   unsigned long mask[] = {
+       0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
+       0x1f, 0x3f, 0x0f, 0x0f, 0x7f, 0x1f,
+       0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
+   int i, j;
+
+   fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
+
+   for (i = 0; i < GAMMA_NUM; i++)
+       for (j = 0; j < GAMMA_LEN; j++)
+           CURVE(i, j) &= mask[i*par->gamma.num_values + j];
+
+   write_reg(par, CMD_PGAMMAC,
+               CURVE(0, 0),
+               CURVE(0, 1),
+               CURVE(0, 2),
+               CURVE(0, 3),
+               CURVE(0, 4),
+               CURVE(0, 5),
+               CURVE(0, 6),
+               (CURVE(0, 7) << 4) | CURVE(0, 8),
+               CURVE(0, 9),
+               CURVE(0, 10),
+               CURVE(0, 11),
+               CURVE(0, 12),
+               CURVE(0, 13),
+               CURVE(0, 14),
+               CURVE(0, 15)
+               );
+
+   write_reg(par, CMD_RAMWR); /* Write Data to GRAM mode */
+
+   return 0;
+}
+#undef CURVE
+#endif
+
+static struct fbtft_display display = {
+   .regwidth = 8,
+   .width = WIDTH,
+   .height = HEIGHT,
+   .bpp = BPP,
+   .fps = FPS,
+#ifdef GAMMA_ADJ
+   .gamma_num = GAMMA_NUM,
+   .gamma_len = GAMMA_LEN,
+   .gamma = DEFAULT_GAMMA,
+#endif
+   .fbtftops = {
+       .init_display = init_display,
+       .set_addr_win = set_addr_win,
+       .set_var = set_var,
+#ifdef GAMMA_ADJ
+       .set_gamma = gamma_adj,
+#endif
+   },
+};
+
+FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9163", &display);
+
+MODULE_ALIAS("spi:" DRVNAME);
+MODULE_ALIAS("platform:" DRVNAME);
+MODULE_ALIAS("spi:ili9163");
+MODULE_ALIAS("platform:ili9163");
+
+MODULE_DESCRIPTION("FB driver for the ILI9163 LCD Controller");
+MODULE_AUTHOR("ololoshka2871");
+MODULE_LICENSE("GPL");
diff --git a/fbtft_device.c b/fbtft_device.c
index b9f4c30..74003d9 100644
--- a/fbtft_device.c
+++ b/fbtft_device.c
@@ -676,6 +676,23 @@ static struct fbtft_device_display displays[] = {
            }
        }
    }, {
+       .name = "nokia5110",
+       .spi = &(struct spi_board_info) {
+           .modalias = "fb_ili9163",
+           .max_speed_hz = 12000000,
+           .mode = SPI_MODE_0,
+           .platform_data = &(struct fbtft_platform_data) {
+               .display = {
+                   .buswidth = 8,
+                   .backlight = 1,
+               },
+               .bgr = true,
+               .gpios = (const struct fbtft_gpio []) {
+                   {},
+               },
+           }
+       }
+   }, {
        .name = "piscreen",
        .spi = &(struct spi_board_info) {
            .modalias = "fb_ili9486",

20141230162511

Sorry for my bad english.

notro commented 9 years ago

Glad you made it work. I'm awaiting the result of this issue before I decide on what to do with future FBTFT changes: https://github.com/notro/fbtft/issues/161#issuecomment-68431405

ololoshka2871 commented 9 years ago

Okay, no problem, introducing the project to the kernel is more important.

notro commented 9 years ago

Development has now moved. Please send a patch to driverdev-devel@linuxdriverproject.org

More: https://github.com/notro/fbtft/wiki/Development