Merge remote-tracking branches 'spi/topic/doc', 'spi/topic/dw' and 'spi/topic/flash...
[linux-2.6-block.git] / drivers / spi / spi.c
index f565cc8901a662a0efc9a0b593e53aeb22cd1c76..b30f03a99dfdfb6789b7fa0d9bfcc662a6db267c 100644 (file)
@@ -702,6 +702,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
                       enum dma_data_direction dir)
 {
        const bool vmalloced_buf = is_vmalloc_addr(buf);
+       unsigned int max_seg_size = dma_get_max_seg_size(dev);
        int desc_len;
        int sgs;
        struct page *vm_page;
@@ -710,10 +711,10 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
        int i, ret;
 
        if (vmalloced_buf) {
-               desc_len = PAGE_SIZE;
+               desc_len = min_t(int, max_seg_size, PAGE_SIZE);
                sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
        } else {
-               desc_len = master->max_dma_len;
+               desc_len = min_t(int, max_seg_size, master->max_dma_len);
                sgs = DIV_ROUND_UP(len, desc_len);
        }
 
@@ -739,7 +740,6 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
                        sg_set_buf(&sgt->sgl[i], sg_buf, min);
                }
 
-
                buf += min;
                len -= min;
        }
@@ -1594,13 +1594,30 @@ static void of_register_spi_devices(struct spi_master *master) { }
 static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
 {
        struct spi_device *spi = data;
+       struct spi_master *master = spi->master;
 
        if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
                struct acpi_resource_spi_serialbus *sb;
 
                sb = &ares->data.spi_serial_bus;
                if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_SPI) {
-                       spi->chip_select = sb->device_selection;
+                       /*
+                        * ACPI DeviceSelection numbering is handled by the
+                        * host controller driver in Windows and can vary
+                        * from driver to driver. In Linux we always expect
+                        * 0 .. max - 1 so we need to ask the driver to
+                        * translate between the two schemes.
+                        */
+                       if (master->fw_translate_cs) {
+                               int cs = master->fw_translate_cs(master,
+                                               sb->device_selection);
+                               if (cs < 0)
+                                       return cs;
+                               spi->chip_select = cs;
+                       } else {
+                               spi->chip_select = sb->device_selection;
+                       }
+
                        spi->max_speed_hz = sb->connection_speed;
 
                        if (sb->clock_phase == ACPI_SPI_SECOND_PHASE)