drm: add functions to get/set gamma ramps
parent
eba6cdc936
commit
4e7b246398
|
@ -657,3 +657,39 @@ int drmModeReplaceFB(int fd, uint32_t buffer_id,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
|
||||
uint16_t *red, uint16_t *green, uint16_t *blue)
|
||||
{
|
||||
int ret;
|
||||
struct drm_mode_crtc_lut l;
|
||||
|
||||
l.crtc_id = crtc_id;
|
||||
l.gamma_size = size;
|
||||
l.red = VOID2U64(red);
|
||||
l.green = VOID2U64(green);
|
||||
l.blue = VOID2U64(blue);
|
||||
|
||||
if ((ret = ioctl(fd, DRM_IOCTL_MODE_GETGAMMA, &l)))
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
|
||||
uint16_t *red, uint16_t *green, uint16_t *blue)
|
||||
{
|
||||
int ret;
|
||||
struct drm_mode_crtc_lut l;
|
||||
|
||||
l.crtc_id = crtc_id;
|
||||
l.gamma_size = size;
|
||||
l.red = VOID2U64(red);
|
||||
l.green = VOID2U64(green);
|
||||
l.blue = VOID2U64(blue);
|
||||
|
||||
if ((ret = ioctl(fd, DRM_IOCTL_MODE_SETGAMMA, &l)))
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -263,3 +263,8 @@ extern void drmModeFreePropertyBlob(drmModePropertyBlobPtr ptr);
|
|||
extern int drmModeConnectorSetProperty(int fd, uint32_t connector_id, uint32_t property_id,
|
||||
uint64_t value);
|
||||
extern int drmCheckModesettingSupported(const char *busid);
|
||||
|
||||
extern int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
|
||||
uint16_t *red, uint16_t *green, uint16_t *blue);
|
||||
extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
|
||||
uint16_t *red, uint16_t *green, uint16_t *blue);
|
||||
|
|
|
@ -279,6 +279,11 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)
|
|||
{
|
||||
struct drm_device *dev = crtc->dev;
|
||||
|
||||
if (crtc->gamma_store) {
|
||||
kfree(crtc->gamma_store);
|
||||
crtc->gamma_store = NULL;
|
||||
}
|
||||
|
||||
drm_idr_put(dev, crtc->id);
|
||||
list_del(&crtc->head);
|
||||
dev->mode_config.num_crtc--;
|
||||
|
@ -896,6 +901,7 @@ int drm_mode_getcrtc(struct drm_device *dev,
|
|||
|
||||
crtc_resp->x = crtc->x;
|
||||
crtc_resp->y = crtc->y;
|
||||
crtc_resp->gamma_size = crtc->gamma_size;
|
||||
|
||||
if (crtc->fb)
|
||||
crtc_resp->fb_id = crtc->fb->id;
|
||||
|
@ -2070,3 +2076,112 @@ void drm_mode_connector_detach_encoder(struct drm_connector *connector,
|
|||
}
|
||||
}
|
||||
EXPORT_SYMBOL(drm_mode_connector_detach_encoder);
|
||||
|
||||
bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
|
||||
int gamma_size)
|
||||
{
|
||||
crtc->gamma_size = gamma_size;
|
||||
|
||||
crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL);
|
||||
if (!crtc->gamma_store) {
|
||||
crtc->gamma_size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
|
||||
|
||||
int drm_mode_gamma_set_ioctl(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv)
|
||||
{
|
||||
struct drm_mode_crtc_lut *crtc_lut = data;
|
||||
struct drm_crtc *crtc;
|
||||
void *r_base, *g_base, *b_base;
|
||||
int size;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&dev->mode_config.mutex);
|
||||
crtc = idr_find(&dev->mode_config.crtc_idr, crtc_lut->crtc_id);
|
||||
if (!crtc || (crtc->id != crtc_lut->crtc_id)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* memcpy into gamma store */
|
||||
if (crtc_lut->gamma_size != crtc->gamma_size) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
size = crtc_lut->gamma_size * (sizeof(uint16_t));
|
||||
r_base = crtc->gamma_store;
|
||||
if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
g_base = r_base + size;
|
||||
if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
b_base = g_base + size;
|
||||
if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size);
|
||||
|
||||
out:
|
||||
mutex_unlock(&dev->mode_config.mutex);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int drm_mode_gamma_get_ioctl(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv)
|
||||
{
|
||||
struct drm_mode_crtc_lut *crtc_lut = data;
|
||||
struct drm_crtc *crtc;
|
||||
void *r_base, *g_base, *b_base;
|
||||
int size;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&dev->mode_config.mutex);
|
||||
crtc = idr_find(&dev->mode_config.crtc_idr, crtc_lut->crtc_id);
|
||||
if (!crtc || (crtc->id != crtc_lut->crtc_id)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* memcpy into gamma store */
|
||||
if (crtc_lut->gamma_size != crtc->gamma_size) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
size = crtc_lut->gamma_size * (sizeof(uint16_t));
|
||||
r_base = crtc->gamma_store;
|
||||
if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
g_base = r_base + size;
|
||||
if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
b_base = g_base + size;
|
||||
if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
|
||||
ret = -EFAULT;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
mutex_unlock(&dev->mode_config.mutex);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -315,8 +315,8 @@ struct drm_crtc_funcs {
|
|||
int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
|
||||
|
||||
/* Set gamma on the CRTC */
|
||||
void (*gamma_set)(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
|
||||
int regno);
|
||||
void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
|
||||
uint32_t size);
|
||||
/* Object destroy routine */
|
||||
void (*destroy)(struct drm_crtc *crtc);
|
||||
|
||||
|
@ -354,6 +354,10 @@ struct drm_crtc {
|
|||
int desired_x, desired_y;
|
||||
const struct drm_crtc_funcs *funcs;
|
||||
|
||||
/* CRTC gamma size for reporting to userspace */
|
||||
uint32_t gamma_size;
|
||||
uint16_t *gamma_store;
|
||||
|
||||
/* if you are using the helper */
|
||||
void *helper_private;
|
||||
};
|
||||
|
@ -627,7 +631,8 @@ extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
|
|||
struct drm_encoder *encoder);
|
||||
extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
|
||||
struct drm_encoder *encoder);
|
||||
|
||||
extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
|
||||
int gamma_size);
|
||||
/* IOCTLs */
|
||||
extern int drm_mode_getresources(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv);
|
||||
|
@ -665,7 +670,11 @@ extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
|
|||
void *data, struct drm_file *file_priv);
|
||||
extern int drm_mode_replacefb(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv);
|
||||
int drm_mode_getencoder(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv);
|
||||
extern int drm_mode_getencoder(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv);
|
||||
extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv);
|
||||
extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
|
||||
void *data, struct drm_file *file_priv);
|
||||
#endif /* __DRM_CRTC_H__ */
|
||||
|
||||
|
|
|
@ -143,6 +143,8 @@ static struct drm_ioctl_desc drm_ioctls[] = {
|
|||
|
||||
DRM_IOCTL_DEF(DRM_IOCTL_MODE_REPLACEFB, drm_mode_replacefb, DRM_MASTER|DRM_ROOT_ONLY|DRM_CONTROL_ALLOW),
|
||||
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETENCODER, drm_mode_getencoder, DRM_MASTER|DRM_ROOT_ONLY|DRM_CONTROL_ALLOW),
|
||||
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETGAMMA, drm_mode_gamma_get_ioctl, DRM_MASTER),
|
||||
DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETGAMMA, drm_mode_gamma_set_ioctl, DRM_MASTER),
|
||||
|
||||
DRM_IOCTL_DEF(DRM_IOCTL_MM_INIT, drm_mm_init_ioctl,
|
||||
DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
||||
|
|
|
@ -58,9 +58,6 @@ static int drmfb_setcolreg(unsigned regno, unsigned red, unsigned green,
|
|||
return 1;
|
||||
|
||||
if (fb->depth == 8) {
|
||||
if (crtc->funcs->gamma_set) {
|
||||
crtc->funcs->gamma_set(crtc, red, green, blue, regno);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1056,7 +1056,7 @@ static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
|
|||
}
|
||||
|
||||
/** Sets the color ramps on behalf of RandR */
|
||||
static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
|
||||
void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
|
||||
u16 blue, int regno)
|
||||
{
|
||||
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
|
||||
|
@ -1066,6 +1066,24 @@ static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
|
|||
intel_crtc->lut_b[regno] = blue >> 8;
|
||||
}
|
||||
|
||||
static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
|
||||
u16 *blue, uint32_t size)
|
||||
{
|
||||
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
|
||||
int i;
|
||||
|
||||
if (size != 256)
|
||||
return;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
intel_crtc->lut_r[i] = red[i] >> 8;
|
||||
intel_crtc->lut_g[i] = green[i] >> 8;
|
||||
intel_crtc->lut_b[i] = blue[i] >> 8;
|
||||
}
|
||||
|
||||
intel_crtc_load_lut(crtc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pipe with a simple mode set on it for doing load-based monitor
|
||||
* detection.
|
||||
|
@ -1343,6 +1361,7 @@ void intel_crtc_init(struct drm_device *dev, int pipe)
|
|||
|
||||
drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
|
||||
|
||||
drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
|
||||
intel_crtc->pipe = pipe;
|
||||
for (i = 0; i < 256; i++) {
|
||||
intel_crtc->lut_r[i] = i;
|
||||
|
|
|
@ -104,5 +104,6 @@ extern void intel_sdvo_set_hotplug(struct drm_connector *connector, int enable);
|
|||
extern int intelfb_probe(struct drm_device *dev, struct drm_crtc *crtc, struct drm_connector *connector);
|
||||
extern int intelfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
|
||||
extern int intelfb_resize(struct drm_device *dev, struct drm_crtc *crtc);
|
||||
|
||||
extern void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
|
||||
u16 blue, int regno);
|
||||
#endif /* __INTEL_DRV_H__ */
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "drmP.h"
|
||||
#include "drm.h"
|
||||
#include "drm_crtc.h"
|
||||
#include "intel_drv.h"
|
||||
#include "i915_drm.h"
|
||||
#include "i915_drv.h"
|
||||
|
||||
|
@ -79,8 +80,7 @@ static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
|
|||
return 1;
|
||||
|
||||
if (fb->depth == 8) {
|
||||
if (crtc->funcs->gamma_set)
|
||||
crtc->funcs->gamma_set(crtc, red, green, blue, regno);
|
||||
intel_crtc_fb_gamma_set(crtc, red, green, blue, regno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@ static int radeonfb_setcolreg(unsigned regno, unsigned red,
|
|||
if (regno > 255) {
|
||||
return 1;
|
||||
}
|
||||
if (crtc->funcs->gamma_set) {
|
||||
crtc->funcs->gamma_set(crtc, red, green, blue, regno);
|
||||
}
|
||||
// if (crtc->funcs->gamma_set) {
|
||||
// crtc->funcs->gamma_set(crtc, red, green, blue, regno);
|
||||
// }
|
||||
if (regno < 16) {
|
||||
switch (fb->depth) {
|
||||
case 15:
|
||||
|
|
|
@ -1048,7 +1048,7 @@ struct drm_mode_crtc {
|
|||
|
||||
int count_possibles;
|
||||
unsigned int possibles; /**< Connectors that can be connected */
|
||||
int gamma_size;
|
||||
uint32_t gamma_size;
|
||||
int mode_valid;
|
||||
struct drm_mode_modeinfo mode;
|
||||
};
|
||||
|
@ -1173,6 +1173,16 @@ struct drm_mode_hotplug {
|
|||
uint32_t counter;
|
||||
};
|
||||
|
||||
struct drm_mode_crtc_lut {
|
||||
|
||||
uint32_t crtc_id;
|
||||
uint32_t gamma_size;
|
||||
|
||||
uint64_t red;
|
||||
uint64_t green;
|
||||
uint64_t blue;
|
||||
};
|
||||
|
||||
/**
|
||||
* \name Ioctls Definitions
|
||||
*/
|
||||
|
@ -1289,6 +1299,9 @@ struct drm_mode_hotplug {
|
|||
|
||||
#define DRM_IOCTL_MODE_REPLACEFB DRM_IOWR(0xAF, struct drm_mode_fb_cmd)
|
||||
#define DRM_IOCTL_MODE_GETENCODER DRM_IOWR(0xB0, struct drm_mode_get_encoder)
|
||||
#define DRM_IOCTL_MODE_GETGAMMA DRM_IOWR(0xB1, struct drm_mode_crtc_lut)
|
||||
#define DRM_IOCTL_MODE_SETGAMMA DRM_IOWR(0xB2, struct drm_mode_crtc_lut)
|
||||
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -145,6 +145,7 @@ int printCrtc(int fd, drmModeResPtr res, drmModeCrtcPtr crtc, uint32_t id)
|
|||
printf("\twidth : %i\n", crtc->width);
|
||||
printf("\theight : %i\n", crtc->height);
|
||||
printf("\tmode : %p\n", &crtc->mode);
|
||||
printf("\tgamma size : %d\n", crtc->gamma_size);
|
||||
printf("\tnum connectors : %i\n", crtc->count_connectors);
|
||||
printf("\tconnectors : %i\n", crtc->connectors);
|
||||
printf("\tnum possible : %i\n", crtc->count_possibles);
|
||||
|
|
Loading…
Reference in New Issue