2 * Critical Link MityOMAP-L138 SoM
4 * Copyright (C) 2010 Critical Link LLC - http://www.criticallink.com
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of
8 * any kind, whether express or implied.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/console.h>
14 #include <linux/platform_device.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/regulator/machine.h>
17 #include <linux/i2c.h>
18 #include <linux/platform_data/at24.h>
19 #include <linux/etherdevice.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/flash.h>
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26 #include <mach/common.h>
27 #include <mach/cp_intc.h>
28 #include <mach/da8xx.h>
29 #include <linux/platform_data/mtd-davinci.h>
30 #include <linux/platform_data/mtd-davinci-aemif.h>
32 #include <linux/platform_data/spi-davinci.h>
34 #define MITYOMAPL138_PHY_ID ""
36 #define FACTORY_CONFIG_MAGIC 0x012C0138
37 #define FACTORY_CONFIG_VERSION 0x00010001
39 /* Data Held in On-Board I2C device */
40 struct factory_config
{
50 static struct factory_config factory_config
;
53 const char *part_no
; /* part number string of interest */
54 int max_freq
; /* khz */
57 static struct part_no_info mityomapl138_pn_info
[] = {
88 #ifdef CONFIG_CPU_FREQ
89 static void mityomapl138_cpufreq_init(const char *partnum
)
93 for (i
= 0; partnum
&& i
< ARRAY_SIZE(mityomapl138_pn_info
); i
++) {
95 * the part number has additional characters beyond what is
96 * stored in the table. This information is not needed for
97 * determining the speed grade, and would require several
98 * more table entries. Only check the first N characters
101 if (!strncmp(partnum
, mityomapl138_pn_info
[i
].part_no
,
102 strlen(mityomapl138_pn_info
[i
].part_no
))) {
103 da850_max_speed
= mityomapl138_pn_info
[i
].max_freq
;
108 ret
= da850_register_cpufreq("pll0_sysclk3");
110 pr_warning("cpufreq registration failed: %d\n", ret
);
113 static void mityomapl138_cpufreq_init(const char *partnum
) { }
116 static void read_factory_config(struct memory_accessor
*a
, void *context
)
119 const char *partnum
= NULL
;
120 struct davinci_soc_info
*soc_info
= &davinci_soc_info
;
122 ret
= a
->read(a
, (char *)&factory_config
, 0, sizeof(factory_config
));
123 if (ret
!= sizeof(struct factory_config
)) {
124 pr_warning("MityOMAPL138: Read Factory Config Failed: %d\n",
129 if (factory_config
.magic
!= FACTORY_CONFIG_MAGIC
) {
130 pr_warning("MityOMAPL138: Factory Config Magic Wrong (%X)\n",
131 factory_config
.magic
);
135 if (factory_config
.version
!= FACTORY_CONFIG_VERSION
) {
136 pr_warning("MityOMAPL138: Factory Config Version Wrong (%X)\n",
137 factory_config
.version
);
141 pr_info("MityOMAPL138: Found MAC = %pM\n", factory_config
.mac
);
142 if (is_valid_ether_addr(factory_config
.mac
))
143 memcpy(soc_info
->emac_pdata
->mac_addr
,
144 factory_config
.mac
, ETH_ALEN
);
146 pr_warning("MityOMAPL138: Invalid MAC found "
147 "in factory config block\n");
149 partnum
= factory_config
.partnum
;
150 pr_info("MityOMAPL138: Part Number = %s\n", partnum
);
153 /* default maximum speed is valid for all platforms */
154 mityomapl138_cpufreq_init(partnum
);
157 static struct at24_platform_data mityomapl138_fd_chip
= {
160 .flags
= AT24_FLAG_READONLY
| AT24_FLAG_IRUGO
,
161 .setup
= read_factory_config
,
165 static struct davinci_i2c_platform_data mityomap_i2c_0_pdata
= {
166 .bus_freq
= 100, /* kHz */
167 .bus_delay
= 0, /* usec */
170 /* TPS65023 voltage regulator support */
172 static struct regulator_consumer_supply tps65023_dcdc1_consumers
[] = {
179 static struct regulator_consumer_supply tps65023_dcdc2_consumers
[] = {
181 .supply
= "usb0_vdda18",
184 .supply
= "usb1_vdda18",
187 .supply
= "ddr_dvdd18",
190 .supply
= "sata_vddr",
195 static struct regulator_consumer_supply tps65023_dcdc3_consumers
[] = {
197 .supply
= "sata_vdd",
200 .supply
= "usb_cvdd",
203 .supply
= "pll0_vdda",
206 .supply
= "pll1_vdda",
210 /* 1.8V Aux LDO, not used */
211 static struct regulator_consumer_supply tps65023_ldo1_consumers
[] = {
213 .supply
= "1.8v_aux",
217 /* FPGA VCC Aux (2.5 or 3.3) LDO */
218 static struct regulator_consumer_supply tps65023_ldo2_consumers
[] = {
224 static struct regulator_init_data tps65023_regulator_data
[] = {
230 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
|
231 REGULATOR_CHANGE_STATUS
,
234 .num_consumer_supplies
= ARRAY_SIZE(tps65023_dcdc1_consumers
),
235 .consumer_supplies
= tps65023_dcdc1_consumers
,
242 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
245 .num_consumer_supplies
= ARRAY_SIZE(tps65023_dcdc2_consumers
),
246 .consumer_supplies
= tps65023_dcdc2_consumers
,
253 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
256 .num_consumer_supplies
= ARRAY_SIZE(tps65023_dcdc3_consumers
),
257 .consumer_supplies
= tps65023_dcdc3_consumers
,
264 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
267 .num_consumer_supplies
= ARRAY_SIZE(tps65023_ldo1_consumers
),
268 .consumer_supplies
= tps65023_ldo1_consumers
,
275 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
|
276 REGULATOR_CHANGE_STATUS
,
279 .num_consumer_supplies
= ARRAY_SIZE(tps65023_ldo2_consumers
),
280 .consumer_supplies
= tps65023_ldo2_consumers
,
284 static struct i2c_board_info __initdata mityomap_tps65023_info
[] = {
286 I2C_BOARD_INFO("tps65023", 0x48),
287 .platform_data
= &tps65023_regulator_data
[0],
290 I2C_BOARD_INFO("24c02", 0x50),
291 .platform_data
= &mityomapl138_fd_chip
,
295 static int __init
pmic_tps65023_init(void)
297 return i2c_register_board_info(1, mityomap_tps65023_info
,
298 ARRAY_SIZE(mityomap_tps65023_info
));
303 * SPI1_CS0: 8M Flash ST-M25P64-VME6G
305 static struct mtd_partition spi_flash_partitions
[] = {
310 .mask_flags
= MTD_WRITEABLE
,
314 .offset
= MTDPART_OFS_APPEND
,
316 .mask_flags
= MTD_WRITEABLE
,
319 .name
= "u-boot-env",
320 .offset
= MTDPART_OFS_APPEND
,
322 .mask_flags
= MTD_WRITEABLE
,
325 .name
= "periph-config",
326 .offset
= MTDPART_OFS_APPEND
,
328 .mask_flags
= MTD_WRITEABLE
,
332 .offset
= MTDPART_OFS_APPEND
,
333 .size
= SZ_256K
+ SZ_64K
,
337 .offset
= MTDPART_OFS_APPEND
,
338 .size
= SZ_2M
+ SZ_1M
,
342 .offset
= MTDPART_OFS_APPEND
,
347 .offset
= MTDPART_OFS_APPEND
,
348 .size
= MTDPART_SIZ_FULL
,
352 static struct flash_platform_data mityomapl138_spi_flash_data
= {
354 .parts
= spi_flash_partitions
,
355 .nr_parts
= ARRAY_SIZE(spi_flash_partitions
),
359 static struct davinci_spi_config spi_eprom_config
= {
360 .io_type
= SPI_IO_TYPE_DMA
,
365 static struct spi_board_info mityomapl138_spi_flash_info
[] = {
367 .modalias
= "m25p80",
368 .platform_data
= &mityomapl138_spi_flash_data
,
369 .controller_data
= &spi_eprom_config
,
371 .max_speed_hz
= 30000000,
378 * MityDSP-L138 includes a 256 MByte large-page NAND flash
381 static struct mtd_partition mityomapl138_nandflash_partition
[] = {
386 .mask_flags
= 0, /* MTD_WRITEABLE, */
390 .offset
= MTDPART_OFS_APPEND
,
391 .size
= MTDPART_SIZ_FULL
,
396 static struct davinci_nand_pdata mityomapl138_nandflash_data
= {
397 .parts
= mityomapl138_nandflash_partition
,
398 .nr_parts
= ARRAY_SIZE(mityomapl138_nandflash_partition
),
399 .ecc_mode
= NAND_ECC_HW
,
400 .bbt_options
= NAND_BBT_USE_FLASH
,
401 .options
= NAND_BUSWIDTH_16
,
402 .ecc_bits
= 1, /* 4 bit mode is not supported with 16 bit NAND */
405 static struct resource mityomapl138_nandflash_resource
[] = {
407 .start
= DA8XX_AEMIF_CS3_BASE
,
408 .end
= DA8XX_AEMIF_CS3_BASE
+ SZ_512K
+ 2 * SZ_1K
- 1,
409 .flags
= IORESOURCE_MEM
,
412 .start
= DA8XX_AEMIF_CTL_BASE
,
413 .end
= DA8XX_AEMIF_CTL_BASE
+ SZ_32K
- 1,
414 .flags
= IORESOURCE_MEM
,
418 static struct platform_device mityomapl138_nandflash_device
= {
419 .name
= "davinci_nand",
422 .platform_data
= &mityomapl138_nandflash_data
,
424 .num_resources
= ARRAY_SIZE(mityomapl138_nandflash_resource
),
425 .resource
= mityomapl138_nandflash_resource
,
428 static struct platform_device
*mityomapl138_devices
[] __initdata
= {
429 &mityomapl138_nandflash_device
,
432 static void __init
mityomapl138_setup_nand(void)
434 platform_add_devices(mityomapl138_devices
,
435 ARRAY_SIZE(mityomapl138_devices
));
437 if (davinci_aemif_setup(&mityomapl138_nandflash_device
))
438 pr_warn("%s: Cannot configure AEMIF.\n", __func__
);
441 static const short mityomap_mii_pins
[] = {
442 DA850_MII_TXEN
, DA850_MII_TXCLK
, DA850_MII_COL
, DA850_MII_TXD_3
,
443 DA850_MII_TXD_2
, DA850_MII_TXD_1
, DA850_MII_TXD_0
, DA850_MII_RXER
,
444 DA850_MII_CRS
, DA850_MII_RXCLK
, DA850_MII_RXDV
, DA850_MII_RXD_3
,
445 DA850_MII_RXD_2
, DA850_MII_RXD_1
, DA850_MII_RXD_0
, DA850_MDIO_CLK
,
450 static const short mityomap_rmii_pins
[] = {
451 DA850_RMII_TXD_0
, DA850_RMII_TXD_1
, DA850_RMII_TXEN
,
452 DA850_RMII_CRS_DV
, DA850_RMII_RXD_0
, DA850_RMII_RXD_1
,
453 DA850_RMII_RXER
, DA850_RMII_MHZ_50_CLK
, DA850_MDIO_CLK
,
458 static void __init
mityomapl138_config_emac(void)
460 void __iomem
*cfg_chip3_base
;
463 struct davinci_soc_info
*soc_info
= &davinci_soc_info
;
465 soc_info
->emac_pdata
->rmii_en
= 0; /* hardcoded for now */
467 cfg_chip3_base
= DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG
);
468 val
= __raw_readl(cfg_chip3_base
);
470 if (soc_info
->emac_pdata
->rmii_en
) {
472 ret
= davinci_cfg_reg_list(mityomap_rmii_pins
);
473 pr_info("RMII PHY configured\n");
476 ret
= davinci_cfg_reg_list(mityomap_mii_pins
);
477 pr_info("MII PHY configured\n");
481 pr_warning("mii/rmii mux setup failed: %d\n", ret
);
485 /* configure the CFGCHIP3 register for RMII or MII */
486 __raw_writel(val
, cfg_chip3_base
);
488 soc_info
->emac_pdata
->phy_id
= MITYOMAPL138_PHY_ID
;
490 ret
= da8xx_register_emac();
492 pr_warning("emac registration failed: %d\n", ret
);
495 static struct davinci_pm_config da850_pm_pdata
= {
499 static struct platform_device da850_pm_device
= {
500 .name
= "pm-davinci",
502 .platform_data
= &da850_pm_pdata
,
507 static void __init
mityomapl138_init(void)
511 /* for now, no special EDMA channels are reserved */
512 ret
= da850_register_edma(NULL
);
514 pr_warning("edma registration failed: %d\n", ret
);
516 ret
= da8xx_register_watchdog();
518 pr_warning("watchdog registration failed: %d\n", ret
);
520 davinci_serial_init(da8xx_serial_device
);
522 ret
= da8xx_register_i2c(0, &mityomap_i2c_0_pdata
);
524 pr_warning("i2c0 registration failed: %d\n", ret
);
526 ret
= pmic_tps65023_init();
528 pr_warning("TPS65023 PMIC init failed: %d\n", ret
);
530 mityomapl138_setup_nand();
532 ret
= spi_register_board_info(mityomapl138_spi_flash_info
,
533 ARRAY_SIZE(mityomapl138_spi_flash_info
));
535 pr_warn("spi info registration failed: %d\n", ret
);
537 ret
= da8xx_register_spi_bus(1,
538 ARRAY_SIZE(mityomapl138_spi_flash_info
));
540 pr_warning("spi 1 registration failed: %d\n", ret
);
542 mityomapl138_config_emac();
544 ret
= da8xx_register_rtc();
546 pr_warning("rtc setup failed: %d\n", ret
);
548 ret
= da8xx_register_cpuidle();
550 pr_warning("cpuidle registration failed: %d\n", ret
);
552 ret
= da850_register_pm(&da850_pm_device
);
554 pr_warning("da850_evm_init: suspend registration failed: %d\n",
558 #ifdef CONFIG_SERIAL_8250_CONSOLE
559 static int __init
mityomapl138_console_init(void)
561 if (!machine_is_mityomapl138())
564 return add_preferred_console("ttyS", 1, "115200");
566 console_initcall(mityomapl138_console_init
);
569 static void __init
mityomapl138_map_io(void)
574 MACHINE_START(MITYOMAPL138
, "MityDSP-L138/MityARM-1808")
575 .atag_offset
= 0x100,
576 .map_io
= mityomapl138_map_io
,
577 .init_irq
= cp_intc_init
,
578 .init_time
= davinci_timer_init
,
579 .init_machine
= mityomapl138_init
,
580 .init_late
= davinci_init_late
,
581 .dma_zone_size
= SZ_128M
,
582 .restart
= da8xx_restart
,