diff options
author | Daniel Drake <dsd@laptop.org> | 2011-03-03 14:03:31 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 15:37:49 -0400 |
commit | c6384c886dfed806f07ae2f8ba4d3740b57cde9c (patch) | |
tree | 610d83eb567490f465e86a3f2a1254a74ada8d4e /drivers/media/video | |
parent | 4a1cba5151ccddf4a7071fe4950fb699e8b23bf9 (diff) |
[media] via-camera: Fix OLPC serial check
The code that checks the OLPC serial port is never built at the moment,
because CONFIG_OLPC_XO_1_5 doesn't exist and probably won't be added.
Fix it so that it gets compiled in, only executes on OLPC laptops, and
move the check into the probe routine.
The compiler is smart enough to eliminate this code when CONFIG_OLPC=n
(due to machine_is_olpc() always returning false).
Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r-- | drivers/media/video/via-camera.c | 83 |
1 files changed, 37 insertions, 46 deletions
diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c index 3f0146fcf752..8c780c2d937b 100644 --- a/drivers/media/video/via-camera.c +++ b/drivers/media/video/via-camera.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/via-core.h> | 25 | #include <linux/via-core.h> |
26 | #include <linux/via-gpio.h> | 26 | #include <linux/via-gpio.h> |
27 | #include <linux/via_i2c.h> | 27 | #include <linux/via_i2c.h> |
28 | #include <asm/olpc.h> | ||
28 | 29 | ||
29 | #include "via-camera.h" | 30 | #include "via-camera.h" |
30 | 31 | ||
@@ -38,14 +39,12 @@ MODULE_PARM_DESC(flip_image, | |||
38 | "If set, the sensor will be instructed to flip the image " | 39 | "If set, the sensor will be instructed to flip the image " |
39 | "vertically."); | 40 | "vertically."); |
40 | 41 | ||
41 | #ifdef CONFIG_OLPC_XO_1_5 | ||
42 | static int override_serial; | 42 | static int override_serial; |
43 | module_param(override_serial, bool, 0444); | 43 | module_param(override_serial, bool, 0444); |
44 | MODULE_PARM_DESC(override_serial, | 44 | MODULE_PARM_DESC(override_serial, |
45 | "The camera driver will normally refuse to load if " | 45 | "The camera driver will normally refuse to load if " |
46 | "the XO 1.5 serial port is enabled. Set this option " | 46 | "the XO 1.5 serial port is enabled. Set this option " |
47 | "to force the issue."); | 47 | "to force-enable the camera."); |
48 | #endif | ||
49 | 48 | ||
50 | /* | 49 | /* |
51 | * Basic window sizes. | 50 | * Basic window sizes. |
@@ -1317,6 +1316,37 @@ static struct video_device viacam_v4l_template = { | |||
1317 | .release = video_device_release_empty, /* Check this */ | 1316 | .release = video_device_release_empty, /* Check this */ |
1318 | }; | 1317 | }; |
1319 | 1318 | ||
1319 | /* | ||
1320 | * The OLPC folks put the serial port on the same pin as | ||
1321 | * the camera. They also get grumpy if we break the | ||
1322 | * serial port and keep them from using it. So we have | ||
1323 | * to check the serial enable bit and not step on it. | ||
1324 | */ | ||
1325 | #define VIACAM_SERIAL_DEVFN 0x88 | ||
1326 | #define VIACAM_SERIAL_CREG 0x46 | ||
1327 | #define VIACAM_SERIAL_BIT 0x40 | ||
1328 | |||
1329 | static __devinit bool viacam_serial_is_enabled(void) | ||
1330 | { | ||
1331 | struct pci_bus *pbus = pci_find_bus(0, 0); | ||
1332 | u8 cbyte; | ||
1333 | |||
1334 | pci_bus_read_config_byte(pbus, VIACAM_SERIAL_DEVFN, | ||
1335 | VIACAM_SERIAL_CREG, &cbyte); | ||
1336 | if ((cbyte & VIACAM_SERIAL_BIT) == 0) | ||
1337 | return false; /* Not enabled */ | ||
1338 | if (override_serial == 0) { | ||
1339 | printk(KERN_NOTICE "Via camera: serial port is enabled, " \ | ||
1340 | "refusing to load.\n"); | ||
1341 | printk(KERN_NOTICE "Specify override_serial=1 to force " \ | ||
1342 | "module loading.\n"); | ||
1343 | return true; | ||
1344 | } | ||
1345 | printk(KERN_NOTICE "Via camera: overriding serial port\n"); | ||
1346 | pci_bus_write_config_byte(pbus, VIACAM_SERIAL_DEVFN, | ||
1347 | VIACAM_SERIAL_CREG, cbyte & ~VIACAM_SERIAL_BIT); | ||
1348 | return false; | ||
1349 | } | ||
1320 | 1350 | ||
1321 | static __devinit int viacam_probe(struct platform_device *pdev) | 1351 | static __devinit int viacam_probe(struct platform_device *pdev) |
1322 | { | 1352 | { |
@@ -1348,6 +1378,10 @@ static __devinit int viacam_probe(struct platform_device *pdev) | |||
1348 | printk(KERN_ERR "viacam: No I/O memory, so no pictures\n"); | 1378 | printk(KERN_ERR "viacam: No I/O memory, so no pictures\n"); |
1349 | return -ENOMEM; | 1379 | return -ENOMEM; |
1350 | } | 1380 | } |
1381 | |||
1382 | if (machine_is_olpc() && viacam_serial_is_enabled()) | ||
1383 | return -EBUSY; | ||
1384 | |||
1351 | /* | 1385 | /* |
1352 | * Basic structure initialization. | 1386 | * Basic structure initialization. |
1353 | */ | 1387 | */ |
@@ -1459,7 +1493,6 @@ static __devexit int viacam_remove(struct platform_device *pdev) | |||
1459 | return 0; | 1493 | return 0; |
1460 | } | 1494 | } |
1461 | 1495 | ||
1462 | |||
1463 | static struct platform_driver viacam_driver = { | 1496 | static struct platform_driver viacam_driver = { |
1464 | .driver = { | 1497 | .driver = { |
1465 | .name = "viafb-camera", | 1498 | .name = "viafb-camera", |
@@ -1468,50 +1501,8 @@ static struct platform_driver viacam_driver = { | |||
1468 | .remove = viacam_remove, | 1501 | .remove = viacam_remove, |
1469 | }; | 1502 | }; |
1470 | 1503 | ||
1471 | |||
1472 | #ifdef CONFIG_OLPC_XO_1_5 | ||
1473 | /* | ||
1474 | * The OLPC folks put the serial port on the same pin as | ||
1475 | * the camera. They also get grumpy if we break the | ||
1476 | * serial port and keep them from using it. So we have | ||
1477 | * to check the serial enable bit and not step on it. | ||
1478 | */ | ||
1479 | #define VIACAM_SERIAL_DEVFN 0x88 | ||
1480 | #define VIACAM_SERIAL_CREG 0x46 | ||
1481 | #define VIACAM_SERIAL_BIT 0x40 | ||
1482 | |||
1483 | static __devinit int viacam_check_serial_port(void) | ||
1484 | { | ||
1485 | struct pci_bus *pbus = pci_find_bus(0, 0); | ||
1486 | u8 cbyte; | ||
1487 | |||
1488 | pci_bus_read_config_byte(pbus, VIACAM_SERIAL_DEVFN, | ||
1489 | VIACAM_SERIAL_CREG, &cbyte); | ||
1490 | if ((cbyte & VIACAM_SERIAL_BIT) == 0) | ||
1491 | return 0; /* Not enabled */ | ||
1492 | if (override_serial == 0) { | ||
1493 | printk(KERN_NOTICE "Via camera: serial port is enabled, " \ | ||
1494 | "refusing to load.\n"); | ||
1495 | printk(KERN_NOTICE "Specify override_serial=1 to force " \ | ||
1496 | "module loading.\n"); | ||
1497 | return -EBUSY; | ||
1498 | } | ||
1499 | printk(KERN_NOTICE "Via camera: overriding serial port\n"); | ||
1500 | pci_bus_write_config_byte(pbus, VIACAM_SERIAL_DEVFN, | ||
1501 | VIACAM_SERIAL_CREG, cbyte & ~VIACAM_SERIAL_BIT); | ||
1502 | return 0; | ||
1503 | } | ||
1504 | #endif | ||
1505 | |||
1506 | |||
1507 | |||
1508 | |||
1509 | static int viacam_init(void) | 1504 | static int viacam_init(void) |
1510 | { | 1505 | { |
1511 | #ifdef CONFIG_OLPC_XO_1_5 | ||
1512 | if (viacam_check_serial_port()) | ||
1513 | return -EBUSY; | ||
1514 | #endif | ||
1515 | return platform_driver_register(&viacam_driver); | 1506 | return platform_driver_register(&viacam_driver); |
1516 | } | 1507 | } |
1517 | module_init(viacam_init); | 1508 | module_init(viacam_init); |