2 * arch/ubicom32/mach-ip7k/board-ip7145dpf.c
3 * Board file for IP7145DPF, rev 1.0, P/N 8007-0410
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
28 #include <linux/device.h>
29 #include <linux/platform_device.h>
30 #include <linux/gpio.h>
32 #include <linux/input.h>
34 #include <linux/i2c.h>
35 #include <linux/i2c-gpio.h>
36 #include <linux/i2c/pca953x.h>
38 #include <asm/board.h>
39 #include <asm/machdep.h>
40 #include <asm/ubicom32input.h>
41 #include <asm/ubicom32input_i2c.h>
42 #include <asm/ubicom32bl.h>
43 #include <asm/ubicom32lcdpower.h>
44 #include <asm/vdc_tio.h>
46 #include <asm/ubicom32sd.h>
47 #include <asm/sd_tio.h>
48 #include <asm/devtree.h>
49 #include <asm/audio.h>
51 #include <asm/ring_tio.h>
53 /******************************************************************************
54 * SD/IO Port F (Slot 1) platform data
56 static struct resource ip7145dpf_portf_sd_resources[] = {
62 * The init routine will query the devtree and fill this in
64 .flags = IORESOURCE_IRQ,
72 * The init routine will query the devtree and fill this in
74 .flags = IORESOURCE_IRQ,
78 * Memory Mapped Registers
82 * The init routine will query the devtree and fill this in
84 .flags = IORESOURCE_MEM,
88 static struct ubicom32sd_card ip7145dpf_portf_sd_cards[] = {
90 .pin_wp = IP7145DPF_IOB0,
92 .pin_pwr = IP7145DPF_IOB4,
96 .pin_wp = IP7145DPF_IOB1,
98 .pin_pwr = IP7145DPF_IOB5,
103 static struct ubicom32sd_platform_data ip7145dpf_portf_sd_platform_data = {
105 .cards = ip7145dpf_portf_sd_cards,
108 static struct platform_device ip7145dpf_portf_sd_device = {
109 .name = "ubicom32sd",
111 .resource = ip7145dpf_portf_sd_resources,
112 .num_resources = ARRAY_SIZE(ip7145dpf_portf_sd_resources),
114 .platform_data = &ip7145dpf_portf_sd_platform_data,
120 * ip7145dpf_portf_sd_init
122 static void ip7145dpf_portf_sd_init(void)
125 * Check the device tree for the sd_tio
127 struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portf_sd");
129 printk(KERN_INFO "PortF SDTIO not found\n");
134 * Fill in the resources and platform data from devtree information
136 ip7145dpf_portf_sd_resources[0].start = sd_node->dn.sendirq;
137 ip7145dpf_portf_sd_resources[1].start = sd_node->dn.recvirq;
138 ip7145dpf_portf_sd_resources[2].start = (u32_t)&(sd_node->regs);
139 ip7145dpf_portf_sd_resources[2].end = (u32_t)&(sd_node->regs) + sizeof(sd_node->regs);
141 platform_device_register(&ip7145dpf_portf_sd_device);
144 /******************************************************************************
145 * SD/IO Port B (Slot 2) platform data
147 static struct resource ip7145dpf_portb_sd_resources[] = {
153 * The init routine will query the devtree and fill this in
155 .flags = IORESOURCE_IRQ,
163 * The init routine will query the devtree and fill this in
165 .flags = IORESOURCE_IRQ,
169 * Memory Mapped Registers
173 * The init routine will query the devtree and fill this in
175 .flags = IORESOURCE_MEM,
179 static struct ubicom32sd_card ip7145dpf_portb_sd_cards[] = {
181 .pin_wp = IP7145DPF_IOB2,
183 .pin_pwr = IP7145DPF_IOB6,
184 .pin_cd = IP7145DPF_IOB3,
188 static struct ubicom32sd_platform_data ip7145dpf_portb_sd_platform_data = {
190 .cards = ip7145dpf_portb_sd_cards,
193 static struct platform_device ip7145dpf_portb_sd_device = {
194 .name = "ubicom32sd",
196 .resource = ip7145dpf_portb_sd_resources,
197 .num_resources = ARRAY_SIZE(ip7145dpf_portb_sd_resources),
199 .platform_data = &ip7145dpf_portb_sd_platform_data,
205 * ip7145dpf_portb_sd_init
207 static void ip7145dpf_portb_sd_init(void)
210 * Check the device tree for the sd_tio
212 struct sd_tio_node *sd_node = (struct sd_tio_node *)devtree_find_node("portb_sd");
214 printk(KERN_INFO "PortB SDTIO not found\n");
219 * Fill in the resources and platform data from devtree information
221 ip7145dpf_portb_sd_resources[0].start = sd_node->dn.sendirq;
222 ip7145dpf_portb_sd_resources[1].start = sd_node->dn.recvirq;
223 ip7145dpf_portb_sd_resources[2].start = (u32_t)&(sd_node->regs);
224 ip7145dpf_portb_sd_resources[2].end = (u32_t)&(sd_node->regs) + sizeof(sd_node->regs);
226 platform_device_register(&ip7145dpf_portb_sd_device);
230 #ifdef IP7145DPF_USE_MMC_SPI
231 /******************************************************************************
232 * SPI over GPIO (MMC_SPI)
234 #include <linux/spi/spi.h>
235 #include <linux/spi/mmc_spi.h>
236 #include <linux/mmc/host.h>
237 #include <asm/ubicom32-spi-gpio.h>
239 #define MMC_CS GPIO_RF_5 // PF5 D3
240 #define MMC_CD GPIO_RA_4 // PA4 CD
241 #define MMC_WP IP7145DPF_IOB0 // IOB0 WP
242 #define MMC_PWR IP7145DPF_IOB4 // IOB4 PWR
245 * SPI bus over GPIO (for SD card)
247 static struct ubicom32_spi_gpio_platform_data ip7145dpf_spi_gpio_data = {
248 .pin_mosi = GPIO_RF_0, // PF0 CMD
249 .pin_miso = GPIO_RF_2, // PF2 D0
250 .pin_clk = GPIO_RF_1, // PF1 CLK
251 .bus_num = 0, // We'll call this SPI bus 0
252 .num_chipselect = 1, // only one device on this SPI bus
255 static struct platform_device ip7145dpf_spi_gpio_device = {
256 .name = "ubicom32-spi-gpio",
259 .platform_data = &ip7145dpf_spi_gpio_data,
264 * ip7145dpf_mmc_spi_setpower_slot_a
265 * Set the power state for slot A
267 static void ip7145dpf_mmc_spi_setpower_slot_a(struct device *dev, unsigned int vdd)
269 struct mmc_spi_platform_data *pd = dev->platform_data;
272 * Power is inverted, we could tell the IOB to do it, but it's cleaner this way.
274 if ((1 << vdd) & pd->ocr_mask) {
275 gpio_set_value(MMC_PWR, 0);
278 gpio_set_value(MMC_PWR, 1);
282 * ip7145dpf_mmc_spi_get_cd_slot_a
283 * Get the CD bit for slot A
285 static int ip7145dpf_mmc_spi_get_cd_slot_a(struct device *dev)
288 * Note that the sense of the GPIO is inverted
290 return !gpio_get_value(MMC_CD);
294 * ip7145dpf_mmc_spi_get_ro_slot_a
295 * Get the WP bit for slot A
297 static int ip7145dpf_mmc_spi_get_ro_slot_a(struct device *dev)
300 * Note that the sense of the GPIO is inverted, we could tell the IOB to do it, but
301 * it's clearer this way.
303 return !gpio_get_value(MMC_WP);
307 * ip7145dpf_mmc_spi_exit_slot_a
308 * Free the appropriate GPIOs for slot A SD slot.
310 static void ip7145dpf_mmc_spi_exit_slot_a(struct device *dev, void *appdata)
316 platform_device_unregister(&ip7145dpf_spi_gpio_device);
320 * ip7145dpf_mmc_spi_init_slot_a
321 * Allocate the appropriate GPIOs for slot A SD slot.
322 * WP is on IOB0, CD is PA4, CS is on PF5
323 * TODO: make CD an interrupt
325 static int ip7145dpf_mmc_spi_init_slot_a(void)
327 int ret = gpio_request(MMC_CD, "mmc-a-cd");
329 printk(KERN_ERR "%s: could not request mmc-a-cd pin\n", __FUNCTION__);
332 gpio_direction_input(MMC_CD);
334 ret = gpio_request(MMC_CS, "mmc-a-cs");
336 printk(KERN_ERR "%s: could not request mmc-a-cs pin\n", __FUNCTION__);
339 gpio_direction_output(MMC_CS, 0);
341 ret = gpio_request(MMC_WP, "mmc-a-wp");
343 printk(KERN_ERR "%s: could not request mmc-a-wp pin\n", __FUNCTION__);
346 gpio_direction_input(MMC_WP);
349 * Start off with power off
351 ret = gpio_request(MMC_PWR, "mmc-a-pwr");
353 printk(KERN_ERR "%s: could not request mmc-a-pwr pin\n", __FUNCTION__);
356 ret = gpio_direction_output(MMC_PWR, 1);
372 * MMC_SPI driver (currently bitbang)
374 static struct mmc_spi_platform_data ip7145dpf_mmc_platform_data = {
375 .ocr_mask = MMC_VDD_33_34,
376 .exit = ip7145dpf_mmc_spi_exit_slot_a,
377 .get_ro = ip7145dpf_mmc_spi_get_ro_slot_a,
378 .get_cd = ip7145dpf_mmc_spi_get_cd_slot_a,
380 .setpower = ip7145dpf_mmc_spi_setpower_slot_a,
381 .powerup_msecs = 500,
385 .caps = MMC_CAP_NEEDS_POLL,
388 static struct ubicom32_spi_gpio_controller_data ip7145dpf_mmc_controller_data = {
392 static struct spi_board_info ip7145dpf_spi_board_info[] = {
394 .modalias = "mmc_spi",
397 .max_speed_hz = 2000000,
398 .platform_data = &ip7145dpf_mmc_platform_data,
399 .controller_data = &ip7145dpf_mmc_controller_data,
402 #endif /* IP7145DPF_USE_MMC_SPI */
405 * ip7145dpf_u72_setup
406 * Called by I2C to tell us that u72 is setup.
408 * This function is called by I2C to tell us that u72 has been setup. All
409 * devices which rely on this chip being initialized (or even present) need to
410 * be initialized in this function otherwise they may get initialized too early.
412 * Currently the only device depending on u72 is the SPI
414 static int __init ip7145dpf_u72_setup(struct i2c_client *client, unsigned gpio, unsigned ngpio, void *context)
416 #ifdef IP7145DPF_USE_MMC_SPI
417 if (ip7145dpf_mmc_spi_init_slot_a()) {
418 printk(KERN_ERR "%s: could not request mmc resources\n", __FUNCTION__);
420 printk(KERN_INFO "%s: registering SPI resources\n", __FUNCTION__);
421 spi_register_board_info(ip7145dpf_spi_board_info, ARRAY_SIZE(ip7145dpf_spi_board_info));
422 platform_device_register(&ip7145dpf_spi_gpio_device);
426 * Initialize the Port F/Port B SD slots
428 ip7145dpf_portf_sd_init();
429 ip7145dpf_portb_sd_init();
434 /******************************************************************************
435 * LCD VGH on the board at PE6
437 static struct ubicom32lcdpower_platform_data ip7145dpf_lcdpower_data = {
438 .vgh_gpio = GPIO_RE_6,
439 .vgh_polarity = true,
442 static struct platform_device ip7145dpf_lcdpower_device = {
443 .name = "ubicom32lcdpower",
446 .platform_data = &ip7145dpf_lcdpower_data,
450 /******************************************************************************
451 * Backlight on the board PD0, hardware PWM
453 static struct ubicom32bl_platform_data ip7145dpf_backlight_data = {
454 .type = UBICOM32BL_TYPE_PWM,
458 .default_intensity = 0x80,
461 static struct platform_device ip7145dpf_backlight_device = {
462 .name = "ubicom32bl",
465 .platform_data = &ip7145dpf_backlight_data,
469 /******************************************************************************
470 * Ubicom32Input on I2C, U48 MAX7310, address 0x18, 8 bits
472 static struct ubicom32input_i2c_button ip7145dpf_ubicom32input_i2c_u48_buttons[] = {
517 static struct ubicom32input_i2c_platform_data ip7145dpf_ubicom32input_i2c_u48_platform_data = {
518 .buttons = ip7145dpf_ubicom32input_i2c_u48_buttons,
519 .nbuttons = ARRAY_SIZE(ip7145dpf_ubicom32input_i2c_u48_buttons),
520 .name = "Ubicom32 Input I2C U48",
523 /******************************************************************************
524 * Additional GPIO chips
526 static struct pca953x_platform_data ip7145dpf_gpio_u72_platform_data = {
527 .gpio_base = IP7145DPF_U72_BASE,
528 .setup = ip7145dpf_u72_setup,
531 /******************************************************************************
532 * Devices on the I2C bus
534 static struct i2c_board_info __initdata ip7145dpf_i2c_board_info[] = {
536 * U51, S35390A RTC, address 0x30
544 * U48, MAX7310 IO expander, 8 bits, address 0x18
547 .type = "ubicom32in_max7310",
549 .platform_data = &ip7145dpf_ubicom32input_i2c_u48_platform_data,
553 * U72, MAX7310 IOB expander, 8 bits, address 0x19
558 .platform_data = &ip7145dpf_gpio_u72_platform_data,
563 * I2C bus on the board, SDA PE1, SCL PE2
565 static struct i2c_gpio_platform_data ip7145dpf_i2c_data = {
566 .sda_pin = GPIO_RE_1,
567 .scl_pin = GPIO_RE_2,
568 .sda_is_open_drain = 0,
569 .scl_is_open_drain = 0,
572 static struct platform_device ip7145dpf_i2c_device = {
576 .platform_data = &ip7145dpf_i2c_data,
580 /******************************************************************************
581 * Use ubicom32input driver to monitor the various pushbuttons on this board.
587 * Not sutable for the keypad buttons since those run on I2C GPIO. The polling
588 * of ubicom32input would seem to be excessive for this.
590 * TODO: pick some ubicom understood EV_xxx define for WPS and Fact Default
592 static struct ubicom32input_button ip7145dpf_ubicom32input_buttons[] = {
604 .desc = "Factory Default",
616 static struct ubicom32input_platform_data ip7145dpf_ubicom32input_data = {
617 .buttons = ip7145dpf_ubicom32input_buttons,
618 .nbuttons = ARRAY_SIZE(ip7145dpf_ubicom32input_buttons),
621 static struct platform_device ip7145dpf_ubicom32input_device = {
622 .name = "ubicom32input",
625 .platform_data = &ip7145dpf_ubicom32input_data,
630 * List of all devices in our system
632 static struct platform_device *ip7145dpf_devices[] __initdata = {
633 &ip7145dpf_i2c_device,
634 &ip7145dpf_lcdpower_device,
635 &ip7145dpf_backlight_device,
636 &ip7145dpf_ubicom32input_device,
640 * ip7145dpf_power_off
641 * Called to turn the power off for this board
643 static void ip7145dpf_power_off(void)
645 gpio_set_value(GPIO_RE_5, 0);
650 * Called to add the devices which we have on this board
652 static int __init ip7145dpf_init(void)
655 struct platform_device *audio_dev;
659 #ifdef CONFIG_UIO_UBICOM32RING
660 ring_tio_init("decoder_ring");
664 * Start up the video driver first
669 * Take over holding of the power from the system
671 ret = gpio_request(GPIO_RE_5, "power_hold");
673 printk(KERN_ERR "%s: could not request power hold GPIO\n", __FUNCTION__);
675 gpio_direction_output(GPIO_RE_5, 1);
676 mach_power_off = ip7145dpf_power_off;
679 * USB SEL_HOST_USB line
681 ret = gpio_request(GPIO_RF_11, "SEL_HOST_USB");
683 printk(KERN_ERR "%s: could not request SEL_HOST_USB GPIO\n", __FUNCTION__);
685 gpio_direction_output(GPIO_RF_11, 0);
690 audio_dev = audio_device_alloc("snd-ubi32-generic", "audio", "audio-i2sout", 0);
692 platform_device_register(audio_dev);
696 * Register all of the devices we have on this board
698 printk(KERN_INFO "%s: registering device resources\n", __FUNCTION__);
699 platform_add_devices(ip7145dpf_devices, ARRAY_SIZE(ip7145dpf_devices));
702 * Register all of the devices which sit on the I2C bus
704 printk(KERN_INFO "%s: registering i2c resources\n", __FUNCTION__);
705 i2c_register_board_info(0, ip7145dpf_i2c_board_info, ARRAY_SIZE(ip7145dpf_i2c_board_info));
708 * We have to initialize the SPI after the I2C IOB gets setup. SPI is initialized in
709 * ip7145dpf_u72_setup
715 arch_initcall(ip7145dpf_init);