diff options
Diffstat (limited to 'arch/avr32/mach-at32ap/at32ap700x.c')
-rw-r--r-- | arch/avr32/mach-at32ap/at32ap700x.c | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c index eb9d4dc2e86d..e67c99945428 100644 --- a/arch/avr32/mach-at32ap/at32ap700x.c +++ b/arch/avr32/mach-at32ap/at32ap700x.c | |||
@@ -12,9 +12,12 @@ | |||
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/platform_device.h> | 13 | #include <linux/platform_device.h> |
14 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
15 | #include <linux/slab.h> | ||
15 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
16 | #include <linux/spi/spi.h> | 17 | #include <linux/spi/spi.h> |
17 | #include <linux/usb/atmel_usba_udc.h> | 18 | #include <linux/usb/atmel_usba_udc.h> |
19 | |||
20 | #include <mach/atmel-mci.h> | ||
18 | #include <linux/atmel-mci.h> | 21 | #include <linux/atmel-mci.h> |
19 | 22 | ||
20 | #include <asm/io.h> | 23 | #include <asm/io.h> |
@@ -1181,19 +1184,32 @@ static struct resource atmel_spi1_resource[] = { | |||
1181 | DEFINE_DEV(atmel_spi, 1); | 1184 | DEFINE_DEV(atmel_spi, 1); |
1182 | DEV_CLK(spi_clk, atmel_spi1, pba, 1); | 1185 | DEV_CLK(spi_clk, atmel_spi1, pba, 1); |
1183 | 1186 | ||
1184 | static void __init | 1187 | void __init |
1185 | at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, | 1188 | at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, unsigned int n) |
1186 | unsigned int n, const u8 *pins) | ||
1187 | { | 1189 | { |
1190 | /* | ||
1191 | * Manage the chipselects as GPIOs, normally using the same pins | ||
1192 | * the SPI controller expects; but boards can use other pins. | ||
1193 | */ | ||
1194 | static u8 __initdata spi_pins[][4] = { | ||
1195 | { GPIO_PIN_PA(3), GPIO_PIN_PA(4), | ||
1196 | GPIO_PIN_PA(5), GPIO_PIN_PA(20) }, | ||
1197 | { GPIO_PIN_PB(2), GPIO_PIN_PB(3), | ||
1198 | GPIO_PIN_PB(4), GPIO_PIN_PA(27) }, | ||
1199 | }; | ||
1188 | unsigned int pin, mode; | 1200 | unsigned int pin, mode; |
1189 | 1201 | ||
1202 | /* There are only 2 SPI controllers */ | ||
1203 | if (bus_num > 1) | ||
1204 | return; | ||
1205 | |||
1190 | for (; n; n--, b++) { | 1206 | for (; n; n--, b++) { |
1191 | b->bus_num = bus_num; | 1207 | b->bus_num = bus_num; |
1192 | if (b->chip_select >= 4) | 1208 | if (b->chip_select >= 4) |
1193 | continue; | 1209 | continue; |
1194 | pin = (unsigned)b->controller_data; | 1210 | pin = (unsigned)b->controller_data; |
1195 | if (!pin) { | 1211 | if (!pin) { |
1196 | pin = pins[b->chip_select]; | 1212 | pin = spi_pins[bus_num][b->chip_select]; |
1197 | b->controller_data = (void *)pin; | 1213 | b->controller_data = (void *)pin; |
1198 | } | 1214 | } |
1199 | mode = AT32_GPIOF_OUTPUT; | 1215 | mode = AT32_GPIOF_OUTPUT; |
@@ -1206,16 +1222,6 @@ at32_spi_setup_slaves(unsigned int bus_num, struct spi_board_info *b, | |||
1206 | struct platform_device *__init | 1222 | struct platform_device *__init |
1207 | at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) | 1223 | at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) |
1208 | { | 1224 | { |
1209 | /* | ||
1210 | * Manage the chipselects as GPIOs, normally using the same pins | ||
1211 | * the SPI controller expects; but boards can use other pins. | ||
1212 | */ | ||
1213 | static u8 __initdata spi0_pins[] = | ||
1214 | { GPIO_PIN_PA(3), GPIO_PIN_PA(4), | ||
1215 | GPIO_PIN_PA(5), GPIO_PIN_PA(20), }; | ||
1216 | static u8 __initdata spi1_pins[] = | ||
1217 | { GPIO_PIN_PB(2), GPIO_PIN_PB(3), | ||
1218 | GPIO_PIN_PB(4), GPIO_PIN_PA(27), }; | ||
1219 | struct platform_device *pdev; | 1225 | struct platform_device *pdev; |
1220 | u32 pin_mask; | 1226 | u32 pin_mask; |
1221 | 1227 | ||
@@ -1228,7 +1234,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) | |||
1228 | select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP); | 1234 | select_peripheral(PIOA, (1 << 0), PERIPH_A, AT32_GPIOF_PULLUP); |
1229 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); | 1235 | select_peripheral(PIOA, pin_mask, PERIPH_A, 0); |
1230 | 1236 | ||
1231 | at32_spi_setup_slaves(0, b, n, spi0_pins); | 1237 | at32_spi_setup_slaves(0, b, n); |
1232 | break; | 1238 | break; |
1233 | 1239 | ||
1234 | case 1: | 1240 | case 1: |
@@ -1239,7 +1245,7 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n) | |||
1239 | select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP); | 1245 | select_peripheral(PIOB, (1 << 0), PERIPH_B, AT32_GPIOF_PULLUP); |
1240 | select_peripheral(PIOB, pin_mask, PERIPH_B, 0); | 1246 | select_peripheral(PIOB, pin_mask, PERIPH_B, 0); |
1241 | 1247 | ||
1242 | at32_spi_setup_slaves(1, b, n, spi1_pins); | 1248 | at32_spi_setup_slaves(1, b, n); |
1243 | break; | 1249 | break; |
1244 | 1250 | ||
1245 | default: | 1251 | default: |
@@ -1320,7 +1326,7 @@ struct platform_device *__init | |||
1320 | at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | 1326 | at32_add_device_mci(unsigned int id, struct mci_platform_data *data) |
1321 | { | 1327 | { |
1322 | struct platform_device *pdev; | 1328 | struct platform_device *pdev; |
1323 | struct dw_dma_slave *dws = &data->dma_slave; | 1329 | struct mci_dma_data *slave; |
1324 | u32 pioa_mask; | 1330 | u32 pioa_mask; |
1325 | u32 piob_mask; | 1331 | u32 piob_mask; |
1326 | 1332 | ||
@@ -1339,16 +1345,22 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1339 | ARRAY_SIZE(atmel_mci0_resource))) | 1345 | ARRAY_SIZE(atmel_mci0_resource))) |
1340 | goto fail; | 1346 | goto fail; |
1341 | 1347 | ||
1342 | dws->dma_dev = &dw_dmac0_device.dev; | 1348 | slave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL); |
1343 | dws->reg_width = DW_DMA_SLAVE_WIDTH_32BIT; | 1349 | if (!slave) |
1344 | dws->cfg_hi = (DWC_CFGH_SRC_PER(0) | 1350 | goto fail; |
1351 | |||
1352 | slave->sdata.dma_dev = &dw_dmac0_device.dev; | ||
1353 | slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT; | ||
1354 | slave->sdata.cfg_hi = (DWC_CFGH_SRC_PER(0) | ||
1345 | | DWC_CFGH_DST_PER(1)); | 1355 | | DWC_CFGH_DST_PER(1)); |
1346 | dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | 1356 | slave->sdata.cfg_lo &= ~(DWC_CFGL_HS_DST_POL |
1347 | | DWC_CFGL_HS_SRC_POL); | 1357 | | DWC_CFGL_HS_SRC_POL); |
1348 | 1358 | ||
1359 | data->dma_slave = slave; | ||
1360 | |||
1349 | if (platform_device_add_data(pdev, data, | 1361 | if (platform_device_add_data(pdev, data, |
1350 | sizeof(struct mci_platform_data))) | 1362 | sizeof(struct mci_platform_data))) |
1351 | goto fail; | 1363 | goto fail_free; |
1352 | 1364 | ||
1353 | /* CLK line is common to both slots */ | 1365 | /* CLK line is common to both slots */ |
1354 | pioa_mask = 1 << 10; | 1366 | pioa_mask = 1 << 10; |
@@ -1372,7 +1384,7 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1372 | /* Slot is unused */ | 1384 | /* Slot is unused */ |
1373 | break; | 1385 | break; |
1374 | default: | 1386 | default: |
1375 | goto fail; | 1387 | goto fail_free; |
1376 | } | 1388 | } |
1377 | 1389 | ||
1378 | select_peripheral(PIOA, pioa_mask, PERIPH_A, 0); | 1390 | select_peripheral(PIOA, pioa_mask, PERIPH_A, 0); |
@@ -1399,7 +1411,7 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1399 | break; | 1411 | break; |
1400 | default: | 1412 | default: |
1401 | if (!data->slot[0].bus_width) | 1413 | if (!data->slot[0].bus_width) |
1402 | goto fail; | 1414 | goto fail_free; |
1403 | 1415 | ||
1404 | data->slot[1].bus_width = 0; | 1416 | data->slot[1].bus_width = 0; |
1405 | break; | 1417 | break; |
@@ -1410,7 +1422,10 @@ at32_add_device_mci(unsigned int id, struct mci_platform_data *data) | |||
1410 | platform_device_add(pdev); | 1422 | platform_device_add(pdev); |
1411 | return pdev; | 1423 | return pdev; |
1412 | 1424 | ||
1425 | fail_free: | ||
1426 | kfree(slave); | ||
1413 | fail: | 1427 | fail: |
1428 | data->dma_slave = NULL; | ||
1414 | platform_device_put(pdev); | 1429 | platform_device_put(pdev); |
1415 | return NULL; | 1430 | return NULL; |
1416 | } | 1431 | } |
@@ -1756,10 +1771,13 @@ at32_add_device_usba(unsigned int id, struct usba_platform_data *data) | |||
1756 | ARRAY_SIZE(usba0_resource))) | 1771 | ARRAY_SIZE(usba0_resource))) |
1757 | goto out_free_pdev; | 1772 | goto out_free_pdev; |
1758 | 1773 | ||
1759 | if (data) | 1774 | if (data) { |
1760 | usba_data.pdata.vbus_pin = data->vbus_pin; | 1775 | usba_data.pdata.vbus_pin = data->vbus_pin; |
1761 | else | 1776 | usba_data.pdata.vbus_pin_inverted = data->vbus_pin_inverted; |
1777 | } else { | ||
1762 | usba_data.pdata.vbus_pin = -EINVAL; | 1778 | usba_data.pdata.vbus_pin = -EINVAL; |
1779 | usba_data.pdata.vbus_pin_inverted = -EINVAL; | ||
1780 | } | ||
1763 | 1781 | ||
1764 | data = &usba_data.pdata; | 1782 | data = &usba_data.pdata; |
1765 | data->num_ep = ARRAY_SIZE(at32_usba_ep); | 1783 | data->num_ep = ARRAY_SIZE(at32_usba_ep); |