--- zzzz-none-000/linux-2.6.39.4/drivers/i2c/busses/i2c-pxa-pci.c 2011-08-03 19:43:28.000000000 +0000 +++ puma6-arm-6490-729/linux-2.6.39.4/drivers/i2c/busses/i2c-pxa-pci.c 2021-11-10 13:23:10.000000000 +0000 @@ -11,17 +11,38 @@ #include #define CE4100_PCI_I2C_DEVS 3 +#define CE5X00_PCI_I2C_DEVS 4 +#define CE2600_PCI_I2C_DEVS 2 + struct ce4100_devices { - struct platform_device *pdev[CE4100_PCI_I2C_DEVS]; + unsigned int dev_num; + struct platform_device **pdev; }; +unsigned int pio_mode = 0; +unsigned int fast_mode = 1; +/*set_iwcr_flag is used to indentify whether to set I2C iwcr register*/ +/*There is workaround for CE5300 to set iwcr reigister*/ +unsigned int set_iwcr_flag = 0; + +module_param(pio_mode, uint, S_IRUGO); +MODULE_PARM_DESC(pio_mode, "whether the I2C running at polling mode(1) or Interrupt mode(0)"); +module_param(fast_mode, uint, S_IRUGO); +MODULE_PARM_DESC(fast_mode, "whether the I2C running at standard mode(0) or fast mode(1)"); +module_param(set_iwcr_flag, uint, S_IRUGO); +MODULE_PARM_DESC(set_iwcr_flag, "whether set I2C iwcr register to 0x12"); + static struct platform_device *add_i2c_device(struct pci_dev *dev, int bar) { struct platform_device *pdev; struct i2c_pxa_platform_data pdata; struct resource res[2]; +#ifdef CONFIG_OF +#ifndef CONFIG_GEN3_I2C struct device_node *child; +#endif +#endif static int devnum; int ret; @@ -35,7 +56,8 @@ res[1].flags = IORESOURCE_IRQ; res[1].start = dev->irq; res[1].end = dev->irq; - +#ifdef CONFIG_OF +#ifndef CONFIG_GEN3_I2C for_each_child_of_node(dev->dev.of_node, child) { const void *prop; struct resource r; @@ -64,24 +86,38 @@ ret = -EINVAL; goto out; } - +#endif +#endif + pdata.fast_mode = fast_mode; + pdata.use_pio = pio_mode; + pdata.set_iwcr_flag = set_iwcr_flag; + pdev = platform_device_alloc("ce4100-i2c", devnum); if (!pdev) { +#ifdef CONFIG_OF +#ifndef CONFIG_GEN3_I2C of_node_put(child); +#endif +#endif ret = -ENOMEM; goto out; } pdev->dev.parent = &dev->dev; + +#ifdef CONFIG_OF +#ifndef CONFIG_GEN3_I2C pdev->dev.of_node = child; +#endif +#endif ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); if (ret) goto err; - + ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (ret) goto err; - + ret = platform_device_add(pdev); if (ret) goto err; @@ -98,21 +134,53 @@ { int ret; int i; + unsigned int id, rev; struct ce4100_devices *sds; ret = pci_enable_device_mem(dev); if (ret) return ret; +#ifdef CONFIG_OF +#ifndef CONFIG_GEN3_I2C if (!dev->dev.of_node) { dev_err(&dev->dev, "Missing device tree node.\n"); return -EINVAL; } +#endif +#endif sds = kzalloc(sizeof(*sds), GFP_KERNEL); if (!sds) - goto err_mem; + goto err_mem_sds; + + intelce_get_soc_info(&id, &rev); + switch (id) { + case CE5300_SOC_DEVICE_ID: + /*when detect as CE5300 other than CE5300 A0 platform here we set set_iwcr_flag to 1*/ + if(rev >= 4){ + set_iwcr_flag = 1; + } + sds->dev_num = CE5X00_PCI_I2C_DEVS; + break; + case CE4100_SOC_DEVICE_ID: + case CE4200_SOC_DEVICE_ID: + sds->dev_num = CE4100_PCI_I2C_DEVS; + break; + case CE2600_SOC_DEVICE_ID: + sds->dev_num = CE2600_PCI_I2C_DEVS; + if (rev == 0) + sds->dev_num = CE2600_PCI_I2C_DEVS - 1; /*i2c bus 1 have bug*/ + break; + default: + printk(KERN_ERR "Don't support this soc device id:0x%x\n",id); + goto err_mem_pdev; + } + + sds->pdev = kzalloc(sizeof(struct platform_device *) * sds->dev_num, GFP_KERNEL); + if (!sds->pdev) + goto err_mem_pdev; - for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) { + for (i = 0; i < sds->dev_num; i++) { sds->pdev[i] = add_i2c_device(dev, i); if (IS_ERR(sds->pdev[i])) { while (--i >= 0) @@ -125,8 +193,10 @@ err_dev_add: pci_set_drvdata(dev, NULL); + kfree(sds->pdev); +err_mem_pdev: kfree(sds); -err_mem: +err_mem_sds: pci_disable_device(dev); return ret; } @@ -139,13 +209,33 @@ sds = pci_get_drvdata(dev); pci_set_drvdata(dev, NULL); - for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) + for (i = 0; i < sds->dev_num; i++) platform_device_unregister(sds->pdev[i]); pci_disable_device(dev); + kfree(sds->pdev); kfree(sds); } +#ifdef CONFIG_PM +static int ce4100_i2c_suspend(struct pci_dev *dev, pm_message_t state) +{ + + pci_save_state(dev); + pci_set_power_state(dev, pci_choose_state(dev, state)); + return 0; +} + +static int ce4100_i2c_resume(struct pci_dev *dev) +{ + + pci_set_power_state(dev, PCI_D0); + pci_restore_state(dev); + + return 0; +} + +#endif static struct pci_device_id ce4100_i2c_devices[] __devinitdata = { { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e68)}, { }, @@ -157,6 +247,10 @@ .id_table = ce4100_i2c_devices, .probe = ce4100_i2c_probe, .remove = __devexit_p(ce4100_i2c_remove), +#ifdef CONFIG_PM + .suspend = ce4100_i2c_suspend, + .resume = ce4100_i2c_resume, +#endif }; static int __init ce4100_i2c_init(void)