xref: /openbmc/linux/arch/arm/mach-omap1/board-sx1.c (revision 5bb578a0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/mach-omap1/board-sx1.c
4 *
5 * Modified from board-generic.c
6 *
7 * Support for the Siemens SX1 mobile phone.
8 *
9 * Original version : Vladimir Ananiev (Vovan888-at-gmail com)
10 *
11 * Maintainters : Vladimir Ananiev (aka Vovan888), Sergge
12 *		oslik.ru
13 */
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>
31 #include "tc.h"
32 
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/map.h>
36 
37 #include "flash.h"
38 #include "mux.h"
39 #include "board-sx1.h"
40 #include "hardware.h"
41 #include "usb.h"
42 #include "common.h"
43 
44 /* Write to I2C device */
sx1_i2c_write_byte(u8 devaddr,u8 regoffset,u8 value)45 int sx1_i2c_write_byte(u8 devaddr, u8 regoffset, u8 value)
46 {
47 	struct i2c_adapter *adap;
48 	int err;
49 	struct i2c_msg msg[1];
50 	unsigned char data[2];
51 
52 	adap = i2c_get_adapter(0);
53 	if (!adap)
54 		return -ENODEV;
55 	msg->addr = devaddr;	/* I2C address of chip */
56 	msg->flags = 0;
57 	msg->len = 2;
58 	msg->buf = data;
59 	data[0] = regoffset;	/* register num */
60 	data[1] = value;		/* register data */
61 	err = i2c_transfer(adap, msg, 1);
62 	i2c_put_adapter(adap);
63 	if (err >= 0)
64 		return 0;
65 	return err;
66 }
67 
68 /* Read from I2C device */
sx1_i2c_read_byte(u8 devaddr,u8 regoffset,u8 * value)69 int sx1_i2c_read_byte(u8 devaddr, u8 regoffset, u8 *value)
70 {
71 	struct i2c_adapter *adap;
72 	int err;
73 	struct i2c_msg msg[1];
74 	unsigned char data[2];
75 
76 	adap = i2c_get_adapter(0);
77 	if (!adap)
78 		return -ENODEV;
79 
80 	msg->addr = devaddr;	/* I2C address of chip */
81 	msg->flags = 0;
82 	msg->len = 1;
83 	msg->buf = data;
84 	data[0] = regoffset;	/* register num */
85 	err = i2c_transfer(adap, msg, 1);
86 
87 	msg->addr = devaddr;	/* I2C address */
88 	msg->flags = I2C_M_RD;
89 	msg->len = 1;
90 	msg->buf = data;
91 	err = i2c_transfer(adap, msg, 1);
92 	*value = data[0];
93 	i2c_put_adapter(adap);
94 
95 	if (err >= 0)
96 		return 0;
97 	return err;
98 }
99 /* set keyboard backlight intensity */
sx1_setkeylight(u8 keylight)100 int sx1_setkeylight(u8 keylight)
101 {
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);
105 }
106 /* get current keylight intensity */
sx1_getkeylight(u8 * keylight)107 int sx1_getkeylight(u8 * keylight)
108 {
109 	return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_KEYLIGHT_REG, keylight);
110 }
111 /* set LCD backlight intensity */
sx1_setbacklight(u8 backlight)112 int sx1_setbacklight(u8 backlight)
113 {
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,
117 				  backlight);
118 }
119 /* get current LCD backlight intensity */
sx1_getbacklight(u8 * backlight)120 int sx1_getbacklight (u8 * backlight)
121 {
122 	return sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_BACKLIGHT_REG,
123 				 backlight);
124 }
125 /* set LCD backlight power on/off */
sx1_setmmipower(u8 onoff)126 int sx1_setmmipower(u8 onoff)
127 {
128 	int err;
129 	u8 dat = 0;
130 	err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
131 	if (err < 0)
132 		return err;
133 	if (onoff)
134 		dat |= SOFIA_MMILIGHT_POWER;
135 	else
136 		dat &= ~SOFIA_MMILIGHT_POWER;
137 	return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
138 }
139 
140 /* set USB power on/off */
sx1_setusbpower(u8 onoff)141 int sx1_setusbpower(u8 onoff)
142 {
143 	int err;
144 	u8 dat = 0;
145 	err = sx1_i2c_read_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, &dat);
146 	if (err < 0)
147 		return err;
148 	if (onoff)
149 		dat |= SOFIA_USB_POWER;
150 	else
151 		dat &= ~SOFIA_USB_POWER;
152 	return sx1_i2c_write_byte(SOFIA_I2C_ADDR, SOFIA_POWER1_REG, dat);
153 }
154 
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);
161 
162 /*----------- Keypad -------------------------*/
163 
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 */
193 };
194 
195 static struct resource sx1_kp_resources[] = {
196 	[0] = {
197 		.start	= INT_KEYBOARD,
198 		.end	= INT_KEYBOARD,
199 		.flags	= IORESOURCE_IRQ,
200 	},
201 };
202 
203 static const struct matrix_keymap_data sx1_keymap_data = {
204 	.keymap		= sx1_keymap,
205 	.keymap_size	= ARRAY_SIZE(sx1_keymap),
206 };
207 
208 static struct omap_kp_platform_data sx1_kp_data = {
209 	.rows		= 6,
210 	.cols		= 6,
211 	.keymap_data	= &sx1_keymap_data,
212 	.delay	= 80,
213 };
214 
215 static struct platform_device sx1_kp_device = {
216 	.name		= "omap-keypad",
217 	.id		= -1,
218 	.dev		= {
219 		.platform_data = &sx1_kp_data,
220 	},
221 	.num_resources	= ARRAY_SIZE(sx1_kp_resources),
222 	.resource	= sx1_kp_resources,
223 };
224 
225 /*----------- MTD -------------------------*/
226 
227 static struct mtd_partition sx1_partitions[] = {
228 	/* bootloader (U-Boot, etc) in first sector */
229 	{
230 		.name		= "bootloader",
231 		.offset		= 0x01800000,
232 		.size		= SZ_128K,
233 		.mask_flags	= MTD_WRITEABLE, /* force read-only */
234 	},
235 	/* bootloader params in the next sector */
236 	{
237 		.name		= "params",
238 		.offset		= MTDPART_OFS_APPEND,
239 		.size		= SZ_128K,
240 		.mask_flags	= 0,
241 	},
242 	/* kernel */
243 	{
244 		.name		= "kernel",
245 		.offset		= MTDPART_OFS_APPEND,
246 		.size		= SZ_2M - 2 * SZ_128K,
247 		.mask_flags	= 0
248 	},
249 	/* file system */
250 	{
251 		.name		= "filesystem",
252 		.offset		= MTDPART_OFS_APPEND,
253 		.size		= MTDPART_SIZ_FULL,
254 		.mask_flags	= 0
255 	}
256 };
257 
258 static struct physmap_flash_data sx1_flash_data = {
259 	.width		= 2,
260 	.set_vpp	= omap1_set_vpp,
261 	.parts		= sx1_partitions,
262 	.nr_parts	= ARRAY_SIZE(sx1_partitions),
263 };
264 
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,
270 };
271 
272 static struct platform_device sx1_flash_device = {
273 	.name		= "physmap-flash",
274 	.id		= 0,
275 	.dev		= {
276 		.platform_data	= &sx1_flash_data,
277 	},
278 	.num_resources	= 1,
279 	.resource	= &sx1_new_flash_resource,
280 };
281 
282 /*----------- USB -------------------------*/
283 
284 static struct omap_usb_config sx1_usb_config __initdata = {
285 	.otg		= 0,
286 	.register_dev	= 1,
287 	.register_host	= 0,
288 	.hmc_mode	= 0,
289 	.pins[0]	= 2,
290 	.pins[1]	= 0,
291 	.pins[2]	= 0,
292 };
293 
294 /*----------- LCD -------------------------*/
295 
296 static const struct omap_lcd_config sx1_lcd_config __initconst = {
297 	.ctrl_name	= "internal",
298 };
299 
300 /*-----------------------------------------*/
301 static struct platform_device *sx1_devices[] __initdata = {
302 	&sx1_flash_device,
303 	&sx1_kp_device,
304 };
305 
306 /*-----------------------------------------*/
307 
308 static struct gpiod_lookup_table sx1_gpio_table = {
309 	.dev_id = NULL,
310 	.table = {
311 		GPIO_LOOKUP("gpio-0-15", 1, "irda_off",
312 			    GPIO_ACTIVE_HIGH),
313 		GPIO_LOOKUP("gpio-0-15", 11, "switch",
314 			    GPIO_ACTIVE_HIGH),
315 		GPIO_LOOKUP("gpio-0-15", 15, "usb_on",
316 			    GPIO_ACTIVE_HIGH),
317 		{ }
318 	},
319 };
320 
omap_sx1_init(void)321 static void __init omap_sx1_init(void)
322 {
323 	struct gpio_desc *d;
324 
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);
332 
333 	platform_add_devices(sx1_devices, ARRAY_SIZE(sx1_devices));
334 
335 	omap_serial_init();
336 	omap_register_i2c_bus(1, 100, NULL, 0);
337 	omap1_usb_init(&sx1_usb_config);
338 	sx1_mmc_init();
339 	gpiod_add_lookup_table(&sx1_gpio_table);
340 
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);
344 	if (IS_ERR(d))
345 		pr_err("Unable to get IRDA OFF GPIO descriptor\n");
346 	else
347 		gpiod_put(d);
348 	d = gpiod_get(NULL, "switch", GPIOD_OUT_LOW);
349 	if (IS_ERR(d))
350 		pr_err("Unable to get SWITCH GPIO descriptor\n");
351 	else
352 		gpiod_put(d);
353 	d = gpiod_get(NULL, "usb_on", GPIOD_OUT_LOW);
354 	if (IS_ERR(d))
355 		pr_err("Unable to get USB ON GPIO descriptor\n");
356 	else
357 		gpiod_put(d);
358 
359 	omapfb_set_lcd_config(&sx1_lcd_config);
360 }
361 
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,
371 MACHINE_END
372