|
@@ -13,6 +13,7 @@
|
|
|
*
|
|
*
|
|
|
* Needs a recent kernel (written against 6.18).
|
|
* Needs a recent kernel (written against 6.18).
|
|
|
*/
|
|
*/
|
|
|
|
|
+#include <linux/backlight.h>
|
|
|
#include <linux/debugfs.h>
|
|
#include <linux/debugfs.h>
|
|
|
#include <linux/delay.h>
|
|
#include <linux/delay.h>
|
|
|
#include <linux/i2c.h>
|
|
#include <linux/i2c.h>
|
|
@@ -86,9 +87,10 @@ struct s1d_device {
|
|
|
|
|
|
|
|
struct delayed_work flush_work;
|
|
struct delayed_work flush_work;
|
|
|
|
|
|
|
|
- struct mutex lock; /* protects pending_frame, dirty_y0, dirty_y1 */
|
|
|
|
|
|
|
+ struct mutex lock; /* protects pending_frame, dirty_*, bl_on */
|
|
|
u8 *pending_frame;
|
|
u8 *pending_frame;
|
|
|
unsigned int dirty_y0, dirty_y1;
|
|
unsigned int dirty_y0, dirty_y1;
|
|
|
|
|
+ bool bl_on; /* requested; the worker drives the pin */
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
static struct s1d_device *to_s1d(struct drm_device *drm)
|
|
static struct s1d_device *to_s1d(struct drm_device *drm)
|
|
@@ -125,9 +127,11 @@ static void s1d_flush_work(struct work_struct *work)
|
|
|
struct s1d_device *s = container_of(to_delayed_work(work), struct s1d_device,
|
|
struct s1d_device *s = container_of(to_delayed_work(work), struct s1d_device,
|
|
|
flush_work);
|
|
flush_work);
|
|
|
unsigned int stride = s->panel.stride, y0, y1;
|
|
unsigned int stride = s->panel.stride, y0, y1;
|
|
|
|
|
+ bool bl_on;
|
|
|
int idx, ret;
|
|
int idx, ret;
|
|
|
|
|
|
|
|
mutex_lock(&s->lock);
|
|
mutex_lock(&s->lock);
|
|
|
|
|
+ bl_on = s->bl_on;
|
|
|
y0 = s->dirty_y0;
|
|
y0 = s->dirty_y0;
|
|
|
y1 = s->dirty_y1;
|
|
y1 = s->dirty_y1;
|
|
|
s->dirty_y0 = s->cfg.height;
|
|
s->dirty_y0 = s->cfg.height;
|
|
@@ -137,11 +141,20 @@ static void s1d_flush_work(struct work_struct *work)
|
|
|
(y1 - y0) * stride);
|
|
(y1 - y0) * stride);
|
|
|
mutex_unlock(&s->lock);
|
|
mutex_unlock(&s->lock);
|
|
|
|
|
|
|
|
- if (y1 <= y0)
|
|
|
|
|
- return;
|
|
|
|
|
if (!drm_dev_enter(&s->drm, &idx))
|
|
if (!drm_dev_enter(&s->drm, &idx))
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
|
|
+ /* before the first init this only records the level for init */
|
|
|
|
|
+ if (bl_on != s->panel.backlight) {
|
|
|
|
|
+ ret = s1d_panel_backlight(&s->panel, bl_on);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ drm_err_ratelimited(&s->drm, "backlight failed: %d\n", ret);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (y1 <= y0) {
|
|
|
|
|
+ drm_dev_exit(idx);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ret = s->panel_ready ? 0 : s1d_panel_init(&s->panel);
|
|
ret = s->panel_ready ? 0 : s1d_panel_init(&s->panel);
|
|
|
if (!ret) {
|
|
if (!ret) {
|
|
|
s->panel_ready = true;
|
|
s->panel_ready = true;
|
|
@@ -275,6 +288,11 @@ static void s1d_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_stat
|
|
|
if (s->panel_ready && !s1d_panel_display(&s->panel, true))
|
|
if (s->panel_ready && !s1d_panel_display(&s->panel, true))
|
|
|
goto out;
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
+ /* init drives the backlight pin too, so give it the current request */
|
|
|
|
|
+ mutex_lock(&s->lock);
|
|
|
|
|
+ s->panel.backlight = s->bl_on;
|
|
|
|
|
+ mutex_unlock(&s->lock);
|
|
|
|
|
+
|
|
|
/* VRAM is cleared by init, so the shadow and work frame start at zero */
|
|
/* VRAM is cleared by init, so the shadow and work frame start at zero */
|
|
|
ret = s1d_panel_init(&s->panel);
|
|
ret = s1d_panel_init(&s->panel);
|
|
|
if (ret)
|
|
if (ret)
|
|
@@ -418,6 +436,57 @@ static int s1d_kms_init(struct s1d_device *s)
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* ---- backlight ---------------------------------------------------------- */
|
|
|
|
|
+
|
|
|
|
|
+/* The panel belongs to the worker, so only record the request and kick it */
|
|
|
|
|
+static int s1d_bl_update(struct backlight_device *bd)
|
|
|
|
|
+{
|
|
|
|
|
+ struct s1d_device *s = bl_get_data(bd);
|
|
|
|
|
+
|
|
|
|
|
+ mutex_lock(&s->lock);
|
|
|
|
|
+ s->bl_on = backlight_get_brightness(bd) > 0;
|
|
|
|
|
+ mutex_unlock(&s->lock);
|
|
|
|
|
+ mod_delayed_work(system_long_wq, &s->flush_work, 0);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static const struct backlight_ops s1d_bl_ops = {
|
|
|
|
|
+ .options = BL_CORE_SUSPENDRESUME,
|
|
|
|
|
+ .update_status = s1d_bl_update,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+static void s1d_cancel_work(void *data)
|
|
|
|
|
+{
|
|
|
|
|
+ struct s1d_device *s = data;
|
|
|
|
|
+
|
|
|
|
|
+ cancel_delayed_work_sync(&s->flush_work);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int s1d_backlight_init(struct s1d_device *s)
|
|
|
|
|
+{
|
|
|
|
|
+ const struct backlight_properties props = {
|
|
|
|
|
+ .type = BACKLIGHT_RAW,
|
|
|
|
|
+ .max_brightness = 1,
|
|
|
|
|
+ .brightness = 1,
|
|
|
|
|
+ };
|
|
|
|
|
+ struct backlight_device *bd;
|
|
|
|
|
+ int ret;
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * devm undoes in reverse: this runs after the backlight is gone, so a
|
|
|
|
|
+ * brightness write during unbind cannot leave work behind.
|
|
|
|
|
+ */
|
|
|
|
|
+ ret = devm_add_action_or_reset(&s->client->dev, s1d_cancel_work, s);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ return ret;
|
|
|
|
|
+
|
|
|
|
|
+ s->bl_on = true;
|
|
|
|
|
+ /* the name the frontends look for by default */
|
|
|
|
|
+ bd = devm_backlight_device_register(&s->client->dev, "radio-backlight",
|
|
|
|
|
+ &s->client->dev, s, &s1d_bl_ops, &props);
|
|
|
|
|
+ return PTR_ERR_OR_ZERO(bd);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void s1d_debugfs_init(struct s1d_device *s)
|
|
static void s1d_debugfs_init(struct s1d_device *s)
|
|
|
{
|
|
{
|
|
|
struct dentry *d = s->client->debugfs;
|
|
struct dentry *d = s->client->debugfs;
|
|
@@ -488,6 +557,10 @@ static int s1d_probe(struct i2c_client *client)
|
|
|
if (ret)
|
|
if (ret)
|
|
|
return dev_err_probe(dev, ret, "KMS init failed\n");
|
|
return dev_err_probe(dev, ret, "KMS init failed\n");
|
|
|
|
|
|
|
|
|
|
+ ret = s1d_backlight_init(s);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ return dev_err_probe(dev, ret, "backlight registration failed\n");
|
|
|
|
|
+
|
|
|
i2c_set_clientdata(client, s);
|
|
i2c_set_clientdata(client, s);
|
|
|
|
|
|
|
|
ret = drm_dev_register(&s->drm, 0);
|
|
ret = drm_dev_register(&s->drm, 0);
|