/** * pnp_disable_dev - disables device * @dev: pointer to the desired device * * inform the correct pnp protocol so that resources can be used by other devices */ int pnp_disable_dev(struct pnp_dev *dev) { if (!dev) return -EINVAL; if (!dev->active) { return 0; /* the device is already disabled */ } if (!pnp_can_disable(dev)) { pnp_info("Device %s does not supported disabling.", dev->dev.bus_id); return -EINVAL; } if (dev->protocol->disable(dev)<0) { pnp_err("Failed to disable device %s.", dev->dev.bus_id); return -EIO; } dev->active = 0; pnp_info("Device %s disabled.", dev->dev.bus_id); /* release the resources so that other devices can use them */ down(&pnp_res_mutex); pnp_clean_resource_table(&dev->res); up(&pnp_res_mutex); return 1; }
/** * pnp_activate_dev - activates a PnP device for use * @dev: pointer to the desired device * * does not validate or set resources so be careful. */ int pnp_activate_dev(struct pnp_dev *dev) { if (!dev) return -EINVAL; if (dev->active) { return 0; /* the device is already active */ } /* ensure resources are allocated */ if (pnp_auto_config_dev(dev)) return -EBUSY; if (!pnp_can_write(dev)) { pnp_info("Device %s does not supported activation.", dev->dev.bus_id); return -EINVAL; } if (dev->protocol->set(dev, &dev->res)<0) { pnp_err("Failed to activate device %s.", dev->dev.bus_id); return -EIO; } dev->active = 1; pnp_info("Device %s activated.", dev->dev.bus_id); return 1; }
int __init pnpacpi_init(void) { if (acpi_disabled || pnpacpi_disabled) { pnp_info("PnP ACPI: disabled"); return 0; } pnp_info("PnP ACPI init"); pnp_register_protocol(&pnpacpi_protocol); acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL); pnp_info("PnP ACPI: found %d devices", num); return 0; }
int pnp_stop_dev(struct pnp_dev *dev) { if (!pnp_can_disable(dev)) { pnp_info("Device %s does not support disabling.", dev->dev.bus_id); return -EINVAL; } if (dev->protocol->disable(dev)<0) { pnp_err("Failed to disable device %s.", dev->dev.bus_id); return -EIO; } pnp_info("Device %s disabled.", dev->dev.bus_id); return 0; }
static int __init pnpacpi_init(void) { if (acpi_disabled || pnpacpi_disabled) { pnp_info("PnP ACPI: disabled"); return 0; } pnp_info("PnP ACPI init"); pnp_register_protocol(&pnpacpi_protocol); register_acpi_bus_type(&acpi_pnp_bus); acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL); pnp_info("PnP ACPI: found %d devices", num); unregister_acpi_bus_type(&acpi_pnp_bus); pnp_platform_devices = 1; return 0; }
int pnp_start_dev(struct pnp_dev *dev) { if (!pnp_can_write(dev)) { pnp_info("Device %s does not support activation.", dev->dev.bus_id); return -EINVAL; } if (dev->protocol->set(dev, &dev->res)<0) { pnp_err("Failed to activate device %s.", dev->dev.bus_id); return -EIO; } pnp_info("Device %s activated.", dev->dev.bus_id); return 0; }
/** * pnp_auto_config_dev - automatically assigns resources to a device * @dev: pointer to the desired device * */ int pnp_auto_config_dev(struct pnp_dev *dev) { struct pnp_option *dep; int i = 1; if(!dev) return -EINVAL; if(!pnp_can_configure(dev)) { pnp_info("Device %s does not support resource configuration.", dev->dev.bus_id); return -ENODEV; } if (!dev->dependent) { if (pnp_assign_resources(dev, 0)) return 0; } else { dep = dev->dependent; do { if (pnp_assign_resources(dev, i)) return 0; dep = dep->next; i++; } while (dep); } pnp_err("Unable to assign resources to device %s.", dev->dev.bus_id); return -EBUSY; }
static ssize_t pnp_set_current_resources(struct device * dmdev, struct device_attribute *attr, const char * ubuf, size_t count) { struct pnp_dev *dev = to_pnp_dev(dmdev); char *buf = (void *)ubuf; int retval = 0; if (dev->status & PNP_ATTACHED) { retval = -EBUSY; pnp_info("Device %s cannot be configured because it is in use.", dev->dev.bus_id); goto done; } while (isspace(*buf)) ++buf; if (!strnicmp(buf,"disable",7)) { retval = pnp_disable_dev(dev); goto done; } if (!strnicmp(buf,"activate",8)) { retval = pnp_activate_dev(dev); goto done; } if (!strnicmp(buf,"fill",4)) { if (dev->active) goto done; retval = pnp_auto_config_dev(dev); goto done; } if (!strnicmp(buf,"auto",4)) { if (dev->active) goto done; pnp_init_resource_table(&dev->res); retval = pnp_auto_config_dev(dev); goto done; } if (!strnicmp(buf,"clear",5)) { if (dev->active) goto done; pnp_init_resource_table(&dev->res); goto done; } if (!strnicmp(buf,"get",3)) { down(&pnp_res_mutex); if (pnp_can_read(dev)) dev->protocol->get(dev, &dev->res); up(&pnp_res_mutex); goto done; } if (!strnicmp(buf,"set",3)) { int nport = 0, nmem = 0, nirq = 0, ndma = 0; if (dev->active) goto done; buf += 3; pnp_init_resource_table(&dev->res); down(&pnp_res_mutex); while (1) { while (isspace(*buf)) ++buf; if (!strnicmp(buf,"io",2)) { buf += 2; while (isspace(*buf)) ++buf; dev->res.port_resource[nport].start = simple_strtoul(buf,&buf,0); while (isspace(*buf)) ++buf; if(*buf == '-') { buf += 1; while (isspace(*buf)) ++buf; dev->res.port_resource[nport].end = simple_strtoul(buf,&buf,0); } else dev->res.port_resource[nport].end = dev->res.port_resource[nport].start; dev->res.port_resource[nport].flags = IORESOURCE_IO; nport++; if (nport >= PNP_MAX_PORT) break; continue; } if (!strnicmp(buf,"mem",3)) { buf += 3; while (isspace(*buf)) ++buf; dev->res.mem_resource[nmem].start = simple_strtoul(buf,&buf,0); while (isspace(*buf)) ++buf; if(*buf == '-') { buf += 1; while (isspace(*buf)) ++buf; dev->res.mem_resource[nmem].end = simple_strtoul(buf,&buf,0); } else dev->res.mem_resource[nmem].end = dev->res.mem_resource[nmem].start; dev->res.mem_resource[nmem].flags = IORESOURCE_MEM; nmem++; if (nmem >= PNP_MAX_MEM) break; continue; } if (!strnicmp(buf,"irq",3)) { buf += 3; while (isspace(*buf)) ++buf; dev->res.irq_resource[nirq].start = dev->res.irq_resource[nirq].end = simple_strtoul(buf,&buf,0); dev->res.irq_resource[nirq].flags = IORESOURCE_IRQ; nirq++; if (nirq >= PNP_MAX_IRQ) break; continue; } if (!strnicmp(buf,"dma",3)) { buf += 3; while (isspace(*buf)) ++buf; dev->res.dma_resource[ndma].start = dev->res.dma_resource[ndma].end = simple_strtoul(buf,&buf,0); dev->res.dma_resource[ndma].flags = IORESOURCE_DMA; ndma++; if (ndma >= PNP_MAX_DMA) break; continue; } break; } up(&pnp_res_mutex); goto done; } done: if (retval < 0) return retval; return count; }