Commit 3b73125a authored by Philipp Zabel's avatar Philipp Zabel Committed by Russell King

[ARM] 5044/1: pwm_bl: add init/notify/exit callbacks

This allows platform code to manipulate GPIOs and brightness level as
needed.
Signed-off-by: default avatarPhilipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 4a730719
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
struct pwm_bl_data { struct pwm_bl_data {
struct pwm_device *pwm; struct pwm_device *pwm;
unsigned int period; unsigned int period;
int (*notify)(int brightness);
}; };
static int pwm_backlight_update_status(struct backlight_device *bl) static int pwm_backlight_update_status(struct backlight_device *bl)
...@@ -37,6 +38,9 @@ static int pwm_backlight_update_status(struct backlight_device *bl) ...@@ -37,6 +38,9 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
if (bl->props.fb_blank != FB_BLANK_UNBLANK) if (bl->props.fb_blank != FB_BLANK_UNBLANK)
brightness = 0; brightness = 0;
if (pb->notify)
brightness = pb->notify(brightness);
if (brightness == 0) { if (brightness == 0) {
pwm_config(pb->pwm, 0, pb->period); pwm_config(pb->pwm, 0, pb->period);
pwm_disable(pb->pwm); pwm_disable(pb->pwm);
...@@ -62,30 +66,39 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -62,30 +66,39 @@ static int pwm_backlight_probe(struct platform_device *pdev)
struct platform_pwm_backlight_data *data = pdev->dev.platform_data; struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
struct backlight_device *bl; struct backlight_device *bl;
struct pwm_bl_data *pb; struct pwm_bl_data *pb;
int ret;
if (!data) if (!data)
return -EINVAL; return -EINVAL;
if (data->init) {
ret = data->init(&pdev->dev);
if (ret < 0)
return ret;
}
pb = kzalloc(sizeof(*pb), GFP_KERNEL); pb = kzalloc(sizeof(*pb), GFP_KERNEL);
if (!pb) if (!pb) {
return -ENOMEM; ret = -ENOMEM;
goto err_alloc;
}
pb->period = data->pwm_period_ns; pb->period = data->pwm_period_ns;
pb->notify = data->notify;
pb->pwm = pwm_request(data->pwm_id, "backlight"); pb->pwm = pwm_request(data->pwm_id, "backlight");
if (pb->pwm == NULL) { if (pb->pwm == NULL) {
dev_err(&pdev->dev, "unable to request PWM for backlight\n"); dev_err(&pdev->dev, "unable to request PWM for backlight\n");
kfree(pb); ret = -EBUSY;
return -EBUSY; goto err_pwm;
} }
bl = backlight_device_register(pdev->name, &pdev->dev, bl = backlight_device_register(pdev->name, &pdev->dev,
pb, &pwm_backlight_ops); pb, &pwm_backlight_ops);
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");
pwm_free(pb->pwm); ret = PTR_ERR(bl);
kfree(pb); goto err_bl;
return PTR_ERR(bl);
} }
bl->props.max_brightness = data->max_brightness; bl->props.max_brightness = data->max_brightness;
...@@ -94,10 +107,20 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -94,10 +107,20 @@ static int pwm_backlight_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, bl); platform_set_drvdata(pdev, bl);
return 0; return 0;
err_bl:
pwm_free(pb->pwm);
err_pwm:
kfree(pb);
err_alloc:
if (data->exit)
data->exit(&pdev->dev);
return ret;
} }
static int pwm_backlight_remove(struct platform_device *pdev) static int pwm_backlight_remove(struct platform_device *pdev)
{ {
struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
struct backlight_device *bl = platform_get_drvdata(pdev); struct backlight_device *bl = platform_get_drvdata(pdev);
struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev); struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
...@@ -106,6 +129,8 @@ static int pwm_backlight_remove(struct platform_device *pdev) ...@@ -106,6 +129,8 @@ static int pwm_backlight_remove(struct platform_device *pdev)
pwm_disable(pb->pwm); pwm_disable(pb->pwm);
pwm_free(pb->pwm); pwm_free(pb->pwm);
kfree(pb); kfree(pb);
if (data->exit)
data->exit(&pdev->dev);
return 0; return 0;
} }
......
...@@ -9,6 +9,9 @@ struct platform_pwm_backlight_data { ...@@ -9,6 +9,9 @@ struct platform_pwm_backlight_data {
unsigned int max_brightness; unsigned int max_brightness;
unsigned int dft_brightness; unsigned int dft_brightness;
unsigned int pwm_period_ns; unsigned int pwm_period_ns;
int (*init)(struct device *dev);
int (*notify)(int brightness);
void (*exit)(struct device *dev);
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment