コード例 #1
0
ファイル: core.c プロジェクト: grate-driver/linux
static void kp2000_pcie_remove(struct pci_dev *pdev)
{
	struct kp2000_device *pcard = pci_get_drvdata(pdev);

	dev_dbg(&pdev->dev, "kp2000_pcie_remove(pdev=%p)\n", pdev);

	if (pcard == NULL)
		return;

	mutex_lock(&pcard->sem);
	kp2000_remove_cores(pcard);
	mfd_remove_devices(PCARD_TO_DEV(pcard));
	misc_deregister(&pcard->miscdev);
	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
	free_irq(pcard->pdev->irq, pcard);
	pci_disable_msi(pcard->pdev);
	if (pcard->dma_bar_base != NULL) {
		iounmap(pcard->dma_bar_base);
		pci_release_region(pdev, DMA_BAR);
		pcard->dma_bar_base = NULL;
	}
	if (pcard->regs_bar_base != NULL) {
		iounmap(pcard->regs_bar_base);
		pci_release_region(pdev, REG_BAR);
		pcard->regs_bar_base = NULL;
	}
	pci_disable_device(pcard->pdev);
	pci_set_drvdata(pdev, NULL);
	mutex_unlock(&pcard->sem);
	ida_simple_remove(&card_num_ida, pcard->card_num);
	kfree(pcard);
}
コード例 #2
0
ファイル: hua_ts_core.c プロジェクト: redspider110/cavan
static void hua_ts_device_remove(struct hua_input_device *dev)
{
	struct hua_ts_device *ts = (struct hua_ts_device *)dev;
	struct hua_input_chip *chip = dev->chip;
	struct hua_input_core *core = chip->core;

#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&ts->early_suspend);
#elif defined(CONFIG_FB) && defined(CONFIG_HUAMOBILE_USE_FB_NOTIFILER)
	fb_unregister_client(&ts->fb_notifier);
#else
	unregister_pm_notifier(&ts->pm_notifier);
#endif

	sysfs_remove_files(&dev->misc_dev.dev->kobj, hua_ts_device_attributes);
	hua_input_remove_sysfs_files(&core->prop_kobj, &hua_ts_board_properties_attr, 1);
	kfree(hua_ts_board_properties_attr.attr.name);
	hua_input_remove_kobject(&core->prop_kobj);
}
コード例 #3
0
ファイル: dfl-fme-main.c プロジェクト: AlexShiLucky/linux
static void fme_hdr_uinit(struct platform_device *pdev,
			  struct dfl_feature *feature)
{
	dev_dbg(&pdev->dev, "FME HDR UInit.\n");
	sysfs_remove_files(&pdev->dev.kobj, fme_hdr_attrs);
}
コード例 #4
0
static inline void __remove_sysfs_file_common(void)
{
    sysfs_remove_files(&kset_gpu->kobj, (const struct attribute **)gc_default_attrs);
}
コード例 #5
0
ファイル: core.c プロジェクト: grate-driver/linux
static int kp2000_pcie_probe(struct pci_dev *pdev,
			     const struct pci_device_id *id)
{
	int err = 0;
	struct kp2000_device *pcard;
	int rv;
	unsigned long reg_bar_phys_addr;
	unsigned long reg_bar_phys_len;
	unsigned long dma_bar_phys_addr;
	unsigned long dma_bar_phys_len;
	u16 regval;

	dev_dbg(&pdev->dev, "kp2000_pcie_probe(pdev = [%p], id = [%p])\n",
		pdev, id);

	/*
	 * Step 1: Allocate a struct for the pcard
	 */
	pcard = kzalloc(sizeof(struct kp2000_device), GFP_KERNEL);
	if (NULL == pcard) {
		dev_err(&pdev->dev,
			"probe: failed to allocate private card data\n");
		return -ENOMEM;
	}
	dev_dbg(&pdev->dev, "probe: allocated struct kp2000_device @ %p\n",
		pcard);

	/*
	 * Step 2: Initialize trivial pcard elements
	 */
	err = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
	if (err < 0) {
		dev_err(&pdev->dev, "probe: failed to get card number (%d)\n",
			err);
		goto out2;
	}
	pcard->card_num = err;
	scnprintf(pcard->name, 16, "kpcard%u", pcard->card_num);

	mutex_init(&pcard->sem);
	mutex_lock(&pcard->sem);

	pcard->pdev = pdev;
	pci_set_drvdata(pdev, pcard);

	/*
	 * Step 3: Enable PCI device
	 */
	err = pci_enable_device(pcard->pdev);
	if (err) {
		dev_err(&pcard->pdev->dev,
			"probe: failed to enable PCIE2000 PCIe device (%d)\n",
			err);
		goto out3;
	}

	/*
	 * Step 4: Setup the Register BAR
	 */
	reg_bar_phys_addr = pci_resource_start(pcard->pdev, REG_BAR);
	reg_bar_phys_len = pci_resource_len(pcard->pdev, REG_BAR);

	pcard->regs_bar_base = ioremap_nocache(reg_bar_phys_addr, PAGE_SIZE);
	if (NULL == pcard->regs_bar_base) {
		dev_err(&pcard->pdev->dev,
			"probe: REG_BAR could not remap memory to virtual space\n");
		err = -ENODEV;
		goto out4;
	}
	dev_dbg(&pcard->pdev->dev,
		"probe: REG_BAR virt hardware address start [%p]\n",
		pcard->regs_bar_base);

	err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
	if (err) {
		iounmap(pcard->regs_bar_base);
		dev_err(&pcard->pdev->dev,
			"probe: failed to acquire PCI region (%d)\n",
			err);
		err = -ENODEV;
		goto out4;
	}

	pcard->regs_base_resource.start = reg_bar_phys_addr;
	pcard->regs_base_resource.end   = reg_bar_phys_addr +
					  reg_bar_phys_len - 1;
	pcard->regs_base_resource.flags = IORESOURCE_MEM;

	/*
	 * Step 5: Setup the DMA BAR
	 */
	dma_bar_phys_addr = pci_resource_start(pcard->pdev, DMA_BAR);
	dma_bar_phys_len = pci_resource_len(pcard->pdev, DMA_BAR);

	pcard->dma_bar_base = ioremap_nocache(dma_bar_phys_addr,
					      dma_bar_phys_len);
	if (NULL == pcard->dma_bar_base) {
		dev_err(&pcard->pdev->dev,
			"probe: DMA_BAR could not remap memory to virtual space\n");
		err = -ENODEV;
		goto out5;
	}
	dev_dbg(&pcard->pdev->dev,
		"probe: DMA_BAR virt hardware address start [%p]\n",
		pcard->dma_bar_base);

	pcard->dma_common_regs = pcard->dma_bar_base + KPC_DMA_COMMON_OFFSET;

	err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
	if (err) {
		iounmap(pcard->dma_bar_base);
		dev_err(&pcard->pdev->dev,
			"probe: failed to acquire PCI region (%d)\n", err);
		err = -ENODEV;
		goto out5;
	}

	pcard->dma_base_resource.start = dma_bar_phys_addr;
	pcard->dma_base_resource.end   = dma_bar_phys_addr +
					 dma_bar_phys_len - 1;
	pcard->dma_base_resource.flags = IORESOURCE_MEM;

	/*
	 * Step 6: System Regs
	 */
	pcard->sysinfo_regs_base = pcard->regs_bar_base;
	err = read_system_regs(pcard);
	if (err)
		goto out6;

	// Disable all "user" interrupts because they're not used yet.
	writeq(0xFFFFFFFFFFFFFFFF,
	       pcard->sysinfo_regs_base + REG_INTERRUPT_MASK);

	/*
	 * Step 7: Configure PCI thingies
	 */
	// let the card master PCIe
	pci_set_master(pcard->pdev);
	// enable IO and mem if not already done
	pci_read_config_word(pcard->pdev, PCI_COMMAND, &regval);
	regval |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
	pci_write_config_word(pcard->pdev, PCI_COMMAND, regval);

	// Clear relaxed ordering bit
	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
					   PCI_EXP_DEVCTL_RELAX_EN, 0);

	// Set Max_Payload_Size and Max_Read_Request_Size
	regval = (0x0) << 5; // Max_Payload_Size = 128 B
	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
					   PCI_EXP_DEVCTL_PAYLOAD, regval);
	regval = (0x0) << 12; // Max_Read_Request_Size = 128 B
	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL,
					   PCI_EXP_DEVCTL_READRQ, regval);

	// Enable error reporting for: Correctable Errors, Non-Fatal Errors,
	// Fatal Errors, Unsupported Requests
	pcie_capability_clear_and_set_word(pcard->pdev, PCI_EXP_DEVCTL, 0,
					   PCI_EXP_DEVCTL_CERE |
					   PCI_EXP_DEVCTL_NFERE |
					   PCI_EXP_DEVCTL_FERE |
					   PCI_EXP_DEVCTL_URRE);

	err = dma_set_mask(PCARD_TO_DEV(pcard), DMA_BIT_MASK(64));
	if (err) {
		dev_err(&pcard->pdev->dev,
			"CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
		goto out7;
	}
	dev_dbg(&pcard->pdev->dev,
		"Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));

	/*
	 * Step 8: Configure IRQs
	 */
	err = pci_enable_msi(pcard->pdev);
	if (err < 0)
		goto out8a;

	rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED,
			 pcard->name, pcard);
	if (rv) {
		dev_err(&pcard->pdev->dev,
			"kp2000_pcie_probe: failed to request_irq: %d\n", rv);
		goto out8b;
	}

	/*
	 * Step 9: Setup sysfs attributes
	 */
	err = sysfs_create_files(&(pdev->dev.kobj), kp_attr_list);
	if (err) {
		dev_err(&pdev->dev, "Failed to add sysfs files: %d\n", err);
		goto out9;
	}

	/*
	 * Step 10: Setup misc device
	 */
	pcard->miscdev.minor = MISC_DYNAMIC_MINOR;
	pcard->miscdev.fops = &kp2000_fops;
	pcard->miscdev.parent = &pcard->pdev->dev;
	pcard->miscdev.name = pcard->name;

	err = misc_register(&pcard->miscdev);
	if (err) {
		dev_err(&pcard->pdev->dev,
			"kp2000_pcie_probe: misc_register failed: %d\n", err);
		goto out10;
	}

	/*
	 * Step 11: Probe cores
	 */
	err = kp2000_probe_cores(pcard);
	if (err)
		goto out11;

	/*
	 * Step 12: Enable IRQs in HW
	 */
	writel(KPC_DMA_CARD_IRQ_ENABLE | KPC_DMA_CARD_USER_INTERRUPT_MODE,
	       pcard->dma_common_regs);

	dev_dbg(&pcard->pdev->dev, "kp2000_pcie_probe() complete!\n");
	mutex_unlock(&pcard->sem);
	return 0;

out11:
	misc_deregister(&pcard->miscdev);
out10:
	sysfs_remove_files(&(pdev->dev.kobj), kp_attr_list);
out9:
	free_irq(pcard->pdev->irq, pcard);
out8b:
	pci_disable_msi(pcard->pdev);
out8a:
out7:
out6:
	iounmap(pcard->dma_bar_base);
	pci_release_region(pdev, DMA_BAR);
	pcard->dma_bar_base = NULL;
out5:
	iounmap(pcard->regs_bar_base);
	pci_release_region(pdev, REG_BAR);
	pcard->regs_bar_base = NULL;
out4:
	pci_disable_device(pcard->pdev);
out3:
	mutex_unlock(&pcard->sem);
	ida_simple_remove(&card_num_ida, pcard->card_num);
out2:
	kfree(pcard);
	return err;
}
コード例 #6
0
static void cavan_sensor_device_remove(struct cavan_input_device *dev)
{
	pr_pos_info();

	sysfs_remove_files(&dev->misc_dev.dev->kobj, cavan_sensor_device_attributes);
}
コード例 #7
0
ファイル: afhba_sysfs.c プロジェクト: petermilne/AFHBA402
void afhba_remove_sysfs_class(struct AFHBA_DEV *adev)
{
	sysfs_remove_files(&adev->pci_dev->dev.kobj, class_attrs);
}
コード例 #8
0
ファイル: afhba_sysfs.c プロジェクト: petermilne/AFHBA402
void afhba_remove_sysfs(struct AFHBA_DEV *adev)
{
	sysfs_remove_files(&adev->class_dev->kobj, dev_attrs);
}