2 * Critical Link MityOMAP-L138 SoM
4 * Copyright (C) 2010 Critical Link LLC - https://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 #define pr_fmt(fmt) "MityOMAPL138: " fmt
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/console.h>
16 #include <linux/platform_device.h>
17 #include <linux/property.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/notifier.h>
20 #include <linux/nvmem-consumer.h>
21 #include <linux/nvmem-provider.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/i2c.h>
24 #include <linux/etherdevice.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/flash.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <mach/common.h>
32 #include <mach/da8xx.h>
33 #include <linux/platform_data/mtd-davinci.h>
34 #include <linux/platform_data/mtd-davinci-aemif.h>
35 #include <linux/platform_data/ti-aemif.h>
37 #include <linux/platform_data/spi-davinci.h>
39 #define MITYOMAPL138_PHY_ID ""
41 #define FACTORY_CONFIG_MAGIC 0x012C0138
42 #define FACTORY_CONFIG_VERSION 0x00010001
44 /* Data Held in On-Board I2C device */
45 struct factory_config
{
55 static struct factory_config factory_config
;
57 #ifdef CONFIG_CPU_FREQ
59 const char *part_no
; /* part number string of interest */
60 int max_freq
; /* khz */
63 static struct part_no_info mityomapl138_pn_info
[] = {
94 static void mityomapl138_cpufreq_init(const char *partnum
)
98 for (i
= 0; partnum
&& i
< ARRAY_SIZE(mityomapl138_pn_info
); i
++) {
100 * the part number has additional characters beyond what is
101 * stored in the table. This information is not needed for
102 * determining the speed grade, and would require several
103 * more table entries. Only check the first N characters
106 if (!strncmp(partnum
, mityomapl138_pn_info
[i
].part_no
,
107 strlen(mityomapl138_pn_info
[i
].part_no
))) {
108 da850_max_speed
= mityomapl138_pn_info
[i
].max_freq
;
113 ret
= da850_register_cpufreq("pll0_sysclk3");
115 pr_warn("cpufreq registration failed: %d\n", ret
);
118 static void mityomapl138_cpufreq_init(const char *partnum
) { }
121 static int read_factory_config(struct notifier_block
*nb
,
122 unsigned long event
, void *data
)
125 const char *partnum
= NULL
;
126 struct nvmem_device
*nvmem
= data
;
128 if (strcmp(nvmem_dev_name(nvmem
), "1-00500") != 0)
131 if (!IS_BUILTIN(CONFIG_NVMEM
)) {
132 pr_warn("Factory Config not available without CONFIG_NVMEM\n");
136 ret
= nvmem_device_read(nvmem
, 0, sizeof(factory_config
),
138 if (ret
!= sizeof(struct factory_config
)) {
139 pr_warn("Read Factory Config Failed: %d\n", ret
);
143 if (factory_config
.magic
!= FACTORY_CONFIG_MAGIC
) {
144 pr_warn("Factory Config Magic Wrong (%X)\n",
145 factory_config
.magic
);
149 if (factory_config
.version
!= FACTORY_CONFIG_VERSION
) {
150 pr_warn("Factory Config Version Wrong (%X)\n",
151 factory_config
.version
);
155 partnum
= factory_config
.partnum
;
156 pr_info("Part Number = %s\n", partnum
);
159 /* default maximum speed is valid for all platforms */
160 mityomapl138_cpufreq_init(partnum
);
165 static struct notifier_block mityomapl138_nvmem_notifier
= {
166 .notifier_call
= read_factory_config
,
170 * We don't define a cell for factory config as it will be accessed from the
171 * board file using the nvmem notifier chain.
173 static struct nvmem_cell_info mityomapl138_nvmem_cells
[] = {
181 static struct nvmem_cell_table mityomapl138_nvmem_cell_table
= {
182 .nvmem_name
= "1-00500",
183 .cells
= mityomapl138_nvmem_cells
,
184 .ncells
= ARRAY_SIZE(mityomapl138_nvmem_cells
),
187 static struct nvmem_cell_lookup mityomapl138_nvmem_cell_lookup
= {
188 .nvmem_name
= "1-00500",
189 .cell_name
= "macaddr",
190 .dev_id
= "davinci_emac.1",
191 .con_id
= "mac-address",
194 static const struct property_entry mityomapl138_fd_chip_properties
[] = {
195 PROPERTY_ENTRY_U32("pagesize", 8),
196 PROPERTY_ENTRY_BOOL("read-only"),
200 static struct davinci_i2c_platform_data mityomap_i2c_0_pdata
= {
201 .bus_freq
= 100, /* kHz */
202 .bus_delay
= 0, /* usec */
205 /* TPS65023 voltage regulator support */
207 static struct regulator_consumer_supply tps65023_dcdc1_consumers
[] = {
214 static struct regulator_consumer_supply tps65023_dcdc2_consumers
[] = {
216 .supply
= "usb0_vdda18",
219 .supply
= "usb1_vdda18",
222 .supply
= "ddr_dvdd18",
225 .supply
= "sata_vddr",
230 static struct regulator_consumer_supply tps65023_dcdc3_consumers
[] = {
232 .supply
= "sata_vdd",
235 .supply
= "usb_cvdd",
238 .supply
= "pll0_vdda",
241 .supply
= "pll1_vdda",
245 /* 1.8V Aux LDO, not used */
246 static struct regulator_consumer_supply tps65023_ldo1_consumers
[] = {
248 .supply
= "1.8v_aux",
252 /* FPGA VCC Aux (2.5 or 3.3) LDO */
253 static struct regulator_consumer_supply tps65023_ldo2_consumers
[] = {
259 static struct regulator_init_data tps65023_regulator_data
[] = {
265 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
|
266 REGULATOR_CHANGE_STATUS
,
269 .num_consumer_supplies
= ARRAY_SIZE(tps65023_dcdc1_consumers
),
270 .consumer_supplies
= tps65023_dcdc1_consumers
,
277 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
280 .num_consumer_supplies
= ARRAY_SIZE(tps65023_dcdc2_consumers
),
281 .consumer_supplies
= tps65023_dcdc2_consumers
,
288 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
291 .num_consumer_supplies
= ARRAY_SIZE(tps65023_dcdc3_consumers
),
292 .consumer_supplies
= tps65023_dcdc3_consumers
,
299 .valid_ops_mask
= REGULATOR_CHANGE_STATUS
,
302 .num_consumer_supplies
= ARRAY_SIZE(tps65023_ldo1_consumers
),
303 .consumer_supplies
= tps65023_ldo1_consumers
,
310 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
|
311 REGULATOR_CHANGE_STATUS
,
314 .num_consumer_supplies
= ARRAY_SIZE(tps65023_ldo2_consumers
),
315 .consumer_supplies
= tps65023_ldo2_consumers
,
319 static struct i2c_board_info __initdata mityomap_tps65023_info
[] = {
321 I2C_BOARD_INFO("tps65023", 0x48),
322 .platform_data
= &tps65023_regulator_data
[0],
325 I2C_BOARD_INFO("24c02", 0x50),
326 .properties
= mityomapl138_fd_chip_properties
,
330 static int __init
pmic_tps65023_init(void)
332 return i2c_register_board_info(1, mityomap_tps65023_info
,
333 ARRAY_SIZE(mityomap_tps65023_info
));
338 * SPI1_CS0: 8M Flash ST-M25P64-VME6G
340 static struct mtd_partition spi_flash_partitions
[] = {
345 .mask_flags
= MTD_WRITEABLE
,
349 .offset
= MTDPART_OFS_APPEND
,
351 .mask_flags
= MTD_WRITEABLE
,
354 .name
= "u-boot-env",
355 .offset
= MTDPART_OFS_APPEND
,
357 .mask_flags
= MTD_WRITEABLE
,
360 .name
= "periph-config",
361 .offset
= MTDPART_OFS_APPEND
,
363 .mask_flags
= MTD_WRITEABLE
,
367 .offset
= MTDPART_OFS_APPEND
,
368 .size
= SZ_256K
+ SZ_64K
,
372 .offset
= MTDPART_OFS_APPEND
,
373 .size
= SZ_2M
+ SZ_1M
,
377 .offset
= MTDPART_OFS_APPEND
,
382 .offset
= MTDPART_OFS_APPEND
,
383 .size
= MTDPART_SIZ_FULL
,
387 static struct flash_platform_data mityomapl138_spi_flash_data
= {
389 .parts
= spi_flash_partitions
,
390 .nr_parts
= ARRAY_SIZE(spi_flash_partitions
),
394 static struct davinci_spi_config spi_eprom_config
= {
395 .io_type
= SPI_IO_TYPE_DMA
,
400 static struct spi_board_info mityomapl138_spi_flash_info
[] = {
402 .modalias
= "m25p80",
403 .platform_data
= &mityomapl138_spi_flash_data
,
404 .controller_data
= &spi_eprom_config
,
406 .max_speed_hz
= 30000000,
413 * MityDSP-L138 includes a 256 MByte large-page NAND flash
416 static struct mtd_partition mityomapl138_nandflash_partition
[] = {
421 .mask_flags
= 0, /* MTD_WRITEABLE, */
425 .offset
= MTDPART_OFS_APPEND
,
426 .size
= MTDPART_SIZ_FULL
,
431 static struct davinci_nand_pdata mityomapl138_nandflash_data
= {
433 .parts
= mityomapl138_nandflash_partition
,
434 .nr_parts
= ARRAY_SIZE(mityomapl138_nandflash_partition
),
435 .engine_type
= NAND_ECC_ENGINE_TYPE_ON_HOST
,
436 .bbt_options
= NAND_BBT_USE_FLASH
,
437 .options
= NAND_BUSWIDTH_16
,
438 .ecc_bits
= 1, /* 4 bit mode is not supported with 16 bit NAND */
441 static struct resource mityomapl138_nandflash_resource
[] = {
443 .start
= DA8XX_AEMIF_CS3_BASE
,
444 .end
= DA8XX_AEMIF_CS3_BASE
+ SZ_512K
+ 2 * SZ_1K
- 1,
445 .flags
= IORESOURCE_MEM
,
448 .start
= DA8XX_AEMIF_CTL_BASE
,
449 .end
= DA8XX_AEMIF_CTL_BASE
+ SZ_32K
- 1,
450 .flags
= IORESOURCE_MEM
,
454 static struct platform_device mityomapl138_aemif_devices
[] = {
456 .name
= "davinci_nand",
459 .platform_data
= &mityomapl138_nandflash_data
,
461 .num_resources
= ARRAY_SIZE(mityomapl138_nandflash_resource
),
462 .resource
= mityomapl138_nandflash_resource
,
466 static struct resource mityomapl138_aemif_resources
[] = {
468 .start
= DA8XX_AEMIF_CTL_BASE
,
469 .end
= DA8XX_AEMIF_CTL_BASE
+ SZ_32K
- 1,
470 .flags
= IORESOURCE_MEM
,
474 static struct aemif_abus_data mityomapl138_aemif_abus_data
[] = {
480 static struct aemif_platform_data mityomapl138_aemif_pdata
= {
481 .abus_data
= mityomapl138_aemif_abus_data
,
482 .num_abus_data
= ARRAY_SIZE(mityomapl138_aemif_abus_data
),
483 .sub_devices
= mityomapl138_aemif_devices
,
484 .num_sub_devices
= ARRAY_SIZE(mityomapl138_aemif_devices
),
487 static struct platform_device mityomapl138_aemif_device
= {
491 .platform_data
= &mityomapl138_aemif_pdata
,
493 .resource
= mityomapl138_aemif_resources
,
494 .num_resources
= ARRAY_SIZE(mityomapl138_aemif_resources
),
497 static void __init
mityomapl138_setup_nand(void)
499 if (platform_device_register(&mityomapl138_aemif_device
))
500 pr_warn("%s: Cannot register AEMIF device\n", __func__
);
503 static const short mityomap_mii_pins
[] = {
504 DA850_MII_TXEN
, DA850_MII_TXCLK
, DA850_MII_COL
, DA850_MII_TXD_3
,
505 DA850_MII_TXD_2
, DA850_MII_TXD_1
, DA850_MII_TXD_0
, DA850_MII_RXER
,
506 DA850_MII_CRS
, DA850_MII_RXCLK
, DA850_MII_RXDV
, DA850_MII_RXD_3
,
507 DA850_MII_RXD_2
, DA850_MII_RXD_1
, DA850_MII_RXD_0
, DA850_MDIO_CLK
,
512 static const short mityomap_rmii_pins
[] = {
513 DA850_RMII_TXD_0
, DA850_RMII_TXD_1
, DA850_RMII_TXEN
,
514 DA850_RMII_CRS_DV
, DA850_RMII_RXD_0
, DA850_RMII_RXD_1
,
515 DA850_RMII_RXER
, DA850_RMII_MHZ_50_CLK
, DA850_MDIO_CLK
,
520 static void __init
mityomapl138_config_emac(void)
522 void __iomem
*cfg_chip3_base
;
525 struct davinci_soc_info
*soc_info
= &davinci_soc_info
;
527 soc_info
->emac_pdata
->rmii_en
= 0; /* hardcoded for now */
529 cfg_chip3_base
= DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG
);
530 val
= __raw_readl(cfg_chip3_base
);
532 if (soc_info
->emac_pdata
->rmii_en
) {
534 ret
= davinci_cfg_reg_list(mityomap_rmii_pins
);
535 pr_info("RMII PHY configured\n");
538 ret
= davinci_cfg_reg_list(mityomap_mii_pins
);
539 pr_info("MII PHY configured\n");
543 pr_warn("mii/rmii mux setup failed: %d\n", ret
);
547 /* configure the CFGCHIP3 register for RMII or MII */
548 __raw_writel(val
, cfg_chip3_base
);
550 soc_info
->emac_pdata
->phy_id
= MITYOMAPL138_PHY_ID
;
552 ret
= da8xx_register_emac();
554 pr_warn("emac registration failed: %d\n", ret
);
557 static void __init
mityomapl138_init(void)
561 da850_register_clocks();
563 /* for now, no special EDMA channels are reserved */
564 ret
= da850_register_edma(NULL
);
566 pr_warn("edma registration failed: %d\n", ret
);
568 ret
= da8xx_register_watchdog();
570 pr_warn("watchdog registration failed: %d\n", ret
);
572 davinci_serial_init(da8xx_serial_device
);
574 nvmem_register_notifier(&mityomapl138_nvmem_notifier
);
575 nvmem_add_cell_table(&mityomapl138_nvmem_cell_table
);
576 nvmem_add_cell_lookups(&mityomapl138_nvmem_cell_lookup
, 1);
578 ret
= da8xx_register_i2c(0, &mityomap_i2c_0_pdata
);
580 pr_warn("i2c0 registration failed: %d\n", ret
);
582 ret
= pmic_tps65023_init();
584 pr_warn("TPS65023 PMIC init failed: %d\n", ret
);
586 mityomapl138_setup_nand();
588 ret
= spi_register_board_info(mityomapl138_spi_flash_info
,
589 ARRAY_SIZE(mityomapl138_spi_flash_info
));
591 pr_warn("spi info registration failed: %d\n", ret
);
593 ret
= da8xx_register_spi_bus(1,
594 ARRAY_SIZE(mityomapl138_spi_flash_info
));
596 pr_warn("spi 1 registration failed: %d\n", ret
);
598 mityomapl138_config_emac();
600 ret
= da8xx_register_rtc();
602 pr_warn("rtc setup failed: %d\n", ret
);
604 ret
= da8xx_register_cpuidle();
606 pr_warn("cpuidle registration failed: %d\n", ret
);
611 #ifdef CONFIG_SERIAL_8250_CONSOLE
612 static int __init
mityomapl138_console_init(void)
614 if (!machine_is_mityomapl138())
617 return add_preferred_console("ttyS", 1, "115200");
619 console_initcall(mityomapl138_console_init
);
622 static void __init
mityomapl138_map_io(void)
627 MACHINE_START(MITYOMAPL138
, "MityDSP-L138/MityARM-1808")
628 .atag_offset
= 0x100,
629 .map_io
= mityomapl138_map_io
,
630 .init_irq
= da850_init_irq
,
631 .init_time
= da850_init_time
,
632 .init_machine
= mityomapl138_init
,
633 .init_late
= davinci_init_late
,
634 .dma_zone_size
= SZ_128M
,