/arch/mips/powertv/asic/asic_devices.c

http://github.com/mirrors/linux · C · 549 lines · 344 code · 70 blank · 135 comment · 59 complexity · b2293653e37d5bc237556150e8115a7e MD5 · raw file

  1. /*
  2. *
  3. * Description: Defines the platform resources for Gaia-based settops.
  4. *
  5. * Copyright (C) 2005-2009 Scientific-Atlanta, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * NOTE: The bootloader allocates persistent memory at an address which is
  22. * 16 MiB below the end of the highest address in KSEG0. All fixed
  23. * address memory reservations must avoid this region.
  24. */
  25. #include <linux/device.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/resource.h>
  29. #include <linux/serial_reg.h>
  30. #include <linux/io.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/mm.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/module.h>
  35. #include <asm/page.h>
  36. #include <linux/swap.h>
  37. #include <linux/highmem.h>
  38. #include <linux/dma-mapping.h>
  39. #include <asm/mach-powertv/asic.h>
  40. #include <asm/mach-powertv/asic_regs.h>
  41. #include <asm/mach-powertv/interrupts.h>
  42. #ifdef CONFIG_BOOTLOADER_DRIVER
  43. #include <asm/mach-powertv/kbldr.h>
  44. #endif
  45. #include <asm/bootinfo.h>
  46. #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0))
  47. /*
  48. * Forward Prototypes
  49. */
  50. static void pmem_setup_resource(void);
  51. /*
  52. * Global Variables
  53. */
  54. enum asic_type asic;
  55. unsigned int platform_features;
  56. unsigned int platform_family;
  57. struct register_map _asic_register_map;
  58. EXPORT_SYMBOL(_asic_register_map); /* Exported for testing */
  59. unsigned long asic_phy_base;
  60. unsigned long asic_base;
  61. EXPORT_SYMBOL(asic_base); /* Exported for testing */
  62. struct resource *gp_resources;
  63. /*
  64. * Don't recommend to use it directly, it is usually used by kernel internally.
  65. * Portable code should be using interfaces such as ioremp, dma_map_single, etc.
  66. */
  67. unsigned long phys_to_dma_offset;
  68. EXPORT_SYMBOL(phys_to_dma_offset);
  69. /*
  70. *
  71. * IO Resource Definition
  72. *
  73. */
  74. struct resource asic_resource = {
  75. .name = "ASIC Resource",
  76. .start = 0,
  77. .end = ASIC_IO_SIZE,
  78. .flags = IORESOURCE_MEM,
  79. };
  80. /*
  81. * Allow override of bootloader-specified model
  82. * Returns zero on success, a negative errno value on failure. This parameter
  83. * allows overriding of the bootloader-specified model.
  84. */
  85. static char __initdata cmdline[COMMAND_LINE_SIZE];
  86. #define FORCEFAMILY_PARAM "forcefamily"
  87. /*
  88. * check_forcefamily - check for, and parse, forcefamily command line parameter
  89. * @forced_family: Pointer to two-character array in which to store the
  90. * value of the forcedfamily parameter, if any.
  91. */
  92. static __init int check_forcefamily(unsigned char forced_family[2])
  93. {
  94. const char *p;
  95. forced_family[0] = '\0';
  96. forced_family[1] = '\0';
  97. /* Check the command line for a forcefamily directive */
  98. strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1);
  99. p = strstr(cmdline, FORCEFAMILY_PARAM);
  100. if (p && (p != cmdline) && (*(p - 1) != ' '))
  101. p = strstr(p, " " FORCEFAMILY_PARAM "=");
  102. if (p) {
  103. p += strlen(FORCEFAMILY_PARAM "=");
  104. if (*p == '\0' || *(p + 1) == '\0' ||
  105. (*(p + 2) != '\0' && *(p + 2) != ' '))
  106. pr_err(FORCEFAMILY_PARAM " must be exactly two "
  107. "characters long, ignoring value\n");
  108. else {
  109. forced_family[0] = *p;
  110. forced_family[1] = *(p + 1);
  111. }
  112. }
  113. return 0;
  114. }
  115. /*
  116. * platform_set_family - determine major platform family type.
  117. *
  118. * Returns family type; -1 if none
  119. * Returns the family type; -1 if none
  120. *
  121. */
  122. static __init noinline void platform_set_family(void)
  123. {
  124. unsigned char forced_family[2];
  125. unsigned short bootldr_family;
  126. if (check_forcefamily(forced_family) == 0)
  127. bootldr_family = BOOTLDRFAMILY(forced_family[0],
  128. forced_family[1]);
  129. else
  130. bootldr_family = (unsigned short) BOOTLDRFAMILY(
  131. CONFIG_BOOTLOADER_FAMILY[0],
  132. CONFIG_BOOTLOADER_FAMILY[1]);
  133. pr_info("Bootloader Family = 0x%04X\n", bootldr_family);
  134. switch (bootldr_family) {
  135. case BOOTLDRFAMILY('R', '1'):
  136. platform_family = FAMILY_1500;
  137. break;
  138. case BOOTLDRFAMILY('4', '4'):
  139. platform_family = FAMILY_4500;
  140. break;
  141. case BOOTLDRFAMILY('4', '6'):
  142. platform_family = FAMILY_4600;
  143. break;
  144. case BOOTLDRFAMILY('A', '1'):
  145. platform_family = FAMILY_4600VZA;
  146. break;
  147. case BOOTLDRFAMILY('8', '5'):
  148. platform_family = FAMILY_8500;
  149. break;
  150. case BOOTLDRFAMILY('R', '2'):
  151. platform_family = FAMILY_8500RNG;
  152. break;
  153. case BOOTLDRFAMILY('8', '6'):
  154. platform_family = FAMILY_8600;
  155. break;
  156. case BOOTLDRFAMILY('B', '1'):
  157. platform_family = FAMILY_8600VZB;
  158. break;
  159. case BOOTLDRFAMILY('E', '1'):
  160. platform_family = FAMILY_1500VZE;
  161. break;
  162. case BOOTLDRFAMILY('F', '1'):
  163. platform_family = FAMILY_1500VZF;
  164. break;
  165. case BOOTLDRFAMILY('8', '7'):
  166. platform_family = FAMILY_8700;
  167. break;
  168. default:
  169. platform_family = -1;
  170. }
  171. }
  172. unsigned int platform_get_family(void)
  173. {
  174. return platform_family;
  175. }
  176. EXPORT_SYMBOL(platform_get_family);
  177. /*
  178. * platform_get_asic - determine the ASIC type.
  179. *
  180. * Returns the ASIC type, or ASIC_UNKNOWN if unknown
  181. *
  182. */
  183. enum asic_type platform_get_asic(void)
  184. {
  185. return asic;
  186. }
  187. EXPORT_SYMBOL(platform_get_asic);
  188. /*
  189. * set_register_map - set ASIC register configuration
  190. * @phys_base: Physical address of the base of the ASIC registers
  191. * @map: Description of key ASIC registers
  192. */
  193. static void __init set_register_map(unsigned long phys_base,
  194. const struct register_map *map)
  195. {
  196. asic_phy_base = phys_base;
  197. _asic_register_map = *map;
  198. register_map_virtualize(&_asic_register_map);
  199. asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE);
  200. }
  201. /**
  202. * configure_platform - configuration based on platform type.
  203. */
  204. void __init configure_platform(void)
  205. {
  206. platform_set_family();
  207. switch (platform_family) {
  208. case FAMILY_1500:
  209. case FAMILY_1500VZE:
  210. case FAMILY_1500VZF:
  211. platform_features = FFS_CAPABLE;
  212. asic = ASIC_CALLIOPE;
  213. set_register_map(CALLIOPE_IO_BASE, &calliope_register_map);
  214. if (platform_family == FAMILY_1500VZE) {
  215. gp_resources = non_dvr_vze_calliope_resources;
  216. pr_info("Platform: 1500/Vz Class E - "
  217. "CALLIOPE, NON_DVR_CAPABLE\n");
  218. } else if (platform_family == FAMILY_1500VZF) {
  219. gp_resources = non_dvr_vzf_calliope_resources;
  220. pr_info("Platform: 1500/Vz Class F - "
  221. "CALLIOPE, NON_DVR_CAPABLE\n");
  222. } else {
  223. gp_resources = non_dvr_calliope_resources;
  224. pr_info("Platform: 1500/RNG100 - CALLIOPE, "
  225. "NON_DVR_CAPABLE\n");
  226. }
  227. break;
  228. case FAMILY_4500:
  229. platform_features = FFS_CAPABLE | PCIE_CAPABLE |
  230. DISPLAY_CAPABLE;
  231. asic = ASIC_ZEUS;
  232. set_register_map(ZEUS_IO_BASE, &zeus_register_map);
  233. gp_resources = non_dvr_zeus_resources;
  234. pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n");
  235. break;
  236. case FAMILY_4600:
  237. {
  238. unsigned int chipversion = 0;
  239. /* The settop has PCIE but it isn't used, so don't advertise
  240. * it*/
  241. platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
  242. /* Cronus and Cronus Lite have the same register map */
  243. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  244. /* ASIC version will determine if this is a real CronusLite or
  245. * Castrati(Cronus) */
  246. chipversion = asic_read(chipver3) << 24;
  247. chipversion |= asic_read(chipver2) << 16;
  248. chipversion |= asic_read(chipver1) << 8;
  249. chipversion |= asic_read(chipver0);
  250. if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11))
  251. asic = ASIC_CRONUS;
  252. else
  253. asic = ASIC_CRONUSLITE;
  254. gp_resources = non_dvr_cronuslite_resources;
  255. pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, "
  256. "chipversion=0x%08X\n",
  257. (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE",
  258. chipversion);
  259. break;
  260. }
  261. case FAMILY_4600VZA:
  262. platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
  263. asic = ASIC_CRONUS;
  264. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  265. gp_resources = non_dvr_cronus_resources;
  266. pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n");
  267. break;
  268. case FAMILY_8500:
  269. case FAMILY_8500RNG:
  270. platform_features = DVR_CAPABLE | PCIE_CAPABLE |
  271. DISPLAY_CAPABLE;
  272. asic = ASIC_ZEUS;
  273. set_register_map(ZEUS_IO_BASE, &zeus_register_map);
  274. gp_resources = dvr_zeus_resources;
  275. pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n");
  276. break;
  277. case FAMILY_8600:
  278. case FAMILY_8600VZB:
  279. platform_features = DVR_CAPABLE | PCIE_CAPABLE |
  280. DISPLAY_CAPABLE;
  281. asic = ASIC_CRONUS;
  282. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  283. gp_resources = dvr_cronus_resources;
  284. pr_info("Platform: 8600/Vz Class B - CRONUS, "
  285. "DVR_CAPABLE\n");
  286. break;
  287. case FAMILY_8700:
  288. platform_features = FFS_CAPABLE | PCIE_CAPABLE;
  289. asic = ASIC_GAIA;
  290. set_register_map(GAIA_IO_BASE, &gaia_register_map);
  291. gp_resources = dvr_gaia_resources;
  292. pr_info("Platform: 8700 - GAIA, DVR_CAPABLE\n");
  293. break;
  294. default:
  295. pr_crit("Platform: UNKNOWN PLATFORM\n");
  296. break;
  297. }
  298. switch (asic) {
  299. case ASIC_ZEUS:
  300. phys_to_dma_offset = 0x30000000;
  301. break;
  302. case ASIC_CALLIOPE:
  303. phys_to_dma_offset = 0x10000000;
  304. break;
  305. case ASIC_CRONUSLITE:
  306. /* Fall through */
  307. case ASIC_CRONUS:
  308. /*
  309. * TODO: We suppose 0x10000000 aliases into 0x20000000-
  310. * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000-
  311. * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000.
  312. */
  313. phys_to_dma_offset = 0x10000000;
  314. break;
  315. default:
  316. phys_to_dma_offset = 0x00000000;
  317. break;
  318. }
  319. }
  320. /*
  321. * RESOURCE ALLOCATION
  322. *
  323. */
  324. /*
  325. * Allocates/reserves the Platform memory resources early in the boot process.
  326. * This ignores any resources that are designated IORESOURCE_IO
  327. */
  328. void __init platform_alloc_bootmem(void)
  329. {
  330. int i;
  331. int total = 0;
  332. /* Get persistent memory data from command line before allocating
  333. * resources. This need to happen before normal command line parsing
  334. * has been done */
  335. pmem_setup_resource();
  336. /* Loop through looking for resources that want a particular address */
  337. for (i = 0; gp_resources[i].flags != 0; i++) {
  338. int size = resource_size(&gp_resources[i]);
  339. if ((gp_resources[i].start != 0) &&
  340. ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
  341. reserve_bootmem(dma_to_phys(gp_resources[i].start),
  342. size, 0);
  343. total += resource_size(&gp_resources[i]);
  344. pr_info("reserve resource %s at %08x (%u bytes)\n",
  345. gp_resources[i].name, gp_resources[i].start,
  346. resource_size(&gp_resources[i]));
  347. }
  348. }
  349. /* Loop through assigning addresses for those that are left */
  350. for (i = 0; gp_resources[i].flags != 0; i++) {
  351. int size = resource_size(&gp_resources[i]);
  352. if ((gp_resources[i].start == 0) &&
  353. ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
  354. void *mem = alloc_bootmem_pages(size);
  355. if (mem == NULL)
  356. pr_err("Unable to allocate bootmem pages "
  357. "for %s\n", gp_resources[i].name);
  358. else {
  359. gp_resources[i].start =
  360. phys_to_dma(virt_to_phys(mem));
  361. gp_resources[i].end =
  362. gp_resources[i].start + size - 1;
  363. total += size;
  364. pr_info("allocate resource %s at %08x "
  365. "(%u bytes)\n",
  366. gp_resources[i].name,
  367. gp_resources[i].start, size);
  368. }
  369. }
  370. }
  371. pr_info("Total Platform driver memory allocation: 0x%08x\n", total);
  372. /* indicate resources that are platform I/O related */
  373. for (i = 0; gp_resources[i].flags != 0; i++) {
  374. if ((gp_resources[i].start != 0) &&
  375. ((gp_resources[i].flags & IORESOURCE_IO) != 0)) {
  376. pr_info("reserved platform resource %s at %08x\n",
  377. gp_resources[i].name, gp_resources[i].start);
  378. }
  379. }
  380. }
  381. /*
  382. *
  383. * PERSISTENT MEMORY (PMEM) CONFIGURATION
  384. *
  385. */
  386. static unsigned long pmemaddr __initdata;
  387. static int __init early_param_pmemaddr(char *p)
  388. {
  389. pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0);
  390. return 0;
  391. }
  392. early_param("pmemaddr", early_param_pmemaddr);
  393. static long pmemlen __initdata;
  394. static int __init early_param_pmemlen(char *p)
  395. {
  396. /* TODO: we can use this code when and if the bootloader ever changes this */
  397. #if 0
  398. pmemlen = (unsigned long)simple_strtoul(p, NULL, 0);
  399. #else
  400. pmemlen = 0x20000;
  401. #endif
  402. return 0;
  403. }
  404. early_param("pmemlen", early_param_pmemlen);
  405. /*
  406. * Set up persistent memory. If we were given values, we patch the array of
  407. * resources. Otherwise, persistent memory may be allocated anywhere at all.
  408. */
  409. static void __init pmem_setup_resource(void)
  410. {
  411. struct resource *resource;
  412. resource = asic_resource_get("DiagPersistentMemory");
  413. if (resource && pmemaddr && pmemlen) {
  414. /* The address provided by bootloader is in kseg0. Convert to
  415. * a bus address. */
  416. resource->start = phys_to_dma(pmemaddr - 0x80000000);
  417. resource->end = resource->start + pmemlen - 1;
  418. pr_info("persistent memory: start=0x%x end=0x%x\n",
  419. resource->start, resource->end);
  420. }
  421. }
  422. /*
  423. *
  424. * RESOURCE ACCESS FUNCTIONS
  425. *
  426. */
  427. /**
  428. * asic_resource_get - retrieves parameters for a platform resource.
  429. * @name: string to match resource
  430. *
  431. * Returns a pointer to a struct resource corresponding to the given name.
  432. *
  433. * CANNOT BE NAMED platform_resource_get, which would be the obvious choice,
  434. * as this function name is already declared
  435. */
  436. struct resource *asic_resource_get(const char *name)
  437. {
  438. int i;
  439. for (i = 0; gp_resources[i].flags != 0; i++) {
  440. if (strcmp(gp_resources[i].name, name) == 0)
  441. return &gp_resources[i];
  442. }
  443. return NULL;
  444. }
  445. EXPORT_SYMBOL(asic_resource_get);
  446. /**
  447. * platform_release_memory - release pre-allocated memory
  448. * @ptr: pointer to memory to release
  449. * @size: size of resource
  450. *
  451. * This must only be called for memory allocated or reserved via the boot
  452. * memory allocator.
  453. */
  454. void platform_release_memory(void *ptr, int size)
  455. {
  456. free_reserved_area(ptr, ptr + size, -1, NULL);
  457. }
  458. EXPORT_SYMBOL(platform_release_memory);
  459. /*
  460. *
  461. * FEATURE AVAILABILITY FUNCTIONS
  462. *
  463. */
  464. int platform_supports_dvr(void)
  465. {
  466. return (platform_features & DVR_CAPABLE) != 0;
  467. }
  468. int platform_supports_ffs(void)
  469. {
  470. return (platform_features & FFS_CAPABLE) != 0;
  471. }
  472. int platform_supports_pcie(void)
  473. {
  474. return (platform_features & PCIE_CAPABLE) != 0;
  475. }
  476. int platform_supports_display(void)
  477. {
  478. return (platform_features & DISPLAY_CAPABLE) != 0;
  479. }