Linux I2C development
 help / color / mirror / Atom feed
* RE: I2c message at init time
@ 2009-03-24 10:29 Ayman KHAMOUMA
  0 siblings, 0 replies; 4+ messages in thread
From: Ayman KHAMOUMA @ 2009-03-24 10:29 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA

 
PS:
The i2c_smbus_write is called at the device's probe.

-----Original Message-----
From: khamouma [mailto:ayman.khamouma-qxv4g6HH51o@public.gmane.org] 
Sent: Tuesday, March 24, 2009 11:28 AM
To: 'linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org'
Subject: I2c message at init time

Hi everybody,

I'm coming back here for a new problem...
I can't find out how to send i2c messages at init time (setup.c) I need to
send some commands via i2c in order to make my hdd work I tried to write it
as an i2c driver at init time, but it doesn't seem to work
(smbus_write_byte_data returns -1... But it works in my "normal" modules)

Any idea ?
Here is what I'm doing:

static int __init device_init(void)
{
    unsigned        sysconf;
    int         ret;
    struct stpio_pin *pin;

    stx7100_configure_sata();
    stx7100_configure_pwm(&pwm_private_info);
    stx7100_configure_ssc(&ssc_private_info);
    stx7100_configure_usb();
    stx7100_configure_lirc(&lirc_scd);
    stx7100_configure_pata(3, 1, IRL0_IRQ);



    //vpp_pio = stpio_request_set_pin(2, 7, "flash_VPP", STPIO_OUT, 0);

    phy_reset_pin = stpio_request_set_pin(3, 7, "ste100p_reset",
                          STPIO_OUT, 1);
    stx7100_configure_ethernet(0, 0, 0);

    ret = platform_add_devices(mtv7109_devices,
ARRAY_SIZE(mtv7109_devices));

	//this is the driver I added:
    i2c_add_driver(&i2c_MTV7109PioExp_driver);
    
    
    pin = stpio_request_pin(2,5, "ATAPWR", STPIO_OUT);
    
/* reset ATAPI pin */

    stpio_set_pin(pin, 1);
    udelay(10);
    stpio_set_pin(pin, 0);
    udelay(10);
    stpio_set_pin(pin, 1);
    udelay(10);
    stpio_free_pin(pin);

    //ret = platform_add_devices(mtv7109_devices,
ARRAY_SIZE(mtv7109_devices));

    //i2c_add_driver(&i2c_MTV7109PioExp_driver);
    return ret;
}

device_initcall(device_init);

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: Need help on selecting one (and only one) i2c bus
@ 2009-03-11 11:22 Jean Delvare
       [not found] ` <20090311122257.7c7805f0-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jean Delvare @ 2009-03-11 11:22 UTC (permalink / raw)
  To: Ayman KHAMOUMA; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

Hi Ayman,

On Wed, 11 Mar 2009 11:55:22 +0100, Ayman KHAMOUMA wrote:
> After some researches I guess I have to use the normal_i2c and ignore
> arrays:
> 
> static unsigned short normal_i2c[] = { 0x71, I2C_CLIENT_END};
> static unsigned short ignore[] = { 0x01, 0x71, 0x02, 0x71, I2C_CLIENT_END};
> 
> static struct i2c_client_address_data addr_data = {
>     .normal_i2c = normal_i2c,
>     .ignore     = ignore,
> };
> 
> Int the init function I have to allocate a major to the driver, and than add
> the I2c driver:
> i2c_add_driver(&i2c_my_drv);
> 
> After doing that, i2c_my_drv.attach_adapter is called.
> 
> Which will call (among others) my probe function, in which I call
> i2c_attach_client.
> 
> 
> Am I in the right way ?

No. You're using the old, deprecated way to instantiate devices, and
you are abusing it (the ignore array wasn't meant to be used the way
you do.)

You said you're using kernel 2.6.23.17, it's not brand new, but it's
not too old either. At any rate, it already includes the new-style
device binding. So, instead of using the old binding model and then
fight to get your driver to _not_ attach to improper devices/addresses,
you should use the new model and explicitly instantiate your device, so
that your driver won't even try to bind to the wrong devices.

I have posted an explanation about how to do this recently:
http://marc.info/?l=linux-i2c&m=123659553713018&w=2

You should convert your driver to a new-style one and use either method
1 or method 2, whichever is easier for you. See the following document
for a guide on how to update your code:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/i2c/upgrading-clients;hb=HEAD

It's for kernel 2.6.26 and later but it should mostly apply to 2.6.23
too. The only big difference I can think of is that 2.6.23 doesn't have
struct i2c_device_id, instead the device driver binding is based on the
i2c driver name. I can help you with this if you can't figure it out.

As a side note, the fact that you needed to add buses 1 and 2 to the
ignore list suggests that something is wrong with your I2C bus driver.
It is rather unlikely that all 3 I2C buses on your system have a device
at address 0x71, so your old-style driver shouldn't have instantiated 3
devices. If it did, it strongly suggests that the quick write i2c-core
is using to check for the presence of a device at a given address
improperly reported success in all cases. You really should check your
I2C bus driver and in particular the implementation of 0-byte messages
before going further with the device driver.

-- 
Jean Delvare
http://khali.linux-fr.org/wishlist.html

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

end of thread, other threads:[~2009-03-24 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-24 10:29 I2c message at init time Ayman KHAMOUMA
  -- strict thread matches above, loose matches on Subject: below --
2009-03-11 11:22 Need help on selecting one (and only one) i2c bus Jean Delvare
     [not found] ` <20090311122257.7c7805f0-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-03-24 10:27   ` I2c message at init time Ayman KHAMOUMA
     [not found]     ` <000201c9ac6b$34a95300$2d3f81a4-J7BnVcvkGbbQT0dZR+AlfA@public.gmane.org>
2009-03-24 15:52       ` Jean Delvare
     [not found]         ` <20090324165227.0d97454c-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-03-24 15:58           ` Ayman KHAMOUMA

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox