Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/init.h> |
| 3 | #include <linux/i2c.h> |
| 4 | #include <linux/i2c-algo-bit.h> |
| 5 | #include <linux/i2c-gpio.h> |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 6 | #include <linux/platform_device.h> |
Linus Walleij | 0f33286 | 2011-08-22 08:33:30 +0100 | [diff] [blame] | 7 | #include <plat/gpio-nomadik.h> |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 8 | #include <plat/pincfg.h> |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 9 | |
| 10 | /* |
| 11 | * There are two busses in the 8815NHK. |
| 12 | * They could, in theory, be driven by the hardware component, but we |
| 13 | * use bit-bang through GPIO by now, to keep things simple |
| 14 | */ |
| 15 | |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 16 | /* I2C0 connected to the STw4811 power management chip */ |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 17 | static struct i2c_gpio_platform_data nhk8815_i2c_data0 = { |
| 18 | /* keep defaults for timeouts; pins are push-pull bidirectional */ |
| 19 | .scl_pin = 62, |
| 20 | .sda_pin = 63, |
| 21 | }; |
| 22 | |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 23 | /* I2C1 connected to various sensors */ |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 24 | static struct i2c_gpio_platform_data nhk8815_i2c_data1 = { |
| 25 | /* keep defaults for timeouts; pins are push-pull bidirectional */ |
| 26 | .scl_pin = 53, |
| 27 | .sda_pin = 54, |
| 28 | }; |
| 29 | |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 30 | /* I2C2 connected to the USB portions of the STw4811 only */ |
| 31 | static struct i2c_gpio_platform_data nhk8815_i2c_data2 = { |
| 32 | /* keep defaults for timeouts; pins are push-pull bidirectional */ |
| 33 | .scl_pin = 73, |
| 34 | .sda_pin = 74, |
| 35 | }; |
| 36 | |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 37 | static struct platform_device nhk8815_i2c_dev0 = { |
| 38 | .name = "i2c-gpio", |
| 39 | .id = 0, |
| 40 | .dev = { |
| 41 | .platform_data = &nhk8815_i2c_data0, |
| 42 | }, |
| 43 | }; |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 44 | |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 45 | static struct platform_device nhk8815_i2c_dev1 = { |
| 46 | .name = "i2c-gpio", |
| 47 | .id = 1, |
| 48 | .dev = { |
| 49 | .platform_data = &nhk8815_i2c_data1, |
| 50 | }, |
| 51 | }; |
| 52 | |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 53 | static struct platform_device nhk8815_i2c_dev2 = { |
| 54 | .name = "i2c-gpio", |
| 55 | .id = 2, |
| 56 | .dev = { |
| 57 | .platform_data = &nhk8815_i2c_data2, |
| 58 | }, |
| 59 | }; |
| 60 | |
| 61 | static pin_cfg_t cpu8815_pins_i2c[] = { |
| 62 | PIN_CFG_INPUT(62, GPIO, PULLUP), |
| 63 | PIN_CFG_INPUT(63, GPIO, PULLUP), |
| 64 | PIN_CFG_INPUT(53, GPIO, PULLUP), |
| 65 | PIN_CFG_INPUT(54, GPIO, PULLUP), |
| 66 | PIN_CFG_INPUT(73, GPIO, PULLUP), |
| 67 | PIN_CFG_INPUT(74, GPIO, PULLUP), |
| 68 | }; |
| 69 | |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 70 | static int __init nhk8815_i2c_init(void) |
| 71 | { |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 72 | nmk_config_pins(cpu8815_pins_i2c, ARRAY_SIZE(cpu8815_pins_i2c)); |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 73 | platform_device_register(&nhk8815_i2c_dev0); |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 74 | platform_device_register(&nhk8815_i2c_dev1); |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 75 | platform_device_register(&nhk8815_i2c_dev2); |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static void __exit nhk8815_i2c_exit(void) |
| 81 | { |
| 82 | platform_device_unregister(&nhk8815_i2c_dev0); |
| 83 | platform_device_unregister(&nhk8815_i2c_dev1); |
Linus Walleij | 661d414 | 2012-01-25 14:34:52 +0100 | [diff] [blame] | 84 | platform_device_unregister(&nhk8815_i2c_dev2); |
Alessandro Rubini | 63796b7 | 2009-07-02 15:29:22 +0100 | [diff] [blame] | 85 | return; |
| 86 | } |
| 87 | |
| 88 | module_init(nhk8815_i2c_init); |
| 89 | module_exit(nhk8815_i2c_exit); |