Ejemplo n.º 1
0
static ssize_t store_linear(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t len)
{
	struct lm3533_bl *bl = dev_get_drvdata(dev);
	unsigned long linear;
	u8 mask;
	u8 val;
	int ret;

	if (kstrtoul(buf, 0, &linear))
		return -EINVAL;

	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);

	if (linear)
		val = mask;
	else
		val = 0;

	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val,
									mask);
	if (ret)
		return ret;

	return len;
}
Ejemplo n.º 2
0
static ssize_t store_als_en(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t len)
{
	struct lm3533_bl *bl = dev_get_drvdata(dev);
	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
	int enable;
	u8 val;
	u8 mask;
	int ret;

	if (kstrtoint(buf, 0, &enable))
		return -EINVAL;

	mask = 1 << (2 * ctrlbank);

	if (enable)
		val = mask;
	else
		val = 0;

	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val,
									mask);
	if (ret)
		return ret;

	return len;
}
Ejemplo n.º 3
0
static int __devinit lm3533_bl_setup(struct lm3533_bl *bl,
					struct lm3533_bl_platform_data *pdata)
{
	int ret;
	u8 mask;
	u8 val;

	ret = lm3533_ctrlbank_set_max_current(&bl->cb, pdata->max_current);
	if (ret)
		return ret;

	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);

	if (pdata->linear)
		val = mask;
	else
		val = 0;

	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val,
									mask);
	if (ret)
		return ret;

	return lm3533_ctrlbank_set_pwm(&bl->cb, pdata->pwm);
}
Ejemplo n.º 4
0
static ssize_t show_als_channel(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct lm3533_bl *bl = dev_get_drvdata(dev);
	unsigned channel = lm3533_bl_get_ctrlbank_id(bl);

	return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
}
Ejemplo n.º 5
0
static ssize_t show_als_en(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct lm3533_bl *bl = dev_get_drvdata(dev);
	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
	u8 val;
	u8 mask;
	bool enable;
	int ret;

	ret = lm3533_read(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, &val);
	if (ret)
		return ret;

	mask = 1 << (2 * ctrlbank);
	enable = val & mask;

	return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
}
Ejemplo n.º 6
0
static ssize_t show_linear(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct lm3533_bl *bl = dev_get_drvdata(dev);
	u8 val;
	u8 mask;
	int linear;
	int ret;

	ret = lm3533_read(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, &val);
	if (ret)
		return ret;

	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);

	if (val & mask)
		linear = 1;
	else
		linear = 0;

	return scnprintf(buf, PAGE_SIZE, "%x\n", linear);
}
Ejemplo n.º 7
0
static ssize_t show_linear(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct lm3533_bl *bl = dev_get_drvdata(dev);
	u8 val;
	u8 mask;
	int linear;
	int ret;
	int i = 0;
	for(i=0x10; i<0xB3; i++)
	{
		ret = lm3533_read(bl->lm3533, i, &val);
		if(ret)
		{
			printk("in %s,can not read [0x%02x]\n",__func__,i);
		}
		else
		{
			printk("in %s,read [0x%02x]: 0x%02x\n",__func__,i,val);
		}

	}

	ret = lm3533_read(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, &val);
	if (ret)
		return ret;

	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);

	if (val & mask)
		linear = 1;
	else
		linear = 0;

	return scnprintf(buf, PAGE_SIZE, "%x\n", linear);
}
Ejemplo n.º 8
0
static int lm3533_bl_probe(struct platform_device *pdev)
{
	struct lm3533 *lm3533;
	struct lm3533_bl_platform_data *pdata;
	struct lm3533_bl *bl;
	struct backlight_device *bd;
	struct backlight_properties props;
	int ret;

	dev_dbg(&pdev->dev, "%s\n", __func__);

	lm3533 = dev_get_drvdata(pdev->dev.parent);
	if (!lm3533)
		return -EINVAL;

	pdata = dev_get_platdata(&pdev->dev);
	if (!pdata) {
		dev_err(&pdev->dev, "no platform data\n");
		return -EINVAL;
	}

	if (pdev->id < 0 || pdev->id >= LM3533_HVCTRLBANK_COUNT) {
		dev_err(&pdev->dev, "illegal backlight id %d\n", pdev->id);
		return -EINVAL;
	}

	bl = devm_kzalloc(&pdev->dev, sizeof(*bl), GFP_KERNEL);
	if (!bl)
		return -ENOMEM;

	bl->lm3533 = lm3533;
	bl->id = pdev->id;

	bl->cb.lm3533 = lm3533;
	bl->cb.id = lm3533_bl_get_ctrlbank_id(bl);
	bl->cb.dev = NULL;			/* until registered */

	memset(&props, 0, sizeof(props));
	props.type = BACKLIGHT_RAW;
	props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
	props.brightness = pdata->default_brightness;
	bd = devm_backlight_device_register(&pdev->dev, pdata->name,
					pdev->dev.parent, bl, &lm3533_bl_ops,
					&props);
	if (IS_ERR(bd)) {
		dev_err(&pdev->dev, "failed to register backlight device\n");
		return PTR_ERR(bd);
	}

	bl->bd = bd;
	bl->cb.dev = &bl->bd->dev;

	platform_set_drvdata(pdev, bl);

	ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
	if (ret < 0) {
		dev_err(&pdev->dev, "failed to create sysfs attributes\n");
		return ret;
	}

	backlight_update_status(bd);

	ret = lm3533_bl_setup(bl, pdata);
	if (ret)
		goto err_sysfs_remove;

	ret = lm3533_ctrlbank_enable(&bl->cb);
	if (ret)
		goto err_sysfs_remove;

	return 0;

err_sysfs_remove:
	sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group);

	return ret;
}