--- /dev/null
+#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