--- zzzz-none-000/linux-2.6.39.4/drivers/spi/pxa2xx_spi_pci.c 2011-08-03 19:43:28.000000000 +0000 +++ puma6-atom-6490-729/linux-2.6.39.4/drivers/spi/pxa2xx_spi_pci.c 2021-11-10 13:38:15.000000000 +0000 @@ -5,8 +5,25 @@ #include #include #include +#include #include +#define CE4200_NUM_SPI_MASTER 1 +#define CE4200_NUM_CHIPSELECT 4 +#define CE4X00_SPI_MAX_SPEED 1843200 +#define CE5X00_SPI_MAX_SPEED 5000000 + +#define GEN3_BOARD_INFO_CONFIG + +#ifdef SPI_CE_DEBUG +#define spi_dbg(fmt, args...) do \ + { \ + printk(KERN_INFO fmt, ##args); \ + } while(0) +#else +#define spi_dbg(fmt,args...) do {} while(0) +#endif + struct ce4100_info { struct ssp_device ssp; struct platform_device *spi_pdev; @@ -15,6 +32,65 @@ static DEFINE_MUTEX(ssp_lock); static LIST_HEAD(ssp_list); +#ifdef CONFIG_GEN3_SPI +#ifdef GEN3_BOARD_INFO_CONFIG +struct spi_board_info CE4X00_spi_devices[]={ + { + .modalias = "spidev", + .chip_select = 0, + .max_speed_hz = CE4X00_SPI_MAX_SPEED, + .bus_num = 0, + }, + { + .modalias = "spidev", + .chip_select = 1, + .max_speed_hz = CE4X00_SPI_MAX_SPEED, + .bus_num = 0, + }, + { + .modalias = "spidev", + .chip_select = 2, + .max_speed_hz = CE4X00_SPI_MAX_SPEED, + .bus_num = 0, + }, + { + .modalias = "spidev", + .chip_select = 3, + .max_speed_hz = CE4X00_SPI_MAX_SPEED, + .bus_num = 0, + }, +}; + +struct spi_board_info CE5X00_spi_devices[]={ + { + .modalias = "spidev", + .chip_select = 0, + .max_speed_hz = CE5X00_SPI_MAX_SPEED, + .bus_num = 0, + }, + { + .modalias = "spidev", + .chip_select = 1, + .max_speed_hz = CE5X00_SPI_MAX_SPEED, + .bus_num = 0, + }, + { + .modalias = "spidev", + .chip_select = 2, + .max_speed_hz = CE5X00_SPI_MAX_SPEED, + .bus_num = 0, + }, + { + .modalias = "spidev", + .chip_select = 3, + .max_speed_hz = CE5X00_SPI_MAX_SPEED, + .bus_num = 0, + }, +}; + +#endif +#endif + struct ssp_device *pxa_ssp_request(int port, const char *label) { struct ssp_device *ssp = NULL; @@ -50,16 +126,56 @@ } EXPORT_SYMBOL_GPL(pxa_ssp_free); +#ifdef CONFIG_GEN3_SPI +#ifdef GEN3_BOARD_INFO_CONFIG +static void add_spi_dev_devices(void) +{ + unsigned int id; + + spi_dbg("add CE SPI board info\n"); + intelce_get_soc_info(&id, NULL); + switch (id) + { + case CE5300_SOC_DEVICE_ID: + spi_register_board_info(CE5X00_spi_devices,ARRAY_SIZE(CE5X00_spi_devices)); + break; + case CE4200_SOC_DEVICE_ID: + default: + spi_register_board_info(CE4X00_spi_devices,ARRAY_SIZE(CE4X00_spi_devices)); + break; + } +} +static void remove_spi_dev_devices(void) +{ + unsigned int id; + + spi_dbg("remove CE SPI board info\n"); + intelce_get_soc_info(&id, NULL); + switch (id) + { + case CE5300_SOC_DEVICE_ID: + spi_unregister_board_info(CE5X00_spi_devices, ARRAY_SIZE(CE5X00_spi_devices)); + break; + case CE4200_SOC_DEVICE_ID: + default: + spi_unregister_board_info(CE4X00_spi_devices, ARRAY_SIZE(CE4X00_spi_devices)); + break; + } +} +#endif +#endif + static int __devinit ce4100_spi_probe(struct pci_dev *dev, const struct pci_device_id *ent) { int ret; resource_size_t phys_beg; resource_size_t phys_len; - struct ce4100_info *spi_info; + struct ce4100_info *spi_info = NULL; struct platform_device *pdev; - struct pxa2xx_spi_master spi_pdata; + struct pxa2xx_spi_master *spi_pdata = NULL; struct ssp_device *ssp; + unsigned int id; ret = pci_enable_device(dev); if (ret) @@ -79,35 +195,62 @@ spi_info = kzalloc(sizeof(*spi_info), GFP_KERNEL); if (!pdev || !spi_info ) { ret = -ENOMEM; - goto err_nomem; + goto err_malloc_spi_info; } - memset(&spi_pdata, 0, sizeof(spi_pdata)); - spi_pdata.num_chipselect = dev->devfn; - - ret = platform_device_add_data(pdev, &spi_pdata, sizeof(spi_pdata)); - if (ret) - goto err_nomem; + spi_pdata = kzalloc(sizeof(*spi_pdata), GFP_KERNEL); + if (!spi_pdata) { + ret = -ENOMEM; + goto err_malloc_spi_pdata; + + } + printk("spi_pdata is %p\n", spi_pdata); + spi_pdata->num_chipselect = dev->devfn; + spi_pdata->num_chipselect = CE4200_NUM_CHIPSELECT; + pdev->dev.platform_data = spi_pdata; + pdev->id = CE4200_NUM_SPI_MASTER-1; pdev->dev.parent = &dev->dev; +#ifdef CONFIG_OF pdev->dev.of_node = dev->dev.of_node; +#endif ssp = &spi_info->ssp; + + ssp->phys_base = pci_resource_start(dev, 0); ssp->mmio_base = ioremap(phys_beg, phys_len); if (!ssp->mmio_base) { dev_err(&pdev->dev, "failed to ioremap() registers\n"); ret = -EIO; - goto err_nomem; + goto err_ioremap; } ssp->irq = dev->irq; ssp->port_id = pdev->id; - ssp->type = PXA25x_SSP; - + intelce_get_soc_info(&id, NULL); + switch (id) + { + case CE5300_SOC_DEVICE_ID: + ssp->type = CE5X00_SSP; + printk("ssp type is CE5X00 SSP\n"); + break; + case CE4200_SOC_DEVICE_ID: + default: + ssp->type = CE4100_SSP; + printk("ssp type is CE4100 SSP\n"); + break; + } + mutex_lock(&ssp_lock); list_add(&ssp->node, &ssp_list); mutex_unlock(&ssp_lock); pci_set_drvdata(dev, spi_info); +#ifdef CONFIG_GEN3_SPI +#ifdef GEN3_BOARD_INFO_CONFIG + add_spi_dev_devices(); +#endif +#endif + spi_info->spi_pdev = pdev; ret = platform_device_add(pdev); if (ret) goto err_dev_add; @@ -121,10 +264,14 @@ mutex_unlock(&ssp_lock); iounmap(ssp->mmio_base); -err_nomem: +err_ioremap: + +err_malloc_spi_pdata: + kfree(spi_info); + +err_malloc_spi_info: release_mem_region(phys_beg, phys_len); platform_device_put(pdev); - kfree(spi_info); return ret; } @@ -135,8 +282,14 @@ spi_info = pci_get_drvdata(dev); ssp = &spi_info->ssp; - platform_device_unregister(spi_info->spi_pdev); +#ifdef CONFIG_GEN3_SPI +#ifdef GEN3_BOARD_INFO_CONFIG + remove_spi_dev_devices(); +#endif +#endif + + platform_device_unregister(spi_info->spi_pdev); iounmap(ssp->mmio_base); release_mem_region(pci_resource_start(dev, 0), pci_resource_len(dev, 0)); @@ -148,8 +301,28 @@ pci_set_drvdata(dev, NULL); pci_disable_device(dev); kfree(spi_info); + +} + +#ifdef CONFIG_PM +static int ce4XXX_spi_suspend(struct pci_dev *dev, pm_message_t state) +{ + spi_dbg("Start to do spi pci suspend\n"); + pci_save_state(dev); + pci_set_power_state(dev, pci_choose_state(dev, state)); + return 0; } +static int ce4XXX_spi_resume(struct pci_dev *dev) +{ + spi_dbg("Start to do spi pci resume\n"); + pci_set_power_state(dev, PCI_D0); + pci_restore_state(dev); + + return 0; +} +#endif + static struct pci_device_id ce4100_spi_devices[] __devinitdata = { { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) }, { }, @@ -161,6 +334,11 @@ .id_table = ce4100_spi_devices, .probe = ce4100_spi_probe, .remove = __devexit_p(ce4100_spi_remove), +#ifdef CONFIG_PM + .suspend = ce4XXX_spi_suspend, + .resume = ce4XXX_spi_resume, +#endif + }; static int __init ce4100_spi_init(void)