static int __devinit pcf50633_probe(struct i2c_client *client, const struct i2c_device_id *ids) { struct pcf50633 *pcf; struct pcf50633_platform_data *pdata = client->dev.platform_data; int i, ret; int version, variant; if (!client->irq) { dev_err(&client->dev, "Missing IRQ\n"); return -ENOENT; } pcf = kzalloc(sizeof(*pcf), GFP_KERNEL); if (!pcf) return -ENOMEM; pcf->pdata = pdata; mutex_init(&pcf->lock); i2c_set_clientdata(client, pcf); pcf->dev = &client->dev; pcf->i2c_client = client; version = pcf50633_reg_read(pcf, 0); variant = pcf50633_reg_read(pcf, 1); if (version < 0 || variant < 0) { dev_err(pcf->dev, "Unable to probe pcf50633\n"); ret = -ENODEV; goto err_free; } dev_info(pcf->dev, "Probed device version %d variant %d\n", version, variant); pcf50633_irq_init(pcf, client->irq); /* Create sub devices */ pcf50633_client_dev_register(pcf, "pcf50633-input", &pcf->input_pdev); pcf50633_client_dev_register(pcf, "pcf50633-rtc", &pcf->rtc_pdev); pcf50633_client_dev_register(pcf, "pcf50633-mbc", &pcf->mbc_pdev); pcf50633_client_dev_register(pcf, "pcf50633-adc", &pcf->adc_pdev); pcf50633_client_dev_register(pcf, "pcf50633-backlight", &pcf->bl_pdev); for (i = 0; i < PCF50633_NUM_REGULATORS; i++) { struct platform_device *pdev; pdev = platform_device_alloc("pcf50633-regltr", i); if (!pdev) { dev_err(pcf->dev, "Cannot create regulator %d\n", i); continue; } pdev->dev.parent = pcf->dev; platform_device_add_data(pdev, &pdata->reg_init_data[i], sizeof(pdata->reg_init_data[i])); pcf->regulator_pdev[i] = pdev; platform_device_add(pdev); } ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group); if (ret) dev_err(pcf->dev, "error creating sysfs entries\n"); if (pdata->probe_done) pdata->probe_done(pcf); return 0; err_free: kfree(pcf); return ret; }
/** * dwc3_otg_start_host - helper function for starting/stoping the host controller driver. * * @otg: Pointer to the otg_transceiver structure. * @on: start / stop the host controller driver. * * Returns 0 on success otherwise negative errno. */ static int dwc3_otg_start_host(struct usb_otg *otg, int on) { struct dwc3_otg *dotg = container_of(otg, struct dwc3_otg, otg); struct dwc3_ext_xceiv *ext_xceiv = dotg->ext_xceiv; struct dwc3 *dwc = dotg->dwc; int ret = 0; if (!dwc->xhci) return -EINVAL; if (!dotg->vbus_otg) { dotg->vbus_otg = devm_regulator_get(dwc->dev->parent, "vbus_dwc3"); if (IS_ERR(dotg->vbus_otg)) { dev_err(dwc->dev, "Failed to get vbus regulator\n"); ret = PTR_ERR(dotg->vbus_otg); dotg->vbus_otg = 0; return ret; } } if (on) { dev_dbg(otg->phy->dev, "%s: turn on host\n", __func__); /* * This should be revisited for more testing post-silicon. * In worst case we may need to disconnect the root hub * before stopping the controller so that it does not * interfere with runtime pm/system pm. * We can also consider registering and unregistering xhci * platform device. It is almost similar to add_hcd and * remove_hcd, But we may not use standard set_host method * anymore. */ dwc3_otg_set_hsphy_auto_suspend(dotg, true); dwc3_otg_set_host_regs(dotg); /* * FIXME If micro A cable is disconnected during system suspend, * xhci platform device will be removed before runtime pm is * enabled for xhci device. Due to this, disable_depth becomes * greater than one and runtimepm is not enabled for next microA * connect. Fix this by calling pm_runtime_init for xhci device. */ pm_runtime_init(&dwc->xhci->dev); ret = platform_device_add(dwc->xhci); if (ret) { dev_err(otg->phy->dev, "%s: failed to add XHCI pdev ret=%d\n", __func__, ret); return ret; } dwc3_otg_notify_host_mode(otg, on); ret = regulator_enable(dotg->vbus_otg); if (ret) { dev_err(otg->phy->dev, "unable to enable vbus_otg\n"); platform_device_del(dwc->xhci); return ret; } /* re-init OTG EVTEN register as XHCI reset clears it */ if (ext_xceiv && !ext_xceiv->otg_capability) dwc3_otg_reset(dotg); } else { dev_dbg(otg->phy->dev, "%s: turn off host\n", __func__); ret = regulator_disable(dotg->vbus_otg); if (ret) { dev_err(otg->phy->dev, "unable to disable vbus_otg\n"); return ret; } dwc3_otg_notify_host_mode(otg, on); platform_device_del(dwc->xhci); /* * Perform USB hardware RESET (both core reset and DBM reset) * when moving from host to peripheral. This is required for * peripheral mode to work. */ if (ext_xceiv && ext_xceiv->otg_capability && ext_xceiv->ext_block_reset) ext_xceiv->ext_block_reset(ext_xceiv, true); dwc3_otg_set_hsphy_auto_suspend(dotg, false); dwc3_otg_set_peripheral_regs(dotg); /* re-init core and OTG registers as block reset clears these */ dwc3_post_host_reset_core_init(dwc); if (ext_xceiv && !ext_xceiv->otg_capability) dwc3_otg_reset(dotg); } return 0; }
static int omap2430_probe(struct platform_device *pdev) { struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; struct omap_musb_board_data *data; struct platform_device *musb; struct omap2430_glue *glue; struct device_node *np = pdev->dev.of_node; struct musb_hdrc_config *config; int ret = -ENOMEM; glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); if (!glue) { dev_err(&pdev->dev, "failed to allocate glue context\n"); goto err0; } musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); if (!musb) { dev_err(&pdev->dev, "failed to allocate musb device\n"); goto err0; } musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &omap2430_dmamask; musb->dev.coherent_dma_mask = omap2430_dmamask; glue->dev = &pdev->dev; glue->musb = musb; glue->status = OMAP_MUSB_UNKNOWN; if (np) { pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { dev_err(&pdev->dev, "failed to allocate musb platfrom data\n"); goto err2; } data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) { dev_err(&pdev->dev, "failed to allocate musb board data\n"); goto err2; } config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); if (!config) { dev_err(&pdev->dev, "failed to allocate musb hdrc config\n"); goto err2; } of_property_read_u32(np, "mode", (u32 *)&pdata->mode); of_property_read_u32(np, "interface_type", (u32 *)&data->interface_type); of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps); of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits); of_property_read_u32(np, "power", (u32 *)&pdata->power); config->multipoint = of_property_read_bool(np, "multipoint"); pdata->has_mailbox = of_property_read_bool(np, "ti,has-mailbox"); pdata->board_data = data; pdata->config = config; } if (pdata->has_mailbox) { glue->control_otghs = omap_get_control_dev(); if (IS_ERR(glue->control_otghs)) { dev_vdbg(&pdev->dev, "Failed to get control device\n"); return -ENODEV; } } else { glue->control_otghs = ERR_PTR(-ENODEV); } pdata->platform_ops = &omap2430_ops; platform_set_drvdata(pdev, glue); /* * REVISIT if we ever have two instances of the wrapper, we will be * in big trouble */ _glue = glue; INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); ret = platform_device_add_resources(musb, pdev->resource, pdev->num_resources); if (ret) { dev_err(&pdev->dev, "failed to add resources\n"); goto err2; } ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); if (ret) { dev_err(&pdev->dev, "failed to add platform_data\n"); goto err2; } pm_runtime_enable(&pdev->dev); ret = platform_device_add(musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device\n"); goto err2; } return 0; err2: platform_device_put(musb); err0: return ret; }
static int dtv_probe(struct platform_device *pdev) { struct msm_fb_data_type *mfd; struct fb_info *fbi; struct platform_device *mdp_dev = NULL; struct msm_fb_panel_data *pdata = NULL; int rc; if (pdev->id == 0) { dtv_pdata = pdev->dev.platform_data; return 0; } mfd = platform_get_drvdata(pdev); if (!mfd) return -ENODEV; if (mfd->key != MFD_KEY) return -EINVAL; if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST) return -ENOMEM; mdp_dev = platform_device_alloc("mdp", pdev->id); if (!mdp_dev) return -ENOMEM; /* * link to the latest pdev */ mfd->pdev = mdp_dev; mfd->dest = DISPLAY_LCDC; /* * alloc panel device data */ if (platform_device_add_data (mdp_dev, pdev->dev.platform_data, sizeof(struct msm_fb_panel_data))) { pr_err("dtv_probe: platform_device_add_data failed!\n"); platform_device_put(mdp_dev); return -ENOMEM; } /* * data chain */ pdata = (struct msm_fb_panel_data *)mdp_dev->dev.platform_data; pdata->on = dtv_on; pdata->off = dtv_off; pdata->next = pdev; /* * get/set panel specific fb info */ mfd->panel_info = pdata->panel_info; if (hdmi_prim_display) mfd->fb_imgType = MSMFB_DEFAULT_TYPE; else mfd->fb_imgType = MDP_RGB_565; fbi = mfd->fbi; fbi->var.pixclock = mfd->panel_info.clk_rate; fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch; fbi->var.right_margin = mfd->panel_info.lcdc.h_front_porch; fbi->var.upper_margin = mfd->panel_info.lcdc.v_back_porch; fbi->var.lower_margin = mfd->panel_info.lcdc.v_front_porch; fbi->var.hsync_len = mfd->panel_info.lcdc.h_pulse_width; fbi->var.vsync_len = mfd->panel_info.lcdc.v_pulse_width; #ifdef CONFIG_MSM_BUS_SCALING if (!dtv_bus_scale_handle && dtv_pdata && dtv_pdata->bus_scale_table) { dtv_bus_scale_handle = msm_bus_scale_register_client( dtv_pdata->bus_scale_table); if (!dtv_bus_scale_handle) { pr_err("%s not able to get bus scale\n", __func__); } } #else ebi1_clk = clk_get(NULL, "ebi1_dtv_clk"); if (IS_ERR(ebi1_clk)) { ebi1_clk = NULL; pr_warning("%s: Couldn't get ebi1 clock\n", __func__); } #endif /* * set driver data */ platform_set_drvdata(mdp_dev, mfd); /* * register in mdp driver */ rc = platform_device_add(mdp_dev); if (rc) goto dtv_probe_err; pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); pdev_list[pdev_list_cnt++] = pdev; return 0; dtv_probe_err: #ifdef CONFIG_MSM_BUS_SCALING if (dtv_pdata && dtv_pdata->bus_scale_table && dtv_bus_scale_handle > 0) msm_bus_scale_unregister_client(dtv_bus_scale_handle); #endif platform_device_put(mdp_dev); return rc; }
static int mddi_ext_probe(struct platform_device *pdev) { struct msm_fb_data_type *mfd; struct platform_device *mdp_dev = NULL; struct msm_fb_panel_data *pdata = NULL; int rc; resource_size_t size ; u32 clk_rate; if ((pdev->id == 0) && (pdev->num_resources >= 0)) { mddi_ext_pdata = pdev->dev.platform_data; size = resource_size(&pdev->resource[0]); msm_emdh_base = ioremap(pdev->resource[0].start, size); MSM_FB_INFO("external mddi base address = 0x%x\n", pdev->resource[0].start); if (unlikely(!msm_emdh_base)) return -ENOMEM; mddi_ext_resource_initialized = 1; return 0; } if (!mddi_ext_resource_initialized) return -EPERM; mfd = platform_get_drvdata(pdev); if (!mfd) return -ENODEV; if (mfd->key != MFD_KEY) return -EINVAL; if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST) return -ENOMEM; mdp_dev = platform_device_alloc("mdp", pdev->id); if (!mdp_dev) return -ENOMEM; ///////////////////////////////////////// // link to the latest pdev ///////////////////////////////////////// mfd->pdev = mdp_dev; mfd->dest = DISPLAY_EXT_MDDI; ///////////////////////////////////////// // alloc panel device data ///////////////////////////////////////// if (platform_device_add_data (mdp_dev, pdev->dev.platform_data, sizeof(struct msm_fb_panel_data))) { printk(KERN_ERR "mddi_ext_probe: platform_device_add_data failed!\n"); platform_device_put(mdp_dev); return -ENOMEM; } ///////////////////////////////////////// // data chain ///////////////////////////////////////// pdata = mdp_dev->dev.platform_data; pdata->on = mddi_ext_on; pdata->off = mddi_ext_off; pdata->next = pdev; ///////////////////////////////////////// // get/set panel specific fb info ///////////////////////////////////////// mfd->panel_info = pdata->panel_info; mfd->fb_imgType = MDP_RGB_565; clk_rate = mfd->panel_info.clk_max; if (mddi_ext_pdata && mddi_ext_pdata->mddi_sel_clk && mddi_ext_pdata->mddi_sel_clk(&clk_rate)) printk(KERN_ERR "%s: can't select mddi io clk targate rate = %d\n", __func__, clk_rate); if (clk_set_max_rate(mddi_ext_clk, clk_rate) < 0) printk(KERN_ERR "%s: clk_set_max_rate failed\n", __func__); mfd->panel_info.clk_rate = mfd->panel_info.clk_min; ///////////////////////////////////////// // set driver data ///////////////////////////////////////// platform_set_drvdata(mdp_dev, mfd); ///////////////////////////////////////// // register in mdp driver ///////////////////////////////////////// rc = platform_device_add(mdp_dev); if (rc) { goto mddi_ext_probe_err; } pdev_list[pdev_list_cnt++] = pdev; #ifdef CONFIG_HAS_EARLYSUSPEND mfd->mddi_ext_early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB; mfd->mddi_ext_early_suspend.suspend = mddi_ext_early_suspend; mfd->mddi_ext_early_suspend.resume = mddi_ext_early_resume; register_early_suspend(&mfd->mddi_ext_early_suspend); #endif return 0; mddi_ext_probe_err: platform_device_put(mdp_dev); return rc; }
static int motor_add_one(unsigned int id, unsigned int *params) { int status, err; struct cdev *motor_cdev; struct platform_device *pdev; struct gpio_pwm_platform_data pdata; if ( mot_nump[id] < 4 ) { printk(KERN_INFO "stepper: nothing to register for id: %d.\n", id); return 0; } g_enable[id] = params[1]; g_dir[id] = params[2]; g_step[id] = params[3]; g_lpwr[id] = params[4]; polarity[id] = params[5]; /* sanity check */ if ( !( g_enable[id] && g_dir[id] && g_step[id])) { printk(KERN_INFO "stepper: missing parameters, exit driver.\n"); goto err_para; } /* request and set pwm channel and gpio pins */ pdev = platform_device_alloc("gpio_pwm", g_step[id]); if (!pdev) { err = -ENOMEM; goto err_para; } pdata.gpio = g_step[id]; err = platform_device_add_data(pdev, &pdata, sizeof(pdata)); if (err) goto err; err = platform_device_add(pdev); if (err) goto err; pwmc[id] = pwm_request("gpio_pwm", g_step[id], "stepper"); if (pwmc[id] != NULL) { goto err_pwm; } motor_pwm_set (pwmc[id], 0); /* set default pwm pulse */ if ( gpio_request(g_enable[id], "motor-enable") < 0 ) { goto err_gpioenable; } gpio_direction_output(g_enable[id] ,0); if ( gpio_request(g_dir[id], "motor-ccw") < 0) { goto err_gpiodir; } gpio_direction_output(g_dir[id] ,0); if (g_lpwr[id] != 0) { if ( gpio_request(g_lpwr[id], "motor-lowpwr") < 0 ) { goto err_gpiolwr; } gpio_direction_output(g_lpwr[id] ,0); } /* set to home */ steps[id] = 0; /* alloc a new device number (major: dynamic, minor: 0) */ status = alloc_chrdev_region(&motor_devno, 0, 1, "motor"); /* create a new char device */ motor_cdev = cdev_alloc(); if(motor_cdev == NULL) { status=-ENOMEM; goto err_dev; } /*save the cdev for id's */ mot_map[id] = (int) motor_cdev; motor_cdev->owner = THIS_MODULE; motor_cdev->ops = &motor_fops; status = cdev_add(motor_cdev, motor_devno, 1); if(status){ goto err_dev; } device_create(motor_class, NULL, motor_devno, NULL, "motor%d", params[0]); printk(KERN_INFO "stepper: motor%d registred on major: %u; minor: %u\n", \ params[0], MAJOR(motor_devno), MINOR(motor_devno)); return 0; err: printk(KERN_INFO "stepper: err\n"); err_dev: printk(KERN_INFO "stepper: err_dev\n"); err_gpiolwr: printk(KERN_INFO "stepper: err_gpiolwr\n"); err_gpiodir: printk(KERN_INFO "stepper: err_gpiodir\n"); err_gpioenable: printk(KERN_INFO "stepper: err_gpioenable\n"); err_gpiostep: printk(KERN_INFO "stepper: err_gpiostep "); err_pwm: printk(KERN_INFO "stepper: err_pwm\n"); err_para: printk(KERN_INFO "stepper: Error management not yet implemented. \ Please reboot your board %d\n",g_step[id]); return -1; }
static struct platform_device * soc_button_device_create(struct pnp_dev *pdev, const struct soc_button_info *button_info, bool autorepeat) { const struct soc_button_info *info; struct platform_device *pd; struct gpio_keys_button *gpio_keys; struct gpio_keys_platform_data *gpio_keys_pdata; int n_buttons = 0; int gpio; int error; gpio_keys_pdata = devm_kzalloc(&pdev->dev, sizeof(*gpio_keys_pdata) + sizeof(*gpio_keys) * MAX_NBUTTONS, GFP_KERNEL); if (!gpio_keys_pdata) return ERR_PTR(-ENOMEM); gpio_keys = (void *)(gpio_keys_pdata + 1); for (info = button_info; info->name; info++) { if (info->autorepeat != autorepeat) continue; gpio = soc_button_lookup_gpio(&pdev->dev, info->acpi_index); if (gpio < 0) continue; gpio_keys[n_buttons].type = info->event_type; gpio_keys[n_buttons].code = info->event_code; gpio_keys[n_buttons].gpio = gpio; gpio_keys[n_buttons].active_low = 1; gpio_keys[n_buttons].desc = info->name; gpio_keys[n_buttons].wakeup = info->wakeup; n_buttons++; } if (n_buttons == 0) { error = -ENODEV; goto err_free_mem; } gpio_keys_pdata->buttons = gpio_keys; gpio_keys_pdata->nbuttons = n_buttons; gpio_keys_pdata->rep = autorepeat; pd = platform_device_alloc("gpio-keys", PLATFORM_DEVID_AUTO); if (!pd) { error = -ENOMEM; goto err_free_mem; } error = platform_device_add_data(pd, gpio_keys_pdata, sizeof(*gpio_keys_pdata)); if (error) goto err_free_pdev; error = platform_device_add(pd); if (error) goto err_free_pdev; return pd; err_free_pdev: platform_device_put(pd); err_free_mem: devm_kfree(&pdev->dev, gpio_keys_pdata); return ERR_PTR(error); }
static int __devinit da8xx_probe(struct platform_device *pdev) { struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; struct platform_device *musb; struct da8xx_glue *glue; struct clk *clk; int ret = -ENOMEM; glue = kzalloc(sizeof(*glue), GFP_KERNEL); if (!glue) { dev_err(&pdev->dev, "failed to allocate glue context\n"); goto err0; } musb = platform_device_alloc("musb-hdrc", -1); if (!musb) { dev_err(&pdev->dev, "failed to allocate musb device\n"); goto err1; } clk = clk_get(&pdev->dev, "usb20"); if (IS_ERR(clk)) { dev_err(&pdev->dev, "failed to get clock\n"); ret = PTR_ERR(clk); goto err2; } ret = clk_enable(clk); if (ret) { dev_err(&pdev->dev, "failed to enable clock\n"); goto err3; } musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &da8xx_dmamask; musb->dev.coherent_dma_mask = da8xx_dmamask; glue->dev = &pdev->dev; glue->musb = musb; glue->clk = clk; pdata->platform_ops = &da8xx_ops; platform_set_drvdata(pdev, glue); ret = platform_device_add_resources(musb, pdev->resource, pdev->num_resources); if (ret) { dev_err(&pdev->dev, "failed to add resources\n"); goto err4; } ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); if (ret) { dev_err(&pdev->dev, "failed to add platform_data\n"); goto err4; } ret = platform_device_add(musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device\n"); goto err4; } return 0; err4: clk_disable(clk); err3: clk_put(clk); err2: platform_device_put(musb); err1: kfree(glue); err0: return ret; }
static int __devinit omap2430_probe(struct platform_device *pdev) { struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; struct platform_device *musb; struct omap2430_glue *glue; int ret = -ENOMEM; glue = kzalloc(sizeof(*glue), GFP_KERNEL); if (!glue) { dev_err(&pdev->dev, "failed to allocate glue context\n"); goto err0; } musb = platform_device_alloc("musb-hdrc", -1); if (!musb) { dev_err(&pdev->dev, "failed to allocate musb device\n"); goto err1; } musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &omap2430_dmamask; musb->dev.coherent_dma_mask = omap2430_dmamask; glue->dev = &pdev->dev; glue->musb = musb; pdata->platform_ops = &omap2430_ops; platform_set_drvdata(pdev, glue); ret = platform_device_add_resources(musb, pdev->resource, pdev->num_resources); if (ret) { dev_err(&pdev->dev, "failed to add resources\n"); goto err2; } ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); if (ret) { dev_err(&pdev->dev, "failed to add platform_data\n"); goto err2; } pm_runtime_enable(&pdev->dev); ret = platform_device_add(musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device\n"); goto err2; } return 0; err2: platform_device_put(musb); err1: kfree(glue); err0: return ret; }
static int __init fighter_audio_init(void) { int ret = 0, rc = 0; struct pm_gpio param = { .direction = PM_GPIO_DIR_OUT, .output_buffer = PM_GPIO_OUT_BUF_CMOS, .output_value = 0, .pull = PM_GPIO_PULL_NO, .vin_sel = PM_GPIO_VIN_L17, .out_strength = PM_GPIO_STRENGTH_MED, .function = PM_GPIO_FUNC_NORMAL, }; if (!cpu_is_msm8960()) { pr_info("%s: Not the right machine type\n", __func__); return -ENODEV ; } pr_info("%s", __func__); msm8960_snd_device = platform_device_alloc("soc-audio", 0); if (!msm8960_snd_device) { pr_err("Platform device allocation failed\n"); return -ENOMEM; } memcpy(msm8960_dai, msm8960_dai_common, sizeof(msm8960_dai_common)); memcpy(msm8960_dai + ARRAY_SIZE(msm8960_dai_common), msm8960_dai_delta_tabla2x, sizeof(msm8960_dai_delta_tabla2x)); platform_set_drvdata(msm8960_snd_device, &snd_soc_card_msm8960); ret = platform_device_add(msm8960_snd_device); if (ret) { platform_device_put(msm8960_snd_device); return ret; } msm8960_snd_tabla1x_device = platform_device_alloc("soc-audio", 1); if (!msm8960_snd_tabla1x_device) { pr_err("Platform device allocation failed\n"); return -ENOMEM; } memcpy(msm8960_tabla1x_dai, msm8960_dai_common, sizeof(msm8960_dai_common)); memcpy(msm8960_tabla1x_dai + ARRAY_SIZE(msm8960_dai_common), msm8960_dai_delta_tabla1x, sizeof(msm8960_dai_delta_tabla1x)); platform_set_drvdata(msm8960_snd_tabla1x_device, &snd_soc_tabla1x_card_msm8960); ret = platform_device_add(msm8960_snd_tabla1x_device); if (ret) { platform_device_put(msm8960_snd_tabla1x_device); return ret; } rc = gpio_request(PM8921_GPIO_PM_TO_SYS(FIGHTER_PMGPIO_AUD_AMP_EN), "fighter_en"); rc = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(FIGHTER_PMGPIO_AUD_AMP_EN), ¶m); if (rc < 0) pr_aud_err("failed to configure tpa2051_en gpio\n"); mutex_init(&cdc_mclk_mutex); htc_register_q6asm_ops(&qops); htc_register_pcm_routing_ops(&rops); acoustic_register_ops(&acoustic); return ret; } late_initcall(fighter_audio_init); static void __exit fighter_audio_exit(void) { if (!cpu_is_msm8960()) { pr_info("%s: Not the right machine type\n", __func__); return ; } pr_info("%s", __func__); platform_device_unregister(msm8960_snd_device); platform_device_unregister(msm8960_snd_tabla1x_device); gpio_free(PAMP_GPIO); mutex_destroy(&cdc_mclk_mutex); } module_exit(fighter_audio_exit); MODULE_DESCRIPTION("ALSA Platform Fighter"); MODULE_LICENSE("GPL v2");
static int imx_ahci_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *mem, *irq, res[2]; const struct of_device_id *of_id; const struct ahci_platform_data *pdata = NULL; struct imx_ahci_priv *imxpriv; struct device *ahci_dev; struct platform_device *ahci_pdev; int ret; imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL); if (!imxpriv) { dev_err(dev, "can't alloc ahci_host_priv\n"); return -ENOMEM; } ahci_pdev = platform_device_alloc("ahci", -1); if (!ahci_pdev) return -ENODEV; ahci_dev = &ahci_pdev->dev; ahci_dev->parent = dev; imxpriv->ahb_clk = devm_clk_get(dev, "ahb"); if (IS_ERR(imxpriv->ahb_clk)) { dev_err(dev, "can't get ahb clock.\n"); ret = PTR_ERR(imxpriv->ahb_clk); goto err_out; } imxpriv->sata_ref_clk = devm_clk_get(dev, "sata_ref"); if (IS_ERR(imxpriv->sata_ref_clk)) { dev_err(dev, "can't get sata_ref clock.\n"); ret = PTR_ERR(imxpriv->sata_ref_clk); goto err_out; } imxpriv->ahci_pdev = ahci_pdev; platform_set_drvdata(pdev, imxpriv); of_id = of_match_device(imx_ahci_of_match, dev); if (of_id) { pdata = of_id->data; } else { ret = -EINVAL; goto err_out; } mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!mem || !irq) { dev_err(dev, "no mmio/irq resource\n"); ret = -ENOMEM; goto err_out; } res[0] = *mem; res[1] = *irq; ahci_dev->coherent_dma_mask = DMA_BIT_MASK(32); ahci_dev->dma_mask = &ahci_dev->coherent_dma_mask; ahci_dev->of_node = dev->of_node; ret = platform_device_add_resources(ahci_pdev, res, 2); if (ret) goto err_out; ret = platform_device_add_data(ahci_pdev, pdata, sizeof(*pdata)); if (ret) goto err_out; ret = platform_device_add(ahci_pdev); if (ret) { err_out: platform_device_put(ahci_pdev); return ret; } return 0; }
static int __init omap3pandora_soc_init(void) { int ret; if (!machine_is_omap3_pandora()) return -ENODEV; pr_info("OMAP3 Pandora SoC init\n"); ret = gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO, "dac_power"); if (ret) { pr_err(PREFIX "Failed to get DAC power GPIO\n"); return ret; } ret = gpio_direction_output(OMAP3_PANDORA_DAC_POWER_GPIO, 0); if (ret) { pr_err(PREFIX "Failed to set DAC power GPIO direction\n"); goto fail0; } ret = gpio_request(OMAP3_PANDORA_AMP_POWER_GPIO, "amp_power"); if (ret) { pr_err(PREFIX "Failed to get amp power GPIO\n"); goto fail0; } ret = gpio_direction_output(OMAP3_PANDORA_AMP_POWER_GPIO, 0); if (ret) { pr_err(PREFIX "Failed to set amp power GPIO direction\n"); goto fail1; } omap3pandora_snd_device = platform_device_alloc("soc-audio", -1); if (omap3pandora_snd_device == NULL) { pr_err(PREFIX "Platform device allocation failed\n"); ret = -ENOMEM; goto fail1; } platform_set_drvdata(omap3pandora_snd_device, &snd_soc_card_omap3pandora); ret = platform_device_add(omap3pandora_snd_device); if (ret) { pr_err(PREFIX "Unable to add platform device\n"); goto fail2; } omap3pandora_dac_reg = regulator_get(&omap3pandora_snd_device->dev, "vcc"); if (IS_ERR(omap3pandora_dac_reg)) { pr_err(PREFIX "Failed to get DAC regulator from %s: %ld\n", dev_name(&omap3pandora_snd_device->dev), PTR_ERR(omap3pandora_dac_reg)); ret = PTR_ERR(omap3pandora_dac_reg); goto fail3; } return 0; fail3: platform_device_del(omap3pandora_snd_device); fail2: platform_device_put(omap3pandora_snd_device); fail1: gpio_free(OMAP3_PANDORA_AMP_POWER_GPIO); fail0: gpio_free(OMAP3_PANDORA_DAC_POWER_GPIO); return ret; }
static int lcdc_probe(struct platform_device *pdev) { struct msm_fb_data_type *mfd; struct fb_info *fbi; struct platform_device *mdp_dev = NULL; struct msm_fb_panel_data *pdata = NULL; int rc; if (pdev->id == 0) { lcdc_pdata = pdev->dev.platform_data; return 0; } mfd = platform_get_drvdata(pdev); pdev_hdmi_01=pdev; printk(KERN_ERR "[Jackie] lcdc_probe(), pdev=0x%x, mfd=0x%x\n", (unsigned int) pdev, (unsigned int) mfd); if (!mfd) return -ENODEV; if (mfd->key != MFD_KEY) return -EINVAL; if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST) return -ENOMEM; mdp_dev = platform_device_alloc("mdp", pdev->id); if (!mdp_dev) return -ENOMEM; mfd->pdev = mdp_dev; mfd->dest = DISPLAY_LCDC; if (platform_device_add_data (mdp_dev, pdev->dev.platform_data, sizeof(struct msm_fb_panel_data))) { printk(KERN_ERR "lcdc_probe: platform_device_add_data failed!\n"); platform_device_put(mdp_dev); return -ENOMEM; } pdata = (struct msm_fb_panel_data *)mdp_dev->dev.platform_data; pdata->on = lcdc_on; pdata->off = lcdc_off; pdata->next = pdev; mfd->panel_info = pdata->panel_info; if (mfd->index == 0) mfd->fb_imgType = MSMFB_DEFAULT_TYPE; else mfd->fb_imgType = MDP_RGB_565; fbi = mfd->fbi; fbi->var.pixclock = clk_round_rate(pixel_mdp_clk, mfd->panel_info.clk_rate); fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch; fbi->var.right_margin = mfd->panel_info.lcdc.h_front_porch; fbi->var.upper_margin = mfd->panel_info.lcdc.v_back_porch; fbi->var.lower_margin = mfd->panel_info.lcdc.v_front_porch; fbi->var.hsync_len = mfd->panel_info.lcdc.h_pulse_width; fbi->var.vsync_len = mfd->panel_info.lcdc.v_pulse_width; platform_set_drvdata(mdp_dev, mfd); rc = platform_device_add(mdp_dev); if (rc) goto lcdc_probe_err; pdev_list[pdev_list_cnt++] = pdev; return 0; lcdc_probe_err: platform_device_put(mdp_dev); return rc; }
static int lcdc_probe(struct platform_device *pdev) { struct msm_fb_data_type *mfd; struct fb_info *fbi; struct platform_device *mdp_dev = NULL; struct msm_fb_panel_data *pdata = NULL; int rc; if (pdev->id == 0) { lcdc_pdata = pdev->dev.platform_data; return 0; } mfd = platform_get_drvdata(pdev); if (!mfd) return -ENODEV; if (mfd->key != MFD_KEY) return -EINVAL; if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST) return -ENOMEM; mdp_dev = platform_device_alloc("mdp", pdev->id); if (!mdp_dev) return -ENOMEM; /* * link to the latest pdev */ mfd->pdev = mdp_dev; mfd->dest = DISPLAY_LCDC; /* * alloc panel device data */ if (platform_device_add_data (mdp_dev, pdev->dev.platform_data, sizeof(struct msm_fb_panel_data))) { printk(KERN_ERR "lcdc_probe: platform_device_add_data failed!\n"); platform_device_put(mdp_dev); return -ENOMEM; } /* * data chain */ pdata = (struct msm_fb_panel_data *)mdp_dev->dev.platform_data; pdata->on = lcdc_on; pdata->off = lcdc_off; pdata->next = pdev; /* * get/set panel specific fb info */ mfd->panel_info = pdata->panel_info; if (mfd->index == 0) mfd->fb_imgType = MSMFB_DEFAULT_TYPE; else mfd->fb_imgType = MDP_RGB_565; fbi = mfd->fbi; fbi->var.pixclock = clk_round_rate(pixel_mdp_clk, mfd->panel_info.clk_rate); fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch; fbi->var.right_margin = mfd->panel_info.lcdc.h_front_porch; fbi->var.upper_margin = mfd->panel_info.lcdc.v_back_porch; fbi->var.lower_margin = mfd->panel_info.lcdc.v_front_porch; fbi->var.hsync_len = mfd->panel_info.lcdc.h_pulse_width; fbi->var.vsync_len = mfd->panel_info.lcdc.v_pulse_width; #ifndef CONFIG_MSM_BUS_SCALING mfd->ebi1_clk = clk_get(NULL, "ebi1_lcdc_clk"); if (IS_ERR(mfd->ebi1_clk)) return PTR_ERR(mfd->ebi1_clk); #endif /* * set driver data */ platform_set_drvdata(mdp_dev, mfd); /* * register in mdp driver */ rc = platform_device_add(mdp_dev); if (rc) goto lcdc_probe_err; pdev_list[pdev_list_cnt++] = pdev; /* DSTxkf37152 xiangguangchao enable lcd display, begin 2011/3/9 */ //pdata->on(mfd->pdev); //mfd->bl_level = (mfd->panel_info.bl_max)/10 * 4; //pdata->set_backlight(mfd); /* DSTxkf37152 xiangguangchao enable lcd display, end 2011/3/9 */ return 0; lcdc_probe_err: platform_device_put(mdp_dev); return rc; }
static int ebi2_lcd_probe(struct platform_device *pdev) { struct msm_fb_data_type *mfd; struct platform_device *mdp_dev = NULL; struct msm_fb_panel_data *pdata = NULL; int rc, i; if (pdev->id == 0) { for (i = 0; i < pdev->num_resources; i++) { if (!strncmp(pdev->resource[i].name, "base", 4)) { ebi2_base = ioremap(pdev->resource[i].start, pdev->resource[i].end - pdev->resource[i].start + 1); if (!ebi2_base) { printk(KERN_ERR "ebi2_base ioremap failed!\n"); return -ENOMEM; } ebi2_lcd_cfg0 = (void *)(ebi2_base + 0x20); ebi2_lcd_cfg1 = (void *)(ebi2_base + 0x24); } else if (!strncmp(pdev->resource[i].name, "lcd01", 5)) { lcd01_base = ioremap(pdev->resource[i].start, pdev->resource[i].end - pdev->resource[i].start + 1); if (!lcd01_base) { printk(KERN_ERR "lcd01_base ioremap failed!\n"); return -ENOMEM; } } else if (!strncmp(pdev->resource[i].name, "lcd02", 5)) { lcd02_base = ioremap(pdev->resource[i].start, pdev->resource[i].end - pdev->resource[i].start + 1); if (!lcd02_base) { printk(KERN_ERR "lcd02_base ioremap failed!\n"); return -ENOMEM; } } } ebi2_lcd_resource_initialized = 1; return 0; } if (!ebi2_lcd_resource_initialized) return -EPERM; mfd = platform_get_drvdata(pdev); if (!mfd) return -ENODEV; if (mfd->key != MFD_KEY) return -EINVAL; if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST) return -ENOMEM; if (ebi2_base == NULL) return -ENOMEM; mdp_dev = platform_device_alloc("mdp", pdev->id); if (!mdp_dev) return -ENOMEM; /* link to the latest pdev */ mfd->pdev = mdp_dev; mfd->dest = DISPLAY_LCD; /* add panel data */ if (platform_device_add_data (mdp_dev, pdev->dev.platform_data, sizeof(struct msm_fb_panel_data))) { printk(KERN_ERR "ebi2_lcd_probe: platform_device_add_data failed!\n"); platform_device_put(mdp_dev); return -ENOMEM; } /* data chain */ pdata = mdp_dev->dev.platform_data; pdata->on = panel_next_on; pdata->off = panel_next_off; pdata->next = pdev; /* get/set panel specific fb info */ mfd->panel_info = pdata->panel_info; if (mfd->panel_info.bpp == 24) mfd->fb_imgType = MDP_RGB_888; else mfd->fb_imgType = MDP_RGB_565; /* config msm ebi2 lcd register */ if (mfd->panel_info.pdest == DISPLAY_1) { outp32(ebi2_base, (inp32(ebi2_base) & (~(EBI2_PRIM_LCD_CLR))) | EBI2_PRIM_LCD_SEL); /* * current design has one set of cfg0/1 register to control * both EBI2 channels. so, we're using the PRIM channel to * configure both. */ outp32(ebi2_lcd_cfg0, mfd->panel_info.wait_cycle); if (mfd->panel_info.bpp == 18) outp32(ebi2_lcd_cfg1, 0x01000000); else outp32(ebi2_lcd_cfg1, 0x0); } else { #ifdef DEBUG_EBI2_LCD /* * confliting with QCOM SURF FPGA CS. * OEM should enable below for their CS mapping */ outp32(ebi2_base, (inp32(ebi2_base)&(~(EBI2_SECD_LCD_CLR))) |EBI2_SECD_LCD_SEL); #endif } /* * map cs (chip select) address */ if (mfd->panel_info.pdest == DISPLAY_1) { mfd->cmd_port = lcd01_base; mfd->data_port = (void *)((uint32) mfd->cmd_port + EBI2_PRIM_LCD_RS_PIN); mfd->data_port_phys = (void *)(LCD_PRIM_BASE_PHYS + EBI2_PRIM_LCD_RS_PIN); } else { mfd->cmd_port = lcd01_base; mfd->data_port = (void *)((uint32) mfd->cmd_port + EBI2_SECD_LCD_RS_PIN); mfd->data_port_phys = (void *)(LCD_SECD_BASE_PHYS + EBI2_SECD_LCD_RS_PIN); } /* * set driver data */ platform_set_drvdata(mdp_dev, mfd); /* * register in mdp driver */ rc = platform_device_add(mdp_dev); if (rc) { goto ebi2_lcd_probe_err; } #if 0 /* FIXME: */ pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); #endif pdev_list[pdev_list_cnt++] = pdev; return 0; ebi2_lcd_probe_err: platform_device_put(mdp_dev); return rc; }
static int ucb1400_core_probe(struct device *dev) { int err; struct ucb1400 *ucb; struct ucb1400_ts ucb_ts; struct ucb1400_gpio ucb_gpio; struct snd_ac97 *ac97; memset(&ucb_ts, 0, sizeof(ucb_ts)); memset(&ucb_gpio, 0, sizeof(ucb_gpio)); ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL); if (!ucb) { err = -ENOMEM; goto err; } dev_set_drvdata(dev, ucb); ac97 = to_ac97_t(dev); ucb_ts.id = ucb1400_reg_read(ac97, UCB_ID); if (ucb_ts.id != UCB_ID_1400) { err = -ENODEV; goto err0; } ucb_gpio.ac97 = ac97; ucb->ucb1400_gpio = platform_device_alloc("ucb1400_gpio", -1); if (!ucb->ucb1400_gpio) { err = -ENOMEM; goto err0; } err = platform_device_add_data(ucb->ucb1400_gpio, &ucb_gpio, sizeof(ucb_gpio)); if (err) goto err1; err = platform_device_add(ucb->ucb1400_gpio); if (err) goto err1; ucb_ts.ac97 = ac97; ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1); if (!ucb->ucb1400_ts) { err = -ENOMEM; goto err2; } err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts, sizeof(ucb_ts)); if (err) goto err3; err = platform_device_add(ucb->ucb1400_ts); if (err) goto err3; return 0; err3: platform_device_put(ucb->ucb1400_ts); err2: platform_device_unregister(ucb->ucb1400_gpio); err1: platform_device_put(ucb->ucb1400_gpio); err0: kfree(ucb); err: return err; }
static int mxs_saif_probe(struct platform_device *pdev) { struct resource *iores, *dmares; struct mxs_saif *saif; struct mxs_saif_platform_data *pdata; int ret = 0; if (pdev->id >= ARRAY_SIZE(mxs_saif)) return -EINVAL; saif = kzalloc(sizeof(*saif), GFP_KERNEL); if (!saif) return -ENOMEM; mxs_saif[pdev->id] = saif; saif->id = pdev->id; pdata = pdev->dev.platform_data; if (pdata && !pdata->master_mode) { saif->master_id = pdata->master_id; if (saif->master_id < 0 || saif->master_id >= ARRAY_SIZE(mxs_saif) || saif->master_id == saif->id) { dev_err(&pdev->dev, "get wrong master id\n"); return -EINVAL; } } else { saif->master_id = saif->id; } saif->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(saif->clk)) { ret = PTR_ERR(saif->clk); dev_err(&pdev->dev, "Cannot get the clock: %d\n", ret); goto failed_clk; } iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!iores) { ret = -ENODEV; dev_err(&pdev->dev, "failed to get io resource: %d\n", ret); goto failed_get_resource; } if (!request_mem_region(iores->start, resource_size(iores), "mxs-saif")) { dev_err(&pdev->dev, "request_mem_region failed\n"); ret = -EBUSY; goto failed_get_resource; } saif->base = ioremap(iores->start, resource_size(iores)); if (!saif->base) { dev_err(&pdev->dev, "ioremap failed\n"); ret = -ENODEV; goto failed_ioremap; } dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); if (!dmares) { ret = -ENODEV; dev_err(&pdev->dev, "failed to get dma resource: %d\n", ret); goto failed_ioremap; } saif->dma_param.chan_num = dmares->start; saif->irq = platform_get_irq(pdev, 0); if (saif->irq < 0) { ret = saif->irq; dev_err(&pdev->dev, "failed to get irq resource: %d\n", ret); goto failed_get_irq1; } saif->dev = &pdev->dev; ret = request_irq(saif->irq, mxs_saif_irq, 0, "mxs-saif", saif); if (ret) { dev_err(&pdev->dev, "failed to request irq\n"); goto failed_get_irq1; } saif->dma_param.chan_irq = platform_get_irq(pdev, 1); if (saif->dma_param.chan_irq < 0) { ret = saif->dma_param.chan_irq; dev_err(&pdev->dev, "failed to get dma irq resource: %d\n", ret); goto failed_get_irq2; } platform_set_drvdata(pdev, saif); ret = snd_soc_register_dai(&pdev->dev, &mxs_saif_dai); if (ret) { dev_err(&pdev->dev, "register DAI failed\n"); goto failed_register; } saif->soc_platform_pdev = platform_device_alloc( "mxs-pcm-audio", pdev->id); if (!saif->soc_platform_pdev) { ret = -ENOMEM; goto failed_pdev_alloc; } platform_set_drvdata(saif->soc_platform_pdev, saif); ret = platform_device_add(saif->soc_platform_pdev); if (ret) { dev_err(&pdev->dev, "failed to add soc platform device\n"); goto failed_pdev_add; } return 0; failed_pdev_add: platform_device_put(saif->soc_platform_pdev); failed_pdev_alloc: snd_soc_unregister_dai(&pdev->dev); failed_register: failed_get_irq2: free_irq(saif->irq, saif); failed_get_irq1: iounmap(saif->base); failed_ioremap: release_mem_region(iores->start, resource_size(iores)); failed_get_resource: clk_put(saif->clk); failed_clk: kfree(saif); return ret; }
static int msm8960_configure_headset_mic_gpios(void) { int ret; struct pm_gpio param = { .direction = PM_GPIO_DIR_OUT, .output_buffer = PM_GPIO_OUT_BUF_CMOS, .output_value = 1, .pull = PM_GPIO_PULL_NO, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_MED, .function = PM_GPIO_FUNC_NORMAL, }; ret = gpio_request(PM8921_GPIO_PM_TO_SYS(23), "AV_SWITCH"); if (ret) { pr_err("%s: Failed to request gpio %d\n", __func__, PM8921_GPIO_PM_TO_SYS(23)); return ret; } ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(23), ¶m); if (ret) pr_err("%s: Failed to configure gpio %d\n", __func__, PM8921_GPIO_PM_TO_SYS(23)); else gpio_direction_output(PM8921_GPIO_PM_TO_SYS(23), 0); ret = gpio_request(PM8921_GPIO_PM_TO_SYS(35), "US_EURO_SWITCH"); if (ret) { pr_err("%s: Failed to request gpio %d\n", __func__, PM8921_GPIO_PM_TO_SYS(35)); gpio_free(PM8921_GPIO_PM_TO_SYS(23)); return ret; } ret = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(35), ¶m); if (ret) pr_err("%s: Failed to configure gpio %d\n", __func__, PM8921_GPIO_PM_TO_SYS(35)); else gpio_direction_output(PM8921_GPIO_PM_TO_SYS(35), 0); return 0; } static void msm8960_free_headset_mic_gpios(void) { if (msm8960_headset_gpios_configured) { gpio_free(PM8921_GPIO_PM_TO_SYS(23)); gpio_free(PM8921_GPIO_PM_TO_SYS(35)); } } static int __init msm8960_audio_init(void) { int ret; if (!cpu_is_msm8960() && !cpu_is_msm8930()) { pr_err("%s: Not the right machine type\n", __func__); return -ENODEV ; } mbhc_cfg.calibration = def_tabla_mbhc_cal(); if (!mbhc_cfg.calibration) { pr_err("Calibration data allocation failed\n"); return -ENOMEM; } msm8960_snd_device = platform_device_alloc("soc-audio", 0); if (!msm8960_snd_device) { pr_err("Platform device allocation failed\n"); kfree(mbhc_cfg.calibration); return -ENOMEM; } memcpy(msm8960_dai, msm8960_dai_common, sizeof(msm8960_dai_common)); memcpy(msm8960_dai + ARRAY_SIZE(msm8960_dai_common), msm8960_dai_delta_tabla2x, sizeof(msm8960_dai_delta_tabla2x)); platform_set_drvdata(msm8960_snd_device, &snd_soc_card_msm8960); ret = platform_device_add(msm8960_snd_device); if (ret) { platform_device_put(msm8960_snd_device); kfree(mbhc_cfg.calibration); return ret; } msm8960_snd_tabla1x_device = platform_device_alloc("soc-audio", 1); if (!msm8960_snd_tabla1x_device) { pr_err("Platform device allocation failed\n"); kfree(mbhc_cfg.calibration); return -ENOMEM; } memcpy(msm8960_tabla1x_dai, msm8960_dai_common, sizeof(msm8960_dai_common)); memcpy(msm8960_tabla1x_dai + ARRAY_SIZE(msm8960_dai_common), msm8960_dai_delta_tabla1x, sizeof(msm8960_dai_delta_tabla1x)); platform_set_drvdata(msm8960_snd_tabla1x_device, &snd_soc_tabla1x_card_msm8960); ret = platform_device_add(msm8960_snd_tabla1x_device); if (ret) { platform_device_put(msm8960_snd_tabla1x_device); kfree(mbhc_cfg.calibration); return -ENOMEM; return ret; } if (msm8960_configure_headset_mic_gpios()) { pr_err("%s Fail to configure headset mic gpios\n", __func__); msm8960_headset_gpios_configured = 0; } else msm8960_headset_gpios_configured = 1; mutex_init(&cdc_mclk_mutex); return ret; }
static int omap2430_probe(struct platform_device *pdev) { struct resource musb_resources[3]; struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); struct omap_musb_board_data *data; struct platform_device *musb; struct omap2430_glue *glue; struct device_node *np = pdev->dev.of_node; struct musb_hdrc_config *config; int ret = -ENOMEM; glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); if (!glue) { dev_err(&pdev->dev, "failed to allocate glue context\n"); goto err0; } musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); if (!musb) { dev_err(&pdev->dev, "failed to allocate musb device\n"); goto err0; } musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &omap2430_dmamask; musb->dev.coherent_dma_mask = omap2430_dmamask; glue->dev = &pdev->dev; glue->musb = musb; glue->status = OMAP_MUSB_UNKNOWN; glue->control_otghs = ERR_PTR(-ENODEV); if (np) { struct device_node *control_node; struct platform_device *control_pdev; pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { dev_err(&pdev->dev, "failed to allocate musb platform data\n"); goto err2; } data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) { dev_err(&pdev->dev, "failed to allocate musb board data\n"); goto err2; } config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL); if (!config) { dev_err(&pdev->dev, "failed to allocate musb hdrc config\n"); goto err2; } of_property_read_u32(np, "mode", (u32 *)&pdata->mode); of_property_read_u32(np, "interface-type", (u32 *)&data->interface_type); of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps); of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); of_property_read_u32(np, "power", (u32 *)&pdata->power); config->multipoint = of_property_read_bool(np, "multipoint"); pdata->board_data = data; pdata->config = config; control_node = of_parse_phandle(np, "ctrl-module", 0); if (control_node) { control_pdev = of_find_device_by_node(control_node); if (!control_pdev) { dev_err(&pdev->dev, "Failed to get control device\n"); ret = -EINVAL; goto err2; } glue->control_otghs = &control_pdev->dev; } } pdata->platform_ops = &omap2430_ops; platform_set_drvdata(pdev, glue); /* * REVISIT if we ever have two instances of the wrapper, we will be * in big trouble */ _glue = glue; INIT_WORK(&glue->omap_musb_mailbox_work, omap_musb_mailbox_work); memset(musb_resources, 0x00, sizeof(*musb_resources) * ARRAY_SIZE(musb_resources)); musb_resources[0].name = pdev->resource[0].name; musb_resources[0].start = pdev->resource[0].start; musb_resources[0].end = pdev->resource[0].end; musb_resources[0].flags = pdev->resource[0].flags; musb_resources[1].name = pdev->resource[1].name; musb_resources[1].start = pdev->resource[1].start; musb_resources[1].end = pdev->resource[1].end; musb_resources[1].flags = pdev->resource[1].flags; musb_resources[2].name = pdev->resource[2].name; musb_resources[2].start = pdev->resource[2].start; musb_resources[2].end = pdev->resource[2].end; musb_resources[2].flags = pdev->resource[2].flags; ret = platform_device_add_resources(musb, musb_resources, ARRAY_SIZE(musb_resources)); if (ret) { dev_err(&pdev->dev, "failed to add resources\n"); goto err2; } ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); if (ret) { dev_err(&pdev->dev, "failed to add platform_data\n"); goto err2; } pm_runtime_enable(&pdev->dev); ret = platform_device_add(musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device\n"); goto err2; } return 0; err2: platform_device_put(musb); err0: return ret; }
static int __init smsc47b397_device_add(unsigned short address) { struct resource res = { .start = address, .end = address + SMSC_EXTENT - 1, .name = DRVNAME, .flags = IORESOURCE_IO, }; int err; err = acpi_check_resource_conflict(&res); if (err) goto exit; pdev = platform_device_alloc(DRVNAME, address); if (!pdev) { err = -ENOMEM; pr_err("Device allocation failed\n"); goto exit; } err = platform_device_add_resources(pdev, &res, 1); if (err) { pr_err("Device resource addition failed (%d)\n", err); goto exit_device_put; } err = platform_device_add(pdev); if (err) { pr_err("Device addition failed (%d)\n", err); goto exit_device_put; } return 0; exit_device_put: platform_device_put(pdev); exit: return err; } static int __init smsc47b397_find(void) { u8 id, rev; char *name; unsigned short addr; superio_enter(); id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); switch (id) { case 0x81: name = "SCH5307-NS"; break; case 0x6f: name = "LPC47B397-NC"; break; case 0x85: case 0x8c: name = "SCH5317"; break; default: superio_exit(); return -ENODEV; } rev = superio_inb(SUPERIO_REG_DEVREV); superio_select(SUPERIO_REG_LD8); addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) | superio_inb(SUPERIO_REG_BASE_LSB); pr_info("found SMSC %s (base address 0x%04x, revision %u)\n", name, addr, rev); superio_exit(); return addr; }
static int dsps_create_musb_pdev(struct dsps_glue *glue, struct platform_device *parent) { struct musb_hdrc_platform_data pdata; struct resource resources[2]; struct resource *res; struct device *dev = &parent->dev; struct musb_hdrc_config *config; struct platform_device *musb; struct device_node *dn = parent->dev.of_node; int ret; memset(resources, 0, sizeof(resources)); res = platform_get_resource_byname(parent, IORESOURCE_MEM, "mc"); if (!res) { dev_err(dev, "failed to get memory.\n"); return -EINVAL; } resources[0] = *res; res = platform_get_resource_byname(parent, IORESOURCE_IRQ, "mc"); if (!res) { dev_err(dev, "failed to get irq.\n"); return -EINVAL; } resources[1] = *res; /* allocate the child platform device */ musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); if (!musb) { dev_err(dev, "failed to allocate musb device\n"); return -ENOMEM; } musb->dev.parent = dev; musb->dev.dma_mask = &musb_dmamask; musb->dev.coherent_dma_mask = musb_dmamask; musb->dev.of_node = of_node_get(dn); glue->musb = musb; ret = platform_device_add_resources(musb, resources, ARRAY_SIZE(resources)); if (ret) { dev_err(dev, "failed to add resources\n"); goto err; } config = devm_kzalloc(&parent->dev, sizeof(*config), GFP_KERNEL); if (!config) { dev_err(dev, "failed to allocate musb hdrc config\n"); ret = -ENOMEM; goto err; } pdata.config = config; pdata.platform_ops = &dsps_ops; config->num_eps = get_int_prop(dn, "mentor,num-eps"); config->ram_bits = get_int_prop(dn, "mentor,ram-bits"); config->host_port_deassert_reset_at_resume = 1; pdata.mode = get_musb_port_mode(dev); /* DT keeps this entry in mA, musb expects it as per USB spec */ pdata.power = get_int_prop(dn, "mentor,power") / 2; config->multipoint = of_property_read_bool(dn, "mentor,multipoint"); ret = platform_device_add_data(musb, &pdata, sizeof(pdata)); if (ret) { dev_err(dev, "failed to add platform_data\n"); goto err; } ret = platform_device_add(musb); if (ret) { dev_err(dev, "failed to register musb device\n"); goto err; } return 0; err: platform_device_put(musb); return ret; }
static int wl1271_probe(struct spi_device *spi) { struct wl12xx_spi_glue *glue; struct wlcore_platdev_data pdev_data; struct resource res[1]; int ret; memset(&pdev_data, 0x00, sizeof(pdev_data)); pdev_data.if_ops = &spi_ops; glue = devm_kzalloc(&spi->dev, sizeof(*glue), GFP_KERNEL); if (!glue) { dev_err(&spi->dev, "can't allocate glue\n"); return -ENOMEM; } glue->dev = &spi->dev; spi_set_drvdata(spi, glue); /* This is the only SPI value that we need to set here, the rest * comes from the board-peripherals file */ spi->bits_per_word = 32; glue->reg = devm_regulator_get(&spi->dev, "vwlan"); if (PTR_ERR(glue->reg) == -EPROBE_DEFER) return -EPROBE_DEFER; if (IS_ERR(glue->reg)) { dev_err(glue->dev, "can't get regulator\n"); return PTR_ERR(glue->reg); } ret = wlcore_probe_of(spi, glue, &pdev_data); if (IS_ERR_VALUE(ret)) { dev_err(glue->dev, "can't get device tree parameters (%d)\n", ret); return ret; } ret = spi_setup(spi); if (ret < 0) { dev_err(glue->dev, "spi_setup failed\n"); return ret; } glue->core = platform_device_alloc("wl12xx", PLATFORM_DEVID_AUTO); if (!glue->core) { dev_err(glue->dev, "can't allocate platform_device\n"); return -ENOMEM; } glue->core->dev.parent = &spi->dev; memset(res, 0x00, sizeof(res)); res[0].start = spi->irq; res[0].flags = IORESOURCE_IRQ | irq_get_trigger_type(spi->irq); res[0].name = "irq"; ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res)); if (ret) { dev_err(glue->dev, "can't add resources\n"); goto out_dev_put; } ret = platform_device_add_data(glue->core, &pdev_data, sizeof(pdev_data)); if (ret) { dev_err(glue->dev, "can't add platform data\n"); goto out_dev_put; } ret = platform_device_add(glue->core); if (ret) { dev_err(glue->dev, "can't register platform device\n"); goto out_dev_put; } return 0; out_dev_put: platform_device_put(glue->core); return ret; }
static int diag_bridge_probe(struct usb_interface *ifc, const struct usb_device_id *id) { struct diag_bridge *dev; struct usb_host_interface *ifc_desc; struct usb_endpoint_descriptor *ep_desc; int i; int ret = -ENOMEM; __u8 ifc_num; pr_debug("id:%lu", id->driver_info); ifc_num = ifc->cur_altsetting->desc.bInterfaceNumber; /* is this interface supported ? */ if (ifc_num != id->driver_info) return -ENODEV; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) { pr_err("unable to allocate dev"); return -ENOMEM; } dev->pdev = platform_device_alloc("diag_bridge", -1); if (!dev->pdev) { pr_err("unable to allocate platform device"); kfree(dev); return -ENOMEM; } __dev = dev; dev->udev = usb_get_dev(interface_to_usbdev(ifc)); dev->ifc = ifc; kref_init(&dev->kref); mutex_init(&dev->ifc_mutex); init_usb_anchor(&dev->submitted); ifc_desc = ifc->cur_altsetting; for (i = 0; i < ifc_desc->desc.bNumEndpoints; i++) { ep_desc = &ifc_desc->endpoint[i].desc; #ifdef LG_FW_HSIC_EMS_DEBUG /* secheol.pyo - endpoint logging */ printk("[%s]for ++, i= %d, ifc_desc->desc.bNumEndpoints = %d\n", __func__,i, ifc_desc->desc.bNumEndpoints); #endif /* secheol.pyo - endpoint logging */ if (!dev->in_epAddr && usb_endpoint_is_bulk_in(ep_desc)) dev->in_epAddr = ep_desc->bEndpointAddress; if (!dev->out_epAddr && usb_endpoint_is_bulk_out(ep_desc)) dev->out_epAddr = ep_desc->bEndpointAddress; #ifdef LG_FW_HSIC_EMS_DEBUG /* secheol.pyo - endpoint logging */ printk("[%s]for --, i= %d, dev->in_epAddr = %d, dev->out_epAddr = %d \n", __func__,i, dev->in_epAddr, dev->out_epAddr); #endif/* secheol.pyo - endpoint logging */ } if (!(dev->in_epAddr && dev->out_epAddr)) { pr_err("could not find bulk in and bulk out endpoints"); ret = -ENODEV; goto error; } usb_set_intfdata(ifc, dev); diag_bridge_debugfs_init(); platform_device_add(dev->pdev); dev_dbg(&dev->ifc->dev, "%s: complete\n", __func__); return 0; error: if (dev) kref_put(&dev->kref, diag_bridge_delete); return ret; }
static int ux500_probe(struct platform_device *pdev) { struct resource musb_resources[2]; struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); struct device_node *np = pdev->dev.of_node; struct platform_device *musb; struct ux500_glue *glue; struct clk *clk; int ret = -ENOMEM; if (!pdata) { if (np) { pdata = ux500_of_probe(pdev, np); if (!pdata) goto err0; pdev->dev.platform_data = pdata; } else { dev_err(&pdev->dev, "no pdata or device tree found\n"); goto err0; } } glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); if (!glue) goto err0; musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); if (!musb) { dev_err(&pdev->dev, "failed to allocate musb device\n"); goto err0; } clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { dev_err(&pdev->dev, "failed to get clock\n"); ret = PTR_ERR(clk); goto err1; } ret = clk_prepare_enable(clk); if (ret) { dev_err(&pdev->dev, "failed to enable clock\n"); goto err1; } musb->dev.parent = &pdev->dev; musb->dev.dma_mask = &pdev->dev.coherent_dma_mask; musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; glue->dev = &pdev->dev; glue->musb = musb; glue->clk = clk; pdata->platform_ops = &ux500_ops; pdata->config = &ux500_musb_hdrc_config; platform_set_drvdata(pdev, glue); memset(musb_resources, 0x00, sizeof(*musb_resources) * ARRAY_SIZE(musb_resources)); musb_resources[0].name = pdev->resource[0].name; musb_resources[0].start = pdev->resource[0].start; musb_resources[0].end = pdev->resource[0].end; musb_resources[0].flags = pdev->resource[0].flags; musb_resources[1].name = pdev->resource[1].name; musb_resources[1].start = pdev->resource[1].start; musb_resources[1].end = pdev->resource[1].end; musb_resources[1].flags = pdev->resource[1].flags; ret = platform_device_add_resources(musb, musb_resources, ARRAY_SIZE(musb_resources)); if (ret) { dev_err(&pdev->dev, "failed to add resources\n"); goto err2; } ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); if (ret) { dev_err(&pdev->dev, "failed to add platform_data\n"); goto err2; } ret = platform_device_add(musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device\n"); goto err2; } return 0; err2: clk_disable_unprepare(clk); err1: platform_device_put(musb); err0: return ret; }
static int mddi_probe(struct platform_device *pdev) { struct msm_fb_data_type *mfd; struct platform_device *mdp_dev = NULL; struct msm_fb_panel_data *pdata = NULL; int rc; resource_size_t size ; u32 clk_rate; if ((pdev->id == 0) && (pdev->num_resources >= 0)) { mddi_pdata = pdev->dev.platform_data; size = resource_size(&pdev->resource[0]); msm_pmdh_base = ioremap(pdev->resource[0].start, size); MSM_FB_INFO("primary mddi base phy_addr = 0x%x virt = 0x%x\n", pdev->resource[0].start, (int) msm_pmdh_base); if (unlikely(!msm_pmdh_base)) return -ENOMEM; if (mddi_pdata && mddi_pdata->mddi_power_save) mddi_pdata->mddi_power_save(1); mddi_resource_initialized = 1; return 0; } if (!mddi_resource_initialized) return -EPERM; mfd = platform_get_drvdata(pdev); if (!mfd) return -ENODEV; if (mfd->key != MFD_KEY) return -EINVAL; if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST) return -ENOMEM; mdp_dev = platform_device_alloc("mdp", pdev->id); if (!mdp_dev) return -ENOMEM; /* * link to the latest pdev */ mfd->pdev = mdp_dev; mfd->dest = DISPLAY_LCD; /* * alloc panel device data */ if (platform_device_add_data (mdp_dev, pdev->dev.platform_data, sizeof(struct msm_fb_panel_data))) { printk(KERN_ERR "mddi_probe: platform_device_add_data failed!\n"); platform_device_put(mdp_dev); return -ENOMEM; } /* * data chain */ pdata = mdp_dev->dev.platform_data; pdata->on = mddi_on; pdata->off = mddi_off; pdata->next = pdev; /* * get/set panel specific fb info */ mfd->panel_info = pdata->panel_info; #ifdef MSMFB_FRAMEBUF_32 if (mfd->index == 0) mfd->fb_imgType = MDP_RGBA_8888; /* primary */ else mfd->fb_imgType = MDP_RGB_565; /* secondary */ #else mfd->fb_imgType = MDP_RGB_565; #endif clk_rate = mfd->panel_info.clk_max; if (mddi_pdata && mddi_pdata->mddi_sel_clk && mddi_pdata->mddi_sel_clk(&clk_rate)) printk(KERN_ERR "%s: can't select mddi io clk targate rate = %d\n", __func__, clk_rate); if (clk_set_max_rate(mddi_clk, clk_rate) < 0) printk(KERN_ERR "%s: clk_set_max_rate failed\n", __func__); mfd->panel_info.clk_rate = mfd->panel_info.clk_min; if (!mddi_client_type) mddi_client_type = mfd->panel_info.lcd.rev; else if (!mfd->panel_info.lcd.rev) printk(KERN_ERR "%s: mddi client is trying to revert back to type 1 !!!\n", __func__); /* * set driver data */ platform_set_drvdata(mdp_dev, mfd); /* * register in mdp driver */ rc = platform_device_add(mdp_dev); if (rc) goto mddi_probe_err; pdev_list[pdev_list_cnt++] = pdev; #ifdef CONFIG_HAS_EARLYSUSPEND mfd->mddi_early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB; mfd->mddi_early_suspend.suspend = mddi_early_suspend; mfd->mddi_early_suspend.resume = mddi_early_resume; register_early_suspend(&mfd->mddi_early_suspend); #endif return 0; mddi_probe_err: platform_device_put(mdp_dev); return rc; }
static int __init msi_init(void) { int ret; if (acpi_disabled) return -ENODEV; if (!force && !dmi_check_system(msi_dmi_table)) return -ENODEV; if (auto_brightness < 0 || auto_brightness > 2) return -EINVAL; /* Register backlight stuff */ msibl_device = backlight_device_register("msi-laptop-bl", NULL, NULL, &msibl_ops); if (IS_ERR(msibl_device)) return PTR_ERR(msibl_device); msibl_device->props.max_brightness = MSI_LCD_LEVEL_MAX-1, ret = platform_driver_register(&msipf_driver); if (ret) goto fail_backlight; /* Register platform stuff */ msipf_device = platform_device_alloc("msi-laptop-pf", -1); if (!msipf_device) { ret = -ENOMEM; goto fail_platform_driver; } ret = platform_device_add(msipf_device); if (ret) goto fail_platform_device1; ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group); if (ret) goto fail_platform_device2; /* Disable automatic brightness control by default because * this module was probably loaded to do brightness control in * software. */ if (auto_brightness != 2) set_auto_brightness(auto_brightness); printk(KERN_INFO "msi-laptop: driver "MSI_DRIVER_VERSION" successfully loaded.\n"); return 0; fail_platform_device2: platform_device_del(msipf_device); fail_platform_device1: platform_device_put(msipf_device); fail_platform_driver: platform_driver_unregister(&msipf_driver); fail_backlight: backlight_device_unregister(msibl_device); return ret; }
static int __init fighter_audio_init(void) { int ret = 0, rc = 0; #ifdef CONFIG_AUDIO_USAGE_FOR_POWER_CONSUMPTION int retval = 0; #endif struct pm_gpio param = { .direction = PM_GPIO_DIR_OUT, .output_buffer = PM_GPIO_OUT_BUF_CMOS, .output_value = 0, .pull = PM_GPIO_PULL_NO, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_MED, .function = PM_GPIO_FUNC_NORMAL, }; pr_debug("%s", __func__); msm8960_snd_device = platform_device_alloc("soc-audio", 0); if (!msm8960_snd_device) { pr_aud_err("%s, Platform device allocation failed\n", __func__); return -ENOMEM; } platform_set_drvdata(msm8960_snd_device, &snd_soc_card_msm8960); ret = platform_device_add(msm8960_snd_device); if (ret) { pr_aud_err("%s, Platform device add failed\n", __func__); platform_device_put(msm8960_snd_device); return ret; } #ifdef CONFIG_AUDIO_USAGE_FOR_POWER_CONSUMPTION /* Create two audio status file nodes, audio_speaker_t and * audio_headset_t under /sys/audio_stats/ */ if (audio_stat_kobj == NULL) { audio_stat_kobj = kobject_create_and_add("audio_stats", NULL); retval = sysfs_create_file(audio_stat_kobj, attrs[0]); if (!retval) { pr_err("Speaker file node creation failed under kobject\n"); } retval = sysfs_create_file(audio_stat_kobj, attrs[1]); if (!retval) { pr_err("Headset file node creation failed under kobject\n"); } } #endif rc = gpio_request(PM8921_GPIO_PM_TO_SYS(FIGHTER_AUD_AMP_EN), "tpa2051_en"); rc = pm8xxx_gpio_config(PM8921_GPIO_PM_TO_SYS(FIGHTER_AUD_AMP_EN), ¶m); if (rc < 0) pr_aud_err("failed to configure tpa2051_en gpio\n"); gpio_tlmm_config(msm_2051_gpio[0], GPIO_CFG_ENABLE); gpio_tlmm_config(msm_2051_gpio[1], GPIO_CFG_ENABLE); htc_8960_register_q6asm_ops(&qops); htc_8960_register_pcm_routing_ops(&rops); acoustic_register_ops(&acoustic); return ret; } late_initcall(fighter_audio_init); static void __exit fighter_audio_exit(void) { pr_debug("%s", __func__); platform_device_unregister(msm8960_snd_device); }
int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink, struct wm8350_led_platform_data *pdata) { struct wm8350_led *led; struct platform_device *pdev; int ret; if (lednum >= ARRAY_SIZE(wm8350->pmic.led) || lednum < 0) { dev_err(wm8350->dev, "Invalid LED index %d\n", lednum); return -ENODEV; } led = &wm8350->pmic.led[lednum]; if (led->pdev) { dev_err(wm8350->dev, "LED %d already allocated\n", lednum); return -EINVAL; } pdev = platform_device_alloc("wm8350-led", lednum); if (pdev == NULL) { dev_err(wm8350->dev, "Failed to allocate LED %d\n", lednum); return -ENOMEM; } led->isink_consumer.dev = &pdev->dev; led->isink_consumer.supply = "led_isink"; led->isink_init.num_consumer_supplies = 1; led->isink_init.consumer_supplies = &led->isink_consumer; led->isink_init.constraints.min_uA = 0; led->isink_init.constraints.max_uA = pdata->max_uA; led->isink_init.constraints.valid_ops_mask = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS; led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL; ret = wm8350_register_regulator(wm8350, isink, &led->isink_init); if (ret != 0) { platform_device_put(pdev); return ret; } led->dcdc_consumer.dev = &pdev->dev; led->dcdc_consumer.supply = "led_vcc"; led->dcdc_init.num_consumer_supplies = 1; led->dcdc_init.consumer_supplies = &led->dcdc_consumer; led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL; led->dcdc_init.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS; ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init); if (ret != 0) { platform_device_put(pdev); return ret; } switch (isink) { case WM8350_ISINK_A: wm8350->pmic.isink_A_dcdc = dcdc; break; case WM8350_ISINK_B: wm8350->pmic.isink_B_dcdc = dcdc; break; } pdev->dev.platform_data = pdata; pdev->dev.parent = wm8350->dev; ret = platform_device_add(pdev); if (ret != 0) { dev_err(wm8350->dev, "Failed to register LED %d: %d\n", lednum, ret); platform_device_put(pdev); return ret; } led->pdev = pdev; return 0; }
static int keyreset_probe(struct platform_device *pdev) { int ret = -ENOMEM; struct keycombo_platform_data *pdata_child; struct keyreset_platform_data *pdata; int up_size = 0, down_size = 0, size; int key, *keyp; struct keyreset_state *state; KEY_LOGI("%s: +++\n", __func__); if (pdev->dev.of_node) { pdata = kzalloc(sizeof(struct keyreset_platform_data), GFP_KERNEL); if (!pdata) { KEY_LOGE("[KEY] fail to allocate keyreset_platform_data\n"); ret = -ENOMEM; goto err_get_pdata_fail; } ret = keyreset_parse_dt(pdev->dev.of_node, pdata); if (ret < 0) { KEY_LOGE("[KEY] keyreset_parse_dt fail\n"); ret = -ENOMEM; goto err_parse_fail; } } else { pdata = pdev->dev.platform_data; if(!pdata) { KEY_LOGE("[KEY] keyreset_platform_data does not exist\n"); ret = -ENOMEM; goto err_get_pdata_fail; } } state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL); if (!state) return -ENOMEM; state->pdev_child = platform_device_alloc(KEYCOMBO_NAME, PLATFORM_DEVID_AUTO); if (!state->pdev_child) return -ENOMEM; state->pdev_child->dev.parent = &pdev->dev; keyp = pdata->keys_down; while ((key = *keyp++)) { if (key >= KEY_MAX) continue; down_size++; } if (pdata->keys_up) { keyp = pdata->keys_up; while ((key = *keyp++)) { if (key >= KEY_MAX) continue; up_size++; } } size = sizeof(struct keycombo_platform_data); pdata_child = devm_kzalloc(&pdev->dev, sizeof(struct keycombo_platform_data), GFP_KERNEL); if (!pdata_child) goto error; pdata_child->keys_down = devm_kzalloc(&pdev->dev, sizeof(uint32_t) * (down_size + 1), GFP_KERNEL); if (!pdata_child->keys_down) goto error; memcpy(pdata_child->keys_down, pdata->keys_down, sizeof(uint32_t) * down_size); if (!pdata_child->keys_down) goto error; if (up_size > 0) { pdata_child->keys_up = devm_kzalloc(&pdev->dev, sizeof(uint32_t) * (up_size + 1), GFP_KERNEL); if (!pdata_child->keys_up) goto error; memcpy(pdata_child->keys_up, pdata->keys_up, sizeof(uint32_t) * up_size); if (!pdata_child->keys_up) goto error; } state->reset_fn = pdata->reset_fn; pdata_child->key_down_fn = do_reset_fn; pdata_child->priv = state; pdata_child->key_down_delay = pdata->key_down_delay; ret = platform_device_add_data(state->pdev_child, pdata_child, size); if (ret) goto error; platform_set_drvdata(pdev, state); KEY_LOGI("%s: ---\n", __func__); return platform_device_add(state->pdev_child); error: platform_device_put(state->pdev_child); err_parse_fail: if (pdev->dev.of_node) kfree(pdata); err_get_pdata_fail: return ret; }
static int __init f71805f_device_add(unsigned short address) { struct resource res = { .start = address, .end = address + REGION_LENGTH - 1, .flags = IORESOURCE_IO, }; int err; pdev = platform_device_alloc(DRVNAME, address); if (!pdev) { err = -ENOMEM; printk(KERN_ERR DRVNAME ": Device allocation failed\n"); goto exit; } res.name = pdev->name; err = platform_device_add_resources(pdev, &res, 1); if (err) { printk(KERN_ERR DRVNAME ": Device resource addition failed " "(%d)\n", err); goto exit_device_put; } err = platform_device_add(pdev); if (err) { printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", err); goto exit_device_put; } return 0; exit_device_put: platform_device_put(pdev); exit: return err; } static int __init f71805f_find(int sioaddr, unsigned short *address) { int err = -ENODEV; u16 devid; superio_enter(sioaddr); devid = superio_inw(sioaddr, SIO_REG_MANID); if (devid != SIO_FINTEK_ID) goto exit; devid = superio_inw(sioaddr, SIO_REG_DEVID); if (devid != SIO_F71805F_ID) { printk(KERN_INFO DRVNAME ": Unsupported Fintek device, " "skipping\n"); goto exit; } superio_select(sioaddr, F71805F_LD_HWM); if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { printk(KERN_WARNING DRVNAME ": Device not activated, " "skipping\n"); goto exit; } *address = superio_inw(sioaddr, SIO_REG_ADDR); if (*address == 0) { printk(KERN_WARNING DRVNAME ": Base address not set, " "skipping\n"); goto exit; } err = 0; printk(KERN_INFO DRVNAME ": Found F71805F chip at %#x, revision %u\n", *address, superio_inb(sioaddr, SIO_REG_DEVREV)); exit: superio_exit(sioaddr); return err; }