spi_bfin5xx: limit reaches -1
[safe/jmp/linux-2.6] / drivers / spi / spi_butterfly.c
index 79a3c59..c218486 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
-#include <linux/platform_device.h>
+#include <linux/device.h>
 #include <linux/parport.h>
 
+#include <linux/sched.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_bitbang.h>
 #include <linux/spi/flash.h>
@@ -40,8 +40,6 @@
  * and use this custom parallel port cable.
  */
 
-#undef HAVE_USI        /* nyet */
-
 
 /* DATA output bits (pins 2..9 == D0..D7) */
 #define        butterfly_nreset (1 << 1)               /* pin 3 */
 #define        spi_sck_bit     (1 << 0)                /* pin 2 */
 #define        spi_mosi_bit    (1 << 7)                /* pin 9 */
 
-#define        usi_sck_bit     (1 << 3)                /* pin 5 */
-#define        usi_mosi_bit    (1 << 4)                /* pin 6 */
-
 #define        vcc_bits        ((1 << 6) | (1 << 5))   /* pins 7, 8 */
 
 /* STATUS input bits */
 #define        spi_miso_bit    PARPORT_STATUS_BUSY     /* pin 11 */
 
-#define        usi_miso_bit    PARPORT_STATUS_PAPEROUT /* pin 12 */
-
 /* CONTROL output bits */
 #define        spi_cs_bit      PARPORT_CONTROL_SELECT  /* pin 17 */
-/* USI uses no chipselect */
 
 
 
@@ -70,15 +62,6 @@ static inline struct butterfly *spidev_to_pp(struct spi_device *spi)
        return spi->controller_data;
 }
 
-static inline int is_usidev(struct spi_device *spi)
-{
-#ifdef HAVE_USI
-       return spi->chip_select != 1;
-#else
-       return 0;
-#endif
-}
-
 
 struct butterfly {
        /* REVISIT ... for now, this must be first */
@@ -97,23 +80,13 @@ struct butterfly {
 
 /*----------------------------------------------------------------------*/
 
-/*
- * these routines may be slower than necessary because they're hiding
- * the fact that there are two different SPI busses on this cable: one
- * to the DataFlash chip (or AVR SPI controller), the other to the
- * AVR USI controller.
- */
-
 static inline void
 setsck(struct spi_device *spi, int is_on)
 {
        struct butterfly        *pp = spidev_to_pp(spi);
        u8                      bit, byte = pp->lastbyte;
 
-       if (is_usidev(spi))
-               bit = usi_sck_bit;
-       else
-               bit = spi_sck_bit;
+       bit = spi_sck_bit;
 
        if (is_on)
                byte |= bit;
@@ -129,10 +102,7 @@ setmosi(struct spi_device *spi, int is_on)
        struct butterfly        *pp = spidev_to_pp(spi);
        u8                      bit, byte = pp->lastbyte;
 
-       if (is_usidev(spi))
-               bit = usi_mosi_bit;
-       else
-               bit = spi_mosi_bit;
+       bit = spi_mosi_bit;
 
        if (is_on)
                byte |= bit;
@@ -148,10 +118,7 @@ static inline int getmiso(struct spi_device *spi)
        int                     value;
        u8                      bit;
 
-       if (is_usidev(spi))
-               bit = usi_miso_bit;
-       else
-               bit = spi_miso_bit;
+       bit = spi_miso_bit;
 
        /* only STATUS_BUSY is NOT negated */
        value = !(parport_read_status(pp->port) & bit);
@@ -163,21 +130,16 @@ static void butterfly_chipselect(struct spi_device *spi, int value)
        struct butterfly        *pp = spidev_to_pp(spi);
 
        /* set default clock polarity */
-       if (value)
+       if (value != BITBANG_CS_INACTIVE)
                setsck(spi, spi->mode & SPI_CPOL);
 
-       /* no chipselect on this USI link config */
-       if (is_usidev(spi))
-               return;
-
-       /* here, value == "activate or not" */
-
-       /* most PARPORT_CONTROL_* bits are negated */
+       /* here, value == "activate or not";
+        * most PARPORT_CONTROL_* bits are negated, so we must
+        * morph it to value == "bit value to write in control register"
+        */
        if (spi_cs_bit == PARPORT_CONTROL_INIT)
                value = !value;
 
-       /* here, value == "bit value to write in control register"  */
-
        parport_frob_control(pp->port, spi_cs_bit, value ? spi_cs_bit : 0);
 }
 
@@ -202,7 +164,9 @@ butterfly_txrx_word_mode0(struct spi_device *spi,
 
 /* override default partitioning with cmdlinepart */
 static struct mtd_partition partitions[] = { {
-       /* JFFS2 wants partitions of 4*N blocks for this device ... */
+       /* JFFS2 wants partitions of 4*N blocks for this device,
+        * so sectors 0 and 1 can't be partitions by themselves.
+        */
 
        /* sector 0 = 8 pages * 264 bytes/page (1 block)
         * sector 1 = 248 pages * 264 bytes/page
@@ -236,22 +200,16 @@ static void butterfly_attach(struct parport *p)
        int                     status;
        struct butterfly        *pp;
        struct spi_master       *master;
-       struct platform_device  *pdev;
+       struct device           *dev = p->physport->dev;
 
-       if (butterfly)
+       if (butterfly || !dev)
                return;
 
        /* REVISIT:  this just _assumes_ a butterfly is there ... no probe,
         * and no way to be selective about what it binds to.
         */
 
-       /* FIXME where should master->cdev.dev come from?
-        * e.g. /sys/bus/pnp0/00:0b, some PCI thing, etc
-        * setting up a platform device like this is an ugly kluge...
-        */
-       pdev = platform_device_register_simple("butterfly", -1, NULL, 0);
-
-       master = spi_alloc_master(&pdev->dev, sizeof *pp);
+       master = spi_alloc_master(dev, sizeof *pp);
        if (!master) {
                status = -ENOMEM;
                goto done;
@@ -297,7 +255,7 @@ static void butterfly_attach(struct parport *p)
        parport_frob_control(pp->port, spi_cs_bit, 0);
 
        /* stabilize power with chip in reset (nRESET), and
-        * both spi_sck_bit and usi_sck_bit clear (CPOL=0)
+        * spi_sck_bit clear (CPOL=0)
         */
        pp->lastbyte |= vcc_bits;
        parport_write_data(pp->port, pp->lastbyte);
@@ -316,9 +274,11 @@ static void butterfly_attach(struct parport *p)
        if (status < 0)
                goto clean2;
 
-       /* Bus 1 lets us talk to at45db041b (firmware disables AVR)
-        * or AVR (firmware resets at45, acts as spi slave)
+       /* Bus 1 lets us talk to at45db041b (firmware disables AVR SPI), AVR
+        * (firmware resets at45, acts as spi slave) or neither (we ignore
+        * both, AVR uses AT45).  Here we expect firmware for the first option.
         */
+
        pp->info[0].max_speed_hz = 15 * 1000 * 1000;
        strcpy(pp->info[0].modalias, "mtd_dataflash");
        pp->info[0].platform_data = &flash;
@@ -327,22 +287,7 @@ static void butterfly_attach(struct parport *p)
        pp->dataflash = spi_new_device(pp->bitbang.master, &pp->info[0]);
        if (pp->dataflash)
                pr_debug("%s: dataflash at %s\n", p->name,
-                               pp->dataflash->dev.bus_id);
-
-#ifdef HAVE_USI
-       /* even more custom AVR firmware */
-       pp->info[1].max_speed_hz = 10 /* ?? */ * 1000 * 1000;
-       strcpy(pp->info[1].modalias, "butterfly");
-       // pp->info[1].platform_data = ... TBD ... ;
-       pp->info[1].chip_select = 2,
-       pp->info[1].controller_data = pp;
-       pp->butterfly = spi_new_device(pp->bitbang.master, &pp->info[1]);
-       if (pp->butterfly)
-               pr_debug("%s: butterfly at %s\n", p->name,
-                               pp->butterfly->dev.bus_id);
-
-       /* FIXME setup ACK for the IRQ line ...  */
-#endif
+                               dev_name(&pp->dataflash->dev));
 
        // dev_info(_what?_, ...)
        pr_info("%s: AVR Butterfly\n", p->name);
@@ -359,14 +304,12 @@ clean1:
 clean0:
        (void) spi_master_put(pp->bitbang.master);
 done:
-       platform_device_unregister(pdev);
        pr_debug("%s: butterfly probe, fail %d\n", p->name, status);
 }
 
 static void butterfly_detach(struct parport *p)
 {
        struct butterfly        *pp;
-       struct platform_device  *pdev;
        int                     status;
 
        /* FIXME this global is ugly ... but, how to quickly get from
@@ -378,13 +321,7 @@ static void butterfly_detach(struct parport *p)
        pp = butterfly;
        butterfly = NULL;
 
-#ifdef HAVE_USI
-       spi_unregister_device(pp->butterfly);
-       pp->butterfly = NULL;
-#endif
-       spi_unregister_device(pp->dataflash);
-       pp->dataflash = NULL;
-
+       /* stop() unregisters child devices too */
        status = spi_bitbang_stop(&pp->bitbang);
 
        /* turn off VCC */
@@ -394,11 +331,7 @@ static void butterfly_detach(struct parport *p)
        parport_release(pp->pd);
        parport_unregister_device(pp->pd);
 
-       pdev = to_platform_device(pp->bitbang.master->cdev.dev);
-
        (void) spi_master_put(pp->bitbang.master);
-
-       platform_device_unregister(pdev);
 }
 
 static struct parport_driver butterfly_driver = {
@@ -420,4 +353,5 @@ static void __exit butterfly_exit(void)
 }
 module_exit(butterfly_exit);
 
+MODULE_DESCRIPTION("Parport Adapter driver for AVR Butterfly");
 MODULE_LICENSE("GPL");