| 1 | |
| 2 |
|
| 3 | #include <linux/export.h>
|
| 4 | #include <linux/limits.h>
|
| 5 | #include <linux/minmax.h>
|
| 6 | #include <linux/module.h>
|
| 7 |
|
| 8 | #include <drm/drm_print.h>
|
| 9 |
|
| 10 | #include "drm_sysfb_helper.h"
|
| 11 |
|
| 12 | int drm_sysfb_get_validated_int(struct drm_device *dev, const char *name,
|
| 13 | u64 value, u32 max)
|
| 14 | {
|
| 15 | if (value > min(max, INT_MAX)) {
|
| 16 | drm_warn(dev, "%s of %llu exceeds maximum of %u\n", name, value, max);
|
| 17 | return -EINVAL;
|
| 18 | }
|
| 19 | return value;
|
| 20 | }
|
| 21 | EXPORT_SYMBOL(drm_sysfb_get_validated_int);
|
| 22 |
|
| 23 | int drm_sysfb_get_validated_int0(struct drm_device *dev, const char *name,
|
| 24 | u64 value, u32 max)
|
| 25 | {
|
| 26 | if (!value) {
|
| 27 | drm_warn(dev, "%s of 0 not allowed\n", name);
|
| 28 | return -EINVAL;
|
| 29 | }
|
| 30 | return drm_sysfb_get_validated_int(dev, name, value, max);
|
| 31 | }
|
| 32 | EXPORT_SYMBOL(drm_sysfb_get_validated_int0);
|
| 33 |
|
| 34 | const struct drm_format_info *drm_sysfb_get_format(struct drm_device *dev,
|
| 35 | const struct drm_sysfb_format *formats,
|
| 36 | size_t nformats,
|
| 37 | const struct pixel_format *pixel)
|
| 38 | {
|
| 39 | const struct drm_format_info *format = NULL;
|
| 40 | size_t i;
|
| 41 |
|
| 42 | for (i = 0; i < nformats; ++i) {
|
| 43 | const struct drm_sysfb_format *f = &formats[i];
|
| 44 |
|
| 45 | if (pixel_format_equal(pixel, &f->pixel)) {
|
| 46 | format = drm_format_info(f->fourcc);
|
| 47 | break;
|
| 48 | }
|
| 49 | }
|
| 50 |
|
| 51 | if (!format)
|
| 52 | drm_warn(dev, "No compatible color format found\n");
|
| 53 |
|
| 54 | return format;
|
| 55 | }
|
| 56 | EXPORT_SYMBOL(drm_sysfb_get_format);
|
| 57 |
|
| 58 | MODULE_DESCRIPTION("Helpers for DRM sysfb drivers");
|
| 59 | MODULE_LICENSE("GPL");
|