mfd: max8925: Use register offset as REG in backlight

Remove the register offset definition. All these register offset
are transfered as IORESOURCE_REG resources.

Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Haojian Zhuang 2012-09-17 12:19:04 +08:00 committed by Samuel Ortiz
parent 70ffd691ff
commit 63b501e22a
2 changed files with 55 additions and 55 deletions

View File

@ -18,20 +18,16 @@
#include <linux/mfd/core.h> #include <linux/mfd/core.h>
#include <linux/mfd/max8925.h> #include <linux/mfd/max8925.h>
static struct resource backlight_resources[] = { static struct resource bk_resources[] __devinitdata = {
{ { 0x84, 0x84, "mode control", IORESOURCE_REG, },
.name = "max8925-backlight", { 0x85, 0x85, "control", IORESOURCE_REG, },
.start = MAX8925_WLED_MODE_CNTL,
.end = MAX8925_WLED_CNTL,
.flags = IORESOURCE_REG,
},
}; };
static struct mfd_cell backlight_devs[] = { static struct mfd_cell bk_devs[] __devinitdata = {
{ {
.name = "max8925-backlight", .name = "max8925-backlight",
.num_resources = 1, .num_resources = ARRAY_SIZE(bk_resources),
.resources = &backlight_resources[0], .resources = &bk_resources[0],
.id = -1, .id = -1,
}, },
}; };
@ -623,13 +619,14 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
} }
if (pdata && pdata->backlight) { if (pdata && pdata->backlight) {
ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0], bk_devs[0].platform_data = &pdata->backlight;
ARRAY_SIZE(backlight_devs), bk_devs[0].pdata_size = sizeof(struct max8925_backlight_pdata);
&backlight_resources[0], 0, NULL); }
if (ret < 0) { ret = mfd_add_devices(chip->dev, 0, bk_devs, ARRAY_SIZE(bk_devs),
dev_err(chip->dev, "Failed to add backlight subdev\n"); NULL, 0, NULL);
goto out_dev; if (ret < 0) {
} dev_err(chip->dev, "Failed to add backlight subdev\n");
goto out_dev;
} }
if (pdata && pdata->power) { if (pdata && pdata->power) {

View File

@ -27,7 +27,9 @@
struct max8925_backlight_data { struct max8925_backlight_data {
struct max8925_chip *chip; struct max8925_chip *chip;
int current_brightness; int current_brightness;
int reg_mode_cntl;
int reg_cntl;
}; };
static int max8925_backlight_set(struct backlight_device *bl, int brightness) static int max8925_backlight_set(struct backlight_device *bl, int brightness)
@ -42,16 +44,16 @@ static int max8925_backlight_set(struct backlight_device *bl, int brightness)
else else
value = brightness; value = brightness;
ret = max8925_reg_write(chip->i2c, MAX8925_WLED_CNTL, value); ret = max8925_reg_write(chip->i2c, data->reg_cntl, value);
if (ret < 0) if (ret < 0)
goto out; goto out;
if (!data->current_brightness && brightness) if (!data->current_brightness && brightness)
/* enable WLED output */ /* enable WLED output */
ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 1, 1); ret = max8925_set_bits(chip->i2c, data->reg_mode_cntl, 1, 1);
else if (!brightness) else if (!brightness)
/* disable WLED output */ /* disable WLED output */
ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 1, 0); ret = max8925_set_bits(chip->i2c, data->reg_mode_cntl, 1, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
dev_dbg(chip->dev, "set brightness %d\n", value); dev_dbg(chip->dev, "set brightness %d\n", value);
@ -85,7 +87,7 @@ static int max8925_backlight_get_brightness(struct backlight_device *bl)
struct max8925_chip *chip = data->chip; struct max8925_chip *chip = data->chip;
int ret; int ret;
ret = max8925_reg_read(chip->i2c, MAX8925_WLED_CNTL); ret = max8925_reg_read(chip->i2c, data->reg_cntl);
if (ret < 0) if (ret < 0)
return -EINVAL; return -EINVAL;
data->current_brightness = ret; data->current_brightness = ret;
@ -102,69 +104,70 @@ static const struct backlight_ops max8925_backlight_ops = {
static int __devinit max8925_backlight_probe(struct platform_device *pdev) static int __devinit max8925_backlight_probe(struct platform_device *pdev)
{ {
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct max8925_platform_data *max8925_pdata; struct max8925_backlight_pdata *pdata = pdev->dev.platform_data;
struct max8925_backlight_pdata *pdata = NULL;
struct max8925_backlight_data *data; struct max8925_backlight_data *data;
struct backlight_device *bl; struct backlight_device *bl;
struct backlight_properties props; struct backlight_properties props;
struct resource *res; struct resource *res;
char name[MAX8925_NAME_SIZE];
unsigned char value; unsigned char value;
int ret; int ret = 0;
res = platform_get_resource(pdev, IORESOURCE_REG, 0);
if (res == NULL) {
dev_err(&pdev->dev, "No I/O resource!\n");
return -EINVAL;
}
if (pdev->dev.parent->platform_data) {
max8925_pdata = pdev->dev.parent->platform_data;
pdata = max8925_pdata->backlight;
}
if (!pdata) {
dev_err(&pdev->dev, "platform data isn't assigned to "
"backlight\n");
return -EINVAL;
}
data = devm_kzalloc(&pdev->dev, sizeof(struct max8925_backlight_data), data = devm_kzalloc(&pdev->dev, sizeof(struct max8925_backlight_data),
GFP_KERNEL); GFP_KERNEL);
if (data == NULL) if (data == NULL)
return -ENOMEM; return -ENOMEM;
strncpy(name, res->name, MAX8925_NAME_SIZE);
res = platform_get_resource(pdev, IORESOURCE_REG, 0);
if (!res) {
dev_err(&pdev->dev, "No REG resource for mode control!\n");
ret = -ENXIO;
goto out;
}
data->reg_mode_cntl = res->start;
res = platform_get_resource(pdev, IORESOURCE_REG, 1);
if (!res) {
dev_err(&pdev->dev, "No REG resource for control!\n");
ret = -ENXIO;
goto out;
}
data->reg_cntl = res->start;
data->chip = chip; data->chip = chip;
data->current_brightness = 0; data->current_brightness = 0;
memset(&props, 0, sizeof(struct backlight_properties)); memset(&props, 0, sizeof(struct backlight_properties));
props.type = BACKLIGHT_RAW; props.type = BACKLIGHT_RAW;
props.max_brightness = MAX_BRIGHTNESS; props.max_brightness = MAX_BRIGHTNESS;
bl = backlight_device_register(name, &pdev->dev, data, bl = backlight_device_register("max8925-backlight", &pdev->dev, data,
&max8925_backlight_ops, &props); &max8925_backlight_ops, &props);
if (IS_ERR(bl)) { if (IS_ERR(bl)) {
dev_err(&pdev->dev, "failed to register backlight\n"); dev_err(&pdev->dev, "failed to register backlight\n");
return PTR_ERR(bl); ret = PTR_ERR(bl);
goto out;
} }
bl->props.brightness = MAX_BRIGHTNESS; bl->props.brightness = MAX_BRIGHTNESS;
platform_set_drvdata(pdev, bl); platform_set_drvdata(pdev, bl);
value = 0; value = 0;
if (pdata->lxw_scl) if (pdata) {
value |= (1 << 7); if (pdata->lxw_scl)
if (pdata->lxw_freq) value |= (1 << 7);
value |= (LWX_FREQ(pdata->lxw_freq) << 4); if (pdata->lxw_freq)
if (pdata->dual_string) value |= (LWX_FREQ(pdata->lxw_freq) << 4);
value |= (1 << 1); if (pdata->dual_string)
ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 0xfe, value); value |= (1 << 1);
}
ret = max8925_set_bits(chip->i2c, data->reg_mode_cntl, 0xfe, value);
if (ret < 0) if (ret < 0)
goto out; goto out_brt;
backlight_update_status(bl); backlight_update_status(bl);
return 0; return 0;
out: out_brt:
backlight_device_unregister(bl); backlight_device_unregister(bl);
out:
devm_kfree(&pdev->dev, data);
return ret; return ret;
} }