Kernel drivers porting and configuration

From Orange Pi
Jump to: navigation, search

Porting Dallas’s 1-wire Driver

Config the Kernel

Config the kernel to include Dallas’s 1-wire(DS18B20) driver. Under the kernel root directory, enter the following commnad:

make menuconfig

(All the make menuconfig that follows in this document, is executed under kernel root directory) Config as follows:

Device Drivers  --->
  <*> Dallas's 1-wire support  --->
     1-wire Bus Masters  --->
         <*> GPIO 1-wire busmaster
     1-wire Slaves  --->
         <*> Thermal family implementation

Save and exit, re-compile the kernel:

make uImage

Replace the earlier uImage on Orange Pi with the new generated uImage under arch/arm/boot/ directory.

Config the script.fex

Config the script.fex as follows, add the [w1_para] setting:

[w1_para]
w1_used = 1
w1_pin = port:PB10<1><default><default><default>

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on Orange Pi.

Reboot the Orange Pi system, insert the 1-wire device. Remember you need have the complied 1-wire device driver and use the "insmod" command to load it.

Porting I2C Bus Driver

Config the Kernel

Config the kernel to include I2C bus driver:

make menuconfig
Device Drivers  --->
  {*} I2C support  --->
       I2C Hardware Bus support  --->
           <*> Allwinner Technology SUNXI I2C interface

Save and exit.
Re-compile the kernel:

make uImage

Replace the earlier uImage on Orange Pi with the new generated uImage under arch/arm/boot/ directory.

Config the script.fex

Any I2C module can be used to test the I2C driver, which is connected to the I2C-2 controller. Therefore, config the [twi2_para] setting in the script.fex as follows:

[twi2_para]
twi2_used = 1
twi2_scl = port:PB20<2><default><default><default>
twi2_sda = port:PB21<2><default><default><default>

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on the board.
Reboot the Orange Pi system.

Porting SPI Devices Driver

Config the Kernel

The A20 SPI is not natively supported by linux-sunxi-3.4.90 kernel. You should copy the spi-sun7i.c file to the drivers/spi directory in the kernel, and modify the related Makefile and Kconfig under the same directory.
Add the following line in Makefile:

obj-$(CONFIG_SPI_SUN7I)         += spi-sun7i.o

Add the following line in Kconfig:

config SPI_SUN7I
   tristate "SUN7I SPI Controller"
   depends on ARCH_SUN7I
   help
       Allwinner Soc SPI controller,present on SUN7I chips.
 
config SUN7I_SPI_NDMA
    bool "SUN7I SPI Normal DMA mode select"
    depends on SPI_SUN7I
    help
       This selects SPI DMA mode with DMA transfer
       Y select NDMA mode and N select DDMA mode


make menuconfig


Device Drivers  --->
   [*] SPI support  --->
       <*>   SUN7I SPI Controller
       [*]     SUN7I SPI Normal DMA mode select
       <*>   DesignWare SPI controller core support 
       <*>   User mode SPI device driver support

Save and exit, re-compile the kernel:

make uImage

Replace the earlier uImage on Orange Pi with the new generated uImage under arch/arm/boot/ directory.

Config the script.fex

SPI module AT45DBXX DataFlash Board can be connected to the SPI0 controller, therefore, config the [spi0_para], [spi_devices], and [spi_board0] settings in the script.fex as follows:

[spi0_para]
spi_used = 1
spi_cs_bitmap = 3
spi_cs0 = port:PI10<2><default><default><default>
spi_cs1 = port:PI14<2><default><default><default>
spi_sclk = port:PI11<2><default><default><default>
spi_mosi = port:PI12<2><default><default><default>
spi_miso = port:PI13<2><default><default><default>


[spi_devices]
spi_dev_num = 2


[spi_board0]
modalias = "spidev"
max_speed_hz = 12000000
bus_num = 0
chip_select = 0
mode = 3
full_duplex = 0
manual_cs = 0
 
[spi_board1]
modalias = "spidev"
max_speed_hz = 12000000
bus_num = 0
chip_select = 1
mode = 3
full_duplex = 0
manual_cs = 0

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on Orange Pi.
Now the kernel and script.fex configuration for SPI device have completed.
Reboot the Orange Pi system.
Now you can use the AT45DBXX DataFlash Board to test the SPI driver .

Porting LCD Driver

Config the Kernel

The LCD driver support has been included in linux-sunxi-3.4.XX, the driver file can be found on drivers/video/sunxi/lcd.
Check the kernel configuration, confirm that the driver is included:

make menuconfig


div dir="ltr" class="mw-geshi mw-code mw-content-ltr">
Device Drivers  --->
   Graphics support  --->
      {*} Support for frame buffer devices  --->
          <*>   DISP Driver Support(sunxi)
          -*-     Reserve memory block for sunxi/fb
          [*]     Enable FB/UMP Integration
      <*>    LCD Driver Support(sunxi)
      <*>    HDMI Driver Support(sunxi)

Save and exit, re-compile the kernel:

make uImage

Replace the earlier uImage on the board with the new generated uImage under arch/arm/boot/ directory.

Config the script.fex

The A20 supports two channel video output, however, only LCD0 is available on Orange Pi, therefore, we connect the 7inch capacitive LCD to the LCD0 controller.
Config the script.fex, [dis_init] setting for display device initialization, and [lcd0_para] setting for LCD parameters (depending on the specifications of concrete LCD), as follows:

[disp_init]
disp_init_enable = 1
disp_mode = 0
screen0_output_type = 1
screen0_output_mode = 4
screen1_output_type = 0
screen1_output_mode = 4
fb0_width = 1024
fb0_height = 768
fb0_framebuffer_num = 2
fb0_format = 10
fb0_pixel_sequence = 0
fb0_scaler_mode_enable = 0
fb1_width = 1024
fb1_height = 768
fb1_framebuffer_num = 2
fb1_format = 10
fb1_pixel_sequence = 0
fb1_scaler_mode_enable = 0
lcd0_backlight = 197
lcd1_backlight = 197
lcd0_bright = 50
lcd0_contrast = 50
lcd0_saturation = 57
lcd0_hue = 50
lcd1_bright = 50 
lcd1_contrast = 50
lcd1_saturation = 57
lcd1_hue = 50


[lcd0_para]
lcd_used = 1
lcd_x = 800 
lcd_y = 480
lcd_dclk_freq = 33
lcd_pwm_not_used = 0
lcd_pwm_ch = 0
lcd_pwm_freq = 10000
lcd_pwm_pol = 0
lcd_max_bright = 240
lcd_min_bright = 64
lcd_if = 0
lcd_hbp = 215
lcd_ht = 1055
lcd_vbp = 34
lcd_vt = 1050
lcd_vspw = 3
lcd_hspw = 20
lcd_hv_if = 0
lcd_hv_smode = 0
lcd_hv_s888_if = 0
lcd_hv_syuv_if = 0
lcd_lvds_ch = 0
lcd_lvds_mode = 0
lcd_lvds_bitwidth = 0
lcd_lvds_io_cross = 0
lcd_cpu_if = 0
lcd_frm = 1
lcd_io_cfg0 = 0
lcd_gamma_correction_en = 0
lcd_gamma_tbl_0 = 0x0
lcd_gamma_tbl_1 = 0x10101
lcd_gamma_tbl_255 = 0xffffff
lcd_bl_en_used = 1
lcd_bl_en = port:PH07<1><0><default><1>
lcd_power_used = 1
lcd_power = port:PH08<1><0><default><1>
lcd_pwm_used = 1
lcd_pwm = port:PB02<2><0><default><default>
lcd_gpio_0 =
lcd_gpio_1 =
lcd_gpio_2 =
lcd_gpio_3 =
lcdd0 = port:PD00<2><0><default><default>
lcdd1 = port:PD01<2><0><default><default>
lcdd2 = port:PD02<2><0><default><default>
lcdd3 = port:PD03<2><0><default><default>
lcdd4 = port:PD04<2><0><default><default>
lcdd5 = port:PD05<2><0><default><default>
lcdd6 = port:PD06<2><0><default><default>
lcdd7 = port:PD07<2><0><default><default>
lcdd8 = port:PD08<2><0><default><default>
lcdd9 = port:PD09<2><0><default><default>
lcdd10 = port:PD10<2><0><default><default>
lcdd11 = port:PD11<2><0><default><default>
lcdd12 = port:PD12<2><0><default><default>
lcdd13 = port:PD13<2><0><default><default>
lcdd14 = port:PD14<2><0><default><default>
lcdd15 = port:PD15<2><0><default><default>
lcdd16 = port:PD16<2><0><default><default>
lcdd17 = port:PD17<2><0><default><default>
lcdd18 = port:PD18<2><0><default><default>
lcdd19 = port:PD19<2><0><default><default>
lcdd20 = port:PD20<2><0><default><default>
lcdd21 = port:PD21<2><0><default><default>
lcdd22 = port:PD22<2><0><default><default>
lcdd23 = port:PD23<2><0><default><default>
lcdclk = port:PD24<2><0><default><default>
lcdde = port:PD25<2><0><default><default>
lcdhsync = port:PD26<2><0><default><default>
lcdvsync = port:PD27<2><0><default><default>

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on the board.
Reboot the Orange Pi system, the LCD should be ready to work.

Porting HDMI Driver

HDMI driver has been includes in the kernel, just config the script.fex directly:

[disp_init]
disp_init_enable = 1
disp_mode = 0
screen0_output_type = 3
screen0_output_mode = 4
screen1_output_type = 0
screen1_output_mode = 4
fb0_width = 1024
fb0_height = 768
fb0_framebuffer_num = 2
fb0_format = 10
fb0_pixel_sequence = 0
fb0_scaler_mode_enable = 0
fb1_width = 1024
fb1_height = 768
fb1_framebuffer_num = 2
fb1_format = 10
fb1_pixel_sequence = 0
fb1_scaler_mode_enable = 0
lcd0_backlight = 197
lcd1_backlight = 197
lcd0_bright = 50
lcd0_contrast = 50
lcd0_saturation = 57
lcd0_hue = 50
lcd1_bright = 50
lcd1_contrast = 50
lcd1_saturation = 57
lcd1_hue = 50

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on the board.
Reboot the system, now the HDMI can be used for displaying.

Porting AV driver

AV driver has been included in the kernel, just config the script.fex directly:

[disp_init]
disp_init_enable = 1
disp_mode = 0
screen0_output_type = 2
screen0_output_mode = 11
screen1_output_type = 0
screen1_output_mode = 4
fb0_width = 1024
fb0_height = 768
fb0_framebuffer_num = 2
fb0_format = 10
fb0_pixel_sequence = 0
fb0_scaler_mode_enable = 0
fb1_width = 1024
fb1_height = 768
fb1_framebuffer_num = 2
fb1_format = 10
fb1_pixel_sequence = 0
fb1_scaler_mode_enable = 0
lcd0_backlight = 197
lcd1_backlight = 197
lcd0_bright = 50
lcd0_contrast = 50
lcd0_saturation = 57
lcd0_hue = 50
lcd1_bright = 50
lcd1_contrast = 50
lcd1_saturation = 57
lcd1_hue = 50

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on the board.
Reboot the system, now the AV port can be used for displaying.

Porting CSI Driver

Config the Kernel

make menuconfig


Device Drivers  --->
   <*> Multimedia support  --->
      <*>   Video For Linux
      [*]   CSI Driver Config for sun4i  --->
          <M>   OmniVision OV5460 sensor support

Built the camera driver as module, save and exit.
Comment out the print messages in the s32 img_sw_para_to_reg(u8 type, u8 mode, u8 value) function in disp_layer.c file, which is under drivers/video/sunxi/disp directory.
Lines 95 to 99:

/*      else {
            DE_WRN("not supported yuv channel format:%d in "
                    "img_sw_para_to_regn", value);
            return 0;
         }*/

Lines 125 to 129:

/*      else {
         DE_WRN("not supported yuv channel pixel sequence:%d "
                    "in img_sw_para_to_regn", value);
            return 0;
         }*/

Lines 168 to 172:

/*      else {
          DE_WRN("not supported image0 pixel sequence:%d in "
                    "img_sw_para_to_regn", value);
            return 0;
         }*/

Line 175:

//  DE_WRN("not supported type:%d in img_sw_para_to_regn", type);

Save, re-compile the kernel:

make uImage

Compile the kernel modules:

make modules

Install the kernel modules:

make modules_install

The installation copies the compiled kernel module from the kernel source code to the ubuntu /lib/modules directory.
The related driver module files include: videobuf-core.ko, videobuf-dma-contig.ko, sun4i_csi0.ko, ov7670.ko, which are located respectively in:

videobuf-core.ko, videobuf-dma-contig.ko:
/lib/modules/3.4.XX/kernel/drivers/media/video

ov5640.ko: /lib/modules/3.4.XX/kernel/drivers/media/video/sun4i_csi/device
sun4i_csi0.ko: /lib/modules/3.4.XX/kernel/drivers/media/video/sun4i_csi/csi0

Replace the earlier uImage on Orange Pi with the new generated uImage under arch/arm/boot/ directory.
Copy the above 4 driver files to the board, and install them in order:

insmod  videobuf-core.ko
insmod  videobuf-dma-contig.ko
insmod  ov5640.ko
insmod  sun4i_csi0.ko

Note: please pay attention to the installing order, camera driver should be installed before sun4i_csi0.ko.

Config the script.fex

Since our OV5460 camera is connected to the CSI0 controller, config the [csi0_para] and [camera_list_para] setting in script.fex. The suffix _b in the parameter name indicates that this is a secondary camera parameter while two cameras were connected to the same CSI port.

The details configuration of CSI0:

[csi0_para]
csi_used = 1
csi_dev_qty = 1
csi_stby_mode = 0
csi_mname = "ov5460"
csi_if = 0
csi_iovdd = "axp20_pll"
csi_avdd = ""
csi_dvdd = ""
csi_vol_iovdd = 2800
csi_vol_dvdd =
csi_vol_avdd =
csi_vflip = 1
csi_hflip = 0
csi_flash_pol = 1
csi_facing = 1
csi_twi_id = 1
csi_twi_addr = 0x78
csi_pck = port:PE00<3><default><default><default>
csi_ck = port:PE01<3><default><default><default>
csi_hsync = port:PE02<3><default><default><default>
csi_vsync = port:PE03<3><default><default><default>
csi_d0 = port:PE04<3><default><default><default>
csi_d1 = port:PE05<3><default><default><default>
csi_d2 = port:PE06<3><default><default><default>
csi_d3 = port:PE07<3><default><default><default>
csi_d4 = port:PE08<3><default><default><default>
csi_d5 = port:PE09<3><default><default><default>
csi_d6 = port:PE10<3><default><default><default>
csi_d7 = port:PE11<3><default><default><default>
csi_reset = port:PH14<1><default><default><0>
csi_power_en = port:PH16<1><default><default><0>
csi_stby = port:PH19<1><default><default><0>


[camera_list_para]
camera_list_para_used = 1
ov7670 = 0
gc0308 = 0
gt2005 = 0
hi704 = 0
sp0838 = 0
mt9m112 = 0
mt9m113 = 0
ov2655 = 0
hi253 = 0
gc0307 = 0
mt9d112 = 0
ov5640 = 1
gc2015 = 0
ov2643 = 0
gc0329 = 0
gc0309 = 0
tvp5150 = 0
s5k4ec = 0
ov5650_mv9335 = 0
siv121d = 0
gc2035 = 0


Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on the board.
Connect the OV5640 camera module to Orange Pi, reboot Orange Pi.
Now you can start to try the camera .

Porting USB OTG Driver

Config the Kernel

Config the kernel to include the OTG driver:

make menuconfig
Device Drivers  --->
   [*]USB support  --->
       [*]SUNXI USB2.0 Dual Role Controller support
            [*]SUNXI USB2.0 Manager            
                 USB0 Controller support (otg support) --->
                      (X)otg_suppot

Save and exit. Re-compile the kernel:

make uImage

Replace the earlier uImage on Orange Pi with the new generated uImage under arch/arm/boot/ directory.

Config the script.fex

Config the script.fex as follows, modify the [usbc0] setting as follow:

[usbc0]
usb_used = 1
usb_port_type = 2
usb_detect_type = 1
usb_id_gpio = port:PH04<0><1><default><default>
usb_det_vbus_gpio = port:PH05<0><0><default><default>
usb_drv_vbus_gpio = port:PB09<1><0><default><0>
usb_restric_gpio = port:PH00<1><0><default><0>
usb_host_init_state = 0
usb_restric_flag = 0
usb_restric_voltage = 3550000
usb_restric_capacity = 5

Then convert it into script.bin format by using fex2bin, and replace the earlier script.bin on Orange Pi.

Reboot the Orange Pi system, and connect the OTG cable to the USB OTG port.

Reference

1. Fex_Guide
2. http://docs.cubieboard.org/tutorials/dvk521/documentations/a20/driver_porting_and_configuration

Retrieved from "http://wiki.orangepi.org/index.php?title=Kernel_drivers_porting_and_configuration&oldid=2397"