rk30_phonepad:add get board id support
authorluowei <lw@rock-chips.com>
Mon, 8 Oct 2012 06:07:57 +0000 (14:07 +0800)
committerluowei <lw@rock-chips.com>
Mon, 8 Oct 2012 06:09:15 +0000 (14:09 +0800)
arch/arm/plat-rk/include/plat/board.h [changed mode: 0644->0755]
drivers/input/misc/Kconfig
drivers/input/misc/Makefile
drivers/input/misc/rk_board_id.c [new file with mode: 0644]

old mode 100644 (file)
new mode 100755 (executable)
index 6178c32..7fe3246
@@ -186,6 +186,15 @@ struct sensor_platform_data {
        int (*power_off)(void);
 };
 
+/* Platform data for the board id */
+struct board_id_platform_data {
+       int gpio_pin[32];
+       int num_gpio;
+       int (*init_platform_hw)(void);  
+       int (*exit_platform_hw)(void);  
+};
+
+
 
 struct goodix_platform_data {
        int model ;
index cc7ab5426d269ef7a3956833eb85f3c7afdf5539..b2d165feab474acadeb1c7add2aa992f054a3043 100755 (executable)
@@ -329,6 +329,11 @@ config INPUT_GPIO
        help
          Say Y here if you want to support gpio based keys, wheels etc...
 
+
+config RK_BOARD_ID
+       tristate "get board id support"
+
+
 config HP_SDC_RTC
        tristate "HP SDC Real Time Clock"
        depends on (GSC || HP300) && SERIO
index eaab936a0ada742d902b29a4e9e43d3c488b8015..93e4103aa35fb1ead2f896e791442f913705e511 100755 (executable)
@@ -25,6 +25,7 @@ obj-$(CONFIG_INPUT_CMA3000_I2C)               += cma3000_d0x_i2c.o
 obj-$(CONFIG_INPUT_COBALT_BTNS)                += cobalt_btns.o
 obj-$(CONFIG_INPUT_DM355EVM)           += dm355evm_keys.o
 obj-$(CONFIG_INPUT_GPIO)               += gpio_event.o gpio_matrix.o gpio_input.o gpio_output.o gpio_axis.o
+obj-$(CONFIG_RK_BOARD_ID)              += rk_board_id.o
 obj-$(CONFIG_HP_SDC_RTC)               += hp_sdc_rtc.o
 obj-$(CONFIG_INPUT_IXP4XX_BEEPER)      += ixp4xx-beeper.o
 obj-$(CONFIG_INPUT_KEYCHORD)           += keychord.o
diff --git a/drivers/input/misc/rk_board_id.c b/drivers/input/misc/rk_board_id.c
new file mode 100644 (file)
index 0000000..d1baf0a
--- /dev/null
@@ -0,0 +1,135 @@
+#include <linux/kernel.h>\r
+#include <linux/init.h>\r
+#include <linux/platform_device.h>\r
+#include <linux/input.h>\r
+#include <linux/io.h>\r
+#include <linux/delay.h>\r
+#include <linux/i2c.h>\r
+#include <linux/skbuff.h>\r
+\r
+#include <mach/board.h>\r
+#include <mach/io.h>\r
+#include <mach/gpio.h>\r
+#include <mach/iomux.h>\r
+\r
+\r
+#if 0\r
+#define DBG(x...)  printk(x)\r
+#else\r
+#define DBG(x...)\r
+#endif\r
+\r
+struct board_id_private_data {\r
+       struct mutex id_mutex;\r
+       int board_id;\r
+       struct board_id_platform_data *pdata;\r
+};\r
+\r
+static struct board_id_private_data *g_id;\r
+\r
+\r
+int rk_get_board_id(void)\r
+{\r
+       struct board_id_private_data *id = g_id;\r
+       DBG("%s:id:0x%x\n",__func__,id->board_id);\r
+       return id->board_id;\r
+}\r
+EXPORT_SYMBOL(rk_get_board_id);\r
+\r
+static int _rk_get_board_id(struct board_id_private_data *id)\r
+{\r
+       int result = 0;\r
+       int value = 0;\r
+       int i = 0;\r
+       \r
+       id->board_id = -1;\r
+                       \r
+       for(i=0; i<id->pdata->num_gpio; i++)\r
+       {\r
+               gpio_request(id->pdata->gpio_pin[i],"gpio_board_id");\r
+               gpio_direction_input(id->pdata->gpio_pin[i]);\r
+               gpio_pull_updown(id->pdata->gpio_pin[i], PullDisable);\r
+               value = gpio_get_value(id->pdata->gpio_pin[i]);\r
+               if(value < 0)\r
+                       return value;\r
+               result = (value << i) | result;\r
+               \r
+               DBG("%s:gpio:%d,value:%d\n",__func__,id->pdata->gpio_pin[i],value);\r
+       }\r
+       \r
+       id->board_id = result;\r
+\r
+       \r
+       DBG("%s:num=%d,id=0x%x\n",__func__,id->pdata->num_gpio, id->board_id);\r
+\r
+       return result;\r
+}\r
+\r
+\r
+static int __devinit rk_board_id_probe(struct platform_device *pdev)\r
+{\r
+       struct board_id_platform_data *pdata = pdev->dev.platform_data;\r
+       struct board_id_private_data *id = NULL;\r
+       int result = 0;\r
+\r
+       if(!pdata)\r
+               return -ENOMEM;\r
+       \r
+       id = kzalloc(sizeof(struct board_id_private_data), GFP_KERNEL);\r
+       if (id == NULL) {\r
+               dev_err(&pdev->dev, "Unable to allocate private data\n");\r
+               return -ENOMEM;\r
+       }\r
+\r
+       id->pdata = pdata;\r
+       \r
+       if(pdata->init_platform_hw)\r
+               pdata->init_platform_hw();\r
+       \r
+       result = _rk_get_board_id(id);\r
+\r
+       if(pdata->exit_platform_hw)\r
+               pdata->exit_platform_hw();\r
+       \r
+       platform_set_drvdata(pdev, id); \r
+       g_id = id;\r
+       \r
+       printk("%s:board id :0x%x\n",__func__,result);\r
+       return 0;\r
+}\r
+\r
+static int __devexit rk_board_id_remove(struct platform_device *pdev)\r
+{\r
+       //struct board_id_platform_data *pdata = pdev->dev.platform_data;\r
+       struct board_id_private_data *id = platform_get_drvdata(pdev);\r
+       \r
+       kfree(id);\r
+       \r
+       return 0;\r
+}\r
+\r
+static struct platform_driver rk_board_id_driver = {\r
+       .probe          = rk_board_id_probe,\r
+       .remove         = __devexit_p(rk_board_id_remove),\r
+       .driver         = {\r
+               .name   = "rk-board-id",\r
+               .owner  = THIS_MODULE,\r
+       },\r
+};\r
+\r
+static int __init rk_get_board_init(void)\r
+{\r
+       return platform_driver_register(&rk_board_id_driver);\r
+}\r
+\r
+static void __exit rk_get_board_exit(void)\r
+{\r
+       platform_driver_unregister(&rk_board_id_driver);\r
+}\r
+\r
+subsys_initcall_sync(rk_get_board_init);\r
+module_exit(rk_get_board_exit);\r
+\r
+MODULE_AUTHOR("ROCKCHIP Corporation:lw@rock-chips.com");\r
+MODULE_DESCRIPTION("Interface for get board id");\r
+MODULE_LICENSE("GPL");\r