#include <linux/workqueue.h>\r
#include <linux/freezer.h>\r
#include <linux/proc_fs.h>\r
-#include <mach/gpio.h>\r
-#include <mach/board.h> \r
+#include <linux/gpio.h>\r
+#include <linux/of_gpio.h>\r
+#include <linux/of.h>\r
#ifdef CONFIG_HAS_EARLYSUSPEND\r
#include <linux/earlysuspend.h>\r
#endif\r
#include <linux/l3g4200d.h>\r
#include <linux/sensor-dev.h>\r
+#include <linux/module.h>\r
+\r
\r
\r
/*\r
(struct sensor_private_data *) i2c_get_clientdata(client); \r
int result = 0;\r
int irq;\r
- if((sensor->pdata->irq_enable)&&(sensor->ops->trig != SENSOR_UNKNOW_DATA))\r
+ if((sensor->pdata->irq_enable)&&(sensor->pdata->irq_flags!= SENSOR_UNKNOW_DATA))\r
{\r
//INIT_DELAYED_WORK(&sensor->delaywork, sensor_delaywork_func);\r
if(sensor->pdata->poll_delay_ms < 0)\r
sensor->pdata->poll_delay_ms = 30;\r
- \r
result = gpio_request(client->irq, sensor->i2c_id->name);\r
if (result)\r
{\r
printk("%s:fail to request gpio :%d\n",__func__,client->irq);\r
}\r
- \r
- gpio_pull_updown(client->irq, PullEnable);\r
+ \r
+ //gpio_pull_updown(client->irq, PullEnable);\r
irq = gpio_to_irq(client->irq);\r
//result = request_irq(irq, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor);\r
- result = request_threaded_irq(irq, NULL, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor);\r
+ //result = request_threaded_irq(irq, NULL, sensor_interrupt, sensor->ops->trig, sensor->ops->name, sensor);\r
+ result = devm_request_threaded_irq(&client->dev, irq, NULL, sensor_interrupt, sensor->pdata->irq_flags | IRQF_ONESHOT, sensor->ops->name, sensor);\r
if (result) {\r
printk(KERN_ERR "%s:fail to request irq = %d, ret = 0x%x\n",__func__, irq, result); \r
goto error; \r
disable_irq_nosync(client->irq);//disable irq \r
if(((sensor->pdata->type == SENSOR_TYPE_TEMPERATURE) || (sensor->pdata->type == SENSOR_TYPE_PRESSURE))&& (!(sensor->ops->trig & IRQF_SHARED))) \r
disable_irq_nosync(client->irq);//disable irq\r
- printk("%s:use irq=%d\n",__func__,irq);\r
+ DBG("%s:use irq=%d\n",__func__,irq);\r
}\r
else if(!sensor->pdata->irq_enable)\r
{ \r
if(sensor->pdata->poll_delay_ms < 0)\r
sensor->pdata->poll_delay_ms = 30;\r
\r
- printk("%s:use polling,delay=%d ms\n",__func__,sensor->pdata->poll_delay_ms);\r
+ DBG("%s:use polling,delay=%d ms\n",__func__,sensor->pdata->poll_delay_ms);\r
}\r
\r
error: \r
struct sensor_private_data *sensor =\r
(struct sensor_private_data *) i2c_get_clientdata(client);\r
struct sensor_platform_data *pdata;\r
+ struct device_node *np = client->dev.of_node;\r
+ enum of_gpio_flags rst_flags, pwr_flags;\r
+ unsigned long irq_flags;\r
int result = 0;\r
int type = 0;\r
\r
result = -ENODEV;\r
goto out_no_free;\r
}\r
-\r
- pdata = client->dev.platform_data;\r
+ if (!np) {\r
+ dev_err(&client->dev, "no device tree\n");\r
+ return -EINVAL;\r
+ }\r
+ pdata = devm_kzalloc(&client->dev,sizeof(*pdata), GFP_KERNEL);\r
if (!pdata) {\r
- dev_err(&client->adapter->dev,\r
- "Missing platform data for slave %s\n", devid->name);\r
- result = -EFAULT;\r
+ result = -ENOMEM;\r
goto out_no_free;\r
}\r
-\r
- sensor = kzalloc(sizeof(*sensor), GFP_KERNEL);\r
+ sensor = devm_kzalloc(&client->dev,sizeof(*sensor), GFP_KERNEL);\r
if (!sensor) {\r
result = -ENOMEM;\r
goto out_no_free;\r
}\r
+ \r
+ of_property_read_u32(np,"type",&(pdata->type));\r
+\r
+ pdata->irq_pin = of_get_named_gpio_flags(np, "irq-gpio", 0,(enum of_gpio_flags *)&irq_flags);\r
+ pdata->reset_pin = of_get_named_gpio_flags(np, "reset-gpio",0,&rst_flags);\r
+ pdata->power_pin = of_get_named_gpio_flags(np, "power-gpio",0,&pwr_flags);\r
+ \r
+ of_property_read_u32(np,"irq_enable",&(pdata->irq_enable));\r
+ of_property_read_u32(np,"poll_delay_ms",&(pdata->poll_delay_ms));\r
+\r
+ of_property_read_u32(np,"x_min",&(pdata->x_min));\r
+ of_property_read_u32(np,"y_min",&(pdata->y_min));\r
+ of_property_read_u32(np,"z_min",&(pdata->z_min));\r
+ of_property_read_u32(np,"factory",&(pdata->factory));\r
+ of_property_read_u32(np,"layout",&(pdata->layout));\r
+\r
+ of_property_read_u8(np,"address",&(pdata->address));\r
+ pdata->project_name = of_get_property(np, "project_name", NULL);\r
+\r
+\r
+ switch(pdata->layout)\r
+ {\r
+ case 1:\r
+ pdata->orientation[0] = 1;\r
+ pdata->orientation[1] = 0;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 0;\r
+ pdata->orientation[4] = 1;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = 1;\r
+ break;\r
+\r
+ case 2:\r
+ pdata->orientation[0] = 0;\r
+ pdata->orientation[1] = -1;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 1;\r
+ pdata->orientation[4] = 0;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = 1;\r
+ break;\r
+\r
+ case 3:\r
+ pdata->orientation[0] = -1;\r
+ pdata->orientation[1] = 0;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 0;\r
+ pdata->orientation[4] = -1;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = 1;\r
+ break;\r
+\r
+ case 4:\r
+ pdata->orientation[0] = 0;\r
+ pdata->orientation[1] = 1;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = -1;\r
+ pdata->orientation[4] = 0;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = 1;\r
+ break;\r
+\r
+ case 5:\r
+ pdata->orientation[0] = 1;\r
+ pdata->orientation[1] = 0;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 0;\r
+ pdata->orientation[4] = -1;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = -1;\r
+ break;\r
+\r
+ case 6:\r
+ pdata->orientation[0] = 0;\r
+ pdata->orientation[1] = -1;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = -1;\r
+ pdata->orientation[4] = 0;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = -1;\r
+ break;\r
+\r
+ case 7:\r
+ pdata->orientation[0] = -1;\r
+ pdata->orientation[1] = 0;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 0;\r
+ pdata->orientation[4] = 1;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = -1;\r
+ break;\r
+\r
+ case 8:\r
+ pdata->orientation[0] = 0;\r
+ pdata->orientation[1] = 1;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 1;\r
+ pdata->orientation[4] = 0;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = -1;\r
+ break;\r
+\r
+ default:\r
+ pdata->orientation[0] = 1;\r
+ pdata->orientation[1] = 0;\r
+ pdata->orientation[2] = 0;\r
+\r
+ pdata->orientation[3] = 0;\r
+ pdata->orientation[4] = 1;\r
+ pdata->orientation[5] = 0;\r
+\r
+ pdata->orientation[6] = 0;\r
+ pdata->orientation[7] = 0;\r
+ pdata->orientation[8] = 1;\r
+ break;\r
+ }\r
\r
- type= pdata->type; \r
+ client->irq = pdata->irq_pin;\r
+ type = pdata->type;\r
+ pdata->irq_flags = irq_flags;\r
+ printk("irq_flags = %lu padta->irq_flags = %lu\n",irq_flags, pdata->irq_flags);\r
+ printk("type = %d \n",pdata->type);\r
+ printk("irq = %d \n",pdata->irq);\r
+ printk("irq_pin = %d \n",pdata->irq_pin);\r
+ printk("pwer_pin = %d \n",pdata->power_pin); \r
+ printk("reset_pin = %d \n",pdata->reset_pin);\r
+ printk("irq_enable = %d \n",pdata->irq_enable);\r
+\r
+ printk("poll_delay_ms = %d \n",pdata->poll_delay_ms);\r
+ printk("x_min = %d \n",pdata->x_min);\r
+ printk("y_min = %d \n",pdata->y_min);\r
+ printk("z_min = %d \n",pdata->z_min); \r
+ printk("factory = %d \n",pdata->factory);\r
+ printk("layout = %d \n",pdata->layout);\r
+ printk("address = 0x%x \n",pdata->address);\r
+ printk("project_name = [%s] \n",pdata->project_name);\r
+ \r
+ printk(" == %d,%d ,%d \t ,%d ,%d ,%d , \t ,%d, %d, %d ,==%d\n",pdata->orientation[0],pdata->orientation[1],pdata->orientation[2]\r
+ ,pdata->orientation[3],pdata->orientation[4],pdata->orientation[5]\r
+ ,pdata->orientation[6],pdata->orientation[7],pdata->orientation[8],ARRAY_SIZE(pdata->orientation));\r
+ \r
\r
if((type >= SENSOR_NUM_TYPES) || (type <= SENSOR_TYPE_NULL))\r
{ \r
- dev_err(&client->adapter->dev, "sensor type is error %d\n", pdata->type);\r
+ dev_err(&client->adapter->dev, "sensor type is error %d\n", type);\r
result = -EFAULT;\r
goto out_no_free; \r
}\r
-\r
if(((int)devid->driver_data >= SENSOR_NUM_ID) || ((int)devid->driver_data <= ID_INVALID))\r
{ \r
dev_err(&client->adapter->dev, "sensor id is error %d\n", (int)devid->driver_data);\r
result = -EFAULT;\r
goto out_no_free; \r
}\r
- \r
i2c_set_clientdata(client, sensor);\r
sensor->client = client; \r
sensor->pdata = pdata; \r
sensor->type = type;\r
sensor->i2c_id = (struct i2c_device_id *)devid;\r
\r
- if (pdata->init_platform_hw) {\r
- result = pdata->init_platform_hw();\r
- if (result < 0)\r
- goto out_free_memory;\r
- }\r
-\r
- if(pdata->reset_pin)\r
- gpio_request(pdata->reset_pin,"sensor_reset_pin");\r
-\r
- if(pdata->power_pin)\r
- gpio_request(pdata->power_pin,"sensor_power_pin");\r
\r
memset(&(sensor->axis), 0, sizeof(struct sensor_axis) );\r
atomic_set(&(sensor->data_ready), 0);\r
atomic_set(&sensor->flags.a_flag, 1);\r
atomic_set(&sensor->flags.mv_flag, 1); \r
atomic_set(&sensor->flags.open_flag, 0);\r
- atomic_set(&sensor->flags.debug_flag, 0);\r
+ atomic_set(&sensor->flags.debug_flag, 1);\r
init_waitqueue_head(&sensor->flags.open_wq);\r
sensor->flags.delay = 100;\r
\r
{},\r
};\r
\r
+static struct of_device_id sensor_dt_ids[] = {\r
+ /*gsensor*/\r
+ { .compatible = "gs_mma8452" },\r
+ { .compatible = "gs_lis3dh" },\r
+ { .compatible = "gs_lsm303d" },\r
+ { .compatible = "gs_mma7660" },\r
+ \r
+ /*compass*/\r
+ { .compatible = "ak8975" },\r
+ { .compatible = "ak8963" },\r
+ { .compatible = "ak09911" },\r
+ { .compatible = "mmc314x" },\r
+\r
+ /* gyroscop*/\r
+ { .compatible = "l3g4200d_gyro" },\r
+ { .compatible = "l3g20d_gyro" },\r
+ { .compatible = "ewtsa_gyro" },\r
+ { .compatible = "k3g" },\r
+ \r
+ \r
+ /*light sensor*/\r
+ { .compatible = "light_cm3217" },\r
+ { .compatible = "light_cm3232" },\r
+ { .compatible = "light_al3006" },\r
+ { .compatible = "ls_stk3171" },\r
+ { .compatible = "ls_ap321xx" },\r
+\r
+ { .compatible = "ls_photoresistor" },\r
+ { .compatible = "ls_us5152" },\r
+\r
+ /*temperature sensor*/\r
+ { .compatible = "tmp_ms5607" },\r
+ \r
+ /*pressure sensor*/\r
+ { .compatible = "pr_ms5607" },\r
+\r
+ /*hall sensor*/\r
+ { .compatible = "hall_och165t" },\r
+ { }\r
+};\r
+\r
\r
static struct i2c_driver sensor_driver = {\r
.probe = sensor_probe,\r
.driver = {\r
.owner = THIS_MODULE,\r
.name = "sensors",\r
- },\r
+ .of_match_table = of_match_ptr(sensor_dt_ids),\r
+ },\r
};\r
\r
static int __init sensor_init(void)\r