aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2006-01-06 19:30:44 -0500
committerPaul Mackerras <paulus@samba.org>2006-01-08 23:47:16 -0500
commit730745a5c45093982112ddc94cee6a9973455641 (patch)
tree1c36bd96c28d08e2b5d839ba3f4e37588aad2328 /drivers/macintosh
parent002ec58eb57bac2380f0ed5a4e88121b4bdb32ec (diff)
[PATCH] 1/5 powerpc: Rework PowerMac i2c part 1
This is the first part of a rework of the PowerMac i2c code. It completely reworks the "low_i2c" layer. It is now more flexible, supports KeyWest, SMU and PMU i2c busses, and provides functions to match device nodes to i2c busses and adapters. This patch also extends & fix some bugs in the SMU driver related to i2c support and removes the clock spreading hacks from the pmac feature code rather than adapting them to the new API since they'll be replaced by the platform function code completely in patch 3/5 Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r--drivers/macintosh/smu.c58
-rw-r--r--drivers/macintosh/via-pmu.c264
2 files changed, 38 insertions, 284 deletions
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 96226116a646..9ecd76849e35 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -94,6 +94,8 @@ struct smu_device {
94static struct smu_device *smu; 94static struct smu_device *smu;
95static DECLARE_MUTEX(smu_part_access); 95static DECLARE_MUTEX(smu_part_access);
96 96
97static void smu_i2c_retry(unsigned long data);
98
97/* 99/*
98 * SMU driver low level stuff 100 * SMU driver low level stuff
99 */ 101 */
@@ -469,7 +471,6 @@ int __init smu_init (void)
469 smu->of_node = np; 471 smu->of_node = np;
470 smu->db_irq = NO_IRQ; 472 smu->db_irq = NO_IRQ;
471 smu->msg_irq = NO_IRQ; 473 smu->msg_irq = NO_IRQ;
472 init_timer(&smu->i2c_timer);
473 474
474 /* smu_cmdbuf_abs is in the low 2G of RAM, can be converted to a 475 /* smu_cmdbuf_abs is in the low 2G of RAM, can be converted to a
475 * 32 bits value safely 476 * 32 bits value safely
@@ -544,6 +545,10 @@ static int smu_late_init(void)
544 if (!smu) 545 if (!smu)
545 return 0; 546 return 0;
546 547
548 init_timer(&smu->i2c_timer);
549 smu->i2c_timer.function = smu_i2c_retry;
550 smu->i2c_timer.data = (unsigned long)smu;
551
547 /* 552 /*
548 * Try to request the interrupts 553 * Try to request the interrupts
549 */ 554 */
@@ -570,28 +575,41 @@ static int smu_late_init(void)
570 575
571 return 0; 576 return 0;
572} 577}
573arch_initcall(smu_late_init); 578/* This has to be before arch_initcall as the low i2c stuff relies on the
579 * above having been done before we reach arch_initcalls
580 */
581core_initcall(smu_late_init);
574 582
575/* 583/*
576 * sysfs visibility 584 * sysfs visibility
577 */ 585 */
578 586
587static void smu_create_i2c(struct device_node *np)
588{
589 char name[32];
590 u32 *reg = (u32 *)get_property(np, "reg", NULL);
591
592 if (reg != NULL) {
593 sprintf(name, "smu-i2c-%02x", *reg);
594 of_platform_device_create(np, name, &smu->of_dev->dev);
595 }
596}
597
579static void smu_expose_childs(void *unused) 598static void smu_expose_childs(void *unused)
580{ 599{
581 struct device_node *np; 600 struct device_node *np, *gp;
582 601
583 for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;) { 602 for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;) {
584 if (device_is_compatible(np, "smu-i2c")) { 603 if (device_is_compatible(np, "smu-i2c-control")) {
585 char name[32]; 604 gp = NULL;
586 u32 *reg = (u32 *)get_property(np, "reg", NULL); 605 while ((gp = of_get_next_child(np, gp)) != NULL)
587 606 if (device_is_compatible(gp, "i2c-bus"))
588 if (reg == NULL) 607 smu_create_i2c(gp);
589 continue; 608 } else if (device_is_compatible(np, "smu-i2c"))
590 sprintf(name, "smu-i2c-%02x", *reg); 609 smu_create_i2c(np);
591 of_platform_device_create(np, name, &smu->of_dev->dev);
592 }
593 if (device_is_compatible(np, "smu-sensors")) 610 if (device_is_compatible(np, "smu-sensors"))
594 of_platform_device_create(np, "smu-sensors", &smu->of_dev->dev); 611 of_platform_device_create(np, "smu-sensors",
612 &smu->of_dev->dev);
595 } 613 }
596 614
597} 615}
@@ -712,13 +730,13 @@ static void smu_i2c_complete_command(struct smu_i2c_cmd *cmd, int fail)
712 730
713static void smu_i2c_retry(unsigned long data) 731static void smu_i2c_retry(unsigned long data)
714{ 732{
715 struct smu_i2c_cmd *cmd = (struct smu_i2c_cmd *)data; 733 struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur;
716 734
717 DPRINTK("SMU: i2c failure, requeuing...\n"); 735 DPRINTK("SMU: i2c failure, requeuing...\n");
718 736
719 /* requeue command simply by resetting reply_len */ 737 /* requeue command simply by resetting reply_len */
720 cmd->pdata[0] = 0xff; 738 cmd->pdata[0] = 0xff;
721 cmd->scmd.reply_len = 0x10; 739 cmd->scmd.reply_len = sizeof(cmd->pdata);
722 smu_queue_cmd(&cmd->scmd); 740 smu_queue_cmd(&cmd->scmd);
723} 741}
724 742
@@ -747,10 +765,8 @@ static void smu_i2c_low_completion(struct smu_cmd *scmd, void *misc)
747 */ 765 */
748 if (fail && --cmd->retries > 0) { 766 if (fail && --cmd->retries > 0) {
749 DPRINTK("SMU: i2c failure, starting timer...\n"); 767 DPRINTK("SMU: i2c failure, starting timer...\n");
750 smu->i2c_timer.function = smu_i2c_retry; 768 BUG_ON(cmd != smu->cmd_i2c_cur);
751 smu->i2c_timer.data = (unsigned long)cmd; 769 mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5));
752 smu->i2c_timer.expires = jiffies + msecs_to_jiffies(5);
753 add_timer(&smu->i2c_timer);
754 return; 770 return;
755 } 771 }
756 772
@@ -764,7 +780,7 @@ static void smu_i2c_low_completion(struct smu_cmd *scmd, void *misc)
764 780
765 /* Ok, initial command complete, now poll status */ 781 /* Ok, initial command complete, now poll status */
766 scmd->reply_buf = cmd->pdata; 782 scmd->reply_buf = cmd->pdata;
767 scmd->reply_len = 0x10; 783 scmd->reply_len = sizeof(cmd->pdata);
768 scmd->data_buf = cmd->pdata; 784 scmd->data_buf = cmd->pdata;
769 scmd->data_len = 1; 785 scmd->data_len = 1;
770 cmd->pdata[0] = 0; 786 cmd->pdata[0] = 0;
@@ -786,7 +802,7 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
786 cmd->scmd.done = smu_i2c_low_completion; 802 cmd->scmd.done = smu_i2c_low_completion;
787 cmd->scmd.misc = cmd; 803 cmd->scmd.misc = cmd;
788 cmd->scmd.reply_buf = cmd->pdata; 804 cmd->scmd.reply_buf = cmd->pdata;
789 cmd->scmd.reply_len = 0x10; 805 cmd->scmd.reply_len = sizeof(cmd->pdata);
790 cmd->scmd.data_buf = (u8 *)(char *)&cmd->info; 806 cmd->scmd.data_buf = (u8 *)(char *)&cmd->info;
791 cmd->scmd.status = 1; 807 cmd->scmd.status = 1;
792 cmd->stage = 0; 808 cmd->stage = 0;
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 3c0552016b91..aa481a88ccab 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -197,7 +197,6 @@ static int pmu_adb_reset_bus(void);
197#endif /* CONFIG_ADB */ 197#endif /* CONFIG_ADB */
198 198
199static int init_pmu(void); 199static int init_pmu(void);
200static int pmu_queue_request(struct adb_request *req);
201static void pmu_start(void); 200static void pmu_start(void);
202static irqreturn_t via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs); 201static irqreturn_t via_pmu_interrupt(int irq, void *arg, struct pt_regs *regs);
203static irqreturn_t gpio1_interrupt(int irq, void *arg, struct pt_regs *regs); 202static irqreturn_t gpio1_interrupt(int irq, void *arg, struct pt_regs *regs);
@@ -1802,258 +1801,6 @@ pmu_present(void)
1802 return via != 0; 1801 return via != 0;
1803} 1802}
1804 1803
1805struct pmu_i2c_hdr {
1806 u8 bus;
1807 u8 mode;
1808 u8 bus2;
1809 u8 address;
1810 u8 sub_addr;
1811 u8 comb_addr;
1812 u8 count;
1813};
1814
1815int
1816pmu_i2c_combined_read(int bus, int addr, int subaddr, u8* data, int len)
1817{
1818 struct adb_request req;
1819 struct pmu_i2c_hdr *hdr = (struct pmu_i2c_hdr *)&req.data[1];
1820 int retry;
1821 int rc;
1822
1823 for (retry=0; retry<16; retry++) {
1824 memset(&req, 0, sizeof(req));
1825
1826 hdr->bus = bus;
1827 hdr->address = addr & 0xfe;
1828 hdr->mode = PMU_I2C_MODE_COMBINED;
1829 hdr->bus2 = 0;
1830 hdr->sub_addr = subaddr;
1831 hdr->comb_addr = addr | 1;
1832 hdr->count = len;
1833
1834 req.nbytes = sizeof(struct pmu_i2c_hdr) + 1;
1835 req.reply_expected = 0;
1836 req.reply_len = 0;
1837 req.data[0] = PMU_I2C_CMD;
1838 req.reply[0] = 0xff;
1839 rc = pmu_queue_request(&req);
1840 if (rc)
1841 return rc;
1842 while(!req.complete)
1843 pmu_poll();
1844 if (req.reply[0] == PMU_I2C_STATUS_OK)
1845 break;
1846 mdelay(15);
1847 }
1848 if (req.reply[0] != PMU_I2C_STATUS_OK)
1849 return -1;
1850
1851 for (retry=0; retry<16; retry++) {
1852 memset(&req, 0, sizeof(req));
1853
1854 mdelay(15);
1855
1856 hdr->bus = PMU_I2C_BUS_STATUS;
1857 req.reply[0] = 0xff;
1858
1859 req.nbytes = 2;
1860 req.reply_expected = 0;
1861 req.reply_len = 0;
1862 req.data[0] = PMU_I2C_CMD;
1863 rc = pmu_queue_request(&req);
1864 if (rc)
1865 return rc;
1866 while(!req.complete)
1867 pmu_poll();
1868 if (req.reply[0] == PMU_I2C_STATUS_DATAREAD) {
1869 memcpy(data, &req.reply[1], req.reply_len - 1);
1870 return req.reply_len - 1;
1871 }
1872 }
1873 return -1;
1874}
1875
1876int
1877pmu_i2c_stdsub_write(int bus, int addr, int subaddr, u8* data, int len)
1878{
1879 struct adb_request req;
1880 struct pmu_i2c_hdr *hdr = (struct pmu_i2c_hdr *)&req.data[1];
1881 int retry;
1882 int rc;
1883
1884 for (retry=0; retry<16; retry++) {
1885 memset(&req, 0, sizeof(req));
1886
1887 hdr->bus = bus;
1888 hdr->address = addr & 0xfe;
1889 hdr->mode = PMU_I2C_MODE_STDSUB;
1890 hdr->bus2 = 0;
1891 hdr->sub_addr = subaddr;
1892 hdr->comb_addr = addr & 0xfe;
1893 hdr->count = len;
1894
1895 req.data[0] = PMU_I2C_CMD;
1896 memcpy(&req.data[sizeof(struct pmu_i2c_hdr) + 1], data, len);
1897 req.nbytes = sizeof(struct pmu_i2c_hdr) + len + 1;
1898 req.reply_expected = 0;
1899 req.reply_len = 0;
1900 req.reply[0] = 0xff;
1901 rc = pmu_queue_request(&req);
1902 if (rc)
1903 return rc;
1904 while(!req.complete)
1905 pmu_poll();
1906 if (req.reply[0] == PMU_I2C_STATUS_OK)
1907 break;
1908 mdelay(15);
1909 }
1910 if (req.reply[0] != PMU_I2C_STATUS_OK)
1911 return -1;
1912
1913 for (retry=0; retry<16; retry++) {
1914 memset(&req, 0, sizeof(req));
1915
1916 mdelay(15);
1917
1918 hdr->bus = PMU_I2C_BUS_STATUS;
1919 req.reply[0] = 0xff;
1920
1921 req.nbytes = 2;
1922 req.reply_expected = 0;
1923 req.reply_len = 0;
1924 req.data[0] = PMU_I2C_CMD;
1925 rc = pmu_queue_request(&req);
1926 if (rc)
1927 return rc;
1928 while(!req.complete)
1929 pmu_poll();
1930 if (req.reply[0] == PMU_I2C_STATUS_OK)
1931 return len;
1932 }
1933 return -1;
1934}
1935
1936int
1937pmu_i2c_simple_read(int bus, int addr, u8* data, int len)
1938{
1939 struct adb_request req;
1940 struct pmu_i2c_hdr *hdr = (struct pmu_i2c_hdr *)&req.data[1];
1941 int retry;
1942 int rc;
1943
1944 for (retry=0; retry<16; retry++) {
1945 memset(&req, 0, sizeof(req));
1946
1947 hdr->bus = bus;
1948 hdr->address = addr | 1;
1949 hdr->mode = PMU_I2C_MODE_SIMPLE;
1950 hdr->bus2 = 0;
1951 hdr->sub_addr = 0;
1952 hdr->comb_addr = 0;
1953 hdr->count = len;
1954
1955 req.data[0] = PMU_I2C_CMD;
1956 req.nbytes = sizeof(struct pmu_i2c_hdr) + 1;
1957 req.reply_expected = 0;
1958 req.reply_len = 0;
1959 req.reply[0] = 0xff;
1960 rc = pmu_queue_request(&req);
1961 if (rc)
1962 return rc;
1963 while(!req.complete)
1964 pmu_poll();
1965 if (req.reply[0] == PMU_I2C_STATUS_OK)
1966 break;
1967 mdelay(15);
1968 }
1969 if (req.reply[0] != PMU_I2C_STATUS_OK)
1970 return -1;
1971
1972 for (retry=0; retry<16; retry++) {
1973 memset(&req, 0, sizeof(req));
1974
1975 mdelay(15);
1976
1977 hdr->bus = PMU_I2C_BUS_STATUS;
1978 req.reply[0] = 0xff;
1979
1980 req.nbytes = 2;
1981 req.reply_expected = 0;
1982 req.reply_len = 0;
1983 req.data[0] = PMU_I2C_CMD;
1984 rc = pmu_queue_request(&req);
1985 if (rc)
1986 return rc;
1987 while(!req.complete)
1988 pmu_poll();
1989 if (req.reply[0] == PMU_I2C_STATUS_DATAREAD) {
1990 memcpy(data, &req.reply[1], req.reply_len - 1);
1991 return req.reply_len - 1;
1992 }
1993 }
1994 return -1;
1995}
1996
1997int
1998pmu_i2c_simple_write(int bus, int addr, u8* data, int len)
1999{
2000 struct adb_request req;
2001 struct pmu_i2c_hdr *hdr = (struct pmu_i2c_hdr *)&req.data[1];
2002 int retry;
2003 int rc;
2004
2005 for (retry=0; retry<16; retry++) {
2006 memset(&req, 0, sizeof(req));
2007
2008 hdr->bus = bus;
2009 hdr->address = addr & 0xfe;
2010 hdr->mode = PMU_I2C_MODE_SIMPLE;
2011 hdr->bus2 = 0;
2012 hdr->sub_addr = 0;
2013 hdr->comb_addr = 0;
2014 hdr->count = len;
2015
2016 req.data[0] = PMU_I2C_CMD;
2017 memcpy(&req.data[sizeof(struct pmu_i2c_hdr) + 1], data, len);
2018 req.nbytes = sizeof(struct pmu_i2c_hdr) + len + 1;
2019 req.reply_expected = 0;
2020 req.reply_len = 0;
2021 req.reply[0] = 0xff;
2022 rc = pmu_queue_request(&req);
2023 if (rc)
2024 return rc;
2025 while(!req.complete)
2026 pmu_poll();
2027 if (req.reply[0] == PMU_I2C_STATUS_OK)
2028 break;
2029 mdelay(15);
2030 }
2031 if (req.reply[0] != PMU_I2C_STATUS_OK)
2032 return -1;
2033
2034 for (retry=0; retry<16; retry++) {
2035 memset(&req, 0, sizeof(req));
2036
2037 mdelay(15);
2038
2039 hdr->bus = PMU_I2C_BUS_STATUS;
2040 req.reply[0] = 0xff;
2041
2042 req.nbytes = 2;
2043 req.reply_expected = 0;
2044 req.reply_len = 0;
2045 req.data[0] = PMU_I2C_CMD;
2046 rc = pmu_queue_request(&req);
2047 if (rc)
2048 return rc;
2049 while(!req.complete)
2050 pmu_poll();
2051 if (req.reply[0] == PMU_I2C_STATUS_OK)
2052 return len;
2053 }
2054 return -1;
2055}
2056
2057#ifdef CONFIG_PM 1804#ifdef CONFIG_PM
2058 1805
2059static LIST_HEAD(sleep_notifiers); 1806static LIST_HEAD(sleep_notifiers);
@@ -2358,9 +2105,6 @@ pmac_suspend_devices(void)
2358 return -EBUSY; 2105 return -EBUSY;
2359 } 2106 }
2360 2107
2361 /* Disable clock spreading on some machines */
2362 pmac_tweak_clock_spreading(0);
2363
2364 /* Stop preemption */ 2108 /* Stop preemption */
2365 preempt_disable(); 2109 preempt_disable();
2366 2110
@@ -2431,9 +2175,6 @@ pmac_wakeup_devices(void)
2431 mdelay(10); 2175 mdelay(10);
2432 preempt_enable(); 2176 preempt_enable();
2433 2177
2434 /* Re-enable clock spreading on some machines */
2435 pmac_tweak_clock_spreading(1);
2436
2437 /* Resume devices */ 2178 /* Resume devices */
2438 device_resume(); 2179 device_resume();
2439 2180
@@ -3150,16 +2891,13 @@ static int __init init_pmu_sysfs(void)
3150subsys_initcall(init_pmu_sysfs); 2891subsys_initcall(init_pmu_sysfs);
3151 2892
3152EXPORT_SYMBOL(pmu_request); 2893EXPORT_SYMBOL(pmu_request);
2894EXPORT_SYMBOL(pmu_queue_request);
3153EXPORT_SYMBOL(pmu_poll); 2895EXPORT_SYMBOL(pmu_poll);
3154EXPORT_SYMBOL(pmu_poll_adb); 2896EXPORT_SYMBOL(pmu_poll_adb);
3155EXPORT_SYMBOL(pmu_wait_complete); 2897EXPORT_SYMBOL(pmu_wait_complete);
3156EXPORT_SYMBOL(pmu_suspend); 2898EXPORT_SYMBOL(pmu_suspend);
3157EXPORT_SYMBOL(pmu_resume); 2899EXPORT_SYMBOL(pmu_resume);
3158EXPORT_SYMBOL(pmu_unlock); 2900EXPORT_SYMBOL(pmu_unlock);
3159EXPORT_SYMBOL(pmu_i2c_combined_read);
3160EXPORT_SYMBOL(pmu_i2c_stdsub_write);
3161EXPORT_SYMBOL(pmu_i2c_simple_read);
3162EXPORT_SYMBOL(pmu_i2c_simple_write);
3163#if defined(CONFIG_PM) && defined(CONFIG_PPC32) 2901#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
3164EXPORT_SYMBOL(pmu_enable_irled); 2902EXPORT_SYMBOL(pmu_enable_irled);
3165EXPORT_SYMBOL(pmu_battery_count); 2903EXPORT_SYMBOL(pmu_battery_count);