2 * arch/ubicom32/mach-ip7k/board-ip7500media.c
3 * Board file for IP7500 media board.
5 * Supports the following configuration
7 * P/N 8007-0510 rev 1.0 NOPHY
8 * P/N 8007-0511 rev 1.1 NOPHY
9 * DIP Switch SW2 configuration:
10 * POS 1: on = PCI enabled
11 * POS 2: off = TTYX => PF12
12 * POS 3: off = TTYY => PF15
15 * P/N 8007-0610 rev 1.0
17 * LCD Adapter Board: (optional)
18 * P/N 8007-0920 rev 2.0
19 * P/N 8007-0921 rev 2.1
21 * (C) Copyright 2009, Ubicom, Inc.
23 * This file is part of the Ubicom32 Linux Kernel Port.
25 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
26 * it and/or modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation, either version 2 of the
28 * License, or (at your option) any later version.
30 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
31 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
32 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
33 * the GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with the Ubicom32 Linux Kernel Port. If not,
37 * see <http://www.gnu.org/licenses/>.
39 * Ubicom32 implementation derived from (with many thanks):
44 #include <linux/device.h>
45 #include <linux/platform_device.h>
46 #include <linux/gpio.h>
48 #include <linux/input.h>
50 #include <linux/i2c.h>
51 #include <linux/i2c-gpio.h>
52 #include <linux/i2c/pca953x.h>
54 #include <asm/board.h>
55 #include <asm/machdep.h>
56 #include <asm/ubicom32input_i2c.h>
57 #include <asm/ubicom32bl.h>
58 #include <asm/ubicom32lcdpower.h>
59 #include <asm/vdc_tio.h>
61 #include <asm/ubicom32sd.h>
62 #include <asm/sd_tio.h>
63 #include <asm/devtree.h>
64 #include <asm/audio.h>
66 #include <asm/ring_tio.h>
68 /******************************************************************************
69 * SD/IO Port F (Slot 1) platform data
71 static struct resource ip7500media_portf_sd_resources
[] = {
77 * The init routine will query the devtree and fill this in
79 .flags
= IORESOURCE_IRQ
,
87 * The init routine will query the devtree and fill this in
89 .flags
= IORESOURCE_IRQ
,
93 * Memory Mapped Registers
97 * The init routine will query the devtree and fill this in
99 .flags
= IORESOURCE_MEM
,
103 static struct ubicom32sd_card ip7500media_portf_sd_cards
[] = {
105 .pin_wp
= IP7500MEDIA_IO16
,
107 .pin_pwr
= IP7500MEDIA_IO20
,
108 .pin_cd
= IP7500MEDIA_IO23
,
111 .pin_wp
= IP7500MEDIA_IO17
,
113 .pin_pwr
= IP7500MEDIA_IO21
,
114 .pin_cd
= IP7500MEDIA_IO24
,
118 static struct ubicom32sd_platform_data ip7500media_portf_sd_platform_data
= {
120 .cards
= ip7500media_portf_sd_cards
,
123 static struct platform_device ip7500media_portf_sd_device
= {
124 .name
= "ubicom32sd",
126 .resource
= ip7500media_portf_sd_resources
,
127 .num_resources
= ARRAY_SIZE(ip7500media_portf_sd_resources
),
129 .platform_data
= &ip7500media_portf_sd_platform_data
,
135 * ip7500media_portf_sd_init
137 static void ip7500media_portf_sd_init(void)
140 * Check the device tree for the sd_tio
142 struct sd_tio_node
*sd_node
= (struct sd_tio_node
*)devtree_find_node("portf_sd");
144 printk(KERN_INFO
"PortF SDTIO not found\n");
149 * Fill in the resources and platform data from devtree information
151 ip7500media_portf_sd_resources
[0].start
= sd_node
->dn
.sendirq
;
152 ip7500media_portf_sd_resources
[1].start
= sd_node
->dn
.recvirq
;
153 ip7500media_portf_sd_resources
[2].start
= (u32_t
)&(sd_node
->regs
);
154 ip7500media_portf_sd_resources
[2].end
= (u32_t
)&(sd_node
->regs
) + sizeof(sd_node
->regs
);
156 platform_device_register(&ip7500media_portf_sd_device
);
159 /******************************************************************************
160 * SD/IO Port B (Slot 2) platform data
162 static struct resource ip7500media_portb_sd_resources
[] = {
168 * The init routine will query the devtree and fill this in
170 .flags
= IORESOURCE_IRQ
,
178 * The init routine will query the devtree and fill this in
180 .flags
= IORESOURCE_IRQ
,
184 * Memory Mapped Registers
188 * The init routine will query the devtree and fill this in
190 .flags
= IORESOURCE_MEM
,
194 static struct ubicom32sd_card ip7500media_portb_sd_cards
[] = {
196 .pin_wp
= IP7500MEDIA_IO19
,
198 .pin_pwr
= IP7500MEDIA_IO22
,
199 .pin_cd
= IP7500MEDIA_IO18
,
203 static struct ubicom32sd_platform_data ip7500media_portb_sd_platform_data
= {
205 .cards
= ip7500media_portb_sd_cards
,
208 static struct platform_device ip7500media_portb_sd_device
= {
209 .name
= "ubicom32sd",
211 .resource
= ip7500media_portb_sd_resources
,
212 .num_resources
= ARRAY_SIZE(ip7500media_portb_sd_resources
),
214 .platform_data
= &ip7500media_portb_sd_platform_data
,
220 * ip7500media_portb_sd_init
222 static void ip7500media_portb_sd_init(void)
225 * Check the device tree for the sd_tio
227 struct sd_tio_node
*sd_node
= (struct sd_tio_node
*)devtree_find_node("portb_sd");
229 printk(KERN_INFO
"PortB SDTIO not found\n");
234 * Fill in the resources and platform data from devtree information
236 ip7500media_portb_sd_resources
[0].start
= sd_node
->dn
.sendirq
;
237 ip7500media_portb_sd_resources
[1].start
= sd_node
->dn
.recvirq
;
238 ip7500media_portb_sd_resources
[2].start
= (u32_t
)&(sd_node
->regs
);
239 ip7500media_portb_sd_resources
[2].end
= (u32_t
)&(sd_node
->regs
) + sizeof(sd_node
->regs
);
241 platform_device_register(&ip7500media_portb_sd_device
);
245 * ip7500media_u17_setup
246 * Called by I2C to tell us that u17 is setup.
248 * This function is called by I2C to tell us that u17 has been setup. All
249 * devices which rely on this chip being initialized (or even present) need to
250 * be initialized in this function otherwise they may get initialized too early.
252 * Currently the only device depending on u17 is the SDIO
254 static int __init
ip7500media_u17_setup(struct i2c_client
*client
, unsigned gpio
, unsigned ngpio
, void *context
)
257 * Initialize the Port F/Port B SD slots (only the enabled ports will init)
259 ip7500media_portf_sd_init();
260 ip7500media_portb_sd_init();
265 /******************************************************************************
266 * LCD VGH on the board at PE6
268 static struct ubicom32lcdpower_platform_data ip7500media_lcdpower_data
= {
269 .vgh_gpio
= GPIO_RE_7
,
270 .vgh_polarity
= true,
273 static struct platform_device ip7500media_lcdpower_device
= {
274 .name
= "ubicom32lcdpower",
277 .platform_data
= &ip7500media_lcdpower_data
,
281 /******************************************************************************
282 * Backlight on the board PD0, hardware PWM
284 static struct ubicom32bl_platform_data ip7500media_backlight_data
= {
285 .type
= UBICOM32BL_TYPE_PWM
,
289 .default_intensity
= 0x80,
292 static struct platform_device ip7500media_backlight_device
= {
293 .name
= "ubicom32bl",
296 .platform_data
= &ip7500media_backlight_data
,
300 /******************************************************************************
301 * Ubicom32Input on I2C, U15 MAX7310, address 0x18, 8 bits
303 static struct ubicom32input_i2c_button ip7500media_ubicom32input_i2c_u15_buttons
[] = {
348 static struct ubicom32input_i2c_platform_data ip7500media_ubicom32input_i2c_u15_platform_data
= {
349 .buttons
= ip7500media_ubicom32input_i2c_u15_buttons
,
350 .nbuttons
= ARRAY_SIZE(ip7500media_ubicom32input_i2c_u15_buttons
),
351 .name
= "Ubicom32 Input I2C U15",
354 /******************************************************************************
355 * Additional GPIO chips
357 static struct pca953x_platform_data ip7500media_gpio_u16_platform_data
= {
358 .gpio_base
= IP7500MEDIA_U16_BASE
,
361 static struct pca953x_platform_data ip7500media_gpio_u17_platform_data
= {
362 .gpio_base
= IP7500MEDIA_U17_BASE
,
363 .setup
= ip7500media_u17_setup
,
366 static struct pca953x_platform_data ip7500media_gpio_u18_platform_data
= {
367 .gpio_base
= IP7500MEDIA_U18_BASE
,
371 /******************************************************************************
372 * Touch controller present on LCD Adapter board
374 * Connected via I2C bus, interrupt on PD1
376 #include <linux/i2c/tsc2007.h>
379 * ip7500media_tsc2007_exit_platform_hw
381 static void ip7500media_tsc2007_exit_platform_hw(void)
383 UBICOM32_IO_PORT(RD
)->int_mask
&= ~(1 << 11);
384 UBICOM32_IO_PORT(RD
)->ctl2
&= ~(0x03 << 16);
385 gpio_free(GPIO_RD_1
);
389 * ip7500media_tsc2007_init_platform_hw
391 static int ip7500media_tsc2007_init_platform_hw(void)
393 int res
= gpio_request(GPIO_RD_1
, "TSC2007_IRQ");
397 UBICOM32_IO_PORT(RD
)->function
= 0;
398 UBICOM32_IO_PORT(RD
)->int_mask
= (1 << 11);
399 UBICOM32_IO_PORT(RD
)->ctl2
&= ~(0x03 << 16);
400 UBICOM32_IO_PORT(RD
)->ctl2
|= (0x02 << 16);
406 * ip7500media_tsc2007_clear_penirq
408 static void ip7500media_tsc2007_clear_penirq(void)
410 UBICOM32_IO_PORT(RD
)->int_clr
= (1 << 11);
414 * ip7500media_tsc2007_get_pendown_state
416 static int ip7500media_tsc2007_get_pendown_state(void)
418 return !gpio_get_value(GPIO_RD_1
);
421 static struct tsc2007_platform_data ip7500media_tsc2007_data
= {
424 .get_pendown_state
= ip7500media_tsc2007_get_pendown_state
,
425 .init_platform_hw
= ip7500media_tsc2007_init_platform_hw
,
426 .exit_platform_hw
= ip7500media_tsc2007_exit_platform_hw
,
427 .clear_penirq
= ip7500media_tsc2007_clear_penirq
,
430 /******************************************************************************
431 * Devices on the I2C bus
433 * BEWARE of changing the order of things in this array as we depend on
434 * certain things to be in certain places.
436 static struct i2c_board_info __initdata ip7500media_i2c_board_info
[] = {
438 * U6, CS4350 DAC, address 0x4B
446 * U14, S35390A RTC, address 0x30
454 * U15, MAX7310 IO expander, 8 bits, address 0x18
455 * IO0: User I/O (J16-1) (Left) IO4: User I/O (J16-5) (Enter)
456 * IO1: User I/O (J16-2) (Right) IO5: User I/O (J16-6) (Menu)
457 * IO2: User I/O (J16-3) (Up) IO6: User I/O (J16-7) (Back)
458 * IO3: User I/O (J16-4) (Down) IO7: User I/O (J16-8)
461 .type
= "ubicom32in_max7310",
463 .platform_data
= &ip7500media_ubicom32input_i2c_u15_platform_data
,
467 * U16, MAX7310 IO expander, 8 bits, address 0x1C
468 * IO8 : User I/O (J16-9) IO12: User I/O (J16-17)
469 * IO9 : User I/O (J16-10) IO13: User I/O (J16-18)
470 * IO10: User I/O (J16-15) IO14: User I/O (J16-19)
471 * IO11: User I/O (J16-16) IO15: User I/O (J16-20)
476 .platform_data
= &ip7500media_gpio_u16_platform_data
,
480 * U17, MAX7310 IO expander, 8 bits, address 0x1A
481 * IO16: SDIO1A_WP IO20: SD1A_PWREN
482 * IO17: SDIO1B_WP IO21: SD1B_PWREN
483 * IO18: SDIO2_CD IO22: SD2_PWREN
484 * IO19: SDIO2_WP IO23: SDIO1A_CD
490 .platform_data
= &ip7500media_gpio_u17_platform_data
,
494 * U18, MAX7310 IOB expander, 8 bits, address 0x1E
495 * IO24: SDIO1B_CD IO28: User I/O TP6
496 * IO25: User I/O TP9 IO29: User I/O TP5
497 * IO26: User I/O TP8 IO30: User I/O TP4
498 * IO27: User I/O TP7 IO31: User I/O TP3
503 .platform_data
= &ip7500media_gpio_u18_platform_data
,
508 * Additional I2C devices to add when a LCD adapter board is present
510 static struct i2c_board_info __initdata ip7500media_lcd_adapter_i2c_board_info
[] = {
512 I2C_BOARD_INFO("tsc2007", 0x48),
513 .irq
= PORT_OTHER_INT(RD
),
514 .platform_data
= &ip7500media_tsc2007_data
,
519 * I2C bus on the board, SDA PE4, SCL PE5
521 static struct i2c_gpio_platform_data ip7500media_i2c_data
= {
522 .sda_pin
= GPIO_RE_4
,
523 .scl_pin
= GPIO_RE_5
,
524 .sda_is_open_drain
= 0,
525 .scl_is_open_drain
= 0,
529 static struct platform_device ip7500media_i2c_device
= {
533 .platform_data
= &ip7500media_i2c_data
,
538 * Virtual Frame Buffer device for use with LCD Adapter
540 static struct platform_device ip7500media_vfb_device
= {
541 .name
= "ubicom32vfb",
547 * 0: no override (auto-detect)
549 * 2: force lcd adapter usage
551 static int __initdata vdc_override
= 0;
554 * ip7500media_set_forcevdc
555 * Called when forcevdc is present on the kernel boot line
557 static int __init
ip7500media_set_forcevdc(char *str
)
568 * ip7500media_video_init
569 * Called late to determine what kind of video we have on this board
571 static int __init
ip7500media_video_init(void)
573 struct i2c_adapter
*adap
;
574 struct i2c_msg msg
[1];
576 unsigned char checksum
;
580 if (vdc_override
== 1) {
581 printk(KERN_INFO
"Force VDCTIO mode\n");
584 if (vdc_override
== 2) {
585 printk(KERN_INFO
"Force LCD Adapter Board mode\n");
590 * Check to see if there is an EEPROM out there. If we see an
591 * EEPROM then we will assume a LCD Adapter Board (8007-092x)
594 data
= kmalloc(256, GFP_KERNEL
);
596 printk(KERN_WARNING
"%s: Failed to allocate memory\n", __FUNCTION__
);
600 adap
= i2c_get_adapter(0);
602 printk(KERN_WARNING
"%s: Failed to get i2c adapter\n", __FUNCTION__
);
611 err
= i2c_transfer(adap
, msg
, 1);
617 msg
->flags
= I2C_M_RD
;
620 err
= i2c_transfer(adap
, msg
, 1);
625 i2c_put_adapter(adap
);
628 * Verify the checksum
631 for (i
= 0; i
< 255; i
++) {
634 if (checksum
!= data
[255]) {
635 printk(KERN_WARNING
"%s: Checksum mismatch\n", __FUNCTION__
);
643 platform_device_register(&ip7500media_vfb_device
);
646 * Add the i2c devices on the LCD Adapter board. (We have to use i2c_new_device
647 * since it's late in the boot process.)
649 printk(KERN_INFO
"%s: registering LCD Adapter board i2c resources\n", __FUNCTION__
);
650 for (i
= 0; i
< ARRAY_SIZE(ip7500media_lcd_adapter_i2c_board_info
); i
++) {
651 i2c_new_device(adap
, &ip7500media_lcd_adapter_i2c_board_info
[i
]);
654 i2c_put_adapter(adap
);
659 * No LCD Adapter board, bring up VDC
665 late_initcall(ip7500media_video_init
);
666 __setup("forcevdc=", ip7500media_set_forcevdc
);
670 * Called to add the devices which we have on this board
672 static int __init
ip7500media_init(void)
674 struct platform_device
*audio_dev
;
675 int have_ethernet
= (devtree_find_node("eth_lan") != 0);
681 #ifdef CONFIG_UIO_UBICOM32RING
682 ring_tio_init("decoder_ring");
686 * Register all of the devices we have on this board
688 printk(KERN_INFO
"%s: registering device resources\n", __FUNCTION__
);
689 platform_device_register(&ip7500media_i2c_device
);
690 platform_device_register(&ip7500media_backlight_device
);
693 * If ethernet doesn't exist then we can init the lcdpower
695 if (!have_ethernet
) {
696 platform_device_register(&ip7500media_lcdpower_device
);
700 * Allocate the audio drivers. SPDIF not supported on boards with ethernet.
702 audio_dev
= audio_device_alloc("snd-ubi32-cs4350", "audio", "audio-i2sout", 0);
704 ip7500media_i2c_board_info
[0].platform_data
= audio_dev
;
707 if (!have_ethernet
) {
708 struct platform_device
*audio_dev2
;
710 audio_dev2
= audio_device_alloc("snd-ubi32-generic", "audio", "audio-spdifout", 0);
712 platform_device_register(audio_dev2
);
717 * Register all of the devices which sit on the I2C bus
719 printk(KERN_INFO
"%s: registering i2c resources\n", __FUNCTION__
);
720 i2c_register_board_info(0, ip7500media_i2c_board_info
, ARRAY_SIZE(ip7500media_i2c_board_info
));
723 * We have to initialize the SDIO after the I2C IOB gets setup. SDIO is initialized in
724 * ip7500media_u17_setup
727 printk("IP7500 Media Board\n");
732 arch_initcall(ip7500media_init
);