Skip to content

Commit

Permalink
Merge pull request #198 from NiLuJe/master
Browse files Browse the repository at this point in the history
Some Kindle screen refresh experiments...
  • Loading branch information
chrox committed Jul 6, 2014
2 parents ff16057 + aa7f2f1 commit 2ba492e
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 54 deletions.
165 changes: 135 additions & 30 deletions ffi-cdecl/include/mxcfb-kindle.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.
* Copyright 2004-2013 Freescale Semiconductor, Inc. All Rights Reserved.
*
* - Modified by houqp, added mxcfb_update_data struct from GeekMaster's
* video player, refer to:
Expand All @@ -8,6 +8,8 @@
* - Modified mxcfb_alt_buffer_data struct according to include/linux/mxcfb.h
* from Kindle 5.3.0 firmware. Thanks to eureka@mobileread.
* http://www.mobileread.com/forums/showpost.php?p=2337118&postcount=818
*
* - Frankensteined w/ PW2 stuff -- NiLuJe
*/

/*
Expand Down Expand Up @@ -37,6 +39,9 @@
#define FB_SYNC_CLK_IDLE_EN 0x10000000
#define FB_SYNC_SHARP_MODE 0x08000000
#define FB_SYNC_SWAP_RGB 0x04000000
/* PW2 */
#define FB_ACCEL_TRIPLE_FLAG 0x00000000
#define FB_ACCEL_DOUBLE_FLAG 0x00000001

struct mxcfb_gbl_alpha {
int enable;
Expand Down Expand Up @@ -76,35 +81,70 @@ struct mxcfb_rect {
#define GRAYSCALE_8BIT 0x1
#define GRAYSCALE_8BIT_INVERTED 0x2

/* PW2 */
#define GRAYSCALE_4BIT 0x3
#define GRAYSCALE_4BIT_INVERTED 0x4

#define AUTO_UPDATE_MODE_REGION_MODE 0
#define AUTO_UPDATE_MODE_AUTOMATIC_MODE 1

/* Touch/PW1 */
#define AUTO_UPDATE_MODE_AUTOMATIC_MODE_FULL AUTO_UPDATE_MODE_AUTOMATIC_MODE /* Lab126 */
#define AUTO_UPDATE_MODE_AUTOMATIC_MODE_PART 2 /* Lab126 */

#define UPDATE_SCHEME_SNAPSHOT 0
#define UPDATE_SCHEME_QUEUE 1
#define UPDATE_SCHEME_QUEUE_AND_MERGE 2

#define UPDATE_MODE_PARTIAL 0x0
#define UPDATE_MODE_FULL 0x1

#define WAVEFORM_MODE_INIT 0x0 /* Screen goes to white (clears) */
#define WAVEFORM_MODE_DU 0x1 /* Grey->white/grey->black */
#define WAVEFORM_MODE_GC16 0x2 /* High fidelity (flashing) */
#define WAVEFORM_MODE_GC4 WAVEFORM_MODE_GC16 /* For compatibility */
#define WAVEFORM_MODE_GC16_FAST 0x3 /* Medium fidelity */
#define WAVEFORM_MODE_A2 0x4 /* Faster but even lower fidelity */
#define WAVEFORM_MODE_GL16 0x5 /* High fidelity from white transition */
#define WAVEFORM_MODE_GL16_FAST 0x6 /* Medium fidelity from white transition */
#define WAVEFORM_MODE_INIT 0x0 /* Screen goes to white (clears) */
#define WAVEFORM_MODE_DU 0x1 /* Grey->white/grey->black */
#define WAVEFORM_MODE_GC16 0x2 /* High fidelity (flashing) */
#define WAVEFORM_MODE_GC4 WAVEFORM_MODE_GC16 /* For compatibility */
#define WAVEFORM_MODE_GC16_FAST 0x3 /* Medium fidelity */
#define WAVEFORM_MODE_A2 0x4 /* Faster but even lower fidelity */
#define WAVEFORM_MODE_GL16 0x5 /* High fidelity from white transition */
#define WAVEFORM_MODE_GL16_FAST 0x6 /* Medium fidelity from white transition */

/* FW >= 5.3 */
#define WAVEFORM_MODE_DU4 0x7 /* Medium fidelity 4 level of gray direct update */

/* PW2 */
#define WAVEFORM_MODE_REAGL 0x8 /* Ghost compensation waveform */
#define WAVEFORM_MODE_REAGLD 0x9 /* Ghost compensation waveform with dithering */


#define WAVEFORM_MODE_AUTO 257

#define TEMP_USE_AMBIENT 0x1000
#define TEMP_USE_PAPYRUS 0X1001

/* PW2 */
#define TEMP_USE_AUTO 0x1001

#define EPDC_FLAG_ENABLE_INVERSION 0x01
#define EPDC_FLAG_FORCE_MONOCHROME 0x02
#define EPDC_FLAG_USE_CMAP 0x04
#define EPDC_FLAG_USE_ALT_BUFFER 0x100

#define EPDC_FLAG_ENABLE_INVERSION 0x01
#define EPDC_FLAG_FORCE_MONOCHROME 0x02
#define EPDC_FLAG_USE_ALT_BUFFER 0x100
/* PW2 */
#define EPDC_FLAG_TEST_COLLISION 0x200
#define EPDC_FLAG_GROUP_UPDATE 0x400
#define EPDC_FLAG_FORCE_Y2 0x800
#define EPDC_FLAG_USE_REAGLD 0x1000
#define EPDC_FLAG_USE_DITHERING_Y1 0x2000
#define EPDC_FLAG_USE_DITHERING_Y2 0x4000
#define EPDC_FLAG_USE_DITHERING_Y4 0x8000

/* PW2 */
/* Waveform type as return by MXCFB_GET_WAVEFORM_TYPE ioctl */
/* This indicates to user-space what is supported by the waveform */
#define WAVEFORM_TYPE_4BIT 0x1
#define WAVEFORM_TYPE_5BIT (WAVEFORM_TYPE_4BIT << 1)

#define FB_POWERDOWN_DISABLE -1
#define FB_TEMP_AUTO_UPDATE_DISABLE -1

struct mxcfb_alt_buffer_data {
__u32 phys_addr;
Expand All @@ -118,17 +158,22 @@ struct mxcfb_update_data {
__u32 waveform_mode;
__u32 update_mode;
__u32 update_marker;
/* these two fields have been added by amazon */
__u32 hist_bw_waveform_mode;
__u32 hist_gray_waveform_mode;
__u32 hist_bw_waveform_mode; /*Lab126: Def bw waveform for hist analysis*/
__u32 hist_gray_waveform_mode; /*Lab126: Def gray waveform for hist analysis*/
int temp;
uint flags;
struct mxcfb_alt_buffer_data alt_buffer_data;
};
typedef struct mxcfb_update_data mxcfb_update_data;

/* this is only used in kindle firmware 5.0, later version (5.1) has changed
* the struct to mxcfb_update_data (see above) */
/* PW2 */
struct mxcfb_update_marker_data {
__u32 update_marker;
__u32 collision_test;
};

/* This is only used in kindle firmware 5.0, later version (5.1) has changed
* the struct to mxcfb_update_data (see above).
* We don't actually support this, it's just kept here for shit'n giggles ;) */
struct mxcfb_update_data_50x {
struct mxcfb_rect update_region;
__u32 waveform_mode;
Expand All @@ -149,7 +194,29 @@ struct mxcfb_waveform_modes {
int mode_gc4;
int mode_gc8;
int mode_gc16;
int mode_gc16_fast;
int mode_gc32;
int mode_gl16;
int mode_gl16_fast;
int mode_a2;
/* FW >= 5.3 */
int mode_du4;

/* PW2 */
/*
* reagl_flow
*/
int mode_reagl;
int mode_reagld;
};

/* PW2 */
/*
* Structure used to define a 5*3 matrix of parameters for
* setting IPU DP CSC module related to this framebuffer.
*/
struct mxcfb_csc_matrix {
int param[5][3];
};

#define MXCFB_WAIT_FOR_VSYNC _IOW('F', 0x20, u_int32_t)
Expand All @@ -164,31 +231,65 @@ struct mxcfb_waveform_modes {
#define MXCFB_GET_DIFMT _IOR('F', 0x2A, u_int32_t)
#define MXCFB_GET_FB_BLANK _IOR('F', 0x2B, u_int32_t)
#define MXCFB_SET_DIFMT _IOW('F', 0x2C, u_int32_t)
/* PW2 */
#define MXCFB_CSC_UPDATE _IOW('F', 0x2D, struct mxcfb_csc_matrix)

/* IOCTLs for E-ink panel updates */
#define MXCFB_SET_WAVEFORM_MODES _IOW('F', 0x2B, struct mxcfb_waveform_modes)
#define MXCFB_SET_TEMPERATURE _IOW('F', 0x2C, int32_t)
#define MXCFB_SET_AUTO_UPDATE_MODE _IOW('F', 0x2D, __u32)
#define MXCFB_SEND_UPDATE_50X _IOW('F', 0x2E, struct mxcfb_update_data_50x)
#define MXCFB_WAIT_FOR_UPDATE_COMPLETE _IOW('F', 0x2F, __u32)
#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)

/* This evolved on the PW2... */
#define MXCFB_WAIT_FOR_UPDATE_COMPLETE_TOUCH _IOW('F', 0x2F, __u32)
/* PW2 */
#define MXCFB_WAIT_FOR_UPDATE_COMPLETE _IOWR('F', 0x2F, struct mxcfb_update_marker_data)

#define MXCFB_SET_PWRDOWN_DELAY _IOW('F', 0x30, int32_t)
#define MXCFB_GET_PWRDOWN_DELAY _IOR('F', 0x31, int32_t)
#define MXCFB_SET_UPDATE_SCHEME _IOW('F', 0x32, __u32)
#define MXCFB_GET_PMIC_TEMPERATURE _IOR('F', 0x32, int32_t)
#define MXCFB_SET_BORDER_MODE _IOR('F', 0x33, int32_t)
#define MXCFB_SET_EPD_PWR0_CTRL _IOR('F', 0x34, int32_t)
#define MXCFB_SET_EPD_PWR2_CTRL _IOR('F', 0x35, int32_t)
#define MXCFB_SET_TEMP_AUTO_UPDATE_PERIOD _IOR('F', 0x36, int32_t)
#define MXCFB_SET_MERGE_ON_WAVEFORM_MISMATCH _IOW('F', 0x37, int32_t)
#define MXCFB_SET_PAUSE _IOW('F', 0x33, __u32)
#define MXCFB_GET_PAUSE _IOW('F', 0x34, __u32)
#define MXCFB_SET_RESUME _IOW('F', 0x35, __u32)

/* Touch/PW1 */
#define MXCFB_CLEAR_UPDATE_QUEUE _IOW('F', 0x36, __u32)
/* PW2 */
#define MXCFB_GET_WORK_BUFFER _IOWR('F', 0x36, unsigned long)

/* IOCTLs for E-ink panel updates, kindle firmware version >= 5.1 */
#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)
#define MXCFB_WAIT_FOR_UPDATE_SUBMISSION _IOW('F', 0x37, __u32)

/* FW >= 5.3 */
#define MXCFB_GET_TEMPERATURE _IOR('F', 0x38, int32_t)

/* PW2 */
#define MXCFB_GET_WAVEFORM_TYPE _IOR('F', 0x39, __u32)

/* Deprecated IOCTL for E-ink panel updates, kindle firmware version == 5.0 */
#define MXCFB_SEND_UPDATE_50X _IOW('F', 0x2E, struct mxcfb_update_data_50x)

#ifdef __KERNEL__

/* PW2 */
#define EHWFAULT 901

extern struct fb_videomode mxcfb_modedb[];
extern int mxcfb_modedb_sz;

/* PW2 */
enum panel_modes {
PANEL_MODE_E60_CELESTE = 0,
PANEL_MODE_EN060OC1_3CE_225,
PANEL_MODE_ED060TC1_3CE,
PANEL_MODE_COUNT,
};

/* PW2 */
enum {
MXC_DISP_SPEC_DEV = 0,
MXC_DISP_DDC_DEV = 1,
};

enum {
MXCFB_REFRESH_OFF,
MXCFB_REFRESH_AUTO,
Expand All @@ -197,7 +298,11 @@ enum {

int mxcfb_set_refresh_mode(struct fb_info *fbi, int mode,
struct mxcfb_rect *update_region);

int mxc_elcdif_frame_addr_setup(dma_addr_t phys);

/* PW2 */
void mxcfb_elcdif_register_mode(const struct fb_videomode *modedb,
int num_modes, int dev_mode);

#endif /* __KERNEL__ */
#endif
7 changes: 5 additions & 2 deletions ffi-cdecl/mxcfb_kindle_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ typedef unsigned int uint;

cdecl_struct(mxcfb_rect)
cdecl_struct(mxcfb_alt_buffer_data)
cdecl_struct(mxcfb_alt_buffer_data_kobo)
cdecl_struct(mxcfb_update_data)
cdecl_struct(mxcfb_update_data_kobo)

cdecl_const(MXCFB_SEND_UPDATE)

/* Needed for REAGL on PW2? */
cdecl_struct(mxcfb_update_marker_data)
cdecl_const(MXCFB_WAIT_FOR_UPDATE_COMPLETE)
cdecl_const(MXCFB_WAIT_FOR_UPDATE_SUBMISSION)

2 changes: 0 additions & 2 deletions ffi-cdecl/mxcfb_kobo_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ typedef unsigned int uint;

cdecl_struct(mxcfb_rect)
cdecl_struct(mxcfb_alt_buffer_data)
cdecl_struct(mxcfb_alt_buffer_data_kobo)
cdecl_struct(mxcfb_update_data)
cdecl_struct(mxcfb_update_data_kobo)

cdecl_const(MXCFB_SEND_UPDATE)

18 changes: 11 additions & 7 deletions ffi/framebuffer_linux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ local function mxc_update(fb, refarea, refreshtype, waveform_mode, x, y, w, h)
refarea[0].update_region.width = w or fb.vinfo.xres
refarea[0].update_region.height = h or fb.vinfo.yres
refarea[0].update_marker = 1
refarea[0].temp = 0x1000
-- TODO make the flag configurable from UI,
-- this flag invert all the pixels on display 09.01 2013 (houqp)
-- e.g., the EPDC_FLAG_ENABLE_INVERSION flag inverts all the pixels on display 09.01 2013 (houqp)
refarea[0].flags = 0
-- NOTE: related to EPDC_FLAG_USE_ALT_BUFFER?
refarea[0].alt_buffer_data.phys_addr = 0
refarea[0].alt_buffer_data.width = 0
refarea[0].alt_buffer_data.height = 0
Expand All @@ -49,17 +49,21 @@ end

local function k51_update(fb, refreshtype, waveform_mode, x, y, w, h)
local refarea = ffi.new("struct mxcfb_update_data[1]")
-- only for Amazon's driver:
-- only for Amazon's driver (NOTE: related to debugPaint prefbw & prefgray?):
refarea[0].hist_bw_waveform_mode = 0
refarea[0].hist_gray_waveform_mode = 0
-- TEMP_USE_PAPYRUS on Touch/PW1, TEMP_USE_AUTO on PW2
refarea[0].temp = 0x1001

return mxc_update(fb, refarea, refreshtype, waveform_mode, x, y, w, h)
end

local function kobo_update(fb, refreshtype, waveform_mode, x, y, w, h)
local refarea = ffi.new("struct mxcfb_update_data[1]")
-- only for Kobo driver:
-- only for Kobo's driver:
refarea[0].alt_buffer_data.virt_addr = nil
-- TEMP_USE_AMBIENT
refarea[0].temp = 0x1000

return mxc_update(fb, refarea, refreshtype, waveform_mode, x, y, w, h)
end
Expand Down Expand Up @@ -176,7 +180,7 @@ function framebuffer_mt:setOrientation(mode)
| |
+--------------+
0
--]]
--]]
if mode == 1 then
mode = 2
elseif mode == 2 then
Expand All @@ -187,8 +191,8 @@ function framebuffer_mt:setOrientation(mode)
end

function framebuffer_mt.__index:refresh(refreshtype, waveform_mode, x, y, w, h)
w, x = BB.checkBounds(w or self.bb:getWidth(), x or 0, 0, self.bb:getWidth(), 0xFFFF)
h, y = BB.checkBounds(h or self.bb:getHeight(), y or 0, 0, self.bb:getHeight(), 0xFFFF)
w, x = BB.checkBounds(w or self.bb:getWidth(), x or 0, 0, self.bb:getWidth(), 0xFFFF)
h, y = BB.checkBounds(h or self.bb:getHeight(), y or 0, 0, self.bb:getHeight(), 0xFFFF)
x, y, w, h = self.bb:getPhysicalRect(x, y, w, h)
self:einkUpdateFunc(refreshtype, waveform_mode, x, y, w, h)
end
Expand Down
8 changes: 6 additions & 2 deletions ffi/mxcfb_kindle_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct mxcfb_alt_buffer_data {
unsigned int height;
struct mxcfb_rect alt_update_region;
};
struct mxcfb_alt_buffer_data_kobo;
struct mxcfb_update_data {
struct mxcfb_rect update_region;
unsigned int waveform_mode;
Expand All @@ -24,6 +23,11 @@ struct mxcfb_update_data {
unsigned int flags;
struct mxcfb_alt_buffer_data alt_buffer_data;
};
struct mxcfb_update_data_kobo;
static const int MXCFB_SEND_UPDATE = 1078478382;
struct mxcfb_update_marker_data {
unsigned int update_marker;
unsigned int collision_test;
};
static const int MXCFB_WAIT_FOR_UPDATE_COMPLETE = -1073199569;
static const int MXCFB_WAIT_FOR_UPDATE_SUBMISSION = 1074021943;
]]
4 changes: 1 addition & 3 deletions ffi/mxcfb_kobo_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct mxcfb_alt_buffer_data {
unsigned int height;
struct mxcfb_rect alt_update_region;
};
struct mxcfb_alt_buffer_data_kobo;
struct mxcfb_update_data {
struct mxcfb_rect update_region;
unsigned int waveform_mode;
Expand All @@ -23,6 +22,5 @@ struct mxcfb_update_data {
unsigned int flags;
struct mxcfb_alt_buffer_data alt_buffer_data;
};
struct mxcfb_update_data_kobo;
static const int MXCFB_SEND_UPDATE = 0x4044462e;
static const int MXCFB_SEND_UPDATE = 1078216238;
]]

0 comments on commit 2ba492e

Please sign in to comment.