Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge remote-tracking branches 'spi/topic/omap-100k', 'spi/topic/omap-uwire', 'spi/topic/pl022', 'spi/topic/pm' and 'spi/topic/pxa2xx' into spi-next

+206 -223
+1 -2
Documentation/spi/spi-summary
··· 342 342 .driver = { 343 343 .name = "CHIP", 344 344 .owner = THIS_MODULE, 345 + .pm = &CHIP_pm_ops, 345 346 }, 346 347 347 348 .probe = CHIP_probe, 348 349 .remove = CHIP_remove, 349 - .suspend = CHIP_suspend, 350 - .resume = CHIP_resume, 351 350 }; 352 351 353 352 The driver core will automatically attempt to bind this driver to any SPI
+77 -24
drivers/spi/spi-omap-100k.c
··· 24 24 #include <linux/device.h> 25 25 #include <linux/delay.h> 26 26 #include <linux/platform_device.h> 27 + #include <linux/pm_runtime.h> 27 28 #include <linux/err.h> 28 29 #include <linux/clk.h> 29 30 #include <linux/io.h> ··· 295 294 return ret; 296 295 } 297 296 298 - static int omap1_spi100k_prepare_hardware(struct spi_master *master) 299 - { 300 - struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 301 - 302 - clk_prepare_enable(spi100k->ick); 303 - clk_prepare_enable(spi100k->fck); 304 - 305 - return 0; 306 - } 307 - 308 297 static int omap1_spi100k_transfer_one_message(struct spi_master *master, 309 298 struct spi_message *m) 310 299 { ··· 363 372 return status; 364 373 } 365 374 366 - static int omap1_spi100k_unprepare_hardware(struct spi_master *master) 367 - { 368 - struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 369 - 370 - clk_disable_unprepare(spi100k->ick); 371 - clk_disable_unprepare(spi100k->fck); 372 - 373 - return 0; 374 - } 375 - 376 375 static int omap1_spi100k_probe(struct platform_device *pdev) 377 376 { 378 377 struct spi_master *master; ··· 383 402 384 403 master->setup = omap1_spi100k_setup; 385 404 master->transfer_one_message = omap1_spi100k_transfer_one_message; 386 - master->prepare_transfer_hardware = omap1_spi100k_prepare_hardware; 387 - master->unprepare_transfer_hardware = omap1_spi100k_unprepare_hardware; 388 - master->cleanup = NULL; 389 405 master->num_chipselect = 2; 390 406 master->mode_bits = MODEBITS; 391 407 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); 392 408 master->min_speed_hz = OMAP1_SPI100K_MAX_FREQ/(1<<16); 393 409 master->max_speed_hz = OMAP1_SPI100K_MAX_FREQ; 410 + master->auto_runtime_pm = true; 394 411 395 412 spi100k = spi_master_get_devdata(master); 396 413 ··· 413 434 goto err; 414 435 } 415 436 437 + status = clk_prepare_enable(spi100k->ick); 438 + if (status != 0) { 439 + dev_err(&pdev->dev, "failed to enable ick: %d\n", status); 440 + goto err; 441 + } 442 + 443 + status = clk_prepare_enable(spi100k->fck); 444 + if (status != 0) { 445 + dev_err(&pdev->dev, "failed to enable fck: %d\n", status); 446 + goto err_ick; 447 + } 448 + 449 + pm_runtime_enable(&pdev->dev); 450 + pm_runtime_set_active(&pdev->dev); 451 + 416 452 status = devm_spi_register_master(&pdev->dev, master); 417 453 if (status < 0) 418 - goto err; 454 + goto err_fck; 419 455 420 456 return status; 421 457 458 + err_fck: 459 + clk_disable_unprepare(spi100k->fck); 460 + err_ick: 461 + clk_disable_unprepare(spi100k->ick); 422 462 err: 423 463 spi_master_put(master); 424 464 return status; 425 465 } 426 466 467 + static int omap1_spi100k_remove(struct platform_device *pdev) 468 + { 469 + struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); 470 + struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 471 + 472 + pm_runtime_disable(&pdev->dev); 473 + 474 + clk_disable_unprepare(spi100k->fck); 475 + clk_disable_unprepare(spi100k->ick); 476 + 477 + return 0; 478 + } 479 + 480 + #ifdef CONFIG_PM 481 + static int omap1_spi100k_runtime_suspend(struct device *dev) 482 + { 483 + struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 484 + struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 485 + 486 + clk_disable_unprepare(spi100k->ick); 487 + clk_disable_unprepare(spi100k->fck); 488 + 489 + return 0; 490 + } 491 + 492 + static int omap1_spi100k_runtime_resume(struct device *dev) 493 + { 494 + struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 495 + struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 496 + int ret; 497 + 498 + ret = clk_prepare_enable(spi100k->ick); 499 + if (ret != 0) { 500 + dev_err(dev, "Failed to enable ick: %d\n", ret); 501 + return ret; 502 + } 503 + 504 + ret = clk_prepare_enable(spi100k->fck); 505 + if (ret != 0) { 506 + dev_err(dev, "Failed to enable fck: %d\n", ret); 507 + clk_disable_unprepare(spi100k->ick); 508 + return ret; 509 + } 510 + 511 + return 0; 512 + } 513 + #endif 514 + 515 + static const struct dev_pm_ops omap1_spi100k_pm = { 516 + SET_RUNTIME_PM_OPS(omap1_spi100k_runtime_suspend, 517 + omap1_spi100k_runtime_resume, NULL) 518 + }; 519 + 427 520 static struct platform_driver omap1_spi100k_driver = { 428 521 .driver = { 429 522 .name = "omap1_spi100k", 523 + .pm = &omap1_spi100k_pm, 430 524 }, 431 525 .probe = omap1_spi100k_probe, 526 + .remove = omap1_spi100k_remove, 432 527 }; 433 528 434 529 module_platform_driver(omap1_spi100k_driver);
-1
drivers/spi/spi-omap-uwire.c
··· 44 44 #include <linux/module.h> 45 45 #include <linux/io.h> 46 46 47 - #include <asm/irq.h> 48 47 #include <mach/hardware.h> 49 48 #include <asm/mach-types.h> 50 49
+7 -7
drivers/spi/spi-pl022.c
··· 285 285 */ 286 286 #define DEFAULT_SSP_REG_IMSC 0x0UL 287 287 #define DISABLE_ALL_INTERRUPTS DEFAULT_SSP_REG_IMSC 288 - #define ENABLE_ALL_INTERRUPTS (~DEFAULT_SSP_REG_IMSC) 288 + #define ENABLE_ALL_INTERRUPTS ( \ 289 + SSP_IMSC_MASK_RORIM | \ 290 + SSP_IMSC_MASK_RTIM | \ 291 + SSP_IMSC_MASK_RXIM | \ 292 + SSP_IMSC_MASK_TXIM \ 293 + ) 289 294 290 295 #define CLEAR_ALL_INTERRUPTS 0x3 291 296 ··· 1256 1251 struct pl022 *pl022 = dev_id; 1257 1252 struct spi_message *msg = pl022->cur_msg; 1258 1253 u16 irq_status = 0; 1259 - u16 flag = 0; 1260 1254 1261 1255 if (unlikely(!msg)) { 1262 1256 dev_err(&pl022->adev->dev, ··· 1284 1280 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF) 1285 1281 dev_err(&pl022->adev->dev, 1286 1282 "RXFIFO is full\n"); 1287 - if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_TNF) 1288 - dev_err(&pl022->adev->dev, 1289 - "TXFIFO is full\n"); 1290 1283 1291 1284 /* 1292 1285 * Disable and clear interrupts, disable SSP, ··· 1304 1303 1305 1304 readwriter(pl022); 1306 1305 1307 - if ((pl022->tx == pl022->tx_end) && (flag == 0)) { 1308 - flag = 1; 1306 + if (pl022->tx == pl022->tx_end) { 1309 1307 /* Disable Transmit interrupt, enable receive interrupt */ 1310 1308 writew((readw(SSP_IMSC(pl022->virtbase)) & 1311 1309 ~SSP_IMSC_MASK_TXIM) | SSP_IMSC_MASK_RXIM,
+121 -71
drivers/spi/spi-pxa2xx.c
··· 20 20 #include <linux/errno.h> 21 21 #include <linux/err.h> 22 22 #include <linux/interrupt.h> 23 + #include <linux/kernel.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/spi/pxa2xx_spi.h> 25 26 #include <linux/spi/spi.h> ··· 30 29 #include <linux/clk.h> 31 30 #include <linux/pm_runtime.h> 32 31 #include <linux/acpi.h> 33 - 34 - #include <asm/io.h> 35 - #include <asm/irq.h> 36 - #include <asm/delay.h> 37 32 38 33 #include "spi-pxa2xx.h" 39 34 ··· 63 66 #define LPSS_RX_THRESH_DFLT 64 64 67 #define LPSS_TX_LOTHRESH_DFLT 160 65 68 #define LPSS_TX_HITHRESH_DFLT 224 66 - 67 - struct quark_spi_rate { 68 - u32 bitrate; 69 - u32 dds_clk_rate; 70 - u32 clk_div; 71 - }; 72 - 73 - /* 74 - * 'rate', 'dds', 'clk_div' lookup table, which is defined in 75 - * the Quark SPI datasheet. 76 - */ 77 - static const struct quark_spi_rate quark_spi_rate_table[] = { 78 - /* bitrate, dds_clk_rate, clk_div */ 79 - {50000000, 0x800000, 0}, 80 - {40000000, 0x666666, 0}, 81 - {25000000, 0x400000, 0}, 82 - {20000000, 0x666666, 1}, 83 - {16667000, 0x800000, 2}, 84 - {13333000, 0x666666, 2}, 85 - {12500000, 0x200000, 0}, 86 - {10000000, 0x800000, 4}, 87 - {8000000, 0x666666, 4}, 88 - {6250000, 0x400000, 3}, 89 - {5000000, 0x400000, 4}, 90 - {4000000, 0x666666, 9}, 91 - {3125000, 0x80000, 0}, 92 - {2500000, 0x400000, 9}, 93 - {2000000, 0x666666, 19}, 94 - {1563000, 0x40000, 0}, 95 - {1250000, 0x200000, 9}, 96 - {1000000, 0x400000, 24}, 97 - {800000, 0x666666, 49}, 98 - {781250, 0x20000, 0}, 99 - {625000, 0x200000, 19}, 100 - {500000, 0x400000, 49}, 101 - {400000, 0x666666, 99}, 102 - {390625, 0x10000, 0}, 103 - {250000, 0x400000, 99}, 104 - {200000, 0x666666, 199}, 105 - {195313, 0x8000, 0}, 106 - {125000, 0x100000, 49}, 107 - {100000, 0x200000, 124}, 108 - {50000, 0x100000, 124}, 109 - {25000, 0x80000, 124}, 110 - {10016, 0x20000, 77}, 111 - {5040, 0x20000, 154}, 112 - {1002, 0x8000, 194}, 113 - }; 114 69 115 70 /* Offset from drv_data->lpss_base */ 116 71 #define GENERAL_REG 0x08 ··· 650 701 } 651 702 652 703 /* 653 - * The Quark SPI data sheet gives a table, and for the given 'rate', 654 - * the 'dds' and 'clk_div' can be found in the table. 704 + * The Quark SPI has an additional 24 bit register (DDS_CLK_RATE) to multiply 705 + * input frequency by fractions of 2^24. It also has a divider by 5. 706 + * 707 + * There are formulas to get baud rate value for given input frequency and 708 + * divider parameters, such as DDS_CLK_RATE and SCR: 709 + * 710 + * Fsys = 200MHz 711 + * 712 + * Fssp = Fsys * DDS_CLK_RATE / 2^24 (1) 713 + * Baud rate = Fsclk = Fssp / (2 * (SCR + 1)) (2) 714 + * 715 + * DDS_CLK_RATE either 2^n or 2^n / 5. 716 + * SCR is in range 0 .. 255 717 + * 718 + * Divisor = 5^i * 2^j * 2 * k 719 + * i = [0, 1] i = 1 iff j = 0 or j > 3 720 + * j = [0, 23] j = 0 iff i = 1 721 + * k = [1, 256] 722 + * Special case: j = 0, i = 1: Divisor = 2 / 5 723 + * 724 + * Accordingly to the specification the recommended values for DDS_CLK_RATE 725 + * are: 726 + * Case 1: 2^n, n = [0, 23] 727 + * Case 2: 2^24 * 2 / 5 (0x666666) 728 + * Case 3: less than or equal to 2^24 / 5 / 16 (0x33333) 729 + * 730 + * In all cases the lowest possible value is better. 731 + * 732 + * The function calculates parameters for all cases and chooses the one closest 733 + * to the asked baud rate. 655 734 */ 656 - static u32 quark_x1000_set_clk_regvals(u32 rate, u32 *dds, u32 *clk_div) 735 + static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds) 657 736 { 658 - unsigned int i; 737 + unsigned long xtal = 200000000; 738 + unsigned long fref = xtal / 2; /* mandatory division by 2, 739 + see (2) */ 740 + /* case 3 */ 741 + unsigned long fref1 = fref / 2; /* case 1 */ 742 + unsigned long fref2 = fref * 2 / 5; /* case 2 */ 743 + unsigned long scale; 744 + unsigned long q, q1, q2; 745 + long r, r1, r2; 746 + u32 mul; 659 747 660 - for (i = 0; i < ARRAY_SIZE(quark_spi_rate_table); i++) { 661 - if (rate >= quark_spi_rate_table[i].bitrate) { 662 - *dds = quark_spi_rate_table[i].dds_clk_rate; 663 - *clk_div = quark_spi_rate_table[i].clk_div; 664 - return quark_spi_rate_table[i].bitrate; 748 + /* Case 1 */ 749 + 750 + /* Set initial value for DDS_CLK_RATE */ 751 + mul = (1 << 24) >> 1; 752 + 753 + /* Calculate initial quot */ 754 + q1 = DIV_ROUND_CLOSEST(fref1, rate); 755 + 756 + /* Scale q1 if it's too big */ 757 + if (q1 > 256) { 758 + /* Scale q1 to range [1, 512] */ 759 + scale = fls_long(q1 - 1); 760 + if (scale > 9) { 761 + q1 >>= scale - 9; 762 + mul >>= scale - 9; 763 + } 764 + 765 + /* Round the result if we have a remainder */ 766 + q1 += q1 & 1; 767 + } 768 + 769 + /* Decrease DDS_CLK_RATE as much as we can without loss in precision */ 770 + scale = __ffs(q1); 771 + q1 >>= scale; 772 + mul >>= scale; 773 + 774 + /* Get the remainder */ 775 + r1 = abs(fref1 / (1 << (24 - fls_long(mul))) / q1 - rate); 776 + 777 + /* Case 2 */ 778 + 779 + q2 = DIV_ROUND_CLOSEST(fref2, rate); 780 + r2 = abs(fref2 / q2 - rate); 781 + 782 + /* 783 + * Choose the best between two: less remainder we have the better. We 784 + * can't go case 2 if q2 is greater than 256 since SCR register can 785 + * hold only values 0 .. 255. 786 + */ 787 + if (r2 >= r1 || q2 > 256) { 788 + /* case 1 is better */ 789 + r = r1; 790 + q = q1; 791 + } else { 792 + /* case 2 is better */ 793 + r = r2; 794 + q = q2; 795 + mul = (1 << 24) * 2 / 5; 796 + } 797 + 798 + /* Check case 3 only If the divisor is big enough */ 799 + if (fref / rate >= 80) { 800 + u64 fssp; 801 + u32 m; 802 + 803 + /* Calculate initial quot */ 804 + q1 = DIV_ROUND_CLOSEST(fref, rate); 805 + m = (1 << 24) / q1; 806 + 807 + /* Get the remainder */ 808 + fssp = (u64)fref * m; 809 + do_div(fssp, 1 << 24); 810 + r1 = abs(fssp - rate); 811 + 812 + /* Choose this one if it suits better */ 813 + if (r1 < r) { 814 + /* case 3 is better */ 815 + q = 1; 816 + mul = m; 665 817 } 666 818 } 667 819 668 - *dds = quark_spi_rate_table[i-1].dds_clk_rate; 669 - *clk_div = quark_spi_rate_table[i-1].clk_div; 670 - 671 - return quark_spi_rate_table[i-1].bitrate; 820 + *dds = mul; 821 + return q - 1; 672 822 } 673 823 674 824 static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate) ··· 778 730 rate = min_t(int, ssp_clk, rate); 779 731 780 732 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP) 781 - return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8; 733 + return (ssp_clk / (2 * rate) - 1) & 0xff; 782 734 else 783 - return ((ssp_clk / rate - 1) & 0xfff) << 8; 735 + return (ssp_clk / rate - 1) & 0xfff; 784 736 } 785 737 786 738 static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, 787 739 struct chip_data *chip, int rate) 788 740 { 789 - u32 clk_div; 741 + unsigned int clk_div; 790 742 791 743 switch (drv_data->ssp_type) { 792 744 case QUARK_X1000_SSP: 793 - quark_x1000_set_clk_regvals(rate, &chip->dds_rate, &clk_div); 794 - return clk_div << 8; 745 + clk_div = quark_x1000_get_clk_div(rate, &chip->dds_rate); 746 + break; 795 747 default: 796 - return ssp_get_clk_div(drv_data, rate); 748 + clk_div = ssp_get_clk_div(drv_data, rate); 749 + break; 797 750 } 751 + return clk_div << 8; 798 752 } 799 753 800 754 static void pump_transfers(unsigned long data)
-114
drivers/spi/spi.c
··· 128 128 return 0; 129 129 } 130 130 131 - #ifdef CONFIG_PM_SLEEP 132 - static int spi_legacy_suspend(struct device *dev, pm_message_t message) 133 - { 134 - int value = 0; 135 - struct spi_driver *drv = to_spi_driver(dev->driver); 136 - 137 - /* suspend will stop irqs and dma; no more i/o */ 138 - if (drv) { 139 - if (drv->suspend) 140 - value = drv->suspend(to_spi_device(dev), message); 141 - else 142 - dev_dbg(dev, "... can't suspend\n"); 143 - } 144 - return value; 145 - } 146 - 147 - static int spi_legacy_resume(struct device *dev) 148 - { 149 - int value = 0; 150 - struct spi_driver *drv = to_spi_driver(dev->driver); 151 - 152 - /* resume may restart the i/o queue */ 153 - if (drv) { 154 - if (drv->resume) 155 - value = drv->resume(to_spi_device(dev)); 156 - else 157 - dev_dbg(dev, "... can't resume\n"); 158 - } 159 - return value; 160 - } 161 - 162 - static int spi_pm_suspend(struct device *dev) 163 - { 164 - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 165 - 166 - if (pm) 167 - return pm_generic_suspend(dev); 168 - else 169 - return spi_legacy_suspend(dev, PMSG_SUSPEND); 170 - } 171 - 172 - static int spi_pm_resume(struct device *dev) 173 - { 174 - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 175 - 176 - if (pm) 177 - return pm_generic_resume(dev); 178 - else 179 - return spi_legacy_resume(dev); 180 - } 181 - 182 - static int spi_pm_freeze(struct device *dev) 183 - { 184 - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 185 - 186 - if (pm) 187 - return pm_generic_freeze(dev); 188 - else 189 - return spi_legacy_suspend(dev, PMSG_FREEZE); 190 - } 191 - 192 - static int spi_pm_thaw(struct device *dev) 193 - { 194 - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 195 - 196 - if (pm) 197 - return pm_generic_thaw(dev); 198 - else 199 - return spi_legacy_resume(dev); 200 - } 201 - 202 - static int spi_pm_poweroff(struct device *dev) 203 - { 204 - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 205 - 206 - if (pm) 207 - return pm_generic_poweroff(dev); 208 - else 209 - return spi_legacy_suspend(dev, PMSG_HIBERNATE); 210 - } 211 - 212 - static int spi_pm_restore(struct device *dev) 213 - { 214 - const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 215 - 216 - if (pm) 217 - return pm_generic_restore(dev); 218 - else 219 - return spi_legacy_resume(dev); 220 - } 221 - #else 222 - #define spi_pm_suspend NULL 223 - #define spi_pm_resume NULL 224 - #define spi_pm_freeze NULL 225 - #define spi_pm_thaw NULL 226 - #define spi_pm_poweroff NULL 227 - #define spi_pm_restore NULL 228 - #endif 229 - 230 - static const struct dev_pm_ops spi_pm = { 231 - .suspend = spi_pm_suspend, 232 - .resume = spi_pm_resume, 233 - .freeze = spi_pm_freeze, 234 - .thaw = spi_pm_thaw, 235 - .poweroff = spi_pm_poweroff, 236 - .restore = spi_pm_restore, 237 - SET_RUNTIME_PM_OPS( 238 - pm_generic_runtime_suspend, 239 - pm_generic_runtime_resume, 240 - NULL 241 - ) 242 - }; 243 - 244 131 struct bus_type spi_bus_type = { 245 132 .name = "spi", 246 133 .dev_groups = spi_dev_groups, 247 134 .match = spi_match_device, 248 135 .uevent = spi_uevent, 249 - .pm = &spi_pm, 250 136 }; 251 137 EXPORT_SYMBOL_GPL(spi_bus_type); 252 138
-4
include/linux/spi/spi.h
··· 162 162 * @remove: Unbinds this driver from the spi device 163 163 * @shutdown: Standard shutdown callback used during system state 164 164 * transitions such as powerdown/halt and kexec 165 - * @suspend: Standard suspend callback used during system state transitions 166 - * @resume: Standard resume callback used during system state transitions 167 165 * @driver: SPI device drivers should initialize the name and owner 168 166 * field of this structure. 169 167 * ··· 182 184 int (*probe)(struct spi_device *spi); 183 185 int (*remove)(struct spi_device *spi); 184 186 void (*shutdown)(struct spi_device *spi); 185 - int (*suspend)(struct spi_device *spi, pm_message_t mesg); 186 - int (*resume)(struct spi_device *spi); 187 187 struct device_driver driver; 188 188 }; 189 189