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