1
2
3
4
5
6
7#include <linux/clk.h>
8#include <linux/davinci_emac.h>
9#include <linux/gpio.h>
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/of_platform.h>
13#include <linux/wl12xx.h>
14#include <linux/mmc/card.h>
15#include <linux/mmc/host.h>
16#include <linux/power/smartreflex.h>
17#include <linux/regulator/machine.h>
18#include <linux/regulator/fixed.h>
19
20#include <linux/platform_data/pinctrl-single.h>
21#include <linux/platform_data/hsmmc-omap.h>
22#include <linux/platform_data/iommu-omap.h>
23#include <linux/platform_data/ti-sysc.h>
24#include <linux/platform_data/wkup_m3.h>
25#include <linux/platform_data/asoc-ti-mcbsp.h>
26#include <linux/platform_data/ti-prm.h>
27
28#include "clockdomain.h"
29#include "common.h"
30#include "common-board-devices.h"
31#include "control.h"
32#include "omap_device.h"
33#include "omap-secure.h"
34#include "soc.h"
35
36static struct omap_hsmmc_platform_data __maybe_unused mmc_pdata[2];
37
38struct pdata_init {
39 const char *compatible;
40 void (*fn)(void);
41};
42
43static struct of_dev_auxdata omap_auxdata_lookup[];
44static struct twl4030_gpio_platform_data twl_gpio_auxdata;
45
46#if IS_ENABLED(CONFIG_OMAP_IOMMU)
47int omap_iommu_set_pwrdm_constraint(struct platform_device *pdev, bool request,
48 u8 *pwrst);
49#else
50static inline int omap_iommu_set_pwrdm_constraint(struct platform_device *pdev,
51 bool request, u8 *pwrst)
52{
53 return 0;
54}
55#endif
56
57#ifdef CONFIG_MACH_NOKIA_N8X0
58static void __init omap2420_n8x0_legacy_init(void)
59{
60 omap_auxdata_lookup[0].platform_data = n8x0_legacy_init();
61}
62#else
63#define omap2420_n8x0_legacy_init NULL
64#endif
65
66#ifdef CONFIG_ARCH_OMAP3
67
68
69
70
71
72
73static void __init omap3_gpio126_127_129(void)
74{
75 u32 reg;
76
77 reg = omap_ctrl_readl(OMAP343X_CONTROL_PBIAS_LITE);
78 reg &= ~OMAP343X_PBIASLITEVMODE1;
79 reg |= OMAP343X_PBIASLITEPWRDNZ1;
80 omap_ctrl_writel(reg, OMAP343X_CONTROL_PBIAS_LITE);
81 if (cpu_is_omap3630()) {
82 reg = omap_ctrl_readl(OMAP34XX_CONTROL_WKUP_CTRL);
83 reg |= OMAP36XX_GPIO_IO_PWRDNZ;
84 omap_ctrl_writel(reg, OMAP34XX_CONTROL_WKUP_CTRL);
85 }
86}
87
88static void __init hsmmc2_internal_input_clk(void)
89{
90 u32 reg;
91
92 reg = omap_ctrl_readl(OMAP343X_CONTROL_DEVCONF1);
93 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
94 omap_ctrl_writel(reg, OMAP343X_CONTROL_DEVCONF1);
95}
96
97#ifdef CONFIG_OMAP_HWMOD
98static struct iommu_platform_data omap3_iommu_pdata = {
99 .reset_name = "mmu",
100 .assert_reset = omap_device_assert_hardreset,
101 .deassert_reset = omap_device_deassert_hardreset,
102 .device_enable = omap_device_enable,
103 .device_idle = omap_device_idle,
104};
105
106static struct iommu_platform_data omap3_iommu_isp_pdata = {
107 .device_enable = omap_device_enable,
108 .device_idle = omap_device_idle,
109};
110#endif
111
112static int omap3_sbc_t3730_twl_callback(struct device *dev,
113 unsigned gpio,
114 unsigned ngpio)
115{
116 int res;
117
118 res = gpio_request_one(gpio + 2, GPIOF_OUT_INIT_HIGH,
119 "wlan pwr");
120 if (res)
121 return res;
122
123 gpio_export(gpio, 0);
124
125 return 0;
126}
127
128static void __init omap3_sbc_t3x_usb_hub_init(int gpio, char *hub_name)
129{
130 int err = gpio_request_one(gpio, GPIOF_OUT_INIT_LOW, hub_name);
131
132 if (err) {
133 pr_err("SBC-T3x: %s reset gpio request failed: %d\n",
134 hub_name, err);
135 return;
136 }
137
138 gpio_export(gpio, 0);
139
140 udelay(10);
141 gpio_set_value(gpio, 1);
142 msleep(1);
143}
144
145static void __init omap3_sbc_t3730_twl_init(void)
146{
147 twl_gpio_auxdata.setup = omap3_sbc_t3730_twl_callback;
148}
149
150static void __init omap3_sbc_t3730_legacy_init(void)
151{
152 omap3_sbc_t3x_usb_hub_init(167, "sb-t35 usb hub");
153}
154
155static void __init omap3_sbc_t3530_legacy_init(void)
156{
157 omap3_sbc_t3x_usb_hub_init(167, "sb-t35 usb hub");
158}
159
160static void __init omap3_evm_legacy_init(void)
161{
162 hsmmc2_internal_input_clk();
163}
164
165static void am35xx_enable_emac_int(void)
166{
167 u32 v;
168
169 v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
170 v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR |
171 AM35XX_CPGMAC_C0_MISC_PULSE_CLR | AM35XX_CPGMAC_C0_RX_THRESH_CLR);
172 omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
173 omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
174}
175
176static void am35xx_disable_emac_int(void)
177{
178 u32 v;
179
180 v = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
181 v |= (AM35XX_CPGMAC_C0_RX_PULSE_CLR | AM35XX_CPGMAC_C0_TX_PULSE_CLR);
182 omap_ctrl_writel(v, AM35XX_CONTROL_LVL_INTR_CLEAR);
183 omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
184}
185
186static struct emac_platform_data am35xx_emac_pdata = {
187 .interrupt_enable = am35xx_enable_emac_int,
188 .interrupt_disable = am35xx_disable_emac_int,
189};
190
191static void __init am35xx_emac_reset(void)
192{
193 u32 v;
194
195 v = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
196 v &= ~AM35XX_CPGMACSS_SW_RST;
197 omap_ctrl_writel(v, AM35XX_CONTROL_IP_SW_RESET);
198 omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
199}
200
201static struct gpio cm_t3517_wlan_gpios[] __initdata = {
202 { 56, GPIOF_OUT_INIT_HIGH, "wlan pwr" },
203 { 4, GPIOF_OUT_INIT_HIGH, "xcvr noe" },
204};
205
206static void __init omap3_sbc_t3517_wifi_init(void)
207{
208 int err = gpio_request_array(cm_t3517_wlan_gpios,
209 ARRAY_SIZE(cm_t3517_wlan_gpios));
210 if (err) {
211 pr_err("SBC-T3517: wl12xx gpios request failed: %d\n", err);
212 return;
213 }
214
215 gpio_export(cm_t3517_wlan_gpios[0].gpio, 0);
216 gpio_export(cm_t3517_wlan_gpios[1].gpio, 0);
217
218 msleep(100);
219 gpio_set_value(cm_t3517_wlan_gpios[1].gpio, 0);
220}
221
222static void __init omap3_sbc_t3517_legacy_init(void)
223{
224 omap3_sbc_t3x_usb_hub_init(152, "cm-t3517 usb hub");
225 omap3_sbc_t3x_usb_hub_init(98, "sb-t35 usb hub");
226 am35xx_emac_reset();
227 hsmmc2_internal_input_clk();
228 omap3_sbc_t3517_wifi_init();
229}
230
231static void __init am3517_evm_legacy_init(void)
232{
233 am35xx_emac_reset();
234}
235
236static void __init nokia_n900_legacy_init(void)
237{
238 hsmmc2_internal_input_clk();
239 mmc_pdata[0].name = "external";
240 mmc_pdata[1].name = "internal";
241
242 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
243 if (IS_ENABLED(CONFIG_ARM_ERRATA_430973)) {
244 pr_info("RX-51: Enabling ARM errata 430973 workaround\n");
245
246 rx51_secure_update_aux_cr(BIT(6), 0);
247 } else {
248 pr_warn("RX-51: Not enabling ARM errata 430973 workaround\n");
249 pr_warn("Thumb binaries may crash randomly without this workaround\n");
250 }
251 }
252}
253
254static void __init omap3_tao3530_legacy_init(void)
255{
256 hsmmc2_internal_input_clk();
257}
258
259static void __init omap3_logicpd_torpedo_init(void)
260{
261 omap3_gpio126_127_129();
262}
263
264
265
266static struct platform_device pandora_backlight = {
267 .name = "pandora-backlight",
268 .id = -1,
269};
270
271static void __init omap3_pandora_legacy_init(void)
272{
273 platform_device_register(&pandora_backlight);
274}
275#endif
276
277#ifdef CONFIG_SOC_DRA7XX
278static struct iommu_platform_data dra7_ipu1_dsp_iommu_pdata = {
279 .set_pwrdm_constraint = omap_iommu_set_pwrdm_constraint,
280};
281#endif
282
283static struct clockdomain *ti_sysc_find_one_clockdomain(struct clk *clk)
284{
285 struct clk_hw *hw = __clk_get_hw(clk);
286 struct clockdomain *clkdm = NULL;
287 struct clk_hw_omap *hwclk;
288
289 hwclk = to_clk_hw_omap(hw);
290 if (!omap2_clk_is_hw_omap(hw))
291 return NULL;
292
293 if (hwclk && hwclk->clkdm_name)
294 clkdm = clkdm_lookup(hwclk->clkdm_name);
295
296 return clkdm;
297}
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313static int ti_sysc_clkdm_init(struct device *dev,
314 struct clk *fck, struct clk *ick,
315 struct ti_sysc_cookie *cookie)
316{
317 if (!IS_ERR(fck))
318 cookie->clkdm = ti_sysc_find_one_clockdomain(fck);
319 if (cookie->clkdm)
320 return 0;
321 if (!IS_ERR(ick))
322 cookie->clkdm = ti_sysc_find_one_clockdomain(ick);
323 if (cookie->clkdm)
324 return 0;
325
326 return -ENODEV;
327}
328
329static void ti_sysc_clkdm_deny_idle(struct device *dev,
330 const struct ti_sysc_cookie *cookie)
331{
332 if (cookie->clkdm)
333 clkdm_deny_idle(cookie->clkdm);
334}
335
336static void ti_sysc_clkdm_allow_idle(struct device *dev,
337 const struct ti_sysc_cookie *cookie)
338{
339 if (cookie->clkdm)
340 clkdm_allow_idle(cookie->clkdm);
341}
342
343#ifdef CONFIG_OMAP_HWMOD
344static int ti_sysc_enable_module(struct device *dev,
345 const struct ti_sysc_cookie *cookie)
346{
347 if (!cookie->data)
348 return -EINVAL;
349
350 return omap_hwmod_enable(cookie->data);
351}
352
353static int ti_sysc_idle_module(struct device *dev,
354 const struct ti_sysc_cookie *cookie)
355{
356 if (!cookie->data)
357 return -EINVAL;
358
359 return omap_hwmod_idle(cookie->data);
360}
361
362static int ti_sysc_shutdown_module(struct device *dev,
363 const struct ti_sysc_cookie *cookie)
364{
365 if (!cookie->data)
366 return -EINVAL;
367
368 return omap_hwmod_shutdown(cookie->data);
369}
370#endif
371
372static bool ti_sysc_soc_type_gp(void)
373{
374 return omap_type() == OMAP2_DEVICE_TYPE_GP;
375}
376
377static struct of_dev_auxdata omap_auxdata_lookup[];
378
379static struct ti_sysc_platform_data ti_sysc_pdata = {
380 .auxdata = omap_auxdata_lookup,
381 .soc_type_gp = ti_sysc_soc_type_gp,
382 .init_clockdomain = ti_sysc_clkdm_init,
383 .clkdm_deny_idle = ti_sysc_clkdm_deny_idle,
384 .clkdm_allow_idle = ti_sysc_clkdm_allow_idle,
385#ifdef CONFIG_OMAP_HWMOD
386 .init_module = omap_hwmod_init_module,
387 .enable_module = ti_sysc_enable_module,
388 .idle_module = ti_sysc_idle_module,
389 .shutdown_module = ti_sysc_shutdown_module,
390#endif
391};
392
393static struct pcs_pdata pcs_pdata;
394
395void omap_pcs_legacy_init(int irq, void (*rearm)(void))
396{
397 pcs_pdata.irq = irq;
398 pcs_pdata.rearm = rearm;
399}
400
401static struct ti_prm_platform_data ti_prm_pdata = {
402 .clkdm_deny_idle = clkdm_deny_idle,
403 .clkdm_allow_idle = clkdm_allow_idle,
404 .clkdm_lookup = clkdm_lookup,
405};
406
407
408
409
410
411void omap_auxdata_legacy_init(struct device *dev)
412{
413 if (dev->platform_data)
414 return;
415
416 if (strcmp("twl4030-gpio", dev_name(dev)))
417 return;
418
419 dev->platform_data = &twl_gpio_auxdata;
420}
421
422#if defined(CONFIG_ARCH_OMAP3) && IS_ENABLED(CONFIG_SND_SOC_OMAP_MCBSP)
423static struct omap_mcbsp_platform_data mcbsp_pdata;
424static void __init omap3_mcbsp_init(void)
425{
426 omap3_mcbsp_init_pdata_callback(&mcbsp_pdata);
427}
428#else
429static void __init omap3_mcbsp_init(void) {}
430#endif
431
432
433
434
435
436static struct pdata_init auxdata_quirks[] __initdata = {
437#ifdef CONFIG_SOC_OMAP2420
438 { "nokia,n800", omap2420_n8x0_legacy_init, },
439 { "nokia,n810", omap2420_n8x0_legacy_init, },
440 { "nokia,n810-wimax", omap2420_n8x0_legacy_init, },
441#endif
442#ifdef CONFIG_ARCH_OMAP3
443 { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_twl_init, },
444#endif
445 { },
446};
447
448struct omap_sr_data __maybe_unused omap_sr_pdata[OMAP_SR_NR];
449
450static struct of_dev_auxdata omap_auxdata_lookup[] = {
451#ifdef CONFIG_MACH_NOKIA_N8X0
452 OF_DEV_AUXDATA("ti,omap2420-mmc", 0x4809c000, "mmci-omap.0", NULL),
453 OF_DEV_AUXDATA("menelaus", 0x72, "1-0072", &n8x0_menelaus_platform_data),
454 OF_DEV_AUXDATA("tlv320aic3x", 0x18, "2-0018", &n810_aic33_data),
455#endif
456#ifdef CONFIG_ARCH_OMAP3
457 OF_DEV_AUXDATA("ti,omap2-iommu", 0x5d000000, "5d000000.mmu",
458 &omap3_iommu_pdata),
459 OF_DEV_AUXDATA("ti,omap2-iommu", 0x480bd400, "480bd400.mmu",
460 &omap3_iommu_isp_pdata),
461 OF_DEV_AUXDATA("ti,omap3-smartreflex-core", 0x480cb000,
462 "480cb000.smartreflex", &omap_sr_pdata[OMAP_SR_CORE]),
463 OF_DEV_AUXDATA("ti,omap3-smartreflex-mpu-iva", 0x480c9000,
464 "480c9000.smartreflex", &omap_sr_pdata[OMAP_SR_MPU]),
465 OF_DEV_AUXDATA("ti,omap3-hsmmc", 0x4809c000, "4809c000.mmc", &mmc_pdata[0]),
466 OF_DEV_AUXDATA("ti,omap3-hsmmc", 0x480b4000, "480b4000.mmc", &mmc_pdata[1]),
467
468 OF_DEV_AUXDATA("ti,davinci_mdio", 0x5c030000, "davinci_mdio.0", NULL),
469 OF_DEV_AUXDATA("ti,am3517-emac", 0x5c000000, "davinci_emac.0",
470 &am35xx_emac_pdata),
471 OF_DEV_AUXDATA("nokia,n900-rom-rng", 0, NULL, rx51_secure_rng_call),
472
473#if IS_ENABLED(CONFIG_SND_SOC_OMAP_MCBSP)
474 OF_DEV_AUXDATA("ti,omap3-mcbsp", 0x49022000, "49022000.mcbsp", &mcbsp_pdata),
475 OF_DEV_AUXDATA("ti,omap3-mcbsp", 0x49024000, "49024000.mcbsp", &mcbsp_pdata),
476#endif
477#endif
478#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
479 OF_DEV_AUXDATA("ti,omap4-smartreflex-iva", 0x4a0db000,
480 "4a0db000.smartreflex", &omap_sr_pdata[OMAP_SR_IVA]),
481 OF_DEV_AUXDATA("ti,omap4-smartreflex-core", 0x4a0dd000,
482 "4a0dd000.smartreflex", &omap_sr_pdata[OMAP_SR_CORE]),
483 OF_DEV_AUXDATA("ti,omap4-smartreflex-mpu", 0x4a0d9000,
484 "4a0d9000.smartreflex", &omap_sr_pdata[OMAP_SR_MPU]),
485#endif
486#ifdef CONFIG_SOC_DRA7XX
487 OF_DEV_AUXDATA("ti,dra7-dsp-iommu", 0x40d01000, "40d01000.mmu",
488 &dra7_ipu1_dsp_iommu_pdata),
489 OF_DEV_AUXDATA("ti,dra7-dsp-iommu", 0x41501000, "41501000.mmu",
490 &dra7_ipu1_dsp_iommu_pdata),
491 OF_DEV_AUXDATA("ti,dra7-iommu", 0x58882000, "58882000.mmu",
492 &dra7_ipu1_dsp_iommu_pdata),
493#endif
494
495 OF_DEV_AUXDATA("simple-pm-bus", 0, NULL, omap_auxdata_lookup),
496 OF_DEV_AUXDATA("ti,sysc", 0, NULL, &ti_sysc_pdata),
497 OF_DEV_AUXDATA("pinctrl-single", 0, NULL, &pcs_pdata),
498 OF_DEV_AUXDATA("ti,omap-prm-inst", 0, NULL, &ti_prm_pdata),
499 OF_DEV_AUXDATA("ti,omap-sdma", 0, NULL, &dma_plat_info),
500 { },
501};
502
503
504
505
506
507static struct pdata_init pdata_quirks[] __initdata = {
508#ifdef CONFIG_ARCH_OMAP3
509 { "compulab,omap3-sbc-t3517", omap3_sbc_t3517_legacy_init, },
510 { "compulab,omap3-sbc-t3530", omap3_sbc_t3530_legacy_init, },
511 { "compulab,omap3-sbc-t3730", omap3_sbc_t3730_legacy_init, },
512 { "nokia,omap3-n900", nokia_n900_legacy_init, },
513 { "nokia,omap3-n9", hsmmc2_internal_input_clk, },
514 { "nokia,omap3-n950", hsmmc2_internal_input_clk, },
515 { "logicpd,dm3730-torpedo-devkit", omap3_logicpd_torpedo_init, },
516 { "ti,omap3-evm-37xx", omap3_evm_legacy_init, },
517 { "ti,am3517-evm", am3517_evm_legacy_init, },
518 { "technexion,omap3-tao3530", omap3_tao3530_legacy_init, },
519 { "openpandora,omap3-pandora-600mhz", omap3_pandora_legacy_init, },
520 { "openpandora,omap3-pandora-1ghz", omap3_pandora_legacy_init, },
521#endif
522 { },
523};
524
525static void pdata_quirks_check(struct pdata_init *quirks)
526{
527 while (quirks->compatible) {
528 if (of_machine_is_compatible(quirks->compatible)) {
529 if (quirks->fn)
530 quirks->fn();
531 }
532 quirks++;
533 }
534}
535
536static const char * const pdata_quirks_init_nodes[] = {
537 "prcm",
538 "prm",
539};
540
541static void __init
542pdata_quirks_init_clocks(const struct of_device_id *omap_dt_match_table)
543{
544 struct device_node *np;
545 int i;
546
547 for (i = 0; i < ARRAY_SIZE(pdata_quirks_init_nodes); i++) {
548 np = of_find_node_by_name(NULL, pdata_quirks_init_nodes[i]);
549 if (!np)
550 continue;
551
552 of_platform_populate(np, omap_dt_match_table,
553 omap_auxdata_lookup, NULL);
554 }
555}
556
557void __init pdata_quirks_init(const struct of_device_id *omap_dt_match_table)
558{
559
560
561
562
563 if (of_machine_is_compatible("ti,omap2420") ||
564 of_machine_is_compatible("ti,omap3"))
565 omap_sdrc_init(NULL, NULL);
566
567 if (of_machine_is_compatible("ti,omap3"))
568 omap3_mcbsp_init();
569 pdata_quirks_check(auxdata_quirks);
570
571 pdata_quirks_init_clocks(omap_dt_match_table);
572
573 of_platform_populate(NULL, omap_dt_match_table,
574 omap_auxdata_lookup, NULL);
575 pdata_quirks_check(pdata_quirks);
576}
577