sysfs: add struct file* to bin_attr callbacks
[safe/jmp/linux-2.6] / drivers / misc / eeprom / at25.c
index 6bc0dac..c627e41 100644 (file)
@@ -126,7 +126,8 @@ at25_ee_read(
 }
 
 static ssize_t
-at25_bin_read(struct kobject *kobj, struct bin_attribute *bin_attr,
+at25_bin_read(struct file *filp, struct kobject *kobj,
+             struct bin_attribute *bin_attr,
              char *buf, loff_t off, size_t count)
 {
        struct device           *dev;
@@ -140,7 +141,8 @@ at25_bin_read(struct kobject *kobj, struct bin_attribute *bin_attr,
 
 
 static ssize_t
-at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
+at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
+             size_t count)
 {
        ssize_t                 status = 0;
        unsigned                written = 0;
@@ -172,6 +174,7 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
                unsigned        segment;
                unsigned        offset = (unsigned) off;
                u8              *cp = bounce + 1;
+               int             sr;
 
                *cp = AT25_WREN;
                status = spi_write(at25->spi, cp, 1);
@@ -213,7 +216,6 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
                timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
                retries = 0;
                do {
-                       int     sr;
 
                        sr = spi_w8r8(at25->spi, AT25_RDSR);
                        if (sr < 0 || (sr & AT25_SR_nRDY)) {
@@ -227,7 +229,7 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
                                break;
                } while (retries++ < 3 || time_before_eq(jiffies, timeout));
 
-               if (time_after(jiffies, timeout)) {
+               if ((sr < 0) || (sr & AT25_SR_nRDY)) {
                        dev_err(&at25->spi->dev,
                                "write %d bytes offset %d, "
                                "timeout after %u msecs\n",
@@ -252,7 +254,8 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
 }
 
 static ssize_t
-at25_bin_write(struct kobject *kobj, struct bin_attribute *bin_attr,
+at25_bin_write(struct file *filp, struct kobject *kobj,
+              struct bin_attribute *bin_attr,
               char *buf, loff_t off, size_t count)
 {
        struct device           *dev;
@@ -276,7 +279,7 @@ static ssize_t at25_mem_read(struct memory_accessor *mem, char *buf,
        return at25_ee_read(at25, buf, offset, count);
 }
 
-static ssize_t at25_mem_write(struct memory_accessor *mem, char *buf,
+static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
                          off_t offset, size_t count)
 {
        struct at25_data *at25 = container_of(mem, struct at25_data, mem);
@@ -346,6 +349,7 @@ static int at25_probe(struct spi_device *spi)
         * that's sensitive for read and/or write, like ethernet addresses,
         * security codes, board-specific manufacturing calibrations, etc.
         */
+       sysfs_bin_attr_init(&at25->bin);
        at25->bin.attr.name = "eeprom";
        at25->bin.attr.mode = S_IRUSR;
        at25->bin.read = at25_bin_read;
@@ -416,4 +420,4 @@ module_exit(at25_exit);
 MODULE_DESCRIPTION("Driver for most SPI EEPROMs");
 MODULE_AUTHOR("David Brownell");
 MODULE_LICENSE("GPL");
-
+MODULE_ALIAS("spi:at25");