806
810
static void omapfb_calc_addr(const struct omapfb_info *ofbi,
807
811
const struct fb_var_screeninfo *var,
808
812
const struct fb_fix_screeninfo *fix,
809
int rotation, u32 *paddr, void __iomem **vaddr)
813
int rotation, u32 *paddr)
811
815
u32 data_start_p;
812
void __iomem *data_start_v;
815
if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
818
if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
816
819
data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation);
819
821
data_start_p = omapfb_get_region_paddr(ofbi);
820
data_start_v = omapfb_get_region_vaddr(ofbi);
823
823
if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
824
824
offset = calc_rotation_offset_vrfb(var, fix, rotation);
826
826
offset = calc_rotation_offset_dma(var, fix, rotation);
828
828
data_start_p += offset;
829
data_start_v += offset;
832
831
DBG("offset %d, %d = %d\n",
833
832
var->xoffset, var->yoffset, offset);
835
DBG("paddr %x, vaddr %p\n", data_start_p, data_start_v);
834
DBG("paddr %x\n", data_start_p);
837
836
*paddr = data_start_p;
838
*vaddr = data_start_v;
841
839
/* setup overlay according to the fb */
1735
static void omapfb_auto_update_work(struct work_struct *work)
1737
struct omap_dss_device *dssdev;
1738
struct omap_dss_driver *dssdrv;
1739
struct omapfb_display_data *d;
1742
struct omapfb2_device *fbdev;
1744
d = container_of(work, struct omapfb_display_data,
1745
auto_update_work.work);
1748
dssdrv = dssdev->driver;
1751
if (!dssdrv || !dssdrv->update)
1755
dssdrv->sync(dssdev);
1757
dssdrv->get_resolution(dssdev, &w, &h);
1758
dssdrv->update(dssdev, 0, 0, w, h);
1760
freq = auto_update_freq;
1763
queue_delayed_work(fbdev->auto_update_wq,
1764
&d->auto_update_work, HZ / freq);
1767
void omapfb_start_auto_update(struct omapfb2_device *fbdev,
1768
struct omap_dss_device *display)
1770
struct omapfb_display_data *d;
1772
if (fbdev->auto_update_wq == NULL) {
1773
struct workqueue_struct *wq;
1775
wq = create_singlethread_workqueue("omapfb_auto_update");
1778
dev_err(fbdev->dev, "Failed to create workqueue for "
1783
fbdev->auto_update_wq = wq;
1786
d = get_display_data(fbdev, display);
1788
INIT_DELAYED_WORK(&d->auto_update_work, omapfb_auto_update_work);
1790
d->auto_update_work_enabled = true;
1792
omapfb_auto_update_work(&d->auto_update_work.work);
1795
void omapfb_stop_auto_update(struct omapfb2_device *fbdev,
1796
struct omap_dss_device *display)
1798
struct omapfb_display_data *d;
1800
d = get_display_data(fbdev, display);
1802
cancel_delayed_work_sync(&d->auto_update_work);
1804
d->auto_update_work_enabled = false;
1729
1807
/* initialize fb_info, var, fix to something sane based on the display */
1730
1808
static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi)
1862
1940
for (i = 0; i < fbdev->num_displays; i++) {
1863
if (fbdev->displays[i]->state != OMAP_DSS_DISPLAY_DISABLED)
1864
fbdev->displays[i]->driver->disable(fbdev->displays[i]);
1866
omap_dss_put_device(fbdev->displays[i]);
1941
struct omap_dss_device *dssdev = fbdev->displays[i].dssdev;
1943
if (fbdev->displays[i].auto_update_work_enabled)
1944
omapfb_stop_auto_update(fbdev, dssdev);
1946
if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
1947
dssdev->driver->disable(dssdev);
1949
omap_dss_put_device(dssdev);
1952
if (fbdev->auto_update_wq != NULL) {
1953
flush_workqueue(fbdev->auto_update_wq);
1954
destroy_workqueue(fbdev->auto_update_wq);
1955
fbdev->auto_update_wq = NULL;
1869
1958
dev_set_drvdata(fbdev->dev, NULL);
1873
static void size_notify(struct fb_info *fbi, int w, int h)
1875
struct omapfb_info *ofbi = FB2OFB(fbi);
1876
struct fb_var_screeninfo var = fbi->var;
1877
struct fb_var_screeninfo saved_var = fbi->var;
1879
int new_size = (w * var.bits_per_pixel >> 3) * h;
1881
DBG("size_notify: %dx%d\n", w, h);
1883
var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_ALL | FB_ACTIVATE_NOW;
1886
var.xres_virtual = w;
1887
var.yres_virtual = h;
1891
/* Try to increase memory allocated for FB, if needed */
1892
if (new_size > ofbi->region->size) {
1893
DBG("re-allocating FB - old size: %ld - new size: %d\n", ofbi->region->size, new_size);
1894
omapfb_get_mem_region(ofbi->region);
1895
omapfb_realloc_fbmem(fbi, new_size, 0);
1896
omapfb_put_mem_region(ofbi->region);
1899
/* this ensures fbdev clients, like the console driver, get notified about
1902
orig_flags = fbi->flags;
1903
fbi->flags |= FBINFO_MISC_USEREVENT;
1904
fb_set_var(fbi, &var);
1905
fbi->flags &= ~FBINFO_MISC_USEREVENT;
1907
/* now delete old mode:
1909
saved_var.activate |= FB_ACTIVATE_INV_MODE;
1910
fbi->flags |= FBINFO_MISC_USEREVENT;
1911
fb_set_var(fbi, &saved_var);
1912
fbi->flags = orig_flags;
1917
struct omapfb_notifier_block {
1918
struct notifier_block notifier;
1919
struct omapfb2_device *fbdev;
1922
static int omapfb_notifier(struct notifier_block *nb,
1923
unsigned long evt, void *arg)
1925
struct omapfb_notifier_block *notifier =
1926
container_of(nb, struct omapfb_notifier_block, notifier);
1927
struct omap_dss_device *dssdev = arg;
1928
struct omapfb2_device *fbdev = notifier->fbdev;
1932
/* figure out if this event pertains to this omapfb device:
1934
for (i = 0; i < fbdev->num_managers; i++) {
1935
if (fbdev->managers[i]->device == dssdev) {
1944
/* the event pertains to us.. see if we care:
1947
case OMAP_DSS_SIZE_CHANGE: {
1949
dssdev->driver->get_resolution(dssdev, &w, &h);
1950
for (i = 0; i < fbdev->num_fbs; i++)
1951
size_notify(fbdev->fbs[i], w, h);
1954
default: /* don't care about other events for now */
1961
1962
static int omapfb_create_framebuffers(struct omapfb2_device *fbdev)
2176
2177
struct omap_video_timings timings, temp_timings;
2178
struct omapfb_display_data *d;
2178
2180
r = omapfb_mode_to_timings(mode_str, &timings, &bpp);
2182
fbdev->bpp_overrides[fbdev->num_bpp_overrides].dssdev = display;
2183
fbdev->bpp_overrides[fbdev->num_bpp_overrides].bpp = bpp;
2184
++fbdev->num_bpp_overrides;
2184
d = get_display_data(fbdev, display);
2185
d->bpp_override = bpp;
2186
2187
if (display->driver->check_timings) {
2187
2188
r = display->driver->check_timings(display, &timings);
2207
2208
static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev,
2208
2209
struct omap_dss_device *dssdev)
2211
struct omapfb_display_data *d;
2212
2213
BUG_ON(dssdev->driver->get_recommended_bpp == NULL);
2214
for (i = 0; i < fbdev->num_bpp_overrides; ++i) {
2215
if (dssdev == fbdev->bpp_overrides[i].dssdev)
2216
return fbdev->bpp_overrides[i].bpp;
2215
d = get_display_data(fbdev, dssdev);
2217
if (d->bpp_override != 0)
2218
return d->bpp_override;
2219
2220
return dssdev->driver->get_recommended_bpp(dssdev);
2272
static void fb_videomode_to_omap_timings(struct fb_videomode *m,
2273
struct omap_video_timings *t)
2277
t->pixel_clock = PICOS2KHZ(m->pixclock);
2278
t->hsw = m->hsync_len;
2279
t->hfp = m->right_margin;
2280
t->hbp = m->left_margin;
2281
t->vsw = m->vsync_len;
2282
t->vfp = m->lower_margin;
2283
t->vbp = m->upper_margin;
2286
static int omapfb_find_best_mode(struct omap_dss_device *display,
2287
struct omap_video_timings *timings)
2289
struct fb_monspecs *specs;
2291
int r, i, best_xres, best_idx, len;
2293
if (!display->driver->read_edid)
2297
edid = kmalloc(len, GFP_KERNEL);
2299
r = display->driver->read_edid(display, edid, len);
2303
specs = kzalloc(sizeof(*specs), GFP_KERNEL);
2305
fb_edid_to_monspecs(edid, specs);
2308
fb_edid_add_monspecs(edid + 0x80, specs);
2313
for (i = 0; i < specs->modedb_len; ++i) {
2314
struct fb_videomode *m;
2315
struct omap_video_timings t;
2317
m = &specs->modedb[i];
2319
if (m->pixclock == 0)
2322
/* skip repeated pixel modes */
2323
if (m->xres == 2880 || m->xres == 1440)
2326
fb_videomode_to_omap_timings(m, &t);
2328
r = display->driver->check_timings(display, &t);
2329
if (r == 0 && best_xres < m->xres) {
2330
best_xres = m->xres;
2335
if (best_xres == 0) {
2340
fb_videomode_to_omap_timings(&specs->modedb[best_idx], timings);
2345
fb_destroy_modedb(specs->modedb);
2271
2353
static int omapfb_init_display(struct omapfb2_device *fbdev,
2272
2354
struct omap_dss_device *dssdev)
2274
2356
struct omap_dss_driver *dssdrv = dssdev->driver;
2357
struct omapfb_display_data *d;
2277
2360
r = dssdrv->enable(dssdev);
2396
2473
fbdev->num_displays = 0;
2398
2475
for_each_dss_dev(dssdev) {
2399
struct omapfb_notifier_block *notifier;
2476
struct omapfb_display_data *d;
2400
2478
omap_dss_get_device(dssdev);
2402
2480
if (!dssdev->driver) {
2403
dev_err(&pdev->dev, "no driver for display\n");
2481
dev_warn(&pdev->dev, "no driver for display: %s\n",
2483
omap_dss_put_device(dssdev);
2407
fbdev->displays[fbdev->num_displays++] = dssdev;
2409
notifier = kzalloc(sizeof(struct omapfb_notifier_block), GFP_KERNEL);
2410
notifier->notifier.notifier_call = omapfb_notifier;
2411
notifier->fbdev = fbdev;
2412
omap_dss_add_notify(dssdev, ¬ifier->notifier);
2487
d = &fbdev->displays[fbdev->num_displays++];
2489
if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
2490
d->update_mode = OMAPFB_MANUAL_UPDATE;
2492
d->update_mode = OMAPFB_AUTO_UPDATE;
2429
2509
for (i = 0; i < fbdev->num_managers; i++)
2430
2510
fbdev->managers[i] = omap_dss_get_overlay_manager(i);
2512
/* gfx overlay should be the default one. find a display
2513
* connected to that, and use it as default display */
2514
ovl = omap_dss_get_overlay(0);
2515
if (ovl->manager && ovl->manager->device) {
2516
def_display = ovl->manager->device;
2518
dev_warn(&pdev->dev, "cannot find default display\n");
2432
2522
if (def_mode && strlen(def_mode) > 0) {
2433
2523
if (omapfb_parse_def_modes(fbdev))
2434
2524
dev_warn(&pdev->dev, "cannot parse default modes\n");
2525
} else if (def_display && def_display->driver->set_timings &&
2526
def_display->driver->check_timings) {
2527
struct omap_video_timings t;
2529
r = omapfb_find_best_mode(def_display, &t);
2532
def_display->driver->set_timings(def_display, &t);
2437
2535
r = omapfb_create_framebuffers(fbdev);