/* * keypad controller should be initialized in the following sequence * only, otherwise it might get into FSM stuck state. * * - Initialize keypad control parameters, like no. of rows, columns, * timing values etc., * - configure rows and column gpios pull up/down. * - set irq edge type. * - enable the keypad controller. */ static int __devinit pmic8xxx_kp_probe(struct platform_device *pdev) { const struct pm8xxx_keypad_platform_data *pdata = dev_get_platdata(&pdev->dev); const struct matrix_keymap_data *keymap_data; struct pmic8xxx_kp *kp; int rc; u8 ctrl_val; struct pm_gpio kypd_drv = { .direction = PM_GPIO_DIR_OUT, .output_buffer = PM_GPIO_OUT_BUF_OPEN_DRAIN, .output_value = 0, .pull = PM_GPIO_PULL_NO, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_LOW, .function = PM_GPIO_FUNC_1, .inv_int_pol = 1, }; struct pm_gpio kypd_sns = { .direction = PM_GPIO_DIR_IN, .pull = PM_GPIO_PULL_UP_31P5, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_NO, .function = PM_GPIO_FUNC_NORMAL, .inv_int_pol = 1, }; /* IDPower GPIO ISV add */ struct pm_gpio kypd_sns_dis_pin = { .direction = PM_GPIO_DIR_IN, .pull = PM_GPIO_PULL_UP_31P5, .vin_sel = PM_GPIO_VIN_S4, .out_strength = PM_GPIO_STRENGTH_NO, .function = PM_GPIO_FUNC_NORMAL, .inv_int_pol = 1, .disable_pin = 1, }; /* IDPower GPIO ISV add */ if (!pdata || !pdata->num_cols || !pdata->num_rows || pdata->num_cols > PM8XXX_MAX_COLS || pdata->num_rows > PM8XXX_MAX_ROWS || pdata->num_cols < PM8XXX_MIN_COLS) { dev_err(&pdev->dev, "invalid platform data\n"); return -EINVAL; } if (!pdata->scan_delay_ms || pdata->scan_delay_ms > MAX_SCAN_DELAY || pdata->scan_delay_ms < MIN_SCAN_DELAY || !is_power_of_2(pdata->scan_delay_ms)) { dev_err(&pdev->dev, "invalid keypad scan time supplied\n"); return -EINVAL; } if (!pdata->row_hold_ns || pdata->row_hold_ns > MAX_ROW_HOLD_DELAY || pdata->row_hold_ns < MIN_ROW_HOLD_DELAY || ((pdata->row_hold_ns % MIN_ROW_HOLD_DELAY) != 0)) { dev_err(&pdev->dev, "invalid keypad row hold time supplied\n"); return -EINVAL; } if (!pdata->debounce_ms || ((pdata->debounce_ms % 5) != 0) || pdata->debounce_ms > MAX_DEBOUNCE_TIME || pdata->debounce_ms < MIN_DEBOUNCE_TIME) { dev_err(&pdev->dev, "invalid debounce time supplied\n"); return -EINVAL; } keymap_data = pdata->keymap_data; if (!keymap_data) { dev_err(&pdev->dev, "no keymap data supplied\n"); return -EINVAL; } kp = kzalloc(sizeof(*kp), GFP_KERNEL); if (!kp) return -ENOMEM; platform_set_drvdata(pdev, kp); kp->pdata = pdata; kp->dev = &pdev->dev; kp->input = input_allocate_device(); if (!kp->input) { dev_err(&pdev->dev, "unable to allocate input device\n"); rc = -ENOMEM; goto err_alloc_device; } kp->key_sense_irq = platform_get_irq(pdev, 0); if (kp->key_sense_irq < 0) { dev_err(&pdev->dev, "unable to get keypad sense irq\n"); rc = -ENXIO; goto err_get_irq; } kp->key_stuck_irq = platform_get_irq(pdev, 1); if (kp->key_stuck_irq < 0) { dev_err(&pdev->dev, "unable to get keypad stuck irq\n"); rc = -ENXIO; goto err_get_irq; } kp->input->name = pdata->input_name ? : "PMIC8XXX keypad"; kp->input->phys = pdata->input_phys_device ? : "pmic8xxx_keypad/input0"; kp->input->dev.parent = &pdev->dev; kp->input->id.bustype = BUS_I2C; kp->input->id.version = 0x0001; kp->input->id.product = 0x0001; kp->input->id.vendor = 0x0001; kp->input->evbit[0] = BIT_MASK(EV_KEY); if (pdata->rep) __set_bit(EV_REP, kp->input->evbit); kp->input->keycode = kp->keycodes; kp->input->keycodemax = PM8XXX_MATRIX_MAX_SIZE; kp->input->keycodesize = sizeof(kp->keycodes); kp->input->open = pmic8xxx_kp_open; kp->input->close = pmic8xxx_kp_close; matrix_keypad_build_keymap(keymap_data, PM8XXX_ROW_SHIFT, kp->input->keycode, kp->input->keybit); input_set_capability(kp->input, EV_MSC, MSC_SCAN); input_set_drvdata(kp->input, kp); /* initialize keypad state */ memset(kp->keystate, 0xff, sizeof(kp->keystate)); memset(kp->stuckstate, 0xff, sizeof(kp->stuckstate)); rc = pmic8xxx_kpd_init(kp); if (rc < 0) { dev_err(&pdev->dev, "unable to initialize keypad controller\n"); goto err_get_irq; } rc = pmic8xxx_kp_config_gpio(pdata->cols_gpio_start, pdata->num_cols, kp, &kypd_sns); if (rc < 0) { dev_err(&pdev->dev, "unable to configure keypad sense lines\n"); goto err_gpio_config; } /* IDPower GPIO ISV add */ /* gpio 154,155 (Hi-Z) */ rc = pmic8xxx_kp_config_gpio( 154, 2, kp, &kypd_sns_dis_pin); if (rc < 0) { dev_err(&pdev->dev, "unable to configure keypad sense lines\n"); goto err_gpio_config; } /* IDPower GPIO ISV add */ rc = pmic8xxx_kp_config_gpio(pdata->rows_gpio_start, pdata->num_rows, kp, &kypd_drv); if (rc < 0) { dev_err(&pdev->dev, "unable to configure keypad drive lines\n"); goto err_gpio_config; } rc = request_any_context_irq(kp->key_sense_irq, pmic8xxx_kp_irq, IRQF_TRIGGER_RISING, "pmic-keypad", kp); if (rc < 0) { dev_err(&pdev->dev, "failed to request keypad sense irq\n"); goto err_get_irq; } rc = request_any_context_irq(kp->key_stuck_irq, pmic8xxx_kp_stuck_irq, IRQF_TRIGGER_RISING, "pmic-keypad-stuck", kp); if (rc < 0) { dev_err(&pdev->dev, "failed to request keypad stuck irq\n"); goto err_req_stuck_irq; } rc = pmic8xxx_kp_read_u8(kp, &ctrl_val, KEYP_CTRL); if (rc < 0) { dev_err(&pdev->dev, "failed to read KEYP_CTRL register\n"); goto err_pmic_reg_read; } kp->ctrl_reg = ctrl_val; rc = input_register_device(kp->input); if (rc < 0) { dev_err(&pdev->dev, "unable to register keypad input device\n"); goto err_pmic_reg_read; } device_init_wakeup(&pdev->dev, pdata->wakeup); return 0; err_pmic_reg_read: free_irq(kp->key_stuck_irq, kp); err_req_stuck_irq: free_irq(kp->key_sense_irq, kp); err_gpio_config: err_get_irq: input_free_device(kp->input); err_alloc_device: platform_set_drvdata(pdev, NULL); kfree(kp); return rc; } static int __devexit pmic8xxx_kp_remove(struct platform_device *pdev) { struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); device_init_wakeup(&pdev->dev, 0); free_irq(kp->key_stuck_irq, kp); free_irq(kp->key_sense_irq, kp); input_unregister_device(kp->input); kfree(kp); platform_set_drvdata(pdev, NULL); return 0; } #ifdef CONFIG_PM_SLEEP static int pmic8xxx_kp_suspend(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); struct input_dev *input_dev = kp->input; if (device_may_wakeup(dev)) { enable_irq_wake(kp->key_sense_irq); } else { mutex_lock(&input_dev->mutex); if (input_dev->users) pmic8xxx_kp_disable(kp); mutex_unlock(&input_dev->mutex); } return 0; } static int pmic8xxx_kp_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); struct input_dev *input_dev = kp->input; if (device_may_wakeup(dev)) { disable_irq_wake(kp->key_sense_irq); } else { mutex_lock(&input_dev->mutex); if (input_dev->users) pmic8xxx_kp_enable(kp); mutex_unlock(&input_dev->mutex); } return 0; } #endif static SIMPLE_DEV_PM_OPS(pm8xxx_kp_pm_ops, pmic8xxx_kp_suspend, pmic8xxx_kp_resume); static struct platform_driver pmic8xxx_kp_driver = { .probe = pmic8xxx_kp_probe, .remove = __devexit_p(pmic8xxx_kp_remove), .driver = { .name = PM8XXX_KEYPAD_DEV_NAME, .owner = THIS_MODULE, .pm = &pm8xxx_kp_pm_ops, }, }; module_platform_driver(pmic8xxx_kp_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("PMIC8XXX keypad driver"); MODULE_VERSION("1.0"); MODULE_ALIAS("platform:pmic8xxx_keypad"); MODULE_AUTHOR("Trilok Soni <*****@*****.**>");
static int arizona_ldo1_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); const struct regulator_desc *desc; struct regulator_config config = { }; struct arizona_ldo1 *ldo1; int ret; arizona->external_dcvdd = false; ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); if (!ldo1) return -ENOMEM; ldo1->arizona = arizona; /* * Since the chip usually supplies itself we provide some * default init_data for it. This will be overridden with * platform data if provided. */ switch (arizona->type) { case WM5102: case WM8997: desc = &arizona_ldo1_hc; ldo1->init_data = arizona_ldo1_dvfs; break; default: desc = &arizona_ldo1; ldo1->init_data = arizona_ldo1_default; break; } ldo1->init_data.consumer_supplies = &ldo1->supply; ldo1->supply.supply = "DCVDD"; ldo1->supply.dev_name = dev_name(arizona->dev); config.dev = arizona->dev; config.driver_data = ldo1; config.regmap = arizona->regmap; if (IS_ENABLED(CONFIG_OF)) { if (!dev_get_platdata(arizona->dev)) { ret = arizona_ldo1_of_get_pdata(arizona, &config, desc); if (ret < 0) return ret; config.ena_gpio_initialized = true; } } config.ena_gpio = arizona->pdata.ldoena; if (arizona->pdata.ldo1) config.init_data = arizona->pdata.ldo1; else config.init_data = &ldo1->init_data; /* * LDO1 can only be used to supply DCVDD so if it has no * consumers then DCVDD is supplied externally. */ if (config.init_data->num_consumer_supplies == 0) arizona->external_dcvdd = true; ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config); if (IS_ERR(ldo1->regulator)) { ret = PTR_ERR(ldo1->regulator); dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", ret); return ret; } of_node_put(config.of_node); platform_set_drvdata(pdev, ldo1); return 0; }
static int __devinit cyttsp4_i2c_probe(struct i2c_client *client, const struct i2c_device_id *i2c_id) { struct cyttsp4_i2c *ts_i2c; struct device *dev = &client->dev; char const *adap_id = dev_get_platdata(dev); char const *id; int rc; dev_info(dev, "%s: Starting %s probe...\n", __func__, CYTTSP4_I2C_NAME); dev_dbg(dev, "%s: debug on\n", __func__); dev_vdbg(dev, "%s: verbose debug on\n", __func__); if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(dev, "%s: fail check I2C functionality\n", __func__); rc = -EIO; goto error_alloc_data_failed; } ts_i2c = kzalloc(sizeof(struct cyttsp4_i2c), GFP_KERNEL); if (ts_i2c == NULL) { dev_err(dev, "%s: Error, kzalloc.\n", __func__); rc = -ENOMEM; goto error_alloc_data_failed; } mutex_init(&ts_i2c->lock); ts_i2c->client = client; client->dev.bus = &i2c_bus_type; i2c_set_clientdata(client, ts_i2c); dev_set_drvdata(&client->dev, ts_i2c); if (adap_id) id = adap_id; else id = CYTTSP4_I2C_NAME; dev_dbg(dev, "%s: add adap='%s' (CYTTSP4_I2C_NAME=%s)\n", __func__, id, CYTTSP4_I2C_NAME); pm_runtime_enable(&client->dev); rc = cyttsp4_add_adapter(id, &ops, dev); if (rc) { dev_err(dev, "%s: Error on probe %s\n", __func__, CYTTSP4_I2C_NAME); goto add_adapter_err; } dev_info(dev, "%s: Successful probe %s\n", __func__, CYTTSP4_I2C_NAME); return 0; add_adapter_err: pm_runtime_disable(&client->dev); dev_set_drvdata(&client->dev, NULL); i2c_set_clientdata(client, NULL); kfree(ts_i2c); error_alloc_data_failed: return rc; }
static int cyttsp4_debug_probe(struct cyttsp4_device *ttsp) { struct device *dev = &ttsp->dev; struct cyttsp4_debug_data *dd; struct cyttsp4_debug_platform_data *pdata = dev_get_platdata(dev); int rc; dev_info(dev, "%s: startup\n", __func__); dev_dbg(dev, "%s: debug on\n", __func__); dev_vdbg(dev, "%s: verbose debug on\n", __func__); /* get context and debug print buffers */ dd = kzalloc(sizeof(*dd), GFP_KERNEL); if (dd == NULL) { dev_err(dev, "%s: Error, kzalloc\n", __func__); rc = -ENOMEM; goto cyttsp4_debug_probe_alloc_failed; } rc = device_create_file(dev, &dev_attr_int_count); if (rc) { dev_err(dev, "%s: Error, could not create int_count\n", __func__); goto cyttsp4_debug_probe_create_int_count_failed; } rc = device_create_file(dev, &dev_attr_formated_output); if (rc) { dev_err(dev, "%s: Error, could not create formated_output\n", __func__); goto cyttsp4_debug_probe_create_formated_failed; } mutex_init(&dd->sysfs_lock); dd->ttsp = ttsp; dd->pdata = pdata; dev_set_drvdata(dev, dd); pm_runtime_enable(dev); dd->si = cyttsp4_request_sysinfo(ttsp); if (dd->si == NULL) { dev_err(dev, "%s: Fail get sysinfo pointer from core\n", __func__); rc = -ENODEV; goto cyttsp4_debug_probe_sysinfo_failed; } rc = cyttsp4_subscribe_attention(ttsp, CY_ATTEN_IRQ, cyttsp4_debug_op_attention, CY_MODE_OPERATIONAL); if (rc < 0) { dev_err(dev, "%s: Error, could not subscribe Operating mode attention cb\n", __func__); goto cyttsp4_debug_probe_subscribe_op_failed; } rc = cyttsp4_subscribe_attention(ttsp, CY_ATTEN_IRQ, cyttsp4_debug_cat_attention, CY_MODE_CAT); if (rc < 0) { dev_err(dev, "%s: Error, could not subscribe CaT mode attention cb\n", __func__); goto cyttsp4_debug_probe_subscribe_cat_failed; } rc = cyttsp4_subscribe_attention(ttsp, CY_ATTEN_STARTUP, cyttsp4_debug_startup_attention, 0); if (rc < 0) { dev_err(dev, "%s: Error, could not subscribe startup attention cb\n", __func__); goto cyttsp4_debug_probe_subscribe_startup_failed; } return 0; cyttsp4_debug_probe_subscribe_startup_failed: cyttsp4_unsubscribe_attention(ttsp, CY_ATTEN_IRQ, cyttsp4_debug_cat_attention, CY_MODE_CAT); cyttsp4_debug_probe_subscribe_cat_failed: cyttsp4_unsubscribe_attention(ttsp, CY_ATTEN_IRQ, cyttsp4_debug_op_attention, CY_MODE_OPERATIONAL); cyttsp4_debug_probe_subscribe_op_failed: cyttsp4_debug_probe_sysinfo_failed: pm_runtime_suspend(dev); pm_runtime_disable(dev); dev_set_drvdata(dev, NULL); device_remove_file(dev, &dev_attr_formated_output); cyttsp4_debug_probe_create_formated_failed: device_remove_file(dev, &dev_attr_int_count); cyttsp4_debug_probe_create_int_count_failed: kfree(dd); cyttsp4_debug_probe_alloc_failed: dev_err(dev, "%s failed.\n", __func__); return rc; }
static int tps51632_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct tps51632_regulator_platform_data *pdata; struct regulator_dev *rdev; struct tps51632_chip *tps; int ret; struct regulator_config config = { }; if (client->dev.of_node) { const struct of_device_id *match; match = of_match_device(of_match_ptr(tps51632_of_match), &client->dev); if (!match) { dev_err(&client->dev, "Error: No device match found\n"); return -ENODEV; } } pdata = dev_get_platdata(&client->dev); if (!pdata && client->dev.of_node) pdata = of_get_tps51632_platform_data(&client->dev); if (!pdata) { dev_err(&client->dev, "No Platform data\n"); return -EINVAL; } if (pdata->enable_pwm_dvfs) { if ((pdata->base_voltage_uV < TPS51632_MIN_VOLATGE) || (pdata->base_voltage_uV > TPS51632_MAX_VOLATGE)) { dev_err(&client->dev, "Invalid base_voltage_uV setting\n"); return -EINVAL; } if ((pdata->max_voltage_uV) && ((pdata->max_voltage_uV < TPS51632_MIN_VOLATGE) || (pdata->max_voltage_uV > TPS51632_MAX_VOLATGE))) { dev_err(&client->dev, "Invalid max_voltage_uV setting\n"); return -EINVAL; } } tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); if (!tps) { dev_err(&client->dev, "Memory allocation failed\n"); return -ENOMEM; } tps->dev = &client->dev; tps->desc.name = id->name; tps->desc.id = 0; tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY; tps->desc.min_uV = TPS51632_MIN_VOLATGE; tps->desc.uV_step = TPS51632_VOLATGE_STEP_10mV; tps->desc.linear_min_sel = TPS51632_MIN_VSEL; tps->desc.n_voltages = TPS51632_MAX_VSEL + 1; tps->desc.ops = &tps51632_dcdc_ops; tps->desc.type = REGULATOR_VOLTAGE; tps->desc.owner = THIS_MODULE; if (pdata->enable_pwm_dvfs) tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG; else tps->desc.vsel_reg = TPS51632_VOLTAGE_SELECT_REG; tps->desc.vsel_mask = TPS51632_VOUT_MASK; tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config); if (IS_ERR(tps->regmap)) { ret = PTR_ERR(tps->regmap); dev_err(&client->dev, "regmap init failed, err %d\n", ret); return ret; } i2c_set_clientdata(client, tps); ret = tps51632_init_dcdc(tps, pdata); if (ret < 0) { dev_err(tps->dev, "Init failed, err = %d\n", ret); return ret; } /* Register the regulators */ config.dev = &client->dev; config.init_data = pdata->reg_init_data; config.driver_data = tps; config.regmap = tps->regmap; config.of_node = client->dev.of_node; rdev = devm_regulator_register(&client->dev, &tps->desc, &config); if (IS_ERR(rdev)) { dev_err(tps->dev, "regulator register failed\n"); return PTR_ERR(rdev); } tps->rdev = rdev; return 0; }
static int __devinit sec_charger_probe(struct platform_device *pdev) { struct sec_charger_info *charger; sec_charger_dev_t *mfd_dev = dev_get_drvdata(pdev->dev.parent); sec_charger_pdata_t *pdata = dev_get_platdata(mfd_dev->dev); int ret = 0; dev_dbg(&pdev->dev, "%s: SEC Charger Driver Loading\n", __func__); charger = kzalloc(sizeof(*charger), GFP_KERNEL); if (!charger) return -ENOMEM; platform_set_drvdata(pdev, charger); charger->client = mfd_dev->i2c; charger->pdata = pdata->charger_data; charger->psy_chg.name = "sec-charger"; charger->psy_chg.type = POWER_SUPPLY_TYPE_UNKNOWN; charger->psy_chg.get_property = sec_chg_get_property; charger->psy_chg.set_property = sec_chg_set_property; charger->psy_chg.properties = sec_charger_props; charger->psy_chg.num_properties = ARRAY_SIZE(sec_charger_props); if (!charger->pdata->chg_gpio_init()) { dev_err(&pdev->dev, "%s: Failed to Initialize GPIO\n", __func__); goto err_free; } if (!sec_hal_chg_init(charger)) { dev_err(&pdev->dev, "%s: Failed to Initialize Charger\n", __func__); goto err_free; } ret = power_supply_register(&pdev->dev, &charger->psy_chg); if (ret) { dev_err(&pdev->dev, "%s: Failed to Register psy_chg\n", __func__); goto err_free; } if (charger->pdata->chg_irq) { INIT_DELAYED_WORK_DEFERRABLE( &charger->isr_work, sec_chg_isr_work); ret = request_threaded_irq(charger->pdata->chg_irq, NULL, sec_chg_irq_thread, charger->pdata->chg_irq_attr, "charger-irq", charger); if (ret) { dev_err(&pdev->dev, "%s: Failed to Reqeust IRQ\n", __func__); goto err_supply_unreg; } ret = enable_irq_wake(charger->pdata->chg_irq); if (ret < 0) dev_err(&pdev->dev, "%s: Failed to Enable Wakeup Source(%d)\n", __func__, ret); } ret = sec_chg_create_attrs(charger->psy_chg.dev); if (ret) { dev_err(&pdev->dev, "%s : Failed to create_attrs\n", __func__); goto err_req_irq; } dev_dbg(&pdev->dev, "%s: SEC Charger Driver Loaded\n", __func__); return 0; err_req_irq: if (charger->pdata->chg_irq) free_irq(charger->pdata->chg_irq, charger); err_supply_unreg: power_supply_unregister(&charger->psy_chg); err_free: kfree(charger); return ret; }
int mdp3_ctrl_init(struct msm_fb_data_type *mfd) { struct device *dev = mfd->fbi->dev; struct msm_mdp_interface *mdp3_interface = &mfd->mdp; struct mdp3_session_data *mdp3_session = NULL; u32 intf_type = MDP3_DMA_OUTPUT_SEL_DSI_VIDEO; int rc; int splash_mismatch = 0; pr_debug("mdp3_ctrl_init\n"); rc = mdp3_parse_dt_splash(mfd); if (rc) splash_mismatch = 1; mdp3_interface->on_fnc = mdp3_ctrl_on; mdp3_interface->off_fnc = mdp3_ctrl_off; mdp3_interface->do_histogram = NULL; mdp3_interface->cursor_update = NULL; mdp3_interface->dma_fnc = mdp3_ctrl_pan_display; mdp3_interface->ioctl_handler = mdp3_ctrl_ioctl_handler; mdp3_interface->kickoff_fnc = mdp3_ctrl_display_commit_kickoff; mdp3_interface->lut_update = mdp3_ctrl_lut_update; mdp3_interface->configure_panel = mdp3_update_panel_info; mdp3_session = kmalloc(sizeof(struct mdp3_session_data), GFP_KERNEL); if (!mdp3_session) { pr_err("fail to allocate mdp3 private data structure"); return -ENOMEM; } memset(mdp3_session, 0, sizeof(struct mdp3_session_data)); mutex_init(&mdp3_session->lock); INIT_WORK(&mdp3_session->clk_off_work, mdp3_dispatch_clk_off); INIT_WORK(&mdp3_session->dma_done_work, mdp3_dispatch_dma_done); atomic_set(&mdp3_session->vsync_countdown, 0); mutex_init(&mdp3_session->histo_lock); mdp3_session->dma = mdp3_get_dma_pipe(MDP3_DMA_CAP_ALL); if (!mdp3_session->dma) { rc = -ENODEV; goto init_done; } rc = mdp3_dma_init(mdp3_session->dma); if (rc) { pr_err("fail to init dma\n"); goto init_done; } intf_type = mdp3_ctrl_get_intf_type(mfd); mdp3_session->intf = mdp3_get_display_intf(intf_type); if (!mdp3_session->intf) { rc = -ENODEV; goto init_done; } rc = mdp3_intf_init(mdp3_session->intf); if (rc) { pr_err("fail to init interface\n"); goto init_done; } mdp3_session->dma->output_config.out_sel = intf_type; mdp3_session->mfd = mfd; mdp3_session->panel = dev_get_platdata(&mfd->pdev->dev); mdp3_session->status = mdp3_session->intf->active; mdp3_session->overlay.id = MSMFB_NEW_REQUEST; mdp3_bufq_init(&mdp3_session->bufq_in); mdp3_bufq_init(&mdp3_session->bufq_out); mdp3_session->histo_status = 0; mdp3_session->lut_sel = 0; BLOCKING_INIT_NOTIFIER_HEAD(&mdp3_session->notifier_head); init_timer(&mdp3_session->vsync_timer); mdp3_session->vsync_timer.function = mdp3_vsync_timer_func; mdp3_session->vsync_timer.data = (u32)mdp3_session; mdp3_session->vsync_period = 1000 / mfd->panel_info->mipi.frame_rate; mfd->mdp.private1 = mdp3_session; init_completion(&mdp3_session->dma_completion); if (intf_type != MDP3_DMA_OUTPUT_SEL_DSI_VIDEO) mdp3_session->wait_for_dma_done = mdp3_wait_for_dma_done; rc = sysfs_create_group(&dev->kobj, &vsync_fs_attr_group); if (rc) { pr_err("vsync sysfs group creation failed, ret=%d\n", rc); goto init_done; } mdp3_session->vsync_event_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "vsync_event"); if (!mdp3_session->vsync_event_sd) { pr_err("vsync_event sysfs lookup failed\n"); rc = -ENODEV; goto init_done; } rc = mdp3_create_sysfs_link(dev); if (rc) pr_warn("problem creating link to mdp sysfs\n"); kobject_uevent(&dev->kobj, KOBJ_ADD); pr_debug("vsync kobject_uevent(KOBJ_ADD)\n"); if (mdp3_get_cont_spash_en()) { mdp3_session->clk_on = 1; mdp3_session->in_splash_screen = 1; mdp3_ctrl_notifier_register(mdp3_session, &mdp3_session->mfd->mdp_sync_pt_data.notifier); } if (splash_mismatch) { pr_err("splash memory mismatch, stop splash\n"); mdp3_ctrl_off(mfd); } mdp3_session->vsync_before_commit = true; init_done: if (IS_ERR_VALUE(rc)) kfree(mdp3_session); return rc; }
static int gpio_keys_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); struct gpio_keys_drvdata *ddata; struct input_dev *input; size_t size; int i, error; int wakeup = 0; if (!pdata) { pdata = gpio_keys_get_devtree_pdata(dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); } size = sizeof(struct gpio_keys_drvdata) + pdata->nbuttons * sizeof(struct gpio_button_data); ddata = devm_kzalloc(dev, size, GFP_KERNEL); if (!ddata) { dev_err(dev, "failed to allocate state\n"); return -ENOMEM; } input = devm_input_allocate_device(dev); if (!input) { dev_err(dev, "failed to allocate input device\n"); return -ENOMEM; } ddata->pdata = pdata; ddata->input = input; mutex_init(&ddata->disable_lock); platform_set_drvdata(pdev, ddata); input_set_drvdata(input, ddata); input->name = pdata->name ? : pdev->name; input->phys = "gpio-keys/input0"; input->dev.parent = &pdev->dev; input->open = gpio_keys_open; input->close = gpio_keys_close; input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = 0x0100; /* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) __set_bit(EV_REP, input->evbit); for (i = 0; i < pdata->nbuttons; i++) { const struct gpio_keys_button *button = &pdata->buttons[i]; struct gpio_button_data *bdata = &ddata->data[i]; error = gpio_keys_setup_key(pdev, input, bdata, button); if (error) return error; if (button->wakeup) wakeup = 1; } error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group); if (error) { dev_err(dev, "Unable to export keys/switches, error: %d\n", error); return error; } error = input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", error); goto err_remove_group; } device_init_wakeup(&pdev->dev, wakeup); return 0; err_remove_group: sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); return error; }
static int spi_imx_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; const struct of_device_id *of_id = of_match_device(spi_imx_dt_ids, &pdev->dev); struct spi_imx_master *mxc_platform_info = dev_get_platdata(&pdev->dev); struct spi_master *master; struct spi_imx_data *spi_imx; struct resource *res; int i, ret, irq; if (!np && !mxc_platform_info) { dev_err(&pdev->dev, "can't get the platform data\n"); return -EINVAL; } master = spi_alloc_master(&pdev->dev, sizeof(struct spi_imx_data)); if (!master) return -ENOMEM; platform_set_drvdata(pdev, master); master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); master->bus_num = np ? -1 : pdev->id; spi_imx = spi_master_get_devdata(master); spi_imx->bitbang.master = master; spi_imx->dev = &pdev->dev; spi_imx->devtype_data = of_id ? of_id->data : (struct spi_imx_devtype_data *)pdev->id_entry->driver_data; if (mxc_platform_info) { master->num_chipselect = mxc_platform_info->num_chipselect; master->cs_gpios = devm_kzalloc(&master->dev, sizeof(int) * master->num_chipselect, GFP_KERNEL); if (!master->cs_gpios) return -ENOMEM; for (i = 0; i < master->num_chipselect; i++) master->cs_gpios[i] = mxc_platform_info->chipselect[i]; } spi_imx->bitbang.chipselect = spi_imx_chipselect; spi_imx->bitbang.setup_transfer = spi_imx_setupxfer; spi_imx->bitbang.txrx_bufs = spi_imx_transfer; spi_imx->bitbang.master->setup = spi_imx_setup; spi_imx->bitbang.master->cleanup = spi_imx_cleanup; spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message; spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message; spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx)) spi_imx->bitbang.master->mode_bits |= SPI_LOOP; init_completion(&spi_imx->xfer_done); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); spi_imx->base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(spi_imx->base)) { ret = PTR_ERR(spi_imx->base); goto out_master_put; } spi_imx->base_phys = res->start; irq = platform_get_irq(pdev, 0); if (irq < 0) { ret = irq; goto out_master_put; } ret = devm_request_irq(&pdev->dev, irq, spi_imx_isr, 0, dev_name(&pdev->dev), spi_imx); if (ret) { dev_err(&pdev->dev, "can't get irq%d: %d\n", irq, ret); goto out_master_put; } spi_imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); if (IS_ERR(spi_imx->clk_ipg)) { ret = PTR_ERR(spi_imx->clk_ipg); goto out_master_put; } spi_imx->clk_per = devm_clk_get(&pdev->dev, "per"); if (IS_ERR(spi_imx->clk_per)) { ret = PTR_ERR(spi_imx->clk_per); goto out_master_put; } ret = clk_prepare_enable(spi_imx->clk_per); if (ret) goto out_master_put; ret = clk_prepare_enable(spi_imx->clk_ipg); if (ret) goto out_put_per; spi_imx->spi_clk = clk_get_rate(spi_imx->clk_per); /* * Only validated on i.mx6 now, can remove the constrain if validated on * other chips. */ if (is_imx51_ecspi(spi_imx)) { ret = spi_imx_sdma_init(&pdev->dev, spi_imx, master); if (ret == -EPROBE_DEFER) goto out_clk_put; if (ret < 0) dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret); } spi_imx->devtype_data->reset(spi_imx); spi_imx->devtype_data->intctrl(spi_imx, 0); master->dev.of_node = pdev->dev.of_node; ret = spi_bitbang_start(&spi_imx->bitbang); if (ret) { dev_err(&pdev->dev, "bitbang start failed with %d\n", ret); goto out_clk_put; } if (!master->cs_gpios) { dev_err(&pdev->dev, "No CS GPIOs available\n"); ret = -EINVAL; goto out_clk_put; } for (i = 0; i < master->num_chipselect; i++) { if (!gpio_is_valid(master->cs_gpios[i])) continue; ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i], DRIVER_NAME); if (ret) { dev_err(&pdev->dev, "Can't get CS GPIO %i\n", master->cs_gpios[i]); goto out_clk_put; } } dev_info(&pdev->dev, "probed\n"); clk_disable(spi_imx->clk_ipg); clk_disable(spi_imx->clk_per); return ret; out_clk_put: clk_disable_unprepare(spi_imx->clk_ipg); out_put_per: clk_disable_unprepare(spi_imx->clk_per); out_master_put: spi_master_put(master); return ret; }
static int matrix_keypad_probe(struct platform_device *pdev) { struct matrix_keypad_platform_data *pdata; struct matrix_keypad *keypad; struct input_dev *input_dev; #ifdef CONFIG_SUPPORT_KEYPAD_LED struct device *sec_keypad; #endif int err; pdata = dev_get_platdata(&pdev->dev); if (!pdata) { pdata = matrix_keypad_parse_dt(&pdev->dev); if (IS_ERR(pdata)) { dev_err(&pdev->dev, "no platform data defined\n"); return PTR_ERR(pdata); } } else if (!pdata->keymap_data) { dev_err(&pdev->dev, "no keymap data defined\n"); return -EINVAL; } keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL); input_dev = input_allocate_device(); if (!keypad || !input_dev) { err = -ENOMEM; goto err_free_mem; } keypad->input_dev = input_dev; keypad->pdata = pdata; keypad->row_shift = get_count_order(pdata->num_col_gpios); keypad->stopped = true; INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); spin_lock_init(&keypad->lock); if (pdata->project) input_dev->name = pdata->project; else input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; input_dev->dev.parent = &pdev->dev; input_dev->open = matrix_keypad_start; input_dev->close = matrix_keypad_stop; err = matrix_keypad_build_keymap(pdata->keymap_data, NULL, pdata->num_row_gpios, pdata->num_col_gpios, NULL, input_dev); if (err) { dev_err(&pdev->dev, "failed to build keymap\n"); goto err_free_mem; } if (!pdata->no_autorepeat) __set_bit(EV_REP, input_dev->evbit); input_set_capability(input_dev, EV_MSC, MSC_SCAN); input_set_drvdata(input_dev, keypad); err = matrix_keypad_init_gpio(pdev, keypad); if (err) goto err_free_mem; err = input_register_device(keypad->input_dev); if (err) goto err_free_gpio; #ifdef CONFIG_SUPPORT_KEYPAD_LED /* keypad led control */ sec_keypad = sec_device_create(pdata, "sec_keypad"); if (IS_ERR(sec_keypad)) dev_err(&pdev->dev,"Failed to create device(sec_key)!\n"); err = device_create_file(sec_keypad, &dev_attr_brightness); if (err) { dev_err(&pdev->dev,"Failed to create device file in sysfs entries(%s)!\n", dev_attr_brightness.attr.name); } dev_set_drvdata(sec_keypad, pdata); pdata->vddo_vreg = regulator_get(&pdev->dev,"vddo"); if (IS_ERR(pdata->vddo_vreg)){ pdata->vddo_vreg = NULL; printk(KERN_INFO "pdata->vddo_vreg error\n"); err = -EPERM; goto err_free_gpio; } #endif device_init_wakeup(&pdev->dev, pdata->wakeup); platform_set_drvdata(pdev, keypad); return 0; err_free_gpio: matrix_keypad_free_gpio(keypad); err_free_mem: input_free_device(input_dev); kfree(keypad); return err; }
static int aat2870_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct aat2870_platform_data *pdata = dev_get_platdata(&client->dev); struct aat2870_data *aat2870; int i, j; int ret = 0; aat2870 = devm_kzalloc(&client->dev, sizeof(struct aat2870_data), GFP_KERNEL); if (!aat2870) { dev_err(&client->dev, "Failed to allocate memory for aat2870\n"); return -ENOMEM; } aat2870->dev = &client->dev; dev_set_drvdata(aat2870->dev, aat2870); aat2870->client = client; i2c_set_clientdata(client, aat2870); aat2870->reg_cache = aat2870_regs; if (pdata->en_pin < 0) aat2870->en_pin = -1; else aat2870->en_pin = pdata->en_pin; aat2870->init = pdata->init; aat2870->uninit = pdata->uninit; aat2870->read = aat2870_read; aat2870->write = aat2870_write; aat2870->update = aat2870_update; mutex_init(&aat2870->io_lock); if (aat2870->init) aat2870->init(aat2870); if (aat2870->en_pin >= 0) { ret = devm_gpio_request_one(&client->dev, aat2870->en_pin, GPIOF_OUT_INIT_HIGH, "aat2870-en"); if (ret < 0) { dev_err(&client->dev, "Failed to request GPIO %d\n", aat2870->en_pin); return ret; } } aat2870_enable(aat2870); for (i = 0; i < pdata->num_subdevs; i++) { for (j = 0; j < ARRAY_SIZE(aat2870_devs); j++) { if ((pdata->subdevs[i].id == aat2870_devs[j].id) && !strcmp(pdata->subdevs[i].name, aat2870_devs[j].name)) { aat2870_devs[j].platform_data = pdata->subdevs[i].platform_data; break; } } } ret = mfd_add_devices(aat2870->dev, 0, aat2870_devs, ARRAY_SIZE(aat2870_devs), NULL, 0, NULL); if (ret != 0) { dev_err(aat2870->dev, "Failed to add subdev: %d\n", ret); goto out_disable; } aat2870_init_debugfs(aat2870); return 0; out_disable: aat2870_disable(aat2870); return ret; }
static int __init mc13xxx_led_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct mc13xxx_leds_platform_data *pdata = dev_get_platdata(dev); struct mc13xxx *mcdev = dev_get_drvdata(dev->parent); struct mc13xxx_led_devtype *devtype = (struct mc13xxx_led_devtype *)pdev->id_entry->driver_data; struct mc13xxx_leds *leds; int i, id, ret = -ENODATA; u32 init_led = 0; leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); if (!leds) return -ENOMEM; leds->devtype = devtype; leds->master = mcdev; platform_set_drvdata(pdev, leds); if (dev->parent->of_node) { pdata = mc13xxx_led_probe_dt(pdev); if (IS_ERR(pdata)) return PTR_ERR(pdata); } else if (!pdata) return -ENODATA; leds->num_leds = pdata->num_leds; if ((leds->num_leds < 1) || (leds->num_leds > (devtype->led_max - devtype->led_min + 1))) { dev_err(dev, "Invalid LED count %d\n", leds->num_leds); return -EINVAL; } leds->led = devm_kzalloc(dev, leds->num_leds * sizeof(*leds->led), GFP_KERNEL); if (!leds->led) return -ENOMEM; for (i = 0; i < devtype->num_regs; i++) { ret = mc13xxx_reg_write(mcdev, leds->devtype->ledctrl_base + i, pdata->led_control[i]); if (ret) return ret; } for (i = 0; i < leds->num_leds; i++) { const char *name, *trig; ret = -EINVAL; id = pdata->led[i].id; name = pdata->led[i].name; trig = pdata->led[i].default_trigger; if ((id > devtype->led_max) || (id < devtype->led_min)) { dev_err(dev, "Invalid ID %i\n", id); break; } if (init_led & (1 << id)) { dev_warn(dev, "LED %i already initialized\n", id); break; } init_led |= 1 << id; leds->led[i].id = id; leds->led[i].leds = leds; leds->led[i].cdev.name = name; leds->led[i].cdev.default_trigger = trig; leds->led[i].cdev.flags = LED_CORE_SUSPENDRESUME; leds->led[i].cdev.brightness_set = mc13xxx_led_set; leds->led[i].cdev.max_brightness = mc13xxx_max_brightness(id); INIT_WORK(&leds->led[i].work, mc13xxx_led_work); ret = led_classdev_register(dev->parent, &leds->led[i].cdev); if (ret) { dev_err(dev, "Failed to register LED %i\n", id); break; } } if (ret) while (--i >= 0) { led_classdev_unregister(&leds->led[i].cdev); cancel_work_sync(&leds->led[i].work); } return ret; }
int16_t fimc_is_af_enable(void *device, bool onoff) { int ret = 0; struct fimc_is_device_af *af_device = (struct fimc_is_device_af *)device; struct fimc_is_core *core; bool af_regulator = false, io_regulator = false; struct exynos_platform_fimc_is *core_pdata = dev_get_platdata(fimc_is_dev); core = (struct fimc_is_core *)dev_get_drvdata(fimc_is_dev); if (!core) { err("core is NULL"); return -ENODEV; } pr_info("af_noise : running_rear_camera = %d, onoff = %d\n", core->running_rear_camera, onoff); if (!core->running_rear_camera) { if (core_pdata->use_ois_hsi2c) { fimc_is_af_i2c_config(af_device->client, true); } if (onoff) { fimc_is_af_power(af_device, true); ret = fimc_is_af_i2c_write(af_device->client, 0x02, 0x00); if (ret) { err("i2c write fail\n"); goto power_off; } ret = fimc_is_af_i2c_write(af_device->client, 0x00, 0x00); if (ret) { err("i2c write fail\n"); goto power_off; } ret = fimc_is_af_i2c_write(af_device->client, 0x01, 0x00); if (ret) { err("i2c write fail\n"); goto power_off; } af_noise_count++; pr_info("af_noise : count = %d\n", af_noise_count); } else { /* Check the Power Pins */ af_regulator = fimc_is_check_regulator_status("CAM_AF_2.8V_AP"); io_regulator = fimc_is_check_regulator_status("CAM_IO_1.8V_AP"); if (af_regulator && io_regulator) { ret = fimc_is_af_i2c_write(af_device->client, 0x02, 0x40); if (ret) { err("i2c write fail\n"); } fimc_is_af_power(af_device, false); } else { pr_info("already power off.(%d)\n", __LINE__); } } if (core_pdata->use_ois_hsi2c) { fimc_is_af_i2c_config(af_device->client, false); } } return ret; power_off: if (!core->running_rear_camera) { if (core_pdata->use_ois_hsi2c) { fimc_is_af_i2c_config(af_device->client, false); } af_regulator = fimc_is_check_regulator_status("CAM_AF_2.8V_AP"); io_regulator = fimc_is_check_regulator_status("CAM_IO_1.8V_AP"); if (af_regulator && io_regulator) { fimc_is_af_power(af_device, false); } else { pr_info("already power off.(%d)\n", __LINE__); } } return ret; }
static int si476x_core_probe(struct i2c_client *client, const struct i2c_device_id *id) { int rval; struct si476x_core *core; struct si476x_platform_data *pdata; struct mfd_cell *cell; int cell_num; core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); if (!core) { dev_err(&client->dev, "failed to allocate 'struct si476x_core'\n"); return -ENOMEM; } core->client = client; core->regmap = devm_regmap_init_si476x(core); if (IS_ERR(core->regmap)) { rval = PTR_ERR(core->regmap); dev_err(&client->dev, "Failed to allocate register map: %d\n", rval); return rval; } i2c_set_clientdata(client, core); atomic_set(&core->is_alive, 0); core->power_state = SI476X_POWER_DOWN; pdata = dev_get_platdata(&client->dev); if (pdata) { memcpy(&core->power_up_parameters, &pdata->power_up_parameters, sizeof(core->power_up_parameters)); core->gpio_reset = -1; if (gpio_is_valid(pdata->gpio_reset)) { rval = gpio_request(pdata->gpio_reset, "si476x reset"); if (rval) { dev_err(&client->dev, "Failed to request gpio: %d\n", rval); return rval; } core->gpio_reset = pdata->gpio_reset; gpio_direction_output(core->gpio_reset, 0); } core->diversity_mode = pdata->diversity_mode; memcpy(&core->pinmux, &pdata->pinmux, sizeof(struct si476x_pinmux)); } else { dev_err(&client->dev, "No platform data provided\n"); return -EINVAL; } core->supplies[0].supply = "vd"; core->supplies[1].supply = "va"; core->supplies[2].supply = "vio1"; core->supplies[3].supply = "vio2"; rval = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(core->supplies), core->supplies); if (rval) { dev_err(&client->dev, "Failet to gett all of the regulators\n"); goto free_gpio; } mutex_init(&core->cmd_lock); init_waitqueue_head(&core->command); init_waitqueue_head(&core->tuning); rval = kfifo_alloc(&core->rds_fifo, SI476X_DRIVER_RDS_FIFO_DEPTH * sizeof(struct v4l2_rds_data), GFP_KERNEL); if (rval) { dev_err(&client->dev, "Could not alloate the FIFO\n"); goto free_gpio; } mutex_init(&core->rds_drainer_status_lock); init_waitqueue_head(&core->rds_read_queue); INIT_WORK(&core->rds_fifo_drainer, si476x_core_drain_rds_fifo); if (client->irq) { rval = devm_request_threaded_irq(&client->dev, client->irq, NULL, si476x_core_interrupt, IRQF_TRIGGER_FALLING, client->name, core); if (rval < 0) { dev_err(&client->dev, "Could not request IRQ %d\n", client->irq); goto free_kfifo; } disable_irq(client->irq); dev_dbg(&client->dev, "IRQ requested.\n"); core->rds_fifo_depth = 20; } else { INIT_DELAYED_WORK(&core->status_monitor, si476x_core_poll_loop); dev_info(&client->dev, "No IRQ number specified, will use polling\n"); core->rds_fifo_depth = 5; } core->chip_id = id->driver_data; rval = si476x_core_get_revision_info(core); if (rval < 0) { rval = -ENODEV; goto free_kfifo; } cell_num = 0; cell = &core->cells[SI476X_RADIO_CELL]; cell->name = "si476x-radio"; cell_num++; #ifdef CONFIG_SND_SOC_SI476X if ((core->chip_id == SI476X_CHIP_SI4761 || core->chip_id == SI476X_CHIP_SI4764) && core->pinmux.dclk == SI476X_DCLK_DAUDIO && core->pinmux.dfs == SI476X_DFS_DAUDIO && core->pinmux.dout == SI476X_DOUT_I2S_OUTPUT && core->pinmux.xout == SI476X_XOUT_TRISTATE) { cell = &core->cells[SI476X_CODEC_CELL]; cell->name = "si476x-codec"; cell_num++; } #endif rval = mfd_add_devices(&client->dev, (client->adapter->nr << 8) + client->addr, core->cells, cell_num, NULL, 0, NULL); if (!rval) return 0; free_kfifo: kfifo_free(&core->rds_fifo); free_gpio: if (gpio_is_valid(core->gpio_reset)) gpio_free(core->gpio_reset); return rval; }
static int da9063_regulator_probe(struct platform_device *pdev) { struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev); struct of_regulator_match *da9063_reg_matches = NULL; struct da9063_regulators_pdata *regl_pdata; const struct da9063_dev_model *model; struct da9063_regulators *regulators; struct da9063_regulator *regl; struct regulator_config config; bool bcores_merged, bmem_bio_merged; int id, irq, n, n_regulators, ret, val; size_t size; regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL; if (!regl_pdata) regl_pdata = da9063_parse_regulators_dt(pdev, &da9063_reg_matches); if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) { dev_err(&pdev->dev, "No regulators defined for the platform\n"); return PTR_ERR(regl_pdata); } /* Find regulators set for particular device model */ for (model = regulators_models; model->regulator_info; model++) { if (model->dev_model == da9063->model) break; } if (!model->regulator_info) { dev_err(&pdev->dev, "Chip model not recognised (%u)\n", da9063->model); return -ENODEV; } ret = regmap_read(da9063->regmap, DA9063_REG_CONFIG_H, &val); if (ret < 0) { dev_err(&pdev->dev, "Error while reading BUCKs configuration\n"); return ret; } bcores_merged = val & DA9063_BCORE_MERGE; bmem_bio_merged = val & DA9063_BUCK_MERGE; n_regulators = model->n_regulators; if (bcores_merged) n_regulators -= 2; /* remove BCORE1, BCORE2 */ else n_regulators--; /* remove BCORES_MERGED */ if (bmem_bio_merged) n_regulators -= 2; /* remove BMEM, BIO */ else n_regulators--; /* remove BMEM_BIO_MERGED */ /* Allocate memory required by usable regulators */ size = sizeof(struct da9063_regulators) + n_regulators * sizeof(struct da9063_regulator); regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (!regulators) return -ENOMEM; regulators->n_regulators = n_regulators; platform_set_drvdata(pdev, regulators); /* Register all regulators declared in platform information */ n = 0; id = 0; while (n < regulators->n_regulators) { /* Skip regulator IDs depending on merge mode configuration */ switch (id) { case DA9063_ID_BCORE1: case DA9063_ID_BCORE2: if (bcores_merged) { id++; continue; } break; case DA9063_ID_BMEM: case DA9063_ID_BIO: if (bmem_bio_merged) { id++; continue; } break; case DA9063_ID_BCORES_MERGED: if (!bcores_merged) { id++; continue; } break; case DA9063_ID_BMEM_BIO_MERGED: if (!bmem_bio_merged) { id++; continue; } break; } /* Initialise regulator structure */ regl = ®ulators->regulator[n]; regl->hw = da9063; regl->info = &model->regulator_info[id]; regl->desc = regl->info->desc; regl->desc.type = REGULATOR_VOLTAGE; regl->desc.owner = THIS_MODULE; if (regl->info->mode.reg) regl->mode = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->mode); if (regl->info->suspend.reg) regl->suspend = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->suspend); if (regl->info->sleep.reg) regl->sleep = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->sleep); if (regl->info->suspend_sleep.reg) regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->suspend_sleep); if (regl->info->ilimit.reg) regl->ilimit = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->ilimit); /* Register regulator */ memset(&config, 0, sizeof(config)); config.dev = &pdev->dev; config.init_data = da9063_get_regulator_initdata(regl_pdata, id); config.driver_data = regl; if (da9063_reg_matches) config.of_node = da9063_reg_matches[id].of_node; config.regmap = da9063->regmap; regl->rdev = devm_regulator_register(&pdev->dev, ®l->desc, &config); if (IS_ERR(regl->rdev)) { dev_err(&pdev->dev, "Failed to register %s regulator\n", regl->desc.name); return PTR_ERR(regl->rdev); } id++; n++; } /* LDOs overcurrent event support */ irq = platform_get_irq_byname(pdev, "LDO_LIM"); if (irq < 0) { dev_err(&pdev->dev, "Failed to get IRQ.\n"); return irq; } regulators->irq_ldo_lim = regmap_irq_get_virq(da9063->regmap_irq, irq); if (regulators->irq_ldo_lim >= 0) { ret = request_threaded_irq(regulators->irq_ldo_lim, NULL, da9063_ldo_lim_event, IRQF_TRIGGER_LOW | IRQF_ONESHOT, "LDO_LIM", regulators); if (ret) { dev_err(&pdev->dev, "Failed to request LDO_LIM IRQ.\n"); regulators->irq_ldo_lim = -ENXIO; } } return 0; }
static int hid_time_probe(struct platform_device *pdev) { int ret = 0; struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); struct hid_time_state *time_state = devm_kzalloc(&pdev->dev, sizeof(struct hid_time_state), GFP_KERNEL); if (time_state == NULL) return -ENOMEM; platform_set_drvdata(pdev, time_state); spin_lock_init(&time_state->lock_last_time); init_completion(&time_state->comp_last_time); time_state->common_attributes.hsdev = hsdev; time_state->common_attributes.pdev = pdev; ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_TIME, &time_state->common_attributes); if (ret) { dev_err(&pdev->dev, "failed to setup common attributes!\n"); return ret; } ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME, time_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes!\n"); return ret; } time_state->callbacks.send_event = hid_time_proc_event; time_state->callbacks.capture_sample = hid_time_capture_sample; time_state->callbacks.pdev = pdev; ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME, &time_state->callbacks); if (ret < 0) { dev_err(&pdev->dev, "register callback failed!\n"); return ret; } ret = sensor_hub_device_open(hsdev); if (ret) { dev_err(&pdev->dev, "failed to open sensor hub device!\n"); goto err_open; } /* * Enable HID input processing early in order to be able to read the * clock already in devm_rtc_device_register(). */ hid_device_io_start(hsdev->hdev); time_state->rtc = devm_rtc_device_register(&pdev->dev, "hid-sensor-time", &hid_time_rtc_ops, THIS_MODULE); if (IS_ERR_OR_NULL(time_state->rtc)) { hid_device_io_stop(hsdev->hdev); ret = time_state->rtc ? PTR_ERR(time_state->rtc) : -ENODEV; time_state->rtc = NULL; dev_err(&pdev->dev, "rtc device register failed!\n"); goto err_rtc; } return ret; err_rtc: sensor_hub_device_close(hsdev); err_open: sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); return ret; }
static int adp5588_gpio_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adp5588_gpio_platform_data *pdata = dev_get_platdata(&client->dev); struct adp5588_gpio *dev; struct gpio_chip *gc; int ret, i, revid; if (pdata == NULL) { dev_err(&client->dev, "missing platform data\n"); return -ENODEV; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); return -EIO; } dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) { dev_err(&client->dev, "failed to alloc memory\n"); return -ENOMEM; } dev->client = client; gc = &dev->gpio_chip; gc->direction_input = adp5588_gpio_direction_input; gc->direction_output = adp5588_gpio_direction_output; gc->get = adp5588_gpio_get_value; gc->set = adp5588_gpio_set_value; gc->can_sleep = true; gc->base = pdata->gpio_start; gc->ngpio = ADP5588_MAXGPIO; gc->label = client->name; gc->owner = THIS_MODULE; mutex_init(&dev->lock); ret = adp5588_gpio_read(dev->client, DEV_ID); if (ret < 0) goto err; revid = ret & ADP5588_DEVICE_ID_MASK; for (i = 0, ret = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) { dev->dat_out[i] = adp5588_gpio_read(client, GPIO_DAT_OUT1 + i); dev->dir[i] = adp5588_gpio_read(client, GPIO_DIR1 + i); ret |= adp5588_gpio_write(client, KP_GPIO1 + i, 0); ret |= adp5588_gpio_write(client, GPIO_PULL1 + i, (pdata->pullup_dis_mask >> (8 * i)) & 0xFF); ret |= adp5588_gpio_write(client, GPIO_INT_EN1 + i, 0); if (ret) goto err; } if (pdata->irq_base) { if (WA_DELAYED_READOUT_REVID(revid)) { dev_warn(&client->dev, "GPIO int not supported\n"); } else { ret = adp5588_irq_setup(dev); if (ret) goto err; } } ret = gpiochip_add(&dev->gpio_chip); if (ret) goto err_irq; dev_info(&client->dev, "IRQ Base: %d Rev.: %d\n", pdata->irq_base, revid); if (pdata->setup) { ret = pdata->setup(client, gc->base, gc->ngpio, pdata->context); if (ret < 0) dev_warn(&client->dev, "setup failed, %d\n", ret); } i2c_set_clientdata(client, dev); return 0; err_irq: adp5588_irq_teardown(dev); err: kfree(dev); return ret; }
/* * Probe for NAND controller */ static int lpc32xx_nand_probe(struct platform_device *pdev) { struct lpc32xx_nand_host *host; struct mtd_info *mtd; struct nand_chip *chip; struct resource *rc; struct mtd_part_parser_data ppdata = {}; int res; rc = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (rc == NULL) { dev_err(&pdev->dev, "No memory resource found for device\n"); return -EBUSY; } /* Allocate memory for the device structure (and zero it) */ host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); if (!host) { dev_err(&pdev->dev, "failed to allocate device structure\n"); return -ENOMEM; } host->io_base_dma = rc->start; host->io_base = devm_ioremap_resource(&pdev->dev, rc); if (IS_ERR(host->io_base)) return PTR_ERR(host->io_base); if (pdev->dev.of_node) host->ncfg = lpc32xx_parse_dt(&pdev->dev); if (!host->ncfg) { dev_err(&pdev->dev, "Missing or bad NAND config from device tree\n"); return -ENOENT; } if (host->ncfg->wp_gpio == -EPROBE_DEFER) return -EPROBE_DEFER; if (gpio_is_valid(host->ncfg->wp_gpio) && gpio_request(host->ncfg->wp_gpio, "NAND WP")) { dev_err(&pdev->dev, "GPIO not available\n"); return -EBUSY; } lpc32xx_wp_disable(host); host->pdata = dev_get_platdata(&pdev->dev); mtd = &host->mtd; chip = &host->nand_chip; chip->priv = host; mtd->priv = chip; mtd->owner = THIS_MODULE; mtd->dev.parent = &pdev->dev; /* Get NAND clock */ host->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(host->clk)) { dev_err(&pdev->dev, "Clock failure\n"); res = -ENOENT; goto err_exit1; } clk_enable(host->clk); /* Set NAND IO addresses and command/ready functions */ chip->IO_ADDR_R = SLC_DATA(host->io_base); chip->IO_ADDR_W = SLC_DATA(host->io_base); chip->cmd_ctrl = lpc32xx_nand_cmd_ctrl; chip->dev_ready = lpc32xx_nand_device_ready; chip->chip_delay = 20; /* 20us command delay time */ /* Init NAND controller */ lpc32xx_nand_setup(host); platform_set_drvdata(pdev, host); /* NAND callbacks for LPC32xx SLC hardware */ chip->ecc.mode = NAND_ECC_HW_SYNDROME; chip->read_byte = lpc32xx_nand_read_byte; chip->read_buf = lpc32xx_nand_read_buf; chip->write_buf = lpc32xx_nand_write_buf; chip->ecc.read_page_raw = lpc32xx_nand_read_page_raw_syndrome; chip->ecc.read_page = lpc32xx_nand_read_page_syndrome; chip->ecc.write_page_raw = lpc32xx_nand_write_page_raw_syndrome; chip->ecc.write_page = lpc32xx_nand_write_page_syndrome; chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome; chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome; chip->ecc.calculate = lpc32xx_nand_ecc_calculate; chip->ecc.correct = nand_correct_data; chip->ecc.strength = 1; chip->ecc.hwctl = lpc32xx_nand_ecc_enable; /* bitflip_threshold's default is defined as ecc_strength anyway. * Unfortunately, it is set only later at add_mtd_device(). Meanwhile * being 0, it causes bad block table scanning errors in * nand_scan_tail(), so preparing it here already. */ mtd->bitflip_threshold = chip->ecc.strength; /* * Allocate a large enough buffer for a single huge page plus * extra space for the spare area and ECC storage area */ host->dma_buf_len = LPC32XX_DMA_DATA_SIZE + LPC32XX_ECC_SAVE_SIZE; host->data_buf = devm_kzalloc(&pdev->dev, host->dma_buf_len, GFP_KERNEL); if (host->data_buf == NULL) { dev_err(&pdev->dev, "Error allocating memory\n"); res = -ENOMEM; goto err_exit2; } res = lpc32xx_nand_dma_setup(host); if (res) { res = -EIO; goto err_exit2; } /* Find NAND device */ if (nand_scan_ident(mtd, 1, NULL)) { res = -ENXIO; goto err_exit3; } /* OOB and ECC CPU and DMA work areas */ host->ecc_buf = (uint32_t *)(host->data_buf + LPC32XX_DMA_DATA_SIZE); /* * Small page FLASH has a unique OOB layout, but large and huge * page FLASH use the standard layout. Small page FLASH uses a * custom BBT marker layout. */ if (mtd->writesize <= 512) chip->ecc.layout = &lpc32xx_nand_oob_16; /* These sizes remain the same regardless of page size */ chip->ecc.size = 256; chip->ecc.bytes = LPC32XX_SLC_DEV_ECC_BYTES; chip->ecc.prepad = chip->ecc.postpad = 0; /* Avoid extra scan if using BBT, setup BBT support */ if (host->ncfg->use_bbt) { chip->bbt_options |= NAND_BBT_USE_FLASH; /* * Use a custom BBT marker setup for small page FLASH that * won't interfere with the ECC layout. Large and huge page * FLASH use the standard layout. */ if (mtd->writesize <= 512) { chip->bbt_td = &bbt_smallpage_main_descr; chip->bbt_md = &bbt_smallpage_mirror_descr; } } /* * Fills out all the uninitialized function pointers with the defaults */ if (nand_scan_tail(mtd)) { res = -ENXIO; goto err_exit3; } mtd->name = "nxp_lpc3220_slc"; ppdata.of_node = pdev->dev.of_node; res = mtd_device_parse_register(mtd, NULL, &ppdata, host->ncfg->parts, host->ncfg->num_parts); if (!res) return res; nand_release(mtd); err_exit3: dma_release_channel(host->dma_chan); err_exit2: clk_disable(host->clk); clk_put(host->clk); err_exit1: lpc32xx_wp_enable(host); gpio_free(host->ncfg->wp_gpio); return res; }
static int altera_tse_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); struct altera_tse_priv *priv = dev_get_priv(dev); void *blob = (void *)gd->fdt_blob; int node = dev->of_offset; const char *list, *end; const fdt32_t *cell; void *base, *desc_mem = NULL; unsigned long addr, size; int parent, addrc, sizec; int len, idx; int ret; priv->dma_type = dev_get_driver_data(dev); if (priv->dma_type == ALT_SGDMA) priv->ops = &tse_sgdma_ops; else priv->ops = &tse_msgdma_ops; /* * decode regs. there are multiple reg tuples, and they need to * match with reg-names. */ parent = fdt_parent_offset(blob, node); of_bus_default_count_cells(blob, parent, &addrc, &sizec); list = fdt_getprop(blob, node, "reg-names", &len); if (!list) return -ENOENT; end = list + len; cell = fdt_getprop(blob, node, "reg", &len); if (!cell) return -ENOENT; idx = 0; while (list < end) { addr = fdt_translate_address((void *)blob, node, cell + idx); size = fdt_addr_to_cpu(cell[idx + addrc]); base = map_physmem(addr, size, MAP_NOCACHE); len = strlen(list); if (strcmp(list, "control_port") == 0) priv->mac_dev = base; else if (strcmp(list, "rx_csr") == 0) priv->sgdma_rx = base; else if (strcmp(list, "rx_desc") == 0) priv->rx_desc = base; else if (strcmp(list, "rx_resp") == 0) priv->rx_resp = base; else if (strcmp(list, "tx_csr") == 0) priv->sgdma_tx = base; else if (strcmp(list, "tx_desc") == 0) priv->tx_desc = base; else if (strcmp(list, "s1") == 0) desc_mem = base; idx += addrc + sizec; list += (len + 1); } /* decode fifo depth */ priv->rx_fifo_depth = fdtdec_get_int(blob, node, "rx-fifo-depth", 0); priv->tx_fifo_depth = fdtdec_get_int(blob, node, "tx-fifo-depth", 0); /* decode phy */ addr = fdtdec_get_int(blob, node, "phy-handle", 0); addr = fdt_node_offset_by_phandle(blob, addr); priv->phyaddr = fdtdec_get_int(blob, addr, "reg", 0); /* init desc */ if (priv->dma_type == ALT_SGDMA) { len = sizeof(struct alt_sgdma_descriptor) * 4; if (!desc_mem) { desc_mem = dma_alloc_coherent(len, &addr); if (!desc_mem) return -ENOMEM; } memset(desc_mem, 0, len); priv->tx_desc = desc_mem; priv->rx_desc = priv->tx_desc + 2 * sizeof(struct alt_sgdma_descriptor); } /* allocate recv packet buffer */ priv->rx_buf = malloc_cache_aligned(PKTSIZE_ALIGN); if (!priv->rx_buf) return -ENOMEM; /* stop controller */ debug("Reset TSE & SGDMAs\n"); altera_tse_stop(dev); /* start the phy */ priv->interface = pdata->phy_interface; tse_mdio_init(dev->name, priv); priv->bus = miiphy_get_dev_by_name(dev->name); ret = tse_phy_init(priv, dev); return ret; }
static int serial_omap_probe(struct platform_device *pdev) { struct omap_uart_port_info *omap_up_info = dev_get_platdata(&pdev->dev); struct uart_omap_port *up; struct resource *mem; void __iomem *base; int uartirq = 0; int wakeirq = 0; int ret; enum of_gpio_flags flags; int gpio_sel; unsigned long gpio_flags; /* The optional wakeirq may be specified in the board dts file */ if (pdev->dev.of_node) { uartirq = irq_of_parse_and_map(pdev->dev.of_node, 0); if (!uartirq) return -EPROBE_DEFER; wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1); omap_up_info = of_get_uart_port_info(&pdev->dev); pdev->dev.platform_data = omap_up_info; } else { uartirq = platform_get_irq(pdev, 0); if (uartirq < 0) return -EPROBE_DEFER; } /* Check if the UART needs to be selected */ gpio_sel = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); if (gpio_is_valid(gpio_sel)) { dev_dbg(&pdev->dev, "using gpio %d for uart%d_sel\n", gpio_sel, pdev->id); gpio_flags = (flags & OF_GPIO_ACTIVE_LOW) ? GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH; ret = devm_gpio_request_one(&pdev->dev, gpio_sel, gpio_flags, "uart_sel"); if (ret) { dev_err(&pdev->dev, "gpio%d request failed, ret %d\n", gpio_sel, ret); return ret; } } else if (gpio_sel == -EPROBE_DEFER) { return -EPROBE_DEFER; } up = devm_kzalloc(&pdev->dev, sizeof(*up), GFP_KERNEL); if (!up) return -ENOMEM; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(&pdev->dev, mem); if (IS_ERR(base)) return PTR_ERR(base); up->dev = &pdev->dev; up->port.dev = &pdev->dev; up->port.type = PORT_OMAP; up->port.iotype = UPIO_MEM; up->port.irq = uartirq; up->wakeirq = wakeirq; if (!up->wakeirq) dev_info(up->port.dev, "no wakeirq for uart%d\n", up->port.line); up->port.regshift = 2; up->port.fifosize = 64; up->port.ops = &serial_omap_pops; if (pdev->dev.of_node) up->port.line = of_alias_get_id(pdev->dev.of_node, "serial"); else up->port.line = pdev->id; if (up->port.line < 0) { dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", up->port.line); ret = -ENODEV; goto err_port_line; } if (up->port.line >= OMAP_MAX_HSUART_PORTS) { dev_err(&pdev->dev, "uart ID %d > MAX %d.\n", up->port.line, OMAP_MAX_HSUART_PORTS); ret = -ENXIO; goto err_port_line; } ret = serial_omap_probe_rs485(up, pdev->dev.of_node); if (ret < 0) goto err_rs485; sprintf(up->name, "OMAP UART%d", up->port.line); up->port.mapbase = mem->start; up->port.membase = base; up->port.flags = omap_up_info->flags; up->port.uartclk = omap_up_info->uartclk; if (!up->port.uartclk) { up->port.uartclk = DEFAULT_CLK_SPEED; dev_warn(&pdev->dev, "No clock speed specified: using default: %d\n", DEFAULT_CLK_SPEED); } up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; up->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; pm_qos_add_request(&up->pm_qos_request, PM_QOS_CPU_DMA_LATENCY, up->latency); INIT_WORK(&up->qos_work, serial_omap_uart_qos_work); platform_set_drvdata(pdev, up); if (omap_up_info->autosuspend_timeout == 0) omap_up_info->autosuspend_timeout = -1; device_init_wakeup(up->dev, true); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, omap_up_info->autosuspend_timeout); pm_runtime_irq_safe(&pdev->dev); pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev); omap_serial_fill_features_erratas(up); ui[up->port.line] = up; serial_omap_add_console_port(up); ret = uart_add_one_port(&serial_omap_reg, &up->port); if (ret != 0) goto err_add_port; pm_runtime_mark_last_busy(up->dev); pm_runtime_put_autosuspend(up->dev); return 0; err_add_port: pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); err_rs485: err_port_line: dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n", pdev->id, __func__, ret); return ret; }
static int atcpit_timer_ofdata_to_platdata(struct udevice *dev) { struct atcpit_timer_platdata *plat = dev_get_platdata(dev); plat->regs = map_physmem(devfdt_get_addr(dev) , 0x100 , MAP_NOCACHE); return 0; }
static int __devinit p3_bat_probe(struct platform_device *pdev) { struct p3_battery_platform_data *pdata = dev_get_platdata(&pdev->dev); struct battery_data *battery; int ret; unsigned long trigger; int irq_num; if (!pdata) { pr_err("%s : No platform data\n", __func__); return -EINVAL; } battery = kzalloc(sizeof(*battery), GFP_KERNEL); if (!battery) return -ENOMEM; battery->pdata = pdata; battery->pdata->init_charger_gpio(); platform_set_drvdata(pdev, battery); test_batterydata = battery; battery->present = 1; battery->info.level = 100; battery->info.charging_source = CHARGER_BATTERY; battery->info.batt_health = POWER_SUPPLY_HEALTH_GOOD; #if !defined(CONFIG_MACH_SAMSUNG_P4) || !defined(CONFIG_MACH_SAMSUNG_P4WIFI) || !defined(CONFIG_MACH_SAMSUNG_P4LTE) battery->is_first_check = true; #endif battery->psy_battery.name = "battery"; battery->psy_battery.type = POWER_SUPPLY_TYPE_BATTERY; battery->psy_battery.properties = p3_battery_properties; battery->psy_battery.num_properties = ARRAY_SIZE(p3_battery_properties); battery->psy_battery.get_property = p3_bat_get_property; battery->psy_usb.name = "usb"; battery->psy_usb.type = POWER_SUPPLY_TYPE_USB; battery->psy_usb.supplied_to = supply_list; battery->psy_usb.num_supplicants = ARRAY_SIZE(supply_list); battery->psy_usb.properties = p3_power_properties; battery->psy_usb.num_properties = ARRAY_SIZE(p3_power_properties); battery->psy_usb.get_property = p3_usb_get_property; battery->psy_ac.name = "ac"; battery->psy_ac.type = POWER_SUPPLY_TYPE_MAINS; battery->psy_ac.supplied_to = supply_list; battery->psy_ac.num_supplicants = ARRAY_SIZE(supply_list); battery->psy_ac.properties = p3_power_properties; battery->psy_ac.num_properties = ARRAY_SIZE(p3_power_properties); battery->psy_ac.get_property = p3_ac_get_property; mutex_init(&battery->work_lock); wake_lock_init(&battery->vbus_wake_lock, WAKE_LOCK_SUSPEND, "vbus wake lock"); wake_lock_init(&battery->work_wake_lock, WAKE_LOCK_SUSPEND, "batt_work wake lock"); wake_lock_init(&battery->cable_wake_lock, WAKE_LOCK_SUSPEND, "temp wake lock"); wake_lock_init(&battery->fullcharge_wake_lock, WAKE_LOCK_SUSPEND, "fullcharge wake lock"); #ifdef CONFIG_TARGET_LOCALE_KOR wake_lock_init(&battery->low_comp_wake_lock, WAKE_LOCK_SUSPEND, "low comp wake lock"); #endif #ifdef __TEST_DEVICE_DRIVER__ wake_lock_init(&battery->wake_lock_for_dev, WAKE_LOCK_SUSPEND, "test mode wake lock"); #endif /* __TEST_DEVICE_DRIVER__ */ INIT_WORK(&battery->battery_work, p3_bat_work); INIT_WORK(&battery->cable_work, p3_cable_work); INIT_DELAYED_WORK(&battery->fuelgauge_work, fuelgauge_work_handler); INIT_DELAYED_WORK(&battery->fullcharging_work, fullcharging_work_handler); INIT_DELAYED_WORK(&battery->full_comp_work, full_comp_work_handler); INIT_DELAYED_WORK(&battery->TA_work, p3_TA_work_handler); #ifdef CONFIG_TARGET_LOCALE_KOR INIT_DELAYED_WORK(&battery->low_comp_work, low_comp_work_handler); #endif battery->p3_TA_workqueue = create_singlethread_workqueue( "p3_TA_workqueue"); #ifdef CONFIG_TARGET_LOCALE_KOR battery->low_bat_comp_workqueue = create_singlethread_workqueue( "low_bat_comp_workqueue"); #endif if (!battery->p3_TA_workqueue) { pr_err("Failed to create single workqueue\n"); ret = -ENOMEM; goto err_workqueue_init; } #ifdef CONFIG_TARGET_LOCALE_KOR if (!battery->low_bat_comp_workqueue) { pr_err("Failed to create low_bat_comp_workqueue workqueue\n"); ret = -ENOMEM; goto err_workqueue_init; } #endif battery->last_poll = alarm_get_elapsed_realtime(); alarm_init(&battery->alarm, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, p3_battery_alarm); ret = power_supply_register(&pdev->dev, &battery->psy_battery); if (ret) { pr_err("Failed to register battery power supply.\n"); goto err_battery_psy_register; } ret = power_supply_register(&pdev->dev, &battery->psy_usb); if (ret) { pr_err("Failed to register USB power supply.\n"); goto err_usb_psy_register; } ret = power_supply_register(&pdev->dev, &battery->psy_ac); if (ret) { pr_err("Failed to register AC power supply.\n"); goto err_ac_psy_register; } /* create sec detail attributes */ p3_bat_create_attrs(battery->psy_battery.dev); #ifdef __TEST_DEVICE_DRIVER__ sec_batt_test_create_attrs(battery->psy_ac.dev); #endif /* __TEST_DEVICE_DRIVER__ */ battery->p3_battery_initial = 1; battery->low_batt_boot_flag = 0; battery->connect_irq = gpio_to_irq(pdata->charger.connect_line); if (check_ta_conn(battery)) trigger = IRQF_TRIGGER_HIGH; else trigger = IRQF_TRIGGER_LOW; if (request_irq(battery->connect_irq, p3_TA_interrupt_handler, trigger, "TA_CON intr", battery)) { pr_err("p3_TA_interrupt_handler register failed!\n"); goto err_charger_irq; } disable_irq(battery->connect_irq); // Get initial cable status and enable connection irq. p3_get_cable_status(battery); battery->previous_cable_status = battery->current_cable_status; enable_irq(battery->connect_irq); if (check_ta_conn(battery) && check_UV_charging_case()) battery->low_batt_boot_flag = 1; mutex_lock(&battery->work_lock); fg_alert_init(); mutex_unlock(&battery->work_lock); p3_bat_status_update(&battery->psy_battery); p3_cable_check_status(battery); /* before enable fullcharge interrupt, check fullcharge */ if ((battery->info.charging_source == CHARGER_AC || (battery->info.charging_source == CHARGER_USB && battery->info.force_usb_charging)) && battery->info.charging_enabled && gpio_get_value(pdata->charger.fullcharge_line) == 1) p3_cable_charging(battery); /* Request IRQ */ irq_num = gpio_to_irq(max17042_chip_data->pdata->fuel_alert_line); if (request_irq(irq_num, low_battery_isr, IRQF_TRIGGER_FALLING, "FUEL_ALRT irq", battery)) pr_err("Can NOT request irq 'IRQ_FUEL_ALERT' %d ", irq_num); #ifdef CONFIG_SAMSUNG_LPM_MODE lpm_mode_check(battery); #endif return 0; err_charger_irq: alarm_cancel(&battery->alarm); power_supply_unregister(&battery->psy_ac); err_ac_psy_register: power_supply_unregister(&battery->psy_usb); err_usb_psy_register: power_supply_unregister(&battery->psy_battery); err_battery_psy_register: destroy_workqueue(battery->p3_TA_workqueue); #ifdef CONFIG_TARGET_LOCALE_KOR destroy_workqueue(battery->low_bat_comp_workqueue); #endif err_workqueue_init: wake_lock_destroy(&battery->vbus_wake_lock); wake_lock_destroy(&battery->work_wake_lock); wake_lock_destroy(&battery->cable_wake_lock); wake_lock_destroy(&battery->fullcharge_wake_lock); #ifdef CONFIG_TARGET_LOCALE_KOR wake_lock_destroy(&battery->low_comp_wake_lock); #endif mutex_destroy(&battery->work_lock); kfree(battery); return ret; }
static int fimc_is_probe(struct platform_device *pdev) { struct exynos_platform_fimc_is *pdata; #if defined (ENABLE_IS_CORE) || defined (USE_MCUCTL) struct resource *mem_res; struct resource *regs_res; #endif struct fimc_is_core *core; int ret = -ENODEV; #ifndef ENABLE_IS_CORE int i; #endif u32 stream; struct pinctrl_state *s; probe_info("%s:start(%ld, %ld)\n", __func__, sizeof(struct fimc_is_core), sizeof(struct fimc_is_video_ctx)); core = kzalloc(sizeof(struct fimc_is_core), GFP_KERNEL); if (!core) { probe_err("core is NULL"); return -ENOMEM; } fimc_is_dev = &pdev->dev; dev_set_drvdata(fimc_is_dev, core); pdata = dev_get_platdata(&pdev->dev); if (!pdata) { #ifdef CONFIG_OF ret = fimc_is_parse_dt(pdev); if (ret) { err("fimc_is_parse_dt is fail(%d)", ret); return ret; } pdata = dev_get_platdata(&pdev->dev); #else BUG(); #endif } #ifdef USE_ION_ALLOC core->fimc_ion_client = ion_client_create(ion_exynos, "fimc-is"); #endif core->pdev = pdev; core->pdata = pdata; core->current_position = SENSOR_POSITION_REAR; device_init_wakeup(&pdev->dev, true); /* for mideaserver force down */ atomic_set(&core->rsccount, 0); #if defined (ENABLE_IS_CORE) || defined (USE_MCUCTL) mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem_res) { probe_err("Failed to get io memory region(%p)", mem_res); goto p_err1; } regs_res = request_mem_region(mem_res->start, resource_size(mem_res), pdev->name); if (!regs_res) { probe_err("Failed to request io memory region(%p)", regs_res); goto p_err1; } core->regs_res = regs_res; core->regs = ioremap_nocache(mem_res->start, resource_size(mem_res)); if (!core->regs) { probe_err("Failed to remap io region(%p)", core->regs); goto p_err2; } #else core->regs_res = NULL; core->regs = NULL; #endif #ifdef ENABLE_IS_CORE core->irq = platform_get_irq(pdev, 0); if (core->irq < 0) { probe_err("Failed to get irq(%d)", core->irq); goto p_err3; } #endif ret = pdata->clk_get(&pdev->dev); if (ret) { probe_err("clk_get is fail(%d)", ret); goto p_err3; } ret = fimc_is_mem_probe(&core->resourcemgr.mem, core->pdev); if (ret) { probe_err("fimc_is_mem_probe is fail(%d)", ret); goto p_err3; } ret = fimc_is_resourcemgr_probe(&core->resourcemgr, core); if (ret) { probe_err("fimc_is_resourcemgr_probe is fail(%d)", ret); goto p_err3; } ret = fimc_is_interface_probe(&core->interface, &core->resourcemgr.minfo, (ulong)core->regs, core->irq, core); if (ret) { probe_err("fimc_is_interface_probe is fail(%d)", ret); goto p_err3; } ret = fimc_is_debug_probe(); if (ret) { probe_err("fimc_is_deubg_probe is fail(%d)", ret); goto p_err3; } ret = fimc_is_vender_probe(&core->vender); if (ret) { probe_err("fimc_is_vender_probe is fail(%d)", ret); goto p_err3; } /* group initialization */ ret = fimc_is_groupmgr_probe(&core->groupmgr); if (ret) { probe_err("fimc_is_groupmgr_probe is fail(%d)", ret); goto p_err3; } for (stream = 0; stream < FIMC_IS_STREAM_COUNT; ++stream) { ret = fimc_is_ischain_probe(&core->ischain[stream], &core->interface, &core->resourcemgr, &core->groupmgr, &core->resourcemgr.mem, core->pdev, stream); if (ret) { probe_err("fimc_is_ischain_probe(%d) is fail(%d)", stream, ret); goto p_err3; } #ifndef ENABLE_IS_CORE core->ischain[stream].hardware = &core->hardware; #endif } ret = v4l2_device_register(&pdev->dev, &core->v4l2_dev); if (ret) { dev_err(&pdev->dev, "failed to register fimc-is v4l2 device\n"); goto p_err3; } #ifdef SOC_30S /* video entity - 3a0 */ fimc_is_30s_video_probe(core); #endif #ifdef SOC_30C /* video entity - 3a0 capture */ fimc_is_30c_video_probe(core); #endif #ifdef SOC_30P /* video entity - 3a0 preview */ fimc_is_30p_video_probe(core); #endif #ifdef SOC_31S /* video entity - 3a1 */ fimc_is_31s_video_probe(core); #endif #ifdef SOC_31C /* video entity - 3a1 capture */ fimc_is_31c_video_probe(core); #endif #ifdef SOC_31P /* video entity - 3a1 preview */ fimc_is_31p_video_probe(core); #endif #ifdef SOC_I0S /* video entity - isp0 */ fimc_is_i0s_video_probe(core); #endif #ifdef SOC_I0C /* video entity - isp0 capture */ fimc_is_i0c_video_probe(core); #endif #ifdef SOC_I0P /* video entity - isp0 preview */ fimc_is_i0p_video_probe(core); #endif #ifdef SOC_I1S /* video entity - isp1 */ fimc_is_i1s_video_probe(core); #endif #ifdef SOC_I1C /* video entity - isp1 capture */ fimc_is_i1c_video_probe(core); #endif #ifdef SOC_I1P /* video entity - isp1 preview */ fimc_is_i1p_video_probe(core); #endif #ifdef SOC_DIS /* video entity - dis */ fimc_is_dis_video_probe(core); #endif #ifdef SOC_SCC /* video entity - scc */ fimc_is_scc_video_probe(core); #endif #ifdef SOC_SCP /* video entity - scp */ fimc_is_scp_video_probe(core); #endif #ifdef SOC_MCS /* video entity - scp */ fimc_is_m0s_video_probe(core); fimc_is_m1s_video_probe(core); fimc_is_m0p_video_probe(core); fimc_is_m1p_video_probe(core); fimc_is_m2p_video_probe(core); fimc_is_m3p_video_probe(core); fimc_is_m4p_video_probe(core); #endif platform_set_drvdata(pdev, core); #ifndef ENABLE_IS_CORE ret = fimc_is_interface_ischain_probe(&core->interface_ischain, &core->hardware, &core->resourcemgr, core->pdev, (ulong)core->regs); if (ret) { dev_err(&pdev->dev, "interface_ischain_probe fail\n"); goto p_err1; } ret = fimc_is_hardware_probe(&core->hardware, &core->interface, &core->interface_ischain); if (ret) { dev_err(&pdev->dev, "hardware_probe fail\n"); goto p_err1; } /* set sysfs for set position to actuator */ sysfs_actuator.init_step = 0; for (i = 0; i < INIT_MAX_SETTING; i++) { sysfs_actuator.init_positions[i] = -1; sysfs_actuator.init_delays[i] = -1; } #endif #if defined(CONFIG_SOC_EXYNOS5430) || defined(CONFIG_SOC_EXYNOS5433) #if defined(CONFIG_VIDEOBUF2_ION) if (core->resourcemgr.mem.alloc_ctx) vb2_ion_attach_iommu(core->resourcemgr.mem.alloc_ctx); #endif #endif EXYNOS_MIF_ADD_NOTIFIER(&exynos_fimc_is_mif_throttling_nb); #if defined(CONFIG_PM_RUNTIME) pm_runtime_enable(&pdev->dev); #endif #ifdef ENABLE_FAULT_HANDLER #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)) exynos_sysmmu_set_fault_handler(fimc_is_dev, fimc_is_fault_handler); #else iovmm_set_fault_handler(fimc_is_dev, fimc_is_fault_handler, NULL); #endif #endif /* set sysfs for debuging */ sysfs_debug.en_clk_gate = 0; sysfs_debug.en_dvfs = 1; #ifdef ENABLE_CLOCK_GATE sysfs_debug.en_clk_gate = 1; #ifdef HAS_FW_CLOCK_GATE sysfs_debug.clk_gate_mode = CLOCK_GATE_MODE_FW; #else sysfs_debug.clk_gate_mode = CLOCK_GATE_MODE_HOST; #endif #endif ret = sysfs_create_group(&core->pdev->dev.kobj, &fimc_is_debug_attr_group); s = pinctrl_lookup_state(pdata->pinctrl, "release"); if (pinctrl_select_state(pdata->pinctrl, s) < 0) { probe_err("pinctrl_select_state is fail\n"); goto p_err3; } probe_info("%s:end\n", __func__); return 0; p_err3: iounmap(core->regs); #if defined (ENABLE_IS_CORE) || defined (USE_MCUCTL) p_err2: release_mem_region(regs_res->start, resource_size(regs_res)); #endif p_err1: kfree(core); return ret; }
static int __devinit rc5t583_regulator_probe(struct platform_device *pdev) { struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent); struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev); struct regulator_init_data *reg_data; struct regulator_config config = { }; struct rc5t583_regulator *reg = NULL; struct rc5t583_regulator *regs; struct regulator_dev *rdev; struct rc5t583_regulator_info *ri; int ret; int id; if (!pdata) { dev_err(&pdev->dev, "No platform data, exiting...\n"); return -ENODEV; } regs = devm_kzalloc(&pdev->dev, RC5T583_REGULATOR_MAX * sizeof(struct rc5t583_regulator), GFP_KERNEL); if (!regs) { dev_err(&pdev->dev, "Memory allocation failed exiting..\n"); return -ENOMEM; } for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) { reg_data = pdata->reg_init_data[id]; /* No need to register if there is no regulator data */ if (!reg_data) continue; reg = ®s[id]; ri = &rc5t583_reg_info[id]; reg->reg_info = ri; reg->mfd = rc5t583; reg->dev = &pdev->dev; if (ri->deepsleep_id == RC5T583_DS_NONE) goto skip_ext_pwr_config; ret = rc5t583_ext_power_req_config(rc5t583->dev, ri->deepsleep_id, pdata->regulator_ext_pwr_control[id], pdata->regulator_deepsleep_slot[id]); /* * Configuring external control is not a major issue, * just give warning. */ if (ret < 0) dev_warn(&pdev->dev, "Failed to configure ext control %d\n", id); skip_ext_pwr_config: config.dev = &pdev->dev; config.init_data = reg_data; config.driver_data = reg; config.regmap = rc5t583->regmap; rdev = regulator_register(&ri->desc, &config); if (IS_ERR(rdev)) { dev_err(&pdev->dev, "Failed to register regulator %s\n", ri->desc.name); ret = PTR_ERR(rdev); goto clean_exit; } reg->rdev = rdev; } platform_set_drvdata(pdev, regs); return 0; clean_exit: while (--id >= 0) regulator_unregister(regs[id].rdev); return ret; }
static int gp2a_probe(struct i2c_client *client, const struct i2c_device_id *id) { const struct gp2a_platform_data *pdata = dev_get_platdata(&client->dev); struct gp2a_data *dt; int error; if (!pdata) return -EINVAL; if (pdata->hw_setup) { error = pdata->hw_setup(client); if (error < 0) return error; } error = gpio_request_one(pdata->vout_gpio, GPIOF_IN, GP2A_I2C_NAME); if (error) goto err_hw_shutdown; dt = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL); if (!dt) { error = -ENOMEM; goto err_free_gpio; } dt->pdata = pdata; dt->i2c_client = client; error = gp2a_initialize(dt); if (error < 0) goto err_free_mem; dt->input = input_allocate_device(); if (!dt->input) { error = -ENOMEM; goto err_free_mem; } input_set_drvdata(dt->input, dt); dt->input->open = gp2a_device_open; dt->input->close = gp2a_device_close; dt->input->name = GP2A_I2C_NAME; dt->input->id.bustype = BUS_I2C; dt->input->dev.parent = &client->dev; input_set_capability(dt->input, EV_SW, SW_FRONT_PROXIMITY); error = request_threaded_irq(client->irq, NULL, gp2a_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, GP2A_I2C_NAME, dt); if (error) { dev_err(&client->dev, "irq request failed\n"); goto err_free_input_dev; } error = input_register_device(dt->input); if (error) { dev_err(&client->dev, "device registration failed\n"); goto err_free_irq; } device_init_wakeup(&client->dev, pdata->wakeup); i2c_set_clientdata(client, dt); return 0; err_free_irq: free_irq(client->irq, dt); err_free_input_dev: input_free_device(dt->input); err_free_mem: kfree(dt); err_free_gpio: gpio_free(pdata->vout_gpio); err_hw_shutdown: if (pdata->hw_shutdown) pdata->hw_shutdown(client); return error; }
static int bgpio_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *r; void __iomem *dat; void __iomem *set; void __iomem *clr; void __iomem *dirout; void __iomem *dirin; unsigned long sz; unsigned long flags = pdev->id_entry->driver_data; int err; struct gpio_chip *gc; struct bgpio_pdata *pdata = dev_get_platdata(dev); r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); if (!r) return -EINVAL; sz = resource_size(r); dat = bgpio_map(pdev, "dat", sz); if (IS_ERR(dat)) return PTR_ERR(dat); set = bgpio_map(pdev, "set", sz); if (IS_ERR(set)) return PTR_ERR(set); clr = bgpio_map(pdev, "clr", sz); if (IS_ERR(clr)) return PTR_ERR(clr); dirout = bgpio_map(pdev, "dirout", sz); if (IS_ERR(dirout)) return PTR_ERR(dirout); dirin = bgpio_map(pdev, "dirin", sz); if (IS_ERR(dirin)) return PTR_ERR(dirin); gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL); if (!gc) return -ENOMEM; err = bgpio_init(gc, dev, sz, dat, set, clr, dirout, dirin, flags); if (err) return err; if (pdata) { if (pdata->label) gc->label = pdata->label; gc->base = pdata->base; if (pdata->ngpio > 0) gc->ngpio = pdata->ngpio; } platform_set_drvdata(pdev, gc); return gpiochip_add_data(gc, NULL); }
static int m48t59_rtc_probe(struct platform_device *pdev) { struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); struct m48t59_private *m48t59 = NULL; struct resource *res; int ret = -ENOMEM; char *name; const struct rtc_class_ops *ops; struct nvmem_config nvmem_cfg = { .name = "m48t59-", .word_size = 1, .stride = 1, .reg_read = m48t59_nvram_read, .reg_write = m48t59_nvram_write, .priv = pdev, }; /* This chip could be memory-mapped or I/O-mapped */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (!res) return -EINVAL; } if (res->flags & IORESOURCE_IO) { /* If we are I/O-mapped, the platform should provide * the operations accessing chip registers. */ if (!pdata || !pdata->write_byte || !pdata->read_byte) return -EINVAL; } else if (res->flags & IORESOURCE_MEM) { /* we are memory-mapped */ if (!pdata) { pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return -ENOMEM; /* Ensure we only kmalloc platform data once */ pdev->dev.platform_data = pdata; } if (!pdata->type) pdata->type = M48T59RTC_TYPE_M48T59; /* Try to use the generic memory read/write ops */ if (!pdata->write_byte) pdata->write_byte = m48t59_mem_writeb; if (!pdata->read_byte) pdata->read_byte = m48t59_mem_readb; } m48t59 = devm_kzalloc(&pdev->dev, sizeof(*m48t59), GFP_KERNEL); if (!m48t59) return -ENOMEM; m48t59->ioaddr = pdata->ioaddr; if (!m48t59->ioaddr) { /* ioaddr not mapped externally */ m48t59->ioaddr = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!m48t59->ioaddr) return ret; } /* Try to get irq number. We also can work in * the mode without IRQ. */ m48t59->irq = platform_get_irq(pdev, 0); if (m48t59->irq <= 0) m48t59->irq = NO_IRQ; if (m48t59->irq != NO_IRQ) { ret = devm_request_irq(&pdev->dev, m48t59->irq, m48t59_rtc_interrupt, IRQF_SHARED, "rtc-m48t59", &pdev->dev); if (ret) return ret; } switch (pdata->type) { case M48T59RTC_TYPE_M48T59: name = "m48t59"; ops = &m48t59_rtc_ops; pdata->offset = 0x1ff0; break; case M48T59RTC_TYPE_M48T02: name = "m48t02"; ops = &m48t02_rtc_ops; pdata->offset = 0x7f0; break; case M48T59RTC_TYPE_M48T08: name = "m48t08"; ops = &m48t02_rtc_ops; pdata->offset = 0x1ff0; break; default: dev_err(&pdev->dev, "Unknown RTC type\n"); return -ENODEV; } spin_lock_init(&m48t59->lock); platform_set_drvdata(pdev, m48t59); m48t59->rtc = devm_rtc_allocate_device(&pdev->dev); if (IS_ERR(m48t59->rtc)) return PTR_ERR(m48t59->rtc); m48t59->rtc->nvram_old_abi = true; m48t59->rtc->ops = ops; nvmem_cfg.size = pdata->offset; ret = rtc_nvmem_register(m48t59->rtc, &nvmem_cfg); if (ret) return ret; ret = rtc_register_device(m48t59->rtc); if (ret) return ret; return 0; } /* work with hotplug and coldplug */ MODULE_ALIAS("platform:rtc-m48t59"); static struct platform_driver m48t59_rtc_driver = { .driver = { .name = "rtc-m48t59", }, .probe = m48t59_rtc_probe, };
static int max8997_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max8997_dev *max8997; struct max8997_platform_data *pdata = dev_get_platdata(&i2c->dev); int ret = 0; max8997 = devm_kzalloc(&i2c->dev, sizeof(struct max8997_dev), GFP_KERNEL); if (max8997 == NULL) return -ENOMEM; i2c_set_clientdata(i2c, max8997); max8997->dev = &i2c->dev; max8997->i2c = i2c; max8997->type = max8997_i2c_get_driver_data(i2c, id); max8997->irq = i2c->irq; if (IS_ENABLED(CONFIG_OF) && max8997->dev->of_node) { pdata = max8997_i2c_parse_dt_pdata(max8997->dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); } if (!pdata) return ret; max8997->pdata = pdata; max8997->ono = pdata->ono; mutex_init(&max8997->iolock); max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); i2c_set_clientdata(max8997->rtc, max8997); max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max8997->haptic, max8997); max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max8997->muic, max8997); pm_runtime_set_active(max8997->dev); max8997_irq_init(max8997); ret = mfd_add_devices(max8997->dev, -1, max8997_devs, ARRAY_SIZE(max8997_devs), NULL, 0, NULL); if (ret < 0) { dev_err(max8997->dev, "failed to add MFD devices %d\n", ret); goto err_mfd; } /* * TODO: enable others (flash, muic, rtc, battery, ...) and * check the return value */ /* MAX8997 has a power button input. */ device_init_wakeup(max8997->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max8997->dev); i2c_unregister_device(max8997->muic); i2c_unregister_device(max8997->haptic); i2c_unregister_device(max8997->rtc); return ret; }
static int max8997_haptic_probe(struct platform_device *pdev) { struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); const struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev); const struct max8997_haptic_platform_data *haptic_pdata = NULL; struct max8997_haptic *chip; struct input_dev *input_dev; int error; if (pdata) haptic_pdata = pdata->haptic_pdata; if (!haptic_pdata) { dev_err(&pdev->dev, "no haptic platform data\n"); return -EINVAL; } chip = kzalloc(sizeof(struct max8997_haptic), GFP_KERNEL); input_dev = input_allocate_device(); if (!chip || !input_dev) { dev_err(&pdev->dev, "unable to allocate memory\n"); error = -ENOMEM; goto err_free_mem; } INIT_WORK(&chip->work, max8997_haptic_play_effect_work); mutex_init(&chip->mutex); chip->client = iodev->haptic; chip->dev = &pdev->dev; chip->input_dev = input_dev; chip->pwm_period = haptic_pdata->pwm_period; chip->type = haptic_pdata->type; chip->mode = haptic_pdata->mode; chip->pwm_divisor = haptic_pdata->pwm_divisor; switch (chip->mode) { case MAX8997_INTERNAL_MODE: chip->internal_mode_pattern = haptic_pdata->internal_mode_pattern; chip->pattern_cycle = haptic_pdata->pattern_cycle; chip->pattern_signal_period = haptic_pdata->pattern_signal_period; break; case MAX8997_EXTERNAL_MODE: chip->pwm = pwm_request(haptic_pdata->pwm_channel_id, "max8997-haptic"); if (IS_ERR(chip->pwm)) { error = PTR_ERR(chip->pwm); dev_err(&pdev->dev, "unable to request PWM for haptic, error: %d\n", error); goto err_free_mem; } break; default: dev_err(&pdev->dev, "Invalid chip mode specified (%d)\n", chip->mode); error = -EINVAL; goto err_free_mem; } chip->regulator = regulator_get(&pdev->dev, "inmotor"); if (IS_ERR(chip->regulator)) { error = PTR_ERR(chip->regulator); dev_err(&pdev->dev, "unable to get regulator, error: %d\n", error); goto err_free_pwm; } input_dev->name = "max8997-haptic"; input_dev->id.version = 1; input_dev->dev.parent = &pdev->dev; input_dev->close = max8997_haptic_close; input_set_drvdata(input_dev, chip); input_set_capability(input_dev, EV_FF, FF_RUMBLE); error = input_ff_create_memless(input_dev, NULL, max8997_haptic_play_effect); if (error) { dev_err(&pdev->dev, "unable to create FF device, error: %d\n", error); goto err_put_regulator; } error = input_register_device(input_dev); if (error) { dev_err(&pdev->dev, "unable to register input device, error: %d\n", error); goto err_destroy_ff; } platform_set_drvdata(pdev, chip); return 0; err_destroy_ff: input_ff_destroy(input_dev); err_put_regulator: regulator_put(chip->regulator); err_free_pwm: if (chip->mode == MAX8997_EXTERNAL_MODE) pwm_free(chip->pwm); err_free_mem: input_free_device(input_dev); kfree(chip); return error; }
static int tps65910_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct tps65910 *tps65910; struct tps65910_board *pmic_plat_data; struct tps65910_board *of_pmic_plat_data = NULL; struct tps65910_platform_data *init_data; unsigned long chip_id = id->driver_data; int ret = 0; pmic_plat_data = dev_get_platdata(&i2c->dev); if (!pmic_plat_data && i2c->dev.of_node) { pmic_plat_data = tps65910_parse_dt(i2c, &chip_id); of_pmic_plat_data = pmic_plat_data; } if (!pmic_plat_data) return -EINVAL; init_data = devm_kzalloc(&i2c->dev, sizeof(*init_data), GFP_KERNEL); if (init_data == NULL) return -ENOMEM; tps65910 = devm_kzalloc(&i2c->dev, sizeof(*tps65910), GFP_KERNEL); if (tps65910 == NULL) return -ENOMEM; tps65910->of_plat_data = of_pmic_plat_data; i2c_set_clientdata(i2c, tps65910); tps65910->dev = &i2c->dev; tps65910->i2c_client = i2c; tps65910->id = chip_id; /* Work around silicon erratum SWCZ010: the tps65910 may miss the * first I2C transfer. So issue a dummy transfer before the first * real transfer. */ i2c_master_send(i2c, "", 1); tps65910->regmap = devm_regmap_init_i2c(i2c, &tps65910_regmap_config); if (IS_ERR(tps65910->regmap)) { ret = PTR_ERR(tps65910->regmap); dev_err(&i2c->dev, "regmap initialization failed: %d\n", ret); return ret; } init_data->irq = pmic_plat_data->irq; init_data->irq_base = pmic_plat_data->irq_base; tps65910_irq_init(tps65910, init_data->irq, init_data); tps65910_ck32k_init(tps65910, pmic_plat_data); tps65910_sleepinit(tps65910, pmic_plat_data); if (pmic_plat_data->pm_off && !pm_power_off) { tps65910_i2c_client = i2c; pm_power_off = tps65910_power_off; } ret = devm_mfd_add_devices(tps65910->dev, -1, tps65910s, ARRAY_SIZE(tps65910s), NULL, 0, regmap_irq_get_domain(tps65910->irq_data)); if (ret < 0) { dev_err(&i2c->dev, "mfd_add_devices failed: %d\n", ret); return ret; } return ret; }