diff options
Diffstat (limited to 'arch/sh/boards/mach-kfr2r09/setup.c')
-rw-r--r-- | arch/sh/boards/mach-kfr2r09/setup.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/arch/sh/boards/mach-kfr2r09/setup.c b/arch/sh/boards/mach-kfr2r09/setup.c index bdb10c29ef18..7155be0d1154 100644 --- a/arch/sh/boards/mach-kfr2r09/setup.c +++ b/arch/sh/boards/mach-kfr2r09/setup.c | |||
@@ -16,6 +16,8 @@ | |||
16 | #include <linux/clk.h> | 16 | #include <linux/clk.h> |
17 | #include <linux/gpio.h> | 17 | #include <linux/gpio.h> |
18 | #include <linux/input.h> | 18 | #include <linux/input.h> |
19 | #include <linux/i2c.h> | ||
20 | #include <linux/usb/r8a66597.h> | ||
19 | #include <video/sh_mobile_lcdc.h> | 21 | #include <video/sh_mobile_lcdc.h> |
20 | #include <asm/clock.h> | 22 | #include <asm/clock.h> |
21 | #include <asm/machvec.h> | 23 | #include <asm/machvec.h> |
@@ -113,6 +115,9 @@ static struct platform_device kfr2r09_sh_keysc_device = { | |||
113 | .dev = { | 115 | .dev = { |
114 | .platform_data = &kfr2r09_sh_keysc_info, | 116 | .platform_data = &kfr2r09_sh_keysc_info, |
115 | }, | 117 | }, |
118 | .archdata = { | ||
119 | .hwblk_id = HWBLK_KEYSC, | ||
120 | }, | ||
116 | }; | 121 | }; |
117 | 122 | ||
118 | static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = { | 123 | static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = { |
@@ -173,6 +178,38 @@ static struct platform_device kfr2r09_sh_lcdc_device = { | |||
173 | .dev = { | 178 | .dev = { |
174 | .platform_data = &kfr2r09_sh_lcdc_info, | 179 | .platform_data = &kfr2r09_sh_lcdc_info, |
175 | }, | 180 | }, |
181 | .archdata = { | ||
182 | .hwblk_id = HWBLK_LCDC, | ||
183 | }, | ||
184 | }; | ||
185 | |||
186 | static struct r8a66597_platdata kfr2r09_usb0_gadget_data = { | ||
187 | .on_chip = 1, | ||
188 | }; | ||
189 | |||
190 | static struct resource kfr2r09_usb0_gadget_resources[] = { | ||
191 | [0] = { | ||
192 | .start = 0x04d80000, | ||
193 | .end = 0x04d80123, | ||
194 | .flags = IORESOURCE_MEM, | ||
195 | }, | ||
196 | [1] = { | ||
197 | .start = 65, | ||
198 | .end = 65, | ||
199 | .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW, | ||
200 | }, | ||
201 | }; | ||
202 | |||
203 | static struct platform_device kfr2r09_usb0_gadget_device = { | ||
204 | .name = "r8a66597_udc", | ||
205 | .id = 0, | ||
206 | .dev = { | ||
207 | .dma_mask = NULL, /* not use dma */ | ||
208 | .coherent_dma_mask = 0xffffffff, | ||
209 | .platform_data = &kfr2r09_usb0_gadget_data, | ||
210 | }, | ||
211 | .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources), | ||
212 | .resource = kfr2r09_usb0_gadget_resources, | ||
176 | }; | 213 | }; |
177 | 214 | ||
178 | static struct platform_device *kfr2r09_devices[] __initdata = { | 215 | static struct platform_device *kfr2r09_devices[] __initdata = { |
@@ -186,6 +223,81 @@ static struct platform_device *kfr2r09_devices[] __initdata = { | |||
186 | #define BSC_CS0WCR 0xfec10024 | 223 | #define BSC_CS0WCR 0xfec10024 |
187 | #define BSC_CS4BCR 0xfec10010 | 224 | #define BSC_CS4BCR 0xfec10010 |
188 | #define BSC_CS4WCR 0xfec10030 | 225 | #define BSC_CS4WCR 0xfec10030 |
226 | #define PORT_MSELCRB 0xa4050182 | ||
227 | |||
228 | #ifdef CONFIG_I2C | ||
229 | static int kfr2r09_usb0_gadget_i2c_setup(void) | ||
230 | { | ||
231 | struct i2c_adapter *a; | ||
232 | struct i2c_msg msg; | ||
233 | unsigned char buf[2]; | ||
234 | int ret; | ||
235 | |||
236 | a = i2c_get_adapter(0); | ||
237 | if (!a) | ||
238 | return -ENODEV; | ||
239 | |||
240 | /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */ | ||
241 | buf[0] = 0x13; | ||
242 | msg.addr = 0x09; | ||
243 | msg.buf = buf; | ||
244 | msg.len = 1; | ||
245 | msg.flags = 0; | ||
246 | ret = i2c_transfer(a, &msg, 1); | ||
247 | if (ret != 1) | ||
248 | return -ENODEV; | ||
249 | |||
250 | buf[0] = 0; | ||
251 | msg.addr = 0x09; | ||
252 | msg.buf = buf; | ||
253 | msg.len = 1; | ||
254 | msg.flags = I2C_M_RD; | ||
255 | ret = i2c_transfer(a, &msg, 1); | ||
256 | if (ret != 1) | ||
257 | return -ENODEV; | ||
258 | |||
259 | buf[1] = buf[0] | (1 << 1); | ||
260 | buf[0] = 0x13; | ||
261 | msg.addr = 0x09; | ||
262 | msg.buf = buf; | ||
263 | msg.len = 2; | ||
264 | msg.flags = 0; | ||
265 | ret = i2c_transfer(a, &msg, 1); | ||
266 | if (ret != 1) | ||
267 | return -ENODEV; | ||
268 | |||
269 | return 0; | ||
270 | } | ||
271 | #else | ||
272 | static int kfr2r09_usb0_gadget_i2c_setup(void) | ||
273 | { | ||
274 | return -ENODEV; | ||
275 | } | ||
276 | #endif | ||
277 | |||
278 | static int kfr2r09_usb0_gadget_setup(void) | ||
279 | { | ||
280 | int plugged_in; | ||
281 | |||
282 | gpio_request(GPIO_PTN4, NULL); /* USB_DET */ | ||
283 | gpio_direction_input(GPIO_PTN4); | ||
284 | plugged_in = gpio_get_value(GPIO_PTN4); | ||
285 | if (!plugged_in) | ||
286 | return -ENODEV; /* no cable plugged in */ | ||
287 | |||
288 | if (kfr2r09_usb0_gadget_i2c_setup() != 0) | ||
289 | return -ENODEV; /* unable to configure using i2c */ | ||
290 | |||
291 | ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB); | ||
292 | gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */ | ||
293 | gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */ | ||
294 | gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */ | ||
295 | msleep(20); /* wait 20ms to let the clock settle */ | ||
296 | clk_enable(clk_get(NULL, "usb0")); | ||
297 | ctrl_outw(0x0600, 0xa40501d4); | ||
298 | |||
299 | return 0; | ||
300 | } | ||
189 | 301 | ||
190 | static int __init kfr2r09_devices_setup(void) | 302 | static int __init kfr2r09_devices_setup(void) |
191 | { | 303 | { |
@@ -245,6 +357,10 @@ static int __init kfr2r09_devices_setup(void) | |||
245 | gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */ | 357 | gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */ |
246 | gpio_direction_output(GPIO_PTU0, 1); | 358 | gpio_direction_output(GPIO_PTU0, 1); |
247 | 359 | ||
360 | /* setup USB function */ | ||
361 | if (kfr2r09_usb0_gadget_setup() == 0) | ||
362 | platform_device_register(&kfr2r09_usb0_gadget_device); | ||
363 | |||
248 | return platform_add_devices(kfr2r09_devices, | 364 | return platform_add_devices(kfr2r09_devices, |
249 | ARRAY_SIZE(kfr2r09_devices)); | 365 | ARRAY_SIZE(kfr2r09_devices)); |
250 | } | 366 | } |