| 1 | /* |
| 2 | * arch/ubicom32/mach-ip7k/board-ip7500media.c |
| 3 | * Board file for IP7500 media board. |
| 4 | * |
| 5 | * Supports the following configuration |
| 6 | * CPU Module: |
| 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 |
| 13 | * POS 4: unused |
| 14 | * Media Board: |
| 15 | * P/N 8007-0610 rev 1.0 |
| 16 | * |
| 17 | * LCD Adapter Board: (optional) |
| 18 | * P/N 8007-0920 rev 2.0 |
| 19 | * P/N 8007-0921 rev 2.1 |
| 20 | * |
| 21 | * (C) Copyright 2009, Ubicom, Inc. |
| 22 | * |
| 23 | * This file is part of the Ubicom32 Linux Kernel Port. |
| 24 | * |
| 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. |
| 29 | * |
| 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. |
| 34 | * |
| 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/>. |
| 38 | * |
| 39 | * Ubicom32 implementation derived from (with many thanks): |
| 40 | * arch/m68knommu |
| 41 | * arch/blackfin |
| 42 | * arch/parisc |
| 43 | */ |
| 44 | #include <linux/device.h> |
| 45 | #include <linux/platform_device.h> |
| 46 | #include <linux/gpio.h> |
| 47 | |
| 48 | #include <linux/input.h> |
| 49 | |
| 50 | #include <linux/i2c.h> |
| 51 | #include <linux/i2c-gpio.h> |
| 52 | #include <linux/i2c/pca953x.h> |
| 53 | |
| 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> |
| 60 | |
| 61 | #include <asm/ubicom32sd.h> |
| 62 | #include <asm/sd_tio.h> |
| 63 | #include <asm/devtree.h> |
| 64 | #include <asm/audio.h> |
| 65 | |
| 66 | #include <asm/ring_tio.h> |
| 67 | |
| 68 | /****************************************************************************** |
| 69 | * SD/IO Port F (Slot 1) platform data |
| 70 | */ |
| 71 | static struct resource ip7500media_portf_sd_resources[] = { |
| 72 | /* |
| 73 | * Send IRQ |
| 74 | */ |
| 75 | [0] = { |
| 76 | /* |
| 77 | * The init routine will query the devtree and fill this in |
| 78 | */ |
| 79 | .flags = IORESOURCE_IRQ, |
| 80 | }, |
| 81 | |
| 82 | /* |
| 83 | * Receive IRQ |
| 84 | */ |
| 85 | [1] = { |
| 86 | /* |
| 87 | * The init routine will query the devtree and fill this in |
| 88 | */ |
| 89 | .flags = IORESOURCE_IRQ, |
| 90 | }, |
| 91 | |
| 92 | /* |
| 93 | * Memory Mapped Registers |
| 94 | */ |
| 95 | [2] = { |
| 96 | /* |
| 97 | * The init routine will query the devtree and fill this in |
| 98 | */ |
| 99 | .flags = IORESOURCE_MEM, |
| 100 | }, |
| 101 | }; |
| 102 | |
| 103 | static struct ubicom32sd_card ip7500media_portf_sd_cards[] = { |
| 104 | [0] = { |
| 105 | .pin_wp = IP7500MEDIA_IO16, |
| 106 | .wp_polarity = 1, |
| 107 | .pin_pwr = IP7500MEDIA_IO20, |
| 108 | .pin_cd = IP7500MEDIA_IO23, |
| 109 | }, |
| 110 | [1] = { |
| 111 | .pin_wp = IP7500MEDIA_IO17, |
| 112 | .wp_polarity = 1, |
| 113 | .pin_pwr = IP7500MEDIA_IO21, |
| 114 | .pin_cd = IP7500MEDIA_IO24, |
| 115 | }, |
| 116 | }; |
| 117 | |
| 118 | static struct ubicom32sd_platform_data ip7500media_portf_sd_platform_data = { |
| 119 | .ncards = 2, |
| 120 | .cards = ip7500media_portf_sd_cards, |
| 121 | }; |
| 122 | |
| 123 | static struct platform_device ip7500media_portf_sd_device = { |
| 124 | .name = "ubicom32sd", |
| 125 | .id = 0, |
| 126 | .resource = ip7500media_portf_sd_resources, |
| 127 | .num_resources = ARRAY_SIZE(ip7500media_portf_sd_resources), |
| 128 | .dev = { |
| 129 | .platform_data = &ip7500media_portf_sd_platform_data, |
| 130 | }, |
| 131 | |
| 132 | }; |
| 133 | |
| 134 | /* |
| 135 | * ip7500media_portf_sd_init |
| 136 | */ |
| 137 | static void ip7500media_portf_sd_init(void) |
| 138 | { |
| 139 | /* |
| 140 | * Check the device tree for the sd_tio |
| 141 | */ |
| 142 | struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portf_sd"); |
| 143 | if (!sd_node) { |
| 144 | printk(KERN_INFO "PortF SDTIO not found\n"); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Fill in the resources and platform data from devtree information |
| 150 | */ |
| 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); |
| 155 | |
| 156 | platform_device_register(&ip7500media_portf_sd_device); |
| 157 | } |
| 158 | |
| 159 | /****************************************************************************** |
| 160 | * SD/IO Port B (Slot 2) platform data |
| 161 | */ |
| 162 | static struct resource ip7500media_portb_sd_resources[] = { |
| 163 | /* |
| 164 | * Send IRQ |
| 165 | */ |
| 166 | [0] = { |
| 167 | /* |
| 168 | * The init routine will query the devtree and fill this in |
| 169 | */ |
| 170 | .flags = IORESOURCE_IRQ, |
| 171 | }, |
| 172 | |
| 173 | /* |
| 174 | * Receive IRQ |
| 175 | */ |
| 176 | [1] = { |
| 177 | /* |
| 178 | * The init routine will query the devtree and fill this in |
| 179 | */ |
| 180 | .flags = IORESOURCE_IRQ, |
| 181 | }, |
| 182 | |
| 183 | /* |
| 184 | * Memory Mapped Registers |
| 185 | */ |
| 186 | [2] = { |
| 187 | /* |
| 188 | * The init routine will query the devtree and fill this in |
| 189 | */ |
| 190 | .flags = IORESOURCE_MEM, |
| 191 | }, |
| 192 | }; |
| 193 | |
| 194 | static struct ubicom32sd_card ip7500media_portb_sd_cards[] = { |
| 195 | [0] = { |
| 196 | .pin_wp = IP7500MEDIA_IO19, |
| 197 | .wp_polarity = 1, |
| 198 | .pin_pwr = IP7500MEDIA_IO22, |
| 199 | .pin_cd = IP7500MEDIA_IO18, |
| 200 | }, |
| 201 | }; |
| 202 | |
| 203 | static struct ubicom32sd_platform_data ip7500media_portb_sd_platform_data = { |
| 204 | .ncards = 1, |
| 205 | .cards = ip7500media_portb_sd_cards, |
| 206 | }; |
| 207 | |
| 208 | static struct platform_device ip7500media_portb_sd_device = { |
| 209 | .name = "ubicom32sd", |
| 210 | .id = 1, |
| 211 | .resource = ip7500media_portb_sd_resources, |
| 212 | .num_resources = ARRAY_SIZE(ip7500media_portb_sd_resources), |
| 213 | .dev = { |
| 214 | .platform_data = &ip7500media_portb_sd_platform_data, |
| 215 | }, |
| 216 | |
| 217 | }; |
| 218 | |
| 219 | /* |
| 220 | * ip7500media_portb_sd_init |
| 221 | */ |
| 222 | static void ip7500media_portb_sd_init(void) |
| 223 | { |
| 224 | /* |
| 225 | * Check the device tree for the sd_tio |
| 226 | */ |
| 227 | struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portb_sd"); |
| 228 | if (!sd_node) { |
| 229 | printk(KERN_INFO "PortB SDTIO not found\n"); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Fill in the resources and platform data from devtree information |
| 235 | */ |
| 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); |
| 240 | |
| 241 | platform_device_register(&ip7500media_portb_sd_device); |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * ip7500media_u17_setup |
| 246 | * Called by I2C to tell us that u17 is setup. |
| 247 | * |
| 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. |
| 251 | * |
| 252 | * Currently the only device depending on u17 is the SDIO |
| 253 | */ |
| 254 | static int __init ip7500media_u17_setup(struct i2c_client *client, unsigned gpio, unsigned ngpio, void *context) |
| 255 | { |
| 256 | /* |
| 257 | * Initialize the Port F/Port B SD slots (only the enabled ports will init) |
| 258 | */ |
| 259 | ip7500media_portf_sd_init(); |
| 260 | ip7500media_portb_sd_init(); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | /****************************************************************************** |
| 266 | * LCD VGH on the board at PE6 |
| 267 | */ |
| 268 | static struct ubicom32lcdpower_platform_data ip7500media_lcdpower_data = { |
| 269 | .vgh_gpio = GPIO_RE_7, |
| 270 | .vgh_polarity = true, |
| 271 | }; |
| 272 | |
| 273 | static struct platform_device ip7500media_lcdpower_device = { |
| 274 | .name = "ubicom32lcdpower", |
| 275 | .id = -1, |
| 276 | .dev = { |
| 277 | .platform_data = &ip7500media_lcdpower_data, |
| 278 | }, |
| 279 | }; |
| 280 | |
| 281 | /****************************************************************************** |
| 282 | * Backlight on the board PD0, hardware PWM |
| 283 | */ |
| 284 | static struct ubicom32bl_platform_data ip7500media_backlight_data = { |
| 285 | .type = UBICOM32BL_TYPE_PWM, |
| 286 | .pwm_channel = 2, |
| 287 | .pwm_prescale = 15, |
| 288 | .pwm_period = 60, |
| 289 | .default_intensity = 0x80, |
| 290 | }; |
| 291 | |
| 292 | static struct platform_device ip7500media_backlight_device = { |
| 293 | .name = "ubicom32bl", |
| 294 | .id = -1, |
| 295 | .dev = { |
| 296 | .platform_data = &ip7500media_backlight_data, |
| 297 | }, |
| 298 | }; |
| 299 | |
| 300 | /****************************************************************************** |
| 301 | * Ubicom32Input on I2C, U15 MAX7310, address 0x18, 8 bits |
| 302 | */ |
| 303 | static struct ubicom32input_i2c_button ip7500media_ubicom32input_i2c_u15_buttons[] = { |
| 304 | { |
| 305 | .type = EV_KEY, |
| 306 | .code = KEY_LEFT, |
| 307 | .bit = 0, |
| 308 | .active_low = 1, |
| 309 | }, |
| 310 | { |
| 311 | .type = EV_KEY, |
| 312 | .code = KEY_RIGHT, |
| 313 | .bit = 1, |
| 314 | .active_low = 1, |
| 315 | }, |
| 316 | { |
| 317 | .type = EV_KEY, |
| 318 | .code = KEY_UP, |
| 319 | .bit = 2, |
| 320 | .active_low = 1, |
| 321 | }, |
| 322 | { |
| 323 | .type = EV_KEY, |
| 324 | .code = KEY_DOWN, |
| 325 | .bit = 3, |
| 326 | .active_low = 1, |
| 327 | }, |
| 328 | { |
| 329 | .type = EV_KEY, |
| 330 | .code = KEY_ENTER, |
| 331 | .bit = 4, |
| 332 | .active_low = 1, |
| 333 | }, |
| 334 | { |
| 335 | .type = EV_KEY, |
| 336 | .code = KEY_MENU, |
| 337 | .bit = 5, |
| 338 | .active_low = 1, |
| 339 | }, |
| 340 | { |
| 341 | .type = EV_KEY, |
| 342 | .code = KEY_ESC, |
| 343 | .bit = 6, |
| 344 | .active_low = 1, |
| 345 | }, |
| 346 | }; |
| 347 | |
| 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", |
| 352 | }; |
| 353 | |
| 354 | /****************************************************************************** |
| 355 | * Additional GPIO chips |
| 356 | */ |
| 357 | static struct pca953x_platform_data ip7500media_gpio_u16_platform_data = { |
| 358 | .gpio_base = IP7500MEDIA_U16_BASE, |
| 359 | }; |
| 360 | |
| 361 | static struct pca953x_platform_data ip7500media_gpio_u17_platform_data = { |
| 362 | .gpio_base = IP7500MEDIA_U17_BASE, |
| 363 | .setup = ip7500media_u17_setup, |
| 364 | }; |
| 365 | |
| 366 | static struct pca953x_platform_data ip7500media_gpio_u18_platform_data = { |
| 367 | .gpio_base = IP7500MEDIA_U18_BASE, |
| 368 | }; |
| 369 | |
| 370 | |
| 371 | /****************************************************************************** |
| 372 | * Touch controller present on LCD Adapter board |
| 373 | * |
| 374 | * Connected via I2C bus, interrupt on PD1 |
| 375 | */ |
| 376 | #include <linux/i2c/tsc2007.h> |
| 377 | |
| 378 | /* |
| 379 | * ip7500media_tsc2007_exit_platform_hw |
| 380 | */ |
| 381 | static void ip7500media_tsc2007_exit_platform_hw(void) |
| 382 | { |
| 383 | UBICOM32_IO_PORT(RD)->int_mask &= ~(1 << 11); |
| 384 | UBICOM32_IO_PORT(RD)->ctl2 &= ~(0x03 << 16); |
| 385 | gpio_free(GPIO_RD_1); |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * ip7500media_tsc2007_init_platform_hw |
| 390 | */ |
| 391 | static int ip7500media_tsc2007_init_platform_hw(void) |
| 392 | { |
| 393 | int res = gpio_request(GPIO_RD_1, "TSC2007_IRQ"); |
| 394 | if (res) { |
| 395 | return res; |
| 396 | } |
| 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); |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | /* |
| 406 | * ip7500media_tsc2007_clear_penirq |
| 407 | */ |
| 408 | static void ip7500media_tsc2007_clear_penirq(void) |
| 409 | { |
| 410 | UBICOM32_IO_PORT(RD)->int_clr = (1 << 11); |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * ip7500media_tsc2007_get_pendown_state |
| 415 | */ |
| 416 | static int ip7500media_tsc2007_get_pendown_state(void) |
| 417 | { |
| 418 | return !gpio_get_value(GPIO_RD_1); |
| 419 | } |
| 420 | |
| 421 | static struct tsc2007_platform_data ip7500media_tsc2007_data = { |
| 422 | .model = 2007, |
| 423 | .x_plate_ohms = 350, |
| 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, |
| 428 | }; |
| 429 | |
| 430 | /****************************************************************************** |
| 431 | * Devices on the I2C bus |
| 432 | * |
| 433 | * BEWARE of changing the order of things in this array as we depend on |
| 434 | * certain things to be in certain places. |
| 435 | */ |
| 436 | static struct i2c_board_info __initdata ip7500media_i2c_board_info[] = { |
| 437 | /* |
| 438 | * U6, CS4350 DAC, address 0x4B |
| 439 | */ |
| 440 | { |
| 441 | .type = "cs4350", |
| 442 | .addr = 0x4B, |
| 443 | }, |
| 444 | |
| 445 | /* |
| 446 | * U14, S35390A RTC, address 0x30 |
| 447 | */ |
| 448 | { |
| 449 | .type = "s35390a", |
| 450 | .addr = 0x30, |
| 451 | }, |
| 452 | |
| 453 | /* |
| 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) |
| 459 | */ |
| 460 | { |
| 461 | .type = "ubicom32in_max7310", |
| 462 | .addr = 0x18, |
| 463 | .platform_data = &ip7500media_ubicom32input_i2c_u15_platform_data, |
| 464 | }, |
| 465 | |
| 466 | /* |
| 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) |
| 472 | */ |
| 473 | { |
| 474 | .type = "max7310", |
| 475 | .addr = 0x1C, |
| 476 | .platform_data = &ip7500media_gpio_u16_platform_data, |
| 477 | }, |
| 478 | |
| 479 | /* |
| 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 |
| 485 | * |
| 486 | */ |
| 487 | { |
| 488 | .type = "max7310", |
| 489 | .addr = 0x1A, |
| 490 | .platform_data = &ip7500media_gpio_u17_platform_data, |
| 491 | }, |
| 492 | |
| 493 | /* |
| 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 |
| 499 | */ |
| 500 | { |
| 501 | .type = "max7310", |
| 502 | .addr = 0x1E, |
| 503 | .platform_data = &ip7500media_gpio_u18_platform_data, |
| 504 | }, |
| 505 | }; |
| 506 | |
| 507 | /* |
| 508 | * Additional I2C devices to add when a LCD adapter board is present |
| 509 | */ |
| 510 | static struct i2c_board_info __initdata ip7500media_lcd_adapter_i2c_board_info[] = { |
| 511 | { |
| 512 | I2C_BOARD_INFO("tsc2007", 0x48), |
| 513 | .irq = PORT_OTHER_INT(RD), |
| 514 | .platform_data = &ip7500media_tsc2007_data, |
| 515 | }, |
| 516 | }; |
| 517 | |
| 518 | /* |
| 519 | * I2C bus on the board, SDA PE4, SCL PE5 |
| 520 | */ |
| 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, |
| 526 | .udelay = 50, |
| 527 | }; |
| 528 | |
| 529 | static struct platform_device ip7500media_i2c_device = { |
| 530 | .name = "i2c-gpio", |
| 531 | .id = 0, |
| 532 | .dev = { |
| 533 | .platform_data = &ip7500media_i2c_data, |
| 534 | }, |
| 535 | }; |
| 536 | |
| 537 | /* |
| 538 | * Virtual Frame Buffer device for use with LCD Adapter |
| 539 | */ |
| 540 | static struct platform_device ip7500media_vfb_device = { |
| 541 | .name = "ubicom32vfb", |
| 542 | .id = -1, |
| 543 | }; |
| 544 | |
| 545 | /* |
| 546 | * vdc_override: |
| 547 | * 0: no override (auto-detect) |
| 548 | * 1: force vdc usage |
| 549 | * 2: force lcd adapter usage |
| 550 | */ |
| 551 | static int __initdata vdc_override = 0; |
| 552 | |
| 553 | /* |
| 554 | * ip7500media_set_forcevdc |
| 555 | * Called when forcevdc is present on the kernel boot line |
| 556 | */ |
| 557 | static int __init ip7500media_set_forcevdc(char *str) |
| 558 | { |
| 559 | if (str[0] == '1') { |
| 560 | vdc_override = 1; |
| 561 | } else { |
| 562 | vdc_override = 2; |
| 563 | } |
| 564 | return 1; |
| 565 | } |
| 566 | |
| 567 | /* |
| 568 | * ip7500media_video_init |
| 569 | * Called late to determine what kind of video we have on this board |
| 570 | */ |
| 571 | static int __init ip7500media_video_init(void) |
| 572 | { |
| 573 | struct i2c_adapter *adap; |
| 574 | struct i2c_msg msg[1]; |
| 575 | unsigned char *data; |
| 576 | unsigned char checksum; |
| 577 | int err; |
| 578 | int i; |
| 579 | |
| 580 | if (vdc_override == 1) { |
| 581 | printk(KERN_INFO "Force VDCTIO mode\n"); |
| 582 | goto no_adapter; |
| 583 | } |
| 584 | if (vdc_override == 2) { |
| 585 | printk(KERN_INFO "Force LCD Adapter Board mode\n"); |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | /* |
| 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) |
| 592 | * exists. |
| 593 | */ |
| 594 | data = kmalloc(256, GFP_KERNEL); |
| 595 | if (!data) { |
| 596 | printk(KERN_WARNING "%s: Failed to allocate memory\n", __FUNCTION__); |
| 597 | return -ENOMEM; |
| 598 | } |
| 599 | |
| 600 | adap = i2c_get_adapter(0); |
| 601 | if (!adap) { |
| 602 | printk(KERN_WARNING "%s: Failed to get i2c adapter\n", __FUNCTION__); |
| 603 | kfree(data); |
| 604 | return -ENODEV; |
| 605 | } |
| 606 | data[0] = 0; |
| 607 | msg->addr = 0x50; |
| 608 | msg->flags = 0; |
| 609 | msg->len = 1; |
| 610 | msg->buf = data; |
| 611 | err = i2c_transfer(adap, msg, 1); |
| 612 | if (err < 0) { |
| 613 | goto no_adapter; |
| 614 | } |
| 615 | |
| 616 | msg->addr = 0x50; |
| 617 | msg->flags = I2C_M_RD; |
| 618 | msg->len = 256; |
| 619 | msg->buf = data; |
| 620 | err = i2c_transfer(adap, msg, 1); |
| 621 | if (err < 0) { |
| 622 | goto no_adapter; |
| 623 | } |
| 624 | |
| 625 | i2c_put_adapter(adap); |
| 626 | |
| 627 | /* |
| 628 | * Verify the checksum |
| 629 | */ |
| 630 | checksum = 0xff; |
| 631 | for (i = 0; i < 255; i++) { |
| 632 | checksum ^= data[i]; |
| 633 | } |
| 634 | if (checksum != data[255]) { |
| 635 | printk(KERN_WARNING "%s: Checksum mismatch\n", __FUNCTION__); |
| 636 | } |
| 637 | |
| 638 | kfree(data); |
| 639 | |
| 640 | /* |
| 641 | * Bring up VFB |
| 642 | */ |
| 643 | platform_device_register(&ip7500media_vfb_device); |
| 644 | |
| 645 | /* |
| 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.) |
| 648 | */ |
| 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]); |
| 652 | } |
| 653 | |
| 654 | i2c_put_adapter(adap); |
| 655 | |
| 656 | return 0; |
| 657 | |
| 658 | /* |
| 659 | * No LCD Adapter board, bring up VDC |
| 660 | */ |
| 661 | no_adapter: |
| 662 | vdc_tio_init(); |
| 663 | return 0; |
| 664 | } |
| 665 | late_initcall(ip7500media_video_init); |
| 666 | __setup("forcevdc=", ip7500media_set_forcevdc); |
| 667 | |
| 668 | /* |
| 669 | * ip7500media_init |
| 670 | * Called to add the devices which we have on this board |
| 671 | */ |
| 672 | static int __init ip7500media_init(void) |
| 673 | { |
| 674 | struct platform_device *audio_dev; |
| 675 | int have_ethernet = (devtree_find_node("eth_lan") != 0); |
| 676 | |
| 677 | board_init(); |
| 678 | |
| 679 | ubi_gpio_init(); |
| 680 | |
| 681 | #ifdef CONFIG_UIO_UBICOM32RING |
| 682 | ring_tio_init("decoder_ring"); |
| 683 | #endif |
| 684 | |
| 685 | /* |
| 686 | * Register all of the devices we have on this board |
| 687 | */ |
| 688 | printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__); |
| 689 | platform_device_register(&ip7500media_i2c_device); |
| 690 | platform_device_register(&ip7500media_backlight_device); |
| 691 | |
| 692 | /* |
| 693 | * If ethernet doesn't exist then we can init the lcdpower |
| 694 | */ |
| 695 | if (!have_ethernet) { |
| 696 | platform_device_register(&ip7500media_lcdpower_device); |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | * Allocate the audio drivers. SPDIF not supported on boards with ethernet. |
| 701 | */ |
| 702 | audio_dev = audio_device_alloc("snd-ubi32-cs4350", "audio", "audio-i2sout", 0); |
| 703 | if (audio_dev) { |
| 704 | ip7500media_i2c_board_info[0].platform_data = audio_dev; |
| 705 | } |
| 706 | |
| 707 | if (!have_ethernet) { |
| 708 | struct platform_device *audio_dev2; |
| 709 | |
| 710 | audio_dev2 = audio_device_alloc("snd-ubi32-generic", "audio", "audio-spdifout", 0); |
| 711 | if (audio_dev2) { |
| 712 | platform_device_register(audio_dev2); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | /* |
| 717 | * Register all of the devices which sit on the I2C bus |
| 718 | */ |
| 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)); |
| 721 | |
| 722 | /* |
| 723 | * We have to initialize the SDIO after the I2C IOB gets setup. SDIO is initialized in |
| 724 | * ip7500media_u17_setup |
| 725 | */ |
| 726 | |
| 727 | printk("IP7500 Media Board\n"); |
| 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | arch_initcall(ip7500media_init); |
| 733 | |