All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] I2C reading problem
@ 2009-11-09  3:48 jack
  2009-11-09  8:40 ` Jean Delvare
  0 siblings, 1 reply; 2+ messages in thread
From: jack @ 2009-11-09  3:48 UTC (permalink / raw)
  To: lm-sensors


[-- Attachment #1.1: Type: text/plain, Size: 3658 bytes --]

Dear all,

           Why I cannot read data form i2c? while in interrupt handler
function. The "printk" output is always 0. Could anybody tell me how to fix
me code for correctly reading the data send by i2c.

#include <linux/kernel.h>

#include <linux/module.h>

#include <linux/init.h>

#include <linux/i2c.h>

#include <linux/input.h>

#include <linux/delay.h>

#include <linux/clk.h>

#include <linux/gpio.h>

#include <asm/io.h>

#include "../../../arch/arm/mach-mx51/crm_regs.h"

#include "../../../arch/arm/mach-mx51/iomux.h"

 

#define ABC_I2C_ADDR         0x03

#define I2C_DEV_NAME         "i2c-0"

#define ABC_DD_NAME         "abc_dd"

 

struct abc_dd_priv {

       struct i2c_client *client;

       struct input_dev *input;

       int irq;

};

 

static irqreturn_t abc_event_handler(int irq, void *dev_id){

           int i;

           u_int8_t dd_data[10]={0};

           struct abc_dd_priv *priv = dev_id;    

           memset(dd_data, 0, sizeof(dd_data));

           i2c_master_recv(priv->client,dd_data,sizeof(dd_data));

           for(i=0;i<10;i++){

                     printk(KERN_INFO "dd_data[%d]=%d\n",i,dd_data[i]);

           }

           return IRQ_HANDLED;

}

/* -------------------------------------------------------------------------
*/

 

static int abc_i2c_probe(struct i2c_client *client, const struct
i2c_device_id *id){

 

           struct input_dev *abc_inputdev;

           struct abc_dd_priv *priv;

  unsigned long tmp;

           int retval;

  int res;

 

           priv = kzalloc(sizeof(struct abc_dd_priv), GFP_KERNEL);

        if (!priv) {

                dev_err(&client->dev, "failed to allocate driver data\n");

                return -ENOMEM;

        }

 

           i2c_set_clientdata(client, priv);

           priv->client = client;

           priv->irq = client->irq;

 

           if(priv->irq){

                     tmp=readl(MXC_CCM_CWDR);

                     writel(tmp|0x00000008, MXC_CCM_CWDR);

                     res=mxc_request_iomux(MX51_PIN_GPIO1_5,
IOMUX_CONFIG_ALT0);

                     gpio_config(0,5,false,GPIO_INT_HIGH_LEV);

 
gpio_request_irq(0,5,GPIO_LOW_PRIO,abc_event_handler,0,ABC_DD_NAME,priv);

           }         

 

           abc_inputdev = input_allocate_device();

           if (!abc_inputdev) {

                     printk(KERN_ERR "not enough memory for input
device\n");

                     return -ENOMEM;

           }

           priv->input = abc_inputdev;

           input_set_drvdata(abc_inputdev,priv);

  abc_inputdev->name = ABC_DD_NAME;

 

           retval = input_register_device(priv->input);

  if (retval < 0) {

                     input_free_device(abc_inputdev);

                     return retval;

           }

           return 0;

}

 

static const struct i2c_device_id abc_dd_id[] = {

        { "abc_dd", 0 },

        { }

};

 

MODULE_DEVICE_TABLE(i2c, abc_dd_id);

 

static struct i2c_driver abc_driver = {

        .driver = {

                   .name    = ABC_DD_NAME,

                                    .owner           = THIS_MODULE,

                   },

        .probe = abc_i2c_probe,

                 .id_table = abc_dd_id, 

};

 

/*

 * module load/unload record keeping

 */

 

static int __init abc_dd_init(void)

{

           printk(KERN_INFO "Diver Initiating...\n");

           return i2c_add_driver(&abc_driver);

}

 

static void __exit abc_dd_exit(void)

{

           i2c_del_driver(&abc_driver);

}

 

MODULE_AUTHOR("ABC International Inc.");

MODULE_DESCRIPTION("DD driver");

MODULE_LICENSE("GPL");

 

module_init(abc_dd_init);

module_exit(abc_dd_exit);


[-- Attachment #1.2: Type: text/html, Size: 27281 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [lm-sensors] I2C reading problem
  2009-11-09  3:48 [lm-sensors] I2C reading problem jack
@ 2009-11-09  8:40 ` Jean Delvare
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2009-11-09  8:40 UTC (permalink / raw)
  To: lm-sensors

On Mon, 9 Nov 2009 11:48:29 +0800, jack wrote:
>            Why I cannot read data form i2c? while in interrupt handler
> function. The "printk" output is always 0. Could anybody tell me how to fix
> me code for correctly reading the data send by i2c.

Wrong mailing list, try linux-i2c instead.

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-09  8:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-09  3:48 [lm-sensors] I2C reading problem jack
2009-11-09  8:40 ` Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.