1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-omap1/board-sx1.c
5 * Modified from board-generic.c
7 * Support for the Siemens SX1 mobile phone.
9 * Original version : Vladimir Ananiev (Vovan888-at-gmail com)
11 * Maintainters : Vladimir Ananiev (aka Vovan888), Sergge
14 #include <linux/gpio/machine.h>
15 #include <linux/gpio/consumer.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/input.h>
19 #include <linux/platform_device.h>
20 #include <linux/notifier.h>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/mtd/physmap.h>
24 #include <linux/types.h>
25 #include <linux/i2c.h>
26 #include <linux/errno.h>
27 #include <linux/export.h>
28 #include <linux/omapfb.h>
29 #include <linux/platform_data/keypad-omap.h>
30 #include <linux/omap-dma.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/map.h>
39 #include "board-sx1.h"
44 /* Write to I2C device */
45 int sx1_i2c_write_byte(u8 devaddr
, u8 regoffset
, u8 value
)
47 struct i2c_adapter
*adap
;
49 struct i2c_msg msg
[1];
50 unsigned char data
[2];
52 adap
= i2c_get_adapter(0);
55 msg
->addr
= devaddr
; /* I2C address of chip */
59 data
[0] = regoffset
; /* register num */
60 data
[1] = value
; /* register data */
61 err
= i2c_transfer(adap
, msg
, 1);
62 i2c_put_adapter(adap
);
68 /* Read from I2C device */
69 int sx1_i2c_read_byte(u8 devaddr
, u8 regoffset
, u8
*value
)
71 struct i2c_adapter
*adap
;
73 struct i2c_msg msg
[1];
74 unsigned char data
[2];
76 adap
= i2c_get_adapter(0);
80 msg
->addr
= devaddr
; /* I2C address of chip */
84 data
[0] = regoffset
; /* register num */
85 err
= i2c_transfer(adap
, msg
, 1);
87 msg
->addr
= devaddr
; /* I2C address */
88 msg
->flags
= I2C_M_RD
;
91 err
= i2c_transfer(adap
, msg
, 1);
93 i2c_put_adapter(adap
);
99 /* set keyboard backlight intensity */
100 int sx1_setkeylight(u8 keylight
)
102 if (keylight
> SOFIA_MAX_LIGHT_VAL
)
103 keylight
= SOFIA_MAX_LIGHT_VAL
;
104 return sx1_i2c_write_byte(SOFIA_I2C_ADDR
, SOFIA_KEYLIGHT_REG
, keylight
);
106 /* get current keylight intensity */
107 int sx1_getkeylight(u8
* keylight
)
109 return sx1_i2c_read_byte(SOFIA_I2C_ADDR
, SOFIA_KEYLIGHT_REG
, keylight
);
111 /* set LCD backlight intensity */
112 int sx1_setbacklight(u8 backlight
)
114 if (backlight
> SOFIA_MAX_LIGHT_VAL
)
115 backlight
= SOFIA_MAX_LIGHT_VAL
;
116 return sx1_i2c_write_byte(SOFIA_I2C_ADDR
, SOFIA_BACKLIGHT_REG
,
119 /* get current LCD backlight intensity */
120 int sx1_getbacklight (u8
* backlight
)
122 return sx1_i2c_read_byte(SOFIA_I2C_ADDR
, SOFIA_BACKLIGHT_REG
,
125 /* set LCD backlight power on/off */
126 int sx1_setmmipower(u8 onoff
)
130 err
= sx1_i2c_read_byte(SOFIA_I2C_ADDR
, SOFIA_POWER1_REG
, &dat
);
134 dat
|= SOFIA_MMILIGHT_POWER
;
136 dat
&= ~SOFIA_MMILIGHT_POWER
;
137 return sx1_i2c_write_byte(SOFIA_I2C_ADDR
, SOFIA_POWER1_REG
, dat
);
140 /* set USB power on/off */
141 int sx1_setusbpower(u8 onoff
)
145 err
= sx1_i2c_read_byte(SOFIA_I2C_ADDR
, SOFIA_POWER1_REG
, &dat
);
149 dat
|= SOFIA_USB_POWER
;
151 dat
&= ~SOFIA_USB_POWER
;
152 return sx1_i2c_write_byte(SOFIA_I2C_ADDR
, SOFIA_POWER1_REG
, dat
);
155 EXPORT_SYMBOL(sx1_setkeylight
);
156 EXPORT_SYMBOL(sx1_getkeylight
);
157 EXPORT_SYMBOL(sx1_setbacklight
);
158 EXPORT_SYMBOL(sx1_getbacklight
);
159 EXPORT_SYMBOL(sx1_setmmipower
);
160 EXPORT_SYMBOL(sx1_setusbpower
);
162 /*----------- Keypad -------------------------*/
164 static const unsigned int sx1_keymap
[] = {
165 KEY(3, 5, GROUP_0
| 117), /* camera Qt::Key_F17 */
166 KEY(4, 0, GROUP_0
| 114), /* voice memo Qt::Key_F14 */
167 KEY(4, 1, GROUP_2
| 114), /* voice memo */
168 KEY(4, 2, GROUP_3
| 114), /* voice memo */
169 KEY(0, 0, GROUP_1
| KEY_F12
), /* red button Qt::Key_Hangup */
170 KEY(3, 4, GROUP_1
| KEY_LEFT
),
171 KEY(3, 2, GROUP_1
| KEY_DOWN
),
172 KEY(3, 1, GROUP_1
| KEY_RIGHT
),
173 KEY(3, 0, GROUP_1
| KEY_UP
),
174 KEY(3, 3, GROUP_1
| KEY_POWER
), /* joystick press or Qt::Key_Select */
175 KEY(0, 5, GROUP_1
| KEY_1
),
176 KEY(0, 4, GROUP_1
| KEY_2
),
177 KEY(0, 3, GROUP_1
| KEY_3
),
178 KEY(4, 3, GROUP_1
| KEY_4
),
179 KEY(4, 4, GROUP_1
| KEY_5
),
180 KEY(4, 5, GROUP_1
| KEY_KPASTERISK
),/* "*" */
181 KEY(1, 4, GROUP_1
| KEY_6
),
182 KEY(1, 5, GROUP_1
| KEY_7
),
183 KEY(1, 3, GROUP_1
| KEY_8
),
184 KEY(2, 3, GROUP_1
| KEY_9
),
185 KEY(2, 5, GROUP_1
| KEY_0
),
186 KEY(2, 4, GROUP_1
| 113), /* # F13 Toggle input method Qt::Key_F13 */
187 KEY(1, 0, GROUP_1
| KEY_F11
), /* green button Qt::Key_Call */
188 KEY(2, 1, GROUP_1
| KEY_YEN
), /* left soft Qt::Key_Context1 */
189 KEY(2, 2, GROUP_1
| KEY_F8
), /* right soft Qt::Key_Back */
190 KEY(1, 2, GROUP_1
| KEY_LEFTSHIFT
), /* shift */
191 KEY(1, 1, GROUP_1
| KEY_BACKSPACE
), /* C (clear) */
192 KEY(2, 0, GROUP_1
| KEY_F7
), /* menu Qt::Key_Menu */
195 static struct resource sx1_kp_resources
[] = {
197 .start
= INT_KEYBOARD
,
199 .flags
= IORESOURCE_IRQ
,
203 static const struct matrix_keymap_data sx1_keymap_data
= {
204 .keymap
= sx1_keymap
,
205 .keymap_size
= ARRAY_SIZE(sx1_keymap
),
208 static struct omap_kp_platform_data sx1_kp_data
= {
211 .keymap_data
= &sx1_keymap_data
,
215 static struct platform_device sx1_kp_device
= {
216 .name
= "omap-keypad",
219 .platform_data
= &sx1_kp_data
,
221 .num_resources
= ARRAY_SIZE(sx1_kp_resources
),
222 .resource
= sx1_kp_resources
,
225 /*----------- MTD -------------------------*/
227 static struct mtd_partition sx1_partitions
[] = {
228 /* bootloader (U-Boot, etc) in first sector */
230 .name
= "bootloader",
231 .offset
= 0x01800000,
233 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
235 /* bootloader params in the next sector */
238 .offset
= MTDPART_OFS_APPEND
,
245 .offset
= MTDPART_OFS_APPEND
,
246 .size
= SZ_2M
- 2 * SZ_128K
,
251 .name
= "filesystem",
252 .offset
= MTDPART_OFS_APPEND
,
253 .size
= MTDPART_SIZ_FULL
,
258 static struct physmap_flash_data sx1_flash_data
= {
260 .set_vpp
= omap1_set_vpp
,
261 .parts
= sx1_partitions
,
262 .nr_parts
= ARRAY_SIZE(sx1_partitions
),
265 /* MTD Intel 4000 flash - new flashes */
266 static struct resource sx1_new_flash_resource
= {
267 .start
= OMAP_CS0_PHYS
,
268 .end
= OMAP_CS0_PHYS
+ SZ_32M
- 1,
269 .flags
= IORESOURCE_MEM
,
272 static struct platform_device sx1_flash_device
= {
273 .name
= "physmap-flash",
276 .platform_data
= &sx1_flash_data
,
279 .resource
= &sx1_new_flash_resource
,
282 /*----------- USB -------------------------*/
284 static struct omap_usb_config sx1_usb_config __initdata
= {
294 /*----------- LCD -------------------------*/
296 static const struct omap_lcd_config sx1_lcd_config __initconst
= {
297 .ctrl_name
= "internal",
300 /*-----------------------------------------*/
301 static struct platform_device
*sx1_devices
[] __initdata
= {
306 /*-----------------------------------------*/
308 static struct gpiod_lookup_table sx1_gpio_table
= {
311 GPIO_LOOKUP("gpio-0-15", 1, "irda_off",
313 GPIO_LOOKUP("gpio-0-15", 11, "switch",
315 GPIO_LOOKUP("gpio-0-15", 15, "usb_on",
321 static void __init
omap_sx1_init(void)
325 /* mux pins for uarts */
326 omap_cfg_reg(UART1_TX
);
327 omap_cfg_reg(UART1_RTS
);
328 omap_cfg_reg(UART2_TX
);
329 omap_cfg_reg(UART2_RTS
);
330 omap_cfg_reg(UART3_TX
);
331 omap_cfg_reg(UART3_RX
);
333 platform_add_devices(sx1_devices
, ARRAY_SIZE(sx1_devices
));
336 omap_register_i2c_bus(1, 100, NULL
, 0);
337 omap1_usb_init(&sx1_usb_config
);
339 gpiod_add_lookup_table(&sx1_gpio_table
);
341 /* turn on USB power */
342 /* sx1_setusbpower(1); can't do it here because i2c is not ready */
343 d
= gpiod_get(NULL
, "irda_off", GPIOD_OUT_HIGH
);
345 pr_err("Unable to get IRDA OFF GPIO descriptor\n");
348 d
= gpiod_get(NULL
, "switch", GPIOD_OUT_LOW
);
350 pr_err("Unable to get SWITCH GPIO descriptor\n");
353 d
= gpiod_get(NULL
, "usb_on", GPIOD_OUT_LOW
);
355 pr_err("Unable to get USB ON GPIO descriptor\n");
359 omapfb_set_lcd_config(&sx1_lcd_config
);
362 MACHINE_START(SX1
, "OMAP310 based Siemens SX1")
363 .atag_offset
= 0x100,
364 .map_io
= omap1_map_io
,
365 .init_early
= omap1_init_early
,
366 .init_irq
= omap1_init_irq
,
367 .init_machine
= omap_sx1_init
,
368 .init_late
= omap1_init_late
,
369 .init_time
= omap1_timer_init
,
370 .restart
= omap1_restart
,