diff options
author | Nitin Garg <nitin.garg@freescale.com> | 2012-10-18 19:08:40 -0500 |
---|---|---|
committer | Nitin Garg <nitin.garg@freescale.com> | 2012-10-18 19:20:26 -0500 |
commit | eec23c400e5c39ae338b9112031a302230220294 (patch) | |
tree | 5fdaf2380778e78b88838a7f467b24bd6c048200 /drivers/hwmon | |
parent | 9034a8901397e22523530adafa4c1256ab15fb12 (diff) |
ENGR00230334-2: Port 3.0.35 linux kernel to iMX53 SMD for Jellybean bringup.
Port 3.0.35 linux kernel to iMX53 SMD for Jellybean bringup.
Signed-off-by: Nitin Garg <nitin.garg@freescale.com>
Diffstat (limited to 'drivers/hwmon')
-rwxr-xr-x | drivers/hwmon/da9052-adc.c | 11 | ||||
-rw-r--r-- | drivers/hwmon/imx_ahci_hwmon.c | 12 | ||||
-rwxr-xr-x | drivers/hwmon/mag3110.c | 123 | ||||
-rw-r--r-- | drivers/hwmon/mxc_mma8451.c | 162 |
4 files changed, 180 insertions, 128 deletions
diff --git a/drivers/hwmon/da9052-adc.c b/drivers/hwmon/da9052-adc.c index 6803fc2ccea3..3260eb5f4359 100755 --- a/drivers/hwmon/da9052-adc.c +++ b/drivers/hwmon/da9052-adc.c @@ -2,6 +2,7 @@ * da9052-adc.c -- ADC Driver for Dialog DA9052 * * Copyright(c) 2009 Dialog Semiconductor Ltd. + * Copyright (C) 2012 Freescale Semiconductor, Inc. * * Author: Dialog Semiconductor Ltd <dchen@diasemi.com> * @@ -39,6 +40,15 @@ static const char *input_names[] = { [DA9052_ADC_VBBAT] = "BACK-UP BATTERY TEMP", }; +static struct da9052 *da9052_local; + +int da9052_adc_read(unsigned char channel) +{ + if (da9052_local != NULL) + return da9052_manual_read(da9052_local, channel); + return -1; +} +EXPORT_SYMBOL(da9052_adc_read); int da9052_manual_read(struct da9052 *da9052, unsigned char channel) @@ -591,6 +601,7 @@ static int __init da9052_adc_probe(struct platform_device *pdev) /* Initialize mutex required for ADC Manual read */ mutex_init(&priv->da9052->manconv_lock); + da9052_local = priv->da9052; return 0; out_err_create2: diff --git a/drivers/hwmon/imx_ahci_hwmon.c b/drivers/hwmon/imx_ahci_hwmon.c index 073a2d1697dc..030c455798b8 100644 --- a/drivers/hwmon/imx_ahci_hwmon.c +++ b/drivers/hwmon/imx_ahci_hwmon.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. + * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -57,7 +57,7 @@ static ssize_t imx_ahci_hwmon_temp_show(struct device *dev, { void __iomem *mmio; u32 mpll_test_reg, rtune_ctl_reg, dac_ctl_reg, adc_out_reg; - u32 str1, str2, str3, str4, read_sum, index; + u32 str1, str2, str3, str4, read_sum, index, port_phy_ctl; int m1, m2, a, temp, ret; struct clk *sata_clk, *sata_ref_clk; struct imx_ahci_hwmon *hwmon; @@ -89,6 +89,11 @@ static ssize_t imx_ahci_hwmon_temp_show(struct device *dev, return -1; } + /* Disable PDDQ mode if it is enabled */ + port_phy_ctl = readl(mmio + PORT_PHY_CTL); + if (port_phy_ctl & PORT_PHY_CTL_PDDQ_LOC) + writel(port_phy_ctl & ~PORT_PHY_CTL_PDDQ_LOC, mmio + PORT_PHY_CTL); + /* check rd-wr to reg */ read_sum = 0; sata_phy_cr_addr(SATA_PHY_CR_CLOCK_CRCMP_LT_LIMIT, mmio); @@ -229,6 +234,9 @@ static ssize_t imx_ahci_hwmon_temp_show(struct device *dev, a = (m2 - m1) / (m2 / 1000); temp = ((((-559) * a) / 1000) * a) / 1000 + (1379) * a / 1000 + (-458); + /* Set the Port Phy ctl back */ + writel(port_phy_ctl, mmio + PORT_PHY_CTL); + iounmap(mmio); /* Release the clocks */ diff --git a/drivers/hwmon/mag3110.c b/drivers/hwmon/mag3110.c index 55f2114869cd..f17212553355 100755 --- a/drivers/hwmon/mag3110.c +++ b/drivers/hwmon/mag3110.c @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2011-2012 Freescale Semiconductor, Inc. + * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,11 +40,12 @@ #define MAG3110_AC_OFFSET 0 #define MAG3110_DR_MODE_MASK (0x7 << 5) #define MAG3110_DR_MODE_OFFSET 5 -#define MAG3110_IRQ_USED 0 +#define MAG3110_IRQ_USED 1 -#define POLL_INTERVAL_MAX 500 -#define POLL_INTERVAL 100 -#define INT_TIMEOUT 1000 +#define POLL_INTERVAL_MIN 100 +#define POLL_INTERVAL_MAX 1000 +#define POLL_INTERVAL 500 +#define INT_TIMEOUT 1000 /* register enum for mag3110 registers */ enum { MAG3110_DR_STATUS = 0x00, @@ -83,15 +84,16 @@ struct mag3110_data { int position; }; static short MAGHAL[8][3][3] = { - { {0, 1, 0}, {-1, 0, 0}, {0, 0, 1} }, - { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }, - { {0, -1, 0}, {1, 0, 0}, {0, 0, 1} }, - { {-1, 0, 0}, {0, -1, 0}, {0, 0, 1} }, - - { {0, 1, 0}, {1, 0, 0}, {0, 0, -1} }, - { {1, 0, 0}, {0, -1, 0}, {0, 0, -1} }, - { {0, -1, 0}, {-1, 0, 0}, {0, 0, -1} }, - { {-1, 0, 0}, {0, 1, 0}, {0, 0, -1} }, + {{ 0, 1, 0}, {-1, 0, 0}, {0, 0, 1} }, + {{ 1, 0, 0}, { 0, 1, 0}, {0, 0, 1} }, + {{ 0, -1, 0}, { 1, 0, 0}, {0, 0, 1} }, + {{-1, 0, 0}, { 0, -1, 0}, {0, 0, 1} }, + + {{ 0, 1, 0}, { 1, 0, 0}, {0, 0, -1} }, + {{ 1, 0, 0}, { 0, -1, 0}, {0, 0, -1} }, + {{ 0, -1, 0}, {-1, 0, 0}, {0, 0, -1} }, + {{-1, 0, 0}, { 0, 1, 0}, {0, 0, -1} }, + }; static struct mag3110_data *mag3110_pdata; @@ -106,9 +108,11 @@ static int mag3110_adjust_position(short *x, short *y, short *z) int position = mag3110_pdata->position; if (position < 0 || position > 7) position = 0; + rawdata[0] = *x; rawdata[1] = *y; rawdata[2] = *z; + for (i = 0; i < 3; i++) { data[i] = 0; for (j = 0; j < 3; j++) @@ -142,9 +146,10 @@ static int mag3110_write_reg(struct i2c_client *client, u8 reg, char value) * This function do multiple mag3110 registers read. */ static int mag3110_read_block_data(struct i2c_client *client, u8 reg, - int count, u8 *addr) + int count, u8 *addr) { - if (i2c_smbus_read_i2c_block_data(client, reg, count, addr) < count) { + if (i2c_smbus_read_i2c_block_data + (client, reg, count, addr) < count) { dev_err(&client->dev, "i2c block read failed\n"); return -1; } @@ -172,24 +177,27 @@ static int mag3110_init_client(struct i2c_client *client) } /*************************************************************** -* -* read sensor data from mag3110 -* -***************************************************************/ + * + * read sensor data from mag3110 + * + ***************************************************************/ static int mag3110_read_data(short *x, short *y, short *z) { struct mag3110_data *data; - int retry = 3; u8 tmp_data[MAG3110_XYZ_DATA_LEN]; +#if !MAG3110_IRQ_USED + int retry = 3; int result; +#endif + if (!mag3110_pdata || mag3110_pdata->active == MAG_STANDBY) return -EINVAL; data = mag3110_pdata; #if MAG3110_IRQ_USED if (!wait_event_interruptible_timeout - (data->waitq, data->data_ready != 0, - msecs_to_jiffies(INT_TIMEOUT))) { + (data->waitq, data->data_ready != 0, + msecs_to_jiffies(INT_TIMEOUT))) { dev_dbg(&data->client->dev, "interrupt not received\n"); return -ETIME; } @@ -197,11 +205,12 @@ static int mag3110_read_data(short *x, short *y, short *z) do { msleep(1); result = i2c_smbus_read_byte_data(data->client, - MAG3110_DR_STATUS); + MAG3110_DR_STATUS); retry--; } while (!(result & MAG3110_STATUS_ZYXDR) && retry > 0); /* Clear data_ready flag after data is read out */ if (retry == 0) { + printk(KERN_DEBUG "magd wait data ready timeout....\n"); return -EINVAL; } #endif @@ -209,8 +218,7 @@ static int mag3110_read_data(short *x, short *y, short *z) data->data_ready = 0; if (mag3110_read_block_data(data->client, - MAG3110_OUT_X_MSB, MAG3110_XYZ_DATA_LEN, - tmp_data) < 0) + MAG3110_OUT_X_MSB, MAG3110_XYZ_DATA_LEN, tmp_data) < 0) return -1; *x = ((tmp_data[0] << 8) & 0xff00) | tmp_data[1]; @@ -253,7 +261,7 @@ static irqreturn_t mag3110_irq_handler(int irq, void *dev_id) } #endif static ssize_t mag3110_enable_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct i2c_client *client; int val; @@ -266,8 +274,8 @@ static ssize_t mag3110_enable_show(struct device *dev, } static ssize_t mag3110_enable_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { struct i2c_client *client; int reg, ret, enable; @@ -277,7 +285,7 @@ static ssize_t mag3110_enable_store(struct device *dev, mutex_lock(&mag3110_lock); client = mag3110_pdata->client; reg = mag3110_read_reg(client, MAG3110_CTRL_REG1); - if (enable && mag3110_pdata->active == MAG_STANDBY) { + if (enable && mag3110_pdata->active == MAG_STANDBY) { reg |= MAG3110_AC_MASK; ret = mag3110_write_reg(client, MAG3110_CTRL_REG1, reg); if (!ret) @@ -293,33 +301,33 @@ static ssize_t mag3110_enable_store(struct device *dev, msleep(100); /* Read out MSB data to clear interrupt flag automatically */ mag3110_read_block_data(client, MAG3110_OUT_X_MSB, - MAG3110_XYZ_DATA_LEN, tmp_data); + MAG3110_XYZ_DATA_LEN, tmp_data); } mutex_unlock(&mag3110_lock); return count; } static DEVICE_ATTR(enable, S_IWUSR | S_IRUGO, - mag3110_enable_show, mag3110_enable_store); + mag3110_enable_show, mag3110_enable_store); static ssize_t mag3110_dr_mode_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct i2c_client *client; int val; client = mag3110_pdata->client; val = (mag3110_read_reg(client, MAG3110_CTRL_REG1) - & MAG3110_DR_MODE_MASK) >> MAG3110_DR_MODE_OFFSET; + & MAG3110_DR_MODE_MASK) >> MAG3110_DR_MODE_OFFSET; return sprintf(buf, "%d\n", val); } static ssize_t mag3110_dr_mode_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { - struct i2c_client *client; + struct i2c_client *client ; int reg, ret; unsigned long val; @@ -329,7 +337,7 @@ static ssize_t mag3110_dr_mode_store(struct device *dev, client = mag3110_pdata->client; reg = mag3110_read_reg(client, MAG3110_CTRL_REG1) & - ~MAG3110_DR_MODE_MASK; + ~MAG3110_DR_MODE_MASK; reg |= (val << MAG3110_DR_MODE_OFFSET); /* MAG3110_CTRL_REG1 bit 5-7: data rate mode */ ret = mag3110_write_reg(client, MAG3110_CTRL_REG1, reg); @@ -340,10 +348,10 @@ static ssize_t mag3110_dr_mode_store(struct device *dev, } static DEVICE_ATTR(dr_mode, S_IWUSR | S_IRUGO, - mag3110_dr_mode_show, mag3110_dr_mode_store); + mag3110_dr_mode_show, mag3110_dr_mode_store); static ssize_t mag3110_position_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { int val; mutex_lock(&mag3110_lock); @@ -353,8 +361,8 @@ static ssize_t mag3110_position_show(struct device *dev, } static ssize_t mag3110_position_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { int position; position = simple_strtoul(buf, NULL, 10); @@ -365,7 +373,7 @@ static ssize_t mag3110_position_store(struct device *dev, } static DEVICE_ATTR(position, S_IWUSR | S_IRUGO, - mag3110_position_show, mag3110_position_store); + mag3110_position_show, mag3110_position_store); static struct attribute *mag3110_attributes[] = { &dev_attr_enable.attr, @@ -379,7 +387,7 @@ static const struct attribute_group mag3110_attr_group = { }; static int __devinit mag3110_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { struct i2c_adapter *adapter; struct input_dev *idev; @@ -388,9 +396,9 @@ static int __devinit mag3110_probe(struct i2c_client *client, adapter = to_i2c_adapter(client->dev.parent); if (!i2c_check_functionality(adapter, - I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_I2C_BLOCK)) + I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_I2C_BLOCK)) return -EIO; dev_info(&client->dev, "check mag3110 chip ID\n"); @@ -398,8 +406,8 @@ static int __devinit mag3110_probe(struct i2c_client *client, if (MAG3110_ID != ret) { dev_err(&client->dev, - "read chip ID 0x%x is not equal to 0x%x!\n", ret, - MAG3110_ID); + "read chip ID 0x%x is not equal to 0x%x!\n", + ret, MAG3110_ID); return -EINVAL; } data = kzalloc(sizeof(struct mag3110_data), GFP_KERNEL); @@ -426,6 +434,7 @@ static int __devinit mag3110_probe(struct i2c_client *client, } data->poll_dev->poll = mag3110_dev_poll; data->poll_dev->poll_interval = POLL_INTERVAL; + data->poll_dev->poll_interval_min = POLL_INTERVAL_MIN; data->poll_dev->poll_interval_max = POLL_INTERVAL_MAX; idev = data->poll_dev->input; idev->name = MAG3110_DRV_NAME; @@ -450,10 +459,10 @@ static int __devinit mag3110_probe(struct i2c_client *client, /* set irq type to edge rising */ #if MAG3110_IRQ_USED ret = request_irq(client->irq, mag3110_irq_handler, - IRQF_TRIGGER_RISING, client->dev.driver->name, idev); + IRQF_TRIGGER_RISING, client->dev.driver->name, idev); if (ret < 0) { dev_err(&client->dev, "failed to register irq %d!\n", - client->irq); + client->irq); goto error_rm_dev_sysfs; } #endif @@ -488,7 +497,7 @@ static int __devexit mag3110_remove(struct i2c_client *client) data->ctl_reg1 = mag3110_read_reg(client, MAG3110_CTRL_REG1); ret = mag3110_write_reg(client, MAG3110_CTRL_REG1, - data->ctl_reg1 & ~MAG3110_AC_MASK); + data->ctl_reg1 & ~MAG3110_AC_MASK); free_irq(client->irq, data); input_unregister_polled_device(data->poll_dev); @@ -509,7 +518,7 @@ static int mag3110_suspend(struct i2c_client *client, pm_message_t mesg) if (data->active == MAG_ACTIVED) { data->ctl_reg1 = mag3110_read_reg(client, MAG3110_CTRL_REG1); ret = mag3110_write_reg(client, MAG3110_CTRL_REG1, - data->ctl_reg1 & ~MAG3110_AC_MASK); + data->ctl_reg1 & ~MAG3110_AC_MASK); } return ret; } @@ -521,12 +530,12 @@ static int mag3110_resume(struct i2c_client *client) struct mag3110_data *data = i2c_get_clientdata(client); if (data->active == MAG_ACTIVED) { ret = mag3110_write_reg(client, MAG3110_CTRL_REG1, - data->ctl_reg1); + data->ctl_reg1); if (data->ctl_reg1 & MAG3110_AC_MASK) { - /* Read out MSB data to clear interrupt flag automatically */ + /* Read out MSB data to clear interrupt automatically*/ mag3110_read_block_data(client, MAG3110_OUT_X_MSB, - MAG3110_XYZ_DATA_LEN, tmp_data); + MAG3110_XYZ_DATA_LEN, tmp_data); } } return ret; @@ -545,7 +554,7 @@ static const struct i2c_device_id mag3110_id[] = { MODULE_DEVICE_TABLE(i2c, mag3110_id); static struct i2c_driver mag3110_driver = { .driver = {.name = MAG3110_DRV_NAME, - .owner = THIS_MODULE,}, + .owner = THIS_MODULE,}, .suspend = mag3110_suspend, .resume = mag3110_resume, .probe = mag3110_probe, diff --git a/drivers/hwmon/mxc_mma8451.c b/drivers/hwmon/mxc_mma8451.c index 110ff3485e3f..d144cbcbacdb 100644 --- a/drivers/hwmon/mxc_mma8451.c +++ b/drivers/hwmon/mxc_mma8451.c @@ -2,7 +2,7 @@ * mma8451.c - Linux kernel modules for 3-Axis Orientation/Motion * Detection Sensor * - * Copyright (C) 2010-2012 Freescale Semiconductor, Inc. All Rights Reserved. + * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,20 +33,30 @@ #include <linux/hwmon.h> #include <linux/input-polldev.h> +#define MMA8451_DRV_NAME "mma8451" #define MMA8451_I2C_ADDR 0x1C #define MMA8451_ID 0x1A #define MMA8452_ID 0x2A #define MMA8453_ID 0x3A -#define POLL_INTERVAL_MIN 1 -#define POLL_INTERVAL_MAX 500 -#define POLL_INTERVAL 100 /* msecs */ -#define INPUT_FUZZ 32 -#define INPUT_FLAT 32 +#define POLL_INTERVAL_MIN 20 +#define POLL_INTERVAL_MAX 1000 +#define POLL_INTERVAL 500 +#define INPUT_FUZZ 128 +#define INPUT_FLAT 128 #define MODE_CHANGE_DELAY_MS 100 #define MMA8451_STATUS_ZYXDR 0x08 -#define MMA8451_BUF_SIZE 7 +#define MMA8451_BUF_SIZE 6 + +#define DR_1_25MS 0 +#define DR_2_5MS 1 +#define DR_5_0MS 2 +#define DR_10_0MS 3 +#define DR_20_0MS 4 +#define DR_80_0MS 5 +#define DR_160_0MS 6 +#define DR_640_0MS 7 /* register enum for mma8451 registers */ enum { @@ -106,8 +116,8 @@ enum { }; /* The sensitivity is represented in counts/g. In 2g mode the -sensitivity is 1024 counts/g. In 4g mode the sensitivity is 512 -counts/g and in 8g mode the sensitivity is 256 counts/g. + sensitivity is 1024 counts/g. In 4g mode the sensitivity is 512 + counts/g and in 8g mode the sensitivity is 256 counts/g. */ enum { MODE_2G = 0, @@ -135,15 +145,15 @@ static struct i2c_client *mma8451_i2c_client; static int senstive_mode = MODE_2G; static int ACCHAL[8][3][3] = { - { {0, -1, 0}, {1, 0, 0}, {0, 0, 1} }, - { {-1, 0, 0}, {0, -1, 0}, {0, 0, 1} }, - { {0, 1, 0}, {-1, 0, 0}, {0, 0, 1} }, - { {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }, - - { {0, -1, 0}, {-1, 0, 0}, {0, 0, -1} }, - { {-1, 0, 0}, {0, 1, 0}, {0, 0, -1} }, - { {0, 1, 0}, {1, 0, 0}, {0, 0, -1} }, - { {1, 0, 0}, {0, -1, 0}, {0, 0, -1} }, + {{ 0, -1, 0}, { 1, 0, 0}, {0, 0, 1} }, + {{-1, 0, 0}, { 0, -1, 0}, {0, 0, 1} }, + {{ 0, 1, 0}, {-1, 0, 0}, {0, 0, 1} }, + {{ 1, 0, 0}, { 0, 1, 0}, {0, 0, 1} }, + + {{ 0, -1, 0}, {-1, 0, 0}, {0, 0, -1} }, + {{-1, 0, 0}, { 0, 1, 0}, {0, 0, -1} }, + {{ 0, 1, 0}, { 1, 0, 0}, {0, 0, -1} }, + {{ 1, 0, 0}, { 0, -1, 0}, {0, 0, -1} }, }; static DEFINE_MUTEX(mma8451_lock); @@ -154,10 +164,12 @@ static int mma8451_adjust_position(short *x, short *y, short *z) int position = mma_status.position; if (position < 0 || position > 7) position = 0; + rawdata[0] = *x; rawdata[1] = *y; rawdata[2] = *z; - for (i = 0; i < 3; i++) { + + for (i = 0; i < 3 ; i++) { data[i] = 0; for (j = 0; j < 3; j++) data[i] += rawdata[j] * ACCHAL[position][i][j]; @@ -172,17 +184,23 @@ static int mma8451_change_mode(struct i2c_client *client, int mode) { int result; - mma_status.ctl_reg1 = 0; - result = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, 0); + /* Put sensor into Standby Mode by clearing the Active bit */ + mma_status.ctl_reg1 = 0x00; + result = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, + mma_status.ctl_reg1); if (result < 0) goto out; + /* Write the 2g dynamic range value */ mma_status.mode = mode; result = i2c_smbus_write_byte_data(client, MMA8451_XYZ_DATA_CFG, - mma_status.mode); + mma_status.mode); if (result < 0) goto out; + + /* Set the Active bit and Data rate in CTRL Reg 1 */ mma_status.active = MMA_STANDBY; + mdelay(MODE_CHANGE_DELAY_MS); return 0; @@ -196,13 +214,15 @@ static int mma8451_read_data(short *x, short *y, short *z) u8 tmp_data[MMA8451_BUF_SIZE]; int ret; + /* Read 14-bit XYZ results using 6 byte */ ret = i2c_smbus_read_i2c_block_data(mma8451_i2c_client, - MMA8451_OUT_X_MSB, 7, tmp_data); + MMA8451_OUT_X_MSB, MMA8451_BUF_SIZE, tmp_data); if (ret < MMA8451_BUF_SIZE) { dev_err(&mma8451_i2c_client->dev, "i2c block read failed\n"); return -EIO; } + /* Concatenate the MSB and LSB */ *x = ((tmp_data[0] << 8) & 0xff00) | tmp_data[1]; *y = ((tmp_data[2] << 8) & 0xff00) | tmp_data[3]; *z = ((tmp_data[4] << 8) & 0xff00) | tmp_data[5]; @@ -213,23 +233,24 @@ static void report_abs(void) { short x, y, z; int result; - int retry = 3; mutex_lock(&mma8451_lock); if (mma_status.active == MMA_STANDBY) goto out; - /* wait for the data ready */ - do { - result = i2c_smbus_read_byte_data(mma8451_i2c_client, - MMA8451_STATUS); - retry--; - msleep(1); - } while (!(result & MMA8451_STATUS_ZYXDR) && retry > 0); - if (retry == 0) + /* Read Status register */ + result = i2c_smbus_read_byte_data(mma8451_i2c_client, MMA8451_STATUS); + + /* Check ZYXDR status bit for data available */ + if (!(result & MMA8451_STATUS_ZYXDR)) { + /* Data not ready */ goto out; + } + + /* Read XYZ data */ if (mma8451_read_data(&x, &y, &z) != 0) goto out; mma8451_adjust_position(&x, &y, &z); + /* Report XYZ data */ input_report_abs(mma8451_idev->input, ABS_X, x); input_report_abs(mma8451_idev->input, ABS_Y, y); input_report_abs(mma8451_idev->input, ABS_Z, z); @@ -244,7 +265,7 @@ static void mma8451_dev_poll(struct input_polled_dev *dev) } static ssize_t mma8451_enable_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct i2c_client *client; u8 val; @@ -262,8 +283,8 @@ static ssize_t mma8451_enable_show(struct device *dev, } static ssize_t mma8451_enable_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { struct i2c_client *client; int ret; @@ -273,42 +294,45 @@ static ssize_t mma8451_enable_store(struct device *dev, mutex_lock(&mma8451_lock); client = mma8451_i2c_client; enable = (enable > 0) ? 1 : 0; - if (enable && mma_status.active == MMA_STANDBY) { + + if (enable && mma_status.active == MMA_STANDBY) { val = i2c_smbus_read_byte_data(client, MMA8451_CTRL_REG1); - ret = - i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, - val | 0x01); + /* Set the Active bit and Data rate in CTRL Reg 1 */ + val |= (DR_20_0MS<<3); + val |= 1; + ret = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, + val); if (!ret) { mma_status.active = MMA_ACTIVED; + printk(KERN_DEBUG "mma enable setting active\n"); } - } else if (enable == 0 && mma_status.active == MMA_ACTIVED) { + } else if (enable == 0 && mma_status.active == MMA_ACTIVED) { val = i2c_smbus_read_byte_data(client, MMA8451_CTRL_REG1); - ret = - i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, - val & 0xFE); + ret = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, + val & 0xFE); if (!ret) { mma_status.active = MMA_STANDBY; + printk(KERN_DEBUG "mma enable setting inactive\n"); } } mutex_unlock(&mma8451_lock); return count; } - static ssize_t mma8451_position_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { int position = 0; mutex_lock(&mma8451_lock); - position = mma_status.position; + position = mma_status.position ; mutex_unlock(&mma8451_lock); return sprintf(buf, "%d\n", position); } static ssize_t mma8451_position_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { - int position; + int position; position = simple_strtoul(buf, NULL, 10); mutex_lock(&mma8451_lock); mma_status.position = position; @@ -317,9 +341,9 @@ static ssize_t mma8451_position_store(struct device *dev, } static DEVICE_ATTR(enable, S_IWUSR | S_IRUGO, - mma8451_enable_show, mma8451_enable_store); + mma8451_enable_show, mma8451_enable_store); static DEVICE_ATTR(position, S_IWUSR | S_IRUGO, - mma8451_position_show, mma8451_position_store); + mma8451_position_show, mma8451_position_store); static struct attribute *mma8451_attributes[] = { &dev_attr_enable.attr, @@ -332,7 +356,7 @@ static const struct attribute_group mma8451_attr_group = { }; static int __devinit mma8451_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { int result, client_id; struct input_dev *idev; @@ -341,18 +365,18 @@ static int __devinit mma8451_probe(struct i2c_client *client, mma8451_i2c_client = client; adapter = to_i2c_adapter(client->dev.parent); result = i2c_check_functionality(adapter, - I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA); + I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA); if (!result) goto err_out; client_id = i2c_smbus_read_byte_data(client, MMA8451_WHO_AM_I); - if (client_id != MMA8451_ID && client_id != MMA8452_ID - && client_id != MMA8453_ID) { + if (client_id != MMA8451_ID && client_id != MMA8452_ID && + client_id != MMA8453_ID) { dev_err(&client->dev, - "read chip ID 0x%x is not equal to 0x%x or 0x%x!\n", - result, MMA8451_ID, MMA8452_ID); + "read chip ID 0x%x is not equal to 0x%x \ + or 0x%x!\n", result, MMA8451_ID, MMA8452_ID); result = -EINVAL; goto err_out; } @@ -361,14 +385,15 @@ static int __devinit mma8451_probe(struct i2c_client *client, result = mma8451_change_mode(client, senstive_mode); if (result) { dev_err(&client->dev, - "error when init mma8451 chip:(%d)\n", result); + "error when init mma8451 chip:(%d)\n", result); goto err_out; } hwmon_dev = hwmon_device_register(&client->dev); if (!hwmon_dev) { result = -ENOMEM; - dev_err(&client->dev, "error when register hwmon device\n"); + dev_err(&client->dev, + "error when register hwmon device\n"); goto err_out; } @@ -417,9 +442,9 @@ static int mma8451_stop_chip(struct i2c_client *client) int ret = 0; if (mma_status.active == MMA_ACTIVED) { mma_status.ctl_reg1 = i2c_smbus_read_byte_data(client, - MMA8451_CTRL_REG1); + MMA8451_CTRL_REG1); ret = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, - mma_status.ctl_reg1 & 0xFE); + mma_status.ctl_reg1 & 0xFE); } return ret; } @@ -447,25 +472,24 @@ static int mma8451_resume(struct device *dev) struct i2c_client *client = to_i2c_client(dev); if (mma_status.active == MMA_ACTIVED) ret = i2c_smbus_write_byte_data(client, MMA8451_CTRL_REG1, - mma_status.ctl_reg1); + mma_status.ctl_reg1); return ret; } #endif static const struct i2c_device_id mma8451_id[] = { - {"mma8451", 0}, + {MMA8451_DRV_NAME, 0}, }; - MODULE_DEVICE_TABLE(i2c, mma8451_id); static SIMPLE_DEV_PM_OPS(mma8451_pm_ops, mma8451_suspend, mma8451_resume); static struct i2c_driver mma8451_driver = { .driver = { - .name = "mma8451", - .owner = THIS_MODULE, - .pm = &mma8451_pm_ops, - }, + .name = MMA8451_DRV_NAME, + .owner = THIS_MODULE, + .pm = &mma8451_pm_ops, + }, .probe = mma8451_probe, .remove = __devexit_p(mma8451_remove), .id_table = mma8451_id, |