Project

General

Profile

Kernel loading module problems MityDSP and FPGA configura... » our_baseboard-industrialio_1chip.c

Silvano Bertoldo, 05/29/2014 07:38 AM

 
1
/*
2
 * Critical Link MityOMAP-L138 SoM Baseboard initializtaion file
3
 *
4
 */
5
#include <linux/kernel.h>
6
#include <linux/init.h>
7
#include <linux/gpio.h>
8
#include <linux/platform_device.h>
9
#include <linux/spi/spi.h>
10
#include <linux/delay.h>
11
#include <linux/mtd/mtd.h>
12
#include <linux/usb/musb.h>
13

    
14
#include <asm/mach-types.h>
15
#include <asm/mach/arch.h>
16
#include <asm/setup.h>
17
#include <mach/mux.h>
18
#include <mach/da8xx.h>
19
#include <linux/can/platform/mcp251x.h>
20

    
21
#define BASEBOARD_NAME "IndustrialIO"
22
#define MSTPRI2_LCD_MASK  0x70000000
23
#define MSTPRI2_LCD_SHIFT 28
24
#define LCD_PRIORITY	  0 /* make video output highest priority */
25

    
26
#define MMCSD_CD_PIN		GPIO_TO_PIN(4, 0)
27
#define MMCSD_WP_PIN		GPIO_TO_PIN(4, 1)
28
#define SYSTEM_RESET		GPIO_TO_PIN(5, 14)
29
#define CAN_CS_N		GPIO_TO_PIN(2, 15)		/* FOR US IS TO SELECT CHIP ADF4158 */
30
#define CAN_INT_PIN		GPIO_TO_PIN(2, 12)
31
#define DSD1791_CS_N		GPIO_TO_PIN(0, 8)
32
#define DAC8551_CS_N		GPIO_TO_PIN(0, 15)
33
#define ADS5560_CS_N		GPIO_TO_PIN(0, 6)
34

    
35
static int baseboard_mmc_get_ro(int index)
36
{
37
	return gpio_get_value(MMCSD_WP_PIN);
38
}
39

    
40
static int baseboard_mmc_get_cd(int index)
41
{
42
	return !gpio_get_value(MMCSD_CD_PIN);
43
}
44

    
45
static struct davinci_mmc_config da850_mmc_config = {
46
	.get_ro		= baseboard_mmc_get_ro,
47
	.get_cd		= baseboard_mmc_get_cd,
48
	.wires		= 4,
49
	.max_freq	= 50000000,
50
	.caps		= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
51
	.version	= MMC_CTLR_VERSION_2,
52
};
53

    
54
static const short da850_mmcsd0_pins[] __initconst = {
55
	DA850_MMCSD0_DAT_0, DA850_MMCSD0_DAT_1, DA850_MMCSD0_DAT_2,
56
	DA850_MMCSD0_DAT_3, DA850_MMCSD0_CLK, DA850_MMCSD0_CMD,
57
	DA850_GPIO4_0, DA850_GPIO4_1,
58
	-1
59
};
60

    
61
static __init void baseboard_setup_mmc(void)
62
{
63
	int ret;
64

    
65
	ret = davinci_cfg_reg_list(da850_mmcsd0_pins);
66
	if (ret)
67
		pr_warning("%s: mmcsd0 mux setup failed: %d\n", __func__, ret);
68

    
69
	ret = gpio_request(MMCSD_CD_PIN, "MMC CD\n");
70
	if (ret)
71
		pr_warning("%s: can not open GPIO %d\n", __func__,
72
				MMCSD_CD_PIN);
73
	gpio_direction_input(MMCSD_CD_PIN);
74

    
75
	ret = gpio_request(MMCSD_WP_PIN, "MMC WP\n");
76
	if (ret)
77
		pr_warning("%s: can not open GPIO %d\n", __func__,
78
				MMCSD_WP_PIN);
79
	gpio_direction_input(MMCSD_WP_PIN);
80

    
81
	ret = da8xx_register_mmcsd0(&da850_mmc_config);
82
	if (ret)
83
		pr_warning("%s: mmcsd0 registration failed: %d\n", __func__,
84
				ret);
85
}
86

    
87
/*
88
 * GPIO pins, this is an exhaustive list which may be overridden by
89
 * other devices
90
 */
91
static short baseboard_gpio_pins[] __initdata = {
92
	DA850_GPIO0_0, DA850_GPIO0_1, DA850_GPIO0_2, DA850_GPIO0_3,
93
	DA850_GPIO0_4, DA850_GPIO0_5, DA850_GPIO0_6, DA850_GPIO0_7,
94
	DA850_GPIO0_8, DA850_GPIO0_9, DA850_GPIO0_10, DA850_GPIO0_11,
95
	DA850_GPIO0_12, DA850_GPIO0_13, DA850_GPIO0_14, DA850_GPIO0_15,
96
	DA850_GPIO2_12, DA850_GPIO2_15, -1,
97
};
98

    
99
/* davinci da850 evm audio machine driver */
100
static u8 da850_iis_serializer_direction[] = {
101
	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,
102
	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,
103
	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,
104
	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,	INACTIVE_MODE,
105
};
106

    
107
static struct snd_platform_data baseboard_snd_data = {
108
	.tx_dma_offset	= 0x2000,
109
	.rx_dma_offset	= 0x2000,
110
	.op_mode	= DAVINCI_MCASP_IIS_MODE,
111
	.num_serializer	= ARRAY_SIZE(da850_iis_serializer_direction),
112
	.tdm_slots	= 0,
113
	.serial_dir	= da850_iis_serializer_direction,
114
	.asp_chan_q	= EVENTQ_1,
115
	.version	= MCASP_VERSION_2,
116
	.txnumevt	= 0,
117
	.rxnumevt	= 0,
118
};
119

    
120
static short baseboard_mcasp_pins[21] __initdata = {
121
	DA850_AHCLKX, DA850_ACLKX, DA850_AFSX,
122
	DA850_AHCLKR,
123
	-1, -1, -1, -1,
124
	-1, -1, -1, -1,
125
	-1, -1, -1, -1,
126
	-1, -1, -1, -1,
127
	-1
128
};
129

    
130
static __init int baseboard_setup_mcasp(void)
131
{
132
	int ret;
133

    
134
	baseboard_mcasp_pins[4+0] = DA850_AXR_15;
135
	da850_iis_serializer_direction[15] = TX_MODE;
136

    
137
	ret = davinci_cfg_reg_list(baseboard_mcasp_pins);
138
	if (ret)
139
		pr_warning("%s: mcasp mux setup failed: %d\n", __func__, ret);
140

    
141
	ret = gpio_request(SYSTEM_RESET, "SYSTEM RESET\n");
142
	if (ret)
143
		pr_warning("%s: can't open GPIO %d\n", __func__, SYSTEM_RESET);
144
	msleep(20);
145
	gpio_direction_output(SYSTEM_RESET, 0);
146
	msleep(20);
147
	gpio_set_value(SYSTEM_RESET, 1);
148

    
149
	baseboard_snd_data.tdm_slots = 2;
150
	baseboard_snd_data.txnumevt = 1;
151

    
152
	da8xx_register_mcasp(0, &baseboard_snd_data);
153

    
154
	return ret;
155
}
156

    
157
static const struct display_panel disp_panel = {
158
	QVGA,
159
	16,
160
	16,
161
	COLOR_ACTIVE,
162
};
163

    
164
static struct lcd_ctrl_config lcd_cfg = {
165
	&disp_panel,
166
	.ac_bias		= 255,
167
	.ac_bias_intrpt		= 0,
168
	.dma_burst_sz		= 16,
169
	.bpp			= 16,
170
	.fdd			= 255,
171
	.tft_alt_mode		= 0,
172
	.stn_565_mode		= 0,
173
	.mono_8bit_mode		= 0,
174
	.invert_line_clock	= 0,
175
	.invert_frm_clock	= 0,
176
	.sync_edge		= 0,
177
	.sync_ctrl		= 1,
178
	.raster_order		= 0,
179
};
180

    
181
static struct da8xx_lcdc_platform_data sharp_lq035q7dh06_pdata = {
182
	.manu_name		= "sharp",
183
	.controller_data	= &lcd_cfg,
184
	.type			= "Sharp_LQ035Q7DH06",
185
};
186

    
187
static struct da8xx_lcdc_platform_data chimei_p0430wqlb_pdata = {
188
	.manu_name		= "ChiMei",
189
	.controller_data	= &lcd_cfg,
190
	.type			= "ChiMei_P0430WQLB",
191
};
192

    
193
static struct da8xx_lcdc_platform_data vga_640x480_pdata = {
194
	.manu_name		= "VGA",
195
	.controller_data	= &lcd_cfg,
196
	.type			= "vga_640x480",
197
};
198

    
199
static struct da8xx_lcdc_platform_data wvga_800x480_pdata = {
200
	.manu_name		= "WVGA",
201
	.controller_data	= &lcd_cfg,
202
	.type			= "wvga_800x480",
203
};
204

    
205
static struct da8xx_lcdc_platform_data svga_800x600_pdata = {
206
	.manu_name		= "SVGA",
207
	.controller_data	= &lcd_cfg,
208
	.type			= "svga_800x600",
209
};
210

    
211
static struct da8xx_lcdc_platform_data nec_nl4827hc19_pdata = {
212
	.manu_name		= "NEC",
213
	.controller_data	= &lcd_cfg,
214
	.type			= "NEC_NL4827HC19-05B",
215
};
216

    
217
static __init void baseboard_setup_lcd(const char *panel)
218
{
219
	int ret;
220
	struct da8xx_lcdc_platform_data *pdata;
221

    
222
	u32 prio;
223

    
224
	/* set peripheral master priority up to 1 */
225
	prio = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_MSTPRI2_REG));
226
	prio &= ~MSTPRI2_LCD_MASK;
227
	prio |= LCD_PRIORITY<<MSTPRI2_LCD_SHIFT;
228
	__raw_writel(prio, DA8XX_SYSCFG0_VIRT(DA8XX_MSTPRI2_REG));
229

    
230
	if (!strcmp("Sharp_LQ035Q7DH06", panel))
231
		pdata = &sharp_lq035q7dh06_pdata;
232
	else if (!strcmp("ChiMei_P0430WQLB", panel))
233
		pdata = &chimei_p0430wqlb_pdata;
234
	else if (!strcmp("vga_640x480", panel))
235
		pdata = &vga_640x480_pdata;
236
	else if (!strcmp("wvga_800x480", panel))
237
		pdata = &wvga_800x480_pdata;
238
	else if (!strcmp("svga_800x600", panel))
239
		pdata = &svga_800x600_pdata;
240
	else if (!strcmp("NEC_NL4827HC19-05B", panel)) {
241
		pdata = &nec_nl4827hc19_pdata;
242
		lcd_cfg.invert_line_clock	= 1;
243
		lcd_cfg.invert_frm_clock	= 1;
244
	} else {
245
		pr_warning("%s: unknown LCD type : %s\n", __func__,
246
				panel);
247
		return;
248
	}
249

    
250
	ret = davinci_cfg_reg_list(da850_lcdcntl_pins);
251
	if (ret) {
252
		pr_warning("%s: lcd pinmux failed : %d\n", __func__,
253
				ret);
254
		return;
255
	}
256

    
257
	ret = da8xx_register_lcdc(pdata);
258
}
259

    
260
#ifdef CONFIG_MTD
261
#define OFFSET_LCDCONFIG 176
262
#define LCDCONFIG_LEN 33
263
static void baseboard_mtd_notify(struct mtd_info *mtd)
264
{
265
	int retlen;
266
	char buf[LCDCONFIG_LEN]; /* enable, manufacturer name */
267
	if (!strcmp(mtd->name, "periph-config")) {
268
		mtd->read(mtd, OFFSET_LCDCONFIG, LCDCONFIG_LEN, &retlen,
269
			  buf);
270
		if (retlen == LCDCONFIG_LEN) {
271
			if (buf[0]) {
272
				buf[LCDCONFIG_LEN-1] = 0;
273
				pr_info("Using LCD panel: %s\n", &buf[1]);
274
				baseboard_setup_lcd(&buf[1]);
275
			} else
276
				pr_info("No LCD configured\n");
277
		}
278
	}
279
}
280

    
281
static struct mtd_notifier baseboard_spi_notifier = {
282
	.add	= baseboard_mtd_notify,
283
};
284

    
285
static void baseboard_mtd_notify_add(void)
286
{
287
	register_mtd_user(&baseboard_spi_notifier);
288
}
289
#else
290
static void baseboard_mtd_notify_add(void) { }
291
#endif
292

    
293
								/* MODIFIED. Commented out */
294
/* 								
295
static struct mcp251x_platform_data mcp2515_pdata = {
296
	.oscillator_frequency	= 20000000,
297
};
298
*/
299

    
300
static struct davinci_spi_config spi_mcp2515_config = {
301
	.io_type	= SPI_IO_TYPE_POLL, 			/* MODIFIED. Default value SPI_IO_TYPE_DMA */
302
	.c2tdelay	= 0,
303
	.t2cdelay	= 0,
304
};
305

    
306
static struct davinci_spi_config spi_dsd1791_config = {
307
	.io_type	= SPI_IO_TYPE_DMA,
308
	.c2tdelay	= 0,
309
	.t2cdelay	= 0,
310
};
311

    
312
#ifdef CONFIG_INDIO_EXPANSION_ANALOGIO
313
static struct davinci_spi_config spi_dac8554_config = {
314
	.io_type	= SPI_IO_TYPE_DMA,
315
	.c2tdelay	= 0,
316
	.t2cdelay	= 0,
317
};
318
static struct davinci_spi_config spi_ads5560_config = {
319
	.io_type	= SPI_IO_TYPE_DMA,
320
	.c2tdelay	= 0,
321
	.t2cdelay	= 0,
322
};
323
#endif
324

    
325
static struct spi_board_info baseboard_spi1_info[] = {
326
	{
327
		.modalias		= "spidev",				/* MODIFIED. Default value mcp2515 */
328
		/* .platform_data		= &mcp2515_pdata, */		/* COMMENTED OUT */
329
		.controller_data	= &spi_mcp2515_config,	
330
		.max_speed_hz		= 750000,				/* MODIFIED. Default value 10000000 */
331
		.bus_num		= 1,
332
		.chip_select		= 1,
333
		.mode			= SPI_MODE_0,				/* ADDED. Default value nothing means SPI_MODE_3*/
334
	},
335
	{
336
		.modalias		= "dsd1791",
337
		.controller_data	= &spi_dsd1791_config,
338
		.max_speed_hz		= 1000000,
339
		.bus_num		= 1,
340
		.chip_select		= 2,
341
	},
342
#ifdef CONFIG_INDIO_EXPANSION_ANALOGIO
343
	{
344
		.modalias		= "spidev",
345
		.controller_data	= &spi_dac8554_config,
346
		.max_speed_hz		= 10000000,
347
		.bus_num		= 1,
348
		.chip_select		= 3,
349
	},
350
	{
351
		.modalias		= "spidev",
352
		.controller_data	= &spi_ads5560_config,
353
		.max_speed_hz		= 10000000,
354
		.bus_num		= 1,
355
		.chip_select		= 4,
356
	},
357
#endif
358
};
359

    
360
#ifdef CONFIG_INDIO_EXPANSION_ANALOGIO
361
static struct spi_board_info baseboard_spi3_info[] = {
362
	{
363
		.modalias		= "spidev",
364
		.max_speed_hz		= 10000000,
365
		.bus_num		= 3,
366
		.chip_select		= 0,
367
	},
368
};
369
#endif
370

    
371
static u8 spi1_cs[] = {
372
	SPI_INTERN_CS,
373
	CAN_CS_N,
374
	DSD1791_CS_N,
375
#ifdef CONFIG_INDIO_EXPANSION_ANALOGIO
376
	DAC8551_CS_N,
377
	ADS5560_CS_N,
378
#endif
379
};
380

    
381
static void __init baseboard_setup_spi(void)
382
{
383
	int ret;
384

    
385
	ret = gpio_request(CAN_CS_N, "CAN CS\n");
386
	if (ret)
387
		pr_warning("%s: can not open CAN CS %d\n", __func__, CAN_CS_N);
388

    
389
	ret = gpio_request(DSD1791_CS_N, "DSD1791 CS\n");
390
	if (ret)
391
		pr_warning("%s: can not open DSD1791 CS %d\n", __func__,
392
			DSD1791_CS_N);
393

    
394
#ifdef CONFIG_INDIO_EXPANSION_ANALOGIO
395
	ret = gpio_request(DAC8551_CS_N, "DAC8551 LDAC\n");
396
	if (ret)
397
		pr_warning("%s: can not open DAC8551 LDAC %d\n", __func__, ret);
398

    
399
	ret = gpio_request(ADS5560_CS_N, "ADS5560 CS\n");
400
	if (ret)
401
		pr_warning("%s: can not open ADS5560 CS %d\n", __func__, ret);
402

    
403
	ret = spi_register_board_info(baseboard_spi3_info,
404
					ARRAY_SIZE(baseboard_spi3_info));
405
	if (ret)
406
		pr_warning("%s: Unable to register SPI3 Info: %d\n", __func__,
407
				ret);
408
#endif
409

    
410
	baseboard_spi1_info[0].irq = gpio_to_irq(CAN_INT_PIN);
411

    
412
	ret = spi_register_board_info(baseboard_spi1_info,
413
					ARRAY_SIZE(baseboard_spi1_info));
414
	if (ret)
415
		pr_warning("%s: Unable to register SPI1 Info: %d\n", __func__,
416
				ret);
417
}
418

    
419
static int __init baseboard_pre_init(void)
420
{
421
	pr_info("%s: Entered\n", __func__);
422
	da8xx_spi_pdata[1].chip_sel = spi1_cs;
423
	da8xx_spi_pdata[1].num_chipselect = ARRAY_SIZE(spi1_cs);
424
	davinci_soc_info.emac_pdata->phy_id = "0:03";
425
	return 0;
426
}
427
postcore_initcall_sync(baseboard_pre_init);
428

    
429
static int __init baseboard_init(void)
430
{
431
	pr_info("%s [%s]...\n", __func__, BASEBOARD_NAME);
432

    
433
	davinci_cfg_reg_list(baseboard_gpio_pins);
434

    
435
	baseboard_setup_mmc();
436

    
437
	baseboard_setup_spi();
438

    
439
	baseboard_setup_mcasp();
440

    
441
	baseboard_mtd_notify_add();
442

    
443
	mityomapl138_usb_init(MUSB_OTG);
444

    
445
	return 0;
446
}
447
arch_initcall_sync(baseboard_init);
(1-1/4) Go to top
Add picture from clipboard (Maximum size: 1 GB)