Skip to content

Commit d621bbd

Browse files
Matias NNiLuJe
Matias N
authored andcommitted
Support for Sony PRS-T* (koreader#724)
* Support for Sony PRS-T* running PRSTUX
1 parent f436894 commit d621bbd

File tree

11 files changed

+350
-5
lines changed

11 files changed

+350
-5
lines changed

.ci/build_script.sh

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ elif [ "$TARGET" = pocketbook ]; then
2525
-v "${HOME}/.ccache:${DOCKER_HOME}/.ccache" \
2626
-v "$(pwd):${DOCKER_HOME}/base" "${DOCKER_IMG}" \
2727
/bin/bash -c "source /home/ko/.bashrc && cd /home/ko/base && sudo chown -R ko:ko . && make pocketbook-toolchain && make VERBOSE=1 TARGET=pocketbook all"
28+
elif [ "$TARGET" = sony_prstux ]; then
29+
sudo chmod -R 777 "${HOME}/.ccache"
30+
docker run -t \
31+
-v "${HOME}/.ccache:${DOCKER_HOME}/.ccache" \
32+
-v "$(pwd):${DOCKER_HOME}/base" "${DOCKER_IMG}" \
33+
/bin/bash -c "source /home/ko/.bashrc && cd /home/ko/base && sudo chown -R ko:ko . && make VERBOSE=1 TARGET=sony_prstux all"
2834
else
2935
make all
3036
fi

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ env:
2121
- TARGET=kindle DOCKER_IMG=frenzie/kokindle:0.0.5
2222
- TARGET=kobo DOCKER_IMG=frenzie/kokobo:0.0.5
2323
- TARGET=pocketbook DOCKER_IMG=houqp/kopb:0.0.1
24+
- TARGET=sony_prstux DOCKER_IMG=phreakuencies/prstux-dev:16.04
2425
# ANDROID_ARCH=x86 is currently broken on these older NDKs (at least on Travis), so no point in testing it
2526
- TARGET=android NDKREV=r11c
2627
- TARGET=android NDKREV=r12b

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ libs: \
8888
$(OUTPUT_DIR)/libs/libkoreader-input.so: input/*.c input/*.h $(if $(KINDLE),$(POPEN_NOSHELL_LIB),)
8989
@echo "Building koreader input module..."
9090
$(CC) $(DYNLIB_CFLAGS) -I$(POPEN_NOSHELL_DIR) -I./input \
91-
$(if $(KOBO),-DKOBO,) $(if $(KINDLE),-DKINDLE,) $(if $(POCKETBOOK),-DPOCKETBOOK,) \
91+
$(if $(KOBO),-DKOBO,) $(if $(KINDLE),-DKINDLE,) $(if $(POCKETBOOK),-DPOCKETBOOK,) $(if $(SONY_PRSTUX),-DSONY_PRSTUX,)\
9292
-o $@ \
9393
input/input.c \
9494
$(if $(KINDLE),$(POPEN_NOSHELL_LIB),) \

Makefile.defs

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ else ifeq ($(TARGET), pocketbook)
9292
export POCKETBOOK=1
9393
export PATH:=$(POCKETBOOK_TOOLCHAIN)/bin:$(PATH)
9494
export SYSROOT=$(POCKETBOOK_TOOLCHAIN)/arm-obreey-linux-gnueabi/sysroot
95+
else ifeq ($(TARGET), sony_prstux)
96+
CHOST?=arm-linux-gnueabihf
97+
export SONY_PRSTUX=1
98+
export USE_LJ_WPACLIENT=1
9599
else ifndef TARGET
96100
# if TARGET is not defined we will build an emulator on current machine
97101
export EMULATE_READER=1
@@ -279,6 +283,9 @@ else ifeq ($(TARGET), android)
279283
ARM_ARCH+=-mfloat-abi=softfp
280284
export ac_cv_type_in_port_t=yes
281285
endif
286+
else ifeq ($(TARGET), sony_prstux)
287+
ARM_ARCH:=$(ARMV7_A8_ARCH)
288+
ARM_ARCH+=-mfloat-abi=hard
282289
else ifeq ($(TARGET), arm-generic)
283290
# Defaults to generic crap
284291
ARM_ARCH:=$(ARMV6_GENERIC_ARCH)

ffi-cdecl/include/mxcfb-sony.h

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*
2+
* Copyright 2004-2011 Freescale Semiconductor, Inc. All Rights Reserved.
3+
*/
4+
5+
/*
6+
* The code contained herein is licensed under the GNU Lesser General
7+
* Public License. You may obtain a copy of the GNU Lesser General
8+
* Public License Version 2.1 or later at the following locations:
9+
*
10+
* http://www.opensource.org/licenses/lgpl-license.html
11+
* http://www.gnu.org/copyleft/lgpl.html
12+
*/
13+
14+
/*
15+
* @file arch-mxc/ mxcfb.h
16+
*
17+
* @brief Global header file for the MXC Frame buffer
18+
*
19+
* @ingroup Framebuffer
20+
*/
21+
#ifndef __ASM_ARCH_MXCFB_H__
22+
#define __ASM_ARCH_MXCFB_H__
23+
24+
#include <linux/fb.h>
25+
26+
#define FB_SYNC_OE_LOW_ACT 0x80000000
27+
#define FB_SYNC_CLK_LAT_FALL 0x40000000
28+
#define FB_SYNC_DATA_INVERT 0x20000000
29+
#define FB_SYNC_CLK_IDLE_EN 0x10000000
30+
#define FB_SYNC_SHARP_MODE 0x08000000
31+
#define FB_SYNC_SWAP_RGB 0x04000000
32+
33+
struct mxcfb_gbl_alpha {
34+
int enable;
35+
int alpha;
36+
};
37+
38+
struct mxcfb_loc_alpha {
39+
int enable;
40+
int alpha_in_pixel;
41+
unsigned long alpha_phy_addr0;
42+
unsigned long alpha_phy_addr1;
43+
};
44+
45+
struct mxcfb_color_key {
46+
int enable;
47+
__u32 color_key;
48+
};
49+
50+
struct mxcfb_pos {
51+
__u16 x;
52+
__u16 y;
53+
};
54+
55+
struct mxcfb_gamma {
56+
int enable;
57+
int constk[16];
58+
int slopek[16];
59+
};
60+
61+
struct mxcfb_rect {
62+
__u32 top;
63+
__u32 left;
64+
__u32 width;
65+
__u32 height;
66+
};
67+
68+
#define GRAYSCALE_8BIT 0x1
69+
#define GRAYSCALE_8BIT_INVERTED 0x2
70+
71+
#define AUTO_UPDATE_MODE_REGION_MODE 0
72+
#define AUTO_UPDATE_MODE_AUTOMATIC_MODE 1
73+
74+
#define UPDATE_SCHEME_SNAPSHOT 0
75+
#define UPDATE_SCHEME_QUEUE 1
76+
#define UPDATE_SCHEME_QUEUE_AND_MERGE 2
77+
78+
#define UPDATE_MODE_PARTIAL 0x0
79+
#define UPDATE_MODE_FULL 0x1
80+
81+
#define WAVEFORM_MODE_AUTO 257
82+
83+
#define TEMP_USE_AMBIENT 0x1000
84+
#define TEMP_USE_AUTO 0x1001
85+
86+
#define EPDC_FLAG_ENABLE_INVERSION 0x01
87+
#define EPDC_FLAG_FORCE_MONOCHROME 0x02
88+
#define EPDC_FLAG_USE_ALT_BUFFER 0x100
89+
90+
#define EPDC_FLAG_SP1_1 0x10000
91+
#define EPDC_FLAG_SP1_2 0x20000
92+
93+
#define FB_POWERDOWN_DISABLE -1
94+
95+
/* 2011/03/30 FY11 : Defined max marker value for user process. */
96+
/* (The value larger than this is for driver.)*/
97+
#define UPDATE_MARKER_MAX 0x80000000
98+
99+
struct mxcfb_alt_buffer_data {
100+
void *virt_addr;
101+
__u32 phys_addr;
102+
__u32 width; /* width of entire buffer */
103+
__u32 height; /* height of entire buffer */
104+
struct mxcfb_rect alt_update_region; /* region within buffer to update */
105+
};
106+
107+
struct mxcfb_update_data {
108+
struct mxcfb_rect update_region;
109+
__u32 waveform_mode;
110+
__u32 update_mode;
111+
__u32 update_marker;
112+
int temp;
113+
uint flags;
114+
struct mxcfb_alt_buffer_data alt_buffer_data;
115+
};
116+
117+
/*
118+
* Structure used to define waveform modes for driver
119+
* Needed for driver to perform auto-waveform selection
120+
*/
121+
struct mxcfb_waveform_modes {
122+
int mode_init;
123+
int mode_du;
124+
int mode_gc4;
125+
int mode_gc8;
126+
int mode_gc16;
127+
int mode_gc32;
128+
int mode_a2; /* 2011/03/05 FY11 : Supported A2 mode limitations. */
129+
};
130+
131+
132+
/* 2011/2/24 FY11 : Added waveform version struct. */
133+
#define WF_VER_LEN 10
134+
struct mxcfb_waveform_version {
135+
__u8 version[WF_VER_LEN];
136+
};
137+
138+
139+
/* 2011/03/08 FY11 : Supported to write waveform. */
140+
struct mxcfb_waveform_data
141+
{
142+
__u32 uiSize;
143+
__u8 *pcData;
144+
};
145+
146+
147+
#define MXCFB_WAIT_FOR_VSYNC _IOW('F', 0x20, u_int32_t)
148+
#define MXCFB_SET_GBL_ALPHA _IOW('F', 0x21, struct mxcfb_gbl_alpha)
149+
#define MXCFB_SET_CLR_KEY _IOW('F', 0x22, struct mxcfb_color_key)
150+
#define MXCFB_SET_OVERLAY_POS _IOWR('F', 0x24, struct mxcfb_pos)
151+
#define MXCFB_GET_FB_IPU_CHAN _IOR('F', 0x25, u_int32_t)
152+
#define MXCFB_SET_LOC_ALPHA _IOWR('F', 0x26, struct mxcfb_loc_alpha)
153+
#define MXCFB_SET_LOC_ALP_BUF _IOW('F', 0x27, unsigned long)
154+
#define MXCFB_SET_GAMMA _IOW('F', 0x28, struct mxcfb_gamma)
155+
#define MXCFB_GET_FB_IPU_DI _IOR('F', 0x29, u_int32_t)
156+
#define MXCFB_GET_DIFMT _IOR('F', 0x2A, u_int32_t)
157+
#define MXCFB_GET_FB_BLANK _IOR('F', 0x2B, u_int32_t)
158+
#define MXCFB_SET_DIFMT _IOW('F', 0x2C, u_int32_t)
159+
160+
/* IOCTLs for E-ink panel updates */
161+
#define MXCFB_SET_WAVEFORM_MODES _IOW('F', 0x2B, struct mxcfb_waveform_modes)
162+
#define MXCFB_SET_TEMPERATURE _IOW('F', 0x2C, int32_t)
163+
#define MXCFB_SET_AUTO_UPDATE_MODE _IOW('F', 0x2D, __u32)
164+
#define MXCFB_SEND_UPDATE _IOW('F', 0x2E, struct mxcfb_update_data)
165+
#define MXCFB_WAIT_FOR_UPDATE_COMPLETE _IOW('F', 0x2F, __u32)
166+
#define MXCFB_SET_PWRDOWN_DELAY _IOW('F', 0x30, int32_t)
167+
#define MXCFB_GET_PWRDOWN_DELAY _IOR('F', 0x31, int32_t)
168+
#define MXCFB_SET_UPDATE_SCHEME _IOW('F', 0x32, __u32)
169+
#define MXCFB_GET_PMIC_TEMPERATURE _IOR('F', 0x33, int32_t)
170+
#define MXCFB_SET_BORDER_MODE _IOR('F', 0x34, int32_t)
171+
#define MXCFB_SET_EPD_PWR0_CTRL _IOR('F', 0x35, int32_t)
172+
#define MXCFB_SET_EPD_PWR2_CTRL _IOR('F', 0x36, int32_t)
173+
174+
/* 2011/1/19 FY11 : Added commands to read/write VCOM. */
175+
#define MXCFB_SET_VCOM _IOW('F', 0x37, __u32)
176+
#define MXCFB_GET_VCOM _IOR('F', 0x38, __u32)
177+
178+
/* 2011/2/24 FY11 : Added commands to read waveform version. */
179+
#define MXCFB_GET_WF_VERSION _IOR('F', 0x39, struct mxcfb_waveform_version)
180+
/* 2011/03/08 FY11 : Supported to write waveform. */
181+
#define MXCFB_WRITE_WF _IOW('F', 0x3A, struct mxcfb_waveform_data)
182+
/* 2011/03/30 FY11 : Supported to write standby screen image. */
183+
#define MXCFB_WRITE_SSCREEN _IOW('F', 0x3B, __u8*)
184+
/* 2011/04/12 FY11 : Supported to write panel init flag. */
185+
#define MXCFB_SET_PANELINIT _IOW('F', 0x3C, __u8)
186+
187+
/* 2012/02/03 : Add pending function. */
188+
#define MXCFB_SET_PENDING _IOW('F', 0x3E, __u8)
189+
190+
#ifdef __KERNEL__
191+
192+
extern struct fb_videomode mxcfb_modedb[];
193+
extern int mxcfb_modedb_sz;
194+
195+
enum {
196+
MXCFB_REFRESH_OFF,
197+
MXCFB_REFRESH_AUTO,
198+
MXCFB_REFRESH_PARTIAL,
199+
};
200+
201+
int mxcfb_set_refresh_mode(struct fb_info *fbi, int mode,
202+
struct mxcfb_rect *update_region);
203+
204+
int mxc_elcdif_frame_addr_setup(dma_addr_t phys);
205+
206+
#endif /* __KERNEL__ */
207+
#endif

ffi-cdecl/mxcfb_sony_decl.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// standard Linux framebuffer headers
2+
#include <linux/fb.h>
3+
4+
#include <linux/ioctl.h>
5+
// specialized eink framebuffer headers
6+
#include "include/mxcfb-sony.h"
7+
8+
#include "ffi-cdecl.h"
9+
10+
cdecl_const(UPDATE_MODE_PARTIAL)
11+
cdecl_const(UPDATE_MODE_FULL)
12+
13+
cdecl_const(WAVEFORM_MODE_AUTO)
14+
cdecl_const(TEMP_USE_AMBIENT)
15+
16+
cdecl_const(EPDC_FLAG_ENABLE_INVERSION)
17+
cdecl_const(EPDC_FLAG_FORCE_MONOCHROME)
18+
cdecl_const(EPDC_FLAG_USE_ALT_BUFFER)
19+
cdecl_const(EPDC_FLAG_SP1_1)
20+
cdecl_const(EPDC_FLAG_SP1_2)
21+
22+
cdecl_struct(mxcfb_rect)
23+
cdecl_struct(mxcfb_alt_buffer_data)
24+
cdecl_struct(mxcfb_update_data)
25+
26+
cdecl_const(MXCFB_SEND_UPDATE)
27+
28+
cdecl_const(MXCFB_WAIT_FOR_UPDATE_COMPLETE)

ffi/framebuffer_mxcfb.lua

+23
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ local function pocketbook_mxc_wait_for_update_complete(fb, marker)
104104
return C.ioctl(fb.fd, C.MXCFB_WAIT_FOR_UPDATE_COMPLETE, ffi.new("uint32_t[1]", marker))
105105
end
106106

107+
-- Sony PRS MXCFB_WAIT_FOR_UPDATE_COMPLETE
108+
local function sony_prstux_mxc_wait_for_update_complete(fb, marker)
109+
-- Wait for the previous update to be completed
110+
return C.ioctl(fb.fd, C.MXCFB_WAIT_FOR_UPDATE_COMPLETE, ffi.new("uint32_t[1]", marker))
111+
end
112+
107113
-- Kindle's MXCFB_WAIT_FOR_UPDATE_COMPLETE == 0xc008462f
108114
local function kindle_carta_mxc_wait_for_update_complete(fb, marker, collision_test)
109115
-- Wait for the previous update to be completed
@@ -343,6 +349,12 @@ local function refresh_pocketbook(fb, refreshtype, waveform_mode, x, y, w, h)
343349
return mxc_update(fb, C.MXCFB_SEND_UPDATE, refarea, refreshtype, waveform_mode, x, y, w, h)
344350
end
345351

352+
local function refresh_sony_prstux(fb, refreshtype, waveform_mode, x, y, w, h)
353+
local refarea = ffi.new("struct mxcfb_update_data[1]")
354+
refarea[0].temp = C.TEMP_USE_AMBIENT
355+
return mxc_update(fb, C.MXCFB_SEND_UPDATE, refarea, refreshtype, waveform_mode, x, y, w, h)
356+
end
357+
346358
--[[ framebuffer API ]]--
347359

348360
function framebuffer:refreshPartialImp(x, y, w, h)
@@ -502,6 +514,17 @@ function framebuffer:init()
502514
self.waveform_flashui = self.waveform_ui
503515
self.waveform_full = C.WAVEFORM_MODE_GC16
504516
self.waveform_partial = C.WAVEFORM_MODE_GC16
517+
elseif self.device:isSonyPRSTUX() then
518+
require("ffi/mxcfb_sony_h")
519+
520+
self.mech_refresh = refresh_sony_prstux
521+
self.mech_wait_update_complete = sony_prstux_mxc_wait_for_update_complete
522+
523+
self.waveform_fast = C.WAVEFORM_MODE_A2
524+
self.waveform_ui = C.WAVEFORM_MODE_AUTO
525+
self.waveform_flashui = C.WAVEFORM_MODE_AUTO
526+
self.waveform_full = C.WAVEFORM_MODE_GC16
527+
self.waveform_partial = C.WAVEFORM_MODE_AUTO
505528
else
506529
error("unknown device type")
507530
end

ffi/mxcfb_sony_h.lua

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
local ffi = require("ffi")
2+
3+
ffi.cdef[[
4+
struct mxcfb_rect {
5+
unsigned int top;
6+
unsigned int left;
7+
unsigned int width;
8+
unsigned int height;
9+
};
10+
11+
struct mxcfb_alt_buffer_data {
12+
void* virt_addr;
13+
unsigned int phys_addr;
14+
unsigned int width;
15+
unsigned int height;
16+
struct mxcfb_rect alt_update_region;
17+
};
18+
19+
struct mxcfb_update_data {
20+
struct mxcfb_rect update_region;
21+
unsigned int waveform_mode;
22+
unsigned int update_mode;
23+
unsigned int update_marker;
24+
int temp;
25+
unsigned int flags;
26+
struct mxcfb_alt_buffer_data alt_buffer_data;
27+
};
28+
29+
static const int UPDATE_MODE_PARTIAL = 0;
30+
static const int UPDATE_MODE_FULL = 1;
31+
32+
static const int WAVEFORM_MODE_INIT = 0;
33+
static const int WAVEFORM_MODE_DU = 1;
34+
static const int WAVEFORM_MODE_GC16 = 2;
35+
static const int WAVEFORM_MODE_GC4 = 3;
36+
static const int WAVEFORM_MODE_A2 = 4;
37+
static const int WAVEFORM_MODE_AUTO = 257;
38+
static const int TEMP_USE_AMBIENT = 4096;
39+
static const int TEMP_USE_AUTO = 4097; // this does not exist, simply use a value different than above
40+
static const int EPDC_FLAG_ENABLE_INVERSION = 1;
41+
static const int EPDC_FLAG_FORCE_MONOCHROME = 2;
42+
static const int EPDC_FLAG_USE_ALT_BUFFER = 256;
43+
44+
static const int MXCFB_SEND_UPDATE = 1078216238;
45+
static const int MXCFB_WAIT_FOR_UPDATE_COMPLETE = 1074021935;
46+
]]

0 commit comments

Comments
 (0)