* Error using at91-i2c driver in kernel 4.4.x
@ 2017-05-24 18:18 Bryan Evenson
2017-05-24 18:35 ` Bryan Evenson
0 siblings, 1 reply; 4+ messages in thread
From: Bryan Evenson @ 2017-05-24 18:18 UTC (permalink / raw)
To: linux-i2c@vger.kernel.org; +Cc: Wolfram Sang, Ludovic Desroches
I have been using kernel version 3.10.x for a couple years and I am in the process of upgrading to kernel version 4.4. I am using an Atmel AT91SAM9G25 and I am using Atmel's stable fork of the kernel at github.com/linux4sam/linux-at91. I last pulled the linux-4.4-at91 branch about two weeks ago. Today I noticed that I can no longer talk to an I2C EEPROM that I could with kernel version 3.10. I verified the EEPROM still worked with kernel version 3.10 on my hardware, updated my kernel, and now I can't talk to the EEPROM.
First, for the ARM device tree the i2c section looks like this for my build:
i2c0: i2c@f8010000 {
status = "okay";
wm8731: wm8731@1a {
compatible = "wm8731";
reg = <0x1a>;
};
ov2640: camera@0x30 {
compatible = "ovti,ov2640";
reg = <0x30>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_pck0_as_isi_mck &pinctrl_sensor_power &pinctrl_sensor_reset>;
resetb-gpios = <&pioA 7 GPIO_ACTIVE_LOW>;
pwdn-gpios = <&pioA 13 GPIO_ACTIVE_HIGH>;
clocks = <&pck0>;
clock-names = "xvclk";
assigned-clocks = <&pck0>;
assigned-clock-rates = <25000000>;
status = "disabled";
port {
ov2640_0: endpoint {
remote-endpoint = <&isi_0>;
bus-width = <8>;
};
};
};
24c02@50 {
compatible = "atmel,24c02";
reg = <0x50>;
pagesize = <0x08>;
status = "okay";
};
};
I see the following messages in dmesg:
[ 0.234375] at91_i2c f8010000.i2c: using dma0chan0 (tx) and dma0chan1 (rx) for DMA transfers
[ 0.234375] at91_i2c f8010000.i2c: AT91 i2c bus driver (hw version: 0x402).
[ 0.742187] at24 0-0050: 256 byte 24c02 EEPROM, writable, 8 bytes/write
[ 1.343750] i2c /dev entries driver
To me it appears the i2c driver and the EEPROM driver have been loaded and populated. I see that /dev/i2c-0 and /sys/class/i2c-dev/i2c-0 are populated on my system. I then try to read all 256 bytes from the EEPROM as follows from my C program:
int file;
char filename[] = "/dev/i2c-0";
int addr = 0x50;
char buf[256];
ssize_t readBytes;
/* Open the I2C dev interface file */
file = open(filename, O_RDWR);
if (file < 0)
{
printf("Can't open device\n");
exit(EXIT_FAILURE);
}
/* Set the I2C slave address */
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
printf("Can't set slave address - %m\n");
}
/* Attempt to read out the entire EEPROM */
readBytes = read(file, buf, sizeof(buf));
if(readBytes != (ssize_t)sizeof(buf))
{
printf("Only read %d bytes\n - %m", readBytes);
}
else
{
/* Do something with the data... */
}
When I run the above code with the 4.4 kernel running, I get the following output:
Can't set slave address - Device or resource busy
Only read -1 bytes - Remote I/O error
Any thoughts as to what I should be checking to figure out why i2c isn't working for me anymore?
Thanks,
Bryan
^ permalink raw reply [flat|nested] 4+ messages in thread* RE: Error using at91-i2c driver in kernel 4.4.x
2017-05-24 18:18 Error using at91-i2c driver in kernel 4.4.x Bryan Evenson
@ 2017-05-24 18:35 ` Bryan Evenson
2017-05-24 23:07 ` Wolfram Sang
0 siblings, 1 reply; 4+ messages in thread
From: Bryan Evenson @ 2017-05-24 18:35 UTC (permalink / raw)
To: Bryan Evenson, linux-i2c@vger.kernel.org; +Cc: Wolfram Sang, Ludovic Desroches
All,
> -----Original Message-----
> From: linux-i2c-owner@vger.kernel.org [mailto:linux-i2c-
> owner@vger.kernel.org] On Behalf Of Bryan Evenson
> Sent: Wednesday, May 24, 2017 2:18 PM
> To: linux-i2c@vger.kernel.org
> Cc: Wolfram Sang <wsa@the-dreams.de>; Ludovic Desroches
> <ludovic.desroches@atmel.com>
> Subject: Error using at91-i2c driver in kernel 4.4.x
>
>
> I have been using kernel version 3.10.x for a couple years and I am in the
> process of upgrading to kernel version 4.4. I am using an Atmel
> AT91SAM9G25 and I am using Atmel's stable fork of the kernel at
> github.com/linux4sam/linux-at91. I last pulled the linux-4.4-at91 branch
> about two weeks ago. Today I noticed that I can no longer talk to an I2C
> EEPROM that I could with kernel version 3.10. I verified the EEPROM still
> worked with kernel version 3.10 on my hardware, updated my kernel, and
> now I can't talk to the EEPROM.
>
> First, for the ARM device tree the i2c section looks like this for my build:
>
> i2c0: i2c@f8010000 {
> status = "okay";
>
> wm8731: wm8731@1a {
> compatible = "wm8731";
> reg = <0x1a>;
> };
>
> ov2640: camera@0x30 {
> compatible = "ovti,ov2640";
> reg = <0x30>;
> pinctrl-names = "default";
> pinctrl-0 = <&pinctrl_pck0_as_isi_mck
> &pinctrl_sensor_power &pinctrl_sensor_reset>;
> resetb-gpios = <&pioA 7 GPIO_ACTIVE_LOW>;
> pwdn-gpios = <&pioA 13 GPIO_ACTIVE_HIGH>;
> clocks = <&pck0>;
> clock-names = "xvclk";
> assigned-clocks = <&pck0>;
> assigned-clock-rates = <25000000>;
> status = "disabled";
>
> port {
> ov2640_0: endpoint {
> remote-endpoint = <&isi_0>;
> bus-width = <8>;
> };
> };
> };
> 24c02@50 {
> compatible = "atmel,24c02";
> reg = <0x50>;
> pagesize = <0x08>;
> status = "okay";
> };
> };
>
> I see the following messages in dmesg:
>
> [ 0.234375] at91_i2c f8010000.i2c: using dma0chan0 (tx) and dma0chan1 (rx)
> for DMA transfers
> [ 0.234375] at91_i2c f8010000.i2c: AT91 i2c bus driver (hw version: 0x402).
> [ 0.742187] at24 0-0050: 256 byte 24c02 EEPROM, writable, 8 bytes/write
> [ 1.343750] i2c /dev entries driver
>
> To me it appears the i2c driver and the EEPROM driver have been loaded and
> populated. I see that /dev/i2c-0 and /sys/class/i2c-dev/i2c-0 are populated
> on my system. I then try to read all 256 bytes from the EEPROM as follows
> from my C program:
>
> int file;
> char filename[] = "/dev/i2c-0";
> int addr = 0x50;
> char buf[256];
> ssize_t readBytes;
>
> /* Open the I2C dev interface file */
> file = open(filename, O_RDWR);
> if (file < 0)
> {
> printf("Can't open device\n");
> exit(EXIT_FAILURE);
> }
>
> /* Set the I2C slave address */
> if (ioctl(file, I2C_SLAVE, addr) < 0)
> {
> printf("Can't set slave address - %m\n");
> }
>
> /* Attempt to read out the entire EEPROM */
> readBytes = read(file, buf, sizeof(buf));
> if(readBytes != (ssize_t)sizeof(buf))
> {
> printf("Only read %d bytes\n - %m", readBytes);
> }
> else
> {
> /* Do something with the data... */
> }
>
> When I run the above code with the 4.4 kernel running, I get the following
> output:
>
> Can't set slave address - Device or resource busy
> Only read -1 bytes - Remote I/O error
>
> Any thoughts as to what I should be checking to figure out why i2c isn't
> working for me anymore?
As usual, five minutes after I ask a question I get further. I tried changing the ioctl to I2C_SLAVE_FORCE, and now I can talk to my EEPROM. I'm happy it's now working, but I'm concerned about why I now need to force the slave address. Is this because I now need to set things up differently, or is it a problem with the driver?
Thanks,
Bryan
>
> Thanks,
> Bryan
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body
> of a message to majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Error using at91-i2c driver in kernel 4.4.x
2017-05-24 18:35 ` Bryan Evenson
@ 2017-05-24 23:07 ` Wolfram Sang
2017-05-25 14:23 ` Bryan Evenson
0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2017-05-24 23:07 UTC (permalink / raw)
To: Bryan Evenson; +Cc: linux-i2c@vger.kernel.org, Ludovic Desroches
[-- Attachment #1: Type: text/plain, Size: 756 bytes --]
> As usual, five minutes after I ask a question I get further. I tried
> changing the ioctl to I2C_SLAVE_FORCE, and now I can talk to my
> EEPROM. I'm happy it's now working, but I'm concerned about why I now
> need to force the slave address. Is this because I now need to set
> things up differently, or is it a problem with the driver?
From userspace, you cannot access an I2C client which has a kernel
driver bound to it unless you use I2C_SLAVE_FORCE. And you really should
not do that because you could confuse the kernel driver.
Your old kernel probably did not bind a driver to the EEPROM, so you
could access it from userspace.
Since your DT now describes the EEPROM, why don't you simply access the
'eeprom' file in sysfs?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Error using at91-i2c driver in kernel 4.4.x
2017-05-24 23:07 ` Wolfram Sang
@ 2017-05-25 14:23 ` Bryan Evenson
0 siblings, 0 replies; 4+ messages in thread
From: Bryan Evenson @ 2017-05-25 14:23 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c@vger.kernel.org, Ludovic Desroches
> -----Original Message-----
> From: Wolfram Sang [mailto:wsa@the-dreams.de]
> Sent: Wednesday, May 24, 2017 7:07 PM
> To: Bryan Evenson <bevenson@melinkcorp.com>
> Cc: linux-i2c@vger.kernel.org; Ludovic Desroches
> <ludovic.desroches@atmel.com>
> Subject: Re: Error using at91-i2c driver in kernel 4.4.x
>
> > As usual, five minutes after I ask a question I get further. I tried
> > changing the ioctl to I2C_SLAVE_FORCE, and now I can talk to my
> > EEPROM. I'm happy it's now working, but I'm concerned about why I now
> > need to force the slave address. Is this because I now need to set
> > things up differently, or is it a problem with the driver?
>
> From userspace, you cannot access an I2C client which has a kernel
> driver bound to it unless you use I2C_SLAVE_FORCE. And you really should
> not do that because you could confuse the kernel driver.
>
> Your old kernel probably did not bind a driver to the EEPROM, so you
> could access it from userspace.
>
> Since your DT now describes the EEPROM, why don't you simply access the
> 'eeprom' file in sysfs?
I didn't realize that option now existed for me. I verified that with my older kernel the 'eeprom' file doesn't exist in sysfs, but it does with the newer kernel. I'll leave the old method in place as backup but will default to reading from the eeprom file.
Thanks,
Bryan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-25 14:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24 18:18 Error using at91-i2c driver in kernel 4.4.x Bryan Evenson
2017-05-24 18:35 ` Bryan Evenson
2017-05-24 23:07 ` Wolfram Sang
2017-05-25 14:23 ` Bryan Evenson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox