i2s: add support samplerate up to 192K and support S32_LE
[firefly-linux-kernel-4.4.55.git] / drivers / video / display / transmitter / tc358768.c
index 7beb9e4ae8abd128308af292363ae597cca1a4fb..5f573b3dce8e2274c3b93542dba259731cbd3f27 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 ROCKCHIP, Inc.
- *
+ * drivers/video/display/transmitter/tc358768.c
  * author: hhb@rock-chips.com
  * create date: 2012-10-26
  * This software is licensed under the terms of the GNU General Public
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
-#include "tc358768.h"
+#include <linux/fb.h>
+#include <linux/delay.h>
+#include <linux/rk_fb.h>
+#include <mach/gpio.h>
+#include <mach/iomux.h>
+#include <mach/board.h>
+#include <linux/rk_screen.h>
+#include <linux/ktime.h>
+#include "mipi_dsi.h"
+
+#define CONFIG_TC358768_I2C     1
+#define CONFIG_TC358768_I2C_CLK     400*1000
+
 
 #if 0
 #define dsi_debug   printk
@@ -22,9 +33,9 @@
 #endif
 
 #ifdef CONFIG_TC358768_I2C
-struct tc358768_t *tc358768 = NULL;
-struct i2c_client *tc358768_client = NULL;
-struct mipi_dsi_t *dsi;
+static struct tc358768_t *tc358768 = NULL;
+static struct i2c_client *tc358768_client = NULL;
+static struct mipi_dsi_ops tc358768_ops;
 
 
 u32 i2c_write_32bits(u32 value) 
@@ -89,23 +100,27 @@ int tc358768_gpio_init(void *data) {
        if(reset->reset_pin > INVALID_GPIO) {
                ret = gpio_request(reset->reset_pin, "tc358768_reset");
                if (ret != 0) {
-                       gpio_free(reset->reset_pin);
+                       //gpio_free(reset->reset_pin);
                        printk("%s: request TC358768_RST_PIN error\n", __func__);
                } else {
+#if OLD_RK_IOMUX               
                        if(reset->mux_name)
                                rk30_mux_api_set(reset->mux_name, reset->mux_mode);
-                       gpio_direction_output(reset->reset_pin, reset->effect_value);
+#endif
+                       gpio_direction_output(reset->reset_pin, !reset->effect_value);
                }
        }
        
        if(vdd->enable_pin > INVALID_GPIO) {
                ret = gpio_request(vdd->enable_pin, "tc358768_vddc");
                if (ret != 0) {
-                       gpio_free(vdd->enable_pin);
+                       //gpio_free(vdd->enable_pin);
                        printk("%s: request TC358768_vddc_PIN error\n", __func__);
                } else {
+#if OLD_RK_IOMUX               
                        if(vdd->mux_name)
                                rk30_mux_api_set(vdd->mux_name, vdd->mux_mode); 
+#endif
                        gpio_direction_output(vdd->enable_pin, !vdd->effect_value);
                }
        }
@@ -114,11 +129,13 @@ int tc358768_gpio_init(void *data) {
        if(vdd->enable_pin > INVALID_GPIO) {
                ret = gpio_request(vdd->enable_pin, "tc358768_vddio");
                if (ret != 0) {
-                       gpio_free(vdd->enable_pin);
+                       //gpio_free(vdd->enable_pin);
                        printk("%s: request TC358768_vddio_PIN error\n", __func__);
                } else {
+#if OLD_RK_IOMUX               
                        if(vdd->mux_name)
                                rk30_mux_api_set(vdd->mux_name, vdd->mux_mode); 
+#endif
                        gpio_direction_output(vdd->enable_pin, !vdd->effect_value);     
                }
        }
@@ -127,11 +144,13 @@ int tc358768_gpio_init(void *data) {
        if(vdd->enable_pin > INVALID_GPIO) {
                ret = gpio_request(vdd->enable_pin, "tc358768_vdd_mipi");
                if (ret != 0) {
-                       gpio_free(vdd->enable_pin);
+                       //gpio_free(vdd->enable_pin);
                        printk("%s: request TC358768_vdd_mipi_PIN error\n", __func__);
                } else {
+#if OLD_RK_IOMUX               
                        if(vdd->mux_name)
                                rk30_mux_api_set(vdd->mux_name, vdd->mux_mode); 
+#endif
                        gpio_direction_output(vdd->enable_pin, !vdd->effect_value);     
                }
        }
@@ -142,12 +161,18 @@ int tc358768_gpio_init(void *data) {
 int tc358768_gpio_deinit(void *data) {
        struct reset_t *reset = &tc358768->reset;
        struct power_t *vdd = &tc358768->vddc;
+       gpio_direction_input(reset->reset_pin);
        gpio_free(reset->reset_pin);
        
+       gpio_direction_input(vdd->enable_pin);
+       gpio_free(vdd->enable_pin);
+       
        vdd = &tc358768->vddio;
+       gpio_direction_input(vdd->enable_pin);
        gpio_free(vdd->enable_pin);
        
        vdd = &tc358768->vdd_mipi;
+       gpio_direction_input(vdd->enable_pin);
        gpio_free(vdd->enable_pin);
        return 0;
 }
@@ -195,7 +220,8 @@ int tc358768_vdd_disable(void *data) {
 }
 
 
-int tc358768_power_up(void *data) {
+int tc358768_power_up(void) {
+
        int ret = 0;
        struct tc358768_t *tc = (struct tc358768_t *)tc358768;
        
@@ -207,7 +233,8 @@ int tc358768_power_up(void *data) {
        return ret;
 }
 
-int tc358768_power_down(void *data) {
+int tc358768_power_down(void) {
+
        int ret = 0;
        struct tc358768_t *tc = (struct tc358768_t *)tc358768;
        
@@ -222,7 +249,6 @@ static int tc358768_probe(struct i2c_client *client,
                         const struct i2c_device_id *did) 
 {
     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
-    
     int ret = 0;
 
     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
@@ -230,13 +256,14 @@ static int tc358768_probe(struct i2c_client *client,
                 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
         return -EIO;
     }
+    
     tc358768 = (struct tc358768_t *)client->dev.platform_data;
     if(!tc358768) {
        ret = -1;
        printk("%s:%d tc358768 is null\n", __func__, __LINE__);
        return ret;
     }  
-    
+
     tc358768_client = client;
     if(!tc358768_client) {
        ret = -1;
@@ -273,12 +300,13 @@ static int tc358768_probe(struct i2c_client *client,
     if(!tc358768->vdd_mipi.disable)
        tc358768->vdd_mipi.disable = tc358768_vdd_disable;
        
-    dsi->chip = tc358768;      
-       
+    tc358768_gpio_init(NULL);
+    
     return ret;
 }
 static int tc358768_remove(struct i2c_client *client)
 {
+    tc358768_gpio_deinit(NULL);
     tc358768_client = NULL;
     tc358768 = NULL;
     return 0;
@@ -666,24 +694,50 @@ int mipi_dsi_read_dcs_packet(unsigned char *data, int n) {
        return 0;
 }
 
+int tc358768_get_id(void) {
+       
+       int id = -1;
+       
+       tc358768_power_up();
+       id = tc358768_rd_reg_32bits(0);
+       return id;
+}
+
+static struct mipi_dsi_ops tc358768_ops = {
+       .id = 0x4401,
+       .name = "tc358768a",
+       .get_id = tc358768_get_id,
+       .dsi_set_regs = _tc358768_wr_regs_32bits,
+       .dsi_send_dcs_packet = mipi_dsi_send_dcs_packet,
+       .dsi_read_dcs_packet = mipi_dsi_read_dcs_packet,
+       .power_up = tc358768_power_up,
+       .power_down = tc358768_power_down,
+       
+};
 
-int tc358768_init(struct mipi_dsi_t *pram) {
-       int ret = 0;
-       dsi = pram;
-       if(!dsi)
-               return -1;
-       dsi->id = 0x4401;
-       dsi->dsi_init = _tc358768_wr_regs_32bits;
-       dsi->dsi_hs_start = _tc358768_wr_regs_32bits;
-       dsi->dsi_send_dcs_packet = mipi_dsi_send_dcs_packet;
-       dsi->dsi_read_dcs_packet = mipi_dsi_read_dcs_packet;
+static int __init tc358768_module_init(void)
+{
 #ifdef CONFIG_TC358768_I2C    
     i2c_add_driver(&tc358768_driver);
-#endif    
-       tc358768_gpio_init(NULL);
-       return 0;
-exit_init:
-       //tc358768_power_down(NULL);
-       tc358768_gpio_deinit(NULL);
-       return -1;
+    
+       if(!tc358768 || !tc358768_client)
+               return -1;
+#endif         
+               
+       register_dsi_ops(&tc358768_ops);
+       if(tc358768->id > 0)
+               tc358768_ops.id = tc358768->id;
+    return 0;
 }
+
+static void __exit tc358768_module_exit(void)
+{
+       del_dsi_ops(&tc358768_ops);
+#ifdef CONFIG_TC358768_I2C
+       i2c_del_driver(&tc358768_driver);
+#endif
+}
+
+subsys_initcall_sync(tc358768_module_init);
+//module_exit(tc358768_module_init);
+module_exit(tc358768_module_exit);