Linux 5.6.13
[linux/fpc-iii.git] / arch / arm / mach-davinci / board-mityomapl138.c
blobdfce421c0579782e963431b5947c541887f12a56
1 /*
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.
9 */
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>
28 #include <asm/io.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>
36 #include <mach/mux.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 {
46 u32 magic;
47 u32 version;
48 u8 mac[6];
49 u32 fpga_type;
50 u32 spare;
51 u32 serialnumber;
52 char partnum[32];
55 static struct factory_config factory_config;
57 #ifdef CONFIG_CPU_FREQ
58 struct part_no_info {
59 const char *part_no; /* part number string of interest */
60 int max_freq; /* khz */
63 static struct part_no_info mityomapl138_pn_info[] = {
65 .part_no = "L138-C",
66 .max_freq = 300000,
69 .part_no = "L138-D",
70 .max_freq = 375000,
73 .part_no = "L138-F",
74 .max_freq = 456000,
77 .part_no = "1808-C",
78 .max_freq = 300000,
81 .part_no = "1808-D",
82 .max_freq = 375000,
85 .part_no = "1808-F",
86 .max_freq = 456000,
89 .part_no = "1810-D",
90 .max_freq = 375000,
94 static void mityomapl138_cpufreq_init(const char *partnum)
96 int i, ret;
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
104 * for a match.
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;
109 break;
113 ret = da850_register_cpufreq("pll0_sysclk3");
114 if (ret)
115 pr_warn("cpufreq registration failed: %d\n", ret);
117 #else
118 static void mityomapl138_cpufreq_init(const char *partnum) { }
119 #endif
121 static int read_factory_config(struct notifier_block *nb,
122 unsigned long event, void *data)
124 int ret;
125 const char *partnum = NULL;
126 struct nvmem_device *nvmem = data;
128 if (strcmp(nvmem_dev_name(nvmem), "1-00500") != 0)
129 return NOTIFY_DONE;
131 if (!IS_BUILTIN(CONFIG_NVMEM)) {
132 pr_warn("Factory Config not available without CONFIG_NVMEM\n");
133 goto bad_config;
136 ret = nvmem_device_read(nvmem, 0, sizeof(factory_config),
137 &factory_config);
138 if (ret != sizeof(struct factory_config)) {
139 pr_warn("Read Factory Config Failed: %d\n", ret);
140 goto bad_config;
143 if (factory_config.magic != FACTORY_CONFIG_MAGIC) {
144 pr_warn("Factory Config Magic Wrong (%X)\n",
145 factory_config.magic);
146 goto bad_config;
149 if (factory_config.version != FACTORY_CONFIG_VERSION) {
150 pr_warn("Factory Config Version Wrong (%X)\n",
151 factory_config.version);
152 goto bad_config;
155 partnum = factory_config.partnum;
156 pr_info("Part Number = %s\n", partnum);
158 bad_config:
159 /* default maximum speed is valid for all platforms */
160 mityomapl138_cpufreq_init(partnum);
162 return NOTIFY_STOP;
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[] = {
175 .name = "macaddr",
176 .offset = 0x64,
177 .bytes = ETH_ALEN,
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 */
206 /* 1.2V Core */
207 static struct regulator_consumer_supply tps65023_dcdc1_consumers[] = {
209 .supply = "cvdd",
213 /* 1.8V */
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",
229 /* 1.2V */
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[] = {
255 .supply = "vccaux",
259 static struct regulator_init_data tps65023_regulator_data[] = {
260 /* dcdc1 */
262 .constraints = {
263 .min_uV = 1150000,
264 .max_uV = 1350000,
265 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
266 REGULATOR_CHANGE_STATUS,
267 .boot_on = 1,
269 .num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc1_consumers),
270 .consumer_supplies = tps65023_dcdc1_consumers,
272 /* dcdc2 */
274 .constraints = {
275 .min_uV = 1800000,
276 .max_uV = 1800000,
277 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
278 .boot_on = 1,
280 .num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc2_consumers),
281 .consumer_supplies = tps65023_dcdc2_consumers,
283 /* dcdc3 */
285 .constraints = {
286 .min_uV = 1200000,
287 .max_uV = 1200000,
288 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
289 .boot_on = 1,
291 .num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc3_consumers),
292 .consumer_supplies = tps65023_dcdc3_consumers,
294 /* ldo1 */
296 .constraints = {
297 .min_uV = 1800000,
298 .max_uV = 1800000,
299 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
300 .boot_on = 1,
302 .num_consumer_supplies = ARRAY_SIZE(tps65023_ldo1_consumers),
303 .consumer_supplies = tps65023_ldo1_consumers,
305 /* ldo2 */
307 .constraints = {
308 .min_uV = 2500000,
309 .max_uV = 3300000,
310 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
311 REGULATOR_CHANGE_STATUS,
312 .boot_on = 1,
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));
337 * SPI Devices:
338 * SPI1_CS0: 8M Flash ST-M25P64-VME6G
340 static struct mtd_partition spi_flash_partitions[] = {
341 [0] = {
342 .name = "ubl",
343 .offset = 0,
344 .size = SZ_64K,
345 .mask_flags = MTD_WRITEABLE,
347 [1] = {
348 .name = "u-boot",
349 .offset = MTDPART_OFS_APPEND,
350 .size = SZ_512K,
351 .mask_flags = MTD_WRITEABLE,
353 [2] = {
354 .name = "u-boot-env",
355 .offset = MTDPART_OFS_APPEND,
356 .size = SZ_64K,
357 .mask_flags = MTD_WRITEABLE,
359 [3] = {
360 .name = "periph-config",
361 .offset = MTDPART_OFS_APPEND,
362 .size = SZ_64K,
363 .mask_flags = MTD_WRITEABLE,
365 [4] = {
366 .name = "reserved",
367 .offset = MTDPART_OFS_APPEND,
368 .size = SZ_256K + SZ_64K,
370 [5] = {
371 .name = "kernel",
372 .offset = MTDPART_OFS_APPEND,
373 .size = SZ_2M + SZ_1M,
375 [6] = {
376 .name = "fpga",
377 .offset = MTDPART_OFS_APPEND,
378 .size = SZ_2M,
380 [7] = {
381 .name = "spare",
382 .offset = MTDPART_OFS_APPEND,
383 .size = MTDPART_SIZ_FULL,
387 static struct flash_platform_data mityomapl138_spi_flash_data = {
388 .name = "m25p80",
389 .parts = spi_flash_partitions,
390 .nr_parts = ARRAY_SIZE(spi_flash_partitions),
391 .type = "m24p64",
394 static struct davinci_spi_config spi_eprom_config = {
395 .io_type = SPI_IO_TYPE_DMA,
396 .c2tdelay = 8,
397 .t2cdelay = 8,
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,
405 .mode = SPI_MODE_0,
406 .max_speed_hz = 30000000,
407 .bus_num = 1,
408 .chip_select = 0,
413 * MityDSP-L138 includes a 256 MByte large-page NAND flash
414 * (128K blocks).
416 static struct mtd_partition mityomapl138_nandflash_partition[] = {
418 .name = "rootfs",
419 .offset = 0,
420 .size = SZ_128M,
421 .mask_flags = 0, /* MTD_WRITEABLE, */
424 .name = "homefs",
425 .offset = MTDPART_OFS_APPEND,
426 .size = MTDPART_SIZ_FULL,
427 .mask_flags = 0,
431 static struct davinci_nand_pdata mityomapl138_nandflash_data = {
432 .core_chipsel = 1,
433 .parts = mityomapl138_nandflash_partition,
434 .nr_parts = ARRAY_SIZE(mityomapl138_nandflash_partition),
435 .ecc_mode = NAND_ECC_HW,
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",
457 .id = 1,
458 .dev = {
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[] = {
476 .cs = 1,
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 = {
488 .name = "ti-aemif",
489 .id = -1,
490 .dev = {
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,
508 DA850_MDIO_D,
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,
516 DA850_MDIO_D,
520 static void __init mityomapl138_config_emac(void)
522 void __iomem *cfg_chip3_base;
523 int ret;
524 u32 val;
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) {
533 val |= BIT(8);
534 ret = davinci_cfg_reg_list(mityomap_rmii_pins);
535 pr_info("RMII PHY configured\n");
536 } else {
537 val &= ~BIT(8);
538 ret = davinci_cfg_reg_list(mityomap_mii_pins);
539 pr_info("MII PHY configured\n");
542 if (ret) {
543 pr_warn("mii/rmii mux setup failed: %d\n", ret);
544 return;
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();
553 if (ret)
554 pr_warn("emac registration failed: %d\n", ret);
557 static void __init mityomapl138_init(void)
559 int ret;
561 da850_register_clocks();
563 /* for now, no special EDMA channels are reserved */
564 ret = da850_register_edma(NULL);
565 if (ret)
566 pr_warn("edma registration failed: %d\n", ret);
568 ret = da8xx_register_watchdog();
569 if (ret)
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);
579 if (ret)
580 pr_warn("i2c0 registration failed: %d\n", ret);
582 ret = pmic_tps65023_init();
583 if (ret)
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));
590 if (ret)
591 pr_warn("spi info registration failed: %d\n", ret);
593 ret = da8xx_register_spi_bus(1,
594 ARRAY_SIZE(mityomapl138_spi_flash_info));
595 if (ret)
596 pr_warn("spi 1 registration failed: %d\n", ret);
598 mityomapl138_config_emac();
600 ret = da8xx_register_rtc();
601 if (ret)
602 pr_warn("rtc setup failed: %d\n", ret);
604 ret = da8xx_register_cpuidle();
605 if (ret)
606 pr_warn("cpuidle registration failed: %d\n", ret);
608 davinci_pm_init();
611 #ifdef CONFIG_SERIAL_8250_CONSOLE
612 static int __init mityomapl138_console_init(void)
614 if (!machine_is_mityomapl138())
615 return 0;
617 return add_preferred_console("ttyS", 1, "115200");
619 console_initcall(mityomapl138_console_init);
620 #endif
622 static void __init mityomapl138_map_io(void)
624 da850_init();
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,
635 MACHINE_END