static int __init cpubw_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct devfreq_dev_profile *p = &cpubw_profile; struct devfreq *df; u32 *data, ports[MAX_PATHS * 2]; int ret, len, i; if (of_find_property(dev->of_node, PROP_PORTS, &len)) { len /= sizeof(ports[0]); if (len % 2 || len > ARRAY_SIZE(ports)) { dev_err(dev, "Unexpected number of ports\n"); return -EINVAL; } ret = of_property_read_u32_array(dev->of_node, PROP_PORTS, ports, len); if (ret) return ret; num_paths = len / 2; } else { return -EINVAL; } for (i = 0; i < num_paths; i++) { bw_levels[0].vectors[i].src = ports[2 * i]; bw_levels[0].vectors[i].dst = ports[2 * i + 1]; bw_levels[1].vectors[i].src = ports[2 * i]; bw_levels[1].vectors[i].dst = ports[2 * i + 1]; } bw_levels[0].num_paths = num_paths; bw_levels[1].num_paths = num_paths; if (of_find_property(dev->of_node, PROP_TBL, &len)) { len /= sizeof(*data); data = devm_kzalloc(dev, len * sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; p->freq_table = devm_kzalloc(dev, len * sizeof(*p->freq_table), GFP_KERNEL); if (!p->freq_table) return -ENOMEM; ret = of_property_read_u32_array(dev->of_node, PROP_TBL, data, len); if (ret) return ret; for (i = 0; i < len; i++) p->freq_table[i] = data[i]; p->max_state = len; p->initial_freq = data[len-1]; } bus_client = msm_bus_scale_register_client(&bw_data); if (!bus_client) { dev_err(dev, "Unable to register bus client\n"); return -ENODEV; } df = devfreq_add_device(dev, &cpubw_profile, "msm_cpufreq", NULL); if (IS_ERR(df)) { msm_bus_scale_unregister_client(bus_client); return PTR_ERR(df); } return 0; }
static int __devinit vkey_parse_dt(struct device *dev, struct vkeys_platform_data *pdata) { struct device_node *np = dev->of_node; struct property *prop; int rc, val; rc = of_property_read_string(np, "label", &pdata->name); if (rc) { dev_err(dev, "Failed to read label\n"); return -EINVAL; } printk("virtual kesy wangminrong %s\r\n",pdata->name); rc = of_property_read_u32(np, "qcom,disp-maxx", &pdata->disp_maxx); if (rc) { dev_err(dev, "Failed to read display max x\n"); return -EINVAL; } rc = of_property_read_u32(np, "qcom,disp-maxy", &pdata->disp_maxy); if (rc) { dev_err(dev, "Failed to read display max y\n"); return -EINVAL; } rc = of_property_read_u32(np, "qcom,panel-maxx", &pdata->panel_maxx); if (rc) { dev_err(dev, "Failed to read panel max x\n"); return -EINVAL; } rc = of_property_read_u32(np, "qcom,panel-maxy", &pdata->panel_maxy); if (rc) { dev_err(dev, "Failed to read panel max y\n"); return -EINVAL; } prop = of_find_property(np, "qcom,key-codes", NULL); if (prop) { pdata->num_keys = prop->length / sizeof(u32); pdata->keycodes = devm_kzalloc(dev, sizeof(u32) * pdata->num_keys, GFP_KERNEL); if (!pdata->keycodes) return -ENOMEM; rc = of_property_read_u32_array(np, "qcom,key-codes", pdata->keycodes, pdata->num_keys); if (rc) { dev_err(dev, "Failed to read key codes\n"); return -EINVAL; } } pdata->y_offset = VKEY_Y_OFFSET_DEFAULT; rc = of_property_read_u32(np, "qcom,y-offset", &val); if (!rc) pdata->y_offset = val; else if (rc != -EINVAL) { dev_err(dev, "Failed to read y position offset\n"); return rc; } return 0; }
/* DT parsing for haptics parameters */ static int qpnp_hap_parse_dt(struct qpnp_hap *hap) { struct spmi_device *spmi = hap->spmi; struct property *prop; const char *temp_str; u32 temp; int rc; hap->timeout_ms = QPNP_HAP_TIMEOUT_MS_MAX; rc = of_property_read_u32(spmi->dev.of_node, "qcom,timeout-ms", &temp); if (!rc) { hap->timeout_ms = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read timeout\n"); return rc; } hap->act_type = QPNP_HAP_LRA; rc = of_property_read_string(spmi->dev.of_node, "qcom,actuator-type", &temp_str); if (!rc) { if (strcmp(temp_str, "erm") == 0) hap->act_type = QPNP_HAP_ERM; else if (strcmp(temp_str, "lra") == 0) hap->act_type = QPNP_HAP_LRA; else { dev_err(&spmi->dev, "Invalid actuator type\n"); return -EINVAL; } } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read actuator type\n"); return rc; } if (hap->act_type == QPNP_HAP_LRA) { hap->auto_res_mode = QPNP_HAP_AUTO_RES_ZXD_EOP; rc = of_property_read_string(spmi->dev.of_node, "qcom,lra-auto-res-mode", &temp_str); if (!rc) { if (strcmp(temp_str, "none") == 0) hap->auto_res_mode = QPNP_HAP_AUTO_RES_NONE; else if (strcmp(temp_str, "zxd") == 0) hap->auto_res_mode = QPNP_HAP_AUTO_RES_ZXD; else if (strcmp(temp_str, "qwd") == 0) hap->auto_res_mode = QPNP_HAP_AUTO_RES_QWD; else if (strcmp(temp_str, "max-qwd") == 0) hap->auto_res_mode = QPNP_HAP_AUTO_RES_MAX_QWD; else hap->auto_res_mode = QPNP_HAP_AUTO_RES_ZXD_EOP; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read auto res mode\n"); return rc; } hap->lra_high_z = QPNP_HAP_LRA_HIGH_Z_OPT3; rc = of_property_read_string(spmi->dev.of_node, "qcom,lra-high-z", &temp_str); if (!rc) { if (strcmp(temp_str, "none") == 0) hap->lra_high_z = QPNP_HAP_LRA_HIGH_Z_NONE; else if (strcmp(temp_str, "opt1") == 0) hap->lra_high_z = QPNP_HAP_LRA_HIGH_Z_OPT1; else if (strcmp(temp_str, "opt2") == 0) hap->lra_high_z = QPNP_HAP_LRA_HIGH_Z_OPT2; else hap->lra_high_z = QPNP_HAP_LRA_HIGH_Z_OPT3; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read LRA high-z\n"); return rc; } hap->lra_res_cal_period = QPNP_HAP_RES_CAL_PERIOD_MAX; rc = of_property_read_u32(spmi->dev.of_node, "qcom,lra-res-cal-period", &temp); if (!rc) { hap->lra_res_cal_period = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read cal period\n"); return rc; } } rc = of_property_read_string(spmi->dev.of_node, "qcom,play-mode", &temp_str); if (!rc) { if (strcmp(temp_str, "direct") == 0) hap->play_mode = QPNP_HAP_DIRECT; else if (strcmp(temp_str, "buffer") == 0) hap->play_mode = QPNP_HAP_BUFFER; else if (strcmp(temp_str, "pwm") == 0) hap->play_mode = QPNP_HAP_PWM; else if (strcmp(temp_str, "audio") == 0) hap->play_mode = QPNP_HAP_AUDIO; else { dev_err(&spmi->dev, "Invalid play mode\n"); return -EINVAL; } } else { dev_err(&spmi->dev, "Unable to read play mode\n"); return rc; } hap->vmax_mv = QPNP_HAP_VMAX_MAX_MV; rc = of_property_read_u32(spmi->dev.of_node, "qcom,vmax-mv", &temp); if (!rc) { hap->vmax_mv = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read vmax\n"); return rc; } hap->ilim_ma = QPNP_HAP_ILIM_MIN_MV; rc = of_property_read_u32(spmi->dev.of_node, "qcom,ilim-ma", &temp); if (!rc) { hap->ilim_ma = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read ILim\n"); return rc; } hap->sc_deb_cycles = QPNP_HAP_DEF_SC_DEB_CYCLES; rc = of_property_read_u32(spmi->dev.of_node, "qcom,sc-deb-cycles", &temp); if (!rc) { hap->sc_deb_cycles = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read sc debounce\n"); return rc; } hap->int_pwm_freq_khz = QPNP_HAP_INT_PWM_FREQ_505_KHZ; rc = of_property_read_u32(spmi->dev.of_node, "qcom,int-pwm-freq-khz", &temp); if (!rc) { hap->int_pwm_freq_khz = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read int pwm freq\n"); return rc; } hap->wave_shape = QPNP_HAP_WAV_SQUARE; rc = of_property_read_string(spmi->dev.of_node, "qcom,wave-shape", &temp_str); if (!rc) { if (strcmp(temp_str, "sine") == 0) hap->wave_shape = QPNP_HAP_WAV_SINE; else if (strcmp(temp_str, "square") == 0) hap->wave_shape = QPNP_HAP_WAV_SQUARE; else { dev_err(&spmi->dev, "Unsupported wav shape\n"); return -EINVAL; } } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read wav shape\n"); return rc; } hap->wave_play_rate_us = QPNP_HAP_DEF_WAVE_PLAY_RATE_US; rc = of_property_read_u32(spmi->dev.of_node, "qcom,wave-play-rate-us", &temp); if (!rc) { hap->wave_play_rate_us = temp; } else if (rc != -EINVAL) { dev_err(&spmi->dev, "Unable to read play rate\n"); return rc; } if (hap->play_mode == QPNP_HAP_BUFFER) rc = qpnp_hap_parse_buffer_dt(hap); else if (hap->play_mode == QPNP_HAP_PWM) rc = qpnp_hap_parse_pwm_dt(hap); if (rc < 0) return rc; prop = of_find_property(spmi->dev.of_node, "qcom,brake-pattern", &temp); if (!prop) { dev_err(&spmi->dev, "brake pattern not found"); } else if (temp != QPNP_HAP_BRAKE_PAT_LEN) { dev_err(&spmi->dev, "Invalid length of brake pattern\n"); return -EINVAL; } else memcpy(hap->brake_pat, prop->value, QPNP_HAP_BRAKE_PAT_LEN); hap->use_sc_irq = of_property_read_bool(spmi->dev.of_node, "qcom,use-sc-irq"); if (hap->use_sc_irq) { hap->sc_irq = spmi_get_irq_byname(hap->spmi, NULL, "sc-irq"); if (hap->sc_irq < 0) { dev_err(&spmi->dev, "Unable to get sc irq\n"); return hap->sc_irq; } } return 0; }
static int of_batterydata_read_lut(const struct device_node *np, int max_cols, int max_rows, int *ncols, int *nrows, int *col_legend_data, int *row_legend_data, int *lut_data) { struct property *prop; const __be32 *data; int cols, rows, size, i, j, *out_values; prop = of_find_property(np, "qcom,lut-col-legend", NULL); if (!prop) { pr_err("%s: No col legend found\n", np->name); return -EINVAL; } else if (!prop->value) { pr_err("%s: No col legend value found, np->name\n", np->name); return -ENODATA; } else if (prop->length > max_cols * sizeof(int)) { pr_err("%s: Too many columns\n", np->name); return -EINVAL; } cols = prop->length/sizeof(int); *ncols = cols; data = prop->value; for (i = 0; i < cols; i++) *col_legend_data++ = be32_to_cpup(data++); prop = of_find_property(np, "qcom,lut-row-legend", NULL); if (!prop || row_legend_data == NULL) { /* single row lut */ rows = 1; } else if (!prop->value) { pr_err("%s: No row legend value found\n", np->name); return -ENODATA; } else if (prop->length > max_rows * sizeof(int)) { pr_err("%s: Too many rows\n", np->name); return -EINVAL; } else { rows = prop->length/sizeof(int); *nrows = rows; data = prop->value; for (i = 0; i < rows; i++) *row_legend_data++ = be32_to_cpup(data++); } prop = of_find_property(np, "qcom,lut-data", NULL); if (!prop) { pr_err("prop 'qcom,lut-data' not found\n"); return -EINVAL; } data = prop->value; size = prop->length/sizeof(int); if (size != cols * rows) { pr_err("%s: data size mismatch, %dx%d != %d\n", np->name, cols, rows, size); return -EINVAL; } for (i = 0; i < rows; i++) { out_values = lut_data + (max_cols * i); for (j = 0; j < cols; j++) { *out_values++ = be32_to_cpup(data++); pr_debug("Value = %d\n", *(out_values-1)); } } return 0; }
static struct gpio_regulator_config * of_get_gpio_regulator_config(struct device *dev, struct device_node *np) { struct gpio_regulator_config *config; struct property *prop; const char *regtype; int proplen, gpio, i; config = devm_kzalloc(dev, sizeof(struct gpio_regulator_config), GFP_KERNEL); if (!config) return ERR_PTR(-ENOMEM); config->init_data = of_get_regulator_init_data(dev, np); if (!config->init_data) return ERR_PTR(-EINVAL); config->supply_name = config->init_data->constraints.name; if (of_property_read_bool(np, "enable-active-high")) config->enable_high = true; if (of_property_read_bool(np, "enable-at-boot")) config->enabled_at_boot = true; of_property_read_u32(np, "startup-delay-us", &config->startup_delay); config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); /* Fetch GPIOs. */ config->nr_gpios = of_gpio_count(np); config->gpios = devm_kzalloc(dev, sizeof(struct gpio) * config->nr_gpios, GFP_KERNEL); if (!config->gpios) return ERR_PTR(-ENOMEM); for (i = 0; i < config->nr_gpios; i++) { gpio = of_get_named_gpio(np, "gpios", i); if (gpio < 0) break; config->gpios[i].gpio = gpio; } /* Fetch states. */ prop = of_find_property(np, "states", NULL); if (!prop) { dev_err(dev, "No 'states' property found\n"); return ERR_PTR(-EINVAL); } proplen = prop->length / sizeof(int); config->states = devm_kzalloc(dev, sizeof(struct gpio_regulator_state) * (proplen / 2), GFP_KERNEL); if (!config->states) return ERR_PTR(-ENOMEM); for (i = 0; i < proplen / 2; i++) { config->states[i].value = be32_to_cpup((int *)prop->value + (i * 2)); config->states[i].gpios = be32_to_cpup((int *)prop->value + (i * 2 + 1)); } config->nr_states = i; of_property_read_string(np, "regulator-type", ®type); if (!strncmp("voltage", regtype, 7)) config->type = REGULATOR_VOLTAGE; else if (!strncmp("current", regtype, 7)) config->type = REGULATOR_CURRENT; return config; }
static int sirfsoc_uart_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct sirfsoc_uart_port *sirfport; struct uart_port *port; struct resource *res; int ret; struct dma_slave_config slv_cfg = { .src_maxburst = 1, }; struct dma_slave_config tx_slv_cfg = { .dst_maxburst = 2, }; const struct of_device_id *match; match = of_match_node(sirfsoc_uart_ids, np); sirfport = devm_kzalloc(&pdev->dev, sizeof(*sirfport), GFP_KERNEL); if (!sirfport) { ret = -ENOMEM; goto err; } sirfport->port.line = of_alias_get_id(np, "serial"); sirf_ports[sirfport->port.line] = sirfport; sirfport->port.iotype = UPIO_MEM; sirfport->port.flags = UPF_BOOT_AUTOCONF; port = &sirfport->port; port->dev = &pdev->dev; port->private_data = sirfport; sirfport->uart_reg = (struct sirfsoc_uart_register *)match->data; sirfport->hw_flow_ctrl = of_property_read_bool(np, "uart-has-rtscts") || of_property_read_bool(np, "sirf,uart-has-rtscts") /* deprecated */; if (of_device_is_compatible(np, "sirf,prima2-uart") || of_device_is_compatible(np, "sirf,atlas7-uart")) sirfport->uart_reg->uart_type = SIRF_REAL_UART; if (of_device_is_compatible(np, "sirf,prima2-usp-uart") || of_device_is_compatible(np, "sirf,atlas7-usp-uart")) { sirfport->uart_reg->uart_type = SIRF_USP_UART; if (!sirfport->hw_flow_ctrl) goto usp_no_flow_control; if (of_find_property(np, "cts-gpios", NULL)) sirfport->cts_gpio = of_get_named_gpio(np, "cts-gpios", 0); else sirfport->cts_gpio = -1; if (of_find_property(np, "rts-gpios", NULL)) sirfport->rts_gpio = of_get_named_gpio(np, "rts-gpios", 0); else sirfport->rts_gpio = -1; if ((!gpio_is_valid(sirfport->cts_gpio) || !gpio_is_valid(sirfport->rts_gpio))) { ret = -EINVAL; dev_err(&pdev->dev, "Usp flow control must have cts and rts gpio"); goto err; } ret = devm_gpio_request(&pdev->dev, sirfport->cts_gpio, "usp-cts-gpio"); if (ret) { dev_err(&pdev->dev, "Unable request cts gpio"); goto err; } gpio_direction_input(sirfport->cts_gpio); ret = devm_gpio_request(&pdev->dev, sirfport->rts_gpio, "usp-rts-gpio"); if (ret) { dev_err(&pdev->dev, "Unable request rts gpio"); goto err; } gpio_direction_output(sirfport->rts_gpio, 1); } usp_no_flow_control: if (of_device_is_compatible(np, "sirf,atlas7-uart") || of_device_is_compatible(np, "sirf,atlas7-usp-uart")) sirfport->is_atlas7 = true; if (of_property_read_u32(np, "fifosize", &port->fifosize)) { dev_err(&pdev->dev, "Unable to find fifosize in uart node.\n"); ret = -EFAULT; goto err; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(&pdev->dev, "Insufficient resources.\n"); ret = -EFAULT; goto err; } port->mapbase = res->start; port->membase = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!port->membase) { dev_err(&pdev->dev, "Cannot remap resource.\n"); ret = -ENOMEM; goto err; } res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res == NULL) { dev_err(&pdev->dev, "Insufficient resources.\n"); ret = -EFAULT; goto err; } port->irq = res->start; sirfport->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(sirfport->clk)) { ret = PTR_ERR(sirfport->clk); goto err; } port->uartclk = clk_get_rate(sirfport->clk); port->ops = &sirfsoc_uart_ops; spin_lock_init(&port->lock); platform_set_drvdata(pdev, sirfport); ret = uart_add_one_port(&sirfsoc_uart_drv, port); if (ret != 0) { dev_err(&pdev->dev, "Cannot add UART port(%d).\n", pdev->id); goto err; } sirfport->rx_dma_chan = dma_request_slave_channel(port->dev, "rx"); sirfport->rx_dma_items.xmit.buf = dma_alloc_coherent(port->dev, SIRFSOC_RX_DMA_BUF_SIZE, &sirfport->rx_dma_items.dma_addr, GFP_KERNEL); if (!sirfport->rx_dma_items.xmit.buf) { dev_err(port->dev, "Uart alloc bufa failed\n"); ret = -ENOMEM; goto alloc_coherent_err; } sirfport->rx_dma_items.xmit.head = sirfport->rx_dma_items.xmit.tail = 0; if (sirfport->rx_dma_chan) dmaengine_slave_config(sirfport->rx_dma_chan, &slv_cfg); sirfport->tx_dma_chan = dma_request_slave_channel(port->dev, "tx"); if (sirfport->tx_dma_chan) dmaengine_slave_config(sirfport->tx_dma_chan, &tx_slv_cfg); if (sirfport->rx_dma_chan) { hrtimer_init(&sirfport->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); sirfport->hrt.function = sirfsoc_uart_rx_dma_hrtimer_callback; sirfport->is_hrt_enabled = false; } return 0; alloc_coherent_err: dma_free_coherent(port->dev, SIRFSOC_RX_DMA_BUF_SIZE, sirfport->rx_dma_items.xmit.buf, sirfport->rx_dma_items.dma_addr); dma_release_channel(sirfport->rx_dma_chan); err: return ret; } static int sirfsoc_uart_remove(struct platform_device *pdev) { struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev); struct uart_port *port = &sirfport->port; uart_remove_one_port(&sirfsoc_uart_drv, port); if (sirfport->rx_dma_chan) { dmaengine_terminate_all(sirfport->rx_dma_chan); dma_release_channel(sirfport->rx_dma_chan); dma_free_coherent(port->dev, SIRFSOC_RX_DMA_BUF_SIZE, sirfport->rx_dma_items.xmit.buf, sirfport->rx_dma_items.dma_addr); } if (sirfport->tx_dma_chan) { dmaengine_terminate_all(sirfport->tx_dma_chan); dma_release_channel(sirfport->tx_dma_chan); } return 0; } #ifdef CONFIG_PM_SLEEP static int sirfsoc_uart_suspend(struct device *pdev) { struct sirfsoc_uart_port *sirfport = dev_get_drvdata(pdev); struct uart_port *port = &sirfport->port; uart_suspend_port(&sirfsoc_uart_drv, port); return 0; } static int sirfsoc_uart_resume(struct device *pdev) { struct sirfsoc_uart_port *sirfport = dev_get_drvdata(pdev); struct uart_port *port = &sirfport->port; uart_resume_port(&sirfsoc_uart_drv, port); return 0; } #endif static const struct dev_pm_ops sirfsoc_uart_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(sirfsoc_uart_suspend, sirfsoc_uart_resume) }; static struct platform_driver sirfsoc_uart_driver = { .probe = sirfsoc_uart_probe, .remove = sirfsoc_uart_remove, .driver = { .name = SIRFUART_PORT_NAME, .of_match_table = sirfsoc_uart_ids, .pm = &sirfsoc_uart_pm_ops, }, }; static int __init sirfsoc_uart_init(void) { int ret = 0; ret = uart_register_driver(&sirfsoc_uart_drv); if (ret) goto out; ret = platform_driver_register(&sirfsoc_uart_driver); if (ret) uart_unregister_driver(&sirfsoc_uart_drv); out: return ret; } module_init(sirfsoc_uart_init); static void __exit sirfsoc_uart_exit(void) { platform_driver_unregister(&sirfsoc_uart_driver); uart_unregister_driver(&sirfsoc_uart_drv); }
/* * Translate OpenFirmware node properties into platform_data */ static struct gpio_keys_platform_data * gpio_keys_get_devtree_pdata(struct device *dev) { struct device_node *node, *pp; struct gpio_keys_platform_data *pdata; struct gpio_keys_button *button; int error; int nbuttons; int i; node = dev->of_node; if (!node) { error = -ENODEV; goto err_out; } nbuttons = of_get_child_count(node); if (nbuttons == 0) { error = -ENODEV; goto err_out; } pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button), GFP_KERNEL); if (!pdata) { error = -ENOMEM; goto err_out; } pdata->buttons = (struct gpio_keys_button *)(pdata + 1); pdata->nbuttons = nbuttons; pdata->rep = !!of_get_property(node, "autorepeat", NULL); pdata->name = of_get_property(node, "input-name", NULL); i = 0; for_each_child_of_node(node, pp) { int gpio; enum of_gpio_flags flags; if (!of_find_property(pp, "gpios", NULL)) { pdata->nbuttons--; dev_warn(dev, "Found button without gpios\n"); continue; } gpio = of_get_gpio_flags(pp, 0, &flags); if (gpio < 0) { error = gpio; if (error != -EPROBE_DEFER) dev_err(dev, "Failed to get gpio flags, error: %d\n", error); goto err_free_pdata; } button = &pdata->buttons[i++]; button->gpio = gpio; button->active_low = flags & OF_GPIO_ACTIVE_LOW; if (of_property_read_u32(pp, "linux,code", &button->code)) { dev_err(dev, "Button without keycode: 0x%x\n", button->gpio); error = -EINVAL; goto err_free_pdata; } button->desc = of_get_property(pp, "label", NULL); if (of_property_read_u32(pp, "linux,input-type", &button->type)) button->type = EV_KEY; button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); if (of_property_read_u32(pp, "debounce-interval", &button->debounce_interval)) button->debounce_interval = 5; }
static int __devinit fsl_ssi_probe(struct platform_device *pdev) { struct fsl_ssi_private *ssi_private; int ret = 0; struct device_attribute *dev_attr = NULL; struct device_node *np = pdev->dev.of_node; const char *p, *sprop; const uint32_t *iprop; struct resource res; char name[64]; /* SSIs that are not connected on the board should have a * status = "disabled" * property in their device tree nodes. */ if (!of_device_is_available(np)) return -ENODEV; /* Check for a codec-handle property. */ if (!of_get_property(np, "codec-handle", NULL)) { dev_err(&pdev->dev, "missing codec-handle property\n"); return -ENODEV; } /* We only support the SSI in "I2S Slave" mode */ sprop = of_get_property(np, "fsl,mode", NULL); if (!sprop || strcmp(sprop, "i2s-slave")) { dev_notice(&pdev->dev, "mode %s is unsupported\n", sprop); return -ENODEV; } /* The DAI name is the last part of the full name of the node. */ p = strrchr(np->full_name, '/') + 1; ssi_private = kzalloc(sizeof(struct fsl_ssi_private) + strlen(p), GFP_KERNEL); if (!ssi_private) { dev_err(&pdev->dev, "could not allocate DAI object\n"); return -ENOMEM; } strcpy(ssi_private->name, p); /* Initialize this copy of the CPU DAI driver structure */ memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template, sizeof(fsl_ssi_dai_template)); ssi_private->cpu_dai_drv.name = ssi_private->name; /* Get the addresses and IRQ */ ret = of_address_to_resource(np, 0, &res); if (ret) { dev_err(&pdev->dev, "could not determine device resources\n"); goto error_kmalloc; } ssi_private->ssi = of_iomap(np, 0); if (!ssi_private->ssi) { dev_err(&pdev->dev, "could not map device resources\n"); ret = -ENOMEM; goto error_kmalloc; } ssi_private->ssi_phys = res.start; ssi_private->irq = irq_of_parse_and_map(np, 0); if (ssi_private->irq == NO_IRQ) { dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); ret = -ENXIO; goto error_iomap; } /* The 'name' should not have any slashes in it. */ ret = request_irq(ssi_private->irq, fsl_ssi_isr, 0, ssi_private->name, ssi_private); if (ret < 0) { dev_err(&pdev->dev, "could not claim irq %u\n", ssi_private->irq); goto error_irqmap; } /* Are the RX and the TX clocks locked? */ if (!of_find_property(np, "fsl,ssi-asynchronous", NULL)) ssi_private->cpu_dai_drv.symmetric_rates = 1; /* Determine the FIFO depth. */ iprop = of_get_property(np, "fsl,fifo-depth", NULL); if (iprop) ssi_private->fifo_depth = be32_to_cpup(iprop); else /* Older 8610 DTs didn't have the fifo-depth property */ ssi_private->fifo_depth = 8; /* Initialize the the device_attribute structure */ dev_attr = &ssi_private->dev_attr; sysfs_attr_init(&dev_attr->attr); dev_attr->attr.name = "statistics"; dev_attr->attr.mode = S_IRUGO; dev_attr->show = fsl_sysfs_ssi_show; ret = device_create_file(&pdev->dev, dev_attr); if (ret) { dev_err(&pdev->dev, "could not create sysfs %s file\n", ssi_private->dev_attr.attr.name); goto error_irq; } /* Register with ASoC */ dev_set_drvdata(&pdev->dev, ssi_private); ret = snd_soc_register_dai(&pdev->dev, &ssi_private->cpu_dai_drv); if (ret) { dev_err(&pdev->dev, "failed to register DAI: %d\n", ret); goto error_dev; } /* Trigger the machine driver's probe function. The platform driver * name of the machine driver is taken from /compatible property of the * device tree. We also pass the address of the CPU DAI driver * structure. */ sprop = of_get_property(of_find_node_by_path("/"), "compatible", NULL); /* Sometimes the compatible name has a "fsl," prefix, so we strip it. */ p = strrchr(sprop, ','); if (p) sprop = p + 1; snprintf(name, sizeof(name), "snd-soc-%s", sprop); make_lowercase(name); ssi_private->pdev = platform_device_register_data(&pdev->dev, name, 0, NULL, 0); if (IS_ERR(ssi_private->pdev)) { ret = PTR_ERR(ssi_private->pdev); dev_err(&pdev->dev, "failed to register platform: %d\n", ret); goto error_dai; } return 0; error_dai: snd_soc_unregister_dai(&pdev->dev); error_dev: dev_set_drvdata(&pdev->dev, NULL); device_remove_file(&pdev->dev, dev_attr); error_irq: free_irq(ssi_private->irq, ssi_private); error_irqmap: irq_dispose_mapping(ssi_private->irq); error_iomap: iounmap(ssi_private->ssi); error_kmalloc: kfree(ssi_private); return ret; }
/* * Get info on the currently-loaded firmware * * This function also checks the device tree to see if the boot loader has * uploaded a firmware already. */ struct qe_firmware_info *qe_get_firmware_info(void) { static int initialized; struct property *prop; struct device_node *qe; struct device_node *fw = NULL; const char *sprop; unsigned int i; /* * If we haven't checked yet, and a driver hasn't uploaded a firmware * yet, then check the device tree for information. */ if (qe_firmware_uploaded) return &qe_firmware_info; if (initialized) return NULL; initialized = 1; /* * Newer device trees have an "fsl,qe" compatible property for the QE * node, but we still need to support older device trees. */ qe = of_find_compatible_node(NULL, NULL, "fsl,qe"); if (!qe) { qe = of_find_node_by_type(NULL, "qe"); if (!qe) return NULL; } /* Find the 'firmware' child node */ for_each_child_of_node(qe, fw) { if (strcmp(fw->name, "firmware") == 0) break; } of_node_put(qe); /* Did we find the 'firmware' node? */ if (!fw) return NULL; qe_firmware_uploaded = 1; /* Copy the data into qe_firmware_info*/ sprop = of_get_property(fw, "id", NULL); if (sprop) strncpy(qe_firmware_info.id, sprop, sizeof(qe_firmware_info.id) - 1); prop = of_find_property(fw, "extended-modes", NULL); if (prop && (prop->length == sizeof(u64))) { const u64 *iprop = prop->value; qe_firmware_info.extended_modes = *iprop; } prop = of_find_property(fw, "virtual-traps", NULL); if (prop && (prop->length == 32)) { const u32 *iprop = prop->value; for (i = 0; i < ARRAY_SIZE(qe_firmware_info.vtraps); i++) qe_firmware_info.vtraps[i] = iprop[i]; } of_node_put(fw); return &qe_firmware_info; }
static int nxp_spifi_setup_flash(struct nxp_spifi *spifi, struct device_node *np) { struct mtd_part_parser_data ppdata; enum read_mode flash_read; u32 ctrl, property; u16 mode = 0; int ret; if (!of_property_read_u32(np, "spi-rx-bus-width", &property)) { switch (property) { case 1: break; case 2: mode |= SPI_RX_DUAL; break; case 4: mode |= SPI_RX_QUAD; break; default: dev_err(spifi->dev, "unsupported rx-bus-width\n"); return -EINVAL; } } if (of_find_property(np, "spi-cpha", NULL)) mode |= SPI_CPHA; if (of_find_property(np, "spi-cpol", NULL)) mode |= SPI_CPOL; /* Setup control register defaults */ ctrl = SPIFI_CTRL_TIMEOUT(1000) | SPIFI_CTRL_CSHIGH(15) | SPIFI_CTRL_FBCLK; if (mode & SPI_RX_DUAL) { ctrl |= SPIFI_CTRL_DUAL; flash_read = SPI_NOR_DUAL; } else if (mode & SPI_RX_QUAD) { ctrl &= ~SPIFI_CTRL_DUAL; flash_read = SPI_NOR_QUAD; } else { ctrl |= SPIFI_CTRL_DUAL; flash_read = SPI_NOR_NORMAL; } switch (mode & (SPI_CPHA | SPI_CPOL)) { case SPI_MODE_0: ctrl &= ~SPIFI_CTRL_MODE3; break; case SPI_MODE_3: ctrl |= SPIFI_CTRL_MODE3; break; default: dev_err(spifi->dev, "only mode 0 and 3 supported\n"); return -EINVAL; } writel(ctrl, spifi->io_base + SPIFI_CTRL); spifi->mtd.priv = &spifi->nor; spifi->nor.mtd = &spifi->mtd; spifi->nor.dev = spifi->dev; spifi->nor.priv = spifi; spifi->nor.read = nxp_spifi_read; spifi->nor.write = nxp_spifi_write; spifi->nor.erase = nxp_spifi_erase; spifi->nor.read_reg = nxp_spifi_read_reg; spifi->nor.write_reg = nxp_spifi_write_reg; /* * The first read on a hard reset isn't reliable so do a * dummy read of the id before calling spi_nor_scan(). * The reason for this problem is unknown. * * The official NXP spifilib uses more or less the same * workaround that is applied here by reading the device * id multiple times. */ nxp_spifi_dummy_id_read(&spifi->nor); ret = spi_nor_scan(&spifi->nor, NULL, flash_read); if (ret) { dev_err(spifi->dev, "device scan failed\n"); return ret; } ret = nxp_spifi_setup_memory_cmd(spifi); if (ret) { dev_err(spifi->dev, "memory command setup failed\n"); return ret; } ppdata.of_node = np; ret = mtd_device_parse_register(&spifi->mtd, NULL, &ppdata, NULL, 0); if (ret) { dev_err(spifi->dev, "mtd device parse failed\n"); return ret; } return 0; }
static int spear_cpufreq_driver_init(void) { struct device_node *np; const struct property *prop; struct cpufreq_frequency_table *freq_tbl; const __be32 *val; int cnt, i, ret; np = of_cpu_device_node_get(0); if (!np) { pr_err("No cpu node found"); return -ENODEV; } if (of_property_read_u32(np, "clock-latency", &spear_cpufreq.transition_latency)) spear_cpufreq.transition_latency = CPUFREQ_ETERNAL; prop = of_find_property(np, "cpufreq_tbl", NULL); if (!prop || !prop->value) { pr_err("Invalid cpufreq_tbl"); ret = -ENODEV; goto out_put_node; } cnt = prop->length / sizeof(u32); val = prop->value; freq_tbl = kmalloc(sizeof(*freq_tbl) * (cnt + 1), GFP_KERNEL); if (!freq_tbl) { ret = -ENOMEM; goto out_put_node; } for (i = 0; i < cnt; i++) { freq_tbl[i].driver_data = i; freq_tbl[i].frequency = be32_to_cpup(val++); } freq_tbl[i].driver_data = i; freq_tbl[i].frequency = CPUFREQ_TABLE_END; spear_cpufreq.freq_tbl = freq_tbl; of_node_put(np); spear_cpufreq.clk = clk_get(NULL, "cpu_clk"); if (IS_ERR(spear_cpufreq.clk)) { pr_err("Unable to get CPU clock\n"); ret = PTR_ERR(spear_cpufreq.clk); goto out_put_mem; } ret = cpufreq_register_driver(&spear_cpufreq_driver); if (!ret) return 0; pr_err("failed register driver: %d\n", ret); clk_put(spear_cpufreq.clk); out_put_mem: kfree(freq_tbl); return ret; out_put_node: of_node_put(np); return ret; }
/** * of_get_fixed_voltage_config - extract fixed_voltage_config structure info * @dev: device requesting for fixed_voltage_config * * Populates fixed_voltage_config structure by extracting data from device * tree node, returns a pointer to the populated structure of NULL if memory * alloc fails. */ static struct fixed_voltage_config * of_get_fixed_voltage_config(struct device *dev) { struct fixed_voltage_config *config; struct device_node *np = dev->of_node; const __be32 *delay; struct regulator_init_data *init_data; config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), GFP_KERNEL); if (!config) return ERR_PTR(-ENOMEM); config->init_data = of_get_regulator_init_data(dev, dev->of_node); if (!config->init_data) return ERR_PTR(-EINVAL); init_data = config->init_data; init_data->constraints.apply_uV = 0; config->supply_name = init_data->constraints.name; if (init_data->constraints.min_uV == init_data->constraints.max_uV) { config->microvolts = init_data->constraints.min_uV; } else { dev_err(dev, "Fixed regulator specified with variable voltages\n"); return ERR_PTR(-EINVAL); } if (init_data->constraints.boot_on) config->enabled_at_boot = true; config->gpio = of_get_named_gpio(np, "gpio", 0); /* * of_get_named_gpio() currently returns ENODEV rather than * EPROBE_DEFER. This code attempts to be compatible with both * for now; the ENODEV check can be removed once the API is fixed. * of_get_named_gpio() doesn't differentiate between a missing * property (which would be fine here, since the GPIO is optional) * and some other error. Patches have been posted for both issues. * Once they are check in, we should replace this with: * if (config->gpio < 0 && config->gpio != -ENOENT) */ if ((config->gpio == -ENODEV) || (config->gpio == -EPROBE_DEFER)) return ERR_PTR(-EPROBE_DEFER); delay = of_get_property(np, "startup-delay-us", NULL); if (delay) config->startup_delay = be32_to_cpu(*delay); if (of_find_property(np, "enable-active-high", NULL)) config->enable_high = true; if (of_find_property(np, "gpio-open-drain", NULL)) config->gpio_is_open_drain = true; if (of_find_property(np, "vin-supply", NULL)) config->input_supply = "vin"; return config; }
static int read_gpio_from_dt(struct device_node *dt, struct fullseg_platform_data *pdata) { struct property *prop = NULL; INFO_PRINT("%s \n", __func__); prop = of_find_property(dt, "fullseg,npdreg", NULL); if (prop) { pdata->npdreg = of_get_named_gpio(dt, "fullseg,npdreg", 0); printk("%s: pdata->npdreg = %d\n", __func__, pdata->npdreg); } prop = of_find_property(dt, "fullseg,npdxtal", NULL); if (prop) { pdata->npdxtal = of_get_named_gpio(dt, "fullseg,npdxtal", 0); printk("%s: pdata->npdxtal = %d\n", __func__, pdata->npdxtal); } prop = of_find_property(dt, "fullseg,nrst", NULL); if (prop) { pdata->nrst = of_get_named_gpio(dt, "fullseg,nrst", 0); printk("%s: pdata->nrst = %d\n", __func__, pdata->nrst); } prop = of_find_property(dt, "fullseg,interrupt", NULL); if (prop) { pdata->interrupt = of_get_named_gpio(dt, "fullseg,interrupt", 0); printk("%s: pdata->interrupt = %d\n", __func__, pdata->interrupt); } prop = of_find_property(dt, "fullseg,fm_fullseg_ant_sw", NULL); if (prop) { pdata->fm_fullseg_ant_sw = of_get_named_gpio(dt, "fullseg,fm_fullseg_ant_sw", 0); printk("%s: pdata->fm_fullseg_ant_sw = %d\n", __func__, pdata->fm_fullseg_ant_sw); } prop = of_find_property(dt, "fullseg,1v8_en", NULL); if (prop) { pdata->_1v8_en = of_get_named_gpio(dt, "fullseg,1v8_en", 0); printk("%s: pdata->_1v8_en = %d\n", __func__, pdata->_1v8_en); } prop = of_find_property(dt, "fullseg,1v1_en", NULL); if (prop) { pdata->_1v1_en = of_get_named_gpio(dt, "fullseg,1v1_en", 0); printk("%s: pdata->_1v1_en = %d\n", __func__, pdata->_1v1_en); } prop = of_find_property(dt, "fullseg,ts_clk", NULL); if (prop) { pdata->ts_clk= of_get_named_gpio(dt, "fullseg,ts_clk", 0); printk("%s: pdata->ts_clk = %d\n", __func__, pdata->ts_clk); } prop = of_find_property(dt, "fullseg,ts_en", NULL); if (prop) { pdata->ts_en= of_get_named_gpio(dt, "fullseg,ts_en", 0); printk("%s: pdata->ts_en = %d\n", __func__, pdata->ts_en); } prop = of_find_property(dt, "fullseg,ts_data", NULL); if (prop) { pdata->ts_data= of_get_named_gpio(dt, "fullseg,ts_data", 0); printk("%s: pdata->ts_data = %d\n", __func__, pdata->ts_data); } prop = of_find_property(dt, "fullseg,ts_sync", NULL); if (prop) { pdata->ts_sync= of_get_named_gpio(dt, "fullseg,ts_sync", 0); printk("%s: pdata->ts_sync = %d\n", __func__, pdata->ts_sync); } return 0; }
static int lg4591_probe(struct platform_device *pdev) { struct mmp_mach_panel_info *mi; struct lg4591_plat_data *plat_data; struct device_node *np = pdev->dev.of_node; const char *path_name; struct backlight_properties props; struct backlight_device *bl; int ret; u32 esd_enable; plat_data = kzalloc(sizeof(*plat_data), GFP_KERNEL); if (!plat_data) return -ENOMEM; if (IS_ENABLED(CONFIG_OF)) { ret = of_property_read_string(np, "marvell,path-name", &path_name); if (ret < 0) { kfree(plat_data); return ret; } panel_lg4591.plat_path_name = path_name; if (of_find_property(np, "iovdd-supply", NULL)) panel_lg4591.is_iovdd = 1; if (of_find_property(np, "avdd-supply", NULL)) panel_lg4591.is_avdd = 1; if (of_property_read_u32(np, "panel_esd", &esd_enable)) plat_data->esd_enable = 0; plat_data->esd_enable = esd_enable; } else { /* get configs from platform data */ mi = pdev->dev.platform_data; if (mi == NULL) { dev_err(&pdev->dev, "no platform data defined\n"); kfree(plat_data); return -EINVAL; } plat_data->plat_onoff = mi->plat_set_onoff; panel_lg4591.plat_path_name = mi->plat_path_name; plat_data->plat_set_backlight = mi->plat_set_backlight; plat_data->esd_enable = mi->esd_enable; } plat_data->panel = &panel_lg4591; panel_lg4591.plat_data = plat_data; panel_lg4591.dev = &pdev->dev; mmp_register_panel(&panel_lg4591); if (plat_data->esd_enable) esd_init(&panel_lg4591); /* * if no panel or plat associate backlight control, * don't register backlight device here. */ if (!panel_lg4591.set_brightness && !plat_data->plat_set_backlight) return 0; memset(&props, 0, sizeof(struct backlight_properties)); props.max_brightness = 100; props.type = BACKLIGHT_RAW; bl = backlight_device_register("lcd-bl", &pdev->dev, plat_data, &lg4591_bl_ops, &props); if (IS_ERR(bl)) { ret = PTR_ERR(bl); dev_err(&pdev->dev, "failed to register lcd-backlight\n"); return ret; } bl->props.fb_blank = FB_BLANK_UNBLANK; bl->props.power = FB_BLANK_UNBLANK; bl->props.brightness = 100; ret = lg4591_bl_update_status(bl); if (ret < 0) dev_err(&pdev->dev, "failed to set lcd brightness\n"); return 0; }
void sdhci_get_of_property(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct sdhci_host *host = platform_get_drvdata(pdev); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); const __be32 *clk; u32 bus_width = 0; int size; int runmode_normal; int batterystate_exist; if (of_device_is_available(np)) { if (of_get_property(np, "sdhci,auto-cmd12", NULL)) host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; if (of_get_property(np, "sdhci,1-bit-only", NULL) || (of_property_read_u32(np, "bus-width", &bus_width) == 0 && bus_width == 1)) host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; if (bus_width == 4) host->mmc->caps |= MMC_CAP_4_BIT_DATA; else if (bus_width == 8) host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA; if (sdhci_of_wp_inverted(np)) host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT; if (of_get_property(np, "broken-cd", NULL)) host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; if (of_find_property(np, "non-removable", NULL)) host->mmc->caps |= MMC_CAP_NONREMOVABLE; if (of_get_property(np, "no-1-8-v", NULL)) host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; if (of_device_is_compatible(np, "fsl,p2020-rev1-esdhc")) host->quirks |= SDHCI_QUIRK_BROKEN_DMA; if (of_find_property(np, "use-pio", NULL)) { host->quirks |= SDHCI_QUIRK_BROKEN_DMA; host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; } if (of_find_property(np, "use-dma", NULL)) host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; if (!of_find_property(np, "sdhci-adma-64bit", NULL)) host->quirks2 |= SDHCI_QUIRK2_BROKEN_64_BIT_DMA; if (of_device_is_compatible(np, "fsl,p2020-esdhc") || of_device_is_compatible(np, "fsl,p1010-esdhc") || of_device_is_compatible(np, "fsl,t4240-esdhc") || of_device_is_compatible(np, "fsl,mpc8536-esdhc")) host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; clk = of_get_property(np, "clock-frequency", &size); if (clk && size == sizeof(*clk) && *clk) pltfm_host->clock = be32_to_cpup(clk); host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200; if (of_find_property(np, "caps2-mmc-ddr50-1_8v", NULL)) host->mmc->caps |= MMC_CAP_1_8V_DDR; if (of_find_property(np, "caps2-mmc-ddr50-1_2v", NULL)) host->mmc->caps |= MMC_CAP_1_2V_DDR; if (of_find_property(np, "caps2-mmc-hs200-1_8v", NULL)) { host->mmc->caps2 |= MMC_CAP2_HS200_1_8V_SDR; host->quirks2 &= ~SDHCI_QUIRK2_BROKEN_HS200; } if (of_find_property(np, "caps2-mmc-hs200-1_2v", NULL)) { host->mmc->caps2 |= MMC_CAP2_HS200_1_2V_SDR; host->quirks2 &= ~SDHCI_QUIRK2_BROKEN_HS200; } if (of_find_property(np, "caps2-mmc-hs400-1_8v", NULL)){ host->mmc->caps2 |= MMC_CAP2_HS200_1_8V_SDR; host->mmc->caps2 |= MMC_CAP2_HS400_1_8V; host->quirks2 &= ~SDHCI_QUIRK2_BROKEN_HS200; } if (of_find_property(np, "caps2-mmc-hs400-1_2v", NULL)){ host->mmc->caps2 |= MMC_CAP2_HS200_1_2V_SDR; host->mmc->caps2 |= MMC_CAP2_HS400_1_2V; host->quirks2 &= ~SDHCI_QUIRK2_BROKEN_HS200; } if (of_find_property(np, "caps2-mmc-packed-command", NULL)) host->mmc->caps2 |= MMC_CAP2_PACKED_CMD; runmode_normal = !runmode_is_factory(); #ifdef CONFIG_HISI_COUL batterystate_exist = is_hisi_battery_exist(); #else batterystate_exist = 0; #endif dev_info(&pdev->dev, "runmode_normal = %d batterystate_exist = %d\n", runmode_normal, batterystate_exist); if (of_find_property(np, "caps2-mmc-cache-ctrl", NULL)) { dev_info(&pdev->dev, "caps2-mmc-cache-ctrl is set in dts.\n"); if(runmode_normal || batterystate_exist) { dev_info(&pdev->dev, "cache ctrl on\n"); host->mmc->caps2 |= MMC_CAP2_CACHE_CTRL; } else { dev_info(&pdev->dev, "cache ctrl off\n"); } } if (of_find_property(np, "full-pwr-cycle", NULL)) host->mmc->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; if (of_find_property(np, "caps2-mmc-cmd-queue", NULL)) { dev_info(&pdev->dev, "caps2-mmc-cmd-queue is set in dts.\n"); if(runmode_normal || batterystate_exist) { dev_info(&pdev->dev, "caps2-mmc-cmd-queue on\n"); host->mmc->caps2 |= MMC_CAP2_CMD_QUEUE; } else { dev_info(&pdev->dev, "caps2-mmc-cmd-queue off\n"); } } if (of_find_property(np, "keep-power-in-suspend", NULL)) host->mmc->pm_caps |= MMC_PM_KEEP_POWER; if (of_find_property(np, "enable-sdio-wakeup", NULL)) host->mmc->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; if (of_find_property(np, "caps2-mmc-enhanced_strobe-ctrl", NULL)) host->mmc->caps2 |= MMC_CAP2_ENHANCED_STROBE; if (of_find_property(np, "caps2-mmc-cache_flush_barrier-ctrl", NULL)) host->mmc->caps2 |= MMC_CAP2_CACHE_FLUSH_BARRIER; if (of_find_property(np, "caps2-mmc-bkops_auto-ctrl", NULL)) host->mmc->caps2 |= MMC_CAP2_BKOPS_AUTO_CTRL; if (of_find_property(np, "caps2-mmc-HC-erase-size", NULL)) host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; } }
static int of_platform_serial_probe(struct platform_device *ofdev) { const struct of_device_id *match; struct of_serial_info *info; struct uart_port port; int port_type; int ret; int ids; match = of_match_device(of_platform_serial_table, &ofdev->dev); if (!match) return -EINVAL; if (of_find_property(ofdev->dev.of_node, "used-by-rtas", NULL)) return -EBUSY; info = kzalloc(sizeof(*info), GFP_KERNEL); if (info == NULL) return -ENOMEM; port_type = (unsigned long)match->data; ret = of_platform_serial_setup(ofdev, port_type, &port, info); if (ret) goto out; ids = of_alias_get_id(ofdev->dev.of_node, "serial"); if (ids < 0) { dev_warn(&ofdev->dev, "FAILED to find out alias id\n"); } else { if (ids < CONFIG_SERIAL_8250_RUNTIME_UARTS) port.line = ids; else { dev_warn(&ofdev->dev, "FAILED to register serial driver with id %d\n", ids); goto out; } } switch (port_type) { #ifdef CONFIG_SERIAL_8250 case PORT_8250 ... PORT_MAX_8250: { struct uart_8250_port port8250; memset(&port8250, 0, sizeof(port8250)); port8250.port = port; if (port.fifosize) port8250.capabilities = UART_CAP_FIFO; if (of_property_read_bool(ofdev->dev.of_node, "auto-flow-control")) port8250.capabilities |= UART_CAP_AFE; ret = serial8250_register_8250_port(&port8250); break; } #endif #ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL case PORT_NWPSERIAL: ret = nwpserial_register_port(&port); break; #endif default: /* need to add code for these */ case PORT_UNKNOWN: dev_info(&ofdev->dev, "Unknown serial port found, ignored\n"); ret = -ENODEV; break; } if (ret < 0) goto out; info->type = port_type; info->line = ret; platform_set_drvdata(ofdev, info); return 0; out: kfree(info); irq_dispose_mapping(port.irq); return ret; }
static int ti_dra7_xbar_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; const struct of_device_id *match; struct device_node *dma_node; struct ti_dra7_xbar_data *xbar; struct property *prop; struct resource *res; u32 safe_val; int sz; void __iomem *iomem; int i, ret; if (!node) return -ENODEV; xbar = devm_kzalloc(&pdev->dev, sizeof(*xbar), GFP_KERNEL); if (!xbar) return -ENOMEM; dma_node = of_parse_phandle(node, "dma-masters", 0); if (!dma_node) { dev_err(&pdev->dev, "Can't get DMA master node\n"); return -ENODEV; } match = of_match_node(ti_dra7_master_match, dma_node); if (!match) { dev_err(&pdev->dev, "DMA master is not supported\n"); of_node_put(dma_node); return -EINVAL; } if (of_property_read_u32(dma_node, "dma-requests", &xbar->dma_requests)) { dev_info(&pdev->dev, "Missing XBAR output information, using %u.\n", TI_DRA7_XBAR_OUTPUTS); xbar->dma_requests = TI_DRA7_XBAR_OUTPUTS; } of_node_put(dma_node); xbar->dma_inuse = devm_kcalloc(&pdev->dev, BITS_TO_LONGS(xbar->dma_requests), sizeof(unsigned long), GFP_KERNEL); if (!xbar->dma_inuse) return -ENOMEM; if (of_property_read_u32(node, "dma-requests", &xbar->xbar_requests)) { dev_info(&pdev->dev, "Missing XBAR input information, using %u.\n", TI_DRA7_XBAR_INPUTS); xbar->xbar_requests = TI_DRA7_XBAR_INPUTS; } if (!of_property_read_u32(node, "ti,dma-safe-map", &safe_val)) xbar->safe_val = (u16)safe_val; prop = of_find_property(node, "ti,reserved-dma-request-ranges", &sz); if (prop) { const char pname[] = "ti,reserved-dma-request-ranges"; u32 (*rsv_events)[2]; size_t nelm = sz / sizeof(*rsv_events); int i; if (!nelm) return -EINVAL; rsv_events = kcalloc(nelm, sizeof(*rsv_events), GFP_KERNEL); if (!rsv_events) return -ENOMEM; ret = of_property_read_u32_array(node, pname, (u32 *)rsv_events, nelm * 2); if (ret) return ret; for (i = 0; i < nelm; i++) { ti_dra7_xbar_reserve(rsv_events[i][0], rsv_events[i][1], xbar->dma_inuse); } kfree(rsv_events); } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); iomem = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(iomem)) return PTR_ERR(iomem); xbar->iomem = iomem; xbar->dmarouter.dev = &pdev->dev; xbar->dmarouter.route_free = ti_dra7_xbar_free; xbar->dma_offset = *(u32 *)match->data; mutex_init(&xbar->mutex); platform_set_drvdata(pdev, xbar); /* Reset the crossbar */ for (i = 0; i < xbar->dma_requests; i++) { if (!test_bit(i, xbar->dma_inuse)) ti_dra7_xbar_write(xbar->iomem, i, xbar->safe_val); } ret = of_dma_router_register(node, ti_dra7_xbar_route_allocate, &xbar->dmarouter); if (ret) { /* Restore the defaults for the crossbar */ for (i = 0; i < xbar->dma_requests; i++) { if (!test_bit(i, xbar->dma_inuse)) ti_dra7_xbar_write(xbar->iomem, i, i); } } return ret; }
/* * Fill a struct uart_port for a given device node */ static int of_platform_serial_setup(struct platform_device *ofdev, int type, struct uart_port *port, struct of_serial_info *info) { struct resource resource; struct device_node *np = ofdev->dev.of_node; u32 clk, spd, prop; int ret; memset(port, 0, sizeof *port); if (of_property_read_u32(np, "clock-frequency", &clk)) { /* Get clk rate through clk driver if present */ info->clk = devm_clk_get(&ofdev->dev, NULL); if (IS_ERR(info->clk)) { dev_warn(&ofdev->dev, "clk or clock-frequency not defined\n"); return PTR_ERR(info->clk); } ret = clk_prepare_enable(info->clk); if (ret < 0) return ret; clk = clk_get_rate(info->clk); } /* If current-speed was set, then try not to change it. */ if (of_property_read_u32(np, "current-speed", &spd) == 0) port->custom_divisor = clk / (16 * spd); ret = of_address_to_resource(np, 0, &resource); if (ret) { dev_warn(&ofdev->dev, "invalid address\n"); goto out; } spin_lock_init(&port->lock); port->mapbase = resource.start; port->mapsize = resource_size(&resource); /* Check for shifted address mapping */ if (of_property_read_u32(np, "reg-offset", &prop) == 0) { port->mapbase += prop; port->mapsize -= prop; } /* Check for registers offset within the devices address range */ if (of_property_read_u32(np, "reg-shift", &prop) == 0) port->regshift = prop; /* Check for fifo size */ if (of_property_read_u32(np, "fifo-size", &prop) == 0) port->fifosize = prop; /* Check for a fixed line number */ ret = of_alias_get_id(np, "serial"); if (ret >= 0) port->line = ret; port->irq = irq_of_parse_and_map(np, 0); port->iotype = UPIO_MEM; if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { switch (prop) { case 1: port->iotype = UPIO_MEM; break; case 4: port->iotype = of_device_is_big_endian(np) ? UPIO_MEM32BE : UPIO_MEM32; break; default: dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n", prop); ret = -EINVAL; goto out; } } port->type = type; port->uartclk = clk; port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP | UPF_FIXED_PORT | UPF_FIXED_TYPE; if (of_find_property(np, "no-loopback-test", NULL)) port->flags |= UPF_SKIP_TEST; port->dev = &ofdev->dev; switch (type) { case PORT_TEGRA: port->handle_break = tegra_serial_handle_break; break; case PORT_RT2880: port->iotype = UPIO_AU; break; } if (IS_ENABLED(CONFIG_SERIAL_8250_FSL) && (of_device_is_compatible(np, "fsl,ns16550") || of_device_is_compatible(np, "fsl,16550-FIFO64"))) port->handle_irq = fsl8250_handle_irq; return 0; out: if (info->clk) clk_disable_unprepare(info->clk); return ret; }
static void of_gpiochip_add_pin_range(struct gpio_chip *chip) { struct device_node *np = chip->of_node; struct of_phandle_args pinspec; struct pinctrl_dev *pctldev; int index = 0, ret; const char *name; static const char group_names_propname[] = "gpio-ranges-group-names"; struct property *group_names; if (!np) return; group_names = of_find_property(np, group_names_propname, NULL); for (;; index++) { ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, index, &pinspec); if (ret) break; pctldev = of_pinctrl_get(pinspec.np); if (!pctldev) break; if (pinspec.args[2]) { if (group_names) { ret = of_property_read_string_index(np, group_names_propname, index, &name); if (strlen(name)) { pr_err("%s: Group name of numeric GPIO ranges must be the empty string.\n", np->full_name); break; } } /* npins != 0: linear range */ ret = gpiochip_add_pin_range(chip, pinctrl_dev_get_devname(pctldev), pinspec.args[0], pinspec.args[1], pinspec.args[2]); if (ret) break; } else { /* npins == 0: special range */ if (pinspec.args[1]) { pr_err("%s: Illegal gpio-range format.\n", np->full_name); break; } if (!group_names) { pr_err("%s: GPIO group range requested but no %s property.\n", np->full_name, group_names_propname); break; } ret = of_property_read_string_index(np, group_names_propname, index, &name); if (ret) break; if (!strlen(name)) { pr_err("%s: Group name of GPIO group range cannot be the empty string.\n", np->full_name); break; } ret = gpiochip_add_pingroup_range(chip, pctldev, pinspec.args[0], name); if (ret) break; } } }
static int32_t msm_ois_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { int rc = 0; struct msm_ois_ctrl_t *ois_ctrl_t = NULL; struct msm_ois_vreg *vreg_cfg; bool check_use_gpios; CDBG_I("Enter\n"); if (client == NULL) { pr_err("msm_ois_i2c_probe: client is null\n"); rc = -EINVAL; goto probe_failure; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("i2c_check_functionality failed\n"); goto probe_failure; } if (!client->dev.of_node) { ois_ctrl_t = (struct msm_ois_ctrl_t *)(id->driver_data); } else { ois_ctrl_t = kzalloc(sizeof(struct msm_ois_ctrl_t), GFP_KERNEL); if (!ois_ctrl_t) { pr_err("%s:%d no memory\n", __func__, __LINE__); return -ENOMEM; } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { pr_err("i2c_check_functionality failed\n"); goto probe_failure; } CDBG("client = 0x%p\n", client); rc = of_property_read_u32(client->dev.of_node, "cell-index", &ois_ctrl_t->subdev_id); CDBG("cell-index %d, rc %d\n", ois_ctrl_t->subdev_id, rc); ois_ctrl_t->cam_name = ois_ctrl_t->subdev_id; if (rc < 0) { pr_err("failed rc %d\n", rc); kfree(ois_ctrl_t);//prevent return rc; } check_use_gpios = of_property_read_bool(client->dev.of_node, "unuse-gpios"); CDBG("%s: check unuse-gpio flag(%d)\n", __FUNCTION__, check_use_gpios); if (!check_use_gpios) { rc = msm_ois_get_gpio_data(ois_ctrl_t, client->dev.of_node); } } if (of_find_property(client->dev.of_node, "qcom,cam-vreg-name", NULL)) { vreg_cfg = &ois_ctrl_t->vreg_cfg; rc = msm_camera_get_dt_vreg_data(client->dev.of_node, &vreg_cfg->cam_vreg, &vreg_cfg->num_vreg); if (rc < 0) { kfree(ois_ctrl_t); pr_err("failed rc %d\n", rc); return rc; } } ois_ctrl_t->ois_v4l2_subdev_ops = &msm_ois_subdev_ops; ois_ctrl_t->ois_mutex = &msm_ois_mutex; ois_ctrl_t->i2c_driver = &msm_ois_i2c_driver; CDBG("client = %x\n", (unsigned int) client); ois_ctrl_t->i2c_client.client = client; ois_ctrl_t->i2c_client.addr_type = MSM_CAMERA_I2C_WORD_ADDR; /* Set device type as I2C */ ois_ctrl_t->ois_device_type = MSM_CAMERA_I2C_DEVICE; ois_ctrl_t->i2c_client.i2c_func_tbl = &msm_sensor_qup_func_tbl; ois_ctrl_t->ois_v4l2_subdev_ops = &msm_ois_subdev_ops; ois_ctrl_t->ois_mutex = &msm_ois_mutex; ois_ctrl_t->cam_name = ois_ctrl_t->subdev_id; CDBG("ois_ctrl_t->cam_name: %d", ois_ctrl_t->cam_name); /* Assign name for sub device */ snprintf(ois_ctrl_t->msm_sd.sd.name, sizeof(ois_ctrl_t->msm_sd.sd.name), "%s", ois_ctrl_t->i2c_driver->driver.name); /* Initialize sub device */ v4l2_i2c_subdev_init(&ois_ctrl_t->msm_sd.sd, ois_ctrl_t->i2c_client.client, ois_ctrl_t->ois_v4l2_subdev_ops); v4l2_set_subdevdata(&ois_ctrl_t->msm_sd.sd, ois_ctrl_t); ois_ctrl_t->msm_sd.sd.internal_ops = &msm_ois_internal_ops; ois_ctrl_t->msm_sd.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; media_entity_init(&ois_ctrl_t->msm_sd.sd.entity, 0, NULL, 0); ois_ctrl_t->msm_sd.sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV; ois_ctrl_t->msm_sd.sd.entity.group_id = MSM_CAMERA_SUBDEV_OIS; ois_ctrl_t->msm_sd.close_seq = MSM_SD_CLOSE_2ND_CATEGORY | 0xB; msm_sd_register(&ois_ctrl_t->msm_sd); //g_ois_i2c_client.client = ois_ctrl_t->i2c_client.client; CDBG("Succeded Exit\n"); return rc; probe_failure: if (ois_ctrl_t) kfree(ois_ctrl_t); return rc; }
int of_pinctrl_select_state(struct device_node *np, const char *name) { int state, ret; char *propname; struct property *prop; const __be32 *list; int size, config; phandle phandle; struct device_node *np_config; const char *statename; if (!of_find_property(np, "pinctrl-0", NULL)) return 0; /* For each defined state ID */ for (state = 0; ; state++) { /* Retrieve the pinctrl-* property */ propname = basprintf("pinctrl-%d", state); prop = of_find_property(np, propname, NULL); free(propname); if (!prop) { ret = -ENODEV; break; } size = prop->length; list = prop->value; size /= sizeof(*list); /* Determine whether pinctrl-names property names the state */ ret = of_property_read_string_index(np, "pinctrl-names", state, &statename); /* * If not, statename is just the integer state ID. But rather * than dynamically allocate it and have to free it later, * just point part way into the property name for the string. */ if (ret < 0) { /* strlen("pinctrl-") == 8 */ statename = prop->name + 8; } if (strcmp(name, statename)) continue; /* For every referenced pin configuration node in it */ for (config = 0; config < size; config++) { phandle = be32_to_cpup(list++); /* Look up the pin configuration node */ np_config = of_find_node_by_phandle(phandle); if (!np_config) { pr_err("prop %s %s index %i invalid phandle\n", np->full_name, prop->name, config); ret = -EINVAL; goto err; } /* Parse the node */ ret = pinctrl_config_one(np_config); if (ret < 0) goto err; } return 0; } err: return ret; }
static int32_t msm_ois_platform_probe(struct platform_device *pdev) { int32_t rc = 0; struct msm_camera_cci_client *cci_client = NULL; struct msm_ois_ctrl_t *msm_ois_t = NULL; struct msm_ois_vreg *vreg_cfg; CDBG_I("Enter\n"); if (!pdev->dev.of_node) { pr_err("of_node NULL\n"); return -EINVAL; } msm_ois_t = kzalloc(sizeof(struct msm_ois_ctrl_t), GFP_KERNEL); if (!msm_ois_t) { pr_err("%s:%d failed no memory\n", __func__, __LINE__); return -ENOMEM; } rc = of_property_read_u32((&pdev->dev)->of_node, "cell-index", &pdev->id); CDBG("cell-index %d, rc %d\n", pdev->id, rc); if (rc < 0) { kfree(msm_ois_t); pr_err("failed rc %d\n", rc); return rc; } msm_ois_t->subdev_id = pdev->id; rc = of_property_read_u32((&pdev->dev)->of_node, "qcom,cci-master", &msm_ois_t->cci_master); CDBG("qcom,cci-master %d, rc %d\n", msm_ois_t->cci_master, rc); if (rc < 0) { kfree(msm_ois_t); pr_err("failed rc %d\n", rc); return rc; } if (of_find_property((&pdev->dev)->of_node, "qcom,cam-vreg-name", NULL)) { vreg_cfg = &msm_ois_t->vreg_cfg; rc = msm_camera_get_dt_vreg_data((&pdev->dev)->of_node, &vreg_cfg->cam_vreg, &vreg_cfg->num_vreg); if (rc < 0) { kfree(msm_ois_t); pr_err("failed rc %d\n", rc); return rc; } } msm_ois_t->ois_v4l2_subdev_ops = &msm_ois_subdev_ops; msm_ois_t->ois_mutex = &msm_ois_mutex; msm_ois_t->cam_name = pdev->id; /* Set platform device handle */ msm_ois_t->pdev = pdev; /* Set device type as platform device */ msm_ois_t->ois_device_type = MSM_CAMERA_PLATFORM_DEVICE; msm_ois_t->i2c_client.i2c_func_tbl = &msm_sensor_cci_func_tbl; msm_ois_t->i2c_client.addr_type = MSM_CAMERA_I2C_WORD_ADDR; msm_ois_t->i2c_client.cci_client = kzalloc(sizeof( struct msm_camera_cci_client), GFP_KERNEL); if (!msm_ois_t->i2c_client.cci_client) { kfree(msm_ois_t->vreg_cfg.cam_vreg); kfree(msm_ois_t); pr_err("failed no memory\n"); return -ENOMEM; } cci_client = msm_ois_t->i2c_client.cci_client; cci_client->cci_subdev = msm_cci_get_subdev(); cci_client->cci_i2c_master = MASTER_MAX; v4l2_subdev_init(&msm_ois_t->msm_sd.sd, msm_ois_t->ois_v4l2_subdev_ops); v4l2_set_subdevdata(&msm_ois_t->msm_sd.sd, msm_ois_t); msm_ois_t->msm_sd.sd.internal_ops = &msm_ois_internal_ops; msm_ois_t->msm_sd.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; snprintf(msm_ois_t->msm_sd.sd.name, ARRAY_SIZE(msm_ois_t->msm_sd.sd.name), "msm_ois"); media_entity_init(&msm_ois_t->msm_sd.sd.entity, 0, NULL, 0); msm_ois_t->msm_sd.sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV; msm_ois_t->msm_sd.sd.entity.group_id = MSM_CAMERA_SUBDEV_OIS; msm_ois_t->msm_sd.close_seq = MSM_SD_CLOSE_2ND_CATEGORY | 0xB; rc = msm_sd_register(&msm_ois_t->msm_sd); //g_ois_i2c_client.cci_client = msm_ois_t->i2c_client.cci_client; CDBG("Exit[rc::%d]\n", rc); return rc; }
static int tb10x_gpio_probe(struct platform_device *pdev) { struct tb10x_gpio *tb10x_gpio; struct resource *mem; struct device_node *dn = pdev->dev.of_node; int ret = -EBUSY; u32 ngpio; if (!dn) return -EINVAL; if (of_property_read_u32(dn, "abilis,ngpio", &ngpio)) return -EINVAL; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem) { dev_err(&pdev->dev, "No memory resource defined.\n"); return -EINVAL; } tb10x_gpio = devm_kzalloc(&pdev->dev, sizeof(*tb10x_gpio), GFP_KERNEL); if (tb10x_gpio == NULL) return -ENOMEM; spin_lock_init(&tb10x_gpio->spinlock); tb10x_gpio->base = devm_ioremap_resource(&pdev->dev, mem); if (IS_ERR(tb10x_gpio->base)) return PTR_ERR(tb10x_gpio->base); tb10x_gpio->gc.label = of_node_full_name(dn); tb10x_gpio->gc.dev = &pdev->dev; tb10x_gpio->gc.owner = THIS_MODULE; tb10x_gpio->gc.direction_input = tb10x_gpio_direction_in; tb10x_gpio->gc.get = tb10x_gpio_get; tb10x_gpio->gc.direction_output = tb10x_gpio_direction_out; tb10x_gpio->gc.set = tb10x_gpio_set; tb10x_gpio->gc.request = tb10x_gpio_request; tb10x_gpio->gc.free = tb10x_gpio_free; tb10x_gpio->gc.base = -1; tb10x_gpio->gc.ngpio = ngpio; tb10x_gpio->gc.can_sleep = false; ret = gpiochip_add(&tb10x_gpio->gc); if (ret < 0) { dev_err(&pdev->dev, "Could not add gpiochip.\n"); goto fail_gpiochip_registration; } platform_set_drvdata(pdev, tb10x_gpio); if (of_find_property(dn, "interrupt-controller", NULL)) { struct irq_chip_generic *gc; ret = platform_get_irq(pdev, 0); if (ret < 0) { dev_err(&pdev->dev, "No interrupt specified.\n"); goto fail_get_irq; } tb10x_gpio->gc.to_irq = tb10x_gpio_to_irq; tb10x_gpio->irq = ret; ret = devm_request_irq(&pdev->dev, ret, tb10x_gpio_irq_cascade, IRQF_TRIGGER_NONE | IRQF_SHARED, dev_name(&pdev->dev), tb10x_gpio); if (ret != 0) goto fail_request_irq; tb10x_gpio->domain = irq_domain_add_linear(dn, tb10x_gpio->gc.ngpio, &irq_generic_chip_ops, NULL); if (!tb10x_gpio->domain) { ret = -ENOMEM; goto fail_irq_domain; } ret = irq_alloc_domain_generic_chips(tb10x_gpio->domain, tb10x_gpio->gc.ngpio, 1, tb10x_gpio->gc.label, handle_edge_irq, IRQ_NOREQUEST, IRQ_NOPROBE, IRQ_GC_INIT_MASK_CACHE); if (ret) goto fail_irq_domain; gc = tb10x_gpio->domain->gc->gc[0]; gc->reg_base = tb10x_gpio->base; gc->chip_types[0].type = IRQ_TYPE_EDGE_BOTH; gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit; gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit; gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit; gc->chip_types[0].chip.irq_set_type = tb10x_gpio_irq_set_type; gc->chip_types[0].regs.ack = OFFSET_TO_REG_CHANGE; gc->chip_types[0].regs.mask = OFFSET_TO_REG_INT_EN; } return 0; fail_irq_domain: fail_request_irq: fail_get_irq: gpiochip_remove(&tb10x_gpio->gc); fail_gpiochip_registration: fail_ioremap: return ret; }
static int qpnp_flash_led_parse_each_led_dt(struct qpnp_flash_led *led, struct flash_node_data *flash_node) { const char *temp_string; struct device_node *node = flash_node->cdev.dev->of_node; int rc = 0; u32 val; rc = of_property_read_string(node, "label", &temp_string); if (!rc) { if (strcmp(temp_string, "flash") == 0) flash_node->type = FLASH; else if (strcmp(temp_string, "torch") == 0) flash_node->type = TORCH; else { dev_err(&led->spmi_dev->dev, "Wrong flash LED type\n"); return -EINVAL; } } else if (rc < 0) { dev_err(&led->spmi_dev->dev, "Unable to read flash type\n"); return rc; } rc = of_property_read_u32(node, "qcom,current", &val); if (!rc) { if (val < FLASH_LED_MIN_CURRENT_MA) val = FLASH_LED_MIN_CURRENT_MA; flash_node->prgm_current = (u16)val; } else if (rc != -EINVAL) { dev_err(&led->spmi_dev->dev, "Unable to read current settings\n"); return rc; } rc = of_property_read_u32(node, "qcom,duration", &val); if (!rc) flash_node->duration = (u16)val; else if (rc != -EINVAL) { dev_err(&led->spmi_dev->dev, "Unable to read clamp current\n"); return rc; } rc = of_property_read_u32(node, "qcom,id", &val); if (!rc) flash_node->id = (u8)val; else if (rc != -EINVAL) { dev_err(&led->spmi_dev->dev, "Unable to read led ID\n"); return rc; } switch (led->peripheral_type) { case FLASH_SUBTYPE_SINGLE: flash_node->current_addr = FLASH_LED0_CURRENT(led->base); flash_node->enable = FLASH_LED0_ENABLEMENT; flash_node->trigger = FLASH_LED0_TRIGGER; break; case FLASH_SUBTYPE_DUAL: if (flash_node->id == FLASH_LED_0) { flash_node->enable = FLASH_LED0_ENABLEMENT; if (flash_node->type == TORCH) flash_node->enable = FLASH_MODULE_ENABLE; flash_node->current_addr = FLASH_LED0_CURRENT(led->base); flash_node->trigger = FLASH_LED0_TRIGGER; } else if (flash_node->id == FLASH_LED_1) { flash_node->enable = FLASH_LED1_ENABLEMENT; if (flash_node->type == TORCH) flash_node->enable = FLASH_MODULE_ENABLE; flash_node->current_addr = FLASH_LED1_CURRENT(led->base); flash_node->trigger = FLASH_LED1_TRIGGER; } break; default: dev_err(&led->spmi_dev->dev, "Invalid peripheral type\n"); } if (of_find_property(node, "boost-supply", NULL)) { INIT_DELAYED_WORK(&flash_node->dwork, qpnp_flash_led_delayed_reg_work); flash_node->boost_regulator = regulator_get(flash_node->cdev.dev, "boost"); if (!flash_node->boost_regulator || IS_ERR(flash_node->boost_regulator)) schedule_delayed_work(&flash_node->dwork, FLASH_BOOST_REGULATOR_PROBE_DELAY_MS); rc = of_property_read_u32(node, "boost-voltage-max", &val); if (!rc) flash_node->boost_voltage_max = val; else { dev_err(&led->spmi_dev->dev, "Unable to read maximum boost regulator voltage\n"); goto error_regulator_config; } } return rc; error_regulator_config: regulator_put(flash_node->boost_regulator); return rc; }
static int parse_dt(struct device *dev, struct synaptics_dsx_board_data *bdata) { int retval; u32 value; const char *name; struct property *prop; struct device_node *np = dev->of_node; bdata->irq_gpio = of_get_named_gpio_flags(np, "synaptics,irq-gpio", 0, NULL); retval = of_property_read_u32(np, "synaptics,irq-on-state", &value); if (retval < 0) bdata->irq_on_state = 0; else bdata->irq_on_state = value; retval = of_property_read_u32(np, "synaptics,irq-flags", &value); if (retval < 0) return retval; else bdata->irq_flags = value; retval = of_property_read_string(np, "synaptics,pwr-reg-name", &name); if (retval == -EINVAL) bdata->pwr_reg_name = NULL; else if (retval < 0) return retval; else bdata->pwr_reg_name = name; retval = of_property_read_string(np, "synaptics,bus-reg-name", &name); if (retval == -EINVAL) bdata->bus_reg_name = NULL; else if (retval < 0) return retval; else bdata->bus_reg_name = name; if (of_property_read_bool(np, "synaptics,power-gpio")) { bdata->power_gpio = of_get_named_gpio_flags(np, "synaptics,power-gpio", 0, NULL); retval = of_property_read_u32(np, "synaptics,power-on-state", &value); if (retval < 0) return retval; else bdata->power_on_state = value; } else { bdata->power_gpio = -1; } if (of_property_read_bool(np, "synaptics,power-delay-ms")) { retval = of_property_read_u32(np, "synaptics,power-delay-ms", &value); if (retval < 0) return retval; else bdata->power_delay_ms = value; } else { bdata->power_delay_ms = 0; } if (of_property_read_bool(np, "synaptics,reset-gpio")) { bdata->reset_gpio = of_get_named_gpio_flags(np, "synaptics,reset-gpio", 0, NULL); retval = of_property_read_u32(np, "synaptics,reset-on-state", &value); if (retval < 0) return retval; else bdata->reset_on_state = value; retval = of_property_read_u32(np, "synaptics,reset-active-ms", &value); if (retval < 0) return retval; else bdata->reset_active_ms = value; } else { bdata->reset_gpio = -1; } if (of_property_read_bool(np, "synaptics,reset-delay-ms")) { retval = of_property_read_u32(np, "synaptics,reset-delay-ms", &value); if (retval < 0) return retval; else bdata->reset_delay_ms = value; } else { bdata->reset_delay_ms = 0; } if (of_property_read_bool(np, "synaptics,dev-dscrptr-addr")) { retval = of_property_read_u32(np, "synaptics,dev-dscrptr-addr", &value); if (retval < 0) return retval; else bdata->device_descriptor_addr = (unsigned short)value; } else { bdata->device_descriptor_addr = 0; } if (of_property_read_bool(np, "synaptics,max-y-for-2d")) { retval = of_property_read_u32(np, "synaptics,max-y-for-2d", &value); if (retval < 0) return retval; else bdata->max_y_for_2d = value; } else { bdata->max_y_for_2d = -1; } bdata->swap_axes = of_property_read_bool(np, "synaptics,swap-axes"); bdata->x_flip = of_property_read_bool(np, "synaptics,x-flip"); bdata->y_flip = of_property_read_bool(np, "synaptics,y-flip"); if (of_property_read_bool(np, "synaptics,ub-i2c-addr")) { retval = of_property_read_u32(np, "synaptics,ub-i2c-addr", &value); if (retval < 0) return retval; else bdata->ub_i2c_addr = (unsigned short)value; } else { bdata->ub_i2c_addr = -1; } prop = of_find_property(np, "synaptics,cap-button-codes", NULL); if (prop && prop->length) { bdata->cap_button_map->map = devm_kzalloc(dev, prop->length, GFP_KERNEL); if (!bdata->cap_button_map->map) return -ENOMEM; bdata->cap_button_map->nbuttons = prop->length / sizeof(u32); retval = of_property_read_u32_array(np, "synaptics,cap-button-codes", bdata->cap_button_map->map, bdata->cap_button_map->nbuttons); if (retval < 0) { bdata->cap_button_map->nbuttons = 0; bdata->cap_button_map->map = NULL; } } else { bdata->cap_button_map->nbuttons = 0; bdata->cap_button_map->map = NULL; } prop = of_find_property(np, "synaptics,vir-button-codes", NULL); if (prop && prop->length) { bdata->vir_button_map->map = devm_kzalloc(dev, prop->length, GFP_KERNEL); if (!bdata->vir_button_map->map) return -ENOMEM; bdata->vir_button_map->nbuttons = prop->length / sizeof(u32); bdata->vir_button_map->nbuttons /= 5; retval = of_property_read_u32_array(np, "synaptics,vir-button-codes", bdata->vir_button_map->map, bdata->vir_button_map->nbuttons * 5); if (retval < 0) { bdata->vir_button_map->nbuttons = 0; bdata->vir_button_map->map = NULL; } } else { bdata->vir_button_map->nbuttons = 0; bdata->vir_button_map->map = NULL; } return 0; }
static struct pwm_regulator_board *pwm_regulator_parse_dt( struct platform_device *pdev, struct of_regulator_match **pwm_reg_matches) { struct pwm_regulator_board *pwm_plat_data; struct device_node *np, *regulators; struct of_regulator_match *matches; int idx = 0, ret, count; struct property *prop; int length; const __be32 *init_vol, *max_vol, *min_vol, *suspend_vol, *coefficient, *id; DBG("%s,line=%d\n", __func__, __LINE__); pwm_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pwm_plat_data), GFP_KERNEL); if (!pwm_plat_data) { dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n"); return NULL; } np = of_node_get(pdev->dev.of_node); regulators = of_find_node_by_name(np, "regulators"); if (!regulators) { dev_err(&pdev->dev, "regulator node not found\n"); return NULL; } count = ARRAY_SIZE(pwm_matches); matches = pwm_matches; ret = of_regulator_match(&pdev->dev, regulators, matches, count); of_node_put(regulators); if (ret < 0) { dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret); return NULL; } pwm_plat_data->num_regulators = count; *pwm_reg_matches = matches; for (idx = 0; idx < count; idx++) { if (!matches[idx].init_data || !matches[idx].of_node) continue; pwm_plat_data->pwm_init_data[idx] = matches[idx].init_data; pwm_plat_data->of_node[idx] = matches[idx].of_node; } init_vol = of_get_property(np, "rockchip,pwm_voltage", NULL); if (init_vol) pwm_plat_data->pwm_init_vol = be32_to_cpu(*init_vol); max_vol = of_get_property(np, "rockchip,pwm_max_voltage", NULL); if (max_vol) pwm_plat_data->pwm_max_vol = be32_to_cpu(*max_vol); min_vol = of_get_property(np, "rockchip,pwm_min_voltage", NULL); if (min_vol) pwm_plat_data->pwm_min_vol = be32_to_cpu(*min_vol); suspend_vol = of_get_property(np, "rockchip,pwm_suspend_voltage", NULL); if (suspend_vol) pwm_plat_data->pwm_suspend_vol = be32_to_cpu(*suspend_vol); coefficient = of_get_property(np, "rockchip,pwm_coefficient", NULL); if (coefficient) pwm_plat_data->pwm_coefficient = be32_to_cpu(*coefficient); id = of_get_property(np, "rockchip,pwm_id", NULL); if (id) pwm_plat_data->pwm_id = be32_to_cpu(*id); prop = of_find_property(np, "rockchip,pwm_voltage_map", &length); if (!prop) return NULL; pwm_plat_data->pwm_vol_map_count = length / sizeof(u32); if (pwm_plat_data->pwm_vol_map_count > 0) { size_t size = sizeof(*pwm_plat_data->pwm_voltage_map) * pwm_plat_data->pwm_vol_map_count; pwm_plat_data->pwm_voltage_map = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (!pwm_plat_data->pwm_voltage_map) return NULL; ret = of_property_read_u32_array(np, "rockchip,pwm_voltage_map", pwm_plat_data->pwm_voltage_map, pwm_plat_data->pwm_vol_map_count); if (ret < 0) printk("pwm voltage map not specified\n"); } return pwm_plat_data; }
static int pil_mss_loadable_init(struct modem_data *drv, struct platform_device *pdev) { struct q6v5_data *q6; struct pil_desc *q6_desc; struct resource *res; struct property *prop; int ret; q6 = pil_q6v5_init(pdev); if (IS_ERR(q6)) return PTR_ERR(q6); drv->q6 = q6; drv->xo = q6->xo; q6_desc = &q6->desc; q6_desc->owner = THIS_MODULE; q6_desc->proxy_timeout = PROXY_TIMEOUT_MS; q6_desc->ops = &pil_msa_mss_ops; q6->self_auth = of_property_read_bool(pdev->dev.of_node, "qcom,pil-self-auth"); if (q6->self_auth) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rmb_base"); q6->rmb_base = devm_request_and_ioremap(&pdev->dev, res); if (!q6->rmb_base) return -ENOMEM; drv->rmb_base = q6->rmb_base; q6_desc->ops = &pil_msa_mss_ops_selfauth; } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg"); if (!res) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "restart_reg_sec"); q6->restart_reg_sec = true; } q6->restart_reg = devm_request_and_ioremap(&pdev->dev, res); if (!q6->restart_reg) return -ENOMEM; q6->vreg = NULL; prop = of_find_property(pdev->dev.of_node, "vdd_mss-supply", NULL); if (prop) { q6->vreg = devm_regulator_get(&pdev->dev, "vdd_mss"); if (IS_ERR(q6->vreg)) return PTR_ERR(q6->vreg); ret = regulator_set_voltage(q6->vreg, VDD_MSS_UV, MAX_VDD_MSS_UV); if (ret) dev_err(&pdev->dev, "Failed to set vreg voltage.\n"); ret = regulator_set_optimum_mode(q6->vreg, 100000); if (ret < 0) { dev_err(&pdev->dev, "Failed to set vreg mode.\n"); return ret; } } q6->vreg_mx = devm_regulator_get(&pdev->dev, "vdd_mx"); if (IS_ERR(q6->vreg_mx)) return PTR_ERR(q6->vreg_mx); prop = of_find_property(pdev->dev.of_node, "vdd_mx-uV", NULL); if (!prop) { dev_err(&pdev->dev, "Missing vdd_mx-uV property\n"); return -EINVAL; } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cxrail_bhs_reg"); if (res) q6->cxrail_bhs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); q6->ahb_clk = devm_clk_get(&pdev->dev, "iface_clk"); if (IS_ERR(q6->ahb_clk)) return PTR_ERR(q6->ahb_clk); q6->axi_clk = devm_clk_get(&pdev->dev, "bus_clk"); if (IS_ERR(q6->axi_clk)) return PTR_ERR(q6->axi_clk); q6->rom_clk = devm_clk_get(&pdev->dev, "mem_clk"); if (IS_ERR(q6->rom_clk)) return PTR_ERR(q6->rom_clk); /* Optional. */ if (of_property_match_string(pdev->dev.of_node, "qcom,active-clock-names", "gpll0_mss_clk") >= 0) q6->gpll0_mss_clk = devm_clk_get(&pdev->dev, "gpll0_mss_clk"); ret = pil_desc_init(q6_desc); return ret; }
/* * Translate OpenFirmware node properties into platform_data */ static int gpio_keys_get_devtree_pdata(struct device *dev, struct gpio_keys_platform_data *pdata) { struct device_node *node, *pp; int i; struct gpio_keys_button *buttons; struct regulator *vddo_vreg; u32 reg; node = dev->of_node; if (node == NULL) return -ENODEV; memset(pdata, 0, sizeof *pdata); pdata->rep = !!of_get_property(node, "autorepeat", NULL); pdata->name = of_get_property(node, "input-name", NULL); vddo_vreg = devm_regulator_get(dev, "vddo"); if (IS_ERR(vddo_vreg)) dev_err(dev, "[Keys] no regulator: ignoring\n"); else{ if(!of_property_read_u32(node, "vddo-voltage", ®)) regulator_set_voltage(vddo_vreg, reg*1000, reg*1000); if(regulator_enable(vddo_vreg)) return -EINVAL; } /* First count the subnodes */ pdata->nbuttons = 0; pp = NULL; while ((pp = of_get_next_child(node, pp))) pdata->nbuttons++; if (pdata->nbuttons == 0) return -ENODEV; buttons = kzalloc(pdata->nbuttons * (sizeof *buttons), GFP_KERNEL); if (!buttons) return -ENOMEM; pp = NULL; i = 0; while ((pp = of_get_next_child(node, pp))) { enum of_gpio_flags flags; if (!of_find_property(pp, "gpios", NULL)) { pdata->nbuttons--; dev_warn(dev, "Found button without gpios\n"); continue; } buttons[i].gpio = of_get_gpio_flags(pp, 0, &flags); buttons[i].active_low = flags & OF_GPIO_ACTIVE_LOW; if (of_property_read_u32(pp, "linux,code", ®)) { dev_err(dev, "Button without keycode: 0x%x\n", buttons[i].gpio); goto out_fail; } buttons[i].code = reg; buttons[i].desc = of_get_property(pp, "label", NULL); #ifdef CONFIG_SENSORS_HALL if ((buttons[i].code == SW_FLIP) || (buttons[i].code == SW_LID)) { pdata->gpio_flip_cover = buttons[i].gpio; pdata->flip_code = buttons[i].code; pdata->nbuttons--; #ifdef CONFIG_SENSORS_HALL_IRQ_CTRL pdata->workaround_set = (of_property_read_bool(pp, "hall_wa_disable") ? false : true); #endif dev_info(dev, "[Hall_IC] device tree was founded\n"); continue; } #endif if (of_property_read_u32(pp, "linux,input-type", ®) == 0) buttons[i].type = reg; else buttons[i].type = EV_KEY; buttons[i].wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); if (of_property_read_u32(pp, "debounce-interval", ®) == 0) buttons[i].debounce_interval = reg; else buttons[i].debounce_interval = 5; dev_info(dev, "%s: label:%s, gpio:%d, code:%d, type:%d, debounce:%d\n", __func__, buttons[i].desc, buttons[i].gpio, buttons[i].code, buttons[i].type, buttons[i].debounce_interval); i++; } pdata->buttons = buttons; return 0; out_fail: kfree(buttons); return -ENODEV; }
/* * Translate OpenFirmware node properties into platform_data */ static int gpio_keys_get_devtree_pdata(struct device *dev, struct gpio_keys_platform_data *pdata) { struct device_node *node, *pp; int i; struct gpio_keys_button *buttons; u32 reg; node = dev->of_node; if (node == NULL) return -ENODEV; memset(pdata, 0, sizeof *pdata); pdata->rep = !!of_get_property(node, "autorepeat", NULL); /* First count the subnodes */ pdata->nbuttons = 0; pp = NULL; while ((pp = of_get_next_child(node, pp))) pdata->nbuttons++; if (pdata->nbuttons == 0) return -ENODEV; buttons = kzalloc(pdata->nbuttons * (sizeof *buttons), GFP_KERNEL); if (!buttons) return -ENOMEM; pp = NULL; i = 0; while ((pp = of_get_next_child(node, pp))) { enum of_gpio_flags flags; if (!of_find_property(pp, "gpios", NULL)) { pdata->nbuttons--; dev_warn(dev, "Found button without gpios\n"); continue; } buttons[i].gpio = of_get_gpio_flags(pp, 0, &flags); buttons[i].active_low = flags & OF_GPIO_ACTIVE_LOW; if (of_property_read_u32(pp, "linux,code", ®)) { dev_err(dev, "Button without keycode: 0x%x\n", buttons[i].gpio); goto out_fail; } buttons[i].code = reg; buttons[i].desc = of_get_property(pp, "label", NULL); if (of_property_read_u32(pp, "linux,input-type", ®) == 0) buttons[i].type = reg; else buttons[i].type = EV_KEY; buttons[i].wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); if (of_property_read_u32(pp, "debounce-interval", ®) == 0) buttons[i].debounce_interval = reg; else buttons[i].debounce_interval = 5; i++; } pdata->buttons = buttons; return 0; out_fail: kfree(buttons); return -ENODEV; }
static struct tegra_emc_pdata *tegra_emc_dt_parse_pdata( struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct device_node *tnp, *iter; struct tegra_emc_pdata *pdata; int ret, i, num_tables; u32 tegra_bct_strapping; if (!np) return NULL; tegra_bct_strapping = tegra_get_bct_strapping(); if (of_find_property(np, "nvidia,use-ram-code", NULL)) { tnp = tegra_emc_ramcode_devnode(np); if (!tnp) dev_warn(&pdev->dev, "can't find emc table for ram-code 0x%02x\n", tegra_bct_strapping); } else tnp = of_node_get(np); if (!tnp) return NULL; num_tables = 0; for_each_child_of_node(tnp, iter) if (of_device_is_compatible(iter, "nvidia,tegra20-emc-table")) num_tables++; if (!num_tables) { pdata = NULL; goto out; } pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); pdata->tables = devm_kzalloc(&pdev->dev, sizeof(*pdata->tables) * num_tables, GFP_KERNEL); i = 0; for_each_child_of_node(tnp, iter) { u32 prop; ret = of_property_read_u32(iter, "clock-frequency", &prop); if (ret) { dev_err(&pdev->dev, "no clock-frequency in %s\n", iter->full_name); continue; } pdata->tables[i].rate = prop; ret = of_property_read_u32_array(iter, "nvidia,emc-registers", pdata->tables[i].regs, TEGRA_EMC_NUM_REGS); if (ret) { dev_err(&pdev->dev, "malformed emc-registers property in %s\n", iter->full_name); continue; } i++; }