mxcmmc: decrease minimum frequency to make MMC cards work
[safe/jmp/linux-2.6] / drivers / firewire / fw-card.c
index 08a7e18..8b8c8c2 100644 (file)
@@ -181,6 +181,25 @@ void fw_core_remove_descriptor(struct fw_descriptor *desc)
        mutex_unlock(&card_mutex);
 }
 
+static int set_broadcast_channel(struct device *dev, void *data)
+{
+       fw_device_set_broadcast_channel(fw_device(dev), (long)data);
+       return 0;
+}
+
+static void allocate_broadcast_channel(struct fw_card *card, int generation)
+{
+       int channel, bandwidth = 0;
+
+       fw_iso_resource_manage(card, generation, 1ULL << 31,
+                              &channel, &bandwidth, true);
+       if (channel == 31) {
+               card->broadcast_channel_allocated = true;
+               device_for_each_child(card->device, (void *)(long)generation,
+                                     set_broadcast_channel);
+       }
+}
+
 static const char gap_count_table[] = {
        63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
 };
@@ -199,32 +218,34 @@ static void fw_card_bm_work(struct work_struct *work)
 {
        struct fw_card *card = container_of(work, struct fw_card, work.work);
        struct fw_device *root_device;
-       struct fw_node *root_node, *local_node;
+       struct fw_node *root_node;
        unsigned long flags;
-       int root_id, new_root_id, irm_id, gap_count, generation, grace, rcode;
+       int root_id, new_root_id, irm_id, local_id;
+       int gap_count, generation, grace, rcode;
        bool do_reset = false;
        bool root_device_is_running;
        bool root_device_is_cmc;
        __be32 lock_data[2];
 
        spin_lock_irqsave(&card->lock, flags);
-       local_node = card->local_node;
-       root_node  = card->root_node;
 
-       if (local_node == NULL) {
+       if (card->local_node == NULL) {
                spin_unlock_irqrestore(&card->lock, flags);
                goto out_put_card;
        }
-       fw_node_get(local_node);
-       fw_node_get(root_node);
 
        generation = card->generation;
+       root_node = card->root_node;
+       fw_node_get(root_node);
        root_device = root_node->data;
        root_device_is_running = root_device &&
                        atomic_read(&root_device->state) == FW_DEVICE_RUNNING;
        root_device_is_cmc = root_device && root_device->cmc;
-       root_id = root_node->node_id;
-       grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 10));
+       root_id  = root_node->node_id;
+       irm_id   = card->irm_node->node_id;
+       local_id = card->local_node->node_id;
+
+       grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 8));
 
        if (is_next_generation(generation, card->bm_generation) ||
            (card->bm_generation != generation && grace)) {
@@ -240,16 +261,15 @@ static void fw_card_bm_work(struct work_struct *work)
                 * next generation.
                 */
 
-               irm_id = card->irm_node->node_id;
                if (!card->irm_node->link_on) {
-                       new_root_id = local_node->node_id;
+                       new_root_id = local_id;
                        fw_notify("IRM has link off, making local node (%02x) root.\n",
                                  new_root_id);
                        goto pick_me;
                }
 
                lock_data[0] = cpu_to_be32(0x3f);
-               lock_data[1] = cpu_to_be32(local_node->node_id);
+               lock_data[1] = cpu_to_be32(local_id);
 
                spin_unlock_irqrestore(&card->lock, flags);
 
@@ -263,9 +283,14 @@ static void fw_card_bm_work(struct work_struct *work)
                        goto out;
 
                if (rcode == RCODE_COMPLETE &&
-                   lock_data[0] != cpu_to_be32(0x3f))
-                       /* Somebody else is BM, let them do the work. */
+                   lock_data[0] != cpu_to_be32(0x3f)) {
+
+                       /* Somebody else is BM.  Only act as IRM. */
+                       if (local_id == irm_id)
+                               allocate_broadcast_channel(card, generation);
+
                        goto out;
+               }
 
                spin_lock_irqsave(&card->lock, flags);
 
@@ -276,19 +301,18 @@ static void fw_card_bm_work(struct work_struct *work)
                         * do a bus reset and pick the local node as
                         * root, and thus, IRM.
                         */
-                       new_root_id = local_node->node_id;
+                       new_root_id = local_id;
                        fw_notify("BM lock failed, making local node (%02x) root.\n",
                                  new_root_id);
                        goto pick_me;
                }
        } else if (card->bm_generation != generation) {
                /*
-                * OK, we weren't BM in the last generation, and it's
-                * less than 100ms since last bus reset. Reschedule
-                * this task 100ms from now.
+                * We weren't BM in the last generation, and the last
+                * bus reset is less than 125ms ago.  Reschedule this job.
                 */
                spin_unlock_irqrestore(&card->lock, flags);
-               fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 10));
+               fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
                goto out;
        }
 
@@ -304,7 +328,7 @@ static void fw_card_bm_work(struct work_struct *work)
                 * Either link_on is false, or we failed to read the
                 * config rom.  In either case, pick another root.
                 */
-               new_root_id = local_node->node_id;
+               new_root_id = local_id;
        } else if (!root_device_is_running) {
                /*
                 * If we haven't probed this device yet, bail out now
@@ -326,7 +350,7 @@ static void fw_card_bm_work(struct work_struct *work)
                 * successfully read the config rom, but it's not
                 * cycle master capable.
                 */
-               new_root_id = local_node->node_id;
+               new_root_id = local_id;
        }
 
  pick_me:
@@ -357,10 +381,14 @@ static void fw_card_bm_work(struct work_struct *work)
                          card->index, new_root_id, gap_count);
                fw_send_phy_config(card, new_root_id, generation, gap_count);
                fw_core_initiate_bus_reset(card, 1);
+               /* Will allocate broadcast channel after the reset. */
+       } else {
+               if (local_id == irm_id)
+                       allocate_broadcast_channel(card, generation);
        }
+
  out:
        fw_node_put(root_node);
-       fw_node_put(local_node);
  out_put_card:
        fw_card_put(card);
 }