static ssize_t l2_l2x_counter_srcx_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos, u32 src_id) { struct mali_l2_cache_core *l2_core = (struct mali_l2_cache_core *)filp->private_data; char buf[64]; long val; int ret; if (cnt >= sizeof(buf)) { return -EINVAL; } if (copy_from_user(&buf, ubuf, cnt)) { return -EFAULT; } buf[cnt] = 0; ret = strict_strtol(buf, 10, &val); if (ret < 0) { return ret; } if (val < 0) { /* any negative input will disable counter */ val = MALI_HW_CORE_NO_COUNTER; } if (0 == src_id) { mali_l2_cache_core_set_counter_src0(l2_core, (u32)val); } else { mali_l2_cache_core_set_counter_src1(l2_core, (u32)val); } *ppos += cnt; return cnt; }
/* Recursive argument parser */ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) { int ret = 0; unsigned long param; long offset; char *tmp; switch (arg[0]) { case '$': ret = parse_probe_vars(arg + 1, ff, is_return); break; case '%': /* named register */ ret = regs_query_register_offset(arg + 1); if (ret >= 0) { ff->func = fetch_register; ff->data = (void *)(unsigned long)ret; ret = 0; } break; case '@': /* memory or symbol */ if (isdigit(arg[1])) { ret = strict_strtoul(arg + 1, 0, ¶m); if (ret) break; ff->func = fetch_memory; ff->data = (void *)param; } else { ret = split_symbol_offset(arg + 1, &offset); if (ret) break; ff->data = alloc_symbol_cache(arg + 1, offset); if (ff->data) ff->func = fetch_symbol; else ret = -EINVAL; } break; case '+': /* indirect memory */ case '-': tmp = strchr(arg, '('); if (!tmp) { ret = -EINVAL; break; } *tmp = '\0'; ret = strict_strtol(arg + 1, 0, &offset); if (ret) break; if (arg[0] == '-') offset = -offset; arg = tmp + 1; tmp = strrchr(arg, ')'); if (tmp) { struct indirect_fetch_data *id; *tmp = '\0'; id = kzalloc(sizeof(struct indirect_fetch_data), GFP_KERNEL); if (!id) return -ENOMEM; id->offset = offset; ret = __parse_probe_arg(arg, &id->orig, is_return); if (ret) kfree(id); else { ff->func = fetch_indirect; ff->data = (void *)id; } } else ret = -EINVAL; break; default: /* TODO: support custom handler */ ret = -EINVAL; } return ret; }
ssize_t store_iwmct_log_level_fw(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { struct iwmct_priv *priv = dev_get_drvdata(d); struct top_msg cmd; char *token, *str_buf = NULL; ssize_t ret = count; u16 cmdlen = 0; int i; long val; u8 src, mask; if (!count) goto exit; str_buf = kzalloc(count, GFP_KERNEL); if (!str_buf) { LOG_ERROR(priv, DEBUGFS, "failed to allocate %zd bytes\n", count); ret = -ENOMEM; goto exit; } memcpy(str_buf, buf, count); cmd.hdr.type = COMM_TYPE_H2D; cmd.hdr.category = COMM_CATEGORY_DEBUG; cmd.hdr.opcode = CMD_DBG_LOG_LEVEL; for (i = 0; ((token = strsep(&str_buf, ",")) != NULL) && (i < FW_LOG_SRC_MAX); i++) { while (isspace(*token)) ++token; if (strict_strtol(token, HEXADECIMAL_RADIX, &val)) { LOG_ERROR(priv, DEBUGFS, "failed to convert string to long %s\n", token); ret = -EINVAL; goto exit; } mask = val & 0xFF; /* LSB */ src = (val & 0XFF00) >> 8; /* 2nd least significant byte. */ iwmct_log_set_fw_filter(src, mask); cmd.u.logdefs[i].logsource = src; cmd.u.logdefs[i].sevmask = mask; } cmd.hdr.length = cpu_to_le16(i * sizeof(cmd.u.logdefs[0])); cmdlen = (i * sizeof(cmd.u.logdefs[0]) + sizeof(cmd.hdr)); ret = iwmct_send_hcmd(priv, (u8 *)&cmd, cmdlen); if (ret) { LOG_ERROR(priv, DEBUGFS, "Failed to send %d bytes of fwcmd, ret=%zd\n", cmdlen, ret); goto exit; } else LOG_INFO(priv, DEBUGFS, "fwcmd sent (%d bytes)\n", cmdlen); ret = count; exit: kfree(str_buf); return ret; }
/* Select whether to free (1) or mark unusable (0) the __init pages. */ static int __init set_initfree(char *str) { strict_strtol(str, 0, &initfree); pr_info("initfree: %s free init pages\n", initfree ? "will" : "won't"); return 1; }
void debug_lcd_parse_cmd_str(char ** str) { char *cmd_seq = NULL; int cmd_seq_num = 0; balongfb_logi("enter succ ! \n"); memset(&g_mipi_lcd_debug_info, 0, sizeof(g_mipi_lcd_debug_info)); while (NULL != (cmd_seq = strsep(str, " \\"))) { balongfb_logi("cmd_seq: %s, cmd_seq_num: %d \n", cmd_seq, cmd_seq_num); if (0 == cmd_seq_num) { if (strnicmp(cmd_seq, "GW", 2) == 0) { g_mipi_lcd_debug_info.cmd_type = DTYPE_GEN_WRITE; g_mipi_lcd_debug_info.ops_type = LCD_DEBUG_OPS_TYPE_WRITE; } else if (strnicmp(cmd_seq, "GR", 2) == 0) { g_mipi_lcd_debug_info.cmd_type = DTYPE_GEN_READ1; g_mipi_lcd_debug_info.ops_type = LCD_DEBUG_OPS_TYPE_READ; } else if (strnicmp(cmd_seq, "DW", 2) == 0) { g_mipi_lcd_debug_info.cmd_type = DTYPE_DCS_WRITE; g_mipi_lcd_debug_info.ops_type = LCD_DEBUG_OPS_TYPE_WRITE; } else if (strnicmp(cmd_seq, "DR", 2) == 0) { g_mipi_lcd_debug_info.cmd_type = DTYPE_DCS_READ; g_mipi_lcd_debug_info.ops_type = LCD_DEBUG_OPS_TYPE_READ; } } else if (cmd_seq_num == 1) { if (strnicmp(cmd_seq, "-1", 2) == 0) { g_mipi_lcd_debug_info.lcd_reg_msb = -1; } else { if( strict_strtol(cmd_seq, 0, &g_mipi_lcd_debug_info.lcd_reg_msb) < 0) { balongfb_loge("strict_strtol lcd_reg_msb fail\n"); } } } else if (cmd_seq_num == 2) { if( strict_strtol(cmd_seq, 0, &g_mipi_lcd_debug_info.lcd_reg_lsb) < 0) { balongfb_loge("strict_strtol lcd_reg_lsb fail\n"); } } else { if (g_mipi_lcd_debug_info.ops_type == LCD_DEBUG_OPS_TYPE_READ) { if( strict_strtol(cmd_seq, 0, &g_mipi_lcd_debug_info.para_num) < 0) { balongfb_loge("strict_strtol para_num fail\n"); } break; } else { if (g_mipi_lcd_debug_info.para_num >= DEBUG_LCD_REG_PARA_MAX_NUM) { g_mipi_lcd_debug_info.para_num = DEBUG_LCD_REG_PARA_MAX_NUM; break; } if (0 == strict_strtol(cmd_seq, 0, &g_mipi_lcd_debug_info.para_array[g_mipi_lcd_debug_info.para_num])) { g_mipi_lcd_debug_info.para_num++; balongfb_logi("g_mipi_lcd_debug_info.para_array[%ld] = %ld \n ",g_mipi_lcd_debug_info.para_num - 1, g_mipi_lcd_debug_info.para_array[g_mipi_lcd_debug_info.para_num - 1] ); } } } cmd_seq_num++; } if (DTYPE_GEN_WRITE == g_mipi_lcd_debug_info.cmd_type) { if (1 == g_mipi_lcd_debug_info.para_num) { g_mipi_lcd_debug_info.cmd_type = DTYPE_GEN_WRITE1; } else if (2 == g_mipi_lcd_debug_info.para_num) { g_mipi_lcd_debug_info.cmd_type = DTYPE_GEN_WRITE2; } else if (2 < g_mipi_lcd_debug_info.para_num) { g_mipi_lcd_debug_info.cmd_type = DTYPE_GEN_LWRITE; } else { balongfb_loge("generic write must have para! para_num = %ld \n", g_mipi_lcd_debug_info.para_num); } } if (DTYPE_DCS_WRITE == g_mipi_lcd_debug_info.cmd_type) { if (1 == g_mipi_lcd_debug_info.para_num) { g_mipi_lcd_debug_info.cmd_type = DTYPE_DCS_WRITE1; } else if (1 < g_mipi_lcd_debug_info.para_num) { g_mipi_lcd_debug_info.cmd_type = DTYPE_DCS_LWRITE; } else { /* do nothing */ } } if (LCD_DEBUG_OPS_TYPE_READ == g_mipi_lcd_debug_info.ops_type) { if (0 == g_mipi_lcd_debug_info.para_num) { g_mipi_lcd_debug_info.para_num = 1; } if (g_mipi_lcd_debug_info.para_num > DEBUG_LCD_REG_PARA_MAX_NUM) { g_mipi_lcd_debug_info.para_num = DEBUG_LCD_REG_PARA_MAX_NUM; } if ((g_mipi_lcd_debug_info.para_num > 1) && (g_mipi_lcd_debug_info.cmd_type == DTYPE_GEN_READ1)) { g_mipi_lcd_debug_info.cmd_type = DTYPE_GEN_READ2; } } balongfb_logi("g_mipi_lcd_debug_info.cmd_type = 0x%x \n" " g_mipi_lcd_debug_info.lcd_reg_msb = %ld \n " " g_mipi_lcd_debug_info.lcd_reg_lsb = %ld \n " " g_mipi_lcd_debug_info.ops_type = %d (0:write,1:read) \n" " g_mipi_lcd_debug_info.para_num = %ld \n", g_mipi_lcd_debug_info.cmd_type, g_mipi_lcd_debug_info.lcd_reg_msb, g_mipi_lcd_debug_info.lcd_reg_lsb, g_mipi_lcd_debug_info.ops_type, g_mipi_lcd_debug_info.para_num); return; }
static ssize_t nvsd_settings_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { struct device *dev = container_of((kobj->parent), struct device, kobj); struct nvhost_device *ndev = to_nvhost_device(dev); struct tegra_dc *dc = nvhost_get_drvdata(ndev); struct tegra_dc_sd_settings *sd_settings = dc->out->sd_settings; ssize_t res = count; bool settings_updated = false; long int result; int err; if (sd_settings) { if (IS_NVSD_ATTR(enable)) { if (sd_settings->phase_in_settings) { err = strict_strtol(buf, 10, &result); if (err) return err; if (nvsd_update_enable(sd_settings, result)) nvsd_check_and_update(1, 1, enable); } else { nvsd_check_and_update(0, 1, enable); } } else if (IS_NVSD_ATTR(aggressiveness)) { err = strict_strtol(buf, 10, &result); if (err) return err; if (nvsd_update_agg(sd_settings, result) && !sd_settings->phase_in_settings) settings_updated = true; } else if (IS_NVSD_ATTR(phase_in_settings)) { nvsd_check_and_update(0, 1, phase_in_settings); } else if (IS_NVSD_ATTR(phase_in_adjustments)) { nvsd_check_and_update(0, 1, phase_in_adjustments); } else if (IS_NVSD_ATTR(bin_width)) { nvsd_check_and_update(0, 8, bin_width); } else if (IS_NVSD_ATTR(hw_update_delay)) { nvsd_check_and_update(0, 2, hw_update_delay); } else if (IS_NVSD_ATTR(use_vid_luma)) { nvsd_check_and_update(0, 1, use_vid_luma); } else if (IS_NVSD_ATTR(coeff)) { int ele[3], i = 0, num = 3; nvsd_get_multi(ele, num, i, 0, 15); if (i == num) { sd_settings->coeff.r = ele[0]; sd_settings->coeff.g = ele[1]; sd_settings->coeff.b = ele[2]; settings_updated = true; } else { res = -EINVAL; } } else if (IS_NVSD_ATTR(blp_time_constant)) { nvsd_check_and_update(0, 1024, blp.time_constant); } else if (IS_NVSD_ATTR(blp_step)) { nvsd_check_and_update(0, 255, blp.step); } else if (IS_NVSD_ATTR(fc_time_limit)) { nvsd_check_and_update(0, 255, fc.time_limit); } else if (IS_NVSD_ATTR(fc_threshold)) { nvsd_check_and_update(0, 255, fc.threshold); #ifdef CONFIG_TEGRA_SD_GEN2 } else if (IS_NVSD_ATTR(k_limit_enable)) { nvsd_check_and_update(0, 1, k_limit_enable); } else if (IS_NVSD_ATTR(k_limit)) { nvsd_check_and_update(128, 255, k_limit); } else if (IS_NVSD_ATTR(sd_window_enable)) { nvsd_check_and_update(0, 1, sd_window_enable); } else if (IS_NVSD_ATTR(sd_window)) { int ele[4], i = 0, num = 4; nvsd_get_multi(ele, num, i, 0, LONG_MAX); if (i == num) { sd_settings->sd_window.h_position = ele[0]; sd_settings->sd_window.v_position = ele[1]; sd_settings->sd_window.h_size = ele[2]; sd_settings->sd_window.v_size = ele[3]; settings_updated = true; } else { res = -EINVAL; } } else if (IS_NVSD_ATTR(soft_clipping_enable)) { nvsd_check_and_update(0, 1, soft_clipping_enable); } else if (IS_NVSD_ATTR(soft_clipping_threshold)) { nvsd_check_and_update(0, 255, soft_clipping_threshold); } else if (IS_NVSD_ATTR(smooth_k_enable)) { nvsd_check_and_update(0, 1, smooth_k_enable); } else if (IS_NVSD_ATTR(smooth_k_incr)) { nvsd_check_and_update(0, 16320, smooth_k_incr); } else if (IS_NVSD_ATTR(use_vpulse2)) { nvsd_check_and_update(0, 1, use_vpulse2); #endif } else if (IS_NVSD_ATTR(lut)) { if (nvsd_lut_store(sd_settings, buf)) res = -EINVAL; else settings_updated = true; } else if (IS_NVSD_ATTR(bltf)) { if (nvsd_bltf_store(sd_settings, buf)) res = -EINVAL; else settings_updated = true; } else { res = -EINVAL; } /* Re-init if our settings were updated. */ if (settings_updated) { mutex_lock(&dc->lock); if (!dc->enabled) { mutex_unlock(&dc->lock); return -ENODEV; } tegra_dc_hold_dc_out(dc); nvsd_init(dc, sd_settings); tegra_dc_release_dc_out(dc); mutex_unlock(&dc->lock); /* Update backlight state IFF we're disabling! */ if (!sd_settings->enable && sd_settings->bl_device) { /* Do the actual brightness update outside of * the mutex */ struct platform_device *pdev = sd_settings->bl_device; struct backlight_device *bl = platform_get_drvdata(pdev); if (bl) backlight_update_status(bl); } } } else { /* This shouldn't be reachable. But just in case... */ res = -EINVAL; } return res; }
static int ad5504_spi_read(struct spi_device *spi, u8 addr, u16 *val) { u16 tmp = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr)); int ret; struct spi_transfer t = { .tx_buf = &tmp, .rx_buf = val, .len = 2, }; struct spi_message m; spi_message_init(&m); spi_message_add_tail(&t, &m); ret = spi_sync(spi, &m); *val = be16_to_cpu(*val) & AD5504_RES_MASK; return ret; } static ssize_t ad5504_write_dac(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); long readin; int ret; ret = strict_strtol(buf, 10, &readin); if (ret) return ret; ret = ad5504_spi_write(st->spi, this_attr->address, readin); return ret ? ret : len; } static ssize_t ad5504_read_dac(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret; u16 val; ret = ad5504_spi_read(st->spi, this_attr->address, &val); if (ret) return ret; return sprintf(buf, "%d\n", val); } static ssize_t ad5504_read_powerdown_mode(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); const char mode[][14] = {"20kohm_to_gnd", "three_state"}; return sprintf(buf, "%s\n", mode[st->pwr_down_mode]); } static ssize_t ad5504_write_powerdown_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); int ret; if (sysfs_streq(buf, "20kohm_to_gnd")) st->pwr_down_mode = AD5504_DAC_PWRDN_20K; else if (sysfs_streq(buf, "three_state")) st->pwr_down_mode = AD5504_DAC_PWRDN_3STATE; else ret = -EINVAL; return ret ? ret : len; } static ssize_t ad5504_read_dac_powerdown(struct device *dev, struct device_attribute *attr, char *buf) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); return sprintf(buf, "%d\n", !(st->pwr_down_mask & (1 << this_attr->address))); } static ssize_t ad5504_write_dac_powerdown(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { long readin; int ret; struct iio_dev *indio_dev = dev_get_drvdata(dev); struct ad5504_state *st = iio_priv(indio_dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = strict_strtol(buf, 10, &readin); if (ret) return ret; if (readin == 0) st->pwr_down_mask |= (1 << this_attr->address); else if (readin == 1) st->pwr_down_mask &= ~(1 << this_attr->address); else ret = -EINVAL; ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL, AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) | AD5504_DAC_PWR(st->pwr_down_mask)); /* writes to the CTRL register must be followed by a NOOP */ ad5504_spi_write(st->spi, AD5504_ADDR_NOOP, 0); return ret ? ret : len; }
&dev_attr_pulses.attr, &dev_attr_counter.attr, NULL, }; static const struct attribute_group soft_pwm_dev_attr_group = { .attrs = (struct attribute **) soft_pwm_dev_attrs, }; /* Export a GPIO pin to sysfs, and claim it for PWM usage. * See the equivalent function in drivers/gpio/gpiolib.c */ static ssize_t export_store(struct class *class, struct class_attribute *attr, const char *buf, size_t len){ long gpio; int status; status = strict_strtol(buf, 0, &gpio); if(status<0){ goto done; } status = gpio_request(gpio, "soft_pwm"); if(status<0){ goto done; } status = gpio_direction_output(gpio,0); if(status<0){ goto done; } status = pwm_export(gpio); if(status<0){ goto done; } set_bit(FLAG_SOFTPWM, &pwm_table[gpio].flags); done: if(status){
static ssize_t pp_all_counter_srcx_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos, u32 src_id) { char buf[64]; long val; int ret; u32 ci; struct mali_cluster *cluster; if (cnt >= sizeof(buf)) { return -EINVAL; } if (copy_from_user(&buf, ubuf, cnt)) { return -EFAULT; } buf[cnt] = 0; ret = strict_strtol(buf, 10, &val); if (ret < 0) { return ret; } if (val < 0) { /* any negative input will disable counter */ val = MALI_HW_CORE_NO_COUNTER; } ci = 0; cluster = mali_cluster_get_global_cluster(ci); while (NULL != cluster) { u32 gi = 0; struct mali_group *group = mali_cluster_get_group(cluster, gi); while (NULL != group) { struct mali_pp_core *pp_core = mali_group_get_pp_core(group); if (NULL != pp_core) { if (0 == src_id) { if (MALI_TRUE != mali_pp_core_set_counter_src0(pp_core, (u32)val)) { return 0; } } else { if (MALI_TRUE != mali_pp_core_set_counter_src1(pp_core, (u32)val)) { return 0; } } } /* try next group */ gi++; group = mali_cluster_get_group(cluster, gi); } /* try next cluster */ ci++; cluster = mali_cluster_get_global_cluster(ci); } *ppos += cnt; return cnt; }
* hall sensor gpio value hi is not detected, lo is detected * */ int gpio_hallsensor_detect() { return !gpio_get_value(IOMUX_TO_GPIO(MX50_PIN_SD2_WP)); } EXPORT_SYMBOL(gpio_hallsensor_detect); static int frontlight_enabled; static ssize_t gpio_frontlight_enable_store(struct class *class, const char *buf, size_t len) { int value; int status; status = strict_strtol(buf, 0, &value); if (status < 0) goto done; frontlight_enabled = value > 0 ? 1 : 0; gpio_frontlight_enable(frontlight_enabled); done: return status ? status : len; } ssize_t gpio_frontlight_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%d\n", frontlight_enabled); }