spi-pxa2xx.c (5928808ef623347e0d4aa22327b992e9e125b6ad) spi-pxa2xx.c (7d94a50585884180a487ce17e8ddbfa37f7694b6)
1/*
2 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 16 unchanged lines hidden (view full) ---

25#include <linux/platform_device.h>
26#include <linux/spi/pxa2xx_spi.h>
27#include <linux/spi/spi.h>
28#include <linux/workqueue.h>
29#include <linux/delay.h>
30#include <linux/gpio.h>
31#include <linux/slab.h>
32#include <linux/clk.h>
1/*
2 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *

--- 16 unchanged lines hidden (view full) ---

25#include <linux/platform_device.h>
26#include <linux/spi/pxa2xx_spi.h>
27#include <linux/spi/spi.h>
28#include <linux/workqueue.h>
29#include <linux/delay.h>
30#include <linux/gpio.h>
31#include <linux/slab.h>
32#include <linux/clk.h>
33#include <linux/pm_runtime.h>
33
34#include <asm/io.h>
35#include <asm/irq.h>
36#include <asm/delay.h>
37
38#include "spi-pxa2xx.h"
39
40MODULE_AUTHOR("Stephen Street");

--- 371 unchanged lines hidden (view full) ---

412 /* We did something */
413 return IRQ_HANDLED;
414}
415
416static irqreturn_t ssp_int(int irq, void *dev_id)
417{
418 struct driver_data *drv_data = dev_id;
419 void __iomem *reg = drv_data->ioaddr;
34
35#include <asm/io.h>
36#include <asm/irq.h>
37#include <asm/delay.h>
38
39#include "spi-pxa2xx.h"
40
41MODULE_AUTHOR("Stephen Street");

--- 371 unchanged lines hidden (view full) ---

413 /* We did something */
414 return IRQ_HANDLED;
415}
416
417static irqreturn_t ssp_int(int irq, void *dev_id)
418{
419 struct driver_data *drv_data = dev_id;
420 void __iomem *reg = drv_data->ioaddr;
420 u32 sccr1_reg = read_SSCR1(reg);
421 u32 sccr1_reg;
421 u32 mask = drv_data->mask_sr;
422 u32 status;
423
422 u32 mask = drv_data->mask_sr;
423 u32 status;
424
425 /*
426 * The IRQ might be shared with other peripherals so we must first
427 * check that are we RPM suspended or not. If we are we assume that
428 * the IRQ was not for us (we shouldn't be RPM suspended when the
429 * interrupt is enabled).
430 */
431 if (pm_runtime_suspended(&drv_data->pdev->dev))
432 return IRQ_NONE;
433
434 sccr1_reg = read_SSCR1(reg);
424 status = read_SSSR(reg);
425
426 /* Ignore possible writes if we don't need to write */
427 if (!(sccr1_reg & SSCR1_TIE))
428 mask &= ~SSSR_TFS;
429
430 if (!(status & mask))
431 return IRQ_NONE;

--- 241 unchanged lines hidden (view full) ---

673 * chip configuration */
674 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
675
676 /* Mark as busy and launch transfers */
677 tasklet_schedule(&drv_data->pump_transfers);
678 return 0;
679}
680
435 status = read_SSSR(reg);
436
437 /* Ignore possible writes if we don't need to write */
438 if (!(sccr1_reg & SSCR1_TIE))
439 mask &= ~SSSR_TFS;
440
441 if (!(status & mask))
442 return IRQ_NONE;

--- 241 unchanged lines hidden (view full) ---

684 * chip configuration */
685 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
686
687 /* Mark as busy and launch transfers */
688 tasklet_schedule(&drv_data->pump_transfers);
689 return 0;
690}
691
692static int pxa2xx_spi_prepare_transfer(struct spi_master *master)
693{
694 struct driver_data *drv_data = spi_master_get_devdata(master);
695
696 pm_runtime_get_sync(&drv_data->pdev->dev);
697 return 0;
698}
699
700static int pxa2xx_spi_unprepare_transfer(struct spi_master *master)
701{
702 struct driver_data *drv_data = spi_master_get_devdata(master);
703
704 /* Disable the SSP now */
705 write_SSCR0(read_SSCR0(drv_data->ioaddr) & ~SSCR0_SSE,
706 drv_data->ioaddr);
707
708 pm_runtime_mark_last_busy(&drv_data->pdev->dev);
709 pm_runtime_put_autosuspend(&drv_data->pdev->dev);
710 return 0;
711}
712
681static int setup_cs(struct spi_device *spi, struct chip_data *chip,
682 struct pxa2xx_spi_chip *chip_info)
683{
684 int err = 0;
685
686 if (chip == NULL || chip_info == NULL)
687 return 0;
688

--- 221 unchanged lines hidden (view full) ---

910 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
911
912 master->bus_num = ssp->port_id;
913 master->num_chipselect = platform_info->num_chipselect;
914 master->dma_alignment = DMA_ALIGNMENT;
915 master->cleanup = cleanup;
916 master->setup = setup;
917 master->transfer_one_message = pxa2xx_spi_transfer_one_message;
713static int setup_cs(struct spi_device *spi, struct chip_data *chip,
714 struct pxa2xx_spi_chip *chip_info)
715{
716 int err = 0;
717
718 if (chip == NULL || chip_info == NULL)
719 return 0;
720

--- 221 unchanged lines hidden (view full) ---

942 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
943
944 master->bus_num = ssp->port_id;
945 master->num_chipselect = platform_info->num_chipselect;
946 master->dma_alignment = DMA_ALIGNMENT;
947 master->cleanup = cleanup;
948 master->setup = setup;
949 master->transfer_one_message = pxa2xx_spi_transfer_one_message;
950 master->prepare_transfer_hardware = pxa2xx_spi_prepare_transfer;
951 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
918
919 drv_data->ssp_type = ssp->type;
920 drv_data->null_dma_buf = (u32 *)PTR_ALIGN(&drv_data[1], DMA_ALIGNMENT);
921
922 drv_data->ioaddr = ssp->mmio_base;
923 drv_data->ssdr_physical = ssp->phys_base + SSDR;
924 if (pxa25x_ssp_comp(drv_data)) {
925 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;

--- 49 unchanged lines hidden (view full) ---

975 /* Register with the SPI framework */
976 platform_set_drvdata(pdev, drv_data);
977 status = spi_register_master(master);
978 if (status != 0) {
979 dev_err(&pdev->dev, "problem registering spi master\n");
980 goto out_error_clock_enabled;
981 }
982
952
953 drv_data->ssp_type = ssp->type;
954 drv_data->null_dma_buf = (u32 *)PTR_ALIGN(&drv_data[1], DMA_ALIGNMENT);
955
956 drv_data->ioaddr = ssp->mmio_base;
957 drv_data->ssdr_physical = ssp->phys_base + SSDR;
958 if (pxa25x_ssp_comp(drv_data)) {
959 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;

--- 49 unchanged lines hidden (view full) ---

1009 /* Register with the SPI framework */
1010 platform_set_drvdata(pdev, drv_data);
1011 status = spi_register_master(master);
1012 if (status != 0) {
1013 dev_err(&pdev->dev, "problem registering spi master\n");
1014 goto out_error_clock_enabled;
1015 }
1016
1017 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
1018 pm_runtime_use_autosuspend(&pdev->dev);
1019 pm_runtime_set_active(&pdev->dev);
1020 pm_runtime_enable(&pdev->dev);
1021
983 return status;
984
985out_error_clock_enabled:
986 clk_disable_unprepare(ssp->clk);
987 pxa2xx_spi_dma_release(drv_data);
988 free_irq(ssp->irq, drv_data);
989
990out_error_master_alloc:

--- 6 unchanged lines hidden (view full) ---

997{
998 struct driver_data *drv_data = platform_get_drvdata(pdev);
999 struct ssp_device *ssp;
1000
1001 if (!drv_data)
1002 return 0;
1003 ssp = drv_data->ssp;
1004
1022 return status;
1023
1024out_error_clock_enabled:
1025 clk_disable_unprepare(ssp->clk);
1026 pxa2xx_spi_dma_release(drv_data);
1027 free_irq(ssp->irq, drv_data);
1028
1029out_error_master_alloc:

--- 6 unchanged lines hidden (view full) ---

1036{
1037 struct driver_data *drv_data = platform_get_drvdata(pdev);
1038 struct ssp_device *ssp;
1039
1040 if (!drv_data)
1041 return 0;
1042 ssp = drv_data->ssp;
1043
1044 pm_runtime_get_sync(&pdev->dev);
1045
1005 /* Disable the SSP at the peripheral and SOC level */
1006 write_SSCR0(0, drv_data->ioaddr);
1007 clk_disable_unprepare(ssp->clk);
1008
1009 /* Release DMA */
1010 if (drv_data->master_info->enable_dma)
1011 pxa2xx_spi_dma_release(drv_data);
1012
1046 /* Disable the SSP at the peripheral and SOC level */
1047 write_SSCR0(0, drv_data->ioaddr);
1048 clk_disable_unprepare(ssp->clk);
1049
1050 /* Release DMA */
1051 if (drv_data->master_info->enable_dma)
1052 pxa2xx_spi_dma_release(drv_data);
1053
1054 pm_runtime_put_noidle(&pdev->dev);
1055 pm_runtime_disable(&pdev->dev);
1056
1013 /* Release IRQ */
1014 free_irq(ssp->irq, drv_data);
1015
1016 /* Release SSP */
1017 pxa_ssp_free(ssp);
1018
1019 /* Disconnect from the SPI framework */
1020 spi_unregister_master(drv_data->master);

--- 43 unchanged lines hidden (view full) ---

1064 status = spi_master_resume(drv_data->master);
1065 if (status != 0) {
1066 dev_err(dev, "problem starting queue (%d)\n", status);
1067 return status;
1068 }
1069
1070 return 0;
1071}
1057 /* Release IRQ */
1058 free_irq(ssp->irq, drv_data);
1059
1060 /* Release SSP */
1061 pxa_ssp_free(ssp);
1062
1063 /* Disconnect from the SPI framework */
1064 spi_unregister_master(drv_data->master);

--- 43 unchanged lines hidden (view full) ---

1108 status = spi_master_resume(drv_data->master);
1109 if (status != 0) {
1110 dev_err(dev, "problem starting queue (%d)\n", status);
1111 return status;
1112 }
1113
1114 return 0;
1115}
1116#endif
1072
1117
1118#ifdef CONFIG_PM_RUNTIME
1119static int pxa2xx_spi_runtime_suspend(struct device *dev)
1120{
1121 struct driver_data *drv_data = dev_get_drvdata(dev);
1122
1123 clk_disable_unprepare(drv_data->ssp->clk);
1124 return 0;
1125}
1126
1127static int pxa2xx_spi_runtime_resume(struct device *dev)
1128{
1129 struct driver_data *drv_data = dev_get_drvdata(dev);
1130
1131 clk_prepare_enable(drv_data->ssp->clk);
1132 return 0;
1133}
1134#endif
1135
1073static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
1136static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
1074 .suspend = pxa2xx_spi_suspend,
1075 .resume = pxa2xx_spi_resume,
1137 SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume)
1138 SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend,
1139 pxa2xx_spi_runtime_resume, NULL)
1076};
1140};
1077#endif
1078
1079static struct platform_driver driver = {
1080 .driver = {
1081 .name = "pxa2xx-spi",
1082 .owner = THIS_MODULE,
1141
1142static struct platform_driver driver = {
1143 .driver = {
1144 .name = "pxa2xx-spi",
1145 .owner = THIS_MODULE,
1083#ifdef CONFIG_PM
1084 .pm = &pxa2xx_spi_pm_ops,
1146 .pm = &pxa2xx_spi_pm_ops,
1085#endif
1086 },
1087 .probe = pxa2xx_spi_probe,
1088 .remove = pxa2xx_spi_remove,
1089 .shutdown = pxa2xx_spi_shutdown,
1090};
1091
1092static int __init pxa2xx_spi_init(void)
1093{
1094 return platform_driver_register(&driver);
1095}
1096subsys_initcall(pxa2xx_spi_init);
1097
1098static void __exit pxa2xx_spi_exit(void)
1099{
1100 platform_driver_unregister(&driver);
1101}
1102module_exit(pxa2xx_spi_exit);
1147 },
1148 .probe = pxa2xx_spi_probe,
1149 .remove = pxa2xx_spi_remove,
1150 .shutdown = pxa2xx_spi_shutdown,
1151};
1152
1153static int __init pxa2xx_spi_init(void)
1154{
1155 return platform_driver_register(&driver);
1156}
1157subsys_initcall(pxa2xx_spi_init);
1158
1159static void __exit pxa2xx_spi_exit(void)
1160{
1161 platform_driver_unregister(&driver);
1162}
1163module_exit(pxa2xx_spi_exit);