GNU Linux-libre 5.15.137-gnu
[releases.git] / arch / arm / mach-davinci / board-omapl138-hawk.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Hawkboard.org based on TI's OMAP-L138 Platform
4  *
5  * Initial code: Syed Mohammed Khasim
6  *
7  * Copyright (C) 2009 Texas Instruments Incorporated - https://www.ti.com
8  */
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/console.h>
12 #include <linux/interrupt.h>
13 #include <linux/gpio.h>
14 #include <linux/gpio/machine.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/mtd/rawnand.h>
17 #include <linux/platform_data/gpio-davinci.h>
18 #include <linux/platform_data/mtd-davinci.h>
19 #include <linux/platform_data/mtd-davinci-aemif.h>
20 #include <linux/platform_data/ti-aemif.h>
21 #include <linux/regulator/fixed.h>
22 #include <linux/regulator/machine.h>
23
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26
27 #include <mach/common.h>
28 #include <mach/da8xx.h>
29 #include <mach/mux.h>
30
31 #define HAWKBOARD_PHY_ID                "davinci_mdio-0:07"
32
33 #define DA850_USB1_VBUS_PIN             GPIO_TO_PIN(2, 4)
34 #define DA850_USB1_OC_PIN               GPIO_TO_PIN(6, 13)
35
36 static short omapl138_hawk_mii_pins[] __initdata = {
37         DA850_MII_TXEN, DA850_MII_TXCLK, DA850_MII_COL, DA850_MII_TXD_3,
38         DA850_MII_TXD_2, DA850_MII_TXD_1, DA850_MII_TXD_0, DA850_MII_RXER,
39         DA850_MII_CRS, DA850_MII_RXCLK, DA850_MII_RXDV, DA850_MII_RXD_3,
40         DA850_MII_RXD_2, DA850_MII_RXD_1, DA850_MII_RXD_0, DA850_MDIO_CLK,
41         DA850_MDIO_D,
42         -1
43 };
44
45 static __init void omapl138_hawk_config_emac(void)
46 {
47         void __iomem *cfgchip3 = DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG);
48         int ret;
49         u32 val;
50         struct davinci_soc_info *soc_info = &davinci_soc_info;
51
52         val = __raw_readl(cfgchip3);
53         val &= ~BIT(8);
54         ret = davinci_cfg_reg_list(omapl138_hawk_mii_pins);
55         if (ret) {
56                 pr_warn("%s: CPGMAC/MII mux setup failed: %d\n", __func__, ret);
57                 return;
58         }
59
60         /* configure the CFGCHIP3 register for MII */
61         __raw_writel(val, cfgchip3);
62         pr_info("EMAC: MII PHY configured\n");
63
64         soc_info->emac_pdata->phy_id = HAWKBOARD_PHY_ID;
65
66         ret = da8xx_register_emac();
67         if (ret)
68                 pr_warn("%s: EMAC registration failed: %d\n", __func__, ret);
69 }
70
71 /*
72  * The following EDMA channels/slots are not being used by drivers (for
73  * example: Timer, GPIO, UART events etc) on da850/omap-l138 EVM/Hawkboard,
74  * hence they are being reserved for codecs on the DSP side.
75  */
76 static const s16 da850_dma0_rsv_chans[][2] = {
77         /* (offset, number) */
78         { 8,  6},
79         {24,  4},
80         {30,  2},
81         {-1, -1}
82 };
83
84 static const s16 da850_dma0_rsv_slots[][2] = {
85         /* (offset, number) */
86         { 8,  6},
87         {24,  4},
88         {30, 50},
89         {-1, -1}
90 };
91
92 static const s16 da850_dma1_rsv_chans[][2] = {
93         /* (offset, number) */
94         { 0, 28},
95         {30,  2},
96         {-1, -1}
97 };
98
99 static const s16 da850_dma1_rsv_slots[][2] = {
100         /* (offset, number) */
101         { 0, 28},
102         {30, 90},
103         {-1, -1}
104 };
105
106 static struct edma_rsv_info da850_edma_cc0_rsv = {
107         .rsv_chans      = da850_dma0_rsv_chans,
108         .rsv_slots      = da850_dma0_rsv_slots,
109 };
110
111 static struct edma_rsv_info da850_edma_cc1_rsv = {
112         .rsv_chans      = da850_dma1_rsv_chans,
113         .rsv_slots      = da850_dma1_rsv_slots,
114 };
115
116 static struct edma_rsv_info *da850_edma_rsv[2] = {
117         &da850_edma_cc0_rsv,
118         &da850_edma_cc1_rsv,
119 };
120
121 static const short hawk_mmcsd0_pins[] = {
122         DA850_MMCSD0_DAT_0, DA850_MMCSD0_DAT_1, DA850_MMCSD0_DAT_2,
123         DA850_MMCSD0_DAT_3, DA850_MMCSD0_CLK, DA850_MMCSD0_CMD,
124         DA850_GPIO3_12, DA850_GPIO3_13,
125         -1
126 };
127
128 #define DA850_HAWK_MMCSD_CD_PIN         GPIO_TO_PIN(3, 12)
129 #define DA850_HAWK_MMCSD_WP_PIN         GPIO_TO_PIN(3, 13)
130
131 static struct gpiod_lookup_table mmc_gpios_table = {
132         .dev_id = "da830-mmc.0",
133         .table = {
134                 GPIO_LOOKUP("davinci_gpio", DA850_HAWK_MMCSD_CD_PIN, "cd",
135                             GPIO_ACTIVE_LOW),
136                 GPIO_LOOKUP("davinci_gpio", DA850_HAWK_MMCSD_WP_PIN, "wp",
137                             GPIO_ACTIVE_LOW),
138         },
139 };
140
141 static struct davinci_mmc_config da850_mmc_config = {
142         .wires          = 4,
143         .max_freq       = 50000000,
144         .caps           = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
145 };
146
147 static __init void omapl138_hawk_mmc_init(void)
148 {
149         int ret;
150
151         ret = davinci_cfg_reg_list(hawk_mmcsd0_pins);
152         if (ret) {
153                 pr_warn("%s: MMC/SD0 mux setup failed: %d\n", __func__, ret);
154                 return;
155         }
156
157         gpiod_add_lookup_table(&mmc_gpios_table);
158
159         ret = da8xx_register_mmcsd0(&da850_mmc_config);
160         if (ret) {
161                 pr_warn("%s: MMC/SD0 registration failed: %d\n", __func__, ret);
162                 goto mmc_setup_mmcsd_fail;
163         }
164
165         return;
166
167 mmc_setup_mmcsd_fail:
168         gpiod_remove_lookup_table(&mmc_gpios_table);
169 }
170
171 static struct mtd_partition omapl138_hawk_nandflash_partition[] = {
172         {
173                 .name           = "u-boot env",
174                 .offset         = 0,
175                 .size           = SZ_128K,
176                 .mask_flags     = MTD_WRITEABLE,
177          },
178         {
179                 .name           = "u-boot",
180                 .offset         = MTDPART_OFS_APPEND,
181                 .size           = SZ_512K,
182                 .mask_flags     = MTD_WRITEABLE,
183         },
184         {
185                 .name           = "free space",
186                 .offset         = MTDPART_OFS_APPEND,
187                 .size           = MTDPART_SIZ_FULL,
188                 .mask_flags     = 0,
189         },
190 };
191
192 static struct davinci_aemif_timing omapl138_hawk_nandflash_timing = {
193         .wsetup         = 24,
194         .wstrobe        = 21,
195         .whold          = 14,
196         .rsetup         = 19,
197         .rstrobe        = 50,
198         .rhold          = 0,
199         .ta             = 20,
200 };
201
202 static struct davinci_nand_pdata omapl138_hawk_nandflash_data = {
203         .core_chipsel   = 1,
204         .parts          = omapl138_hawk_nandflash_partition,
205         .nr_parts       = ARRAY_SIZE(omapl138_hawk_nandflash_partition),
206         .engine_type    = NAND_ECC_ENGINE_TYPE_ON_HOST,
207         .ecc_bits       = 4,
208         .bbt_options    = NAND_BBT_USE_FLASH,
209         .options        = NAND_BUSWIDTH_16,
210         .timing         = &omapl138_hawk_nandflash_timing,
211         .mask_chipsel   = 0,
212         .mask_ale       = 0,
213         .mask_cle       = 0,
214 };
215
216 static struct resource omapl138_hawk_nandflash_resource[] = {
217         {
218                 .start  = DA8XX_AEMIF_CS3_BASE,
219                 .end    = DA8XX_AEMIF_CS3_BASE + SZ_32M,
220                 .flags  = IORESOURCE_MEM,
221         },
222         {
223                 .start  = DA8XX_AEMIF_CTL_BASE,
224                 .end    = DA8XX_AEMIF_CTL_BASE + SZ_32K,
225                 .flags  = IORESOURCE_MEM,
226         },
227 };
228
229 static struct resource omapl138_hawk_aemif_resource[] = {
230         {
231                 .start  = DA8XX_AEMIF_CTL_BASE,
232                 .end    = DA8XX_AEMIF_CTL_BASE + SZ_32K,
233                 .flags  = IORESOURCE_MEM,
234         }
235 };
236
237 static struct aemif_abus_data omapl138_hawk_aemif_abus_data[] = {
238         {
239                 .cs     = 3,
240         }
241 };
242
243 static struct platform_device omapl138_hawk_aemif_devices[] = {
244         {
245                 .name           = "davinci_nand",
246                 .id             = -1,
247                 .dev            = {
248                         .platform_data  = &omapl138_hawk_nandflash_data,
249                 },
250                 .resource       = omapl138_hawk_nandflash_resource,
251                 .num_resources  = ARRAY_SIZE(omapl138_hawk_nandflash_resource),
252         }
253 };
254
255 static struct aemif_platform_data omapl138_hawk_aemif_pdata = {
256         .cs_offset = 2,
257         .abus_data = omapl138_hawk_aemif_abus_data,
258         .num_abus_data = ARRAY_SIZE(omapl138_hawk_aemif_abus_data),
259         .sub_devices = omapl138_hawk_aemif_devices,
260         .num_sub_devices = ARRAY_SIZE(omapl138_hawk_aemif_devices),
261 };
262
263 static struct platform_device omapl138_hawk_aemif_device = {
264         .name           = "ti-aemif",
265         .id             = -1,
266         .dev = {
267                 .platform_data  = &omapl138_hawk_aemif_pdata,
268         },
269         .resource       = omapl138_hawk_aemif_resource,
270         .num_resources  = ARRAY_SIZE(omapl138_hawk_aemif_resource),
271 };
272
273 static const short omapl138_hawk_nand_pins[] = {
274         DA850_EMA_WAIT_1, DA850_NEMA_OE, DA850_NEMA_WE, DA850_NEMA_CS_3,
275         DA850_EMA_D_0, DA850_EMA_D_1, DA850_EMA_D_2, DA850_EMA_D_3,
276         DA850_EMA_D_4, DA850_EMA_D_5, DA850_EMA_D_6, DA850_EMA_D_7,
277         DA850_EMA_D_8, DA850_EMA_D_9, DA850_EMA_D_10, DA850_EMA_D_11,
278         DA850_EMA_D_12, DA850_EMA_D_13, DA850_EMA_D_14, DA850_EMA_D_15,
279         DA850_EMA_A_1, DA850_EMA_A_2,
280         -1
281 };
282
283 static int omapl138_hawk_register_aemif(void)
284 {
285         int ret;
286
287         ret = davinci_cfg_reg_list(omapl138_hawk_nand_pins);
288         if (ret)
289                 pr_warn("%s: NAND mux setup failed: %d\n", __func__, ret);
290
291         return platform_device_register(&omapl138_hawk_aemif_device);
292 }
293
294 static const short da850_hawk_usb11_pins[] = {
295         DA850_GPIO2_4, DA850_GPIO6_13,
296         -1
297 };
298
299 static struct regulator_consumer_supply hawk_usb_supplies[] = {
300         REGULATOR_SUPPLY("vbus", NULL),
301 };
302
303 static struct regulator_init_data hawk_usb_vbus_data = {
304         .consumer_supplies      = hawk_usb_supplies,
305         .num_consumer_supplies  = ARRAY_SIZE(hawk_usb_supplies),
306         .constraints    = {
307                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
308         },
309 };
310
311 static struct fixed_voltage_config hawk_usb_vbus = {
312         .supply_name            = "vbus",
313         .microvolts             = 3300000,
314         .init_data              = &hawk_usb_vbus_data,
315 };
316
317 static struct platform_device hawk_usb_vbus_device = {
318         .name           = "reg-fixed-voltage",
319         .id             = 0,
320         .dev            = {
321                 .platform_data = &hawk_usb_vbus,
322         },
323 };
324
325 static struct gpiod_lookup_table hawk_usb_oc_gpio_lookup = {
326         .dev_id         = "ohci-da8xx",
327         .table = {
328                 GPIO_LOOKUP("davinci_gpio", DA850_USB1_OC_PIN, "oc", 0),
329                 { }
330         },
331 };
332
333 static struct gpiod_lookup_table hawk_usb_vbus_gpio_lookup = {
334         .dev_id         = "reg-fixed-voltage.0",
335         .table = {
336                 GPIO_LOOKUP("davinci_gpio", DA850_USB1_VBUS_PIN, NULL, 0),
337                 { }
338         },
339 };
340
341 static struct gpiod_lookup_table *hawk_usb_gpio_lookups[] = {
342         &hawk_usb_oc_gpio_lookup,
343         &hawk_usb_vbus_gpio_lookup,
344 };
345
346 static struct da8xx_ohci_root_hub omapl138_hawk_usb11_pdata = {
347         /* TPS2087 switch @ 5V */
348         .potpgt         = (3 + 1) / 2,  /* 3 ms max */
349 };
350
351 static __init void omapl138_hawk_usb_init(void)
352 {
353         int ret;
354
355         ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
356         if (ret) {
357                 pr_warn("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret);
358                 return;
359         }
360
361         ret = da8xx_register_usb_phy_clocks();
362         if (ret)
363                 pr_warn("%s: USB PHY CLK registration failed: %d\n",
364                         __func__, ret);
365
366         gpiod_add_lookup_tables(hawk_usb_gpio_lookups,
367                                 ARRAY_SIZE(hawk_usb_gpio_lookups));
368
369         ret = da8xx_register_usb_phy();
370         if (ret)
371                 pr_warn("%s: USB PHY registration failed: %d\n",
372                         __func__, ret);
373
374         ret = platform_device_register(&hawk_usb_vbus_device);
375         if (ret) {
376                 pr_warn("%s: Unable to register the vbus supply\n", __func__);
377                 return;
378         }
379
380         ret = da8xx_register_usb11(&omapl138_hawk_usb11_pdata);
381         if (ret)
382                 pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret);
383
384         return;
385 }
386
387 static __init void omapl138_hawk_init(void)
388 {
389         int ret;
390
391         da850_register_clocks();
392
393         ret = da850_register_gpio();
394         if (ret)
395                 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
396
397         davinci_serial_init(da8xx_serial_device);
398
399         omapl138_hawk_config_emac();
400
401         ret = da850_register_edma(da850_edma_rsv);
402         if (ret)
403                 pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);
404
405         omapl138_hawk_mmc_init();
406
407         omapl138_hawk_usb_init();
408
409         ret = omapl138_hawk_register_aemif();
410         if (ret)
411                 pr_warn("%s: aemif registration failed: %d\n", __func__, ret);
412
413         ret = da8xx_register_watchdog();
414         if (ret)
415                 pr_warn("%s: watchdog registration failed: %d\n",
416                         __func__, ret);
417
418         ret = da8xx_register_rproc();
419         if (ret)
420                 pr_warn("%s: dsp/rproc registration failed: %d\n",
421                         __func__, ret);
422
423         regulator_has_full_constraints();
424 }
425
426 #ifdef CONFIG_SERIAL_8250_CONSOLE
427 static int __init omapl138_hawk_console_init(void)
428 {
429         if (!machine_is_omapl138_hawkboard())
430                 return 0;
431
432         return add_preferred_console("ttyS", 2, "115200");
433 }
434 console_initcall(omapl138_hawk_console_init);
435 #endif
436
437 static void __init omapl138_hawk_map_io(void)
438 {
439         da850_init();
440 }
441
442 MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
443         .atag_offset    = 0x100,
444         .map_io         = omapl138_hawk_map_io,
445         .init_irq       = da850_init_irq,
446         .init_time      = da850_init_time,
447         .init_machine   = omapl138_hawk_init,
448         .init_late      = davinci_init_late,
449         .dma_zone_size  = SZ_128M,
450         .reserve        = da8xx_rproc_reserve_cma,
451 MACHINE_END